diff --git a/.talismanrc b/.talismanrc index de4bcea..fe7d1d2 100644 --- a/.talismanrc +++ b/.talismanrc @@ -3,7 +3,7 @@ fileignoreconfig: ignore_detectors: - filecontent - filename: package-lock.json - checksum: 2e59256a4223df4fa670d9bedb571586daa21e59194400b8f9aa4725d378cc72 + checksum: c447ed3d22eef9d2b26b9ae85370de31be04cc94da0af506ada0025bc7a9bbb6 - filename: .husky/pre-commit checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193 - filename: src/graphqlTS/index.ts diff --git a/package-lock.json b/package-lock.json index 1ea032b..7bdf0eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@contentstack/types-generator", - "version": "3.6.0", + "version": "3.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/types-generator", - "version": "3.6.0", + "version": "3.7.0", "license": "MIT", "dependencies": { - "@contentstack/cli-utilities": "^1.13.0", + "@contentstack/cli-utilities": "^1.13.1", "@contentstack/delivery-sdk": "^4.8.0", "@gql2ts/from-schema": "^2.0.0-4", "async": "^3.2.6", @@ -28,7 +28,7 @@ "husky": "^9.1.7", "jest": "^29.7.0", "nock": "^13.5.6", - "rollup": "^4.46.2", + "rollup": "^4.48.0", "ts-jest": "^29.4.0", "tsup": "^8.5.0", "typescript": "^5.7.3" @@ -74,22 +74,22 @@ } }, "node_modules/@babel/core": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.0.tgz", - "integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.3.tgz", + "integrity": "sha512-yDBHV9kQNcr2/sUr9jghVyz9C3Y5G2zUM2H2lo+9mKv4sFgbA8s8Z9t8D1jiTkGoO/NoIfKMyKWr4s6CN23ZwQ==", "dev": true, "license": "MIT", "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.27.1", - "@babel/generator": "^7.28.0", + "@babel/generator": "^7.28.3", "@babel/helper-compilation-targets": "^7.27.2", - "@babel/helper-module-transforms": "^7.27.3", - "@babel/helpers": "^7.27.6", - "@babel/parser": "^7.28.0", + "@babel/helper-module-transforms": "^7.28.3", + "@babel/helpers": "^7.28.3", + "@babel/parser": "^7.28.3", "@babel/template": "^7.27.2", - "@babel/traverse": "^7.28.0", - "@babel/types": "^7.28.0", + "@babel/traverse": "^7.28.3", + "@babel/types": "^7.28.2", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -115,14 +115,14 @@ } }, "node_modules/@babel/generator": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.0.tgz", - "integrity": "sha512-lJjzvrbEeWrhB4P3QBsH7tey117PjLZnDbLiQEKjQ/fNJTjuq4HSqgFA+UNSwZT8D7dxxbnuSBMsa1lrWzKlQg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.3.tgz", + "integrity": "sha512-3lSpxGgvnmZznmBkCRnVREPUFJv2wrv9iAoFDvADJc0ypmdOxdUtcLeBgBJ6zE0PMeTKnxeQzyk0xTBq4Ep7zw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/parser": "^7.28.0", - "@babel/types": "^7.28.0", + "@babel/parser": "^7.28.3", + "@babel/types": "^7.28.2", "@jridgewell/gen-mapping": "^0.3.12", "@jridgewell/trace-mapping": "^0.3.28", "jsesc": "^3.0.2" @@ -183,15 +183,15 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.27.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.27.3.tgz", - "integrity": "sha512-dSOvYwvyLsWBeIRyOeHXp5vPj5l1I011r52FM1+r1jCERv+aFXYk4whgQccYEGYxK2H3ZAIA8nuPkQ0HaUo3qg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.28.3.tgz", + "integrity": "sha512-gytXUbs8k2sXS9PnQptz5o0QnpLL51SwASIORY6XaBKF88nsOT0Zw9szLqlSGQDP/4TljBAD5y98p2U1fqkdsw==", "dev": true, "license": "MIT", "dependencies": { "@babel/helper-module-imports": "^7.27.1", "@babel/helper-validator-identifier": "^7.27.1", - "@babel/traverse": "^7.27.3" + "@babel/traverse": "^7.28.3" }, "engines": { "node": ">=6.9.0" @@ -241,9 +241,9 @@ } }, "node_modules/@babel/helpers": { - "version": "7.28.2", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.2.tgz", - "integrity": "sha512-/V9771t+EgXz62aCcyofnQhGM8DQACbRhvzKFsXKC9QM+5MadF8ZmIm0crDMaz3+o0h0zXfJnd4EhbYbxsrcFw==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.28.3.tgz", + "integrity": "sha512-PTNtvUQihsAsDHMOP5pfobP8C6CM4JWXmP8DrEIt46c3r2bf87Ua1zoqevsMo9g+tWDwgWrFP5EIxuBx5RudAw==", "dev": true, "license": "MIT", "dependencies": { @@ -255,13 +255,13 @@ } }, "node_modules/@babel/parser": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.0.tgz", - "integrity": "sha512-jVZGvOxOuNSsuQuLRTh13nU0AogFlw32w/MT+LV6D3sP5WdbW61E77RnkbaO2dUvmPAYrBDJXGn5gGS6tH4j8g==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.28.3.tgz", + "integrity": "sha512-7+Ey1mAgYqFAx2h0RuoxcQT5+MlG3GTV0TQrgr7/ZliKsm/MNDxVVutlWaziMq7wJNAz8MTqz55XLpWvva6StA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.28.0" + "@babel/types": "^7.28.2" }, "bin": { "parser": "bin/babel-parser.js" @@ -525,18 +525,18 @@ } }, "node_modules/@babel/traverse": { - "version": "7.28.0", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.0.tgz", - "integrity": "sha512-mGe7UK5wWyh0bKRfupsUchrQGqvDbZDbKJw+kcRGSmdHVYrv+ltd0pnpDTVpiTqnaBru9iEvA8pz8W46v0Amwg==", + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.28.3.tgz", + "integrity": "sha512-7w4kZYHneL3A6NP2nxzHvT3HCZ7puDZZjFMqDpBPECub79sTtSO5CGXDkKrTQq8ksAwfD/XI2MRFX23njdDaIQ==", "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.27.1", - "@babel/generator": "^7.28.0", + "@babel/generator": "^7.28.3", "@babel/helper-globals": "^7.28.0", - "@babel/parser": "^7.28.0", + "@babel/parser": "^7.28.3", "@babel/template": "^7.27.2", - "@babel/types": "^7.28.0", + "@babel/types": "^7.28.2", "debug": "^4.3.1" }, "engines": { @@ -611,9 +611,9 @@ } }, "node_modules/@contentstack/core": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.2.3.tgz", - "integrity": "sha512-fAS4whkybRs0/KE/ENaXenl8LeMxR+wtwM1MbGWwyWTN0kfcGf5jRONH8e++qidJqjHe7JhfOZXVXc3I0RQEVQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@contentstack/core/-/core-1.2.4.tgz", + "integrity": "sha512-GTXaoJN/TU8rhfioVK8OKCbQ/hSpz34RLJ7CjGtvIvFrwIHwaVtQ1tu0DK31qWxk3GZ8J4O6Q85sqAFr29DO7w==", "license": "MIT", "dependencies": { "axios": "^1.11.0", @@ -638,14 +638,14 @@ } }, "node_modules/@contentstack/delivery-sdk": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/@contentstack/delivery-sdk/-/delivery-sdk-4.8.0.tgz", - "integrity": "sha512-XDXCl6rzA77hZ8i4K6x83eFUpXjnTB7eIKFcbXRuJ/dky+ZktoZEE/ld2uIry2DsI19cW9quSwAj62wPxqTASA==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/@contentstack/delivery-sdk/-/delivery-sdk-4.8.1.tgz", + "integrity": "sha512-ZQwgX70U6KPAOTNXNXfiujxM1MxEg0bGs+0PlG1q72EeGFMzBUbOVyQLCNKKVxhUfaoKVtzrTePG5l1wZilJRw==", "license": "MIT", "dependencies": { - "@contentstack/core": "^1.2.0", - "@contentstack/utils": "^1.4.0", - "axios": "^1.8.4", + "@contentstack/core": "^1.2.4", + "@contentstack/utils": "^1.4.1", + "axios": "^1.11.0", "humps": "^2.0.1" } }, @@ -1189,9 +1189,9 @@ } }, "node_modules/@isaacs/cliui/node_modules/ansi-regex": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", - "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.0.tgz", + "integrity": "sha512-TKY5pyBkHyADOPYlRT9Lx6F544mPl0vS5Ew7BJ45hA08Q+t3GjbueLliBWN3sMICk6+y7HdyxSzC4bWS8baBdg==", "dev": true, "license": "MIT", "engines": { @@ -1696,9 +1696,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.46.2.tgz", - "integrity": "sha512-Zj3Hl6sN34xJtMv7Anwb5Gu01yujyE/cLBDB2gnHTAHaWS1Z38L7kuSG+oAh0giZMqG060f/YBStXtMH6FvPMA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.48.0.tgz", + "integrity": "sha512-aVzKH922ogVAWkKiyKXorjYymz2084zrhrZRXtLrA5eEx5SO8Dj0c/4FpCHZyn7MKzhW2pW4tK28vVr+5oQ2xw==", "cpu": [ "arm" ], @@ -1710,9 +1710,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.46.2.tgz", - "integrity": "sha512-nTeCWY83kN64oQ5MGz3CgtPx8NSOhC5lWtsjTs+8JAJNLcP3QbLCtDDgUKQc/Ro/frpMq4SHUaHN6AMltcEoLQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.48.0.tgz", + "integrity": "sha512-diOdQuw43xTa1RddAFbhIA8toirSzFMcnIg8kvlzRbK26xqEnKJ/vqQnghTAajy2Dcy42v+GMPMo6jq67od+Dw==", "cpu": [ "arm64" ], @@ -1724,9 +1724,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.46.2.tgz", - "integrity": "sha512-HV7bW2Fb/F5KPdM/9bApunQh68YVDU8sO8BvcW9OngQVN3HHHkw99wFupuUJfGR9pYLLAjcAOA6iO+evsbBaPQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.48.0.tgz", + "integrity": "sha512-QhR2KA18fPlJWFefySJPDYZELaVqIUVnYgAOdtJ+B/uH96CFg2l1TQpX19XpUMWUqMyIiyY45wje8K6F4w4/CA==", "cpu": [ "arm64" ], @@ -1738,9 +1738,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.46.2.tgz", - "integrity": "sha512-SSj8TlYV5nJixSsm/y3QXfhspSiLYP11zpfwp6G/YDXctf3Xkdnk4woJIF5VQe0of2OjzTt8EsxnJDCdHd2xMA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.48.0.tgz", + "integrity": "sha512-Q9RMXnQVJ5S1SYpNSTwXDpoQLgJ/fbInWOyjbCnnqTElEyeNvLAB3QvG5xmMQMhFN74bB5ZZJYkKaFPcOG8sGg==", "cpu": [ "x64" ], @@ -1752,9 +1752,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.46.2.tgz", - "integrity": "sha512-ZyrsG4TIT9xnOlLsSSi9w/X29tCbK1yegE49RYm3tu3wF1L/B6LVMqnEWyDB26d9Ecx9zrmXCiPmIabVuLmNSg==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.48.0.tgz", + "integrity": "sha512-3jzOhHWM8O8PSfyft+ghXZfBkZawQA0PUGtadKYxFqpcYlOYjTi06WsnYBsbMHLawr+4uWirLlbhcYLHDXR16w==", "cpu": [ "arm64" ], @@ -1766,9 +1766,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.46.2.tgz", - "integrity": "sha512-pCgHFoOECwVCJ5GFq8+gR8SBKnMO+xe5UEqbemxBpCKYQddRQMgomv1104RnLSg7nNvgKy05sLsY51+OVRyiVw==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.48.0.tgz", + "integrity": "sha512-NcD5uVUmE73C/TPJqf78hInZmiSBsDpz3iD5MF/BuB+qzm4ooF2S1HfeTChj5K4AV3y19FFPgxonsxiEpy8v/A==", "cpu": [ "x64" ], @@ -1780,9 +1780,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.46.2.tgz", - "integrity": "sha512-EtP8aquZ0xQg0ETFcxUbU71MZlHaw9MChwrQzatiE8U/bvi5uv/oChExXC4mWhjiqK7azGJBqU0tt5H123SzVA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.48.0.tgz", + "integrity": "sha512-JWnrj8qZgLWRNHr7NbpdnrQ8kcg09EBBq8jVOjmtlB3c8C6IrynAJSMhMVGME4YfTJzIkJqvSUSVJRqkDnu/aA==", "cpu": [ "arm" ], @@ -1794,9 +1794,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.46.2.tgz", - "integrity": "sha512-qO7F7U3u1nfxYRPM8HqFtLd+raev2K137dsV08q/LRKRLEc7RsiDWihUnrINdsWQxPR9jqZ8DIIZ1zJJAm5PjQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.48.0.tgz", + "integrity": "sha512-9xu92F0TxuMH0tD6tG3+GtngwdgSf8Bnz+YcsPG91/r5Vgh5LNofO48jV55priA95p3c92FLmPM7CvsVlnSbGQ==", "cpu": [ "arm" ], @@ -1808,9 +1808,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.46.2.tgz", - "integrity": "sha512-3dRaqLfcOXYsfvw5xMrxAk9Lb1f395gkoBYzSFcc/scgRFptRXL9DOaDpMiehf9CO8ZDRJW2z45b6fpU5nwjng==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.48.0.tgz", + "integrity": "sha512-NLtvJB5YpWn7jlp1rJiY0s+G1Z1IVmkDuiywiqUhh96MIraC0n7XQc2SZ1CZz14shqkM+XN2UrfIo7JB6UufOA==", "cpu": [ "arm64" ], @@ -1822,9 +1822,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.46.2.tgz", - "integrity": "sha512-fhHFTutA7SM+IrR6lIfiHskxmpmPTJUXpWIsBXpeEwNgZzZZSg/q4i6FU4J8qOGyJ0TR+wXBwx/L7Ho9z0+uDg==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.48.0.tgz", + "integrity": "sha512-QJ4hCOnz2SXgCh+HmpvZkM+0NSGcZACyYS8DGbWn2PbmA0e5xUk4bIP8eqJyNXLtyB4gZ3/XyvKtQ1IFH671vQ==", "cpu": [ "arm64" ], @@ -1836,9 +1836,9 @@ ] }, "node_modules/@rollup/rollup-linux-loongarch64-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.46.2.tgz", - "integrity": "sha512-i7wfGFXu8x4+FRqPymzjD+Hyav8l95UIZ773j7J7zRYc3Xsxy2wIn4x+llpunexXe6laaO72iEjeeGyUFmjKeA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.48.0.tgz", + "integrity": "sha512-Pk0qlGJnhILdIC5zSKQnprFjrGmjfDM7TPZ0FKJxRkoo+kgMRAg4ps1VlTZf8u2vohSicLg7NP+cA5qE96PaFg==", "cpu": [ "loong64" ], @@ -1850,9 +1850,9 @@ ] }, "node_modules/@rollup/rollup-linux-ppc64-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.46.2.tgz", - "integrity": "sha512-B/l0dFcHVUnqcGZWKcWBSV2PF01YUt0Rvlurci5P+neqY/yMKchGU8ullZvIv5e8Y1C6wOn+U03mrDylP5q9Yw==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.48.0.tgz", + "integrity": "sha512-/dNFc6rTpoOzgp5GKoYjT6uLo8okR/Chi2ECOmCZiS4oqh3mc95pThWma7Bgyk6/WTEvjDINpiBCuecPLOgBLQ==", "cpu": [ "ppc64" ], @@ -1864,9 +1864,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.46.2.tgz", - "integrity": "sha512-32k4ENb5ygtkMwPMucAb8MtV8olkPT03oiTxJbgkJa7lJ7dZMr0GCFJlyvy+K8iq7F/iuOr41ZdUHaOiqyR3iQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.48.0.tgz", + "integrity": "sha512-YBwXsvsFI8CVA4ej+bJF2d9uAeIiSkqKSPQNn0Wyh4eMDY4wxuSp71BauPjQNCKK2tD2/ksJ7uhJ8X/PVY9bHQ==", "cpu": [ "riscv64" ], @@ -1878,9 +1878,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-musl": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.46.2.tgz", - "integrity": "sha512-t5B2loThlFEauloaQkZg9gxV05BYeITLvLkWOkRXogP4qHXLkWSbSHKM9S6H1schf/0YGP/qNKtiISlxvfmmZw==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.48.0.tgz", + "integrity": "sha512-FI3Rr2aGAtl1aHzbkBIamsQyuauYtTF9SDUJ8n2wMXuuxwchC3QkumZa1TEXYIv/1AUp1a25Kwy6ONArvnyeVQ==", "cpu": [ "riscv64" ], @@ -1892,9 +1892,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.46.2.tgz", - "integrity": "sha512-YKjekwTEKgbB7n17gmODSmJVUIvj8CX7q5442/CK80L8nqOUbMtf8b01QkG3jOqyr1rotrAnW6B/qiHwfcuWQA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.48.0.tgz", + "integrity": "sha512-Dx7qH0/rvNNFmCcIRe1pyQ9/H0XO4v/f0SDoafwRYwc2J7bJZ5N4CHL/cdjamISZ5Cgnon6iazAVRFlxSoHQnQ==", "cpu": [ "s390x" ], @@ -1906,9 +1906,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.46.2.tgz", - "integrity": "sha512-Jj5a9RUoe5ra+MEyERkDKLwTXVu6s3aACP51nkfnK9wJTraCC8IMe3snOfALkrjTYd2G1ViE1hICj0fZ7ALBPA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.48.0.tgz", + "integrity": "sha512-GUdZKTeKBq9WmEBzvFYuC88yk26vT66lQV8D5+9TgkfbewhLaTHRNATyzpQwwbHIfJvDJ3N9WJ90wK/uR3cy3Q==", "cpu": [ "x64" ], @@ -1920,9 +1920,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.46.2.tgz", - "integrity": "sha512-7kX69DIrBeD7yNp4A5b81izs8BqoZkCIaxQaOpumcJ1S/kmqNFjPhDu1LHeVXv0SexfHQv5cqHsxLOjETuqDuA==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.48.0.tgz", + "integrity": "sha512-ao58Adz/v14MWpQgYAb4a4h3fdw73DrDGtaiF7Opds5wNyEQwtO6M9dBh89nke0yoZzzaegq6J/EXs7eBebG8A==", "cpu": [ "x64" ], @@ -1934,9 +1934,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.46.2.tgz", - "integrity": "sha512-wiJWMIpeaak/jsbaq2HMh/rzZxHVW1rU6coyeNNpMwk5isiPjSTx0a4YLSlYDwBH/WBvLz+EtsNqQScZTLJy3g==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.48.0.tgz", + "integrity": "sha512-kpFno46bHtjZVdRIOxqaGeiABiToo2J+st7Yce+aiAoo1H0xPi2keyQIP04n2JjDVuxBN6bSz9R6RdTK5hIppw==", "cpu": [ "arm64" ], @@ -1948,9 +1948,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.46.2.tgz", - "integrity": "sha512-gBgaUDESVzMgWZhcyjfs9QFK16D8K6QZpwAaVNJxYDLHWayOta4ZMjGm/vsAEy3hvlS2GosVFlBlP9/Wb85DqQ==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.48.0.tgz", + "integrity": "sha512-rFYrk4lLk9YUTIeihnQMiwMr6gDhGGSbWThPEDfBoU/HdAtOzPXeexKi7yU8jO+LWRKnmqPN9NviHQf6GDwBcQ==", "cpu": [ "ia32" ], @@ -1962,9 +1962,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.46.2.tgz", - "integrity": "sha512-CvUo2ixeIQGtF6WvuB87XWqPQkoFAFqW+HUo/WzHwuHDvIwZCtjdWXoYCcr06iKGydiqTclC4jU/TNObC/xKZg==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.48.0.tgz", + "integrity": "sha512-sq0hHLTgdtwOPDB5SJOuaoHyiP1qSwg+71TQWk8iDS04bW1wIE0oQ6otPiRj2ZvLYNASLMaTp8QRGUVZ+5OL5A==", "cpu": [ "x64" ], @@ -2117,9 +2117,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "20.19.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.10.tgz", - "integrity": "sha512-iAFpG6DokED3roLSP0K+ybeDdIX6Bc0Vd3mLW5uDqThPWtNos3E+EqOM11mPQHKzfWHqEBuLjIlsBQQ8CsISmQ==", + "version": "20.19.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.11.tgz", + "integrity": "sha512-uug3FEEGv0r+jrecvUUpbY8lLisvIjg6AAic6a2bSP5OEOLeJsDSnvhCDov7ipFFMXS3orMpzlmi0ZcuGkBbow==", "dev": true, "license": "MIT", "dependencies": { @@ -2634,9 +2634,9 @@ } }, "node_modules/browserslist": { - "version": "4.25.2", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.2.tgz", - "integrity": "sha512-0si2SJK3ooGzIawRu61ZdPCO1IncZwS8IzuX73sPZsXW6EQ/w/DAfPyKI8l1ETTCr2MnvqWitmlCUxgdul45jA==", + "version": "4.25.3", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.3.tgz", + "integrity": "sha512-cDGv1kkDI4/0e5yON9yM5G/0A5u8sf5TnmdX5C9qHzI9PPu++sQ9zjm1k9NiOrf3riY4OkK0zSGqfvJyJsgCBQ==", "dev": true, "funding": [ { @@ -2654,8 +2654,8 @@ ], "license": "MIT", "dependencies": { - "caniuse-lite": "^1.0.30001733", - "electron-to-chromium": "^1.5.199", + "caniuse-lite": "^1.0.30001735", + "electron-to-chromium": "^1.5.204", "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.3" }, @@ -2813,9 +2813,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001735", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001735.tgz", - "integrity": "sha512-EV/laoX7Wq2J9TQlyIXRxTJqIw4sxfXS4OYgudGxBYRuTv0q7AM6yMEpU/Vo1I94thg9U6EZ2NfZx9GJq83u7w==", + "version": "1.0.30001737", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001737.tgz", + "integrity": "sha512-BiloLiXtQNrY5UyF0+1nSJLXUENuhka2pzy2Fx5pGxqavdrxSCW4U6Pn/PoG3Efspi2frRbHpBV2XsrPE6EDlw==", "dev": true, "funding": [ { @@ -3531,9 +3531,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.200", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.200.tgz", - "integrity": "sha512-rFCxROw7aOe4uPTfIAx+rXv9cEcGx+buAF4npnhtTqCJk5KDFRnh3+KYj7rdVh6lsFt5/aPs+Irj9rZ33WMA7w==", + "version": "1.5.208", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.208.tgz", + "integrity": "sha512-ozZyibehoe7tOhNaf16lKmljVf+3npZcJIEbJRVftVsmAg5TeA1mGS9dVCZzOwr2xT7xK15V0p7+GZqSPgkuPg==", "dev": true, "license": "ISC" }, @@ -5717,9 +5717,9 @@ } }, "node_modules/istanbul-reports": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.7.tgz", - "integrity": "sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.2.0.tgz", + "integrity": "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==", "dev": true, "license": "BSD-3-Clause", "dependencies": { @@ -6573,13 +6573,13 @@ } }, "node_modules/magic-string": { - "version": "0.30.17", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", - "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", + "version": "0.30.18", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.18.tgz", + "integrity": "sha512-yi8swmWbO17qHhwIBNeeZxTceJMeBvWJaId6dyvTSOwTipqeHhMhOrz6513r1sOKnpvQ7zkhlG8tPrpilwTxHQ==", "dev": true, "license": "MIT", "dependencies": { - "@jridgewell/sourcemap-codec": "^1.5.0" + "@jridgewell/sourcemap-codec": "^1.5.5" } }, "node_modules/make-dir": { @@ -6732,16 +6732,16 @@ } }, "node_modules/mlly": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.7.4.tgz", - "integrity": "sha512-qmdSIPC4bDJXgZTCR7XosJiNKySV7O215tsPtDN9iEO/7q/76b/ijtgRu/+epFXSJhijtTCCGp3DWS549P3xKw==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.0.tgz", + "integrity": "sha512-l8D9ODSRWLe2KHJSifWGwBqpTZXIXTeo8mlKjY+E2HAakaTeNpqAyBZ8GSqLzHgw4XmHmC8whvpjJNMbFZN7/g==", "dev": true, "license": "MIT", "dependencies": { - "acorn": "^8.14.0", - "pathe": "^2.0.1", - "pkg-types": "^1.3.0", - "ufo": "^1.5.4" + "acorn": "^8.15.0", + "pathe": "^2.0.3", + "pkg-types": "^1.3.1", + "ufo": "^1.6.1" } }, "node_modules/ms": { @@ -7685,9 +7685,9 @@ } }, "node_modules/rollup": { - "version": "4.46.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.46.2.tgz", - "integrity": "sha512-WMmLFI+Boh6xbop+OAGo9cQ3OgX9MIg7xOQjn+pTCwOkk+FNDAeAemXkJ3HzDJrVXleLOFVa1ipuc1AmEx1Dwg==", + "version": "4.48.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.48.0.tgz", + "integrity": "sha512-BXHRqK1vyt9XVSEHZ9y7xdYtuYbwVod2mLwOMFP7t/Eqoc1pHRlG/WdV2qNeNvZHRQdLedaFycljaYYM96RqJQ==", "dev": true, "license": "MIT", "dependencies": { @@ -7701,26 +7701,26 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.46.2", - "@rollup/rollup-android-arm64": "4.46.2", - "@rollup/rollup-darwin-arm64": "4.46.2", - "@rollup/rollup-darwin-x64": "4.46.2", - "@rollup/rollup-freebsd-arm64": "4.46.2", - "@rollup/rollup-freebsd-x64": "4.46.2", - "@rollup/rollup-linux-arm-gnueabihf": "4.46.2", - "@rollup/rollup-linux-arm-musleabihf": "4.46.2", - "@rollup/rollup-linux-arm64-gnu": "4.46.2", - "@rollup/rollup-linux-arm64-musl": "4.46.2", - "@rollup/rollup-linux-loongarch64-gnu": "4.46.2", - "@rollup/rollup-linux-ppc64-gnu": "4.46.2", - "@rollup/rollup-linux-riscv64-gnu": "4.46.2", - "@rollup/rollup-linux-riscv64-musl": "4.46.2", - "@rollup/rollup-linux-s390x-gnu": "4.46.2", - "@rollup/rollup-linux-x64-gnu": "4.46.2", - "@rollup/rollup-linux-x64-musl": "4.46.2", - "@rollup/rollup-win32-arm64-msvc": "4.46.2", - "@rollup/rollup-win32-ia32-msvc": "4.46.2", - "@rollup/rollup-win32-x64-msvc": "4.46.2", + "@rollup/rollup-android-arm-eabi": "4.48.0", + "@rollup/rollup-android-arm64": "4.48.0", + "@rollup/rollup-darwin-arm64": "4.48.0", + "@rollup/rollup-darwin-x64": "4.48.0", + "@rollup/rollup-freebsd-arm64": "4.48.0", + "@rollup/rollup-freebsd-x64": "4.48.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.48.0", + "@rollup/rollup-linux-arm-musleabihf": "4.48.0", + "@rollup/rollup-linux-arm64-gnu": "4.48.0", + "@rollup/rollup-linux-arm64-musl": "4.48.0", + "@rollup/rollup-linux-loongarch64-gnu": "4.48.0", + "@rollup/rollup-linux-ppc64-gnu": "4.48.0", + "@rollup/rollup-linux-riscv64-gnu": "4.48.0", + "@rollup/rollup-linux-riscv64-musl": "4.48.0", + "@rollup/rollup-linux-s390x-gnu": "4.48.0", + "@rollup/rollup-linux-x64-gnu": "4.48.0", + "@rollup/rollup-linux-x64-musl": "4.48.0", + "@rollup/rollup-win32-arm64-msvc": "4.48.0", + "@rollup/rollup-win32-ia32-msvc": "4.48.0", + "@rollup/rollup-win32-x64-msvc": "4.48.0", "fsevents": "~2.3.2" } }, @@ -8564,10 +8564,13 @@ } }, "node_modules/tinyglobby/node_modules/fdir": { - "version": "6.4.6", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.6.tgz", - "integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, "peerDependencies": { "picomatch": "^3 || ^4" }, diff --git a/package.json b/package.json index c3c1765..dff955f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/types-generator", - "version": "3.6.0", + "version": "3.7.0", "description": "Contentstack type definition generation library", "private": false, "author": "Contentstack", @@ -40,13 +40,13 @@ "husky": "^9.1.7", "jest": "^29.7.0", "nock": "^13.5.6", - "rollup": "^4.46.2", + "rollup": "^4.48.0", "ts-jest": "^29.4.0", "tsup": "^8.5.0", "typescript": "^5.7.3" }, "dependencies": { - "@contentstack/cli-utilities": "^1.13.0", + "@contentstack/cli-utilities": "^1.13.1", "@contentstack/delivery-sdk": "^4.8.0", "@gql2ts/from-schema": "^2.0.0-4", "async": "^3.2.6", diff --git a/src/generateTS/factory.ts b/src/generateTS/factory.ts index 6c32555..fb63fdb 100644 --- a/src/generateTS/factory.ts +++ b/src/generateTS/factory.ts @@ -8,6 +8,7 @@ import { isNumericIdentifier, NUMERIC_IDENTIFIER_EXCLUSION_REASON, checkNumericIdentifierExclusion, + throwUIDValidationError, } from "./shared/utils"; export type TSGenOptions = { @@ -94,6 +95,13 @@ export default function (userOptions: TSGenOptions) { const skippedBlocks: Array<{ uid: string; path: string; reason: string }> = []; + // Collect numeric identifier errors instead of throwing immediately + const numericIdentifierErrors: Array<{ + uid: string; + referenceTo?: string; + type: "content_type" | "global_field"; + }> = []; + const typeMap: TypeMap = { text: { func: type_text, track: true, flag: TypeFlags.BuiltinJS }, number: { func: type_number, track: true, flag: TypeFlags.BuiltinJS }, @@ -152,6 +160,12 @@ export default function (userOptions: TSGenOptions) { } function name_type(uid: string) { + // Check if the UID starts with a number, which would create invalid TypeScript + if (isNumericIdentifier(uid)) { + // Return a fallback name to continue processing + return `InvalidInterface_${uid}`; + } + return [options?.naming?.prefix, _.upperFirst(_.camelCase(uid))] .filter((v) => v) .join(""); @@ -161,14 +175,41 @@ export default function (userOptions: TSGenOptions) { contentType: ContentstackTypes.ContentType | ContentstackTypes.GlobalField, systemFields = false ) { - const interface_declaration = [ - "export interface", - name_type( - contentType.data_type === "global_field" - ? (contentType.reference_to as string) - : contentType.uid - ), - ]; + // Validate the interface name before creating it + let interfaceName: string; + + const isGlobalField = contentType.data_type === "global_field"; + + // Check if the content type's own UID starts with a number + if (isNumericIdentifier(contentType.uid)) { + numericIdentifierErrors.push({ + uid: contentType.uid, + type: "content_type", + }); + // Return a fallback interface declaration to continue processing + interfaceName = `InvalidInterface_${contentType.uid}`; + } else if ( + isGlobalField && + contentType.reference_to && + isNumericIdentifier(contentType.reference_to as string) + ) { + // For global fields, check if the referenced content type has a numeric identifier + // This is a global field error because it references an invalid content type + numericIdentifierErrors.push({ + uid: contentType.uid, // The global field's UID + type: "global_field", + referenceTo: contentType.reference_to as string, // The referenced content type's UID + }); + // Return a fallback interface declaration to continue processing + interfaceName = `InvalidInterface_${contentType.reference_to}`; + } else { + // No numeric identifier issues, generate normal interface name + interfaceName = name_type( + isGlobalField ? (contentType.reference_to as string) : contentType.uid + ); + } + + const interface_declaration = ["export interface", interfaceName]; if (systemFields && contentType.schema_type !== "global_field") { interface_declaration.push("extends", name_type("SystemFields")); } @@ -570,6 +611,56 @@ export default function (userOptions: TSGenOptions) { const definition = visit_content_type(contentType); + // Check for numeric identifier errors and throw them immediately + if (numericIdentifierErrors.length > 0) { + // Group errors by type for better organization + const contentTypeErrors = numericIdentifierErrors.filter( + (err) => err.type === "content_type" + ); + const globalFieldErrors = numericIdentifierErrors.filter( + (err) => err.type === "global_field" + ); + + // Build the detailed error message + let errorDetails = ""; + errorDetails += `Type generation failed: ${numericIdentifierErrors.length} items use numeric identifiers, which result in invalid TypeScript interface names. Use the --prefix flag to resolve this issue.\n\n`; + + if (contentTypeErrors.length > 0) { + errorDetails += "Content Types and Global Fields with Numeric UIDs\n"; + errorDetails += + "Note: Global Fields are also Content Types. If their UID begins with a number, they are listed here.\n\n"; + + contentTypeErrors.forEach((error, index) => { + errorDetails += `${index + 1}. UID: "${error.uid}"\n`; + errorDetails += `TypeScript constraint: Object keys cannot start with a number.\n`; + errorDetails += `Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType").\n\n`; + }); + } + + if (globalFieldErrors.length > 0) { + errorDetails += "Global Fields Referencing Invalid Content Types:\n\n"; + + globalFieldErrors.forEach((error, index) => { + errorDetails += `${index + 1}. Global Field: "${error.uid}"\n`; + errorDetails += ` References: "${error.referenceTo || "Unknown"}"\n`; + errorDetails += `TypeScript constraint: Object keys cannot start with a number.\n`; + errorDetails += `Suggestion: Since UIDs cannot be changed, use the --prefix flag to add a valid prefix to all interface names (e.g., --prefix "ContentType").\n\n`; + }); + } + + errorDetails += "To resolve these issues:\n"; + errorDetails += + "• Use the --prefix flag to add a valid prefix to all interface names.\n"; + errorDetails += '• Example: --prefix "ContentType"\n'; + + // Throw a comprehensive error with all the details + throw { + type: "validation", + error_code: "VALIDATION_ERROR", + error_message: errorDetails, + }; + } + // Log summary table of skipped fields and blocks if (skippedFields.length > 0 || skippedBlocks.length > 0) { cliux.print(""); diff --git a/src/generateTS/index.ts b/src/generateTS/index.ts index f2641ac..4f80c28 100644 --- a/src/generateTS/index.ts +++ b/src/generateTS/index.ts @@ -11,6 +11,7 @@ import { defaultInterfaces } from "./stack/builtins"; import { format } from "../format/index"; import { ContentType } from "../types/schema"; import { cliux } from "@contentstack/cli-utilities"; +import { createValidationError, createErrorDetails } from "./shared/utils"; export const generateTS = async ({ token, @@ -28,11 +29,9 @@ export const generateTS = async ({ }: GenerateTS) => { try { if (!token || !tokenType || !apiKey || !environment || !region) { - throw { - type: "validation", - error_message: - "Please provide all the required params (token, tokenType, apiKey, environment, region)", - }; + throw createValidationError( + "Please provide all the required params (token, tokenType, apiKey, environment, region)" + ); } if (tokenType === TOKEN_TYPE.DELIVERY) { @@ -62,11 +61,9 @@ export const generateTS = async ({ "Please create Content Models to generate type definitions", { color: "yellow" } ); - throw { - type: "validation", - error_message: - "There are no Content Types in the Stack, please create Content Models to generate type definitions", - }; + throw createValidationError( + "There are no Content Types in the Stack, please create Content Models to generate type definitions" + ); } let schemas: ContentType[] = []; @@ -95,43 +92,40 @@ export const generateTS = async ({ } } catch (error: any) { if (error.type === "validation") { - throw { error_message: error.error_message }; + // Handle validation errors with proper error codes + throw { + error_message: error.error_message, + error_code: error.error_code || "VALIDATION_ERROR", + }; } else { const errorObj = JSON.parse(error.message.replace("Error: ", "")); let errorMessage = "Something went wrong"; + let errorCode = "API_ERROR"; + if (errorObj.status) { switch (errorObj.status) { case 401: - cliux.print("Authentication failed", { - color: "red", - bold: true, - }); - cliux.print("Please check your apiKey, token, and region", { - color: "yellow", - }); errorMessage = "Unauthorized: The apiKey, token or region is not valid."; + errorCode = "AUTHENTICATION_FAILED"; break; case 412: - cliux.print("Invalid credentials", { color: "red", bold: true }); - cliux.print("Please verify your apiKey, token, and region", { - color: "yellow", - }); errorMessage = "Invalid Credentials: Please check the provided apiKey, token and region."; + errorCode = "INVALID_CREDENTIALS"; break; default: - cliux.print(`API Error (${errorObj.status})`, { - color: "red", - bold: true, - }); errorMessage = `${errorMessage}, ${errorObj.error_message}`; + errorCode = `API_ERROR_${errorObj.status}`; } } if (errorObj.error_message && !errorObj.status) { errorMessage = `${errorMessage}, ${errorObj.error_message}`; } - throw { error_message: errorMessage }; + throw { + error_message: errorMessage, + error_code: errorCode, + }; } } }; @@ -193,21 +187,19 @@ export const generateTSFromContentTypes = async ({ return output; } catch (err: any) { - // Enhanced error logging with more context - const errorMessage = err.message || "Unknown error occurred"; - const errorDetails = { - error_message: `Type generation failed: ${errorMessage}`, - context: "generateTSFromContentTypes", - timestamp: new Date().toISOString(), - error_type: err.constructor.name, - }; - - // Log detailed error information for debugging - cliux.print(`Type generation failed: ${errorMessage}`, { - color: "red", - bold: true, - }); + // Handle numeric identifier errors specially to preserve their detailed format + if ( + err.type === "validation" && + err.error_code === "VALIDATION_ERROR" && + err.error_message && + err.error_message.includes("numeric identifiers") + ) { + // Pass through the detailed error as-is + throw err; + } + // Use common function to create detailed error information for other errors + const errorDetails = createErrorDetails(err, "generateTSFromContentTypes"); throw errorDetails; } }; diff --git a/src/generateTS/shared/utils.ts b/src/generateTS/shared/utils.ts index b5d6889..0b9b13e 100644 --- a/src/generateTS/shared/utils.ts +++ b/src/generateTS/shared/utils.ts @@ -57,3 +57,90 @@ export function checkNumericIdentifierExclusion( } return { shouldExclude: false }; } + +/** + * Throws a UID validation error with standardized structure + * @param params - Object containing error parameters + * @param params.uid - The UID that caused the validation error + * @param params.errorCode - The error code for the validation error + * @param params.reason - The reason for the validation error + * @param params.suggestion - The suggestion to resolve the issue + * @param params.context - The context where the error occurred + * @param params.referenceTo - Optional reference UID for global field errors + * @throws A validation error object + */ +export function throwUIDValidationError({ + uid, + errorCode, + reason, + suggestion, + context, + referenceTo, +}: { + uid: string; + errorCode: string; + reason: string; + suggestion: string; + context: string; + referenceTo?: string; +}): never { + const errorMessage = + errorCode === "INVALID_GLOBAL_FIELD_REFERENCE" + ? `Global field "${uid}" references content type "${referenceTo}" which starts with a number, creating invalid TypeScript interface names.` + : `Content type UID "${uid}" starts with a number, which creates invalid TypeScript interface names.`; + + throw { + type: "validation", + error_code: errorCode, + error_message: errorMessage, + details: { + uid, + ...(referenceTo ? { reference_to: referenceTo } : {}), + reason, + suggestion, + }, + context, + timestamp: new Date().toISOString(), + }; +} + +/** + * Creates a validation error in the exact format expected by tests + * This maintains backward compatibility while reducing code duplication + * @param errorMessage - The error message to display + * @returns A validation error object with the expected structure + */ +export function createValidationError(errorMessage: string) { + return { + type: "validation", + error_message: errorMessage, + }; +} + +/** + * Creates standardized error details for different types of errors + * @param err - The error object to process + * @param context - The context where the error occurred + * @returns Standardized error details object + */ +export function createErrorDetails( + err: any, + context: string = "generateTSFromContentTypes" +) { + if (err.type === "validation") { + // Handle validation errors with proper error codes + return { + error_message: err.error_message || "Validation error occurred", // Keep for backwards compatibility + error_code: err.error_code || "VALIDATION_ERROR", // New property + details: err.details || {}, + }; + } else { + // Handle other types of errors + const errorMessage = err.message || "Unknown error occurred"; + return { + error_message: `Type generation failed: ${errorMessage}`, // Keep for backwards compatibility + error_code: "TYPE_GENERATION_FAILED", // New property + details: {}, + }; + } +} diff --git a/src/graphqlTS/index.ts b/src/graphqlTS/index.ts index 258799e..796d007 100644 --- a/src/graphqlTS/index.ts +++ b/src/graphqlTS/index.ts @@ -96,25 +96,40 @@ export async function graphqlTS({ if (error.message && !error.response) { throw { error_message: error.message }; } - if (error.response.status === 412) { + + if (error.response?.status === 412) { throw { error_message: "Unauthorized: The apiKey, token or environment is not valid.", }; } else { let details = ""; + // Add proper null checks before accessing array elements if ( - error.response.data.errors[0]?.extensions?.errors?.[0]?.code === - "SCHEMA_BUILD_ERROR" + error.response?.data?.errors && + Array.isArray(error.response.data.errors) && + error.response.data.errors.length > 0 && + error.response.data.errors[0]?.extensions?.errors && + Array.isArray(error.response.data.errors[0].extensions.errors) && + error.response.data.errors[0].extensions.errors.length > 0 && + error.response.data.errors[0].extensions.errors[0]?.code === + "SCHEMA_BUILD_ERROR" ) { - details = error.response.data.errors[0].extensions.errors[0].details - .map((element: { error: string }) => element.error) - .join("\n"); + details = + error.response.data.errors[0].extensions.errors[0].details + ?.map((element: { error: string }) => element.error) + .join("\n") || ""; } + + // Safely access the error message with proper null checks + const errorMessage = + error.response?.data?.errors?.[0]?.extensions?.errors?.[0]?.message; + throw { - error_message: details - ? details - : error.response.data.errors[0]?.extensions?.errors[0].message, + error_message: + details || + errorMessage || + "An error occurred while processing GraphQL schema", }; } } diff --git a/tests/unit/generateTS/generateTS.test.ts b/tests/unit/generateTS/generateTS.test.ts index ccb1612..b3368de 100644 --- a/tests/unit/generateTS/generateTS.test.ts +++ b/tests/unit/generateTS/generateTS.test.ts @@ -129,7 +129,7 @@ describe("generateTS function", () => { expect(generatedTS).toMatch(/Dishes/); // Check for whether typeDef of Content type is included expect(generatedTS).toMatch(/Seo/); // Check for whether typeDef of Global Fields is included expect(generatedTS).toMatch(/export interface SystemFields \{\n/); // Check for whether System Fields are Created - expect(generatedTS).toMatch(/extends SystemFields \{\n/); // Check for whether interfaces have extended system fields interface + expect(generatedTS).toMatch(/extends SystemFields\s*\{/); // Check for whether interfaces have extended system fields interface expect(generatedTS).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for Documentation is generated }); }); diff --git a/tests/unit/generateTSFromContentTypes/generateTSFromContentTypes.test.ts b/tests/unit/generateTSFromContentTypes/generateTSFromContentTypes.test.ts index 53230b4..58e335c 100644 --- a/tests/unit/generateTSFromContentTypes/generateTSFromContentTypes.test.ts +++ b/tests/unit/generateTSFromContentTypes/generateTSFromContentTypes.test.ts @@ -35,7 +35,7 @@ describe("generateTSFromContentTypes function", () => { expect(generatedTSfromCT).toMatch(/(?!Dishes)testDishes/); // Check for whether typeDef of Content type is included with test prefix expect(generatedTSfromCT).toMatch(/(?!Seo)testSeo/); // Check for whether typeDef of Global Fields is included with test prefix expect(generatedTSfromCT).toMatch(/export interface testSystemFields \{\n/); // Check for whether System Fields are Created with test prefix - expect(generatedTSfromCT).toMatch(/extends testSystemFields \{\n/); // Check for whether interfaces have extended testSystemFields interface + expect(generatedTSfromCT).toMatch(/extends testSystemFields\s*\{/); // Check for whether interfaces have extended testSystemFields interface expect(generatedTSfromCT).toMatch(/\/\*\*.*\*\/\n\s*(export)/); // Check for is Documentation Generated }); });