diff --git a/lib/contentstack.ts b/lib/contentstack.ts index 68ed320..b1892c7 100644 --- a/lib/contentstack.ts +++ b/lib/contentstack.ts @@ -11,8 +11,7 @@ import { Page } from "./types"; import { getContentstackEndpoints, getRegionForString } from "@timbenniks/contentstack-endpoints"; // Set the region by string value from environment variables -const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION || "EU"); - +const region = getRegionForString(process.env.NEXT_PUBLIC_CONTENTSTACK_REGION as string) // object with all endpoints for region. const endpoints = getContentstackEndpoints(region, true) @@ -26,8 +25,15 @@ export const stack = contentstack.stack({ // Setting the environment based on environment variables environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string, - // Setting the region based on environment variables - region: region, + // 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, + + // 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, + live_preview: { // Enabling live preview if specified in environment variables enable: process.env.NEXT_PUBLIC_CONTENTSTACK_PREVIEW === 'true', @@ -36,7 +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 - host: endpoints.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_PREVIEW_HOST || endpoints && endpoints.preview } }); @@ -52,7 +59,9 @@ export function initLivePreview() { environment: process.env.NEXT_PUBLIC_CONTENTSTACK_ENVIRONMENT as string, // Setting the environment from environment variables }, clientUrlParams: { - host: endpoints.application + // 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 }, editButton: { enable: true, // Enabling the edit button for live preview diff --git a/next.config.mjs b/next.config.mjs index 71d3f5f..3978c7b 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,14 +1,14 @@ /** @type {import('next').NextConfig} */ const nextConfig = { images: { + // Configure allowed hostnames for Next.js Image Optimization remotePatterns: [ - { - hostname: "images.contentstack.io", - }, - { - protocol: "https", - hostname: "*-images.contentstack.com", - }, + ...(process.env.NEXT_PUBLIC_CONTENTSTACK_IMAGE_HOSTNAME + ? [{ hostname: process.env.NEXT_PUBLIC_CONTENTSTACK_IMAGE_HOSTNAME }] + : [ + { hostname: "images.contentstack.io" }, + { hostname: "*-images.contentstack.com" }, + ]), ], }, }; diff --git a/package-lock.json b/package-lock.json index c683145..20eaf35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,20 +10,20 @@ "license": "MIT", "dependencies": { "@contentstack/delivery-sdk": "^4.8.0", - "@contentstack/live-preview-utils": "^3.3.0", - "@timbenniks/contentstack-endpoints": "^1.0.12", + "@contentstack/live-preview-utils": "^3.4.0", + "@timbenniks/contentstack-endpoints": "^1.0.14", "dompurify": "^3.2.6", - "next": "^15.4.5", + "next": "^15.4.6", "react": "^19.1.1", "react-dom": "^19.1.1" }, "devDependencies": { "@tailwindcss/postcss": "^4.1.11", - "@types/node": "^24.1.0", + "@types/node": "^24.2.0", "@types/react": "^19.1.9", "@types/react-dom": "^19.1.7", "eslint": "^9.32.0", - "eslint-config-next": "^15.4.5", + "eslint-config-next": "^15.4.6", "postcss": "^8.5.6", "tailwindcss": "^4.1.11", "typescript": "^5.9.2" @@ -82,9 +82,9 @@ } }, "node_modules/@contentstack/live-preview-utils": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/@contentstack/live-preview-utils/-/live-preview-utils-3.3.0.tgz", - "integrity": "sha512-oqKr/F0LBdeRsgXX8UR2ExLcsKq0AfEXFAqoiviP8sTs1m1+f0LA3ahyL0ehD5ktWQGBVZm75yVLG4iKec1p2g==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@contentstack/live-preview-utils/-/live-preview-utils-3.4.0.tgz", + "integrity": "sha512-nK28/1Xdc3C79CBTXle70qfaWi5SRs7nfR5l/CM0skW+Sc4Eate5h5bnZfji5U+O7kfxATut6wEixUVBH6jbVQ==", "license": "MIT", "dependencies": { "@floating-ui/dom": "^1.7.2", @@ -860,15 +860,15 @@ } }, "node_modules/@next/env": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/env/-/env-15.4.5.tgz", - "integrity": "sha512-ruM+q2SCOVCepUiERoxOmZY9ZVoecR3gcXNwCYZRvQQWRjhOiPJGmQ2fAiLR6YKWXcSAh7G79KEFxN3rwhs4LQ==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/env/-/env-15.4.6.tgz", + "integrity": "sha512-yHDKVTcHrZy/8TWhj0B23ylKv5ypocuCwey9ZqPyv4rPdUdRzpGCkSi03t04KBPyU96kxVtUqx6O3nE1kpxASQ==", "license": "MIT" }, "node_modules/@next/eslint-plugin-next": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-15.4.5.tgz", - "integrity": "sha512-YhbrlbEt0m4jJnXHMY/cCUDBAWgd5SaTa5mJjzOt82QwflAFfW/h3+COp2TfVSzhmscIZ5sg2WXt3MLziqCSCw==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-15.4.6.tgz", + "integrity": "sha512-2NOu3ln+BTcpnbIDuxx6MNq+pRrCyey4WSXGaJIyt0D2TYicHeO9QrUENNjcf673n3B1s7hsiV5xBYRCK1Q8kA==", "dev": true, "license": "MIT", "dependencies": { @@ -876,9 +876,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.4.5.tgz", - "integrity": "sha512-84dAN4fkfdC7nX6udDLz9GzQlMUwEMKD7zsseXrl7FTeIItF8vpk1lhLEnsotiiDt+QFu3O1FVWnqwcRD2U3KA==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.4.6.tgz", + "integrity": "sha512-667R0RTP4DwxzmrqTs4Lr5dcEda9OxuZsVFsjVtxVMVhzSpo6nLclXejJVfQo2/g7/Z9qF3ETDmN3h65mTjpTQ==", "cpu": [ "arm64" ], @@ -892,9 +892,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.4.5.tgz", - "integrity": "sha512-CL6mfGsKuFSyQjx36p2ftwMNSb8PQog8y0HO/ONLdQqDql7x3aJb/wB+LA651r4we2pp/Ck+qoRVUeZZEvSurA==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.4.6.tgz", + "integrity": "sha512-KMSFoistFkaiQYVQQnaU9MPWtp/3m0kn2Xed1Ces5ll+ag1+rlac20sxG+MqhH2qYWX1O2GFOATQXEyxKiIscg==", "cpu": [ "x64" ], @@ -908,9 +908,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.4.5.tgz", - "integrity": "sha512-1hTVd9n6jpM/thnDc5kYHD1OjjWYpUJrJxY4DlEacT7L5SEOXIifIdTye6SQNNn8JDZrcN+n8AWOmeJ8u3KlvQ==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.4.6.tgz", + "integrity": "sha512-PnOx1YdO0W7m/HWFeYd2A6JtBO8O8Eb9h6nfJia2Dw1sRHoHpNf6lN1U4GKFRzRDBi9Nq2GrHk9PF3Vmwf7XVw==", "cpu": [ "arm64" ], @@ -924,9 +924,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.4.5.tgz", - "integrity": "sha512-4W+D/nw3RpIwGrqpFi7greZ0hjrCaioGErI7XHgkcTeWdZd146NNu1s4HnaHonLeNTguKnL2Urqvj28UJj6Gqw==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.4.6.tgz", + "integrity": "sha512-XBbuQddtY1p5FGPc2naMO0kqs4YYtLYK/8aPausI5lyOjr4J77KTG9mtlU4P3NwkLI1+OjsPzKVvSJdMs3cFaw==", "cpu": [ "arm64" ], @@ -940,9 +940,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.4.5.tgz", - "integrity": "sha512-N6Mgdxe/Cn2K1yMHge6pclffkxzbSGOydXVKYOjYqQXZYjLCfN/CuFkaYDeDHY2VBwSHyM2fUjYBiQCIlxIKDA==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.4.6.tgz", + "integrity": "sha512-+WTeK7Qdw82ez3U9JgD+igBAP75gqZ1vbK6R8PlEEuY0OIe5FuYXA4aTjL811kWPf7hNeslD4hHK2WoM9W0IgA==", "cpu": [ "x64" ], @@ -956,9 +956,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.4.5.tgz", - "integrity": "sha512-YZ3bNDrS8v5KiqgWE0xZQgtXgCTUacgFtnEgI4ccotAASwSvcMPDLua7BWLuTfucoRv6mPidXkITJLd8IdJplQ==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.4.6.tgz", + "integrity": "sha512-XP824mCbgQsK20jlXKrUpZoh/iO3vUWhMpxCz8oYeagoiZ4V0TQiKy0ASji1KK6IAe3DYGfj5RfKP6+L2020OQ==", "cpu": [ "x64" ], @@ -972,9 +972,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.4.5.tgz", - "integrity": "sha512-9Wr4t9GkZmMNcTVvSloFtjzbH4vtT4a8+UHqDoVnxA5QyfWe6c5flTH1BIWPGNWSUlofc8dVJAE7j84FQgskvQ==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.4.6.tgz", + "integrity": "sha512-FxrsenhUz0LbgRkNWx6FRRJIPe/MI1JRA4W4EPd5leXO00AZ6YU8v5vfx4MDXTvN77lM/EqsE3+6d2CIeF5NYg==", "cpu": [ "arm64" ], @@ -988,9 +988,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.4.5.tgz", - "integrity": "sha512-voWk7XtGvlsP+w8VBz7lqp8Y+dYw/MTI4KeS0gTVtfdhdJ5QwhXLmNrndFOin/MDoCvUaLWMkYKATaCoUkt2/A==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.4.6.tgz", + "integrity": "sha512-T4ufqnZ4u88ZheczkBTtOF+eKaM14V8kbjud/XrAakoM5DKQWjW09vD6B9fsdsWS2T7D5EY31hRHdta7QKWOng==", "cpu": [ "x64" ], @@ -1399,9 +1399,9 @@ } }, "node_modules/@timbenniks/contentstack-endpoints": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/@timbenniks/contentstack-endpoints/-/contentstack-endpoints-1.0.12.tgz", - "integrity": "sha512-7vXEwt4ZRjaLbUVlbF6VQuv9CFILlxsmBOF7FbULbMAeVvSskDlfErwkiXuCLuCpeSaUca49LORTaSeaQ/CU3A==", + "version": "1.0.14", + "resolved": "file:../../contentstack-endpoints/timbenniks-contentstack-endpoints-1.0.14.tgz", + "integrity": "sha512-IOKO9B7trAgHjY8h1dlgKKpGNq2ErCupFg2X58b7gFhkcyagvITZ01wla/OWz7eY89+Z7rI1hZLfRNBe5fhAoA==", "license": "MIT" }, "node_modules/@tybys/wasm-util": { @@ -1437,13 +1437,13 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.1.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.1.0.tgz", - "integrity": "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==", + "version": "24.2.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.0.tgz", + "integrity": "sha512-3xyG3pMCq3oYCNg7/ZP+E1ooTaGB4cG8JWRsqqOYQdbWNY4zbaV0Ennrd7stjiJEFZCaybcIgpTjJWHRfBSIDw==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~7.8.0" + "undici-types": "~7.10.0" } }, "node_modules/@types/react": { @@ -2772,13 +2772,13 @@ } }, "node_modules/eslint-config-next": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-15.4.5.tgz", - "integrity": "sha512-IMijiXaZ43qFB+Gcpnb374ipTKD8JIyVNR+6VsifFQ/LHyx+A9wgcgSIhCX5PYSjwOoSYD5LtNHKlM5uc23eww==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-15.4.6.tgz", + "integrity": "sha512-4uznvw5DlTTjrZgYZjMciSdDDMO2SWIuQgUNaFyC2O3Zw3Z91XeIejeVa439yRq2CnJb/KEvE4U2AeN/66FpUA==", "dev": true, "license": "MIT", "dependencies": { - "@next/eslint-plugin-next": "15.4.5", + "@next/eslint-plugin-next": "15.4.6", "@rushstack/eslint-patch": "^1.10.3", "@typescript-eslint/eslint-plugin": "^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0", "@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || ^7.0.0 || ^8.0.0", @@ -5072,12 +5072,12 @@ "license": "MIT" }, "node_modules/next": { - "version": "15.4.5", - "resolved": "https://registry.npmjs.org/next/-/next-15.4.5.tgz", - "integrity": "sha512-nJ4v+IO9CPmbmcvsPebIoX3Q+S7f6Fu08/dEWu0Ttfa+wVwQRh9epcmsyCPjmL2b8MxC+CkBR97jgDhUUztI3g==", + "version": "15.4.6", + "resolved": "https://registry.npmjs.org/next/-/next-15.4.6.tgz", + "integrity": "sha512-us++E/Q80/8+UekzB3SAGs71AlLDsadpFMXVNM/uQ0BMwsh9m3mr0UNQIfjKed8vpWXsASe+Qifrnu1oLIcKEQ==", "license": "MIT", "dependencies": { - "@next/env": "15.4.5", + "@next/env": "15.4.6", "@swc/helpers": "0.5.15", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", @@ -5090,14 +5090,14 @@ "node": "^18.18.0 || ^19.8.0 || >= 20.0.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "15.4.5", - "@next/swc-darwin-x64": "15.4.5", - "@next/swc-linux-arm64-gnu": "15.4.5", - "@next/swc-linux-arm64-musl": "15.4.5", - "@next/swc-linux-x64-gnu": "15.4.5", - "@next/swc-linux-x64-musl": "15.4.5", - "@next/swc-win32-arm64-msvc": "15.4.5", - "@next/swc-win32-x64-msvc": "15.4.5", + "@next/swc-darwin-arm64": "15.4.6", + "@next/swc-darwin-x64": "15.4.6", + "@next/swc-linux-arm64-gnu": "15.4.6", + "@next/swc-linux-arm64-musl": "15.4.6", + "@next/swc-linux-x64-gnu": "15.4.6", + "@next/swc-linux-x64-musl": "15.4.6", + "@next/swc-win32-arm64-msvc": "15.4.6", + "@next/swc-win32-x64-msvc": "15.4.6", "sharp": "^0.34.3" }, "peerDependencies": { @@ -6393,9 +6393,9 @@ } }, "node_modules/undici-types": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.8.0.tgz", - "integrity": "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", + "integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index 536c597..25842bc 100644 --- a/package.json +++ b/package.json @@ -19,20 +19,20 @@ }, "dependencies": { "@contentstack/delivery-sdk": "^4.8.0", - "@contentstack/live-preview-utils": "^3.3.0", - "@timbenniks/contentstack-endpoints": "^1.0.12", + "@contentstack/live-preview-utils": "^3.4.0", + "@timbenniks/contentstack-endpoints": "^1.0.14", "dompurify": "^3.2.6", - "next": "^15.4.5", + "next": "^15.4.6", "react": "^19.1.1", "react-dom": "^19.1.1" }, "devDependencies": { "@tailwindcss/postcss": "^4.1.11", - "@types/node": "^24.1.0", + "@types/node": "^24.2.0", "@types/react": "^19.1.9", "@types/react-dom": "^19.1.7", "eslint": "^9.32.0", - "eslint-config-next": "^15.4.5", + "eslint-config-next": "^15.4.6", "postcss": "^8.5.6", "tailwindcss": "^4.1.11", "typescript": "^5.9.2"