diff --git a/package-lock.json b/package-lock.json index 60ce7cb..45f3009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "@contentstack/types-generator", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/types-generator", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "dependencies": { - "@contentstack/delivery-sdk": "^4.2.0", + "@contentstack/delivery-sdk": "^4.4.3", "@gql2ts/from-schema": "^2.0.0-4", - "axios": "^1.7.5", + "axios": "^1.7.8", "lodash": "^4.17.21", "prettier": "^3.3.3" }, @@ -599,34 +599,37 @@ "dev": true }, "node_modules/@contentstack/core": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.1.0.tgz", - "integrity": "sha512-yZZswNe8yw6hH+uAIsFTHL5/rP6jJ5oyjy6S1BPHiCaTc24osQrsMHzG3PxLjC1Z6F0976gEbBkquln+deRaXA==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.1.3.tgz", + "integrity": "sha512-0sbk7xte9JVlPfcgpfhxT9OZeGG0FgHnc7FABEWsBzKi41KSnDj7zFmkK7rVaORkeUM1elhKDmLqNDRYC1oCEw==", "dependencies": { - "axios": "^1.7.2", + "axios": "^1.7.7", "axios-mock-adapter": "^1.22.0", "lodash": "^4.17.21", "qs": "^6.13.0", - "tslib": "^2.6.3" + "tslib": "^2.8.0" } }, "node_modules/@contentstack/delivery-sdk": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/@contentstack/delivery-sdk/-/delivery-sdk-4.3.0.tgz", - "integrity": "sha512-N4hqG6UXKWO5WQyPwZVkJ3gANtnTYoAozIINkLlKu8m48GOUFihFF08Yilvr7smybT2dnoNbkCnlqI64iNPPQA==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/@contentstack/delivery-sdk/-/delivery-sdk-4.4.3.tgz", + "integrity": "sha512-Iu51iC8otU5ipHR/jQSnD/GbQMno4eFCXwTiSbMyJy4yy65dz07lD1ZO0tiskputDR32PU2+AQ3Qv8o1OCDfXQ==", + "license": "MIT", "dependencies": { - "@contentstack/core": "^1.1.0", - "@contentstack/utils": "^1.3.8", + "@contentstack/core": "^1.1.3", + "@contentstack/utils": "^1.3.14", "@types/humps": "^2.0.6", - "axios": "^1.7.4", - "dotenv": "^16.3.1", - "humps": "^2.0.1" + "axios": "^1.7.8", + "dotenv": "^16.4.5", + "humps": "^2.0.1", + "path-browserify": "^1.0.1" } }, "node_modules/@contentstack/utils": { - "version": "1.3.9", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.9.tgz", - "integrity": "sha512-B2+RWRicUPqC2Qbumi35JFqz6HQR+iYjly9ZKqtgSWNNA4hWgsqzx8vX+/Gnhao6O9KWce8NgiyyKGOv567N3A==" + "version": "1.3.15", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.15.tgz", + "integrity": "sha512-m/FNx8LwSquMWo+KQ+zyBALEQTeFuldpLkqTrWXPEtmkPMCNnrF3aLcYHmcpLs7B1nux3wPRD6njhMDUU57giQ==", + "license": "MIT" }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", @@ -2055,9 +2058,10 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -2306,16 +2310,27 @@ "node": ">=8" } }, - "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "node_modules/call-bind-apply-helpers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz", + "integrity": "sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==", + "license": "MIT", "dependencies": { - "es-define-property": "^1.0.0", "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.3.tgz", + "integrity": "sha512-YTd+6wGlNlPxSuri7Y6X8tY2dmm12UMH66RpKMhiX6rsk5wXXnYgbUcOt8kiS31/AjfoTOvCsE+w8nZQLQnzHA==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "get-intrinsic": "^1.2.6" }, "engines": { "node": ">= 0.4" @@ -2604,22 +2619,6 @@ "node": ">=0.10.0" } }, - "node_modules/define-data-property": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", - "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "dependencies": { - "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "gopd": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -2680,6 +2679,20 @@ "url": "https://dotenvx.com" } }, + "node_modules/dunder-proto": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.0.tgz", + "integrity": "sha512-9+Sj30DIu+4KvHqMfLUGLFYL2PkURSYMVXJyXe92nFRvlYq5hBjLEhblKB+vkd/WVlUYMWigiY07T91Fkk0+4A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2720,12 +2733,10 @@ } }, "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -2734,6 +2745,19 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz", + "integrity": "sha512-MZ4iQ6JwHOBQjahnjwaC1ZtIBH+2ohjamzAO3oaHcXYup7qxjF2fixyH+Q71voWHeOkI2q/TnJao/KfXYIZWbw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, "engines": { "node": ">= 0.4" } @@ -3032,15 +3056,21 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.6.tgz", + "integrity": "sha512-qxsEs+9A+u85HhllWJJFicJfPDhRmjzoYdl64aMWW9yRIJmSyxdn8IEkuIM530/7T+lv0TIHd8L6Q/ra0tEoeA==", + "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "dunder-proto": "^1.0.0", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", + "es-object-atoms": "^1.0.0", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.0.0" }, "engines": { "node": ">= 0.4" @@ -3133,11 +3163,12 @@ } }, "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "dependencies": { - "get-intrinsic": "^1.1.3" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -3170,32 +3201,11 @@ "node": ">=8" } }, - "node_modules/has-property-descriptors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", - "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "dependencies": { - "es-define-property": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-proto": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", - "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -4278,6 +4288,15 @@ "tmpl": "1.0.5" } }, + "node_modules/math-intrinsics": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.0.0.tgz", + "integrity": "sha512-4MqMiKP90ybymYvsut0CH2g4XWbfLtmlCkXmtmdcDCxNB+mQcu1w/1+L/VD7vi/PSv7X2JYV7SCcR+jiPXnQtA==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -4435,9 +4454,10 @@ } }, "node_modules/object-inspect": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", - "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", + "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -4538,6 +4558,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "license": "MIT" + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -4772,9 +4798,10 @@ ] }, "node_modules/qs": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", - "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "version": "6.13.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.1.tgz", + "integrity": "sha512-EJPeIn0CYrGu+hli1xilKAPXODtJ12T0sP63Ijx2/khC2JtuaN3JyNIpvmnkmaEtha9ocbG4A4cMcr+TvqvwQg==", + "license": "BSD-3-Clause", "dependencies": { "side-channel": "^1.0.6" }, @@ -4956,22 +4983,6 @@ "semver": "bin/semver.js" } }, - "node_modules/set-function-length": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", - "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "dependencies": { - "define-data-property": "^1.1.4", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -4994,14 +5005,69 @@ } }, "node_modules/side-channel": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", - "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", "dependencies": { - "call-bind": "^1.0.7", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "object-inspect": "^1.13.1" + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -5448,9 +5514,10 @@ } }, "node_modules/tslib": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", - "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "license": "0BSD" }, "node_modules/tsup": { "version": "8.1.0", diff --git a/package.json b/package.json index 94e5422..4d6a249 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/types-generator", - "version": "2.0.2", + "version": "2.0.3", "description": "Contentstack type definition generation library", "private": false, "author": "Contentstack", @@ -42,9 +42,9 @@ "typescript": "^5.4.5" }, "dependencies": { - "@contentstack/delivery-sdk": "^4.2.0", + "@contentstack/delivery-sdk": "^4.4.3", "@gql2ts/from-schema": "^2.0.0-4", - "axios": "^1.7.5", + "axios": "^1.7.8", "lodash": "^4.17.21", "prettier": "^3.3.3" }, diff --git a/src/constants/index.ts b/src/constants/index.ts index 567bcc1..40d7ae1 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,3 +1,11 @@ export const TOKEN_TYPE = { DELIVERY: "delivery", }; + +export const REGIONS = { + US: "US", + EU: "EU", + AZURE_NA: "AZURE_NA", + AZURE_EU: "AZURE_EU", + GCP_NA: "GCP_NA", +}; diff --git a/src/generateTS/index.ts b/src/generateTS/index.ts index 4875467..b38d2cf 100644 --- a/src/generateTS/index.ts +++ b/src/generateTS/index.ts @@ -9,8 +9,6 @@ import { defaultInterfaces } from "./stack/builtins"; import { format } from "../format/index"; import { ContentType } from "../types/schema"; -const validRegions = ["US", "EU", "AZURE_NA", "AZURE_EU", "GCP_NA"]; - export const generateTS = async ({ token, tokenType, @@ -21,6 +19,7 @@ export const generateTS = async ({ prefix, includeDocumentation, systemFields, + host, }: GenerateTS) => { try { if (!token || !tokenType || !apiKey || !environment || !region) { @@ -31,13 +30,6 @@ export const generateTS = async ({ }; } - if (!validRegions.includes(region)) { - throw { - type: "validation", - error_message: - "Please provide a valid region, supported regions are : (US, EU, AZURE_NA, AZURE_EU, GCP_NA)", - }; - } if (tokenType === TOKEN_TYPE.DELIVERY) { const Stack = initializeContentstackSdk({ apiKey, @@ -45,6 +37,7 @@ export const generateTS = async ({ environment, region, branch, + host, }); const contentTypeQuery = Stack.contentType(); diff --git a/src/sdk/utils.ts b/src/sdk/utils.ts index c48b6f9..850d6da 100644 --- a/src/sdk/utils.ts +++ b/src/sdk/utils.ts @@ -1,5 +1,6 @@ import Contentstack, { Region } from "@contentstack/delivery-sdk"; import { StackConnectionConfig } from "../types"; +import { REGIONS } from "../constants"; export const initializeContentstackSdk = ({ apiKey, @@ -7,32 +8,46 @@ export const initializeContentstackSdk = ({ environment, region, branch, + host, }: StackConnectionConfig) => { try { + let isCustomRegion = false; const regionVal: Region | undefined = (function (regionValue: string) { switch (regionValue) { - case "US": + case REGIONS.US: return Region.US; - case "EU": + case REGIONS.EU: return Region.EU; - case "AZURE_NA": + case REGIONS.AZURE_NA: return Region.AZURE_NA; - case "AZURE_EU": + case REGIONS.AZURE_EU: return Region.AZURE_EU; - case "GCP_NA": + case REGIONS.GCP_NA: return Region.GCP_NA; default: - return undefined; + isCustomRegion = true; + break; } })(region as string); - const Stack = Contentstack.stack({ - apiKey: apiKey, - deliveryToken: token, - environment, - region: regionVal, - branch: branch, - }); + let Stack; + if (isCustomRegion && host) { + Stack = Contentstack.stack({ + apiKey: apiKey, + deliveryToken: token, + environment, + host: host, + branch: branch, + }); + } else { + Stack = Contentstack.stack({ + apiKey: apiKey, + deliveryToken: token, + environment, + region: regionVal, + branch: branch, + }); + } return Stack; } catch (err: any) { diff --git a/src/types/index.ts b/src/types/index.ts index 8b71ed7..fa78a70 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,6 +4,7 @@ export interface StackConnectionConfig { region: "US" | "EU" | "AZURE_NA" | "AZURE_EU" | "GCP_NA"; environment: string; branch?: string; + host?: string; } export interface GenerateTSBase extends StackConnectionConfig { diff --git a/tests/integration/generateTS/generateTS.test.ts b/tests/integration/generateTS/generateTS.test.ts index 17554fb..78476a5 100644 --- a/tests/integration/generateTS/generateTS.test.ts +++ b/tests/integration/generateTS/generateTS.test.ts @@ -137,9 +137,7 @@ describe("generateTS function with errors", () => { branch, }); } catch (err: any) { - expect(err.error_message).toEqual( - "Please provide a valid region, supported regions are : (US, EU, AZURE_NA, AZURE_EU, GCP_NA)" - ); + expect(err.error_message).toEqual("Something went wrong"); } }); diff --git a/tests/unit/generateTS/generateTS.test.ts b/tests/unit/generateTS/generateTS.test.ts index 695382f..e66c939 100644 --- a/tests/unit/generateTS/generateTS.test.ts +++ b/tests/unit/generateTS/generateTS.test.ts @@ -191,9 +191,7 @@ describe("generateTS function with errors", () => { branch, }); } catch (err: any) { - expect(err.error_message).toEqual( - "Please provide a valid region, supported regions are : (US, EU, AZURE_NA, AZURE_EU, GCP_NA)" - ); + expect(err.error_message).toEqual("Something went wrong"); } });