diff --git a/.env.example b/.env.example index c4053a4..ded9ac5 100644 --- a/.env.example +++ b/.env.example @@ -4,5 +4,5 @@ NEXT_PUBLIC_CONTENTSTACK_API_KEY=your_api_key_here NEXT_PUBLIC_CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token_here NEXT_PUBLIC_CONTENTSTACK_PREVIEW_TOKEN=your_preview_token_here NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT=preview -NEXT_PUBLIC_CONTENTSTACK_REGION=EU # Options: EU or NA +NEXT_PUBLIC_CONTENTSTACK_REGION=EU # Options: NA, EU, AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU NEXT_PUBLIC_CONTENTSTACK_PREVIEW=true # Set to true to enable preview \ No newline at end of file diff --git a/README.md b/README.md index 677485f..1620038 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 `NEXT_PUBLIC_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 +NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY=your-custom-cdn.example.com +NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST=your-custom-preview.example.com +NEXT_PUBLIC_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/lib/contentstack.ts b/lib/contentstack.ts index d7a9bf0..13cd75c 100644 --- a/lib/contentstack.ts +++ b/lib/contentstack.ts @@ -1,22 +1,19 @@ // Importing Contentstack SDK and specific types for region and query operations import contentstack, { QueryOperation } from "@contentstack/delivery-sdk"; -// Importing Contentstack Live Preview utilities and stack SDK +// Importing Contentstack Live Preview utilities and stack SDK import ContentstackLivePreview, { IStackSdk } from "@contentstack/live-preview-utils"; -// Importing the Page type definition +// Importing the Page type definition import { Page } from "./types"; -// helper functions from private package to retrieve Contentstack endpoints in a convienient way -import { getContentstackEndpoints, getRegionForString } from "@timbenniks/contentstack-endpoints"; +// helper functions to retrieve Contentstack endpoints for a given region +import { getContentstackEndpoint, type ContentstackEndpoints } from "@contentstack/utils"; export const isPreview = process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW === "true"; -// Set the region by string value from environment variables -const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as string) - // object with all endpoints for region. -const endpoints = getContentstackEndpoints(region, true) +const endpoints = getContentstackEndpoint(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION || 'NA', '', true) as ContentstackEndpoints export const stack = contentstack.stack({ // Setting the API key from environment variables @@ -29,13 +26,13 @@ export const stack = contentstack.stack({ environment: process.env.NEXT_PUBLIC_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 : process.env.NEXT_PUBLIC_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: process.env.NEXT_PUBLIC_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: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY || endpoints && endpoints.contentDelivery, + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY || endpoints.contentDelivery as string, live_preview: { // Enabling live preview if specified in environment variables @@ -45,8 +42,8 @@ export const stack = contentstack.stack({ preview_token: process.env.NEXT_PUBLIC_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: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST || endpoints && endpoints.preview + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST || endpoints.preview as string } }); @@ -63,8 +60,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: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION || endpoints && endpoints.application + // for custom or dedicated Contentstack environments, override each endpoint individually using environment variables. + host: process.env.NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION || endpoints.application as string }, editButton: { enable: true, // Enabling the edit button for live preview diff --git a/package-lock.json b/package-lock.json index 3315e9b..950583a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { "name": "kickstart-next", - "version": "1.0.21", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kickstart-next", - "version": "1.0.21", + "version": "1.1.0", "license": "MIT", "dependencies": { "@contentstack/delivery-sdk": "^5.2.1", "@contentstack/live-preview-utils": "^4.4.4", - "@timbenniks/contentstack-endpoints": "^3.0.2", - "isomorphic-dompurify": "^3.17.0", + "@contentstack/utils": "^1.9.1", + "isomorphic-dompurify": "3.17.0", "next": "^16.2.9", "react": "^19.2.7", "react-dom": "^19.2.7" @@ -1880,12 +1880,6 @@ "tailwindcss": "4.3.1" } }, - "node_modules/@timbenniks/contentstack-endpoints": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@timbenniks/contentstack-endpoints/-/contentstack-endpoints-3.0.2.tgz", - "integrity": "sha512-+9Yzfmdgw125BY1EY04a+GpNgAcwScrD1d+rgI+rUvtAoVKP0Y7GpPwD2Y20hb+FdUibvUUIy9BbTM9Ay0Fv7A==", - "license": "MIT" - }, "node_modules/@tybys/wasm-util": { "version": "0.10.2", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz", @@ -2911,9 +2905,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==", "license": "Apache-2.0", "bin": { "baseline-browser-mapping": "dist/cli.cjs" @@ -3381,9 +3375,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" @@ -3404,9 +3398,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.375", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.375.tgz", - "integrity": "sha512-ZWP5eB4BVPW/ZYo9252hQZHZ5XavtsTgpbhcmMmRwymavC5AsLWQWBPaKMeNd2LW0KGby5HPXvj7+sr4ta5j/Q==", + "version": "1.5.376", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.376.tgz", + "integrity": "sha512-cUVA7/RvbFTEuw/i3obUwDTRIXojaxkResf+ibByPFxjc6XK3VNtcQXV0NSbAlJ0FMjcJGgftVVB4Qo184EXvA==", "dev": true, "license": "ISC" }, @@ -5770,9 +5764,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.12", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.12.tgz", - "integrity": "sha512-ZB9RH/39qpq5Vu6Y+NmUaFhQR6pp+M2Xt76XBnEwDaGcVAqhlvxrl3B2bKS5D3NH3QR76v3aSrKaF/Kiy7lEtQ==", + "version": "3.3.13", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.13.tgz", + "integrity": "sha512-sPdqC6ByMVVGvF1ynvvMo0/o+oD1VX7DaHhijt1bFgjvBkHBib4t49GoNDhf2NDta4oeUNlaGbSt5K7qjZ955Q==", "funding": [ { "type": "github", @@ -5883,9 +5877,9 @@ } }, "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": { diff --git a/package.json b/package.json index 15d16a7..2e8f128 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kickstart-next", - "version": "1.0.21", + "version": "1.1.0", "private": false, "repository": { "type": "git", @@ -20,8 +20,8 @@ "dependencies": { "@contentstack/delivery-sdk": "^5.2.1", "@contentstack/live-preview-utils": "^4.4.4", - "@timbenniks/contentstack-endpoints": "^3.0.2", - "isomorphic-dompurify": "^3.17.0", + "@contentstack/utils": "^1.9.1", + "isomorphic-dompurify": "3.17.0", "next": "^16.2.9", "react": "^19.2.7", "react-dom": "^19.2.7"