From f521bd7f1561ef12a1ef4c2f528efc804057e990 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 12 Nov 2025 09:30:08 +0530 Subject: [PATCH 1/2] refactor: region handling logic to utilize getContentstackEndpoint. Remove deprecated regions.json file. --- .talismanrc | 2 +- CHANGELOG.md | 5 ++ package-lock.json | 167 ++++++++---------------------------- package.json | 4 +- src/assets/regions.json | 186 ---------------------------------------- src/lib/contentstack.ts | 4 +- src/lib/utils.ts | 22 +---- 7 files changed, 48 insertions(+), 342 deletions(-) delete mode 100644 src/assets/regions.json diff --git a/.talismanrc b/.talismanrc index ea390f5..cf4e646 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,6 +1,6 @@ fileignoreconfig: - filename: package-lock.json - checksum: 275bc45fd72f2a19f8634536e1e0ea3d6516ea554178d172f9e64d01521b06f7 + checksum: 46c0d87a82455d4b2bae3347f7361dda71d2b979426b1c95ef707a9166c17778 - filename: test/unit/contentstack.spec.ts checksum: d5b99c01459ab8bc597baaa9e6cc4aa91ac6d9bf78af08e1d0220d0c5db3d0b3 - filename: test/unit/utils.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 5652003..251705c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Version: 4.10.3 +#### Date: Nov-12-2025 +Enhancement: Upgraded @contentstack/utils dependency to version 1.6.2 +Refactor: Replaced region handling logic to use getContentstackEndpoint from @contentstack/utils + ### Version: 4.10.2 #### Date: Oct-29-2025 Enhancement: Added logHandler interceptors for request and response logging diff --git a/package-lock.json b/package-lock.json index 78b7109..f5eac92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "hasInstallScript": true, "license": "MIT", "dependencies": { "@contentstack/core": "^1.3.1", - "@contentstack/utils": "^1.5.0", + "@contentstack/utils": "^1.6.1", "axios": "^1.13.1", "humps": "^2.0.1" }, @@ -71,6 +71,7 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -1917,9 +1918,10 @@ } }, "node_modules/@contentstack/utils": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.5.0.tgz", - "integrity": "sha512-tL1pcC4hJ+zcrvHq9c/ShTLjCVg8ACWahLDZvqT5VAalTsnR5Ik7QltjEcRsfpz/ucLQ1GVyRQRpezELCIon4A==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.6.1.tgz", + "integrity": "sha512-DyA4XWL2j70G2u1AUHt0GPTF1StFjjDAHNelVBvADiBUeg1RKT8+tMp3GMVs6p/ZhDEG6eZPsrKVlP26CUwsuA==", + "hasInstallScript": true, "license": "MIT" }, "node_modules/@cspotcode/source-map-support": { @@ -2858,7 +2860,6 @@ "integrity": "sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25" @@ -2956,7 +2957,6 @@ "integrity": "sha512-gB7Vxa6FReZZEGva03Eh+84W8BSZOjsNyXboglOINu6d8iZZ0eotSXGziKgjpkj3feZ1ofKZMs0PRObVAOROVw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "nx": "18.3.5", "tslib": "^2.3.0" @@ -3148,7 +3148,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3166,7 +3165,6 @@ "os": [ "darwin" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3184,7 +3182,6 @@ "os": [ "freebsd" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3202,7 +3199,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3220,7 +3216,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3238,7 +3233,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3256,7 +3250,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3274,7 +3267,6 @@ "os": [ "linux" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3292,7 +3284,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">= 10" } @@ -3310,7 +3301,6 @@ "os": [ "win32" ], - "peer": true, "engines": { "node": ">= 10" } @@ -4194,7 +4184,6 @@ "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/connect": "*", "@types/node": "*" @@ -4206,7 +4195,6 @@ "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*" } @@ -4217,7 +4205,6 @@ "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/estree": "*", "@types/json-schema": "*" @@ -4229,7 +4216,6 @@ "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/eslint": "*", "@types/estree": "*" @@ -4261,7 +4247,6 @@ "integrity": "sha512-jnHMsrd0Mwa9Cf4IdOzbz543y4XJepXrbia2T4b6+spXC2We3t1y6K44D3mR8XMFSXMCf3/l7rCgddfx7UNVBA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*", "@types/qs": "*", @@ -4284,8 +4269,7 @@ "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/humps": { "version": "2.0.6", @@ -4349,8 +4333,7 @@ "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/jsonwebtoken": { "version": "9.0.10", @@ -4368,8 +4351,7 @@ "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/ms": { "version": "2.1.0", @@ -4384,6 +4366,7 @@ "integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -4410,16 +4393,14 @@ "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.14.0.tgz", "integrity": "sha512-eOunJqu0K1923aExK6y8p6fsihYEn/BYuQ4g0CxAAgFc4b/ZLN4CrsRZ55srTdqoiLzU2B2evC+apEIxprEzkQ==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/range-parser": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/retry": { "version": "0.12.0", @@ -4434,7 +4415,6 @@ "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*" } @@ -4445,7 +4425,6 @@ "integrity": "sha512-tRs1dB+g8Itk72rlSI2ZrW6vZg0YrLI81iQSTkMmOqnqCaNr/8Ek4VwWcN5vZgCYWbg/JJSGBlUaYGAOP73qBw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/http-errors": "*", "@types/node": "*", @@ -4458,7 +4437,6 @@ "integrity": "sha512-Uqt8rPBE8SY0RK8JB1EzVOIZ32uqy8HwdxCnoCOsYrvnswqmFZ/k+9Ikidlk/ImhsdvBsloHbAlewb2IEBV/Og==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/mime": "^1", "@types/node": "*" @@ -4511,7 +4489,6 @@ "integrity": "sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/helper-numbers": "1.13.2", "@webassemblyjs/helper-wasm-bytecode": "1.13.2" @@ -4522,24 +4499,21 @@ "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.13.2.tgz", "integrity": "sha512-6oXyTOzbKxGH4steLbLNOu71Oj+C8Lg34n6CqRvqfS2O71BxY6ByfMDRhBytzknj9yGUPVJ1qIKhRlAwO1AovA==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@webassemblyjs/helper-api-error": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.13.2.tgz", "integrity": "sha512-U56GMYxy4ZQCbDZd6JuvvNV/WFildOjsaWD3Tzzvmw/mas3cXzRJPMjP83JqEsgSbyrmaGjBfDtV7KDXV9UzFQ==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@webassemblyjs/helper-buffer": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.14.1.tgz", "integrity": "sha512-jyH7wtcHiKssDtFPRB+iQdxlDf96m0E39yb0k5uJVhFGleZFoNw1c4aeIcVUPPbXUVJ94wwnMOAqUHyzoEPVMA==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@webassemblyjs/helper-numbers": { "version": "1.13.2", @@ -4547,7 +4521,6 @@ "integrity": "sha512-FE8aCmS5Q6eQYcV3gI35O4J789wlQA+7JrqTTpJqn5emA4U2hvwJmvFRC0HODS+3Ye6WioDklgd6scJ3+PLnEA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/floating-point-hex-parser": "1.13.2", "@webassemblyjs/helper-api-error": "1.13.2", @@ -4559,8 +4532,7 @@ "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.13.2.tgz", "integrity": "sha512-3QbLKy93F0EAIXLh0ogEVR6rOubA9AoZ+WRYhNbFyuB70j3dRdwH9g+qXhLAO0kiYGlg3TxDV+I4rQTr/YNXkA==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@webassemblyjs/helper-wasm-section": { "version": "1.14.1", @@ -4568,7 +4540,6 @@ "integrity": "sha512-ds5mXEqTJ6oxRoqjhWDU83OgzAYjwsCV8Lo/N+oRsNDmx/ZDpqalmrtgOMkHwxsG0iI//3BwWAErYRHtgn0dZw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@webassemblyjs/helper-buffer": "1.14.1", @@ -4582,7 +4553,6 @@ "integrity": "sha512-4LtOzh58S/5lX4ITKxnAK2USuNEvpdVV9AlgGQb8rJDHaLeHciwG4zlGr0j/SNWlr7x3vO1lDEsuePvtcDNCkw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@xtuc/ieee754": "^1.2.0" } @@ -4593,7 +4563,6 @@ "integrity": "sha512-Lde1oNoIdzVzdkNEAWZ1dZ5orIbff80YPdHx20mrHwHrVNNTjNr8E3xz9BdpcGqRQbAEa+fkrCb+fRFTl/6sQw==", "dev": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "@xtuc/long": "4.2.2" } @@ -4603,8 +4572,7 @@ "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.13.2.tgz", "integrity": "sha512-3NQWGjKTASY1xV5m7Hr0iPeXD9+RDobLll3T9d2AO+g3my8xy5peVyjSag4I50mR1bBSN/Ct12lo+R9tJk0NZQ==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@webassemblyjs/wasm-edit": { "version": "1.14.1", @@ -4612,7 +4580,6 @@ "integrity": "sha512-RNJUIQH/J8iA/1NzlE4N7KtyZNHi3w7at7hDjvRNm5rcUXa00z1vRz3glZoULfJ5mpvYhLybmVcwcjGrC1pRrQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@webassemblyjs/helper-buffer": "1.14.1", @@ -4630,7 +4597,6 @@ "integrity": "sha512-AmomSIjP8ZbfGQhumkNvgC33AY7qtMCXnN6bL2u2Js4gVCg8fp735aEiMSBbDR7UQIj90n4wKAFUSEd0QN2Ukg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@webassemblyjs/helper-wasm-bytecode": "1.13.2", @@ -4645,7 +4611,6 @@ "integrity": "sha512-PTcKLUNvBqnY2U6E5bdOQcSM+oVP/PmrDY9NzowJjislEjwP/C4an2303MCVS2Mg9d3AJpIGdUFIQQWbPds0Sw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@webassemblyjs/helper-buffer": "1.14.1", @@ -4659,7 +4624,6 @@ "integrity": "sha512-JLBl+KZ0R5qB7mCnud/yyX08jWFw5MsoalJ1pQ4EdFlgj9VdXKGuENGsiCIjegI1W7p91rUlcB/LB5yRJKNTcQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@webassemblyjs/helper-api-error": "1.13.2", @@ -4675,7 +4639,6 @@ "integrity": "sha512-kPSSXE6De1XOR820C90RIo2ogvZG+c3KiHzqUoO/F34Y2shGzesfqv7o57xrxovZJH/MetF5UjroJ/R/3isoiw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@webassemblyjs/ast": "1.14.1", "@xtuc/long": "4.2.2" @@ -4733,16 +4696,14 @@ "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==", "dev": true, - "license": "BSD-3-Clause", - "peer": true + "license": "BSD-3-Clause" }, "node_modules/@xtuc/long": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", "dev": true, - "license": "Apache-2.0", - "peer": true + "license": "Apache-2.0" }, "node_modules/@yarnpkg/lockfile": { "version": "1.1.0", @@ -4813,6 +4774,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -4837,7 +4799,6 @@ "integrity": "sha512-wKmbr/DDiIXzEOiWrTTUcDm24kQ2vGfZQvM2fwg2vXqR5uW6aapr7ObPtj1th32b9u90/Pf4AItvdTh42fBmVQ==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=10.13.0" }, @@ -4905,7 +4866,6 @@ "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "ajv": "^8.0.0" }, @@ -4924,7 +4884,6 @@ "integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3" }, @@ -5040,6 +4999,7 @@ "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.1.tgz", "integrity": "sha512-hU4EGxxt+j7TQijx1oYdAjw4xuIp1wRQSsbMFwSthCWeBQur1eF+qJ5iQ5sN3Tw8YRzQNKb8jszgBdMDVqwJcw==", "license": "MIT", + "peer": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", @@ -5369,6 +5329,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.19", "caniuse-lite": "^1.0.30001751", @@ -5600,7 +5561,6 @@ "integrity": "sha512-rNjApaLzuwaOTjCiT8lSDdGN1APCiqkChLMJxJPWLunPAt5fy8xgU9/jNOchV84wfIxrA0lRQB7oCT8jrn/wrQ==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=6.0" } @@ -6332,8 +6292,7 @@ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/es-object-atoms": { "version": "1.1.1", @@ -6369,6 +6328,7 @@ "dev": true, "hasInstallScript": true, "license": "MIT", + "peer": true, "bin": { "esbuild": "bin/esbuild" }, @@ -6470,7 +6430,6 @@ "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" @@ -6485,7 +6444,6 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "engines": { "node": ">=4.0" } @@ -6523,7 +6481,6 @@ "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "dependencies": { "estraverse": "^5.2.0" }, @@ -6574,7 +6531,6 @@ "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=0.8.x" } @@ -6717,8 +6673,7 @@ "url": "https://opencollective.com/fastify" } ], - "license": "BSD-3-Clause", - "peer": true + "license": "BSD-3-Clause" }, "node_modules/fastest-levenshtein": { "version": "1.0.16", @@ -7136,8 +7091,7 @@ "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", "dev": true, - "license": "BSD-2-Clause", - "peer": true + "license": "BSD-2-Clause" }, "node_modules/glob/node_modules/brace-expansion": { "version": "1.1.12", @@ -7885,6 +7839,7 @@ "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -7953,24 +7908,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-circus/node_modules/babel-plugin-macros": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz", - "integrity": "sha512-Cg7TFGpIr01vOQNODXOOaGz2NpCU5gl8x1qJFbb6hbZxR7XrcE2vtbAsTAbJ7/xwJtUuJEw8K8Zr/AE0LHlesg==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "@babel/runtime": "^7.12.5", - "cosmiconfig": "^7.0.0", - "resolve": "^1.19.0" - }, - "engines": { - "node": ">=10", - "npm": ">=6" - } - }, "node_modules/jest-circus/node_modules/cosmiconfig": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", @@ -7978,7 +7915,6 @@ "dev": true, "license": "MIT", "optional": true, - "peer": true, "dependencies": { "@types/parse-json": "^4.0.0", "import-fresh": "^3.2.1", @@ -8742,8 +8678,7 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/json5": { "version": "2.2.3", @@ -8906,7 +8841,6 @@ "integrity": "sha512-IWqP2SCPhyVFTBtRcgMHdzlf9ul25NwaFx4wCEH/KjAXuuHY4yNjvPXsBokp8jCB936PyWRaPKUNh8NvylLp2Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=6.11.5" }, @@ -9375,7 +9309,6 @@ "dev": true, "hasInstallScript": true, "license": "MIT", - "peer": true, "dependencies": { "@nrwl/tao": "18.3.5", "@yarnpkg/lockfile": "^1.1.0", @@ -9446,8 +9379,7 @@ "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true, - "license": "Python-2.0", - "peer": true + "license": "Python-2.0" }, "node_modules/nx/node_modules/dotenv": { "version": "16.3.2", @@ -9455,7 +9387,6 @@ "integrity": "sha512-HTlk5nmhkm8F6JcdXvHIzaorzCoziNQT9mGxLPVXW8wJF1TiGSL60ZGB4gHWabHOaMmWmhvk2/lPHfnBiT78AQ==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "engines": { "node": ">=12" }, @@ -9469,7 +9400,6 @@ "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "argparse": "^2.0.1" }, @@ -9483,7 +9413,6 @@ "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", "dev": true, "license": "ISC", - "peer": true, "bin": { "semver": "bin/semver.js" }, @@ -10090,7 +10019,6 @@ "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "safe-buffer": "^5.1.0" } @@ -10261,7 +10189,6 @@ "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=0.10.0" } @@ -10492,7 +10419,6 @@ "integrity": "sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/json-schema": "^7.0.9", "ajv": "^8.9.0", @@ -10546,7 +10472,6 @@ "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, "license": "BSD-3-Clause", - "peer": true, "dependencies": { "randombytes": "^2.1.0" } @@ -11037,7 +10962,6 @@ "integrity": "sha512-nIVck8DK+GM/0Frwd+nIhZ84pR/BX7rmXMfYwyg+Sri5oGVE99/E3KvXqpC2xHFxyqXyGHTKBSioxxplrO4I4w==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.15.0", @@ -11057,7 +10981,6 @@ "integrity": "sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.25", "jest-worker": "^27.4.5", @@ -11093,7 +11016,6 @@ "integrity": "sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*", "merge-stream": "^2.0.0", @@ -11109,7 +11031,6 @@ "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -11125,8 +11046,7 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/terser/node_modules/source-map-support": { "version": "0.5.21", @@ -11134,7 +11054,6 @@ "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -11257,6 +11176,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -11489,6 +11409,7 @@ "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -11707,21 +11628,6 @@ "webidl-conversions": "^4.0.2" } }, - "node_modules/tsup/node_modules/yaml": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.1.tgz", - "integrity": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==", - "dev": true, - "license": "ISC", - "optional": true, - "peer": true, - "bin": { - "yaml": "bin.mjs" - }, - "engines": { - "node": ">= 14.6" - } - }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", @@ -11997,7 +11903,6 @@ "integrity": "sha512-c5EGNOiyxxV5qmTtAB7rbiXxi1ooX1pQKMLX/MIabJjRA0SJBQOjKF+KSVfHkr9U1cADPon0mRiVe/riyaiDUA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" @@ -12082,6 +11987,7 @@ "integrity": "sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@discoveryjs/json-ext": "^0.5.0", "@webpack-cli/configtest": "^2.1.1", @@ -12153,7 +12059,6 @@ "integrity": "sha512-yd1RBzSGanHkitROoPFd6qsrxt+oFhg/129YzheDGqeustzX0vTZJZsSsQjVQC4yzBQ56K55XU8gaNCtIzOnTg==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=10.13.0" } @@ -12164,7 +12069,6 @@ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">= 0.6" } @@ -12175,7 +12079,6 @@ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "mime-db": "1.52.0" }, diff --git a/package.json b/package.json index 893eba3..64d66c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.10.2", + "version": "4.10.3", "type": "module", "license": "MIT", "main": "./dist/legacy/index.cjs", @@ -38,7 +38,7 @@ }, "dependencies": { "@contentstack/core": "^1.3.1", - "@contentstack/utils": "^1.5.0", + "@contentstack/utils": "^1.6.1", "axios": "^1.13.1", "humps": "^2.0.1" }, diff --git a/src/assets/regions.json b/src/assets/regions.json deleted file mode 100644 index 88a4637..0000000 --- a/src/assets/regions.json +++ /dev/null @@ -1,186 +0,0 @@ -{ - "regions": [ - { - "id": "na", - "name": "AWS North America", - "cloudProvider": "AWS", - "location": "North America", - "alias": ["na", "us", "aws-na", "aws_na"], - "isDefault": true, - "endpoints": { - "application": "https://app.contentstack.com", - "contentDelivery": "https://cdn.contentstack.io", - "contentManagement": "https://api.contentstack.io", - "auth": "https://auth-api.contentstack.com", - "graphqlDelivery": "https://graphql.contentstack.com", - "preview": "https://rest-preview.contentstack.com", - "graphqlPreview": "https://graphql-preview.contentstack.com", - "images": "https://images.contentstack.io", - "assets": "https://assets.contentstack.io", - "automate": "https://automations-api.contentstack.com", - "launch": "https://launch-api.contentstack.com", - "developerHub": "https://developerhub-api.contentstack.com", - "brandKit": "https://brand-kits-api.contentstack.com", - "genAI": "https://ai.contentstack.com", - "personalize": "https://personalize-api.contentstack.com", - "personalizeEdge": "https://personalize-edge.contentstack.com" - } - }, - { - "id": "eu", - "name": "AWS Europe", - "cloudProvider": "AWS", - "location": "Europe", - "alias": ["eu", "aws-eu", "aws_eu"], - "isDefault": false, - "endpoints": { - "application": "https://eu-app.contentstack.com", - "contentDelivery": "https://eu-cdn.contentstack.com", - "contentManagement": "https://eu-api.contentstack.com", - "auth": "https://eu-auth-api.contentstack.com", - "graphqlDelivery": "https://eu-graphql.contentstack.com", - "preview": "https://eu-rest-preview.contentstack.com", - "graphqlPreview": "https://eu-graphql-preview.contentstack.com", - "images": "https://eu-images.contentstack.com", - "assets": "https://eu-assets.contentstack.com", - "automate": "https://eu-prod-automations-api.contentstack.com", - "launch": "https://eu-launch-api.contentstack.com", - "developerHub": "https://eu-developerhub-api.contentstack.com", - "brandKit": "https://eu-brand-kits-api.contentstack.com", - "genAI": "https://eu-ai.contentstack.com", - "personalize": "https://eu-personalize-api.contentstack.com", - "personalizeEdge": "https://eu-personalize-edge.contentstack.com" - } - }, - { - "id": "au", - "name": "AWS Australia", - "cloudProvider": "AWS", - "location": "Australia", - "alias": ["au", "aws-au", "aws_au"], - "isDefault": false, - "endpoints": { - "application": "https://au-app.contentstack.com", - "contentDelivery": "https://au-cdn.contentstack.com", - "contentManagement": "https://au-api.contentstack.com", - "auth": "https://au-auth-api.contentstack.com", - "graphqlDelivery": "https://au-graphql.contentstack.com", - "preview": "https://au-rest-preview.contentstack.com", - "graphqlPreview": "https://au-graphql-preview.contentstack.com", - "images": "https://au-images.contentstack.com", - "assets": "https://au-assets.contentstack.com", - "automate": "https://au-prod-automations-api.contentstack.com", - "launch": "https://au-launch-api.contentstack.com", - "developerHub": "https://au-developerhub-api.contentstack.com", - "brandKit": "https://au-brand-kits-api.contentstack.com", - "genAI": "https://au-ai.contentstack.com", - "personalize": "https://au-personalize-api.contentstack.com", - "personalizeEdge": "https://au-personalize-edge.contentstack.com" - } - }, - { - "id": "azure-na", - "name": "Azure North America", - "cloudProvider": "Azure", - "location": "North America", - "alias": ["azure-na", "azure_na"], - "isDefault": false, - "endpoints": { - "application": "https://azure-na-app.contentstack.com", - "contentDelivery": "https://azure-na-cdn.contentstack.com", - "contentManagement": "https://azure-na-api.contentstack.com", - "auth": "https://azure-na-auth-api.contentstack.com", - "graphqlDelivery": "https://azure-na-graphql.contentstack.com", - "preview": "https://azure-na-rest-preview.contentstack.com", - "graphqlPreview": "https://azure-na-graphql-preview.contentstack.com", - "images": "https://azure-na-images.contentstack.com", - "assets": "https://azure-na-assets.contentstack.com", - "automate": "https://azure-na-automations-api.contentstack.com", - "launch": "https://azure-na-launch-api.contentstack.com", - "developerHub": "https://azure-na-developerhub-api.contentstack.com", - "brandKit": "https://azure-na-brand-kits-api.contentstack.com", - "genAI": "https://azure-na-ai.contentstack.com", - "personalize": "https://azure-na-personalize-api.contentstack.com", - "personalizeEdge": "https://azure-na-personalize-edge.contentstack.com" - } - }, - { - "id": "azure-eu", - "name": "Azure Europe", - "cloudProvider": "Azure", - "location": "Europe", - "alias": ["azure-eu", "azure_eu"], - "isDefault": false, - "endpoints": { - "application": "https://azure-eu-app.contentstack.com", - "contentDelivery": "https://azure-eu-cdn.contentstack.com", - "contentManagement": "https://azure-eu-api.contentstack.com", - "auth": "https://azure-eu-auth-api.contentstack.com", - "graphqlDelivery": "https://azure-eu-graphql.contentstack.com", - "preview": "https://azure-eu-rest-preview.contentstack.com", - "graphqlPreview": "https://azure-eu-graphql-preview.contentstack.com", - "images": "https://azure-eu-images.contentstack.com", - "assets": "https://azure-eu-assets.contentstack.com", - "automate": "https://azure-eu-automations-api.contentstack.com", - "launch": "https://azure-eu-launch-api.contentstack.com", - "developerHub": "https://azure-eu-developerhub-api.contentstack.com", - "brandKit": "https://azure-eu-brand-kits-api.contentstack.com", - "genAI": "https://azure-eu-ai.contentstack.com", - "personalize": "https://azure-eu-personalize-api.contentstack.com", - "personalizeEdge": "https://azure-eu-personalize-edge.contentstack.com" - } - }, - { - "id": "gcp-na", - "name": "GCP North America", - "cloudProvider": "GCP", - "location": "North America", - "alias": ["gcp-na", "gcp_na"], - "isDefault": false, - "endpoints": { - "application": "https://gcp-na-app.contentstack.com", - "contentDelivery": "https://gcp-na-cdn.contentstack.com", - "contentManagement": "https://gcp-na-api.contentstack.com", - "auth": "https://gcp-na-auth-api.contentstack.com", - "graphqlDelivery": "https://gcp-na-graphql.contentstack.com", - "preview": "https://gcp-na-rest-preview.contentstack.com", - "graphqlPreview": "https://gcp-na-graphql-preview.contentstack.com", - "images": "https://gcp-na-images.contentstack.com", - "assets": "https://gcp-na-assets.contentstack.com", - "automate": "https://gcp-na-automations-api.contentstack.com", - "launch": "https://gcp-na-launch-api.contentstack.com", - "developerHub": "https://gcp-na-developerhub-api.contentstack.com", - "brandKit": "https://gcp-na-brand-kits-api.contentstack.com", - "genAI": "https://gcp-na-brand-kits-api.contentstack.com", - "personalize": "https://gcp-na-personalize-api.contentstack.com", - "personalizeEdge": "https://gcp-na-personalize-edge.contentstack.com" - } - }, - { - "id": "gcp-eu", - "name": "GCP Europe", - "cloudProvider": "GCP", - "location": "Europe", - "alias": ["gcp-eu", "gcp_eu"], - "isDefault": false, - "endpoints": { - "application": "https://gcp-eu-app.contentstack.com", - "contentDelivery": "https://gcp-eu-cdn.contentstack.com", - "contentManagement": "https://gcp-eu-api.contentstack.com", - "auth": "https://gcp-eu-auth-api.contentstack.com", - "graphqlDelivery": "https://gcp-eu-graphql.contentstack.com", - "preview": "https://gcp-eu-rest-preview.contentstack.com", - "graphqlPreview": "https://gcp-eu-graphql-preview.contentstack.com", - "images": "https://gcp-eu-images.contentstack.com", - "assets": "https://gcp-eu-assets.contentstack.com", - "automate": "https://gcp-eu-automations-api.contentstack.com", - "launch": "https://gcp-eu-launch-api.contentstack.com", - "developerHub": "https://gcp-eu-developerhub-api.contentstack.com", - "brandKit": "https://gcp-eu-brand-kits-api.contentstack.com", - "genAI": "https://gcp-eu-brand-kits-api.contentstack.com", - "personalize": "https://gcp-eu-personalize-api.contentstack.com", - "personalizeEdge": "https://gcp-eu-personalize-edge.contentstack.com" - } - } - ] -} diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index bce199b..e8370b8 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -1,5 +1,5 @@ import { httpClient, retryRequestHandler, retryResponseErrorHandler, retryResponseHandler } from '@contentstack/core'; -import { AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios'; +import { AxiosRequestHeaders } from 'axios'; import { handleRequest } from './cache'; import { Stack as StackClass } from './stack'; import { Policy, StackConfig, ContentstackPlugin } from './types'; @@ -34,7 +34,7 @@ let version = '{{VERSION}}'; */ // eslint-disable-next-line @typescript-eslint/naming-convention export function stack(config: StackConfig): StackClass { - const DEFAULT_HOST = Utility.getHostforRegion(config.region, config.host); + const DEFAULT_HOST = Utility.getHostforRegion(config.region || "", config.host); let defaultConfig = { defaultHostname: DEFAULT_HOST, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 43d4892..341e1de 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,26 +1,10 @@ import { Region, params } from './types'; -import regionsData from '../assets/regions.json'; +import { getContentstackEndpoint } from '@contentstack/utils'; -export function getHostforRegion(cloudRegion: string = "aws_na", host?: string): string { +export function getHostforRegion(region: string = "aws_na", host?: string): string { if (host) return host; - // Handle null, undefined, or empty string cases - if (!cloudRegion || typeof cloudRegion !== 'string') { - throw new Error("Unable to set host using the provided region. Please provide a valid region."); - } - - const normalizedRegion = cloudRegion.toLowerCase(); - - const regionObj = regionsData.regions.find(r => - r.id === normalizedRegion || - r.alias.some(alias => alias === normalizedRegion) - ); - - if (!regionObj) { - throw new Error("Unable to set host using the provided region. Please provide a valid region."); - } - - return regionObj ? regionObj.endpoints.contentDelivery.replace(/^https?:\/\//, '') : 'cdn.contentstack.io'; + return getContentstackEndpoint(region, 'contentDelivery', true) as string; } export function isBrowser() { From ea7f79a35576ba198b4f2abf2222e091948acca1 Mon Sep 17 00:00:00 2001 From: Nadeem Patwekar Date: Wed, 12 Nov 2025 11:44:16 +0530 Subject: [PATCH 2/2] fix: update default region handling in stack function and improve error messages for invalid regions --- src/lib/contentstack.ts | 2 +- test/unit/contentstack.spec.ts | 3 ++- test/unit/stack.spec.ts | 2 +- test/unit/utils.spec.ts | 12 ++++++------ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib/contentstack.ts b/src/lib/contentstack.ts index e8370b8..837b99d 100644 --- a/src/lib/contentstack.ts +++ b/src/lib/contentstack.ts @@ -34,7 +34,7 @@ let version = '{{VERSION}}'; */ // eslint-disable-next-line @typescript-eslint/naming-convention export function stack(config: StackConfig): StackClass { - const DEFAULT_HOST = Utility.getHostforRegion(config.region || "", config.host); + const DEFAULT_HOST = Utility.getHostforRegion(config.region || "aws_na", config.host); let defaultConfig = { defaultHostname: DEFAULT_HOST, diff --git a/test/unit/contentstack.spec.ts b/test/unit/contentstack.spec.ts index 7a8fe02..6cc48e6 100644 --- a/test/unit/contentstack.spec.ts +++ b/test/unit/contentstack.spec.ts @@ -396,7 +396,8 @@ describe("Contentstack", () => { const stackInstance = createStackInstance(config); - expect(getHostforRegionSpy).toHaveBeenCalledWith(undefined, undefined); + // When no region is provided, the default parameter "aws_na" is used + expect(getHostforRegionSpy).toHaveBeenCalledWith("aws_na", undefined); expect(stackInstance).toBeInstanceOf(Stack); getHostforRegionSpy.mockRestore(); diff --git a/test/unit/stack.spec.ts b/test/unit/stack.spec.ts index abc1e89..b154f0e 100644 --- a/test/unit/stack.spec.ts +++ b/test/unit/stack.spec.ts @@ -285,7 +285,7 @@ describe('Stack class tests', () => { it('should throw error for invalid region', async () => { await expect(stack.setHost('invalid_region')).rejects.toThrow( - 'Unable to set host using the provided region. Please provide a valid region.' + 'Invalid region: invalid_region' ); }); diff --git a/test/unit/utils.spec.ts b/test/unit/utils.spec.ts index 1703b10..3b27611 100644 --- a/test/unit/utils.spec.ts +++ b/test/unit/utils.spec.ts @@ -118,19 +118,19 @@ describe("Utils functions", () => { it("should throw error for invalid region", () => { expect(() => getHostforRegion("invalid_region")).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "Invalid region: invalid_region" ); }); it("should throw error for empty string region", () => { expect(() => getHostforRegion("")).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "Empty region provided. Please put valid region." ); }); it("should throw error for null region", () => { expect(() => getHostforRegion(null as any)).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "Cannot read properties of null (reading 'toLowerCase')" ); }); @@ -142,15 +142,15 @@ describe("Utils functions", () => { it("should throw error for non-string region types", () => { expect(() => getHostforRegion(123 as any)).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "region.toLowerCase is not a function" ); expect(() => getHostforRegion({} as any)).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "region.toLowerCase is not a function" ); expect(() => getHostforRegion([] as any)).toThrow( - "Unable to set host using the provided region. Please provide a valid region." + "region.toLowerCase is not a function" ); });