From a0ac09fb18bc95c867d1a913d6a8a69dbe6faf78 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 16 May 2024 18:26:46 +0530 Subject: [PATCH 01/12] SRE fixes --- package-lock.json | 286 ++++++++---------- .../src/audit-base-command.ts | 89 +++--- .../contentstack-audit/src/messages/index.ts | 4 +- .../src/modules/content-types.ts | 12 +- .../contentstack-audit/src/modules/entries.ts | 13 +- .../src/modules/extensions.ts | 12 +- .../src/modules/workflows.ts | 13 +- .../src/bootstrap/index.ts | 4 +- .../src/bootstrap/utils.ts | 14 +- .../contentstack-branches/src/utils/index.ts | 6 +- .../contentstack-bulk-publish/copyLogs.js | 4 +- .../src/consumer/publish.js | 3 +- .../src/util/logger.js | 5 +- .../contentstack-clone/src/lib/util/log.js | 8 +- .../src/export/modules-js/assets.js | 19 +- .../src/export/modules-js/environments.js | 2 +- .../src/export/modules-js/extensions.js | 2 +- .../src/export/modules-js/global-fields.js | 2 +- .../src/export/modules-js/labels.js | 2 +- .../src/export/modules-js/marketplace-apps.js | 2 +- .../src/export/modules-js/stack.js | 2 +- .../src/export/modules-js/webhooks.js | 2 +- .../src/export/modules-js/workflows.js | 2 +- .../src/utils/basic-login.ts | 2 +- .../src/utils/file-helper.ts | 10 +- .../contentstack-export/src/utils/logger.ts | 12 +- .../src/utils/setup-branches.ts | 3 +- .../src/utils/setup-export-dir.ts | 3 +- .../src/import/modules-js/assets.js | 23 +- .../src/import/modules-js/content-types.js | 13 +- .../src/import/modules-js/entries.js | 5 +- .../src/import/modules/content-types.ts | 19 +- .../src/import/modules/entries.ts | 32 +- .../src/import/modules/global-fields.ts | 18 +- .../src/import/modules/locales.ts | 14 +- .../src/utils/asset-helper.ts | 3 +- .../src/utils/backup-handler.ts | 4 +- .../src/utils/common-helper.ts | 24 +- .../src/utils/entries-helper.ts | 7 +- .../src/utils/file-helper.ts | 10 +- .../src/utils/import-config-handler.ts | 4 +- packages/contentstack-import/src/utils/log.ts | 4 +- .../contentstack-import/src/utils/logger.ts | 9 +- .../01-change-master-locale.js | 6 +- ...change-master-locale-new-file-structure.js | 12 +- .../src/commands/cm/stacks/migration.js | 3 +- .../src/utils/logger.js | 4 +- .../src/utils/migration-logger.js | 5 +- .../contentstack-seed/src/seed/importer.ts | 4 +- .../contentstack-utilities/src/helpers.ts | 10 + packages/contentstack-utilities/src/logger.ts | 4 +- .../contentstack/src/utils/context-handler.ts | 4 +- 52 files changed, 417 insertions(+), 362 deletions(-) diff --git a/package-lock.json b/package-lock.json index 40582f1622..8e0809418e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4528,9 +4528,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1620.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1620.0.tgz", - "integrity": "sha512-G+mBI/VzuFpobBe+pu++ELc3YXSx2UzBTiLmQuZIQDi2+9VEU+/8QFAH45SI8PRPDRCcn4NMK4Euqs0uCyObvQ==", + "version": "2.1621.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1621.0.tgz", + "integrity": "sha512-v6rxF1u0GpQG1Y9Wul9iaqulSV2uEnp0kHKd6/lZcvEgTYhtJ8N0hOLfqRSWHjH5PaIa46hR9zSAp51r8DJ/OA==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -5273,9 +5273,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001618", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001618.tgz", - "integrity": "sha512-p407+D1tIkDvsEAPS22lJxLQQaG8OTBEqo0KhzfABGk0TU4juBNDSfH0hyAp/HRyx+M8L17z/ltyhxh27FTfQg==", + "version": "1.0.30001620", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz", + "integrity": "sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew==", "dev": true, "funding": [ { @@ -6807,9 +6807,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.769", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.769.tgz", - "integrity": "sha512-bZu7p623NEA2rHTc9K1vykl57ektSPQYFFqQir8BOYf6EKOB+yIsbFB9Kpm7Cgt6tsLr9sRkqfqSZUw7LP1XxQ==", + "version": "1.4.772", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.772.tgz", + "integrity": "sha512-jFfEbxR/abTTJA3ci+2ok1NTuOBBtB4jH+UT6PUmRN+DY3WSD4FFRsgoVQ+QNIJ0T7wrXwzsWCI2WKC46b++2A==", "dev": true }, "node_modules/elegant-spinner": { @@ -14887,9 +14887,9 @@ } }, "node_modules/npm": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/npm/-/npm-10.7.0.tgz", - "integrity": "sha512-FXylyYSXNjgXx3l82BT8RSQvCoGIQ3h8YdRFGKNvo3Pv/bKscK4pdWkx/onwTpHDqGw+oeLf4Rxln9WVyxAxlQ==", + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/npm/-/npm-10.8.0.tgz", + "integrity": "sha512-wh93uRczgp7HDnPMiLXcCkv2hagdJS0zJ9KT/31d0FoXP02+qgN2AOwpaW85fxRWkinl2rELfPw+CjBXW48/jQ==", "bundleDependencies": [ "@isaacs/string-locale-compare", "@npmcli/arborist", @@ -14962,71 +14962,71 @@ ], "dependencies": { "@isaacs/string-locale-compare": "^1.1.0", - "@npmcli/arborist": "^7.2.1", - "@npmcli/config": "^8.0.2", - "@npmcli/fs": "^3.1.0", + "@npmcli/arborist": "^7.5.2", + "@npmcli/config": "^8.3.2", + "@npmcli/fs": "^3.1.1", "@npmcli/map-workspaces": "^3.0.6", "@npmcli/package-json": "^5.1.0", - "@npmcli/promise-spawn": "^7.0.1", + "@npmcli/promise-spawn": "^7.0.2", "@npmcli/redact": "^2.0.0", "@npmcli/run-script": "^8.1.0", - "@sigstore/tuf": "^2.3.2", + "@sigstore/tuf": "^2.3.3", "abbrev": "^2.0.0", "archy": "~1.0.0", - "cacache": "^18.0.2", + "cacache": "^18.0.3", "chalk": "^5.3.0", "ci-info": "^4.0.0", "cli-columns": "^4.0.0", "fastest-levenshtein": "^1.0.16", "fs-minipass": "^3.0.3", - "glob": "^10.3.12", + "glob": "^10.3.15", "graceful-fs": "^4.2.11", - "hosted-git-info": "^7.0.1", + "hosted-git-info": "^7.0.2", "ini": "^4.1.2", - "init-package-json": "^6.0.2", + "init-package-json": "^6.0.3", "is-cidr": "^5.0.5", - "json-parse-even-better-errors": "^3.0.1", - "libnpmaccess": "^8.0.1", - "libnpmdiff": "^6.0.3", - "libnpmexec": "^8.0.0", - "libnpmfund": "^5.0.1", - "libnpmhook": "^10.0.0", - "libnpmorg": "^6.0.1", - "libnpmpack": "^7.0.0", - "libnpmpublish": "^9.0.2", - "libnpmsearch": "^7.0.0", - "libnpmteam": "^6.0.0", - "libnpmversion": "^6.0.0", + "json-parse-even-better-errors": "^3.0.2", + "libnpmaccess": "^8.0.6", + "libnpmdiff": "^6.1.2", + "libnpmexec": "^8.1.1", + "libnpmfund": "^5.0.10", + "libnpmhook": "^10.0.5", + "libnpmorg": "^6.0.6", + "libnpmpack": "^7.0.2", + "libnpmpublish": "^9.0.8", + "libnpmsearch": "^7.0.5", + "libnpmteam": "^6.0.5", + "libnpmversion": "^6.0.2", "make-fetch-happen": "^13.0.1", "minimatch": "^9.0.4", - "minipass": "^7.0.4", + "minipass": "^7.1.1", "minipass-pipeline": "^1.2.4", "ms": "^2.1.2", "node-gyp": "^10.1.0", - "nopt": "^7.2.0", - "normalize-package-data": "^6.0.0", + "nopt": "^7.2.1", + "normalize-package-data": "^6.0.1", "npm-audit-report": "^5.0.0", "npm-install-checks": "^6.3.0", "npm-package-arg": "^11.0.2", - "npm-pick-manifest": "^9.0.0", - "npm-profile": "^9.0.2", - "npm-registry-fetch": "^17.0.0", - "npm-user-validate": "^2.0.0", + "npm-pick-manifest": "^9.0.1", + "npm-profile": "^10.0.0", + "npm-registry-fetch": "^17.0.1", + "npm-user-validate": "^2.0.1", "p-map": "^4.0.0", - "pacote": "^18.0.3", + "pacote": "^18.0.6", "parse-conflict-json": "^3.0.1", "proc-log": "^4.2.0", "qrcode-terminal": "^0.12.0", "read": "^3.0.1", - "semver": "^7.6.0", + "semver": "^7.6.2", "spdx-expression-parse": "^4.0.0", - "ssri": "^10.0.5", + "ssri": "^10.0.6", "supports-color": "^9.4.0", "tar": "^6.2.1", "text-table": "~0.2.0", "tiny-relative-date": "^1.3.0", "treeverse": "^3.0.0", - "validate-npm-package-name": "^5.0.0", + "validate-npm-package-name": "^5.0.1", "which": "^4.0.0", "write-file-atomic": "^5.0.1" }, @@ -15626,34 +15626,35 @@ } }, "node_modules/npm/node_modules/@npmcli/arborist": { - "version": "7.5.1", + "version": "7.5.2", "inBundle": true, "license": "ISC", "dependencies": { "@isaacs/string-locale-compare": "^1.1.0", - "@npmcli/fs": "^3.1.0", + "@npmcli/fs": "^3.1.1", "@npmcli/installed-package-contents": "^2.1.0", "@npmcli/map-workspaces": "^3.0.2", - "@npmcli/metavuln-calculator": "^7.1.0", + "@npmcli/metavuln-calculator": "^7.1.1", "@npmcli/name-from-folder": "^2.0.0", "@npmcli/node-gyp": "^3.0.0", "@npmcli/package-json": "^5.1.0", "@npmcli/query": "^3.1.0", "@npmcli/redact": "^2.0.0", "@npmcli/run-script": "^8.1.0", - "bin-links": "^4.0.1", - "cacache": "^18.0.0", + "bin-links": "^4.0.4", + "cacache": "^18.0.3", "common-ancestor-path": "^1.0.1", - "hosted-git-info": "^7.0.1", - "json-parse-even-better-errors": "^3.0.0", + "hosted-git-info": "^7.0.2", + "json-parse-even-better-errors": "^3.0.2", "json-stringify-nice": "^1.1.4", + "lru-cache": "^10.2.2", "minimatch": "^9.0.4", - "nopt": "^7.0.0", + "nopt": "^7.2.1", "npm-install-checks": "^6.2.0", "npm-package-arg": "^11.0.2", - "npm-pick-manifest": "^9.0.0", - "npm-registry-fetch": "^17.0.0", - "pacote": "^18.0.1", + "npm-pick-manifest": "^9.0.1", + "npm-registry-fetch": "^17.0.1", + "pacote": "^18.0.6", "parse-conflict-json": "^3.0.0", "proc-log": "^4.2.0", "proggy": "^2.0.0", @@ -15661,7 +15662,7 @@ "promise-call-limit": "^3.0.1", "read-package-json-fast": "^3.0.2", "semver": "^7.3.7", - "ssri": "^10.0.5", + "ssri": "^10.0.6", "treeverse": "^3.0.0", "walk-up-path": "^3.0.1" }, @@ -15673,14 +15674,14 @@ } }, "node_modules/npm/node_modules/@npmcli/config": { - "version": "8.3.1", + "version": "8.3.2", "inBundle": true, "license": "ISC", "dependencies": { "@npmcli/map-workspaces": "^3.0.2", "ci-info": "^4.0.0", "ini": "^4.1.2", - "nopt": "^7.0.0", + "nopt": "^7.2.1", "proc-log": "^4.2.0", "read-package-json-fast": "^3.0.2", "semver": "^7.3.5", @@ -15691,7 +15692,7 @@ } }, "node_modules/npm/node_modules/@npmcli/fs": { - "version": "3.1.0", + "version": "3.1.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -15702,7 +15703,7 @@ } }, "node_modules/npm/node_modules/@npmcli/git": { - "version": "5.0.6", + "version": "5.0.7", "inBundle": true, "license": "ISC", "dependencies": { @@ -15749,7 +15750,7 @@ } }, "node_modules/npm/node_modules/@npmcli/metavuln-calculator": { - "version": "7.1.0", + "version": "7.1.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -15797,7 +15798,7 @@ } }, "node_modules/npm/node_modules/@npmcli/promise-spawn": { - "version": "7.0.1", + "version": "7.0.2", "inBundle": true, "license": "ISC", "dependencies": { @@ -15871,7 +15872,7 @@ } }, "node_modules/npm/node_modules/@sigstore/protobuf-specs": { - "version": "0.3.1", + "version": "0.3.2", "inBundle": true, "license": "Apache-2.0", "engines": { @@ -15879,26 +15880,28 @@ } }, "node_modules/npm/node_modules/@sigstore/sign": { - "version": "2.3.0", + "version": "2.3.1", "inBundle": true, "license": "Apache-2.0", "dependencies": { "@sigstore/bundle": "^2.3.0", "@sigstore/core": "^1.0.0", "@sigstore/protobuf-specs": "^0.3.1", - "make-fetch-happen": "^13.0.0" + "make-fetch-happen": "^13.0.1", + "proc-log": "^4.2.0", + "promise-retry": "^2.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/@sigstore/tuf": { - "version": "2.3.2", + "version": "2.3.3", "inBundle": true, "license": "Apache-2.0", "dependencies": { "@sigstore/protobuf-specs": "^0.3.0", - "tuf-js": "^2.2.0" + "tuf-js": "^2.2.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" @@ -15926,12 +15929,12 @@ } }, "node_modules/npm/node_modules/@tufjs/models": { - "version": "2.0.0", + "version": "2.0.1", "inBundle": true, "license": "MIT", "dependencies": { "@tufjs/canonical-json": "2.0.0", - "minimatch": "^9.0.3" + "minimatch": "^9.0.4" }, "engines": { "node": "^16.14.0 || >=18.0.0" @@ -16003,7 +16006,7 @@ "license": "MIT" }, "node_modules/npm/node_modules/bin-links": { - "version": "4.0.3", + "version": "4.0.4", "inBundle": true, "license": "ISC", "dependencies": { @@ -16035,16 +16038,8 @@ "balanced-match": "^1.0.0" } }, - "node_modules/npm/node_modules/builtins": { - "version": "5.1.0", - "inBundle": true, - "license": "MIT", - "dependencies": { - "semver": "^7.0.0" - } - }, "node_modules/npm/node_modules/cacache": { - "version": "18.0.2", + "version": "18.0.3", "inBundle": true, "license": "ISC", "dependencies": { @@ -16130,7 +16125,7 @@ } }, "node_modules/npm/node_modules/cmd-shim": { - "version": "6.0.2", + "version": "6.0.3", "inBundle": true, "license": "ISC", "engines": { @@ -16305,7 +16300,7 @@ } }, "node_modules/npm/node_modules/glob": { - "version": "10.3.12", + "version": "10.3.15", "inBundle": true, "license": "ISC", "dependencies": { @@ -16313,13 +16308,13 @@ "jackspeak": "^2.3.6", "minimatch": "^9.0.1", "minipass": "^7.0.4", - "path-scurry": "^1.10.2" + "path-scurry": "^1.11.0" }, "bin": { "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -16342,7 +16337,7 @@ } }, "node_modules/npm/node_modules/hosted-git-info": { - "version": "7.0.1", + "version": "7.0.2", "inBundle": true, "license": "ISC", "dependencies": { @@ -16394,7 +16389,7 @@ } }, "node_modules/npm/node_modules/ignore-walk": { - "version": "6.0.4", + "version": "6.0.5", "inBundle": true, "license": "ISC", "dependencies": { @@ -16429,7 +16424,7 @@ } }, "node_modules/npm/node_modules/init-package-json": { - "version": "6.0.2", + "version": "6.0.3", "inBundle": true, "license": "ISC", "dependencies": { @@ -16531,7 +16526,7 @@ "license": "MIT" }, "node_modules/npm/node_modules/json-parse-even-better-errors": { - "version": "3.0.1", + "version": "3.0.2", "inBundle": true, "license": "MIT", "engines": { @@ -16565,29 +16560,29 @@ "license": "MIT" }, "node_modules/npm/node_modules/libnpmaccess": { - "version": "8.0.5", + "version": "8.0.6", "inBundle": true, "license": "ISC", "dependencies": { "npm-package-arg": "^11.0.2", - "npm-registry-fetch": "^17.0.0" + "npm-registry-fetch": "^17.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmdiff": { - "version": "6.1.1", + "version": "6.1.2", "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/arborist": "^7.2.1", + "@npmcli/arborist": "^7.5.2", "@npmcli/installed-package-contents": "^2.1.0", "binary-extensions": "^2.3.0", "diff": "^5.1.0", "minimatch": "^9.0.4", "npm-package-arg": "^11.0.2", - "pacote": "^18.0.1", + "pacote": "^18.0.6", "tar": "^6.2.1" }, "engines": { @@ -16595,15 +16590,15 @@ } }, "node_modules/npm/node_modules/libnpmexec": { - "version": "8.1.0", + "version": "8.1.1", "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/arborist": "^7.2.1", + "@npmcli/arborist": "^7.5.2", "@npmcli/run-script": "^8.1.0", "ci-info": "^4.0.0", "npm-package-arg": "^11.0.2", - "pacote": "^18.0.1", + "pacote": "^18.0.6", "proc-log": "^4.2.0", "read": "^3.0.1", "read-package-json-fast": "^3.0.2", @@ -16615,103 +16610,103 @@ } }, "node_modules/npm/node_modules/libnpmfund": { - "version": "5.0.9", + "version": "5.0.10", "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/arborist": "^7.2.1" + "@npmcli/arborist": "^7.5.2" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmhook": { - "version": "10.0.4", + "version": "10.0.5", "inBundle": true, "license": "ISC", "dependencies": { "aproba": "^2.0.0", - "npm-registry-fetch": "^17.0.0" + "npm-registry-fetch": "^17.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmorg": { - "version": "6.0.5", + "version": "6.0.6", "inBundle": true, "license": "ISC", "dependencies": { "aproba": "^2.0.0", - "npm-registry-fetch": "^17.0.0" + "npm-registry-fetch": "^17.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmpack": { - "version": "7.0.1", + "version": "7.0.2", "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/arborist": "^7.2.1", + "@npmcli/arborist": "^7.5.2", "@npmcli/run-script": "^8.1.0", "npm-package-arg": "^11.0.2", - "pacote": "^18.0.1" + "pacote": "^18.0.6" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmpublish": { - "version": "9.0.7", + "version": "9.0.8", "inBundle": true, "license": "ISC", "dependencies": { "ci-info": "^4.0.0", - "normalize-package-data": "^6.0.0", + "normalize-package-data": "^6.0.1", "npm-package-arg": "^11.0.2", - "npm-registry-fetch": "^17.0.0", + "npm-registry-fetch": "^17.0.1", "proc-log": "^4.2.0", "semver": "^7.3.7", "sigstore": "^2.2.0", - "ssri": "^10.0.5" + "ssri": "^10.0.6" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmsearch": { - "version": "7.0.4", + "version": "7.0.5", "inBundle": true, "license": "ISC", "dependencies": { - "npm-registry-fetch": "^17.0.0" + "npm-registry-fetch": "^17.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmteam": { - "version": "6.0.4", + "version": "6.0.5", "inBundle": true, "license": "ISC", "dependencies": { "aproba": "^2.0.0", - "npm-registry-fetch": "^17.0.0" + "npm-registry-fetch": "^17.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" } }, "node_modules/npm/node_modules/libnpmversion": { - "version": "6.0.1", + "version": "6.0.2", "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/git": "^5.0.6", + "@npmcli/git": "^5.0.7", "@npmcli/run-script": "^8.1.0", - "json-parse-even-better-errors": "^3.0.0", + "json-parse-even-better-errors": "^3.0.2", "proc-log": "^4.2.0", "semver": "^7.3.7" }, @@ -16764,7 +16759,7 @@ } }, "node_modules/npm/node_modules/minipass": { - "version": "7.0.4", + "version": "7.1.1", "inBundle": true, "license": "ISC", "engines": { @@ -16783,7 +16778,7 @@ } }, "node_modules/npm/node_modules/minipass-fetch": { - "version": "3.0.4", + "version": "3.0.5", "inBundle": true, "license": "MIT", "dependencies": { @@ -16971,7 +16966,7 @@ } }, "node_modules/npm/node_modules/nopt": { - "version": "7.2.0", + "version": "7.2.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -16985,7 +16980,7 @@ } }, "node_modules/npm/node_modules/normalize-package-data": { - "version": "6.0.0", + "version": "6.0.1", "inBundle": true, "license": "BSD-2-Clause", "dependencies": { @@ -17007,7 +17002,7 @@ } }, "node_modules/npm/node_modules/npm-bundled": { - "version": "3.0.0", + "version": "3.0.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -17062,7 +17057,7 @@ } }, "node_modules/npm/node_modules/npm-pick-manifest": { - "version": "9.0.0", + "version": "9.0.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -17076,19 +17071,19 @@ } }, "node_modules/npm/node_modules/npm-profile": { - "version": "9.0.2", + "version": "10.0.0", "inBundle": true, "license": "ISC", "dependencies": { - "npm-registry-fetch": "^17.0.0", + "npm-registry-fetch": "^17.0.1", "proc-log": "^4.0.0" }, "engines": { - "node": "^16.14.0 || >=18.0.0" + "node": ">=18.0.0" } }, "node_modules/npm/node_modules/npm-registry-fetch": { - "version": "17.0.0", + "version": "17.0.1", "inBundle": true, "license": "ISC", "dependencies": { @@ -17106,7 +17101,7 @@ } }, "node_modules/npm/node_modules/npm-user-validate": { - "version": "2.0.0", + "version": "2.0.1", "inBundle": true, "license": "BSD-2-Clause", "engines": { @@ -17128,7 +17123,7 @@ } }, "node_modules/npm/node_modules/pacote": { - "version": "18.0.3", + "version": "18.0.6", "inBundle": true, "license": "ISC", "dependencies": { @@ -17151,7 +17146,7 @@ "tar": "^6.1.11" }, "bin": { - "pacote": "lib/bin.js" + "pacote": "bin/index.js" }, "engines": { "node": "^16.14.0 || >=18.0.0" @@ -17179,7 +17174,7 @@ } }, "node_modules/npm/node_modules/path-scurry": { - "version": "1.10.2", + "version": "1.11.1", "inBundle": true, "license": "BlueOak-1.0.0", "dependencies": { @@ -17187,7 +17182,7 @@ "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -17255,7 +17250,7 @@ } }, "node_modules/npm/node_modules/promzard": { - "version": "1.0.1", + "version": "1.0.2", "inBundle": true, "license": "ISC", "dependencies": { @@ -17318,12 +17313,9 @@ "optional": true }, "node_modules/npm/node_modules/semver": { - "version": "7.6.0", + "version": "7.6.2", "inBundle": true, "license": "ISC", - "dependencies": { - "lru-cache": "^6.0.0" - }, "bin": { "semver": "bin/semver.js" }, @@ -17331,17 +17323,6 @@ "node": ">=10" } }, - "node_modules/npm/node_modules/semver/node_modules/lru-cache": { - "version": "6.0.0", - "inBundle": true, - "license": "ISC", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/npm/node_modules/shebang-command": { "version": "2.0.0", "inBundle": true, @@ -17466,7 +17447,7 @@ "license": "BSD-3-Clause" }, "node_modules/npm/node_modules/ssri": { - "version": "10.0.5", + "version": "10.0.6", "inBundle": true, "license": "ISC", "dependencies": { @@ -17602,13 +17583,13 @@ } }, "node_modules/npm/node_modules/tuf-js": { - "version": "2.2.0", + "version": "2.2.1", "inBundle": true, "license": "MIT", "dependencies": { - "@tufjs/models": "2.0.0", + "@tufjs/models": "2.0.1", "debug": "^4.3.4", - "make-fetch-happen": "^13.0.0" + "make-fetch-happen": "^13.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" @@ -17660,12 +17641,9 @@ } }, "node_modules/npm/node_modules/validate-npm-package-name": { - "version": "5.0.0", + "version": "5.0.1", "inBundle": true, "license": "ISC", - "dependencies": { - "builtins": "^5.0.0" - }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index b77879fc7d..6709bf037b 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -416,50 +416,55 @@ export abstract class AuditBaseCommand extends BaseCommand, ): Promise { - const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`); - - return new Promise((resolve, reject) => { - // file deepcode ignore MissingClose: Will auto close once csv stream end - const ws = createWriteStream(csvPath).on('error', reject); - const defaultColumns = Object.keys(OutputColumn); - const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null; - let missingRefs: RefErrorReturnType[] | WorkflowExtensionsRefErrorReturnType[] = - Object.values(listOfMissingRefs).flat(); - const columns: (keyof typeof OutputColumn)[] = userDefinedColumns - ? [...userDefinedColumns, ...defaultColumns.filter((val: string) => !userDefinedColumns.includes(val))] - : defaultColumns; - - if (this.sharedConfig.flags.filter) { - const [column, value]: [keyof typeof OutputColumn, string] = this.sharedConfig.flags.filter.split('='); - // Filter the missingRefs array - missingRefs = missingRefs.filter((row) => { - if (OutputColumn[column] in row) { - const rowKey = OutputColumn[column] as keyof (RefErrorReturnType | WorkflowExtensionsRefErrorReturnType); - return row[rowKey] === value; + if(Object.keys(config.moduleConfig).includes(moduleName)){ + const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`); + return new Promise((resolve, reject) => { + // file deepcode ignore MissingClose: Will auto close once csv stream end + const ws = createWriteStream(csvPath).on('error', reject); + const defaultColumns = Object.keys(OutputColumn); + const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null; + let missingRefs: RefErrorReturnType[] | WorkflowExtensionsRefErrorReturnType[] = + Object.values(listOfMissingRefs).flat(); + const columns: (keyof typeof OutputColumn)[] = userDefinedColumns + ? [...userDefinedColumns, ...defaultColumns.filter((val: string) => !userDefinedColumns.includes(val))] + : defaultColumns; + + if (this.sharedConfig.flags.filter) { + const [column, value]: [keyof typeof OutputColumn, string] = this.sharedConfig.flags.filter.split('='); + // Filter the missingRefs array + missingRefs = missingRefs.filter((row) => { + if (OutputColumn[column] in row) { + const rowKey = OutputColumn[column] as keyof (RefErrorReturnType | WorkflowExtensionsRefErrorReturnType); + return row[rowKey] === value; + } + return false; + }); + } + + const rowData: Record[] = []; + for (const issue of missingRefs) { + let row: Record = {}; + + for (const column of columns) { + if (Object.keys(issue).includes(OutputColumn[column])) { + const issueKey = OutputColumn[column] as keyof typeof issue; + row[column] = issue[issueKey] as string; + row[column] = typeof row[column] === 'object' ? JSON.stringify(row[column]) : row[column]; + } } - return false; - }); - } - - const rowData: Record[] = []; - for (const issue of missingRefs) { - let row: Record = {}; - - for (const column of columns) { - if (Object.keys(issue).includes(OutputColumn[column])) { - const issueKey = OutputColumn[column] as keyof typeof issue; - row[column] = issue[issueKey] as string; - row[column] = typeof row[column] === 'object' ? JSON.stringify(row[column]) : row[column]; + + if (this.currentCommand === 'cm:stacks:audit:fix') { + row['Fix status'] = row.fixStatus; } + + rowData.push(row); } - - if (this.currentCommand === 'cm:stacks:audit:fix') { - row['Fix status'] = row.fixStatus; - } - - rowData.push(row); - } - csv.write(rowData, { headers: true }).pipe(ws).on('error', reject).on('finish', resolve); - }); + csv.write(rowData, { headers: true }).pipe(ws).on('error', reject).on('finish', resolve); + }); + } else { + return new Promise((reject)=>{ + return reject() + }) + } } } diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index d8a37c1c98..a488baf23a 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -77,7 +77,9 @@ function $t(msg: string, args: Record): string { for (const key of Object.keys(args)) { const escapedKey = escapeRegExp(key); - msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), escapeRegExp(args[key]) || escapedKey); + const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g'); + const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; + msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); } return msg; diff --git a/packages/contentstack-audit/src/modules/content-types.ts b/packages/contentstack-audit/src/modules/content-types.ts index 274768ceee..a0b5e733b5 100644 --- a/packages/contentstack-audit/src/modules/content-types.ts +++ b/packages/contentstack-audit/src/modules/content-types.ts @@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; -import { ux } from '@contentstack/cli-utilities'; +import { sanitizepath, ux } from '@contentstack/cli-utilities'; import { LogFn, @@ -51,11 +51,17 @@ export default class ContentType { this.fix = fix ?? false; this.ctSchema = ctSchema; this.gfSchema = gfSchema; - this.moduleName = moduleName ?? 'content-types'; + this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(config.basePath, config.moduleConfig[this.moduleName].dirName); + this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); } + validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { + if(Object.keys(moduleConfig).includes(moduleName)){ + return moduleName; + } + return 'content-types' + } /** * The `run` function checks if a folder path exists, sets the schema based on the module name, * iterates over the schema and looks for references, and returns a list of missing references. diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index bc3f5013bb..4baa28ca28 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -3,7 +3,7 @@ import find from 'lodash/find'; import values from 'lodash/values'; import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; -import { ux, FsUtility } from '@contentstack/cli-utilities'; +import { ux, FsUtility, sanitizepath } from '@contentstack/cli-utilities'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import auditConfig from '../config'; @@ -67,9 +67,16 @@ export default class Entries { this.fix = fix ?? false; this.ctSchema = ctSchema; this.gfSchema = gfSchema; - this.moduleName = moduleName ?? 'entries'; + this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(config.basePath, config.moduleConfig.entries.dirName); + this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig.entries.dirName)); + } + + validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { + if(Object.keys(moduleConfig).includes(moduleName)){ + return moduleName; + } + return 'entries' } /** diff --git a/packages/contentstack-audit/src/modules/extensions.ts b/packages/contentstack-audit/src/modules/extensions.ts index 10d47bc9a4..77af2e7134 100644 --- a/packages/contentstack-audit/src/modules/extensions.ts +++ b/packages/contentstack-audit/src/modules/extensions.ts @@ -2,7 +2,7 @@ import path, { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import { cloneDeep } from 'lodash'; import { LogFn, ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, Extension } from '../types'; -import { ux } from '@contentstack/cli-utilities'; +import { ux, sanitizepath } from '@contentstack/cli-utilities'; import auditConfig from '../config'; import { $t, auditMsg, commonMsg } from '../messages'; @@ -34,14 +34,20 @@ export default class Extensions { this.fix = fix ?? false; this.ctSchema = ctSchema; this.extensionsSchema = []; - this.moduleName = moduleName ?? 'extensions'; + this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(config.basePath, config.moduleConfig[this.moduleName].dirName); + this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); this.missingCtInExtensions = []; this.missingCts = new Set(); this.extensionsPath = ''; } + validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { + if(Object.keys(moduleConfig).includes(moduleName)){ + return moduleName; + } + return 'extensions' + } async run() { if (!existsSync(this.folderPath)) { diff --git a/packages/contentstack-audit/src/modules/workflows.ts b/packages/contentstack-audit/src/modules/workflows.ts index 3e6f48b554..a7129468a0 100644 --- a/packages/contentstack-audit/src/modules/workflows.ts +++ b/packages/contentstack-audit/src/modules/workflows.ts @@ -2,7 +2,7 @@ import { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import { cloneDeep } from 'lodash'; import { LogFn, ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, Workflow } from '../types'; -import { ux } from '@contentstack/cli-utilities'; +import { sanitizepath, ux } from '@contentstack/cli-utilities'; import auditConfig from '../config'; import { $t, auditMsg, commonMsg } from '../messages'; @@ -35,15 +35,22 @@ export default class Workflows { this.fix = fix ?? false; this.ctSchema = ctSchema; this.workflowSchema = []; - this.moduleName = moduleName ?? 'workflows'; + this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(config.basePath, config.moduleConfig[this.moduleName].dirName); + this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); this.missingCtInWorkflows = []; this.missingCts = new Set(); this.workflowPath = ''; this.isBranchFixDone = false; } + validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { + if(Object.keys(moduleConfig).includes(moduleName)){ + return moduleName; + } + return 'workflows' + } + /** * Check whether the given path for the workflow exists or not * If path exist read diff --git a/packages/contentstack-bootstrap/src/bootstrap/index.ts b/packages/contentstack-bootstrap/src/bootstrap/index.ts index 3b71912050..a8341a2d22 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/index.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/index.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { cliux } from '@contentstack/cli-utilities'; +import { cliux, sanitizepath } from '@contentstack/cli-utilities'; import { default as ContentStackSeed } from '@contentstack/cli-cm-seed/lib/commands/cm/stacks/seed'; import { AppConfig } from '../config'; @@ -58,7 +58,7 @@ export default class Bootstrap { if (options.appConfig.branch) { this.repo.branch = options.appConfig.branch; } - this.cloneDirectory = path.join(options.cloneDirectory, this.repo.name); + this.cloneDirectory = path.join(sanitizepath(options.cloneDirectory), sanitizepath(this.repo.name)); this.ghClient = new GitHubClient(this.repo, options.appConfig.private, options.accessToken); this.options = options; } diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index 12bf53ddfd..cdc91fb24e 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import { cliux, pathValidator } from '@contentstack/cli-utilities'; +import { cliux, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; import { continueBootstrapCommand } from '../bootstrap/interactive'; import { AppConfig } from '../config'; import messageHandler from '../messages'; @@ -154,7 +154,7 @@ const envFileHandler = async ( case 'reactjs': case 'reactjs-starter': fileName = `.env.${environmentVariables.environment}.local`; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); content = `REACT_APP_CONTENTSTACK_API_KEY=${ environmentVariables.api_key }\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}${ @@ -173,7 +173,7 @@ const envFileHandler = async ( case 'nextjs': case 'nextjs-starter': fileName = `.env.${environmentVariables.environment}.local`; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ @@ -192,7 +192,7 @@ const envFileHandler = async ( case 'gatsby': case 'gatsby-starter': fileName = `.env.${environmentVariables.environment}`; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ @@ -239,7 +239,7 @@ const envFileHandler = async ( !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); result = await writeEnvFile(content, filePath); break; case 'nuxtjs': @@ -247,7 +247,7 @@ const envFileHandler = async ( case 'nuxt3-starter': case 'stencil-starter': fileName = production ? '.env.production' : '.env'; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); // Note: Stencil app needs all the env variables, even if they are not having values otherwise the rollup does not work properly and throws process in undefined error. content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken @@ -266,7 +266,7 @@ const envFileHandler = async ( break; case 'vue-starter': fileName = '.env'; - filePath = pathValidator(path.join(clonedDirectory, fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ diff --git a/packages/contentstack-branches/src/utils/index.ts b/packages/contentstack-branches/src/utils/index.ts index 3f73553f68..e472abb9bc 100644 --- a/packages/contentstack-branches/src/utils/index.ts +++ b/packages/contentstack-branches/src/utils/index.ts @@ -4,7 +4,7 @@ import fs from 'fs'; import path from 'path'; import forEach from 'lodash/forEach' -import { configHandler, cliux, messageHandler } from '@contentstack/cli-utilities'; +import { configHandler, cliux, messageHandler, sanitizepath } from '@contentstack/cli-utilities'; import { MergeParams } from '../interfaces'; export const getbranchesList = (branchResult, baseBranch: string) => { @@ -40,7 +40,7 @@ export const refreshbranchConfig = async (apiKey, branchUid) => { export const writeFile = (filePath, data) => { return new Promise((resolve, reject) => { data = typeof data === 'object' ? JSON.stringify(data, null, 2) : data || '{}'; - fs.writeFile(path.resolve(filePath), data, (error) => { + fs.writeFile(path.resolve(sanitizepath(filePath)), data, (error) => { if (error) { return reject(error); } @@ -52,7 +52,7 @@ export const writeFile = (filePath, data) => { // by default file type is json export const readFile = (filePath, options = { type: 'json' }) => { return new Promise((resolve, reject) => { - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { reject(error); diff --git a/packages/contentstack-bulk-publish/copyLogs.js b/packages/contentstack-bulk-publish/copyLogs.js index 9a18d966e6..d6a67e36da 100644 --- a/packages/contentstack-bulk-publish/copyLogs.js +++ b/packages/contentstack-bulk-publish/copyLogs.js @@ -4,6 +4,8 @@ const path = require('path'); const logFileDir = 'logs'; const dummyDir = 'test/dummy/'; +import { sanitizepath } from '@contentstack/cli-utilities'; + if (!fs.existsSync(path.join(__dirname, logFileDir))) { fs.mkdirSync(path.join(__dirname, logFileDir)); } @@ -30,5 +32,5 @@ const logs = [ ]; logs.forEach((element) => { - fs.createReadStream(path.join(__dirname, dummyDir, element)).pipe(fs.createWriteStream(path.join(__dirname, logFileDir, element))); + fs.createReadStream(path.join(__dirname, dummyDir, sanitizepath(element))).pipe(fs.createWriteStream(path.join(__dirname, logFileDir, sanitizepath(element)))); }); diff --git a/packages/contentstack-bulk-publish/src/consumer/publish.js b/packages/contentstack-bulk-publish/src/consumer/publish.js index ad2d0ebc11..39b42b586d 100644 --- a/packages/contentstack-bulk-publish/src/consumer/publish.js +++ b/packages/contentstack-bulk-publish/src/consumer/publish.js @@ -9,6 +9,7 @@ const apiVersionForNRP = '3.2'; const nrpApiVersionWarning = `Provided apiVersion is invalid. ${apiVersionForNRP} is only supported value. Continuing with regular bulk-publish for now.`; const { getLoggerInstance, addLogs, getLogsDirPath } = require('../util/logger'); +const { sanitizepath } = require('@contentstack/cli-utilities'); const logsDir = getLogsDirPath(); let logger; @@ -18,7 +19,7 @@ function initializeLogger(fileName) { fileNme = fileName; fileNme = `${Date.now()}.${fileNme}`; logger = getLoggerInstance(fileNme); - return path.join(logsDir, fileNme); + return path.join(logsDir, sanitizepath(fileNme)); } /* eslint-disable camelcase */ diff --git a/packages/contentstack-bulk-publish/src/util/logger.js b/packages/contentstack-bulk-publish/src/util/logger.js index 5da2d4108a..45e60021cf 100644 --- a/packages/contentstack-bulk-publish/src/util/logger.js +++ b/packages/contentstack-bulk-publish/src/util/logger.js @@ -1,3 +1,4 @@ +const { sanitizepath } = require('@contentstack/cli-utilities'); const path = require('path'); const winston = require('winston'); const cwd = process.cwd(); @@ -6,7 +7,7 @@ const logsDir = path.join(cwd, 'contentstack-cli-logs', 'bulk-publish'); let filename; module.exports.getLoggerInstance = (fileName) => { - filename = path.join(logsDir, fileName); + filename = path.join(logsDir, sanitizepath(fileName)); return winston.createLogger({ transports: [ new winston.transports.File({ filename: `${filename}.error`, level: 'error' }), @@ -17,7 +18,7 @@ module.exports.getLoggerInstance = (fileName) => { /* eslint-disable no-multi-assign */ const getFileLoggerInstance = (module.exports.getFileLoggerInstance = (fileName) => { - filename = path.join(logsDir, fileName); + filename = path.join(logsDir, sanitizepath(fileName)); return winston.createLogger({ transports: [new winston.transports.File({ filename })], }); diff --git a/packages/contentstack-clone/src/lib/util/log.js b/packages/contentstack-clone/src/lib/util/log.js index 7cd92de20a..d90aaa71bd 100644 --- a/packages/contentstack-clone/src/lib/util/log.js +++ b/packages/contentstack-clone/src/lib/util/log.js @@ -1,13 +1,13 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ var winston = require('winston'); var path = require('path'); var mkdirp = require('mkdirp'); -const { pathValidator } = require('@contentstack/cli-utilities'); +const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities'); var slice = Array.prototype.slice; function returnString(args) { @@ -42,10 +42,10 @@ var myCustomLevels = { }; function init(_logPath, logfileName) { - var logsDir = pathValidator(path.resolve(_logPath, 'logs', 'import')); + var logsDir = pathValidator(path.resolve(sanitizepath(_logPath), 'logs', 'import')); // Create dir if doesn't already exist mkdirp.sync(logsDir); - var logPath = path.join(logsDir, pathValidator(logfileName) + '.log'); + var logPath = path.join(sanitizepath(logsDir), pathValidator(sanitizepath(logfileName)) + '.log'); var transports = [ new winston.transports.File({ diff --git a/packages/contentstack-export/src/export/modules-js/assets.js b/packages/contentstack-export/src/export/modules-js/assets.js index e8c3fd4e7f..222b42ee4d 100644 --- a/packages/contentstack-export/src/export/modules-js/assets.js +++ b/packages/contentstack-export/src/export/modules-js/assets.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -11,7 +11,7 @@ const Promise = require('bluebird'); const _ = require('lodash'); const chalk = require('chalk'); const progress = require('progress-stream'); -const { HttpClient, configHandler } = require('@contentstack/cli-utilities'); +const { HttpClient, configHandler, validateUids, sanitizepath, validateFileName } = require('@contentstack/cli-utilities'); const { fileHelper, log, formatError } = require('../../utils'); let { default: config } = require('../../config'); @@ -282,9 +282,11 @@ module.exports = class ExportAssets { } if (version <= 0) { - const assetVersionInfoFile = path.resolve(self.assetsFolderPath, uid, '_contentstack_' + uid + '.json'); - fileHelper.writeFileSync(assetVersionInfoFile, assetVersionInfo); - return resolve(); + if(validateUids(uid)){ + const assetVersionInfoFile = path.resolve(self.assetsFolderPath, uid, '_contentstack_' + uid + '.json'); + fileHelper.writeFileSync(assetVersionInfoFile, assetVersionInfo); + return resolve(); + } } const queryrequestOption = { version: version, @@ -327,8 +329,11 @@ module.exports = class ExportAssets { downloadAsset(asset) { const self = this; return new Promise(async (resolve, reject) => { - const assetFolderPath = path.resolve(self.assetsFolderPath, asset.uid); - const assetFilePath = path.resolve(assetFolderPath, asset.filename); + if(!validateUids(asset.uid) && !validateFileName(asset.filename)) { + reject(`UIDs not valid`) + } + const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), asset.uid); + const assetFilePath = path.resolve(sanitizepath(assetFolderPath), asset.filename); if (fs.existsSync(assetFilePath)) { log( diff --git a/packages/contentstack-export/src/export/modules-js/environments.js b/packages/contentstack-export/src/export/modules-js/environments.js index 685e0a7aba..6c8af23acf 100644 --- a/packages/contentstack-export/src/export/modules-js/environments.js +++ b/packages/contentstack-export/src/export/modules-js/environments.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ const path = require('path'); diff --git a/packages/contentstack-export/src/export/modules-js/extensions.js b/packages/contentstack-export/src/export/modules-js/extensions.js index 8dced426b5..931b6f7c46 100644 --- a/packages/contentstack-export/src/export/modules-js/extensions.js +++ b/packages/contentstack-export/src/export/modules-js/extensions.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/export/modules-js/global-fields.js b/packages/contentstack-export/src/export/modules-js/global-fields.js index 7b2ee936c3..dbbe04f850 100644 --- a/packages/contentstack-export/src/export/modules-js/global-fields.js +++ b/packages/contentstack-export/src/export/modules-js/global-fields.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/export/modules-js/labels.js b/packages/contentstack-export/src/export/modules-js/labels.js index 03e19ef4d9..9b6f4fba20 100644 --- a/packages/contentstack-export/src/export/modules-js/labels.js +++ b/packages/contentstack-export/src/export/modules-js/labels.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/export/modules-js/marketplace-apps.js b/packages/contentstack-export/src/export/modules-js/marketplace-apps.js index 88c051b651..686da41e86 100644 --- a/packages/contentstack-export/src/export/modules-js/marketplace-apps.js +++ b/packages/contentstack-export/src/export/modules-js/marketplace-apps.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ const _ = require('lodash'); diff --git a/packages/contentstack-export/src/export/modules-js/stack.js b/packages/contentstack-export/src/export/modules-js/stack.js index 4f4e8329c4..d585964c04 100644 --- a/packages/contentstack-export/src/export/modules-js/stack.js +++ b/packages/contentstack-export/src/export/modules-js/stack.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/export/modules-js/webhooks.js b/packages/contentstack-export/src/export/modules-js/webhooks.js index 32c5d5c02e..ec5e559a20 100644 --- a/packages/contentstack-export/src/export/modules-js/webhooks.js +++ b/packages/contentstack-export/src/export/modules-js/webhooks.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/export/modules-js/workflows.js b/packages/contentstack-export/src/export/modules-js/workflows.js index ec9460850c..e7cd7667ff 100644 --- a/packages/contentstack-export/src/export/modules-js/workflows.js +++ b/packages/contentstack-export/src/export/modules-js/workflows.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/utils/basic-login.ts b/packages/contentstack-export/src/utils/basic-login.ts index e324c70f97..87e1cc5932 100644 --- a/packages/contentstack-export/src/utils/basic-login.ts +++ b/packages/contentstack-export/src/utils/basic-login.ts @@ -3,7 +3,7 @@ /* eslint-disable no-empty */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-export/src/utils/file-helper.ts b/packages/contentstack-export/src/utils/file-helper.ts index a329787094..682b2bdbe6 100644 --- a/packages/contentstack-export/src/utils/file-helper.ts +++ b/packages/contentstack-export/src/utils/file-helper.ts @@ -2,12 +2,12 @@ import * as fs from 'fs'; import * as path from 'path'; import mkdirp from 'mkdirp'; import bigJSON from 'big-json'; -import { FsUtility } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; export const readFileSync = function (filePath: string, parse: boolean): unknown { let data; parse = typeof parse === 'undefined' ? true : parse; - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); if (fs.existsSync(filePath)) { data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : data; } @@ -17,7 +17,7 @@ export const readFileSync = function (filePath: string, parse: boolean): unknown // by default file type is json export const readFile = async (filePath: string, options = { type: 'json' }): Promise => { return new Promise((resolve, reject) => { - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { reject(error); @@ -35,7 +35,7 @@ export const readLargeFile = function (filePath: string, options: { type?: strin if (typeof filePath !== 'string') { return; } - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); if (fs.existsSync(filePath)) { return new Promise((resolve, reject) => { const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' }); @@ -76,7 +76,7 @@ export const writeLargeFile = function (filePath: string, data: any): Promise { const stringifyStream = bigJSON.createStringifyStream({ body: data, diff --git a/packages/contentstack-export/src/utils/logger.ts b/packages/contentstack-export/src/utils/logger.ts index 944a08e9bc..66cf7b5606 100644 --- a/packages/contentstack-export/src/utils/logger.ts +++ b/packages/contentstack-export/src/utils/logger.ts @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -8,7 +8,7 @@ import * as winston from 'winston'; import * as path from 'path'; import mkdirp from 'mkdirp'; import { ExportConfig } from '../types'; - +import { sanitizepath } from '@contentstack/cli-utilities' const slice = Array.prototype.slice; const ansiRegexPattern = [ @@ -24,7 +24,7 @@ function returnString(args: unknown[]) { if (item && typeof item === 'object') { try { return JSON.stringify(item).replace(/authtoken\":\d"blt................/g, 'authtoken":"blt....'); - } catch (error) {} + } catch (error) { } return item; } return item; @@ -58,12 +58,12 @@ let errorTransport; function init(_logPath: string) { if (!logger || !errorLogger) { - const logsDir = path.resolve(_logPath, 'logs', 'export'); + const logsDir = path.resolve(sanitizepath(_logPath), 'logs', 'export'); // Create dir if doesn't already exist mkdirp.sync(logsDir); successTransport = { - filename: path.join(logsDir, 'success.log'), + filename: path.join(sanitizepath(logsDir), 'success.log'), maxFiles: 20, maxsize: 1000000, tailable: true, @@ -71,7 +71,7 @@ function init(_logPath: string) { }; errorTransport = { - filename: path.join(logsDir, 'error.log'), + filename: path.join(sanitizepath(logsDir), 'error.log'), maxFiles: 20, maxsize: 1000000, tailable: true, diff --git a/packages/contentstack-export/src/utils/setup-branches.ts b/packages/contentstack-export/src/utils/setup-branches.ts index d2051f003f..18066e24e2 100644 --- a/packages/contentstack-export/src/utils/setup-branches.ts +++ b/packages/contentstack-export/src/utils/setup-branches.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import { writeFileSync, makeDirectory } from './file-helper'; import { isAuthenticated, configHandler } from '@contentstack/cli-utilities'; import { ExportConfig } from '../types'; +import { sanitizepath } from '@contentstack/cli-utilities'; const setupBranches = async (config: ExportConfig, stackAPIClient: any) => { if (typeof config !== 'object') { @@ -40,7 +41,7 @@ const setupBranches = async (config: ExportConfig, stackAPIClient: any) => { makeDirectory(config.exportDir); // create branch info file - writeFileSync(path.join(config.exportDir, 'branches.json'), branches); + writeFileSync(path.join(sanitizepath(config.exportDir), 'branches.json'), branches); // add branches list in the config.branches = branches; }; diff --git a/packages/contentstack-export/src/utils/setup-export-dir.ts b/packages/contentstack-export/src/utils/setup-export-dir.ts index 26cc3737b6..c925e2c52c 100644 --- a/packages/contentstack-export/src/utils/setup-export-dir.ts +++ b/packages/contentstack-export/src/utils/setup-export-dir.ts @@ -1,12 +1,13 @@ import path from 'path'; import { ExportConfig } from '../types'; import { makeDirectory } from './file-helper'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default async function setupExportDir(exportConfig: ExportConfig) { makeDirectory(exportConfig.exportDir); if (exportConfig.branches) { return Promise.all( - exportConfig.branches.map((branch) => makeDirectory(path.join(exportConfig.exportDir, branch.uid))), + exportConfig.branches.map((branch) => makeDirectory(path.join(sanitizepath(exportConfig.exportDir), sanitizepath(branch.uid)))), ); } } diff --git a/packages/contentstack-import/src/import/modules-js/assets.js b/packages/contentstack-import/src/import/modules-js/assets.js index 3ed612cd7c..2e811f1f97 100755 --- a/packages/contentstack-import/src/import/modules-js/assets.js +++ b/packages/contentstack-import/src/import/modules-js/assets.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ const fs = require('fs'); @@ -11,6 +11,7 @@ const mkdirp = require('mkdirp'); const Promise = require('bluebird'); let { default: config } = require('../../config'); const { fileHelper, log, uploadAssetHelper } = require('../../utils'); +const { sanitizepath, validateUids, validateFileName } = require('@contentstack/cli-utilities'); module.exports = class ImportAssets { assets; @@ -88,7 +89,10 @@ module.exports = class ImportAssets { // the asset has been already imported return void 0; } - let currentAssetFolderPath = path.join(self.assetsFolderPath, assetUid); + if(!validateUids(assetUid)){ + reject(`UID Not Valid`) + } + let currentAssetFolderPath = path.join(sanitizepath(self.assetsFolderPath), assetUid); if (fs.existsSync(currentAssetFolderPath)) { // if this is true, means, the exported asset data is versioned // hence, upload each asset with its version @@ -100,7 +104,10 @@ module.exports = class ImportAssets { let uidContainer = {}; let urlContainer = {}; - let assetPath = path.resolve(currentAssetFolderPath, self.assets[assetUid].filename); + if(!validateFileName(self.assets[assetUid].filename)){ + reject(`File Name Not Valid`) + } + let assetPath = path.resolve(sanitizepath(currentAssetFolderPath), self.assets[assetUid].filename); if (self.assets[assetUid].parent_uid && typeof self.assets[assetUid].parent_uid === 'string') { if (self.mappedFolderUids.hasOwnProperty(self.assets[assetUid].parent_uid)) { @@ -179,8 +186,11 @@ module.exports = class ImportAssets { uploadVersionedAssets(uid, assetFolderPath) { let self = this; return new Promise(function (resolve, reject) { + if(!validateUids(uid)){ + reject(`UID not valid`) + } let versionedAssetMetadata = fileHelper.readFileSync( - path.join(assetFolderPath, '_contentstack_' + uid + '.json'), + path.join(sanitizepath(assetFolderPath), '_contentstack_' + uid + '.json'), ); // using last version, find asset's parent let lastVersion = versionedAssetMetadata[versionedAssetMetadata.length - 1]; @@ -207,7 +217,10 @@ module.exports = class ImportAssets { versionedAssetMetadata, function () { let assetMetadata = versionedAssetMetadata[counter]; - let assetPath = path.join(assetFolderPath, assetMetadata.filename); + if(!validateFileName(assetMetadata.filename)){ + reject(`File Name not valid`) + } + let assetPath = path.join(sanitizepath(assetFolderPath), assetMetadata.filename); if (++counter === 1) { return self diff --git a/packages/contentstack-import/src/import/modules-js/content-types.js b/packages/contentstack-import/src/import/modules-js/content-types.js index 7a1f000068..1f65795e40 100755 --- a/packages/contentstack-import/src/import/modules-js/content-types.js +++ b/packages/contentstack-import/src/import/modules-js/content-types.js @@ -3,6 +3,7 @@ const path = require('path'); const chalk = require('chalk'); const { cloneDeep, find, findIndex } = require('lodash'); const { fileHelper, log, executeTask, formatError, schemaTemplate, lookupExtension } = require('../../utils'); +const { sanitizepath } = require('@contentstack/cli-utilities'); class ContentTypesImport { constructor(importConfig, stackAPIClient) { @@ -12,12 +13,12 @@ class ContentTypesImport { this.globalFieldConfig = importConfig.modules.globalfields; this.importConcurrency = this.contentTypeConfig.importConcurrency || this.importConfig.importConcurrency; this.writeConcurrency = this.contentTypeConfig.writeConcurrency || this.importConfig.writeConcurrency; - this.contentTypesFolderPath = path.join(this.importConfig.data, this.contentTypeConfig.dirName); - this.mapperFolderPath = path.join(this.importConfig.data, 'mapper', 'content_types'); - this.existingContentTypesPath = path.join(this.mapperFolderPath, 'success.json'); - this.globalFieldsFolderPath = path.resolve(this.importConfig.data, this.globalFieldConfig.dirName); - this.globalFieldMapperFolderPath = path.join(importConfig.data, 'mapper', 'global_fields', 'success.json'); - this.globalFieldPendingPath = path.join(importConfig.data, 'mapper', 'global_fields', 'pending_global_fields.js'); + this.contentTypesFolderPath = path.join(sanitizepath(this.importConfig.data), sanitizepath(this.contentTypeConfig.dirName)); + this.mapperFolderPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'content_types'); + this.existingContentTypesPath = path.join(sanitizepath(this.mapperFolderPath), 'success.json'); + this.globalFieldsFolderPath = path.resolve(sanitizepath(this.importConfig.data),sanitizepath(this.globalFieldConfig.dirName)); + this.globalFieldMapperFolderPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'success.json'); + this.globalFieldPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); this.ignoredFilesInContentTypesFolder = new Map([ ['__master.json', 'true'], ['__priority.json', 'true'], diff --git a/packages/contentstack-import/src/import/modules-js/entries.js b/packages/contentstack-import/src/import/modules-js/entries.js index 72a4a12f13..eede00bd2f 100755 --- a/packages/contentstack-import/src/import/modules-js/entries.js +++ b/packages/contentstack-import/src/import/modules-js/entries.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -20,6 +20,7 @@ const { lookupEntries, } = require('../../utils'); const { default: config } = require('../../config'); +const { sanitizepath } = require('@contentstack/cli-utilities'); const addlogs = log; module.exports = class ImportEntries { mappedAssetUidPath; @@ -838,7 +839,7 @@ module.exports = class ImportEntries { return resolve(); } self.mappedUids[query.entry.uid] = response.body.entries[0].uid; - let _ePath = path.join(this.entryMapperPath, query.locale, query.content_type, 'success.json'); + let _ePath = path.join(sanitizepath(this.entryMapperPath), sanitizepath(query.locale), sanitizepath(query.content_type), 'success.json'); let entries = fileHelper.readFileSync(_ePath); entries.push(query.entry); fileHelper.writeFileSync(_ePath, entries); diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index cf4a573195..bde12737df 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -1,7 +1,7 @@ /* eslint-disable no-prototype-builtins */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -11,6 +11,7 @@ import { fsUtil, log, formatError, schemaTemplate, lookupExtension, lookUpTaxono import { ImportConfig, ModuleClassParams } from '../../types'; import BaseClass, { ApiOptions } from './base-class'; import { updateFieldRules } from '../../utils/content-type-helper'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default class ContentTypesImport extends BaseClass { private cTsMapperPath: string; @@ -59,12 +60,12 @@ export default class ContentTypesImport extends BaseClass { this.cTsConfig = importConfig.modules['content-types']; this.gFsConfig = importConfig.modules['global-fields']; this.reqConcurrency = this.cTsConfig.writeConcurrency || this.importConfig.writeConcurrency; - this.cTsFolderPath = path.join(this.importConfig.data, this.cTsConfig.dirName); - this.cTsMapperPath = path.join(this.importConfig.data, 'mapper', 'content_types'); - this.cTsSuccessPath = path.join(this.cTsMapperPath, 'success.json'); - this.gFsFolderPath = path.resolve(this.importConfig.data, this.gFsConfig.dirName); - this.gFsMapperFolderPath = path.join(importConfig.data, 'mapper', 'global_fields', 'success.json'); - this.gFsPendingPath = path.join(importConfig.data, 'mapper', 'global_fields', 'pending_global_fields.js'); + this.cTsFolderPath = path.join(sanitizepath(this.importConfig.data), sanitizepath(this.cTsConfig.dirName)); + this.cTsMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'content_types'); + this.cTsSuccessPath = path.join(sanitizepath(this.cTsMapperPath), 'success.json'); + this.gFsFolderPath = path.resolve(sanitizepath(this.importConfig.data), sanitizepath(this.gFsConfig.dirName)); + this.gFsMapperFolderPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'success.json'); + this.gFsPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); this.marketplaceAppMapperPath = path.join(this.importConfig.data, 'mapper', 'marketplace_apps', 'uid-mapping.json'); this.ignoredFilesInContentTypesFolder = new Map([ ['__master.json', 'true'], @@ -79,8 +80,8 @@ export default class ContentTypesImport extends BaseClass { this.gFs = []; this.createdGFs = []; this.pendingGFs = []; - this.taxonomiesPath = path.join(importConfig.data, 'mapper/taxonomies', 'success.json'); - this.extPendingPath = path.join(importConfig.data, 'mapper', 'extensions', 'pending_extensions.js'); + this.taxonomiesPath = path.join(sanitizepath(importConfig.data), 'mapper/taxonomies', 'success.json'); + this.extPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'extensions', 'pending_extensions.js'); } async start(): Promise { diff --git a/packages/contentstack-import/src/import/modules/entries.ts b/packages/contentstack-import/src/import/modules/entries.ts index b3a9372c93..12fc6c22ed 100644 --- a/packages/contentstack-import/src/import/modules/entries.ts +++ b/packages/contentstack-import/src/import/modules/entries.ts @@ -1,13 +1,13 @@ /* eslint-disable no-prototype-builtins */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ import * as path from 'path'; import { isEmpty, values, cloneDeep, find, indexOf, forEach } from 'lodash'; -import { FsUtility } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; import { fsUtil, log, @@ -61,22 +61,22 @@ export default class EntriesImport extends BaseClass { constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); - this.assetUidMapperPath = path.resolve(importConfig.data, 'mapper', 'assets', 'uid-mapping.json'); - this.assetUrlMapperPath = path.resolve(importConfig.data, 'mapper', 'assets', 'url-mapping.json'); - this.entriesMapperPath = path.resolve(importConfig.data, 'mapper', 'entries'); - this.envPath = path.resolve(importConfig.data, 'environments', 'environments.json'); - this.entriesUIDMapperPath = path.join(this.entriesMapperPath, 'uid-mapping.json'); - this.uniqueUidMapperPath = path.join(this.entriesMapperPath, 'unique-mapping.json'); - this.modifiedCTsPath = path.join(this.entriesMapperPath, 'modified-schemas.json'); - this.marketplaceAppMapperPath = path.join(this.importConfig.data, 'mapper', 'marketplace_apps', 'uid-mapping.json'); - this.taxonomiesPath = path.join(this.importConfig.data, 'mapper', 'taxonomies', 'terms', 'success.json'); + this.assetUidMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'assets', 'uid-mapping.json'); + this.assetUrlMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'assets', 'url-mapping.json'); + this.entriesMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'entries'); + this.envPath = path.resolve(sanitizepath(importConfig.data), 'environments', 'environments.json'); + this.entriesUIDMapperPath = path.join(sanitizepath(this.entriesMapperPath), 'uid-mapping.json'); + this.uniqueUidMapperPath = path.join(sanitizepath(this.entriesMapperPath), 'unique-mapping.json'); + this.modifiedCTsPath = path.join(sanitizepath(this.entriesMapperPath), 'modified-schemas.json'); + this.marketplaceAppMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.taxonomiesPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'taxonomies', 'terms', 'success.json'); this.entriesConfig = importConfig.modules.entries; - this.entriesPath = path.resolve(importConfig.data, this.entriesConfig.dirName); - this.cTsPath = path.resolve(importConfig.data, importConfig.modules['content-types'].dirName); + this.entriesPath = path.resolve(sanitizepath(importConfig.data), sanitizepath(this.entriesConfig.dirName)); + this.cTsPath = path.resolve(sanitizepath(importConfig.data), sanitizepath(importConfig.modules['content-types'].dirName)); this.localesPath = path.resolve( - importConfig.data, - importConfig.modules.locales.dirName, - importConfig.modules.locales.fileName, + sanitizepath(importConfig.data), + sanitizepath(importConfig.modules.locales.dirName), + sanitizepath(importConfig.modules.locales.fileName), ); this.importConcurrency = this.entriesConfig.importConcurrency || importConfig.importConcurrency; this.entriesUidMapper = {}; diff --git a/packages/contentstack-import/src/import/modules/global-fields.ts b/packages/contentstack-import/src/import/modules/global-fields.ts index 4cb4789cd1..2c6e975d9c 100644 --- a/packages/contentstack-import/src/import/modules/global-fields.ts +++ b/packages/contentstack-import/src/import/modules/global-fields.ts @@ -1,13 +1,13 @@ /* eslint-disable no-prototype-builtins */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ import * as path from 'path'; import { isEmpty, cloneDeep } from 'lodash'; -import { cliux } from '@contentstack/cli-utilities'; +import { cliux, sanitizepath } from '@contentstack/cli-utilities'; import { GlobalFieldData } from '@contentstack/management/types/stack/globalField'; import { fsUtil, log, formatError, fileHelper, lookupExtension, removeReferenceFields } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; @@ -50,13 +50,13 @@ export default class ImportGlobalFields extends BaseClass { this.pendingGFs = []; this.existingGFs = []; this.reqConcurrency = this.gFsConfig.writeConcurrency || this.config.writeConcurrency; - this.gFsMapperPath = path.resolve(this.config.data, 'mapper', 'global_fields'); - this.gFsFolderPath = path.resolve(this.config.data, this.gFsConfig.dirName); - this.gFsFailsPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'fails.json'); - this.gFsSuccessPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'success.json'); - this.gFsUidMapperPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'uid-mapping.json'); - this.gFsPendingPath = path.resolve(this.config.data, 'mapper', 'global_fields', 'pending_global_fields.js'); - this.marketplaceAppMapperPath = path.join(this.config.data, 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.gFsMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields'); + this.gFsFolderPath = path.resolve(sanitizepath(this.config.data), this.gFsConfig.dirName); + this.gFsFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'fails.json'); + this.gFsSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'success.json'); + this.gFsUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'uid-mapping.json'); + this.gFsPendingPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'pending_global_fields.js'); + this.marketplaceAppMapperPath = path.join(sanitizepath(this.config.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); } async start(): Promise { diff --git a/packages/contentstack-import/src/import/modules/locales.ts b/packages/contentstack-import/src/import/modules/locales.ts index 5c417d8256..bf4091596d 100644 --- a/packages/contentstack-import/src/import/modules/locales.ts +++ b/packages/contentstack-import/src/import/modules/locales.ts @@ -1,13 +1,13 @@ /* eslint-disable no-prototype-builtins */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ import * as path from 'path'; import { values, isEmpty, filter, pick } from 'lodash'; -import { cliux } from '@contentstack/cli-utilities'; +import { cliux, sanitizepath } from '@contentstack/cli-utilities'; import { fsUtil, log, formatError, fileHelper } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; @@ -49,11 +49,11 @@ export default class ImportLocales extends BaseClass { this.createdLocales = []; this.failedLocales = []; this.reqConcurrency = this.localeConfig.writeConcurrency || this.config.writeConcurrency; - this.langMapperPath = path.resolve(this.config.data, 'mapper', 'languages'); - this.langFolderPath = path.resolve(this.config.data, this.localeConfig.dirName); - this.langFailsPath = path.resolve(this.config.data, 'mapper', 'languages', 'fails.json'); - this.langSuccessPath = path.resolve(this.config.data, 'mapper', 'languages', 'success.json'); - this.langUidMapperPath = path.resolve(this.config.data, 'mapper', 'languages', 'uid-mapper.json'); + this.langMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages'); + this.langFolderPath = path.resolve(sanitizepath(this.config.data), this.localeConfig.dirName); + this.langFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'fails.json'); + this.langSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'success.json'); + this.langUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'uid-mapper.json'); } async start(): Promise { diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index 48bf419a5f..c722193898 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -266,7 +266,8 @@ export const lookupAssets = function ( let uid = mappedAssetUids[assetUid]; if (typeof uid !== 'undefined') { const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - entry = entry.replace(new RegExp(escapedAssetUid, 'img'), uid); + const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img'); + entry = entry.replace(regex, uid); matchedUids.push(assetUid); } else { unmatchedUids.push(assetUid); diff --git a/packages/contentstack-import/src/utils/backup-handler.ts b/packages/contentstack-import/src/utils/backup-handler.ts index 15eda75004..96388857ce 100755 --- a/packages/contentstack-import/src/utils/backup-handler.ts +++ b/packages/contentstack-import/src/utils/backup-handler.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { copy } from 'fs-extra'; -import { cliux } from '@contentstack/cli-utilities'; +import { cliux, sanitizepath } from '@contentstack/cli-utilities'; import { fileHelper, trace } from './index'; import { ImportConfig } from '../types'; @@ -14,7 +14,7 @@ export default async function backupHandler(importConfig: ImportConfig): Promise const subDir = isSubDirectory(importConfig); if (subDir) { - backupDirPath = path.resolve(importConfig.contentDir, '..', '_backup_' + Math.floor(Math.random() * 1000)); + backupDirPath = path.resolve(sanitizepath(importConfig.contentDir), '..', '_backup_' + Math.floor(Math.random() * 1000)); if (importConfig.createBackupDir) { cliux.print( `Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, diff --git a/packages/contentstack-import/src/utils/common-helper.ts b/packages/contentstack-import/src/utils/common-helper.ts index ed402fcf42..7b398d4ef8 100644 --- a/packages/contentstack-import/src/utils/common-helper.ts +++ b/packages/contentstack-import/src/utils/common-helper.ts @@ -1,13 +1,13 @@ /* eslint-disable no-console */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ import * as _ from 'lodash'; import * as path from 'path'; -import { HttpClient, managementSDKClient, isAuthenticated } from '@contentstack/cli-utilities'; +import { HttpClient, managementSDKClient, isAuthenticated, sanitizepath } from '@contentstack/cli-utilities'; import { readFileSync, readdirSync, readFile } from './file-helper'; import chalk from 'chalk'; import { log } from './logger'; @@ -65,9 +65,9 @@ export const sanitizeStack = (importConfig: ImportConfig) => { const newStackVersion = stackDetails.data.stack.settings.version; const newStackDate = new Date(newStackVersion).toString(); const stackFilePath = path.join( - importConfig.data, - importConfig.modules.stack.dirName, - importConfig.modules.stack.fileName, + sanitizepath(importConfig.data), + sanitizepath(importConfig.modules.stack.dirName), + sanitizepath(importConfig.modules.stack.fileName), ); const oldStackDetails = readFileSync(stackFilePath); @@ -184,7 +184,7 @@ export const formatError = (error: any) => { } else { error = JSON.parse(error.message); } - } catch (e) {} + } catch (e) { } let message = error?.errorMessage || error?.error_message || error?.message || error; if (error && error.errors && Object.keys(error.errors).length > 0) { Object.keys(error.errors).forEach((e) => { @@ -244,12 +244,12 @@ export const formatDate = (date: Date = new Date()) => { .getDate() .toString() .padStart(2, '0')}T${date.getHours().toString().padStart(2, '0')}-${date - .getMinutes() - .toString() - .padStart(2, '0')}-${date.getSeconds().toString().padStart(2, '0')}-${date - .getMilliseconds() - .toString() - .padStart(3, '0')}Z`; + .getMinutes() + .toString() + .padStart(2, '0')}-${date.getSeconds().toString().padStart(2, '0')}-${date + .getMilliseconds() + .toString() + .padStart(3, '0')}Z`; return formattedDate; }; diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 1cf6e84581..7d970f0c5c 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -202,7 +202,8 @@ export const lookupEntries = function ( if (mappedUids.hasOwnProperty(uid)) { const sanitizedUid = escapeRegExp(uid); const escapedMappedUid = escapeRegExp(mappedUids[uid]); - entry = entry.replace(new RegExp(sanitizedUid, 'img'), escapedMappedUid); + const uidRegex = new RegExp(`\\b${sanitizedUid}\\b`, 'img'); + entry = entry.replace(uidRegex, escapedMappedUid); mapped.push(uid); } else { unmapped.push(uid); @@ -572,7 +573,9 @@ export const restoreJsonRteEntryRefs = ( }; function updateUids(str: string, match: string, uidMapper: Record) { - return str.replace(new RegExp(match, 'g'), (match: string) => uidMapper[match]); + const sanitizedMatch = escapeRegExp(match); + const regex = new RegExp(`\\b${sanitizedMatch}\\b`, 'g'); + return str.replace(regex, (matchedString) => uidMapper[matchedString]); } function setDirtyTrue(jsonRteChild: any) { diff --git a/packages/contentstack-import/src/utils/file-helper.ts b/packages/contentstack-import/src/utils/file-helper.ts index a8446e93cb..21f8939a0b 100644 --- a/packages/contentstack-import/src/utils/file-helper.ts +++ b/packages/contentstack-import/src/utils/file-helper.ts @@ -2,11 +2,11 @@ import * as fs from 'fs'; import * as path from 'path'; import mkdirp from 'mkdirp'; import * as bigJSON from 'big-json'; -import { FsUtility } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; export const readFileSync = function (filePath: string, parse: boolean = true): any { let data; - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); if (fs.existsSync(filePath)) { try { data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : data; @@ -20,7 +20,7 @@ export const readFileSync = function (filePath: string, parse: boolean = true): // by default file type is json export const readFile = async (filePath: string, options = { type: 'json' }): Promise => { return new Promise((resolve, reject) => { - filePath = path.resolve(filePath); + filePath = path.resolve(sanitizepath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { if (error.code === 'ENOENT') { @@ -41,7 +41,7 @@ export const readLargeFile = function (filePath: string, opts?: any): Promise { const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' }); @@ -82,7 +82,7 @@ export const writeLargeFile = function (filePath: string, data: any): Promise { const stringifyStream = bigJSON.createStringifyStream({ body: data, diff --git a/packages/contentstack-import/src/utils/import-config-handler.ts b/packages/contentstack-import/src/utils/import-config-handler.ts index 546bfd8a18..c46e4c58b8 100644 --- a/packages/contentstack-import/src/utils/import-config-handler.ts +++ b/packages/contentstack-import/src/utils/import-config-handler.ts @@ -1,7 +1,7 @@ import merge from 'merge'; import * as path from 'path'; import { omit, filter, includes, isArray } from 'lodash'; -import { configHandler, isAuthenticated, cliux } from '@contentstack/cli-utilities'; +import { configHandler, isAuthenticated, cliux, sanitizepath } from '@contentstack/cli-utilities'; import defaultConfig from '../config'; import { readFile, fileExistsSync } from './file-helper'; import { askContentDir, askAPIKey } from './interactive'; @@ -81,7 +81,7 @@ const setupConfig = async (importCmdFlags: any): Promise => { if (importCmdFlags['branch']) { config.branchName = importCmdFlags['branch']; - config.branchDir = path.join(config.contentDir, config.branchName); + config.branchDir = path.join(sanitizepath(config.contentDir), sanitizepath (config.branchName)); } if (importCmdFlags['module']) { config.moduleName = importCmdFlags['module']; diff --git a/packages/contentstack-import/src/utils/log.ts b/packages/contentstack-import/src/utils/log.ts index 7c3923a3f8..5445da302b 100644 --- a/packages/contentstack-import/src/utils/log.ts +++ b/packages/contentstack-import/src/utils/log.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { LogEntry } from 'winston/index'; -import { Logger, pathValidator } from '@contentstack/cli-utilities'; +import { Logger, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger'; import { ImportConfig } from '../types'; @@ -26,7 +26,7 @@ export function log(entryOrMessage: MessageType, logType?: LogsType, hidden?: bo export function initLogger(config?: ImportConfig | undefined) { if (!logger) { - const basePath = pathValidator(join(config?.cliLogsPath ?? process.cwd(), 'logs', 'import')); + const basePath = pathValidator(join(sanitizepath(config?.cliLogsPath ?? process.cwd()), 'logs', 'import')); logger = new Logger(Object.assign(config ?? {}, { basePath })); } diff --git a/packages/contentstack-import/src/utils/logger.ts b/packages/contentstack-import/src/utils/logger.ts index d3542c11a1..08a5ef8044 100644 --- a/packages/contentstack-import/src/utils/logger.ts +++ b/packages/contentstack-import/src/utils/logger.ts @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -8,6 +8,7 @@ import * as winston from 'winston'; import * as path from 'path'; import mkdirp from 'mkdirp'; import { ImportConfig } from '../types'; +import { sanitizepath } from '@contentstack/cli-utilities'; const slice = Array.prototype.slice; @@ -58,9 +59,9 @@ let errorTransport; function init(_logPath: string) { if (!logger || !errorLogger) { - const logsDir = path.resolve(_logPath, 'logs', 'import'); + const logsDir = path.resolve(sanitizepath(_logPath), 'logs', 'import'); successTransport = { - filename: path.join(logsDir, 'success.log'), + filename: path.join(sanitizepath(logsDir), 'success.log'), maxFiles: 20, maxsize: 1000000, tailable: true, @@ -68,7 +69,7 @@ function init(_logPath: string) { }; errorTransport = { - filename: path.join(logsDir, 'error.log'), + filename: path.join(sanitizepath(logsDir), 'error.log'), maxFiles: 20, maxsize: 1000000, tailable: true, diff --git a/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js b/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js index 56adb1458b..532e4e4116 100644 --- a/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js +++ b/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js @@ -2,7 +2,7 @@ let fs = require('fs').promises; let path = require('path') let crypto = require('crypto') let supportedLocales = require('./locales.json') -const { pathValidator } = require('@contentstack/cli-utilities') +const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities') module.exports = async ({migration, config}) => { let changeMasterLocale = { @@ -51,10 +51,10 @@ module.exports = async ({migration, config}) => { let contentTypes = await fs.readdir(pathValidator(path.resolve(config.data_dir, 'entries'))) let sourceMasterLocaleEntries, targetMasterLocaleEntries for (let contentType of contentTypes) { - sourceMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(config.data_dir, `entries/${contentType}/${masterLocale}.json`)), {encoding: 'utf8'}) + sourceMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${sanitizepath(contentType)}/${sanitizepath(masterLocale)}.json`)), {encoding: 'utf8'}) sourceMasterLocaleEntries = JSON.parse(sourceMasterLocaleEntries) - targetMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(config.data_dir, `entries/${contentType}/${config.target_locale}.json`)), { encoding: 'utf8', flag: 'a+'}) + targetMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${sanitizepath(contentType)}/${sanitizepath(config.target_locale)}.json`)), { encoding: 'utf8', flag: 'a+'}) if (targetMasterLocaleEntries.length === 0) { targetMasterLocaleEntries = {} } else { diff --git a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js index 475e1643c7..4707e4bf19 100644 --- a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js +++ b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js @@ -3,7 +3,7 @@ let { existsSync } = require('fs'); let path = require('path'); let crypto = require('crypto'); let supportedLocales = require('./locales.json'); -const { pathValidator, FsUtility } = require('@contentstack/cli-utilities'); +const { pathValidator, FsUtility, sanitizepath } = require('@contentstack/cli-utilities'); module.exports = async ({ migration, config }) => { let changeMasterLocale = { @@ -18,9 +18,9 @@ module.exports = async ({ migration, config }) => { } async function tailorData() { - let locales = await fs.readFile(pathValidator(path.resolve(config.data_dir, 'locales/locales.json')), 'utf-8'); + let locales = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/locales.json')), 'utf-8'); let masterLocale = await fs.readFile( - pathValidator(path.resolve(config.data_dir, 'locales/master-locale.json')), + pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/master-locale.json')), 'utf-8', ); @@ -49,7 +49,7 @@ module.exports = async ({ migration, config }) => { await handleEntries(masterLocale); await fs.writeFile( - pathValidator(path.resolve(config.data_dir, 'locales/locales.json')), + pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/locales.json')), JSON.stringify(locales), ); masterLocale = await fs.readFile( @@ -67,12 +67,12 @@ module.exports = async ({ migration, config }) => { } async function handleEntries(masterLocale) { - let contentTypes = await fs.readdir(pathValidator(path.resolve(config.data_dir, 'entries'))); + let contentTypes = await fs.readdir(pathValidator(path.resolve(sanitizepath(config.data_dir), 'entries'))); for (let contentType of contentTypes) { let sourceMasterLocaleEntries, targetMasterLocaleEntries; sourceMasterLocaleEntries = await fs.readFile( - pathValidator(path.resolve(config.data_dir, `entries/${contentType}/${masterLocale}/index.json`)), + pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${contentType}/${masterLocale}/index.json`)), { encoding: 'utf8' }, ); diff --git a/packages/contentstack-migration/src/commands/cm/stacks/migration.js b/packages/contentstack-migration/src/commands/cm/stacks/migration.js index cf591102bb..191a69c146 100644 --- a/packages/contentstack-migration/src/commands/cm/stacks/migration.js +++ b/packages/contentstack-migration/src/commands/cm/stacks/migration.js @@ -19,6 +19,7 @@ const { flags, isAuthenticated, pathValidator, + sanitizepath, } = require('@contentstack/cli-utilities'); const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators'); @@ -180,7 +181,7 @@ class MigrationCommand extends Command { const file = element; if (extname(file) === '.js') { // eslint-disable-next-line no-await-in-loop - await this.execSingleFile(pathValidator(resolve(filePath, file)), mapInstance); + await this.execSingleFile(pathValidator(resolve(sanitizepath(filePath), sanitizepath(file))), mapInstance); } } } catch (error) { diff --git a/packages/contentstack-migration/src/utils/logger.js b/packages/contentstack-migration/src/utils/logger.js index d6f96953c1..f23a4a2566 100644 --- a/packages/contentstack-migration/src/utils/logger.js +++ b/packages/contentstack-migration/src/utils/logger.js @@ -4,7 +4,7 @@ const { createLogger, format, transports } = require('winston'); const { resolve, join } = require('path'); const { slice } = Array.prototype; const { stringify } = JSON; -const { pathValidator } = require('@contentstack/cli-utilities'); +const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities'); const { combine, label, printf, colorize } = format; @@ -33,7 +33,7 @@ function init(logFileName) { // Create dir if does not exist makeDir(logsDir); - const logPath = pathValidator(join(logsDir, logFileName + '.log')); + const logPath = pathValidator(join(sanitizepath(logsDir), sanitizepath(logFileName) + '.log')); const logger = createLogger({ format: combine(colorize(), label({ label: 'Migration' }), customFormat), transports: [new transports.File({ filename: logPath })], diff --git a/packages/contentstack-migration/src/utils/migration-logger.js b/packages/contentstack-migration/src/utils/migration-logger.js index 0417f1e637..636a619311 100644 --- a/packages/contentstack-migration/src/utils/migration-logger.js +++ b/packages/contentstack-migration/src/utils/migration-logger.js @@ -1,14 +1,15 @@ const winston = require('winston'); const path = require('path'); +const { sanitizepath } = require('@contentstack/cli-utilities'); module.exports = class MigrationLogger { constructor(filePath) { - this.filePath = path.join(filePath, 'migration-logs'); + this.filePath = path.join(sanitizepath(filePath), 'migration-logs'); this.logger = winston.createLogger({ levels: { error: 1 }, transports: [ new winston.transports.File({ level: 'error', - filename: path.join(this.filePath, 'error.logs'), + filename: path.join(sanitizepath(this.filePath), 'error.logs'), format: winston.format.combine(winston.format.timestamp(), winston.format.json()), }), ], diff --git a/packages/contentstack-seed/src/seed/importer.ts b/packages/contentstack-seed/src/seed/importer.ts index a12d731834..106a60348b 100644 --- a/packages/contentstack-seed/src/seed/importer.ts +++ b/packages/contentstack-seed/src/seed/importer.ts @@ -1,7 +1,7 @@ import * as process from 'process'; import * as path from 'path'; import ImportCommand from '@contentstack/cli-cm-import'; -import { pathValidator } from '@contentstack/cli-utilities'; +import { pathValidator, sanitizepath } from '@contentstack/cli-utilities'; const STACK_FOLDER = 'stack'; @@ -16,7 +16,7 @@ export interface ImporterOptions { } export async function run(options: ImporterOptions) { - const importPath = pathValidator(path.resolve(options.tmpPath, STACK_FOLDER)); + const importPath = pathValidator(path.resolve(sanitizepath(options.tmpPath), STACK_FOLDER)); const args = options.alias ? ['-k', options.api_key, '-d', importPath, '--alias', options.alias!] diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index 144770fe9a..172c2871ad 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -1,5 +1,6 @@ import authHandler from './auth-handler'; import { HttpClient, cliux, configHandler } from '.'; +import { string } from '@oclif/core/lib/args'; export const isAuthenticated = () => authHandler.isAuthenticated(); export const doesBranchExist = async (stack, branchName) => { return stack @@ -53,3 +54,12 @@ export const validatePath = (input: string) => { // To escape special characters in a string export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + +// To remove the relative path +export const sanitizepath = (str: string) => str.replace(/^(\.\.(\/|\\|$))+/, ''); + +// To validate the UIDs of assets +export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); + +// Validate File name +export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); \ No newline at end of file diff --git a/packages/contentstack-utilities/src/logger.ts b/packages/contentstack-utilities/src/logger.ts index e457e22395..cc866a568c 100644 --- a/packages/contentstack-utilities/src/logger.ts +++ b/packages/contentstack-utilities/src/logger.ts @@ -3,7 +3,7 @@ import { klona } from 'klona/full'; import path, { normalize } from 'path'; import winston, { LogEntry } from 'winston'; -import { cliux as ux, PrintOptions, messageHandler } from './index'; +import { cliux as ux, PrintOptions, messageHandler, sanitizepath } from './index'; export class LoggerService { name: string; @@ -19,7 +19,7 @@ export class LoggerService { const logger = winston.createLogger({ transports: [ new winston.transports.File({ - filename: path.resolve(process.env.CS_CLI_LOG_PATH || `${pathToLog}/logs`, `${name}.log`), + filename: path.resolve(sanitizepath(process.env.CS_CLI_LOG_PATH) || `${sanitizepath(pathToLog)}/logs`, `${sanitizepath(name)}.log`), }), ], format: winston.format.combine( diff --git a/packages/contentstack/src/utils/context-handler.ts b/packages/contentstack/src/utils/context-handler.ts index 6632c9a6a7..e708ebe02e 100644 --- a/packages/contentstack/src/utils/context-handler.ts +++ b/packages/contentstack/src/utils/context-handler.ts @@ -1,6 +1,6 @@ import * as shortUUID from 'short-uuid'; import * as path from 'path'; -import { configHandler, pathValidator } from '@contentstack/cli-utilities'; +import { configHandler, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; import { machineIdSync } from 'node-machine-id'; export default class CsdxContext { @@ -48,7 +48,7 @@ export default class CsdxContext { this.plugin.name = command.pluginName; this.plugin.config = { ...((this.plugin.pjson && this.plugin.pjson.csdxConfig) || {}) }; this.messageFilePath = pathValidator( - path.resolve(this.plugin.root, this.plugin.config.messageFilePath || './messages/index.json'), + path.resolve(sanitizepath(this.plugin.root), sanitizepath(this.plugin.config.messageFilePath) || './messages/index.json'), ); this.info.shortCommandName = this.plugin?.config?.shortCommandName?.[cliOpts.id]; analyticsInfo.push(this.info.shortCommandName || cliOpts.id); From 700b8eb04ca6eab3a4842bb79fb385f571816b7c Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 17 May 2024 14:48:52 +0530 Subject: [PATCH 02/12] fix path related issues --- .../src/audit-base-command.ts | 6 ++--- .../src/bootstrap/utils.ts | 2 +- .../src/export/modules-js/assets.js | 6 ++--- .../src/export/modules-js/content-types.js | 9 ++++---- .../src/export/modules-js/entries.js | 19 +++++++-------- .../src/export/modules-js/global-fields.js | 7 +++--- .../src/export/modules-js/locales.js | 3 ++- .../src/export/modules/content-types.ts | 9 ++++---- .../src/export/modules/entries.ts | 23 ++++++++++--------- .../src/export/modules/global-fields.ts | 7 +++--- .../src/export/modules/locales.ts | 3 ++- .../src/utils/common-helper.ts | 7 +++--- .../src/import/modules-js/assets.js | 8 +++---- .../src/import/modules-js/environments.js | 2 +- .../src/import/modules-js/extensions.js | 2 +- .../src/import/modules-js/global-fields.js | 2 +- .../src/import/modules-js/labels.js | 2 +- .../src/import/modules-js/locales.js | 2 +- .../src/import/modules-js/marketplace-apps.js | 2 +- .../src/import/modules-js/webhooks.js | 2 +- .../src/import/modules-js/workflows.js | 2 +- .../src/import/modules/content-types.ts | 2 +- .../src/import/modules/entries.ts | 6 ++--- .../src/import/modules/global-fields.ts | 2 +- .../src/import/modules/locales.ts | 2 +- .../src/utils/content-type-helper.ts | 2 +- .../src/utils/extension-helper.ts | 2 +- .../src/utils/file-helper.ts | 2 +- .../src/utils/login-handler.ts | 2 +- .../05-Update-reference-entry-from-mapper.js | 4 ++-- ...change-master-locale-new-file-structure.js | 4 ++-- 31 files changed, 81 insertions(+), 72 deletions(-) diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 6709bf037b..a3fc677772 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid'; import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; import cloneDeep from 'lodash/cloneDeep'; -import { cliux, ux } from '@contentstack/cli-utilities'; +import { cliux, sanitizepath, ux } from '@contentstack/cli-utilities'; import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'; import config from './config'; @@ -396,7 +396,7 @@ export abstract class AuditBaseCommand extends BaseCommand, ): Promise { if(Object.keys(config.moduleConfig).includes(moduleName)){ - const csvPath = join(this.sharedConfig.reportPath, `${moduleName}.csv`); + const csvPath = join(sanitizepath(this.sharedConfig.reportPath), `${sanitizepath(moduleName)}.csv`); return new Promise((resolve, reject) => { // file deepcode ignore MissingClose: Will auto close once csv stream end const ws = createWriteStream(csvPath).on('error', reject); diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index cdc91fb24e..21756a763e 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -221,7 +221,7 @@ const envFileHandler = async ( !isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : '' } \n\t } \n };`; fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`; - filePath = pathValidator(path.join(clonedDirectory, 'src', 'environments', fileName)); + filePath = pathValidator(path.join(sanitizepath(clonedDirectory), 'src', 'environments', sanitizepath(fileName))); result = await writeEnvFile(content, filePath); break; case 'angular-starter': diff --git a/packages/contentstack-export/src/export/modules-js/assets.js b/packages/contentstack-export/src/export/modules-js/assets.js index 222b42ee4d..9b485c6b6f 100644 --- a/packages/contentstack-export/src/export/modules-js/assets.js +++ b/packages/contentstack-export/src/export/modules-js/assets.js @@ -283,7 +283,7 @@ module.exports = class ExportAssets { if (version <= 0) { if(validateUids(uid)){ - const assetVersionInfoFile = path.resolve(self.assetsFolderPath, uid, '_contentstack_' + uid + '.json'); + const assetVersionInfoFile = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(uid), '_contentstack_' + sanitizepath(uid) + '.json'); fileHelper.writeFileSync(assetVersionInfoFile, assetVersionInfo); return resolve(); } @@ -332,8 +332,8 @@ module.exports = class ExportAssets { if(!validateUids(asset.uid) && !validateFileName(asset.filename)) { reject(`UIDs not valid`) } - const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), asset.uid); - const assetFilePath = path.resolve(sanitizepath(assetFolderPath), asset.filename); + const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(asset.uid)); + const assetFilePath = path.resolve(sanitizepath(assetFolderPath), sanitizepath(asset.filename)); if (fs.existsSync(assetFilePath)) { log( diff --git a/packages/contentstack-export/src/export/modules-js/content-types.js b/packages/contentstack-export/src/export/modules-js/content-types.js index 058525a5bf..c509026d7a 100644 --- a/packages/contentstack-export/src/export/modules-js/content-types.js +++ b/packages/contentstack-export/src/export/modules-js/content-types.js @@ -1,6 +1,7 @@ const path = require('path'); const chalk = require('chalk'); const { fileHelper, executeTask, formatError, log } = require('../../utils'); +const { sanitizepath } = require('@contentstack/cli-utilities'); class ContentTypesExport { constructor(exportConfig, stackAPIClient) { @@ -18,9 +19,9 @@ class ContentTypesExport { this.qs.uid = { $in: this.exportConfig.contentTypes }; } this.contentTypesPath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - this.contentTypesConfig.dirName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName) || '', + sanitizepath(this.contentTypesConfig.dirName), ); this.contentTypes = []; this.fetchConcurrency = this.contentTypesConfig.fetchConcurrency || this.exportConfig.fetchConcurrency; @@ -76,7 +77,7 @@ class ContentTypesExport { async writeContentTypes(contentTypes) { function write(contentType) { return fileHelper.writeFile( - path.join(this.contentTypesPath, `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), + path.join(sanitizepath(this.contentTypesPath), `${sanitizepath (contentType.uid === 'schema' ? 'schema|1' : contentType.uid)}.json`), contentType, ); } diff --git a/packages/contentstack-export/src/export/modules-js/entries.js b/packages/contentstack-export/src/export/modules-js/entries.js index e3aaf126e0..bccdc15e5b 100644 --- a/packages/contentstack-export/src/export/modules-js/entries.js +++ b/packages/contentstack-export/src/export/modules-js/entries.js @@ -2,23 +2,24 @@ const path = require('path'); const chalk = require('chalk'); const { values } = require('lodash'); const { executeTask, formatError, fileHelper, log } = require('../../utils'); +const { sanitizepath } = require('@contentstack/cli-utilities'); class EntriesExport { constructor(exportConfig, stackAPIClient) { this.stackAPIClient = stackAPIClient; this.exportConfig = exportConfig; this.entriesConfig = exportConfig.modules.entries; - this.entriesRootPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName); + this.entriesRootPath = path.resolve((sanitizepath(exportConfig.data)), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName)); this.localesFilePath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - exportConfig.modules.locales.dirName, - exportConfig.modules.locales.fileName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(exportConfig.modules.locales.dirName), + sanitizepath(exportConfig.modules.locales.fileName), ); this.schemaFilePath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - exportConfig.modules.content_types.dirName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(exportConfig.modules.content_types.dirName), 'schema.json', ); this.fetchConcurrency = this.entriesConfig.fetchConcurrency || exportConfig.fetchConcurrency; @@ -78,7 +79,7 @@ class EntriesExport { if (versionedEntries.length > 0) { const write = (versionedEntry) => fileHelper.writeFile( - path.join(versionedEntryPath, 'version-' + versionedEntry._version + '.json'), + path.join(sanitizepath(versionedEntryPath), 'version-' + sanitizepath(versionedEntry._version) + '.json'), versionedEntry, ); await executeTask(versionedEntries, write.bind(this), { concurrency: this.writeConcurrency }); diff --git a/packages/contentstack-export/src/export/modules-js/global-fields.js b/packages/contentstack-export/src/export/modules-js/global-fields.js index dbbe04f850..b6849c4c2a 100644 --- a/packages/contentstack-export/src/export/modules-js/global-fields.js +++ b/packages/contentstack-export/src/export/modules-js/global-fields.js @@ -10,6 +10,7 @@ const mkdirp = require('mkdirp'); const { merge } = require('lodash'); const { formatError, log, fileHelper } = require('../../utils'); const { default: config } = require('../../config'); +const { sanitizepath } = require('@contentstack/cli-utilities'); module.exports = class ExportGlobalFields { limit = 100; @@ -34,9 +35,9 @@ module.exports = class ExportGlobalFields { this.config = merge(config, exportConfig); this.stackAPIClient = stackAPIClient; this.globalfieldsFolderPath = path.resolve( - this.config.data, - this.config.branchName || '', - this.globalfieldsConfig.dirName, + sanitizepath(this.config.data), + sanitizepath(this.config.branchName || ''), + sanitizepath(this.globalfieldsConfig.dirName), ); } diff --git a/packages/contentstack-export/src/export/modules-js/locales.js b/packages/contentstack-export/src/export/modules-js/locales.js index 9aac775951..916a9b1986 100644 --- a/packages/contentstack-export/src/export/modules-js/locales.js +++ b/packages/contentstack-export/src/export/modules-js/locales.js @@ -1,6 +1,7 @@ const path = require('path'); const chalk = require('chalk'); const { formatError, log, fileHelper } = require('../../utils'); +const { sanitizepath } = require('@contentstack/cli-utilities'); class LocaleExport { constructor(exportConfig, stackAPIClient) { this.stackAPIClient = stackAPIClient; @@ -15,7 +16,7 @@ class LocaleExport { }, }; - this.localesPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.localeConfig.dirName); + this.localesPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.localeConfig.dirName)); this.locales = {}; this.masterLocale = {}; this.fetchConcurrency = this.localeConfig.fetchConcurrency || this.exportConfig.fetchConcurrency; diff --git a/packages/contentstack-export/src/export/modules/content-types.ts b/packages/contentstack-export/src/export/modules/content-types.ts index 54ccdbd8c1..a70a1494b4 100644 --- a/packages/contentstack-export/src/export/modules/content-types.ts +++ b/packages/contentstack-export/src/export/modules/content-types.ts @@ -3,6 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil, executeTask } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default class ContentTypesExport extends BaseClass { private stackAPIClient: ReturnType; @@ -43,9 +44,9 @@ export default class ContentTypesExport extends BaseClass { } this.contentTypesDirPath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - this.contentTypesConfig.dirName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(this.contentTypesConfig.dirName), ); this.contentTypes = []; } @@ -98,7 +99,7 @@ export default class ContentTypesExport extends BaseClass { async writeContentTypes(contentTypes: Record[]) { function write(contentType: Record) { return fsUtil.writeFile( - path.join(this.contentTypesDirPath, `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), + path.join(sanitizepath(this.contentTypesDirPath), `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), contentType, ); } diff --git a/packages/contentstack-export/src/export/modules/entries.ts b/packages/contentstack-export/src/export/modules/entries.ts index b1981929cf..2eb7165735 100644 --- a/packages/contentstack-export/src/export/modules/entries.ts +++ b/packages/contentstack-export/src/export/modules/entries.ts @@ -3,6 +3,7 @@ import { ContentstackClient, FsUtility } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass, { ApiOptions } from './base-class'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default class EntriesExport extends BaseClass { private stackAPIClient: ReturnType; @@ -28,17 +29,17 @@ export default class EntriesExport extends BaseClass { this.stackAPIClient = stackAPIClient; this.exportConfig = exportConfig; this.entriesConfig = exportConfig.modules.entries; - this.entriesDirPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.entriesConfig.dirName); + this.entriesDirPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName)); this.localesFilePath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - exportConfig.modules.locales.dirName, - exportConfig.modules.locales.fileName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(exportConfig.modules.locales.dirName), + sanitizepath(exportConfig.modules.locales.fileName), ); this.schemaFilePath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - exportConfig.modules.content_types.dirName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(exportConfig.modules.content_types.dirName), 'schema.json', ); } @@ -118,7 +119,7 @@ export default class EntriesExport extends BaseClass { if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) { if (options.skip === 0) { - const entryBasePath = path.join(this.entriesDirPath, options.contentType, options.locale); + const entryBasePath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType), sanitizepath(options.locale)); await fsUtil.makeDirectory(entryBasePath); this.entriesFileHelper = new FsUtility({ moduleName: 'entries', @@ -131,7 +132,7 @@ export default class EntriesExport extends BaseClass { } this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true }); if (this.entriesConfig.exportVersions) { - let versionedEntryPath = path.join(this.entriesDirPath, options.contentType, options.locale, 'versions'); + let versionedEntryPath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType),sanitizepath(options.locale), 'versions'); fsUtil.makeDirectory(versionedEntryPath); await this.fetchEntriesVersions(entriesSearchResponse.items, { locale: options.locale, @@ -152,7 +153,7 @@ export default class EntriesExport extends BaseClass { options: { locale: string; contentType: string; versionedEntryPath: string }, ): Promise { const onSuccess = ({ response, apiData: entry }: any) => { - fsUtil.writeFile(path.join(options.versionedEntryPath, `${entry.uid}.json`), response); + fsUtil.writeFile(path.join(sanitizepath(options.versionedEntryPath), `${entry.uid}.json`), response); log( this.exportConfig, `Exported versioned entries of type '${options.contentType}' locale '${options.locale}'`, diff --git a/packages/contentstack-export/src/export/modules/global-fields.ts b/packages/contentstack-export/src/export/modules/global-fields.ts index 6a364a7656..fc178fa0cd 100644 --- a/packages/contentstack-export/src/export/modules/global-fields.ts +++ b/packages/contentstack-export/src/export/modules/global-fields.ts @@ -3,6 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default class GlobalFieldsExport extends BaseClass { private stackAPIClient: ReturnType; @@ -35,9 +36,9 @@ export default class GlobalFieldsExport extends BaseClass { limit: this.globalFieldsConfig.limit, }; this.globalFieldsDirPath = path.resolve( - exportConfig.data, - exportConfig.branchName || '', - this.globalFieldsConfig.dirName, + sanitizepath(exportConfig.data), + sanitizepath(exportConfig.branchName || ''), + sanitizepath(this.globalFieldsConfig.dirName), ); this.globalFields = []; } diff --git a/packages/contentstack-export/src/export/modules/locales.ts b/packages/contentstack-export/src/export/modules/locales.ts index 5043882215..3926483831 100644 --- a/packages/contentstack-export/src/export/modules/locales.ts +++ b/packages/contentstack-export/src/export/modules/locales.ts @@ -3,6 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; +import { sanitizepath } from '@contentstack/cli-utilities'; export default class LocaleExport extends BaseClass { private stackAPIClient: ReturnType; @@ -40,7 +41,7 @@ export default class LocaleExport extends BaseClass { BASE: this.localeConfig.requiredKeys, }, }; - this.localesPath = path.resolve(exportConfig.data, exportConfig.branchName || '', this.localeConfig.dirName); + this.localesPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''),sanitizepath(this.localeConfig.dirName)); this.locales = {}; this.masterLocale = {}; } diff --git a/packages/contentstack-export/src/utils/common-helper.ts b/packages/contentstack-export/src/utils/common-helper.ts index c0c45cc058..2e608ec854 100644 --- a/packages/contentstack-export/src/utils/common-helper.ts +++ b/packages/contentstack-export/src/utils/common-helper.ts @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ @@ -9,6 +9,7 @@ import * as path from 'path'; import { isAuthenticated } from '@contentstack/cli-utilities'; import { ExternalConfig, ExportConfig } from '../types'; import { fsUtil } from './file-helper'; +import { sanitizepath } from '@contentstack/cli-utilities'; export const validateConfig = function (config: ExternalConfig) { if (!config.host || !config.cdn) { @@ -83,7 +84,7 @@ export const executeTask = function ( export const writeExportMetaFile = (exportConfig: ExportConfig, metaFilePath?: string) => { const exportMeta = { contentVersion: exportConfig.contentVersion, - logsPath: path.join(exportConfig.exportDir, 'logs', 'export'), + logsPath: path.join(sanitizepath(exportConfig.exportDir), 'logs', 'export'), }; - fsUtil.writeFile(path.join(metaFilePath || exportConfig.exportDir, 'export-info.json'), exportMeta); + fsUtil.writeFile(path.join(sanitizepath(metaFilePath || exportConfig.exportDir), 'export-info.json'), exportMeta); }; diff --git a/packages/contentstack-import/src/import/modules-js/assets.js b/packages/contentstack-import/src/import/modules-js/assets.js index 2e811f1f97..fbe117734e 100755 --- a/packages/contentstack-import/src/import/modules-js/assets.js +++ b/packages/contentstack-import/src/import/modules-js/assets.js @@ -92,7 +92,7 @@ module.exports = class ImportAssets { if(!validateUids(assetUid)){ reject(`UID Not Valid`) } - let currentAssetFolderPath = path.join(sanitizepath(self.assetsFolderPath), assetUid); + let currentAssetFolderPath = path.join(sanitizepath(self.assetsFolderPath), sanitizepath(assetUid)); if (fs.existsSync(currentAssetFolderPath)) { // if this is true, means, the exported asset data is versioned // hence, upload each asset with its version @@ -107,7 +107,7 @@ module.exports = class ImportAssets { if(!validateFileName(self.assets[assetUid].filename)){ reject(`File Name Not Valid`) } - let assetPath = path.resolve(sanitizepath(currentAssetFolderPath), self.assets[assetUid].filename); + let assetPath = path.resolve(sanitizepath(currentAssetFolderPath), sanitizepath(self.assets[assetUid].filename)); if (self.assets[assetUid].parent_uid && typeof self.assets[assetUid].parent_uid === 'string') { if (self.mappedFolderUids.hasOwnProperty(self.assets[assetUid].parent_uid)) { @@ -190,7 +190,7 @@ module.exports = class ImportAssets { reject(`UID not valid`) } let versionedAssetMetadata = fileHelper.readFileSync( - path.join(sanitizepath(assetFolderPath), '_contentstack_' + uid + '.json'), + path.join(sanitizepath(assetFolderPath), '_contentstack_' + sanitizepath(uid) + '.json'), ); // using last version, find asset's parent let lastVersion = versionedAssetMetadata[versionedAssetMetadata.length - 1]; @@ -220,7 +220,7 @@ module.exports = class ImportAssets { if(!validateFileName(assetMetadata.filename)){ reject(`File Name not valid`) } - let assetPath = path.join(sanitizepath(assetFolderPath), assetMetadata.filename); + let assetPath = path.join(sanitizepath(assetFolderPath), sanitizepath(assetMetadata.filename)); if (++counter === 1) { return self diff --git a/packages/contentstack-import/src/import/modules-js/environments.js b/packages/contentstack-import/src/import/modules-js/environments.js index d56650fe4e..3da28de070 100755 --- a/packages/contentstack-import/src/import/modules-js/environments.js +++ b/packages/contentstack-import/src/import/modules-js/environments.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/extensions.js b/packages/contentstack-import/src/import/modules-js/extensions.js index 42145aec2d..47f1031b9c 100644 --- a/packages/contentstack-import/src/import/modules-js/extensions.js +++ b/packages/contentstack-import/src/import/modules-js/extensions.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/global-fields.js b/packages/contentstack-import/src/import/modules-js/global-fields.js index e830271aa2..12ea4a4d86 100644 --- a/packages/contentstack-import/src/import/modules-js/global-fields.js +++ b/packages/contentstack-import/src/import/modules-js/global-fields.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/labels.js b/packages/contentstack-import/src/import/modules-js/labels.js index 32dc585cd7..b685f78d23 100644 --- a/packages/contentstack-import/src/import/modules-js/labels.js +++ b/packages/contentstack-import/src/import/modules-js/labels.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/locales.js b/packages/contentstack-import/src/import/modules-js/locales.js index fd8eba0cf4..1b2d12828c 100755 --- a/packages/contentstack-import/src/import/modules-js/locales.js +++ b/packages/contentstack-import/src/import/modules-js/locales.js @@ -1,7 +1,7 @@ /* eslint-disable no-prototype-builtins */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/marketplace-apps.js b/packages/contentstack-import/src/import/modules-js/marketplace-apps.js index 44ac6102a7..a651cb8aef 100644 --- a/packages/contentstack-import/src/import/modules-js/marketplace-apps.js +++ b/packages/contentstack-import/src/import/modules-js/marketplace-apps.js @@ -1,6 +1,6 @@ /*! * Contentstack Export - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ const fs = require('fs'); diff --git a/packages/contentstack-import/src/import/modules-js/webhooks.js b/packages/contentstack-import/src/import/modules-js/webhooks.js index 5d89090631..fb5c573e47 100644 --- a/packages/contentstack-import/src/import/modules-js/webhooks.js +++ b/packages/contentstack-import/src/import/modules-js/webhooks.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules-js/workflows.js b/packages/contentstack-import/src/import/modules-js/workflows.js index f782201075..494dbc3c41 100644 --- a/packages/contentstack-import/src/import/modules-js/workflows.js +++ b/packages/contentstack-import/src/import/modules-js/workflows.js @@ -1,6 +1,6 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index bde12737df..f9cfb23b59 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -66,7 +66,7 @@ export default class ContentTypesImport extends BaseClass { this.gFsFolderPath = path.resolve(sanitizepath(this.importConfig.data), sanitizepath(this.gFsConfig.dirName)); this.gFsMapperFolderPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'success.json'); this.gFsPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); - this.marketplaceAppMapperPath = path.join(this.importConfig.data, 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.marketplaceAppMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); this.ignoredFilesInContentTypesFolder = new Map([ ['__master.json', 'true'], ['__priority.json', 'true'], diff --git a/packages/contentstack-import/src/import/modules/entries.ts b/packages/contentstack-import/src/import/modules/entries.ts index 12fc6c22ed..03f65222da 100644 --- a/packages/contentstack-import/src/import/modules/entries.ts +++ b/packages/contentstack-import/src/import/modules/entries.ts @@ -336,7 +336,7 @@ export default class EntriesImport extends BaseClass { ); entry.uid = oldUid; entry.entryOldUid = oldUid; - entry.sourceEntryFilePath = path.join(basePath, additionalInfo.entryFileName); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily entriesCreateFileHelper.writeIntoFile({ [oldUid]: entry } as any, { mapKeyVal: true }); } else { log(this.importConfig, `Created entry: '${entry.title}' of content type ${cTUid} in locale ${locale}`, 'info'); @@ -348,7 +348,7 @@ export default class EntriesImport extends BaseClass { this.autoCreatedEntries.push({ cTUid, locale, entryUid: response.uid }); } this.entriesUidMapper[entry.uid] = response.uid; - entry.sourceEntryFilePath = path.join(basePath, additionalInfo.entryFileName); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily entry.entryOldUid = entry.uid; // stores old uid temporarily entriesCreateFileHelper.writeIntoFile({ [entry.uid]: entry } as any, { mapKeyVal: true }); } @@ -360,7 +360,7 @@ export default class EntriesImport extends BaseClass { if (error?.errors?.title || error?.errors?.uid) { if (this.importConfig.replaceExisting) { entry.entryOldUid = uid; - entry.sourceEntryFilePath = path.join(basePath, additionalInfo.entryFileName); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily existingEntriesFileHelper.writeIntoFile({ [uid]: entry } as any, { mapKeyVal: true }); } if (!this.importConfig.skipExisting) { diff --git a/packages/contentstack-import/src/import/modules/global-fields.ts b/packages/contentstack-import/src/import/modules/global-fields.ts index 2c6e975d9c..8fdd549ac6 100644 --- a/packages/contentstack-import/src/import/modules/global-fields.ts +++ b/packages/contentstack-import/src/import/modules/global-fields.ts @@ -51,7 +51,7 @@ export default class ImportGlobalFields extends BaseClass { this.existingGFs = []; this.reqConcurrency = this.gFsConfig.writeConcurrency || this.config.writeConcurrency; this.gFsMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields'); - this.gFsFolderPath = path.resolve(sanitizepath(this.config.data), this.gFsConfig.dirName); + this.gFsFolderPath = path.resolve(sanitizepath(this.config.data), sanitizepath(this.gFsConfig.dirName)); this.gFsFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'fails.json'); this.gFsSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'success.json'); this.gFsUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'uid-mapping.json'); diff --git a/packages/contentstack-import/src/import/modules/locales.ts b/packages/contentstack-import/src/import/modules/locales.ts index bf4091596d..e4afdee4c9 100644 --- a/packages/contentstack-import/src/import/modules/locales.ts +++ b/packages/contentstack-import/src/import/modules/locales.ts @@ -50,7 +50,7 @@ export default class ImportLocales extends BaseClass { this.failedLocales = []; this.reqConcurrency = this.localeConfig.writeConcurrency || this.config.writeConcurrency; this.langMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages'); - this.langFolderPath = path.resolve(sanitizepath(this.config.data), this.localeConfig.dirName); + this.langFolderPath = path.resolve(sanitizepath(this.config.data), sanitizepath(this.localeConfig.dirName)); this.langFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'fails.json'); this.langSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'success.json'); this.langUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'uid-mapper.json'); diff --git a/packages/contentstack-import/src/utils/content-type-helper.ts b/packages/contentstack-import/src/utils/content-type-helper.ts index d096392229..3e3b30ef35 100644 --- a/packages/contentstack-import/src/utils/content-type-helper.ts +++ b/packages/contentstack-import/src/utils/content-type-helper.ts @@ -46,7 +46,7 @@ export const schemaTemplate = { /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-import/src/utils/extension-helper.ts b/packages/contentstack-import/src/utils/extension-helper.ts index 976d1b326a..073fcc1551 100644 --- a/packages/contentstack-import/src/utils/extension-helper.ts +++ b/packages/contentstack-import/src/utils/extension-helper.ts @@ -4,7 +4,7 @@ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ import { join } from 'node:path'; diff --git a/packages/contentstack-import/src/utils/file-helper.ts b/packages/contentstack-import/src/utils/file-helper.ts index 21f8939a0b..9429f6479b 100644 --- a/packages/contentstack-import/src/utils/file-helper.ts +++ b/packages/contentstack-import/src/utils/file-helper.ts @@ -117,7 +117,7 @@ export const readdirSync = function (dirPath: string): any { export const isFolderExist = async (folderPath: string): Promise => { return new Promise((resolve, reject) => { - folderPath = path.resolve(folderPath); + folderPath = path.resolve(sanitizepath(folderPath)); fs.access(folderPath, (error) => { if (error) { return resolve(false); diff --git a/packages/contentstack-import/src/utils/login-handler.ts b/packages/contentstack-import/src/utils/login-handler.ts index e908417619..996e7797a8 100644 --- a/packages/contentstack-import/src/utils/login-handler.ts +++ b/packages/contentstack-import/src/utils/login-handler.ts @@ -3,7 +3,7 @@ /* eslint-disable no-empty */ /*! * Contentstack Import - * Copyright (c) 2019 Contentstack LLC + * Copyright (c) 2024 Contentstack LLC * MIT Licensed */ diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js index 33d9c25229..064b3cc546 100644 --- a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -8,9 +8,9 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf let uidMapping = {}; modules.forEach((module) => { - const mappingFilePath = path.join(filePath, 'mapper', module, 'uid-mapping.json'); + const mappingFilePath = path.join(sanitizepath(filePath), 'mapper', sanitizepath(module), 'uid-mapping.json'); if (fs.existsSync(mappingFilePath)) { - const mappedIds = JSON.parse(fs.readFileSync(mappingFilePath, 'utf-8')); + const mappedIds = JSON.parse(fs.readFileSync(sanitizepath(mappingFilePath), 'utf-8')); if (module === 'marketplace_apps') { Object.values(mappedIds).forEach((ids) => Object.assign(uidMapping, ids)); diff --git a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js index 4707e4bf19..de922494fa 100644 --- a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js +++ b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js @@ -79,8 +79,8 @@ module.exports = async ({ migration, config }) => { sourceMasterLocaleEntries = await fs.readFile( pathValidator( path.resolve( - config.data_dir, - `entries/${contentType}/${masterLocale}/${Object.values(JSON.parse(sourceMasterLocaleEntries))}`, + sanitizepath(config.data_dir), + `entries/${sanitizepath(contentType)}/${sanitizepath(masterLocale)}/${Object.values(JSON.parse(sanitizepath(sourceMasterLocaleEntries)))}`, ), ), { encoding: 'utf8' }, From 965df09694de9c08bb562d44f46364ccb9d78888 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 17 May 2024 14:57:02 +0530 Subject: [PATCH 03/12] variable update --- package-lock.json | 18 +++++----- .../src/audit-base-command.ts | 6 ++-- .../src/modules/content-types.ts | 4 +-- .../contentstack-audit/src/modules/entries.ts | 4 +-- .../src/modules/extensions.ts | 4 +-- .../src/modules/workflows.ts | 4 +-- .../src/bootstrap/index.ts | 4 +-- .../src/bootstrap/utils.ts | 16 ++++----- .../contentstack-branches/src/utils/index.ts | 6 ++-- .../contentstack-bulk-publish/copyLogs.js | 4 +-- .../src/consumer/publish.js | 4 +-- .../src/util/logger.js | 6 ++-- .../contentstack-clone/src/lib/util/log.js | 6 ++-- .../src/export/modules-js/assets.js | 8 ++--- .../src/export/modules-js/content-types.js | 10 +++--- .../src/export/modules-js/entries.js | 20 +++++------ .../src/export/modules-js/global-fields.js | 8 ++--- .../src/export/modules-js/locales.js | 4 +-- .../src/export/modules/content-types.ts | 10 +++--- .../src/export/modules/entries.ts | 24 ++++++------- .../src/export/modules/global-fields.ts | 8 ++--- .../src/export/modules/locales.ts | 4 +-- .../src/utils/common-helper.ts | 6 ++-- .../src/utils/file-helper.ts | 10 +++--- .../contentstack-export/src/utils/logger.ts | 8 ++--- .../src/utils/setup-branches.ts | 4 +-- .../src/utils/setup-export-dir.ts | 4 +-- .../src/import/modules-js/assets.js | 10 +++--- .../src/import/modules-js/content-types.js | 14 ++++---- .../src/import/modules-js/entries.js | 4 +-- .../src/import/modules/content-types.ts | 20 +++++------ .../src/import/modules/entries.ts | 36 +++++++++---------- .../src/import/modules/global-fields.ts | 16 ++++----- .../src/import/modules/locales.ts | 12 +++---- .../src/utils/backup-handler.ts | 4 +-- .../src/utils/common-helper.ts | 8 ++--- .../src/utils/file-helper.ts | 12 +++---- .../src/utils/import-config-handler.ts | 4 +-- packages/contentstack-import/src/utils/log.ts | 4 +-- .../contentstack-import/src/utils/logger.ts | 8 ++--- .../05-Update-reference-entry-from-mapper.js | 4 +-- .../01-change-master-locale.js | 6 ++-- ...change-master-locale-new-file-structure.js | 16 ++++----- .../src/commands/cm/stacks/migration.js | 4 +-- .../src/utils/logger.js | 4 +-- .../src/utils/migration-logger.js | 6 ++-- .../contentstack-seed/src/seed/importer.ts | 4 +-- .../contentstack-utilities/src/helpers.ts | 2 +- packages/contentstack-utilities/src/logger.ts | 4 +-- .../contentstack/src/utils/context-handler.ts | 4 +-- 50 files changed, 210 insertions(+), 210 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8e0809418e..a14ad02d7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3467,9 +3467,9 @@ "dev": true }, "node_modules/@types/lodash": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.1.tgz", - "integrity": "sha512-X+2qazGS3jxLAIz5JDXDzglAF3KpijdhFxlf/V1+hEsOUc+HnWi81L/uv/EvGuV90WY+7mPGFCUDGfQC3Gj95Q==" + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.4.tgz", + "integrity": "sha512-wYCP26ZLxaT3R39kiN2+HcJ4kTd3U1waI/cY7ivWYqFP6pW3ZNpvi6Wd6PHZx7T/t8z0vlkXMg3QYLa7DZ/IJQ==" }, "node_modules/@types/markdown-it": { "version": "14.1.1", @@ -4528,9 +4528,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1621.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1621.0.tgz", - "integrity": "sha512-v6rxF1u0GpQG1Y9Wul9iaqulSV2uEnp0kHKd6/lZcvEgTYhtJ8N0hOLfqRSWHjH5PaIa46hR9zSAp51r8DJ/OA==", + "version": "2.1622.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1622.0.tgz", + "integrity": "sha512-ff/jc1XwSCWDcqa7ezLLsqRbs1IVPXMoUTMFHHYRTuNwGQDn/073DbmyLkqD4ARBcTxkOooSaP7uySoZ2ekFeg==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -6807,9 +6807,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.772", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.772.tgz", - "integrity": "sha512-jFfEbxR/abTTJA3ci+2ok1NTuOBBtB4jH+UT6PUmRN+DY3WSD4FFRsgoVQ+QNIJ0T7wrXwzsWCI2WKC46b++2A==", + "version": "1.4.773", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.773.tgz", + "integrity": "sha512-87eHF+h3PlCRwbxVEAw9KtK3v7lWfc/sUDr0W76955AdYTG4bV/k0zrl585Qnj/skRMH2qOSiE+kqMeOQ+LOpw==", "dev": true }, "node_modules/elegant-spinner": { diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index a3fc677772..3951be0e17 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -5,7 +5,7 @@ import { v4 as uuid } from 'uuid'; import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; import cloneDeep from 'lodash/cloneDeep'; -import { cliux, sanitizepath, ux } from '@contentstack/cli-utilities'; +import { cliux, sanitizePath, ux } from '@contentstack/cli-utilities'; import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'; import config from './config'; @@ -396,7 +396,7 @@ export abstract class AuditBaseCommand extends BaseCommand, ): Promise { if(Object.keys(config.moduleConfig).includes(moduleName)){ - const csvPath = join(sanitizepath(this.sharedConfig.reportPath), `${sanitizepath(moduleName)}.csv`); + const csvPath = join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.csv`); return new Promise((resolve, reject) => { // file deepcode ignore MissingClose: Will auto close once csv stream end const ws = createWriteStream(csvPath).on('error', reject); diff --git a/packages/contentstack-audit/src/modules/content-types.ts b/packages/contentstack-audit/src/modules/content-types.ts index a0b5e733b5..069ac06920 100644 --- a/packages/contentstack-audit/src/modules/content-types.ts +++ b/packages/contentstack-audit/src/modules/content-types.ts @@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; -import { sanitizepath, ux } from '@contentstack/cli-utilities'; +import { sanitizePath, ux } from '@contentstack/cli-utilities'; import { LogFn, @@ -53,7 +53,7 @@ export default class ContentType { this.gfSchema = gfSchema; this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); + this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); } validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index 4baa28ca28..0544f0d7e7 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -3,7 +3,7 @@ import find from 'lodash/find'; import values from 'lodash/values'; import isEmpty from 'lodash/isEmpty'; import { join, resolve } from 'path'; -import { ux, FsUtility, sanitizepath } from '@contentstack/cli-utilities'; +import { ux, FsUtility, sanitizePath } from '@contentstack/cli-utilities'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import auditConfig from '../config'; @@ -69,7 +69,7 @@ export default class Entries { this.gfSchema = gfSchema; this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig.entries.dirName)); + this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig.entries.dirName)); } validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { diff --git a/packages/contentstack-audit/src/modules/extensions.ts b/packages/contentstack-audit/src/modules/extensions.ts index 77af2e7134..cbf5139fc7 100644 --- a/packages/contentstack-audit/src/modules/extensions.ts +++ b/packages/contentstack-audit/src/modules/extensions.ts @@ -2,7 +2,7 @@ import path, { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import { cloneDeep } from 'lodash'; import { LogFn, ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, Extension } from '../types'; -import { ux, sanitizepath } from '@contentstack/cli-utilities'; +import { ux, sanitizePath } from '@contentstack/cli-utilities'; import auditConfig from '../config'; import { $t, auditMsg, commonMsg } from '../messages'; @@ -36,7 +36,7 @@ export default class Extensions { this.extensionsSchema = []; this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); + this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); this.missingCtInExtensions = []; this.missingCts = new Set(); diff --git a/packages/contentstack-audit/src/modules/workflows.ts b/packages/contentstack-audit/src/modules/workflows.ts index a7129468a0..d386feabba 100644 --- a/packages/contentstack-audit/src/modules/workflows.ts +++ b/packages/contentstack-audit/src/modules/workflows.ts @@ -2,7 +2,7 @@ import { join, resolve } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import { cloneDeep } from 'lodash'; import { LogFn, ConfigType, ContentTypeStruct, CtConstructorParam, ModuleConstructorParam, Workflow } from '../types'; -import { sanitizepath, ux } from '@contentstack/cli-utilities'; +import { sanitizePath, ux } from '@contentstack/cli-utilities'; import auditConfig from '../config'; import { $t, auditMsg, commonMsg } from '../messages'; @@ -37,7 +37,7 @@ export default class Workflows { this.workflowSchema = []; this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; - this.folderPath = resolve(sanitizepath(config.basePath), sanitizepath(config.moduleConfig[this.moduleName].dirName)); + this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); this.missingCtInWorkflows = []; this.missingCts = new Set(); diff --git a/packages/contentstack-bootstrap/src/bootstrap/index.ts b/packages/contentstack-bootstrap/src/bootstrap/index.ts index a8341a2d22..b0e8e9ae0f 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/index.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/index.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { cliux, sanitizepath } from '@contentstack/cli-utilities'; +import { cliux, sanitizePath } from '@contentstack/cli-utilities'; import { default as ContentStackSeed } from '@contentstack/cli-cm-seed/lib/commands/cm/stacks/seed'; import { AppConfig } from '../config'; @@ -58,7 +58,7 @@ export default class Bootstrap { if (options.appConfig.branch) { this.repo.branch = options.appConfig.branch; } - this.cloneDirectory = path.join(sanitizepath(options.cloneDirectory), sanitizepath(this.repo.name)); + this.cloneDirectory = path.join(sanitizePath(options.cloneDirectory), sanitizePath(this.repo.name)); this.ghClient = new GitHubClient(this.repo, options.appConfig.private, options.accessToken); this.options = options; } diff --git a/packages/contentstack-bootstrap/src/bootstrap/utils.ts b/packages/contentstack-bootstrap/src/bootstrap/utils.ts index 21756a763e..82e91b226a 100644 --- a/packages/contentstack-bootstrap/src/bootstrap/utils.ts +++ b/packages/contentstack-bootstrap/src/bootstrap/utils.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import { cliux, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; +import { cliux, pathValidator, sanitizePath } from '@contentstack/cli-utilities'; import { continueBootstrapCommand } from '../bootstrap/interactive'; import { AppConfig } from '../config'; import messageHandler from '../messages'; @@ -154,7 +154,7 @@ const envFileHandler = async ( case 'reactjs': case 'reactjs-starter': fileName = `.env.${environmentVariables.environment}.local`; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); content = `REACT_APP_CONTENTSTACK_API_KEY=${ environmentVariables.api_key }\nREACT_APP_CONTENTSTACK_DELIVERY_TOKEN=${environmentVariables.deliveryToken}${ @@ -173,7 +173,7 @@ const envFileHandler = async ( case 'nextjs': case 'nextjs-starter': fileName = `.env.${environmentVariables.environment}.local`; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ @@ -192,7 +192,7 @@ const envFileHandler = async ( case 'gatsby': case 'gatsby-starter': fileName = `.env.${environmentVariables.environment}`; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ @@ -221,7 +221,7 @@ const envFileHandler = async ( !isUSRegion && !customHost ? `,\n\t\tregion: '${region.name}'` : '' } \n\t } \n };`; fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), 'src', 'environments', sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), 'src', 'environments', sanitizePath(fileName))); result = await writeEnvFile(content, filePath); break; case 'angular-starter': @@ -239,7 +239,7 @@ const envFileHandler = async ( !isUSRegion && !customHost ? '\nCONTENTSTACK_REGION=' + region.name : '' }\nCONTENTSTACK_LIVE_PREVIEW=${livePreviewEnabled}\nCONTENTSTACK_LIVE_EDIT_TAGS=false`; fileName = `.env${environmentVariables.environment === 'production' ? '.prod' : ''}`; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); result = await writeEnvFile(content, filePath); break; case 'nuxtjs': @@ -247,7 +247,7 @@ const envFileHandler = async ( case 'nuxt3-starter': case 'stencil-starter': fileName = production ? '.env.production' : '.env'; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); // Note: Stencil app needs all the env variables, even if they are not having values otherwise the rollup does not work properly and throws process in undefined error. content = `CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nCONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken @@ -266,7 +266,7 @@ const envFileHandler = async ( break; case 'vue-starter': fileName = '.env'; - filePath = pathValidator(path.join(sanitizepath(clonedDirectory), sanitizepath(fileName))); + filePath = pathValidator(path.join(sanitizePath(clonedDirectory), sanitizePath(fileName))); content = `VUE_APP_CONTENTSTACK_API_KEY=${environmentVariables.api_key}\nVUE_APP_CONTENTSTACK_DELIVERY_TOKEN=${ environmentVariables.deliveryToken }\n${ diff --git a/packages/contentstack-branches/src/utils/index.ts b/packages/contentstack-branches/src/utils/index.ts index e472abb9bc..da9a10cfdb 100644 --- a/packages/contentstack-branches/src/utils/index.ts +++ b/packages/contentstack-branches/src/utils/index.ts @@ -4,7 +4,7 @@ import fs from 'fs'; import path from 'path'; import forEach from 'lodash/forEach' -import { configHandler, cliux, messageHandler, sanitizepath } from '@contentstack/cli-utilities'; +import { configHandler, cliux, messageHandler, sanitizePath } from '@contentstack/cli-utilities'; import { MergeParams } from '../interfaces'; export const getbranchesList = (branchResult, baseBranch: string) => { @@ -40,7 +40,7 @@ export const refreshbranchConfig = async (apiKey, branchUid) => { export const writeFile = (filePath, data) => { return new Promise((resolve, reject) => { data = typeof data === 'object' ? JSON.stringify(data, null, 2) : data || '{}'; - fs.writeFile(path.resolve(sanitizepath(filePath)), data, (error) => { + fs.writeFile(path.resolve(sanitizePath(filePath)), data, (error) => { if (error) { return reject(error); } @@ -52,7 +52,7 @@ export const writeFile = (filePath, data) => { // by default file type is json export const readFile = (filePath, options = { type: 'json' }) => { return new Promise((resolve, reject) => { - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { reject(error); diff --git a/packages/contentstack-bulk-publish/copyLogs.js b/packages/contentstack-bulk-publish/copyLogs.js index d6a67e36da..73d2585855 100644 --- a/packages/contentstack-bulk-publish/copyLogs.js +++ b/packages/contentstack-bulk-publish/copyLogs.js @@ -4,7 +4,7 @@ const path = require('path'); const logFileDir = 'logs'; const dummyDir = 'test/dummy/'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; if (!fs.existsSync(path.join(__dirname, logFileDir))) { fs.mkdirSync(path.join(__dirname, logFileDir)); @@ -32,5 +32,5 @@ const logs = [ ]; logs.forEach((element) => { - fs.createReadStream(path.join(__dirname, dummyDir, sanitizepath(element))).pipe(fs.createWriteStream(path.join(__dirname, logFileDir, sanitizepath(element)))); + fs.createReadStream(path.join(__dirname, dummyDir, sanitizePath(element))).pipe(fs.createWriteStream(path.join(__dirname, logFileDir, sanitizePath(element)))); }); diff --git a/packages/contentstack-bulk-publish/src/consumer/publish.js b/packages/contentstack-bulk-publish/src/consumer/publish.js index 39b42b586d..1c05186ce1 100644 --- a/packages/contentstack-bulk-publish/src/consumer/publish.js +++ b/packages/contentstack-bulk-publish/src/consumer/publish.js @@ -9,7 +9,7 @@ const apiVersionForNRP = '3.2'; const nrpApiVersionWarning = `Provided apiVersion is invalid. ${apiVersionForNRP} is only supported value. Continuing with regular bulk-publish for now.`; const { getLoggerInstance, addLogs, getLogsDirPath } = require('../util/logger'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); const logsDir = getLogsDirPath(); let logger; @@ -19,7 +19,7 @@ function initializeLogger(fileName) { fileNme = fileName; fileNme = `${Date.now()}.${fileNme}`; logger = getLoggerInstance(fileNme); - return path.join(logsDir, sanitizepath(fileNme)); + return path.join(logsDir, sanitizePath(fileNme)); } /* eslint-disable camelcase */ diff --git a/packages/contentstack-bulk-publish/src/util/logger.js b/packages/contentstack-bulk-publish/src/util/logger.js index 45e60021cf..16434dd504 100644 --- a/packages/contentstack-bulk-publish/src/util/logger.js +++ b/packages/contentstack-bulk-publish/src/util/logger.js @@ -1,4 +1,4 @@ -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); const path = require('path'); const winston = require('winston'); const cwd = process.cwd(); @@ -7,7 +7,7 @@ const logsDir = path.join(cwd, 'contentstack-cli-logs', 'bulk-publish'); let filename; module.exports.getLoggerInstance = (fileName) => { - filename = path.join(logsDir, sanitizepath(fileName)); + filename = path.join(logsDir, sanitizePath(fileName)); return winston.createLogger({ transports: [ new winston.transports.File({ filename: `${filename}.error`, level: 'error' }), @@ -18,7 +18,7 @@ module.exports.getLoggerInstance = (fileName) => { /* eslint-disable no-multi-assign */ const getFileLoggerInstance = (module.exports.getFileLoggerInstance = (fileName) => { - filename = path.join(logsDir, sanitizepath(fileName)); + filename = path.join(logsDir, sanitizePath(fileName)); return winston.createLogger({ transports: [new winston.transports.File({ filename })], }); diff --git a/packages/contentstack-clone/src/lib/util/log.js b/packages/contentstack-clone/src/lib/util/log.js index d90aaa71bd..7d806cd9a8 100644 --- a/packages/contentstack-clone/src/lib/util/log.js +++ b/packages/contentstack-clone/src/lib/util/log.js @@ -7,7 +7,7 @@ var winston = require('winston'); var path = require('path'); var mkdirp = require('mkdirp'); -const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities'); +const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities'); var slice = Array.prototype.slice; function returnString(args) { @@ -42,10 +42,10 @@ var myCustomLevels = { }; function init(_logPath, logfileName) { - var logsDir = pathValidator(path.resolve(sanitizepath(_logPath), 'logs', 'import')); + var logsDir = pathValidator(path.resolve(sanitizePath(_logPath), 'logs', 'import')); // Create dir if doesn't already exist mkdirp.sync(logsDir); - var logPath = path.join(sanitizepath(logsDir), pathValidator(sanitizepath(logfileName)) + '.log'); + var logPath = path.join(sanitizePath(logsDir), pathValidator(sanitizePath(logfileName)) + '.log'); var transports = [ new winston.transports.File({ diff --git a/packages/contentstack-export/src/export/modules-js/assets.js b/packages/contentstack-export/src/export/modules-js/assets.js index 9b485c6b6f..798e6320fd 100644 --- a/packages/contentstack-export/src/export/modules-js/assets.js +++ b/packages/contentstack-export/src/export/modules-js/assets.js @@ -11,7 +11,7 @@ const Promise = require('bluebird'); const _ = require('lodash'); const chalk = require('chalk'); const progress = require('progress-stream'); -const { HttpClient, configHandler, validateUids, sanitizepath, validateFileName } = require('@contentstack/cli-utilities'); +const { HttpClient, configHandler, validateUids, sanitizePath, validateFileName } = require('@contentstack/cli-utilities'); const { fileHelper, log, formatError } = require('../../utils'); let { default: config } = require('../../config'); @@ -283,7 +283,7 @@ module.exports = class ExportAssets { if (version <= 0) { if(validateUids(uid)){ - const assetVersionInfoFile = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(uid), '_contentstack_' + sanitizepath(uid) + '.json'); + const assetVersionInfoFile = path.resolve(sanitizePath(self.assetsFolderPath), sanitizePath(uid), '_contentstack_' + sanitizePath(uid) + '.json'); fileHelper.writeFileSync(assetVersionInfoFile, assetVersionInfo); return resolve(); } @@ -332,8 +332,8 @@ module.exports = class ExportAssets { if(!validateUids(asset.uid) && !validateFileName(asset.filename)) { reject(`UIDs not valid`) } - const assetFolderPath = path.resolve(sanitizepath(self.assetsFolderPath), sanitizepath(asset.uid)); - const assetFilePath = path.resolve(sanitizepath(assetFolderPath), sanitizepath(asset.filename)); + const assetFolderPath = path.resolve(sanitizePath(self.assetsFolderPath), sanitizePath(asset.uid)); + const assetFilePath = path.resolve(sanitizePath(assetFolderPath), sanitizePath(asset.filename)); if (fs.existsSync(assetFilePath)) { log( diff --git a/packages/contentstack-export/src/export/modules-js/content-types.js b/packages/contentstack-export/src/export/modules-js/content-types.js index c509026d7a..d5dcde84ee 100644 --- a/packages/contentstack-export/src/export/modules-js/content-types.js +++ b/packages/contentstack-export/src/export/modules-js/content-types.js @@ -1,7 +1,7 @@ const path = require('path'); const chalk = require('chalk'); const { fileHelper, executeTask, formatError, log } = require('../../utils'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); class ContentTypesExport { constructor(exportConfig, stackAPIClient) { @@ -19,9 +19,9 @@ class ContentTypesExport { this.qs.uid = { $in: this.exportConfig.contentTypes }; } this.contentTypesPath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName) || '', - sanitizepath(this.contentTypesConfig.dirName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName) || '', + sanitizePath(this.contentTypesConfig.dirName), ); this.contentTypes = []; this.fetchConcurrency = this.contentTypesConfig.fetchConcurrency || this.exportConfig.fetchConcurrency; @@ -77,7 +77,7 @@ class ContentTypesExport { async writeContentTypes(contentTypes) { function write(contentType) { return fileHelper.writeFile( - path.join(sanitizepath(this.contentTypesPath), `${sanitizepath (contentType.uid === 'schema' ? 'schema|1' : contentType.uid)}.json`), + path.join(sanitizePath(this.contentTypesPath), `${sanitizePath (contentType.uid === 'schema' ? 'schema|1' : contentType.uid)}.json`), contentType, ); } diff --git a/packages/contentstack-export/src/export/modules-js/entries.js b/packages/contentstack-export/src/export/modules-js/entries.js index bccdc15e5b..a9a9627be7 100644 --- a/packages/contentstack-export/src/export/modules-js/entries.js +++ b/packages/contentstack-export/src/export/modules-js/entries.js @@ -2,24 +2,24 @@ const path = require('path'); const chalk = require('chalk'); const { values } = require('lodash'); const { executeTask, formatError, fileHelper, log } = require('../../utils'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); class EntriesExport { constructor(exportConfig, stackAPIClient) { this.stackAPIClient = stackAPIClient; this.exportConfig = exportConfig; this.entriesConfig = exportConfig.modules.entries; - this.entriesRootPath = path.resolve((sanitizepath(exportConfig.data)), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName)); + this.entriesRootPath = path.resolve((sanitizePath(exportConfig.data)), sanitizePath(exportConfig.branchName || ''), sanitizePath(this.entriesConfig.dirName)); this.localesFilePath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(exportConfig.modules.locales.dirName), - sanitizepath(exportConfig.modules.locales.fileName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(exportConfig.modules.locales.dirName), + sanitizePath(exportConfig.modules.locales.fileName), ); this.schemaFilePath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(exportConfig.modules.content_types.dirName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(exportConfig.modules.content_types.dirName), 'schema.json', ); this.fetchConcurrency = this.entriesConfig.fetchConcurrency || exportConfig.fetchConcurrency; @@ -79,7 +79,7 @@ class EntriesExport { if (versionedEntries.length > 0) { const write = (versionedEntry) => fileHelper.writeFile( - path.join(sanitizepath(versionedEntryPath), 'version-' + sanitizepath(versionedEntry._version) + '.json'), + path.join(sanitizePath(versionedEntryPath), 'version-' + sanitizePath(versionedEntry._version) + '.json'), versionedEntry, ); await executeTask(versionedEntries, write.bind(this), { concurrency: this.writeConcurrency }); diff --git a/packages/contentstack-export/src/export/modules-js/global-fields.js b/packages/contentstack-export/src/export/modules-js/global-fields.js index b6849c4c2a..ef32dc6457 100644 --- a/packages/contentstack-export/src/export/modules-js/global-fields.js +++ b/packages/contentstack-export/src/export/modules-js/global-fields.js @@ -10,7 +10,7 @@ const mkdirp = require('mkdirp'); const { merge } = require('lodash'); const { formatError, log, fileHelper } = require('../../utils'); const { default: config } = require('../../config'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); module.exports = class ExportGlobalFields { limit = 100; @@ -35,9 +35,9 @@ module.exports = class ExportGlobalFields { this.config = merge(config, exportConfig); this.stackAPIClient = stackAPIClient; this.globalfieldsFolderPath = path.resolve( - sanitizepath(this.config.data), - sanitizepath(this.config.branchName || ''), - sanitizepath(this.globalfieldsConfig.dirName), + sanitizePath(this.config.data), + sanitizePath(this.config.branchName || ''), + sanitizePath(this.globalfieldsConfig.dirName), ); } diff --git a/packages/contentstack-export/src/export/modules-js/locales.js b/packages/contentstack-export/src/export/modules-js/locales.js index 916a9b1986..a377737d7b 100644 --- a/packages/contentstack-export/src/export/modules-js/locales.js +++ b/packages/contentstack-export/src/export/modules-js/locales.js @@ -1,7 +1,7 @@ const path = require('path'); const chalk = require('chalk'); const { formatError, log, fileHelper } = require('../../utils'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); class LocaleExport { constructor(exportConfig, stackAPIClient) { this.stackAPIClient = stackAPIClient; @@ -16,7 +16,7 @@ class LocaleExport { }, }; - this.localesPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.localeConfig.dirName)); + this.localesPath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), sanitizePath(this.localeConfig.dirName)); this.locales = {}; this.masterLocale = {}; this.fetchConcurrency = this.localeConfig.fetchConcurrency || this.exportConfig.fetchConcurrency; diff --git a/packages/contentstack-export/src/export/modules/content-types.ts b/packages/contentstack-export/src/export/modules/content-types.ts index a70a1494b4..c199cf8784 100644 --- a/packages/contentstack-export/src/export/modules/content-types.ts +++ b/packages/contentstack-export/src/export/modules/content-types.ts @@ -3,7 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil, executeTask } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default class ContentTypesExport extends BaseClass { private stackAPIClient: ReturnType; @@ -44,9 +44,9 @@ export default class ContentTypesExport extends BaseClass { } this.contentTypesDirPath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(this.contentTypesConfig.dirName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(this.contentTypesConfig.dirName), ); this.contentTypes = []; } @@ -99,7 +99,7 @@ export default class ContentTypesExport extends BaseClass { async writeContentTypes(contentTypes: Record[]) { function write(contentType: Record) { return fsUtil.writeFile( - path.join(sanitizepath(this.contentTypesDirPath), `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), + path.join(sanitizePath(this.contentTypesDirPath), `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), contentType, ); } diff --git a/packages/contentstack-export/src/export/modules/entries.ts b/packages/contentstack-export/src/export/modules/entries.ts index 2eb7165735..5dc6976c7f 100644 --- a/packages/contentstack-export/src/export/modules/entries.ts +++ b/packages/contentstack-export/src/export/modules/entries.ts @@ -3,7 +3,7 @@ import { ContentstackClient, FsUtility } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass, { ApiOptions } from './base-class'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default class EntriesExport extends BaseClass { private stackAPIClient: ReturnType; @@ -29,17 +29,17 @@ export default class EntriesExport extends BaseClass { this.stackAPIClient = stackAPIClient; this.exportConfig = exportConfig; this.entriesConfig = exportConfig.modules.entries; - this.entriesDirPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''), sanitizepath(this.entriesConfig.dirName)); + this.entriesDirPath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), sanitizePath(this.entriesConfig.dirName)); this.localesFilePath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(exportConfig.modules.locales.dirName), - sanitizepath(exportConfig.modules.locales.fileName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(exportConfig.modules.locales.dirName), + sanitizePath(exportConfig.modules.locales.fileName), ); this.schemaFilePath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(exportConfig.modules.content_types.dirName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(exportConfig.modules.content_types.dirName), 'schema.json', ); } @@ -119,7 +119,7 @@ export default class EntriesExport extends BaseClass { if (Array.isArray(entriesSearchResponse.items) && entriesSearchResponse.items.length > 0) { if (options.skip === 0) { - const entryBasePath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType), sanitizepath(options.locale)); + const entryBasePath = path.join(sanitizePath(this.entriesDirPath), sanitizePath(options.contentType), sanitizePath(options.locale)); await fsUtil.makeDirectory(entryBasePath); this.entriesFileHelper = new FsUtility({ moduleName: 'entries', @@ -132,7 +132,7 @@ export default class EntriesExport extends BaseClass { } this.entriesFileHelper.writeIntoFile(entriesSearchResponse.items, { mapKeyVal: true }); if (this.entriesConfig.exportVersions) { - let versionedEntryPath = path.join(sanitizepath(this.entriesDirPath), sanitizepath(options.contentType),sanitizepath(options.locale), 'versions'); + let versionedEntryPath = path.join(sanitizePath(this.entriesDirPath), sanitizePath(options.contentType),sanitizePath(options.locale), 'versions'); fsUtil.makeDirectory(versionedEntryPath); await this.fetchEntriesVersions(entriesSearchResponse.items, { locale: options.locale, @@ -153,7 +153,7 @@ export default class EntriesExport extends BaseClass { options: { locale: string; contentType: string; versionedEntryPath: string }, ): Promise { const onSuccess = ({ response, apiData: entry }: any) => { - fsUtil.writeFile(path.join(sanitizepath(options.versionedEntryPath), `${entry.uid}.json`), response); + fsUtil.writeFile(path.join(sanitizePath(options.versionedEntryPath), `${entry.uid}.json`), response); log( this.exportConfig, `Exported versioned entries of type '${options.contentType}' locale '${options.locale}'`, diff --git a/packages/contentstack-export/src/export/modules/global-fields.ts b/packages/contentstack-export/src/export/modules/global-fields.ts index fc178fa0cd..3085eeb3cd 100644 --- a/packages/contentstack-export/src/export/modules/global-fields.ts +++ b/packages/contentstack-export/src/export/modules/global-fields.ts @@ -3,7 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default class GlobalFieldsExport extends BaseClass { private stackAPIClient: ReturnType; @@ -36,9 +36,9 @@ export default class GlobalFieldsExport extends BaseClass { limit: this.globalFieldsConfig.limit, }; this.globalFieldsDirPath = path.resolve( - sanitizepath(exportConfig.data), - sanitizepath(exportConfig.branchName || ''), - sanitizepath(this.globalFieldsConfig.dirName), + sanitizePath(exportConfig.data), + sanitizePath(exportConfig.branchName || ''), + sanitizePath(this.globalFieldsConfig.dirName), ); this.globalFields = []; } diff --git a/packages/contentstack-export/src/export/modules/locales.ts b/packages/contentstack-export/src/export/modules/locales.ts index 3926483831..602da209bd 100644 --- a/packages/contentstack-export/src/export/modules/locales.ts +++ b/packages/contentstack-export/src/export/modules/locales.ts @@ -3,7 +3,7 @@ import { ContentstackClient } from '@contentstack/cli-utilities'; import { log, formatError, fsUtil } from '../../utils'; import { ExportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default class LocaleExport extends BaseClass { private stackAPIClient: ReturnType; @@ -41,7 +41,7 @@ export default class LocaleExport extends BaseClass { BASE: this.localeConfig.requiredKeys, }, }; - this.localesPath = path.resolve(sanitizepath(exportConfig.data), sanitizepath(exportConfig.branchName || ''),sanitizepath(this.localeConfig.dirName)); + this.localesPath = path.resolve(sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''),sanitizePath(this.localeConfig.dirName)); this.locales = {}; this.masterLocale = {}; } diff --git a/packages/contentstack-export/src/utils/common-helper.ts b/packages/contentstack-export/src/utils/common-helper.ts index 2e608ec854..8084b86106 100644 --- a/packages/contentstack-export/src/utils/common-helper.ts +++ b/packages/contentstack-export/src/utils/common-helper.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import { isAuthenticated } from '@contentstack/cli-utilities'; import { ExternalConfig, ExportConfig } from '../types'; import { fsUtil } from './file-helper'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export const validateConfig = function (config: ExternalConfig) { if (!config.host || !config.cdn) { @@ -84,7 +84,7 @@ export const executeTask = function ( export const writeExportMetaFile = (exportConfig: ExportConfig, metaFilePath?: string) => { const exportMeta = { contentVersion: exportConfig.contentVersion, - logsPath: path.join(sanitizepath(exportConfig.exportDir), 'logs', 'export'), + logsPath: path.join(sanitizePath(exportConfig.exportDir), 'logs', 'export'), }; - fsUtil.writeFile(path.join(sanitizepath(metaFilePath || exportConfig.exportDir), 'export-info.json'), exportMeta); + fsUtil.writeFile(path.join(sanitizePath(metaFilePath || exportConfig.exportDir), 'export-info.json'), exportMeta); }; diff --git a/packages/contentstack-export/src/utils/file-helper.ts b/packages/contentstack-export/src/utils/file-helper.ts index 682b2bdbe6..5afc464418 100644 --- a/packages/contentstack-export/src/utils/file-helper.ts +++ b/packages/contentstack-export/src/utils/file-helper.ts @@ -2,12 +2,12 @@ import * as fs from 'fs'; import * as path from 'path'; import mkdirp from 'mkdirp'; import bigJSON from 'big-json'; -import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizePath } from '@contentstack/cli-utilities'; export const readFileSync = function (filePath: string, parse: boolean): unknown { let data; parse = typeof parse === 'undefined' ? true : parse; - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); if (fs.existsSync(filePath)) { data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : data; } @@ -17,7 +17,7 @@ export const readFileSync = function (filePath: string, parse: boolean): unknown // by default file type is json export const readFile = async (filePath: string, options = { type: 'json' }): Promise => { return new Promise((resolve, reject) => { - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { reject(error); @@ -35,7 +35,7 @@ export const readLargeFile = function (filePath: string, options: { type?: strin if (typeof filePath !== 'string') { return; } - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); if (fs.existsSync(filePath)) { return new Promise((resolve, reject) => { const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' }); @@ -76,7 +76,7 @@ export const writeLargeFile = function (filePath: string, data: any): Promise { const stringifyStream = bigJSON.createStringifyStream({ body: data, diff --git a/packages/contentstack-export/src/utils/logger.ts b/packages/contentstack-export/src/utils/logger.ts index 66cf7b5606..39fba53adb 100644 --- a/packages/contentstack-export/src/utils/logger.ts +++ b/packages/contentstack-export/src/utils/logger.ts @@ -8,7 +8,7 @@ import * as winston from 'winston'; import * as path from 'path'; import mkdirp from 'mkdirp'; import { ExportConfig } from '../types'; -import { sanitizepath } from '@contentstack/cli-utilities' +import { sanitizePath } from '@contentstack/cli-utilities' const slice = Array.prototype.slice; const ansiRegexPattern = [ @@ -58,12 +58,12 @@ let errorTransport; function init(_logPath: string) { if (!logger || !errorLogger) { - const logsDir = path.resolve(sanitizepath(_logPath), 'logs', 'export'); + const logsDir = path.resolve(sanitizePath(_logPath), 'logs', 'export'); // Create dir if doesn't already exist mkdirp.sync(logsDir); successTransport = { - filename: path.join(sanitizepath(logsDir), 'success.log'), + filename: path.join(sanitizePath(logsDir), 'success.log'), maxFiles: 20, maxsize: 1000000, tailable: true, @@ -71,7 +71,7 @@ function init(_logPath: string) { }; errorTransport = { - filename: path.join(sanitizepath(logsDir), 'error.log'), + filename: path.join(sanitizePath(logsDir), 'error.log'), maxFiles: 20, maxsize: 1000000, tailable: true, diff --git a/packages/contentstack-export/src/utils/setup-branches.ts b/packages/contentstack-export/src/utils/setup-branches.ts index 18066e24e2..e7ef011b06 100644 --- a/packages/contentstack-export/src/utils/setup-branches.ts +++ b/packages/contentstack-export/src/utils/setup-branches.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { writeFileSync, makeDirectory } from './file-helper'; import { isAuthenticated, configHandler } from '@contentstack/cli-utilities'; import { ExportConfig } from '../types'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; const setupBranches = async (config: ExportConfig, stackAPIClient: any) => { if (typeof config !== 'object') { @@ -41,7 +41,7 @@ const setupBranches = async (config: ExportConfig, stackAPIClient: any) => { makeDirectory(config.exportDir); // create branch info file - writeFileSync(path.join(sanitizepath(config.exportDir), 'branches.json'), branches); + writeFileSync(path.join(sanitizePath(config.exportDir), 'branches.json'), branches); // add branches list in the config.branches = branches; }; diff --git a/packages/contentstack-export/src/utils/setup-export-dir.ts b/packages/contentstack-export/src/utils/setup-export-dir.ts index c925e2c52c..e36237fd08 100644 --- a/packages/contentstack-export/src/utils/setup-export-dir.ts +++ b/packages/contentstack-export/src/utils/setup-export-dir.ts @@ -1,13 +1,13 @@ import path from 'path'; import { ExportConfig } from '../types'; import { makeDirectory } from './file-helper'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default async function setupExportDir(exportConfig: ExportConfig) { makeDirectory(exportConfig.exportDir); if (exportConfig.branches) { return Promise.all( - exportConfig.branches.map((branch) => makeDirectory(path.join(sanitizepath(exportConfig.exportDir), sanitizepath(branch.uid)))), + exportConfig.branches.map((branch) => makeDirectory(path.join(sanitizePath(exportConfig.exportDir), sanitizePath(branch.uid)))), ); } } diff --git a/packages/contentstack-import/src/import/modules-js/assets.js b/packages/contentstack-import/src/import/modules-js/assets.js index fbe117734e..df621297dd 100755 --- a/packages/contentstack-import/src/import/modules-js/assets.js +++ b/packages/contentstack-import/src/import/modules-js/assets.js @@ -11,7 +11,7 @@ const mkdirp = require('mkdirp'); const Promise = require('bluebird'); let { default: config } = require('../../config'); const { fileHelper, log, uploadAssetHelper } = require('../../utils'); -const { sanitizepath, validateUids, validateFileName } = require('@contentstack/cli-utilities'); +const { sanitizePath, validateUids, validateFileName } = require('@contentstack/cli-utilities'); module.exports = class ImportAssets { assets; @@ -92,7 +92,7 @@ module.exports = class ImportAssets { if(!validateUids(assetUid)){ reject(`UID Not Valid`) } - let currentAssetFolderPath = path.join(sanitizepath(self.assetsFolderPath), sanitizepath(assetUid)); + let currentAssetFolderPath = path.join(sanitizePath(self.assetsFolderPath), sanitizePath(assetUid)); if (fs.existsSync(currentAssetFolderPath)) { // if this is true, means, the exported asset data is versioned // hence, upload each asset with its version @@ -107,7 +107,7 @@ module.exports = class ImportAssets { if(!validateFileName(self.assets[assetUid].filename)){ reject(`File Name Not Valid`) } - let assetPath = path.resolve(sanitizepath(currentAssetFolderPath), sanitizepath(self.assets[assetUid].filename)); + let assetPath = path.resolve(sanitizePath(currentAssetFolderPath), sanitizePath(self.assets[assetUid].filename)); if (self.assets[assetUid].parent_uid && typeof self.assets[assetUid].parent_uid === 'string') { if (self.mappedFolderUids.hasOwnProperty(self.assets[assetUid].parent_uid)) { @@ -190,7 +190,7 @@ module.exports = class ImportAssets { reject(`UID not valid`) } let versionedAssetMetadata = fileHelper.readFileSync( - path.join(sanitizepath(assetFolderPath), '_contentstack_' + sanitizepath(uid) + '.json'), + path.join(sanitizePath(assetFolderPath), '_contentstack_' + sanitizePath(uid) + '.json'), ); // using last version, find asset's parent let lastVersion = versionedAssetMetadata[versionedAssetMetadata.length - 1]; @@ -220,7 +220,7 @@ module.exports = class ImportAssets { if(!validateFileName(assetMetadata.filename)){ reject(`File Name not valid`) } - let assetPath = path.join(sanitizepath(assetFolderPath), sanitizepath(assetMetadata.filename)); + let assetPath = path.join(sanitizePath(assetFolderPath), sanitizePath(assetMetadata.filename)); if (++counter === 1) { return self diff --git a/packages/contentstack-import/src/import/modules-js/content-types.js b/packages/contentstack-import/src/import/modules-js/content-types.js index 1f65795e40..0c7e1df68a 100755 --- a/packages/contentstack-import/src/import/modules-js/content-types.js +++ b/packages/contentstack-import/src/import/modules-js/content-types.js @@ -3,7 +3,7 @@ const path = require('path'); const chalk = require('chalk'); const { cloneDeep, find, findIndex } = require('lodash'); const { fileHelper, log, executeTask, formatError, schemaTemplate, lookupExtension } = require('../../utils'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); class ContentTypesImport { constructor(importConfig, stackAPIClient) { @@ -13,12 +13,12 @@ class ContentTypesImport { this.globalFieldConfig = importConfig.modules.globalfields; this.importConcurrency = this.contentTypeConfig.importConcurrency || this.importConfig.importConcurrency; this.writeConcurrency = this.contentTypeConfig.writeConcurrency || this.importConfig.writeConcurrency; - this.contentTypesFolderPath = path.join(sanitizepath(this.importConfig.data), sanitizepath(this.contentTypeConfig.dirName)); - this.mapperFolderPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'content_types'); - this.existingContentTypesPath = path.join(sanitizepath(this.mapperFolderPath), 'success.json'); - this.globalFieldsFolderPath = path.resolve(sanitizepath(this.importConfig.data),sanitizepath(this.globalFieldConfig.dirName)); - this.globalFieldMapperFolderPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'success.json'); - this.globalFieldPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); + this.contentTypesFolderPath = path.join(sanitizePath(this.importConfig.data), sanitizePath(this.contentTypeConfig.dirName)); + this.mapperFolderPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'content_types'); + this.existingContentTypesPath = path.join(sanitizePath(this.mapperFolderPath), 'success.json'); + this.globalFieldsFolderPath = path.resolve(sanitizePath(this.importConfig.data),sanitizePath(this.globalFieldConfig.dirName)); + this.globalFieldMapperFolderPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'success.json'); + this.globalFieldPendingPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); this.ignoredFilesInContentTypesFolder = new Map([ ['__master.json', 'true'], ['__priority.json', 'true'], diff --git a/packages/contentstack-import/src/import/modules-js/entries.js b/packages/contentstack-import/src/import/modules-js/entries.js index eede00bd2f..9583d447e7 100755 --- a/packages/contentstack-import/src/import/modules-js/entries.js +++ b/packages/contentstack-import/src/import/modules-js/entries.js @@ -20,7 +20,7 @@ const { lookupEntries, } = require('../../utils'); const { default: config } = require('../../config'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); const addlogs = log; module.exports = class ImportEntries { mappedAssetUidPath; @@ -839,7 +839,7 @@ module.exports = class ImportEntries { return resolve(); } self.mappedUids[query.entry.uid] = response.body.entries[0].uid; - let _ePath = path.join(sanitizepath(this.entryMapperPath), sanitizepath(query.locale), sanitizepath(query.content_type), 'success.json'); + let _ePath = path.join(sanitizePath(this.entryMapperPath), sanitizePath(query.locale), sanitizePath(query.content_type), 'success.json'); let entries = fileHelper.readFileSync(_ePath); entries.push(query.entry); fileHelper.writeFileSync(_ePath, entries); diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index f9cfb23b59..0590d93ac4 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -11,7 +11,7 @@ import { fsUtil, log, formatError, schemaTemplate, lookupExtension, lookUpTaxono import { ImportConfig, ModuleClassParams } from '../../types'; import BaseClass, { ApiOptions } from './base-class'; import { updateFieldRules } from '../../utils/content-type-helper'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; export default class ContentTypesImport extends BaseClass { private cTsMapperPath: string; @@ -60,13 +60,13 @@ export default class ContentTypesImport extends BaseClass { this.cTsConfig = importConfig.modules['content-types']; this.gFsConfig = importConfig.modules['global-fields']; this.reqConcurrency = this.cTsConfig.writeConcurrency || this.importConfig.writeConcurrency; - this.cTsFolderPath = path.join(sanitizepath(this.importConfig.data), sanitizepath(this.cTsConfig.dirName)); - this.cTsMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'content_types'); - this.cTsSuccessPath = path.join(sanitizepath(this.cTsMapperPath), 'success.json'); - this.gFsFolderPath = path.resolve(sanitizepath(this.importConfig.data), sanitizepath(this.gFsConfig.dirName)); - this.gFsMapperFolderPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'success.json'); - this.gFsPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); - this.marketplaceAppMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.cTsFolderPath = path.join(sanitizePath(this.importConfig.data), sanitizePath(this.cTsConfig.dirName)); + this.cTsMapperPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'content_types'); + this.cTsSuccessPath = path.join(sanitizePath(this.cTsMapperPath), 'success.json'); + this.gFsFolderPath = path.resolve(sanitizePath(this.importConfig.data), sanitizePath(this.gFsConfig.dirName)); + this.gFsMapperFolderPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'success.json'); + this.gFsPendingPath = path.join(sanitizePath(importConfig.data), 'mapper', 'global_fields', 'pending_global_fields.js'); + this.marketplaceAppMapperPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); this.ignoredFilesInContentTypesFolder = new Map([ ['__master.json', 'true'], ['__priority.json', 'true'], @@ -80,8 +80,8 @@ export default class ContentTypesImport extends BaseClass { this.gFs = []; this.createdGFs = []; this.pendingGFs = []; - this.taxonomiesPath = path.join(sanitizepath(importConfig.data), 'mapper/taxonomies', 'success.json'); - this.extPendingPath = path.join(sanitizepath(importConfig.data), 'mapper', 'extensions', 'pending_extensions.js'); + this.taxonomiesPath = path.join(sanitizePath(importConfig.data), 'mapper/taxonomies', 'success.json'); + this.extPendingPath = path.join(sanitizePath(importConfig.data), 'mapper', 'extensions', 'pending_extensions.js'); } async start(): Promise { diff --git a/packages/contentstack-import/src/import/modules/entries.ts b/packages/contentstack-import/src/import/modules/entries.ts index 03f65222da..bae0769e41 100644 --- a/packages/contentstack-import/src/import/modules/entries.ts +++ b/packages/contentstack-import/src/import/modules/entries.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import { isEmpty, values, cloneDeep, find, indexOf, forEach } from 'lodash'; -import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizePath } from '@contentstack/cli-utilities'; import { fsUtil, log, @@ -61,22 +61,22 @@ export default class EntriesImport extends BaseClass { constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); - this.assetUidMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'assets', 'uid-mapping.json'); - this.assetUrlMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'assets', 'url-mapping.json'); - this.entriesMapperPath = path.resolve(sanitizepath(importConfig.data), 'mapper', 'entries'); - this.envPath = path.resolve(sanitizepath(importConfig.data), 'environments', 'environments.json'); - this.entriesUIDMapperPath = path.join(sanitizepath(this.entriesMapperPath), 'uid-mapping.json'); - this.uniqueUidMapperPath = path.join(sanitizepath(this.entriesMapperPath), 'unique-mapping.json'); - this.modifiedCTsPath = path.join(sanitizepath(this.entriesMapperPath), 'modified-schemas.json'); - this.marketplaceAppMapperPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); - this.taxonomiesPath = path.join(sanitizepath(this.importConfig.data), 'mapper', 'taxonomies', 'terms', 'success.json'); + this.assetUidMapperPath = path.resolve(sanitizePath(importConfig.data), 'mapper', 'assets', 'uid-mapping.json'); + this.assetUrlMapperPath = path.resolve(sanitizePath(importConfig.data), 'mapper', 'assets', 'url-mapping.json'); + this.entriesMapperPath = path.resolve(sanitizePath(importConfig.data), 'mapper', 'entries'); + this.envPath = path.resolve(sanitizePath(importConfig.data), 'environments', 'environments.json'); + this.entriesUIDMapperPath = path.join(sanitizePath(this.entriesMapperPath), 'uid-mapping.json'); + this.uniqueUidMapperPath = path.join(sanitizePath(this.entriesMapperPath), 'unique-mapping.json'); + this.modifiedCTsPath = path.join(sanitizePath(this.entriesMapperPath), 'modified-schemas.json'); + this.marketplaceAppMapperPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.taxonomiesPath = path.join(sanitizePath(this.importConfig.data), 'mapper', 'taxonomies', 'terms', 'success.json'); this.entriesConfig = importConfig.modules.entries; - this.entriesPath = path.resolve(sanitizepath(importConfig.data), sanitizepath(this.entriesConfig.dirName)); - this.cTsPath = path.resolve(sanitizepath(importConfig.data), sanitizepath(importConfig.modules['content-types'].dirName)); + this.entriesPath = path.resolve(sanitizePath(importConfig.data), sanitizePath(this.entriesConfig.dirName)); + this.cTsPath = path.resolve(sanitizePath(importConfig.data), sanitizePath(importConfig.modules['content-types'].dirName)); this.localesPath = path.resolve( - sanitizepath(importConfig.data), - sanitizepath(importConfig.modules.locales.dirName), - sanitizepath(importConfig.modules.locales.fileName), + sanitizePath(importConfig.data), + sanitizePath(importConfig.modules.locales.dirName), + sanitizePath(importConfig.modules.locales.fileName), ); this.importConcurrency = this.entriesConfig.importConcurrency || importConfig.importConcurrency; this.entriesUidMapper = {}; @@ -336,7 +336,7 @@ export default class EntriesImport extends BaseClass { ); entry.uid = oldUid; entry.entryOldUid = oldUid; - entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizePath(basePath), sanitizePath(additionalInfo.entryFileName)); // stores source file path temporarily entriesCreateFileHelper.writeIntoFile({ [oldUid]: entry } as any, { mapKeyVal: true }); } else { log(this.importConfig, `Created entry: '${entry.title}' of content type ${cTUid} in locale ${locale}`, 'info'); @@ -348,7 +348,7 @@ export default class EntriesImport extends BaseClass { this.autoCreatedEntries.push({ cTUid, locale, entryUid: response.uid }); } this.entriesUidMapper[entry.uid] = response.uid; - entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizePath(basePath), sanitizePath(additionalInfo.entryFileName)); // stores source file path temporarily entry.entryOldUid = entry.uid; // stores old uid temporarily entriesCreateFileHelper.writeIntoFile({ [entry.uid]: entry } as any, { mapKeyVal: true }); } @@ -360,7 +360,7 @@ export default class EntriesImport extends BaseClass { if (error?.errors?.title || error?.errors?.uid) { if (this.importConfig.replaceExisting) { entry.entryOldUid = uid; - entry.sourceEntryFilePath = path.join(sanitizepath(basePath), sanitizepath(additionalInfo.entryFileName)); // stores source file path temporarily + entry.sourceEntryFilePath = path.join(sanitizePath(basePath), sanitizePath(additionalInfo.entryFileName)); // stores source file path temporarily existingEntriesFileHelper.writeIntoFile({ [uid]: entry } as any, { mapKeyVal: true }); } if (!this.importConfig.skipExisting) { diff --git a/packages/contentstack-import/src/import/modules/global-fields.ts b/packages/contentstack-import/src/import/modules/global-fields.ts index 8fdd549ac6..a4e32e95bb 100644 --- a/packages/contentstack-import/src/import/modules/global-fields.ts +++ b/packages/contentstack-import/src/import/modules/global-fields.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import { isEmpty, cloneDeep } from 'lodash'; -import { cliux, sanitizepath } from '@contentstack/cli-utilities'; +import { cliux, sanitizePath } from '@contentstack/cli-utilities'; import { GlobalFieldData } from '@contentstack/management/types/stack/globalField'; import { fsUtil, log, formatError, fileHelper, lookupExtension, removeReferenceFields } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; @@ -50,13 +50,13 @@ export default class ImportGlobalFields extends BaseClass { this.pendingGFs = []; this.existingGFs = []; this.reqConcurrency = this.gFsConfig.writeConcurrency || this.config.writeConcurrency; - this.gFsMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields'); - this.gFsFolderPath = path.resolve(sanitizepath(this.config.data), sanitizepath(this.gFsConfig.dirName)); - this.gFsFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'fails.json'); - this.gFsSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'success.json'); - this.gFsUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'uid-mapping.json'); - this.gFsPendingPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'global_fields', 'pending_global_fields.js'); - this.marketplaceAppMapperPath = path.join(sanitizepath(this.config.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); + this.gFsMapperPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'global_fields'); + this.gFsFolderPath = path.resolve(sanitizePath(this.config.data), sanitizePath(this.gFsConfig.dirName)); + this.gFsFailsPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'global_fields', 'fails.json'); + this.gFsSuccessPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'global_fields', 'success.json'); + this.gFsUidMapperPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'global_fields', 'uid-mapping.json'); + this.gFsPendingPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'global_fields', 'pending_global_fields.js'); + this.marketplaceAppMapperPath = path.join(sanitizePath(this.config.data), 'mapper', 'marketplace_apps', 'uid-mapping.json'); } async start(): Promise { diff --git a/packages/contentstack-import/src/import/modules/locales.ts b/packages/contentstack-import/src/import/modules/locales.ts index e4afdee4c9..789471132c 100644 --- a/packages/contentstack-import/src/import/modules/locales.ts +++ b/packages/contentstack-import/src/import/modules/locales.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import { values, isEmpty, filter, pick } from 'lodash'; -import { cliux, sanitizepath } from '@contentstack/cli-utilities'; +import { cliux, sanitizePath } from '@contentstack/cli-utilities'; import { fsUtil, log, formatError, fileHelper } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; import BaseClass from './base-class'; @@ -49,11 +49,11 @@ export default class ImportLocales extends BaseClass { this.createdLocales = []; this.failedLocales = []; this.reqConcurrency = this.localeConfig.writeConcurrency || this.config.writeConcurrency; - this.langMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages'); - this.langFolderPath = path.resolve(sanitizepath(this.config.data), sanitizepath(this.localeConfig.dirName)); - this.langFailsPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'fails.json'); - this.langSuccessPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'success.json'); - this.langUidMapperPath = path.resolve(sanitizepath(this.config.data), 'mapper', 'languages', 'uid-mapper.json'); + this.langMapperPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'languages'); + this.langFolderPath = path.resolve(sanitizePath(this.config.data), sanitizePath(this.localeConfig.dirName)); + this.langFailsPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'languages', 'fails.json'); + this.langSuccessPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'languages', 'success.json'); + this.langUidMapperPath = path.resolve(sanitizePath(this.config.data), 'mapper', 'languages', 'uid-mapper.json'); } async start(): Promise { diff --git a/packages/contentstack-import/src/utils/backup-handler.ts b/packages/contentstack-import/src/utils/backup-handler.ts index 96388857ce..ae8afc8782 100755 --- a/packages/contentstack-import/src/utils/backup-handler.ts +++ b/packages/contentstack-import/src/utils/backup-handler.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { copy } from 'fs-extra'; -import { cliux, sanitizepath } from '@contentstack/cli-utilities'; +import { cliux, sanitizePath } from '@contentstack/cli-utilities'; import { fileHelper, trace } from './index'; import { ImportConfig } from '../types'; @@ -14,7 +14,7 @@ export default async function backupHandler(importConfig: ImportConfig): Promise const subDir = isSubDirectory(importConfig); if (subDir) { - backupDirPath = path.resolve(sanitizepath(importConfig.contentDir), '..', '_backup_' + Math.floor(Math.random() * 1000)); + backupDirPath = path.resolve(sanitizePath(importConfig.contentDir), '..', '_backup_' + Math.floor(Math.random() * 1000)); if (importConfig.createBackupDir) { cliux.print( `Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`, diff --git a/packages/contentstack-import/src/utils/common-helper.ts b/packages/contentstack-import/src/utils/common-helper.ts index 7b398d4ef8..bee4d6981b 100644 --- a/packages/contentstack-import/src/utils/common-helper.ts +++ b/packages/contentstack-import/src/utils/common-helper.ts @@ -7,7 +7,7 @@ import * as _ from 'lodash'; import * as path from 'path'; -import { HttpClient, managementSDKClient, isAuthenticated, sanitizepath } from '@contentstack/cli-utilities'; +import { HttpClient, managementSDKClient, isAuthenticated, sanitizePath } from '@contentstack/cli-utilities'; import { readFileSync, readdirSync, readFile } from './file-helper'; import chalk from 'chalk'; import { log } from './logger'; @@ -65,9 +65,9 @@ export const sanitizeStack = (importConfig: ImportConfig) => { const newStackVersion = stackDetails.data.stack.settings.version; const newStackDate = new Date(newStackVersion).toString(); const stackFilePath = path.join( - sanitizepath(importConfig.data), - sanitizepath(importConfig.modules.stack.dirName), - sanitizepath(importConfig.modules.stack.fileName), + sanitizePath(importConfig.data), + sanitizePath(importConfig.modules.stack.dirName), + sanitizePath(importConfig.modules.stack.fileName), ); const oldStackDetails = readFileSync(stackFilePath); diff --git a/packages/contentstack-import/src/utils/file-helper.ts b/packages/contentstack-import/src/utils/file-helper.ts index 9429f6479b..e5c613b90d 100644 --- a/packages/contentstack-import/src/utils/file-helper.ts +++ b/packages/contentstack-import/src/utils/file-helper.ts @@ -2,11 +2,11 @@ import * as fs from 'fs'; import * as path from 'path'; import mkdirp from 'mkdirp'; import * as bigJSON from 'big-json'; -import { FsUtility, sanitizepath } from '@contentstack/cli-utilities'; +import { FsUtility, sanitizePath } from '@contentstack/cli-utilities'; export const readFileSync = function (filePath: string, parse: boolean = true): any { let data; - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); if (fs.existsSync(filePath)) { try { data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : data; @@ -20,7 +20,7 @@ export const readFileSync = function (filePath: string, parse: boolean = true): // by default file type is json export const readFile = async (filePath: string, options = { type: 'json' }): Promise => { return new Promise((resolve, reject) => { - filePath = path.resolve(sanitizepath(filePath)); + filePath = path.resolve(sanitizePath(filePath)); fs.readFile(filePath, 'utf-8', (error, data) => { if (error) { if (error.code === 'ENOENT') { @@ -41,7 +41,7 @@ export const readLargeFile = function (filePath: string, opts?: any): Promise { const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' }); @@ -82,7 +82,7 @@ export const writeLargeFile = function (filePath: string, data: any): Promise { const stringifyStream = bigJSON.createStringifyStream({ body: data, @@ -117,7 +117,7 @@ export const readdirSync = function (dirPath: string): any { export const isFolderExist = async (folderPath: string): Promise => { return new Promise((resolve, reject) => { - folderPath = path.resolve(sanitizepath(folderPath)); + folderPath = path.resolve(sanitizePath(folderPath)); fs.access(folderPath, (error) => { if (error) { return resolve(false); diff --git a/packages/contentstack-import/src/utils/import-config-handler.ts b/packages/contentstack-import/src/utils/import-config-handler.ts index c46e4c58b8..48ee0231ba 100644 --- a/packages/contentstack-import/src/utils/import-config-handler.ts +++ b/packages/contentstack-import/src/utils/import-config-handler.ts @@ -1,7 +1,7 @@ import merge from 'merge'; import * as path from 'path'; import { omit, filter, includes, isArray } from 'lodash'; -import { configHandler, isAuthenticated, cliux, sanitizepath } from '@contentstack/cli-utilities'; +import { configHandler, isAuthenticated, cliux, sanitizePath } from '@contentstack/cli-utilities'; import defaultConfig from '../config'; import { readFile, fileExistsSync } from './file-helper'; import { askContentDir, askAPIKey } from './interactive'; @@ -81,7 +81,7 @@ const setupConfig = async (importCmdFlags: any): Promise => { if (importCmdFlags['branch']) { config.branchName = importCmdFlags['branch']; - config.branchDir = path.join(sanitizepath(config.contentDir), sanitizepath (config.branchName)); + config.branchDir = path.join(sanitizePath(config.contentDir), sanitizePath (config.branchName)); } if (importCmdFlags['module']) { config.moduleName = importCmdFlags['module']; diff --git a/packages/contentstack-import/src/utils/log.ts b/packages/contentstack-import/src/utils/log.ts index 5445da302b..aac6d63457 100644 --- a/packages/contentstack-import/src/utils/log.ts +++ b/packages/contentstack-import/src/utils/log.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { LogEntry } from 'winston/index'; -import { Logger, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; +import { Logger, pathValidator, sanitizePath } from '@contentstack/cli-utilities'; import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger'; import { ImportConfig } from '../types'; @@ -26,7 +26,7 @@ export function log(entryOrMessage: MessageType, logType?: LogsType, hidden?: bo export function initLogger(config?: ImportConfig | undefined) { if (!logger) { - const basePath = pathValidator(join(sanitizepath(config?.cliLogsPath ?? process.cwd()), 'logs', 'import')); + const basePath = pathValidator(join(sanitizePath(config?.cliLogsPath ?? process.cwd()), 'logs', 'import')); logger = new Logger(Object.assign(config ?? {}, { basePath })); } diff --git a/packages/contentstack-import/src/utils/logger.ts b/packages/contentstack-import/src/utils/logger.ts index 08a5ef8044..782e07c2c3 100644 --- a/packages/contentstack-import/src/utils/logger.ts +++ b/packages/contentstack-import/src/utils/logger.ts @@ -8,7 +8,7 @@ import * as winston from 'winston'; import * as path from 'path'; import mkdirp from 'mkdirp'; import { ImportConfig } from '../types'; -import { sanitizepath } from '@contentstack/cli-utilities'; +import { sanitizePath } from '@contentstack/cli-utilities'; const slice = Array.prototype.slice; @@ -59,9 +59,9 @@ let errorTransport; function init(_logPath: string) { if (!logger || !errorLogger) { - const logsDir = path.resolve(sanitizepath(_logPath), 'logs', 'import'); + const logsDir = path.resolve(sanitizePath(_logPath), 'logs', 'import'); successTransport = { - filename: path.join(sanitizepath(logsDir), 'success.log'), + filename: path.join(sanitizePath(logsDir), 'success.log'), maxFiles: 20, maxsize: 1000000, tailable: true, @@ -69,7 +69,7 @@ function init(_logPath: string) { }; errorTransport = { - filename: path.join(sanitizepath(logsDir), 'error.log'), + filename: path.join(sanitizePath(logsDir), 'error.log'), maxFiles: 20, maxsize: 1000000, tailable: true, diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js index 064b3cc546..de122268f7 100644 --- a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -8,9 +8,9 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf let uidMapping = {}; modules.forEach((module) => { - const mappingFilePath = path.join(sanitizepath(filePath), 'mapper', sanitizepath(module), 'uid-mapping.json'); + const mappingFilePath = path.join(sanitizePath(filePath), 'mapper', sanitizePath(module), 'uid-mapping.json'); if (fs.existsSync(mappingFilePath)) { - const mappedIds = JSON.parse(fs.readFileSync(sanitizepath(mappingFilePath), 'utf-8')); + const mappedIds = JSON.parse(fs.readFileSync(sanitizePath(mappingFilePath), 'utf-8')); if (module === 'marketplace_apps') { Object.values(mappedIds).forEach((ids) => Object.assign(uidMapping, ids)); diff --git a/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js b/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js index 532e4e4116..48652ba10d 100644 --- a/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js +++ b/packages/contentstack-migration/examples/change-master-locale/01-change-master-locale.js @@ -2,7 +2,7 @@ let fs = require('fs').promises; let path = require('path') let crypto = require('crypto') let supportedLocales = require('./locales.json') -const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities') +const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities') module.exports = async ({migration, config}) => { let changeMasterLocale = { @@ -51,10 +51,10 @@ module.exports = async ({migration, config}) => { let contentTypes = await fs.readdir(pathValidator(path.resolve(config.data_dir, 'entries'))) let sourceMasterLocaleEntries, targetMasterLocaleEntries for (let contentType of contentTypes) { - sourceMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${sanitizepath(contentType)}/${sanitizepath(masterLocale)}.json`)), {encoding: 'utf8'}) + sourceMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizePath(config.data_dir), `entries/${sanitizePath(contentType)}/${sanitizePath(masterLocale)}.json`)), {encoding: 'utf8'}) sourceMasterLocaleEntries = JSON.parse(sourceMasterLocaleEntries) - targetMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${sanitizepath(contentType)}/${sanitizepath(config.target_locale)}.json`)), { encoding: 'utf8', flag: 'a+'}) + targetMasterLocaleEntries = await fs.readFile(pathValidator(path.resolve(sanitizePath(config.data_dir), `entries/${sanitizePath(contentType)}/${sanitizePath(config.target_locale)}.json`)), { encoding: 'utf8', flag: 'a+'}) if (targetMasterLocaleEntries.length === 0) { targetMasterLocaleEntries = {} } else { diff --git a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js index de922494fa..a9a5b63867 100644 --- a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js +++ b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js @@ -3,7 +3,7 @@ let { existsSync } = require('fs'); let path = require('path'); let crypto = require('crypto'); let supportedLocales = require('./locales.json'); -const { pathValidator, FsUtility, sanitizepath } = require('@contentstack/cli-utilities'); +const { pathValidator, FsUtility, sanitizePath } = require('@contentstack/cli-utilities'); module.exports = async ({ migration, config }) => { let changeMasterLocale = { @@ -18,9 +18,9 @@ module.exports = async ({ migration, config }) => { } async function tailorData() { - let locales = await fs.readFile(pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/locales.json')), 'utf-8'); + let locales = await fs.readFile(pathValidator(path.resolve(sanitizePath(config.data_dir), 'locales/locales.json')), 'utf-8'); let masterLocale = await fs.readFile( - pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/master-locale.json')), + pathValidator(path.resolve(sanitizePath(config.data_dir), 'locales/master-locale.json')), 'utf-8', ); @@ -49,7 +49,7 @@ module.exports = async ({ migration, config }) => { await handleEntries(masterLocale); await fs.writeFile( - pathValidator(path.resolve(sanitizepath(config.data_dir), 'locales/locales.json')), + pathValidator(path.resolve(sanitizePath(config.data_dir), 'locales/locales.json')), JSON.stringify(locales), ); masterLocale = await fs.readFile( @@ -67,20 +67,20 @@ module.exports = async ({ migration, config }) => { } async function handleEntries(masterLocale) { - let contentTypes = await fs.readdir(pathValidator(path.resolve(sanitizepath(config.data_dir), 'entries'))); + let contentTypes = await fs.readdir(pathValidator(path.resolve(sanitizePath(config.data_dir), 'entries'))); for (let contentType of contentTypes) { let sourceMasterLocaleEntries, targetMasterLocaleEntries; sourceMasterLocaleEntries = await fs.readFile( - pathValidator(path.resolve(sanitizepath(config.data_dir), `entries/${contentType}/${masterLocale}/index.json`)), + pathValidator(path.resolve(sanitizePath(config.data_dir), `entries/${contentType}/${masterLocale}/index.json`)), { encoding: 'utf8' }, ); sourceMasterLocaleEntries = await fs.readFile( pathValidator( path.resolve( - sanitizepath(config.data_dir), - `entries/${sanitizepath(contentType)}/${sanitizepath(masterLocale)}/${Object.values(JSON.parse(sanitizepath(sourceMasterLocaleEntries)))}`, + sanitizePath(config.data_dir), + `entries/${sanitizePath(contentType)}/${sanitizePath(masterLocale)}/${Object.values(JSON.parse(sanitizePath(sourceMasterLocaleEntries)))}`, ), ), { encoding: 'utf8' }, diff --git a/packages/contentstack-migration/src/commands/cm/stacks/migration.js b/packages/contentstack-migration/src/commands/cm/stacks/migration.js index 191a69c146..23b2c46257 100644 --- a/packages/contentstack-migration/src/commands/cm/stacks/migration.js +++ b/packages/contentstack-migration/src/commands/cm/stacks/migration.js @@ -19,7 +19,7 @@ const { flags, isAuthenticated, pathValidator, - sanitizepath, + sanitizePath, } = require('@contentstack/cli-utilities'); const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators'); @@ -181,7 +181,7 @@ class MigrationCommand extends Command { const file = element; if (extname(file) === '.js') { // eslint-disable-next-line no-await-in-loop - await this.execSingleFile(pathValidator(resolve(sanitizepath(filePath), sanitizepath(file))), mapInstance); + await this.execSingleFile(pathValidator(resolve(sanitizePath(filePath), sanitizePath(file))), mapInstance); } } } catch (error) { diff --git a/packages/contentstack-migration/src/utils/logger.js b/packages/contentstack-migration/src/utils/logger.js index f23a4a2566..3f875049e6 100644 --- a/packages/contentstack-migration/src/utils/logger.js +++ b/packages/contentstack-migration/src/utils/logger.js @@ -4,7 +4,7 @@ const { createLogger, format, transports } = require('winston'); const { resolve, join } = require('path'); const { slice } = Array.prototype; const { stringify } = JSON; -const { pathValidator, sanitizepath } = require('@contentstack/cli-utilities'); +const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities'); const { combine, label, printf, colorize } = format; @@ -33,7 +33,7 @@ function init(logFileName) { // Create dir if does not exist makeDir(logsDir); - const logPath = pathValidator(join(sanitizepath(logsDir), sanitizepath(logFileName) + '.log')); + const logPath = pathValidator(join(sanitizePath(logsDir), sanitizePath(logFileName) + '.log')); const logger = createLogger({ format: combine(colorize(), label({ label: 'Migration' }), customFormat), transports: [new transports.File({ filename: logPath })], diff --git a/packages/contentstack-migration/src/utils/migration-logger.js b/packages/contentstack-migration/src/utils/migration-logger.js index 636a619311..59fa0fb939 100644 --- a/packages/contentstack-migration/src/utils/migration-logger.js +++ b/packages/contentstack-migration/src/utils/migration-logger.js @@ -1,15 +1,15 @@ const winston = require('winston'); const path = require('path'); -const { sanitizepath } = require('@contentstack/cli-utilities'); +const { sanitizePath } = require('@contentstack/cli-utilities'); module.exports = class MigrationLogger { constructor(filePath) { - this.filePath = path.join(sanitizepath(filePath), 'migration-logs'); + this.filePath = path.join(sanitizePath(filePath), 'migration-logs'); this.logger = winston.createLogger({ levels: { error: 1 }, transports: [ new winston.transports.File({ level: 'error', - filename: path.join(sanitizepath(this.filePath), 'error.logs'), + filename: path.join(sanitizePath(this.filePath), 'error.logs'), format: winston.format.combine(winston.format.timestamp(), winston.format.json()), }), ], diff --git a/packages/contentstack-seed/src/seed/importer.ts b/packages/contentstack-seed/src/seed/importer.ts index 106a60348b..ddeece2f49 100644 --- a/packages/contentstack-seed/src/seed/importer.ts +++ b/packages/contentstack-seed/src/seed/importer.ts @@ -1,7 +1,7 @@ import * as process from 'process'; import * as path from 'path'; import ImportCommand from '@contentstack/cli-cm-import'; -import { pathValidator, sanitizepath } from '@contentstack/cli-utilities'; +import { pathValidator, sanitizePath } from '@contentstack/cli-utilities'; const STACK_FOLDER = 'stack'; @@ -16,7 +16,7 @@ export interface ImporterOptions { } export async function run(options: ImporterOptions) { - const importPath = pathValidator(path.resolve(sanitizepath(options.tmpPath), STACK_FOLDER)); + const importPath = pathValidator(path.resolve(sanitizePath(options.tmpPath), STACK_FOLDER)); const args = options.alias ? ['-k', options.api_key, '-d', importPath, '--alias', options.alias!] diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index 172c2871ad..1d9e088afc 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -56,7 +56,7 @@ export const validatePath = (input: string) => { export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // To remove the relative path -export const sanitizepath = (str: string) => str.replace(/^(\.\.(\/|\\|$))+/, ''); +export const sanitizePath = (str: string) => str.replace(/^(\.\.(\/|\\|$))+/, ''); // To validate the UIDs of assets export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); diff --git a/packages/contentstack-utilities/src/logger.ts b/packages/contentstack-utilities/src/logger.ts index cc866a568c..a5eba73772 100644 --- a/packages/contentstack-utilities/src/logger.ts +++ b/packages/contentstack-utilities/src/logger.ts @@ -3,7 +3,7 @@ import { klona } from 'klona/full'; import path, { normalize } from 'path'; import winston, { LogEntry } from 'winston'; -import { cliux as ux, PrintOptions, messageHandler, sanitizepath } from './index'; +import { cliux as ux, PrintOptions, messageHandler, sanitizePath } from './index'; export class LoggerService { name: string; @@ -19,7 +19,7 @@ export class LoggerService { const logger = winston.createLogger({ transports: [ new winston.transports.File({ - filename: path.resolve(sanitizepath(process.env.CS_CLI_LOG_PATH) || `${sanitizepath(pathToLog)}/logs`, `${sanitizepath(name)}.log`), + filename: path.resolve(sanitizePath(process.env.CS_CLI_LOG_PATH) || `${sanitizePath(pathToLog)}/logs`, `${sanitizePath(name)}.log`), }), ], format: winston.format.combine( diff --git a/packages/contentstack/src/utils/context-handler.ts b/packages/contentstack/src/utils/context-handler.ts index e708ebe02e..7319aae80c 100644 --- a/packages/contentstack/src/utils/context-handler.ts +++ b/packages/contentstack/src/utils/context-handler.ts @@ -1,6 +1,6 @@ import * as shortUUID from 'short-uuid'; import * as path from 'path'; -import { configHandler, pathValidator, sanitizepath } from '@contentstack/cli-utilities'; +import { configHandler, pathValidator, sanitizePath } from '@contentstack/cli-utilities'; import { machineIdSync } from 'node-machine-id'; export default class CsdxContext { @@ -48,7 +48,7 @@ export default class CsdxContext { this.plugin.name = command.pluginName; this.plugin.config = { ...((this.plugin.pjson && this.plugin.pjson.csdxConfig) || {}) }; this.messageFilePath = pathValidator( - path.resolve(sanitizepath(this.plugin.root), sanitizepath(this.plugin.config.messageFilePath) || './messages/index.json'), + path.resolve(sanitizePath(this.plugin.root), sanitizePath(this.plugin.config.messageFilePath) || './messages/index.json'), ); this.info.shortCommandName = this.plugin?.config?.shortCommandName?.[cliOpts.id]; analyticsInfo.push(this.info.shortCommandName || cliOpts.id); From 60f71f2355753a8d67ea5a8ca45aaf96e554c35d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 17 May 2024 18:05:13 +0530 Subject: [PATCH 04/12] fixed Regex --- packages/contentstack-audit/src/messages/index.ts | 5 +++-- .../src/export/modules/content-types.ts | 2 +- .../contentstack-export/src/export/modules/entries.ts | 2 +- .../contentstack-import/src/utils/asset-helper.ts | 11 +++++++---- .../contentstack-import/src/utils/entries-helper.ts | 8 +++++--- .../examples/05-Update-reference-entry-from-mapper.js | 2 ++ .../02-change-master-locale-new-file-structure.js | 2 +- packages/contentstack-utilities/src/helpers.ts | 7 ++++++- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index a488baf23a..6dad1038cf 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -1,5 +1,5 @@ import memoize from 'lodash/memoize'; -import { escapeRegExp } from '@contentstack/cli-utilities'; +import { escapeRegExp, replaceNonAlphanumericWithEmpty } from '@contentstack/cli-utilities'; const errors = {}; @@ -76,7 +76,8 @@ function $t(msg: string, args: Record): string { if (!msg) return ''; for (const key of Object.keys(args)) { - const escapedKey = escapeRegExp(key); + let escapedKey = escapeRegExp(key); + escapedKey = replaceNonAlphanumericWithEmpty(escapedKey) const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g'); const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); diff --git a/packages/contentstack-export/src/export/modules/content-types.ts b/packages/contentstack-export/src/export/modules/content-types.ts index c199cf8784..9e714ec9d0 100644 --- a/packages/contentstack-export/src/export/modules/content-types.ts +++ b/packages/contentstack-export/src/export/modules/content-types.ts @@ -99,7 +99,7 @@ export default class ContentTypesExport extends BaseClass { async writeContentTypes(contentTypes: Record[]) { function write(contentType: Record) { return fsUtil.writeFile( - path.join(sanitizePath(this.contentTypesDirPath), `${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`), + path.join(sanitizePath(this.contentTypesDirPath), sanitizePath(`${contentType.uid === 'schema' ? 'schema|1' : contentType.uid}.json`)), contentType, ); } diff --git a/packages/contentstack-export/src/export/modules/entries.ts b/packages/contentstack-export/src/export/modules/entries.ts index 5dc6976c7f..14964f9c77 100644 --- a/packages/contentstack-export/src/export/modules/entries.ts +++ b/packages/contentstack-export/src/export/modules/entries.ts @@ -153,7 +153,7 @@ export default class EntriesExport extends BaseClass { options: { locale: string; contentType: string; versionedEntryPath: string }, ): Promise { const onSuccess = ({ response, apiData: entry }: any) => { - fsUtil.writeFile(path.join(sanitizePath(options.versionedEntryPath), `${entry.uid}.json`), response); + fsUtil.writeFile(path.join(sanitizePath(options.versionedEntryPath), sanitizePath(`${entry.uid}.json`)), response); log( this.exportConfig, `Exported versioned entries of type '${options.contentType}' locale '${options.locale}'`, diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index c722193898..821c1578e9 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -1,7 +1,7 @@ import Bluebird from 'bluebird'; import * as url from 'url'; import * as path from 'path'; -import { ContentstackClient, managementSDKClient } from '@contentstack/cli-utilities'; +import { ContentstackClient, managementSDKClient, replaceNonAlphanumericWithEmpty, isValidURL } from '@contentstack/cli-utilities'; import { ImportConfig } from '../types'; const debug = require('debug')('util:requests'); let _ = require('lodash'); @@ -255,8 +255,10 @@ export const lookupAssets = function ( // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&'); // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&'); // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl); - entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); - matchedUrls.push(mappedAssetUrl); + if(isValidURL(mappedAssetUrl)){ + entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + matchedUrls.push(mappedAssetUrl); + } } else { unmatchedUrls.push(assetUrl); } @@ -265,7 +267,8 @@ export const lookupAssets = function ( assetUids.forEach(function (assetUid: any) { let uid = mappedAssetUids[assetUid]; if (typeof uid !== 'undefined') { - const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + let escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + escapedAssetUid = replaceNonAlphanumericWithEmpty(escapedAssetUid) const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img'); entry = entry.replace(regex, uid); matchedUids.push(assetUid); diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 7d970f0c5c..4e563639da 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import * as _ from 'lodash'; import config from '../config'; import * as fileHelper from './file-helper'; -import { escapeRegExp } from '@contentstack/cli-utilities'; +import { escapeRegExp, replaceNonAlphanumericWithEmpty } from '@contentstack/cli-utilities'; import { EntryJsonRTEFieldDataType } from '../types/entries'; @@ -200,7 +200,8 @@ export const lookupEntries = function ( let entry = JSON.stringify(data.entry); uids.forEach(function (uid: any) { if (mappedUids.hasOwnProperty(uid)) { - const sanitizedUid = escapeRegExp(uid); + let sanitizedUid = escapeRegExp(uid); + sanitizedUid = replaceNonAlphanumericWithEmpty(sanitizedUid) const escapedMappedUid = escapeRegExp(mappedUids[uid]); const uidRegex = new RegExp(`\\b${sanitizedUid}\\b`, 'img'); entry = entry.replace(uidRegex, escapedMappedUid); @@ -573,7 +574,8 @@ export const restoreJsonRteEntryRefs = ( }; function updateUids(str: string, match: string, uidMapper: Record) { - const sanitizedMatch = escapeRegExp(match); + let sanitizedMatch = escapeRegExp(match); + sanitizedMatch = replaceNonAlphanumericWithEmpty(sanitizedMatch) const regex = new RegExp(`\\b${sanitizedMatch}\\b`, 'g'); return str.replace(regex, (matchedString) => uidMapper[matchedString]); } diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js index de122268f7..45822a73f3 100644 --- a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -1,6 +1,7 @@ const fs = require('fs'); const chalk = require('chalk'); const path = require('path'); +const { replaceNonAlphanumericWithEmpty } = require('@contentstack/cli-utilities'); module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config }) => { const modules = ['entries', 'assets', 'extensions', 'marketplace_apps']; @@ -61,6 +62,7 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf let oldUids = Object.keys(uidMapping); matches.forEach((m) => { if (oldUids.includes(m)) { + m = replaceNonAlphanumericWithEmpty(m); let regex = new RegExp(m, 'g'); stringifiedEntry = stringifiedEntry.replace(regex, uidMapping[m]); console.log(chalk.green(`Replacing the UID '${m}' with '${uidMapping[m]}'...`)); diff --git a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js index a9a5b63867..e4ca3f6550 100644 --- a/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js +++ b/packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js @@ -72,7 +72,7 @@ module.exports = async ({ migration, config }) => { let sourceMasterLocaleEntries, targetMasterLocaleEntries; sourceMasterLocaleEntries = await fs.readFile( - pathValidator(path.resolve(sanitizePath(config.data_dir), `entries/${contentType}/${masterLocale}/index.json`)), + pathValidator(path.resolve(sanitizePath(config.data_dir), sanitizePath(`entries/${contentType}/${masterLocale}/index.json`))), { encoding: 'utf8' }, ); diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index 1d9e088afc..8f0111e639 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -62,4 +62,9 @@ export const sanitizePath = (str: string) => str.replace(/^(\.\.(\/|\\|$))+/, ' export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); // Validate File name -export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); \ No newline at end of file +export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); + +// Validate Regex +export const replaceNonAlphanumericWithEmpty = input => input.replace(/[^a-zA-Z0-9]/g, ''); + +export const isValidURL = url => /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})([\/\w .-]*)*\/?$/.test(url); \ No newline at end of file From 4f34b4866a8d14645eb776cd68041322418f99ae Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 17 May 2024 20:44:12 +0530 Subject: [PATCH 05/12] fix auth issues --- packages/contentstack-utilities/src/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index 8f0111e639..a167b67495 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -56,7 +56,7 @@ export const validatePath = (input: string) => { export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // To remove the relative path -export const sanitizePath = (str: string) => str.replace(/^(\.\.(\/|\\|$))+/, ''); +export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, ''); // To validate the UIDs of assets export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); @@ -65,6 +65,6 @@ export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); // Validate Regex -export const replaceNonAlphanumericWithEmpty = input => input.replace(/[^a-zA-Z0-9]/g, ''); +export const replaceNonAlphanumericWithEmpty = input => input?.replace(/[^a-zA-Z0-9]/g, ''); export const isValidURL = url => /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})([\/\w .-]*)*\/?$/.test(url); \ No newline at end of file From c410fce31ac736984dca456431c7cd32d2bd3f29 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 20 May 2024 15:52:45 +0530 Subject: [PATCH 06/12] Resolved Regular expression DOS attacks and prototype pollution --- package-lock.json | 216 +++++++++++++++--- packages/contentstack-audit/README.md | 14 +- .../contentstack-audit/src/messages/index.ts | 14 +- .../src/utils/asset-helper.ts | 21 +- .../src/utils/entries-helper.ts | 36 +-- .../05-Update-reference-entry-from-mapper.js | 25 +- packages/contentstack-utilities/package.json | 3 +- .../contentstack-utilities/src/helpers.ts | 18 +- packages/contentstack/README.md | 14 +- pnpm-lock.yaml | 42 ++++ 10 files changed, 316 insertions(+), 87 deletions(-) diff --git a/package-lock.json b/package-lock.json index a14ad02d7d..8765699e9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -842,9 +842,13 @@ } }, "node_modules/@contentstack/utils": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.3.tgz", - "integrity": "sha512-Zj2ejyfbxZlXrF1Wl9lhwK2mCCWo5ooiDnSlNA8nupZ1nDsTfouYERgps8r/uyzm18Vda2wBitxloThxKAyzsA==" + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.3.4.tgz", + "integrity": "sha512-RGTJDcI2pabV4Ub5f4yuILz7QclR61qEusdfy48J3pnnXlbw2KODU5iJc/TtGB970OpH87/JlLsQzCUCGsd99g==", + "dependencies": { + "cheerio": "^1.0.0-rc.12", + "dompurify": "^3.1.1" + } }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", @@ -1841,6 +1845,12 @@ "which": "^2.0.2" } }, + "node_modules/@npmcli/git/node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/@npmcli/git/node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -1853,6 +1863,21 @@ "node": ">=10" } }, + "node_modules/@npmcli/git/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/@npmcli/git/node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", @@ -2203,19 +2228,20 @@ } }, "node_modules/@oclif/plugin-plugins": { - "version": "5.0.21", - "resolved": "https://registry.npmjs.org/@oclif/plugin-plugins/-/plugin-plugins-5.0.21.tgz", - "integrity": "sha512-kyCIYUdX2a6+b6c7yjME6rW0Bw/iPqgLgCVhkV14qKHVS7FteGMDyio+nzPJ3BGdMHZuxGh9po7PImqNx7Mk7w==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@oclif/plugin-plugins/-/plugin-plugins-5.1.2.tgz", + "integrity": "sha512-O8LhkCoL4VKFn72Ur2D9zB3a7ntgIrlOzjhRnND6cwsoA0FBeqNi0Jz8pzvJzLv7fZCN9O6kxNBN/Zmkb7rgJg==", "dependencies": { "@oclif/core": "^3.26.6", "chalk": "^5.3.0", "debug": "^4.3.4", - "npm": "^10.7.0", + "npm": "^10.8.0", "npm-package-arg": "^11.0.2", "npm-run-path": "^5.3.0", "object-treeify": "^4.0.1", "semver": "^7.6.2", - "validate-npm-package-name": "^5.0.0", + "validate-npm-package-name": "^5.0.1", + "which": "^4.0.0", "yarn": "^1.22.22" }, "engines": { @@ -4528,9 +4554,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1622.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1622.0.tgz", - "integrity": "sha512-ff/jc1XwSCWDcqa7ezLLsqRbs1IVPXMoUTMFHHYRTuNwGQDn/073DbmyLkqD4ARBcTxkOooSaP7uySoZ2ekFeg==", + "version": "2.1623.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1623.0.tgz", + "integrity": "sha512-SFPc+QJqoghsE0nn6YSmrDDDPpWc3m4rcDQYg6W3GQek+f1v6kycxM5+N58pMZ2iWhRSOTf9NQRcZj0ZU3PklQ==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4559,9 +4585,9 @@ } }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.0.tgz", + "integrity": "sha512-IiB0wQeKyPRdsFVhBgIo31FbzOyf2M6wYl7/NVutFwFBRMiAbjNiydJIHKeLmPugF4kJLfA1uWZ82Is2QzqqFA==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -6106,9 +6132,9 @@ } }, "node_modules/contentstack": { - "version": "3.19.2", - "resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.19.2.tgz", - "integrity": "sha512-AQNfixXaXcj8j/dncq4nMUIoljWNqO+kVLU1o+qGD9pqBiI/e+f2bn1DAqtE9Ona1k+rZnGjcXGi8bPHHyW2yA==", + "version": "3.19.3", + "resolved": "https://registry.npmjs.org/contentstack/-/contentstack-3.19.3.tgz", + "integrity": "sha512-2bfiVXfM6Y76NKIkCYdwHufRBgssCA8OWTucFQiHCPKEN3kWa9Wz7R9VVVErYsyI5He6lGofY/CCtLZkpuvPVw==", "dependencies": { "@contentstack/utils": "^1.3.3", "cheerio": "^1.0.0-rc.12", @@ -6192,6 +6218,25 @@ "node": ">= 8" } }, + "node_modules/cross-spawn/node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + }, + "node_modules/cross-spawn/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -6715,6 +6760,11 @@ "url": "https://github.com/fb55/domhandler?sponsor=1" } }, + "node_modules/dompurify": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.1.3.tgz", + "integrity": "sha512-5sOWYSNPaxz6o2MUPvtyxTTqR4D3L77pr5rUQoWgD5ROQtVIZQgJkXbo1DLlK3vj11YGw5+LnF4SYti4gZmwng==" + }, "node_modules/domutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", @@ -6807,9 +6857,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.773", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.773.tgz", - "integrity": "sha512-87eHF+h3PlCRwbxVEAw9KtK3v7lWfc/sUDr0W76955AdYTG4bV/k0zrl585Qnj/skRMH2qOSiE+kqMeOQ+LOpw==", + "version": "1.4.774", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.774.tgz", + "integrity": "sha512-132O1XCd7zcTkzS3FgkAzKmnBuNJjK8WjcTtNuoylj7MYbqw5eXehjQ5OK91g0zm7OTKIPeaAG4CPoRfD9M1Mg==", "dev": true }, "node_modules/elegant-spinner": { @@ -11432,9 +11482,12 @@ } }, "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz", + "integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==", + "engines": { + "node": ">=16" + } }, "node_modules/isomorphic-fetch": { "version": "3.0.0", @@ -14732,6 +14785,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/node-gyp/node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/node-gyp/node_modules/npmlog": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz", @@ -14776,6 +14835,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/node-gyp/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -19955,6 +20029,62 @@ "node": ">=8.10.0" } }, + "node_modules/recheck": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/recheck/-/recheck-4.4.5.tgz", + "integrity": "sha512-J80Ykhr+xxWtvWrfZfPpOR/iw2ijvb4WY8d9AVoN8oHsPP07JT1rCAalUSACMGxM1cvSocb6jppWFjVS6eTTrA==", + "engines": { + "node": ">=14" + }, + "optionalDependencies": { + "recheck-jar": "4.4.5", + "recheck-linux-x64": "4.4.5", + "recheck-macos-x64": "4.4.5", + "recheck-windows-x64": "4.4.5" + } + }, + "node_modules/recheck-jar": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/recheck-jar/-/recheck-jar-4.4.5.tgz", + "integrity": "sha512-a2kMzcfr+ntT0bObNLY22EUNV6Z6WeZ+DybRmPOUXVWzGcqhRcrK74tpgrYt3FdzTlSh85pqoryAPmrNkwLc0g==", + "optional": true + }, + "node_modules/recheck-linux-x64": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/recheck-linux-x64/-/recheck-linux-x64-4.4.5.tgz", + "integrity": "sha512-s8OVPCpiSGw+tLCxH3eei7Zp2AoL22kXqLmEtWXi0AnYNwfuTjZmeLn2aQjW8qhs8ZPSkxS7uRIRTeZqR5Fv/Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/recheck-macos-x64": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/recheck-macos-x64/-/recheck-macos-x64-4.4.5.tgz", + "integrity": "sha512-Ouup9JwwoKCDclt3Na8+/W2pVbt8FRpzjkDuyM32qTR2TOid1NI+P1GA6/VQAKEOjvaxgGjxhcP/WqAjN+EULA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/recheck-windows-x64": { + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/recheck-windows-x64/-/recheck-windows-x64-4.4.5.tgz", + "integrity": "sha512-mkpzLHu9G9Ztjx8HssJh9k/Xm1d1d/4OoT7etHqFk+k1NGzISCRXBD22DqYF9w8+J4QEzTAoDf8icFt0IGhOEQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/rechoir": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", @@ -21212,6 +21342,12 @@ "node": ">=8" } }, + "node_modules/spawn-wrap/node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/spawn-wrap/node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -21251,6 +21387,21 @@ "semver": "bin/semver.js" } }, + "node_modules/spawn-wrap/node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/spdx-correct": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", @@ -23015,17 +23166,17 @@ } }, "node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", + "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", "dependencies": { - "isexe": "^2.0.0" + "isexe": "^3.1.1" }, "bin": { - "node-which": "bin/node-which" + "node-which": "bin/which.js" }, "engines": { - "node": ">= 8" + "node": "^16.13.0 || >=18.0.0" } }, "node_modules/which-boxed-primitive": { @@ -23934,6 +24085,12 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/yeoman-generator/node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/yeoman-generator/node_modules/json-parse-even-better-errors": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-3.0.2.tgz", @@ -26820,6 +26977,7 @@ "mkdirp": "^1.0.4", "open": "^8.4.2", "ora": "^5.4.0", + "recheck": "^4.4.5", "rxjs": "^6.6.7", "traverse": "^0.6.7", "unique-string": "^2.0.0", diff --git a/packages/contentstack-audit/README.md b/packages/contentstack-audit/README.md index caf850f222..f2f51c70d5 100644 --- a/packages/contentstack-audit/README.md +++ b/packages/contentstack-audit/README.md @@ -267,7 +267,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -341,7 +341,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -390,7 +390,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -420,7 +420,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -461,7 +461,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -489,7 +489,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -533,5 +533,5 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/update.ts)_ diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index 6dad1038cf..cba0ae2cc2 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -1,5 +1,5 @@ import memoize from 'lodash/memoize'; -import { escapeRegExp, replaceNonAlphanumericWithEmpty } from '@contentstack/cli-utilities'; +import { escapeRegExp, validateRegex } from '@contentstack/cli-utilities'; const errors = {}; @@ -76,11 +76,15 @@ function $t(msg: string, args: Record): string { if (!msg) return ''; for (const key of Object.keys(args)) { - let escapedKey = escapeRegExp(key); - escapedKey = replaceNonAlphanumericWithEmpty(escapedKey) + const escapedKey = escapeRegExp(key); const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g'); - const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; - msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); + let { status } = validateRegex(escapedKeyRegex) + if (status === 'safe') { + const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; + msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); + } else { + + } } return msg; diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index 821c1578e9..40fab00ca1 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -1,7 +1,7 @@ import Bluebird from 'bluebird'; import * as url from 'url'; import * as path from 'path'; -import { ContentstackClient, managementSDKClient, replaceNonAlphanumericWithEmpty, isValidURL } from '@contentstack/cli-utilities'; +import { ContentstackClient, managementSDKClient, isValidURL, validateRegex } from '@contentstack/cli-utilities'; import { ImportConfig } from '../types'; const debug = require('debug')('util:requests'); let _ = require('lodash'); @@ -255,9 +255,12 @@ export const lookupAssets = function ( // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&'); // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&'); // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl); - if(isValidURL(mappedAssetUrl)){ - entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); - matchedUrls.push(mappedAssetUrl); + if (isValidURL(mappedAssetUrl)) { + let { status } = validateRegex(new RegExp(assetUrl, 'img')) + if (status === 'safe') { + entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + matchedUrls.push(mappedAssetUrl); + } } } else { unmatchedUrls.push(assetUrl); @@ -267,11 +270,13 @@ export const lookupAssets = function ( assetUids.forEach(function (assetUid: any) { let uid = mappedAssetUids[assetUid]; if (typeof uid !== 'undefined') { - let escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - escapedAssetUid = replaceNonAlphanumericWithEmpty(escapedAssetUid) + const escapedAssetUid = assetUid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const regex = new RegExp(`\\b${escapedAssetUid}\\b`, 'img'); - entry = entry.replace(regex, uid); - matchedUids.push(assetUid); + let { status } = validateRegex(new RegExp(regex, 'img')) + if (status === 'safe') { + entry = entry.replace(regex, uid); + matchedUids.push(assetUid); + } } else { unmatchedUids.push(assetUid); } diff --git a/packages/contentstack-import/src/utils/entries-helper.ts b/packages/contentstack-import/src/utils/entries-helper.ts index 4e563639da..206afa4c5f 100644 --- a/packages/contentstack-import/src/utils/entries-helper.ts +++ b/packages/contentstack-import/src/utils/entries-helper.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import * as _ from 'lodash'; import config from '../config'; import * as fileHelper from './file-helper'; -import { escapeRegExp, replaceNonAlphanumericWithEmpty } from '@contentstack/cli-utilities'; +import { escapeRegExp, validateRegex } from '@contentstack/cli-utilities'; import { EntryJsonRTEFieldDataType } from '../types/entries'; @@ -87,14 +87,17 @@ export const lookupEntries = function ( uids.push(_entry[_parent[j]].uid); } } else { - _entry = _entry[_parent[j]]; - let _keys = _.clone(_parent).splice(j + 1, len); - if (Array.isArray(_entry)) { - for (let i = 0, _i = _entry?.length; i < _i; i++) { - update(_keys, form_id, _entry[i]); + const key = _parent[j]; + if (Object.prototype.hasOwnProperty.call(_entry, key)) { + _entry = _entry[key]; + let _keys = _.clone(_parent).splice(j + 1, len); + if (Array.isArray(_entry)) { + for (let i = 0, _i = _entry?.length; i < _i; i++) { + update(_keys, form_id, _entry[i]); + } + } else if (!(_entry instanceof Object)) { + break; } - } else if (!(_entry instanceof Object)) { - break; } } } @@ -200,12 +203,14 @@ export const lookupEntries = function ( let entry = JSON.stringify(data.entry); uids.forEach(function (uid: any) { if (mappedUids.hasOwnProperty(uid)) { - let sanitizedUid = escapeRegExp(uid); - sanitizedUid = replaceNonAlphanumericWithEmpty(sanitizedUid) + const sanitizedUid = escapeRegExp(uid); const escapedMappedUid = escapeRegExp(mappedUids[uid]); const uidRegex = new RegExp(`\\b${sanitizedUid}\\b`, 'img'); - entry = entry.replace(uidRegex, escapedMappedUid); - mapped.push(uid); + let { status } = validateRegex(uidRegex); + if (status === 'safe') { + entry = entry.replace(uidRegex, escapedMappedUid); + mapped.push(uid); + } } else { unmapped.push(uid); } @@ -574,10 +579,11 @@ export const restoreJsonRteEntryRefs = ( }; function updateUids(str: string, match: string, uidMapper: Record) { - let sanitizedMatch = escapeRegExp(match); - sanitizedMatch = replaceNonAlphanumericWithEmpty(sanitizedMatch) + const sanitizedMatch = escapeRegExp(match); const regex = new RegExp(`\\b${sanitizedMatch}\\b`, 'g'); - return str.replace(regex, (matchedString) => uidMapper[matchedString]); + let { status } = validateRegex(regex); + if (status === 'safe') + return str.replace(regex, (matchedString) => uidMapper[matchedString]); } function setDirtyTrue(jsonRteChild: any) { diff --git a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js index 45822a73f3..d02ddc2d68 100644 --- a/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js +++ b/packages/contentstack-migration/examples/05-Update-reference-entry-from-mapper.js @@ -1,7 +1,8 @@ const fs = require('fs'); const chalk = require('chalk'); const path = require('path'); -const { replaceNonAlphanumericWithEmpty } = require('@contentstack/cli-utilities'); +const { validateRegex } = require('@contentstack/cli-utilities'); + module.exports = async ({ migration, stackSDKInstance, managementAPIClient, config }) => { const modules = ['entries', 'assets', 'extensions', 'marketplace_apps']; @@ -16,7 +17,7 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf if (module === 'marketplace_apps') { Object.values(mappedIds).forEach((ids) => Object.assign(uidMapping, ids)); } else { - Object.assign(uidMapping, mappedIds); + Object.assign(uidMapping, sanitizeObject(mappedIds)); } } }); @@ -24,6 +25,16 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf return uidMapping; }; + const sanitizeObject = (obj) => { + const sanitized = {}; + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + sanitized[key] = obj[key]; + } + } + return sanitized; + } + const getEntries = async (ct) => { try { let entries = []; @@ -62,11 +73,13 @@ module.exports = async ({ migration, stackSDKInstance, managementAPIClient, conf let oldUids = Object.keys(uidMapping); matches.forEach((m) => { if (oldUids.includes(m)) { - m = replaceNonAlphanumericWithEmpty(m); let regex = new RegExp(m, 'g'); - stringifiedEntry = stringifiedEntry.replace(regex, uidMapping[m]); - console.log(chalk.green(`Replacing the UID '${m}' with '${uidMapping[m]}'...`)); - isUpdated = true; + let { status } = validateRegex(regex); + if (status === 'safe') { + stringifiedEntry = stringifiedEntry.replace(regex, uidMapping[m]); + console.log(chalk.green(`Replacing the UID '${m}' with '${uidMapping[m]}'...`)); + isUpdated = true; + } } }); return { stringifiedEntry, isUpdated }; diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index 90943b2623..d9f1786ea7 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -55,7 +55,8 @@ "unique-string": "^2.0.0", "uuid": "^9.0.0", "winston": "^3.7.2", - "xdg-basedir": "^4.0.0" + "xdg-basedir": "^4.0.0", + "recheck": "^4.4.5" }, "devDependencies": { "@contentstack/cli-dev-dependencies": "^1.2.4", diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index a167b67495..bda61760cd 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -1,6 +1,6 @@ +import { checkSync } from "recheck"; import authHandler from './auth-handler'; import { HttpClient, cliux, configHandler } from '.'; -import { string } from '@oclif/core/lib/args'; export const isAuthenticated = () => authHandler.isAuthenticated(); export const doesBranchExist = async (stack, branchName) => { return stack @@ -17,13 +17,13 @@ export const isManagementTokenValid = async (stackAPIKey, managementToken) => { const response = (await httpClient.get(`${configHandler.get('region').cma}/v3/environments?limit=1`))?.data; if (response?.environments) { return { valid: true } - } else if(response?.error_code) { + } else if (response?.error_code) { return { valid: false, message: response.error_message }; } else { - throw typeof response === "string"? response : ""; + throw typeof response === "string" ? response : ""; } } catch (error) { - return { valid: 'failedToCheck',message:`Failed to check the validity of the Management token. ${error}`}; + return { valid: 'failedToCheck', message: `Failed to check the validity of the Management token. ${error}` }; } } @@ -56,15 +56,15 @@ export const validatePath = (input: string) => { export const escapeRegExp = (str: string) => str?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // To remove the relative path -export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, ''); +export const sanitizePath = (str: string) => str?.replace(/^(\.\.(\/|\\|$))+/, ''); // To validate the UIDs of assets -export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); +export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); // Validate File name -export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); +export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); -// Validate Regex -export const replaceNonAlphanumericWithEmpty = input => input?.replace(/[^a-zA-Z0-9]/g, ''); +// Validate Regex for ReDDos +export const validateRegex = (str) => checkSync(str, ""); export const isValidURL = url => /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})([\/\w .-]*)*\/?$/.test(url); \ No newline at end of file diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 22992dcfcb..ea99d7b1d3 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -3492,7 +3492,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -3566,7 +3566,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -3615,7 +3615,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -3645,7 +3645,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -3686,7 +3686,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -3714,7 +3714,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -3758,7 +3758,7 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/update.ts)_ ## `csdx tokens` diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index efd80ea9ae..968adb6085 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1081,6 +1081,7 @@ importers: nyc: ^15.1.0 open: ^8.4.2 ora: ^5.4.0 + recheck: ^4.4.5 rimraf: ^2.7.1 rxjs: ^6.6.7 sinon: ^15.0.1 @@ -1112,6 +1113,7 @@ importers: mkdirp: 1.0.4 open: 8.4.2 ora: 5.4.1 + recheck: 4.4.5 rxjs: 6.6.7 traverse: 0.6.9 unique-string: 2.0.0 @@ -12530,6 +12532,46 @@ packages: picomatch: 2.3.1 dev: true + /recheck-jar/4.4.5: + resolution: {integrity: sha512-a2kMzcfr+ntT0bObNLY22EUNV6Z6WeZ+DybRmPOUXVWzGcqhRcrK74tpgrYt3FdzTlSh85pqoryAPmrNkwLc0g==} + requiresBuild: true + dev: false + optional: true + + /recheck-linux-x64/4.4.5: + resolution: {integrity: sha512-s8OVPCpiSGw+tLCxH3eei7Zp2AoL22kXqLmEtWXi0AnYNwfuTjZmeLn2aQjW8qhs8ZPSkxS7uRIRTeZqR5Fv/Q==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /recheck-macos-x64/4.4.5: + resolution: {integrity: sha512-Ouup9JwwoKCDclt3Na8+/W2pVbt8FRpzjkDuyM32qTR2TOid1NI+P1GA6/VQAKEOjvaxgGjxhcP/WqAjN+EULA==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /recheck-windows-x64/4.4.5: + resolution: {integrity: sha512-mkpzLHu9G9Ztjx8HssJh9k/Xm1d1d/4OoT7etHqFk+k1NGzISCRXBD22DqYF9w8+J4QEzTAoDf8icFt0IGhOEQ==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /recheck/4.4.5: + resolution: {integrity: sha512-J80Ykhr+xxWtvWrfZfPpOR/iw2ijvb4WY8d9AVoN8oHsPP07JT1rCAalUSACMGxM1cvSocb6jppWFjVS6eTTrA==} + engines: {node: '>=14'} + optionalDependencies: + recheck-jar: 4.4.5 + recheck-linux-x64: 4.4.5 + recheck-macos-x64: 4.4.5 + recheck-windows-x64: 4.4.5 + dev: false + /rechoir/0.6.2: resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==} engines: {node: '>= 0.10'} From ef2019c82219b582e8a2d06f532ca1a517888caa Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 21 May 2024 09:59:49 +0530 Subject: [PATCH 07/12] version bump and reverted changes for asset url --- package-lock.json | 162 ++++++++++-------- packages/contentstack-audit/README.md | 16 +- packages/contentstack-audit/package.json | 6 +- .../contentstack-audit/src/modules/entries.ts | 68 ++++---- packages/contentstack-auth/package.json | 2 +- packages/contentstack-bootstrap/README.md | 2 +- packages/contentstack-bootstrap/package.json | 6 +- packages/contentstack-branches/README.md | 2 +- packages/contentstack-branches/package.json | 4 +- packages/contentstack-bulk-publish/README.md | 2 +- .../contentstack-bulk-publish/package.json | 4 +- packages/contentstack-clone/README.md | 2 +- packages/contentstack-clone/package.json | 8 +- packages/contentstack-command/package.json | 2 +- packages/contentstack-config/package.json | 2 +- .../contentstack-export-to-csv/package.json | 2 +- packages/contentstack-export/README.md | 2 +- packages/contentstack-export/package.json | 4 +- packages/contentstack-import/README.md | 2 +- packages/contentstack-import/package.json | 6 +- .../src/utils/asset-helper.ts | 9 +- packages/contentstack-launch/package.json | 2 +- .../contentstack-migrate-rte/package.json | 2 +- packages/contentstack-migration/README.md | 2 +- packages/contentstack-migration/package.json | 4 +- packages/contentstack-seed/package.json | 6 +- packages/contentstack-utilities/package.json | 2 +- packages/contentstack/README.md | 16 +- packages/contentstack/package.json | 22 +-- pnpm-lock.yaml | 60 +++---- 30 files changed, 217 insertions(+), 212 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8765699e9a..e0f6c4d80a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4253,6 +4253,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "delegates": "^1.0.0", @@ -4554,9 +4555,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1623.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1623.0.tgz", - "integrity": "sha512-SFPc+QJqoghsE0nn6YSmrDDDPpWc3m4rcDQYg6W3GQek+f1v6kycxM5+N58pMZ2iWhRSOTf9NQRcZj0ZU3PklQ==", + "version": "2.1624.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1624.0.tgz", + "integrity": "sha512-SxBGDkdmsQTXLKPaY+hLqjlQyZBaGaFD34EhTd4aYuuqT952sxYeDt7w75py4o4O5z4hUUTccqTF9dtpxCPJfg==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4585,9 +4586,9 @@ } }, "node_modules/axios": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.0.tgz", - "integrity": "sha512-IiB0wQeKyPRdsFVhBgIo31FbzOyf2M6wYl7/NVutFwFBRMiAbjNiydJIHKeLmPugF4kJLfA1uWZ82Is2QzqqFA==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", + "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -6761,9 +6762,9 @@ } }, "node_modules/dompurify": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.1.3.tgz", - "integrity": "sha512-5sOWYSNPaxz6o2MUPvtyxTTqR4D3L77pr5rUQoWgD5ROQtVIZQgJkXbo1DLlK3vj11YGw5+LnF4SYti4gZmwng==" + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.1.4.tgz", + "integrity": "sha512-2gnshi6OshmuKil8rMZuQCGiUF3cUxHY3NGDzUAdUx/NPEe5DVnO8BDoAQouvgwnx0R/+a6jUn36Z0FSdq8vww==" }, "node_modules/domutils": { "version": "3.1.0", @@ -6857,9 +6858,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.774", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.774.tgz", - "integrity": "sha512-132O1XCd7zcTkzS3FgkAzKmnBuNJjK8WjcTtNuoylj7MYbqw5eXehjQ5OK91g0zm7OTKIPeaAG4CPoRfD9M1Mg==", + "version": "1.4.775", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.775.tgz", + "integrity": "sha512-JpOfl1aNAiZ88wFzjPczTLwYIoPIsij8S9/XQH9lqMpiJOf23kxea68B8wje4f68t4rOIq4Bh+vP4I65njiJBw==", "dev": true }, "node_modules/elegant-spinner": { @@ -8012,13 +8013,13 @@ } }, "node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/scope-manager": { - "version": "7.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.9.0.tgz", - "integrity": "sha512-ZwPK4DeCDxr3GJltRz5iZejPFAAr4Wk3+2WIBaj1L5PYK5RgxExu/Y68FFVclN0y6GGwH8q+KgKRCvaTmFBbgQ==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.10.0.tgz", + "integrity": "sha512-7L01/K8W/VGl7noe2mgH0K7BE29Sq6KAbVmxurj8GGaPDZXPr8EEQ2seOeAS+mEV9DnzxBQB6ax6qQQ5C6P4xg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.9.0", - "@typescript-eslint/visitor-keys": "7.9.0" + "@typescript-eslint/types": "7.10.0", + "@typescript-eslint/visitor-keys": "7.10.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -8029,9 +8030,9 @@ } }, "node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/types": { - "version": "7.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.9.0.tgz", - "integrity": "sha512-oZQD9HEWQanl9UfsbGVcZ2cGaR0YT5476xfWE0oE5kQa2sNK2frxOlkeacLOTh9po4AlUT5rtkGyYM5kew0z5w==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.10.0.tgz", + "integrity": "sha512-7fNj+Ya35aNyhuqrA1E/VayQX9Elwr8NKZ4WueClR3KwJ7Xx9jcCdOrLW04h51de/+gNbyFMs+IDxh5xIwfbNg==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -8042,13 +8043,13 @@ } }, "node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/typescript-estree": { - "version": "7.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.9.0.tgz", - "integrity": "sha512-zBCMCkrb2YjpKV3LA0ZJubtKCDxLttxfdGmwZvTqqWevUPN0FZvSI26FalGFFUZU/9YQK/A4xcQF9o/VVaCKAg==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.10.0.tgz", + "integrity": "sha512-LXFnQJjL9XIcxeVfqmNj60YhatpRLt6UhdlFwAkjNc6jSUlK8zQOl1oktAP8PlWFzPQC1jny/8Bai3/HPuvN5g==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.9.0", - "@typescript-eslint/visitor-keys": "7.9.0", + "@typescript-eslint/types": "7.10.0", + "@typescript-eslint/visitor-keys": "7.10.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -8070,15 +8071,15 @@ } }, "node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/utils": { - "version": "7.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.9.0.tgz", - "integrity": "sha512-5KVRQCzZajmT4Ep+NEgjXCvjuypVvYHUW7RHlXzNPuak2oWpVoD1jf5xCP0dPAuNIchjC7uQyvbdaSTFaLqSdA==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.10.0.tgz", + "integrity": "sha512-olzif1Fuo8R8m/qKkzJqT7qwy16CzPRWBvERS0uvyc+DHd8AKbO4Jb7kpAvVzMmZm8TrHnI7hvjN4I05zow+tg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.9.0", - "@typescript-eslint/types": "7.9.0", - "@typescript-eslint/typescript-estree": "7.9.0" + "@typescript-eslint/scope-manager": "7.10.0", + "@typescript-eslint/types": "7.10.0", + "@typescript-eslint/typescript-estree": "7.10.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -8092,12 +8093,12 @@ } }, "node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/visitor-keys": { - "version": "7.9.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.9.0.tgz", - "integrity": "sha512-iESPx2TNLDNGQLyjKhUvIKprlP49XNEK+MvIf9nIO7ZZaZdbnfWKHnXAgufpxqfA0YryH8XToi4+CjBgVnFTSQ==", + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.10.0.tgz", + "integrity": "sha512-9ntIVgsi6gg6FIq9xjEO4VQJvwOqA3jaBFQJ/6TK5AvEup2+cECI6Fh7QiBxmfMHXU0V0J4RyPeOU1VDNzl9cg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.9.0", + "@typescript-eslint/types": "7.10.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -9255,6 +9256,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "aproba": "^1.0.3 || ^2.0.0", @@ -14757,6 +14759,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz", "integrity": "sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "delegates": "^1.0.0", @@ -14770,6 +14773,7 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz", "integrity": "sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "aproba": "^1.0.3 || ^2.0.0", @@ -14795,6 +14799,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz", "integrity": "sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "are-we-there-yet": "^3.0.0", @@ -17863,6 +17868,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "are-we-there-yet": "^2.0.0", @@ -19719,6 +19725,7 @@ "version": "6.0.4", "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-6.0.4.tgz", "integrity": "sha512-AEtWXYfopBj2z5N5PbkAOeNHRPUg5q+Nen7QLxV8M2zJq1ym6/lCz3fYNTCXe19puu2d06jfHhrP7v/S2PtMMw==", + "deprecated": "This package is no longer supported. Please use @npmcli/package-json instead.", "dev": true, "dependencies": { "glob": "^10.2.2", @@ -23930,6 +23937,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz", "integrity": "sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "delegates": "^1.0.0", @@ -24046,6 +24054,7 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz", "integrity": "sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "aproba": "^1.0.3 || ^2.0.0", @@ -24511,6 +24520,7 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz", "integrity": "sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==", + "deprecated": "This package is no longer supported.", "dev": true, "dependencies": { "are-we-there-yet": "^3.0.0", @@ -24735,25 +24745,25 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.18.1", + "version": "1.18.2", "license": "MIT", "dependencies": { - "@contentstack/cli-audit": "~1.6.1", + "@contentstack/cli-audit": "~1.6.2", "@contentstack/cli-auth": "~1.3.18", - "@contentstack/cli-cm-bootstrap": "~1.9.2", - "@contentstack/cli-cm-branches": "~1.0.25", - "@contentstack/cli-cm-bulk-publish": "~1.4.6", - "@contentstack/cli-cm-clone": "~1.10.4", - "@contentstack/cli-cm-export": "~1.11.3", + "@contentstack/cli-cm-bootstrap": "~1.9.3", + "@contentstack/cli-cm-branches": "~1.0.26", + "@contentstack/cli-cm-bulk-publish": "~1.4.7", + "@contentstack/cli-cm-clone": "~1.10.5", + "@contentstack/cli-cm-export": "~1.11.4", "@contentstack/cli-cm-export-to-csv": "~1.7.1", - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-cm-migrate-rte": "~1.4.17", - "@contentstack/cli-cm-seed": "~1.7.4", + "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-config": "~1.6.4", "@contentstack/cli-launch": "~1.0.18", - "@contentstack/cli-migration": "~1.5.5", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-migration": "~1.5.6", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/management": "~1.15.3", "@oclif/core": "^3.26.5", "@oclif/plugin-help": "^5", @@ -24803,11 +24813,11 @@ }, "packages/contentstack-audit": { "name": "@contentstack/cli-audit", - "version": "1.6.1", + "version": "1.6.2", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^5.0.0", "chalk": "^4.1.2", @@ -25063,7 +25073,7 @@ "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", @@ -25100,12 +25110,12 @@ }, "packages/contentstack-bootstrap": { "name": "@contentstack/cli-cm-bootstrap", - "version": "1.9.2", + "version": "1.9.3", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-seed": "~1.7.4", + "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.2.1 " @@ -25179,11 +25189,11 @@ }, "packages/contentstack-branches": { "name": "@contentstack/cli-cm-branches", - "version": "1.0.25", + "version": "1.0.26", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^2.9.3", "async": "^3.2.4", "big-json": "^3.2.0", @@ -25285,11 +25295,11 @@ }, "packages/contentstack-bulk-publish": { "name": "@contentstack/cli-cm-bulk-publish", - "version": "1.4.6", + "version": "1.4.7", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "bluebird": "^3.7.2", "chalk": "^4.1.2", "dotenv": "^16.1.4", @@ -25322,14 +25332,14 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.10.4", + "version": "1.10.5", "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.11.3", - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-export": "~1.11.4", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", "chalk": "^4.1.0", "child_process": "^1.0.2", @@ -25435,7 +25445,7 @@ "version": "1.2.18", "license": "MIT", "dependencies": { - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "contentstack": "^3.10.1" }, "devDependencies": { @@ -25510,7 +25520,7 @@ "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", @@ -25888,11 +25898,11 @@ }, "packages/contentstack-export": { "name": "@contentstack/cli-cm-export", - "version": "1.11.3", + "version": "1.11.4", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^3.26.5", "async": "^3.2.4", "big-json": "^3.2.0", @@ -25942,7 +25952,7 @@ "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.1.0", "fast-csv": "^4.3.6", "inquirer": "8.2.4", @@ -26393,12 +26403,12 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.15.5", + "version": "1.15.6", "license": "MIT", "dependencies": { - "@contentstack/cli-audit": "~1.6.1", + "@contentstack/cli-audit": "~1.6.2", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/management": "~1.15.3", "@oclif/core": "^3.26.5", "big-json": "^3.2.0", @@ -26512,7 +26522,7 @@ "dependencies": { "@apollo/client": "^3.7.9", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^3.26.5", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^5.0.0", @@ -26807,7 +26817,7 @@ "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/json-rte-serializer": "~2.0.4", "chalk": "^4.1.2", "collapse-whitespace": "^1.1.7", @@ -26842,11 +26852,11 @@ }, "packages/contentstack-migration": { "name": "@contentstack/cli-migration", - "version": "1.5.5", + "version": "1.5.6", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", "callsites": "^3.1.0", "cardinal": "^2.1.1", @@ -26875,12 +26885,12 @@ }, "packages/contentstack-seed": { "name": "@contentstack/cli-cm-seed", - "version": "1.7.4", + "version": "1.7.5", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.1.13", @@ -26956,7 +26966,7 @@ }, "packages/contentstack-utilities": { "name": "@contentstack/cli-utilities", - "version": "1.6.1", + "version": "1.6.2", "license": "MIT", "dependencies": { "@contentstack/management": "~1.15.3", diff --git a/packages/contentstack-audit/README.md b/packages/contentstack-audit/README.md index f2f51c70d5..1932a32b69 100644 --- a/packages/contentstack-audit/README.md +++ b/packages/contentstack-audit/README.md @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli-audit/1.6.1 darwin-arm64 node-v21.6.2 +@contentstack/cli-audit/1.6.2 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND @@ -267,7 +267,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -341,7 +341,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -390,7 +390,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -420,7 +420,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -461,7 +461,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -489,7 +489,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -533,5 +533,5 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/update.ts)_ diff --git a/packages/contentstack-audit/package.json b/packages/contentstack-audit/package.json index 03b48fafbb..b25640e1da 100644 --- a/packages/contentstack-audit/package.json +++ b/packages/contentstack-audit/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-audit", - "version": "1.6.1", + "version": "1.6.2", "description": "Contentstack audit plugin", "author": "Contentstack CLI", "homepage": "https://github.com/contentstack/cli", @@ -19,7 +19,7 @@ ], "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^5.0.0", "chalk": "^4.1.2", @@ -76,7 +76,7 @@ "prepack": "npm run build && oclif manifest && oclif readme", "test": "mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif readme && git add README.md", - "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json", + "clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json", "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"" }, "engines": { diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index 0544f0d7e7..16ad893fe6 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -67,15 +67,15 @@ export default class Entries { this.fix = fix ?? false; this.ctSchema = ctSchema; this.gfSchema = gfSchema; - this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); + this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig.entries.dirName)); } - validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { - if(Object.keys(moduleConfig).includes(moduleName)){ + validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record): keyof typeof auditConfig.moduleConfig { + if (Object.keys(moduleConfig).includes(moduleName)) { return moduleName; - } + } return 'entries' } @@ -200,7 +200,7 @@ export default class Entries { async fixPrerequisiteData() { this.ctSchema = (await new ContentType({ fix: true, - log: () => {}, + log: () => { }, config: this.config, moduleName: 'content-types', ctSchema: this.ctSchema, @@ -208,7 +208,7 @@ export default class Entries { }).run(true)) as ContentTypeStruct[]; this.gfSchema = (await new GlobalField({ fix: true, - log: () => {}, + log: () => { }, config: this.config, moduleName: 'global-fields', ctSchema: this.ctSchema, @@ -221,7 +221,7 @@ export default class Entries { if (existsSync(extensionPath)) { try { this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8'))); - } catch (error) {} + } catch (error) { } } if (existsSync(marketplacePath)) { @@ -234,7 +234,7 @@ export default class Entries { ) as string[]; this.extensions.push(...metaData); } - } catch (error) {} + } catch (error) { } } } @@ -416,19 +416,19 @@ export default class Entries { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - ct_uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + ct_uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } @@ -588,19 +588,19 @@ export default class Entries { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } diff --git a/packages/contentstack-auth/package.json b/packages/contentstack-auth/package.json index c1c81875c5..0e329ab6fb 100644 --- a/packages/contentstack-auth/package.json +++ b/packages/contentstack-auth/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", diff --git a/packages/contentstack-bootstrap/README.md b/packages/contentstack-bootstrap/README.md index 8b8c47b5b1..056b54340e 100644 --- a/packages/contentstack-bootstrap/README.md +++ b/packages/contentstack-bootstrap/README.md @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bootstrap/1.9.2 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-bootstrap/1.9.3 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-bootstrap/package.json b/packages/contentstack-bootstrap/package.json index 6879e4a464..23aef0ed30 100644 --- a/packages/contentstack-bootstrap/package.json +++ b/packages/contentstack-bootstrap/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-bootstrap", "description": "Bootstrap contentstack apps", - "version": "1.9.2", + "version": "1.9.3", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "scripts": { @@ -17,9 +17,9 @@ "test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\"" }, "dependencies": { - "@contentstack/cli-cm-seed": "~1.7.4", + "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.2.1 " diff --git a/packages/contentstack-branches/README.md b/packages/contentstack-branches/README.md index 63fad9728c..66fd355950 100755 --- a/packages/contentstack-branches/README.md +++ b/packages/contentstack-branches/README.md @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-branches/1.0.25 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-branches/1.0.26 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-branches/package.json b/packages/contentstack-branches/package.json index 8ed1ab4d58..2de3b52cf1 100644 --- a/packages/contentstack-branches/package.json +++ b/packages/contentstack-branches/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-branches", "description": "Contentstack CLI plugin to do branches operations", - "version": "1.0.25", + "version": "1.0.26", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^2.9.3", "async": "^3.2.4", "big-json": "^3.2.0", diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 9cbf43b092..4535acb855 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bulk-publish/1.4.6 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-bulk-publish/1.4.7 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-bulk-publish/package.json b/packages/contentstack-bulk-publish/package.json index 8caa2cdc5f..8a09c9f1be 100644 --- a/packages/contentstack-bulk-publish/package.json +++ b/packages/contentstack-bulk-publish/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-bulk-publish", "description": "Contentstack CLI plugin for bulk publish actions", - "version": "1.4.6", + "version": "1.4.7", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "bluebird": "^3.7.2", "chalk": "^4.1.2", "dotenv": "^16.1.4", diff --git a/packages/contentstack-clone/README.md b/packages/contentstack-clone/README.md index 659c39f34e..1a9f7681df 100644 --- a/packages/contentstack-clone/README.md +++ b/packages/contentstack-clone/README.md @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-clone/1.10.4 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-clone/1.10.5 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 9bb97ca7ab..ed02269c3f 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,15 +1,15 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.10.4", + "version": "1.10.5", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.11.3", - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-export": "~1.11.4", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", "chalk": "^4.1.0", "child_process": "^1.0.2", diff --git a/packages/contentstack-command/package.json b/packages/contentstack-command/package.json index 416b56494f..e5bc4bc526 100644 --- a/packages/contentstack-command/package.json +++ b/packages/contentstack-command/package.json @@ -17,7 +17,7 @@ "format": "eslint src/**/*.ts --fix" }, "dependencies": { - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "contentstack": "^3.10.1" }, "devDependencies": { diff --git a/packages/contentstack-config/package.json b/packages/contentstack-config/package.json index d9446d5019..1220d1e8ac 100644 --- a/packages/contentstack-config/package.json +++ b/packages/contentstack-config/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.0.0", "debug": "^4.1.1", "inquirer": "8.2.4", diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index c278b295fa..0db9e82fb7 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "chalk": "^4.1.0", "fast-csv": "^4.3.6", "inquirer": "8.2.4", diff --git a/packages/contentstack-export/README.md b/packages/contentstack-export/README.md index a1c9704db1..3a44d34a01 100755 --- a/packages/contentstack-export/README.md +++ b/packages/contentstack-export/README.md @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-export/1.11.3 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-export/1.11.4 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 3b38c5b03e..b5531b2be7 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-export", "description": "Contentstack CLI plugin to export content from stack", - "version": "1.11.3", + "version": "1.11.4", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^3.26.5", "async": "^3.2.4", "big-json": "^3.2.0", diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index 6be14da3eb..515c62c35e 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.15.5 darwin-arm64 node-v21.6.2 +@contentstack/cli-cm-import/1.15.6 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 79736b60bd..b7204be466 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,13 +1,13 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.15.5", + "version": "1.15.6", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-audit": "~1.6.1", + "@contentstack/cli-audit": "~1.6.2", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/management": "~1.15.3", "@oclif/core": "^3.26.5", "big-json": "^3.2.0", diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index 40fab00ca1..7c28b3ed32 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -255,13 +255,8 @@ export const lookupAssets = function ( // const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&'); // const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&'); // entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl); - if (isValidURL(mappedAssetUrl)) { - let { status } = validateRegex(new RegExp(assetUrl, 'img')) - if (status === 'safe') { - entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); - matchedUrls.push(mappedAssetUrl); - } - } + entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl); + matchedUrls.push(mappedAssetUrl); } else { unmatchedUrls.push(assetUrl); } diff --git a/packages/contentstack-launch/package.json b/packages/contentstack-launch/package.json index 86bb7515b5..48cf5261a2 100755 --- a/packages/contentstack-launch/package.json +++ b/packages/contentstack-launch/package.json @@ -19,7 +19,7 @@ "dependencies": { "@apollo/client": "^3.7.9", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@oclif/core": "^3.26.5", "@oclif/plugin-help": "^5", "@oclif/plugin-plugins": "^5.0.0", diff --git a/packages/contentstack-migrate-rte/package.json b/packages/contentstack-migrate-rte/package.json index ec89c5665d..4dbe13a682 100644 --- a/packages/contentstack-migrate-rte/package.json +++ b/packages/contentstack-migrate-rte/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/json-rte-serializer": "~2.0.4", "collapse-whitespace": "^1.1.7", "chalk": "^4.1.2", diff --git a/packages/contentstack-migration/README.md b/packages/contentstack-migration/README.md index d84a0a1325..4178a77674 100644 --- a/packages/contentstack-migration/README.md +++ b/packages/contentstack-migration/README.md @@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-migration/1.5.5 darwin-arm64 node-v21.6.2 +@contentstack/cli-migration/1.5.6 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-migration/package.json b/packages/contentstack-migration/package.json index adf38e3bae..c3ad965971 100644 --- a/packages/contentstack-migration/package.json +++ b/packages/contentstack-migration/package.json @@ -1,11 +1,11 @@ { "name": "@contentstack/cli-migration", - "version": "1.5.5", + "version": "1.5.6", "author": "@contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "async": "^3.2.4", "callsites": "^3.1.0", "cardinal": "^2.1.1", diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index f23f387402..b7fc7bec8d 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -1,13 +1,13 @@ { "name": "@contentstack/cli-cm-seed", "description": "create a Stack from existing content types, entries, assets, etc.", - "version": "1.7.4", + "version": "1.7.5", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-command": "~1.2.18", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-utilities": "~1.6.2", "inquirer": "8.2.4", "mkdirp": "^1.0.4", "tar": "^6.1.13", diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index d9f1786ea7..687731af98 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-utilities", - "version": "1.6.1", + "version": "1.6.2", "description": "Utilities for contentstack projects", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index ea99d7b1d3..5708bb2fa4 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.18.1 darwin-arm64 node-v21.6.2 +@contentstack/cli/1.18.2 darwin-arm64 node-v21.6.2 $ csdx --help [COMMAND] USAGE $ csdx COMMAND @@ -3492,7 +3492,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -3566,7 +3566,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -3615,7 +3615,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -3645,7 +3645,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -3686,7 +3686,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -3714,7 +3714,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -3758,7 +3758,7 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/update.ts)_ ## `csdx tokens` diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 5d17343d5e..e0219c520e 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli", "description": "Command-line tool (CLI) to interact with Contentstack", - "version": "1.18.1", + "version": "1.18.2", "author": "Contentstack", "bin": { "csdx": "./bin/run.js" @@ -22,22 +22,22 @@ "prepack": "pnpm compile && oclif manifest && oclif readme" }, "dependencies": { - "@contentstack/cli-audit": "~1.6.1", + "@contentstack/cli-audit": "~1.6.2", "@contentstack/cli-auth": "~1.3.18", - "@contentstack/cli-cm-bootstrap": "~1.9.2", - "@contentstack/cli-cm-branches": "~1.0.25", - "@contentstack/cli-cm-bulk-publish": "~1.4.6", - "@contentstack/cli-cm-export": "~1.11.3", - "@contentstack/cli-cm-clone": "~1.10.4", + "@contentstack/cli-cm-bootstrap": "~1.9.3", + "@contentstack/cli-cm-branches": "~1.0.26", + "@contentstack/cli-cm-bulk-publish": "~1.4.7", + "@contentstack/cli-cm-export": "~1.11.4", + "@contentstack/cli-cm-clone": "~1.10.5", "@contentstack/cli-cm-export-to-csv": "~1.7.1", - "@contentstack/cli-cm-import": "~1.15.5", + "@contentstack/cli-cm-import": "~1.15.6", "@contentstack/cli-cm-migrate-rte": "~1.4.17", - "@contentstack/cli-cm-seed": "~1.7.4", + "@contentstack/cli-cm-seed": "~1.7.5", "@contentstack/cli-command": "~1.2.18", "@contentstack/cli-config": "~1.6.4", "@contentstack/cli-launch": "~1.0.18", - "@contentstack/cli-migration": "~1.5.5", - "@contentstack/cli-utilities": "~1.6.1", + "@contentstack/cli-migration": "~1.5.6", + "@contentstack/cli-utilities": "~1.6.2", "@contentstack/management": "~1.15.3", "@oclif/core": "^3.26.5", "@oclif/plugin-help": "^5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 968adb6085..5ccb0eef76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,22 +10,22 @@ importers: packages/contentstack: specifiers: - '@contentstack/cli-audit': ~1.6.1 + '@contentstack/cli-audit': ~1.6.2 '@contentstack/cli-auth': ~1.3.18 - '@contentstack/cli-cm-bootstrap': ~1.9.2 - '@contentstack/cli-cm-branches': ~1.0.25 - '@contentstack/cli-cm-bulk-publish': ~1.4.6 - '@contentstack/cli-cm-clone': ~1.10.4 - '@contentstack/cli-cm-export': ~1.11.3 + '@contentstack/cli-cm-bootstrap': ~1.9.3 + '@contentstack/cli-cm-branches': ~1.0.26 + '@contentstack/cli-cm-bulk-publish': ~1.4.7 + '@contentstack/cli-cm-clone': ~1.10.5 + '@contentstack/cli-cm-export': ~1.11.4 '@contentstack/cli-cm-export-to-csv': ~1.7.1 - '@contentstack/cli-cm-import': ~1.15.5 + '@contentstack/cli-cm-import': ~1.15.6 '@contentstack/cli-cm-migrate-rte': ~1.4.17 - '@contentstack/cli-cm-seed': ~1.7.4 + '@contentstack/cli-cm-seed': ~1.7.5 '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-config': ~1.6.4 '@contentstack/cli-launch': ~1.0.18 - '@contentstack/cli-migration': ~1.5.5 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-migration': ~1.5.6 + '@contentstack/cli-utilities': ~1.6.2 '@contentstack/management': ~1.15.3 '@oclif/core': ^3.26.5 '@oclif/plugin-help': ^5 @@ -123,7 +123,7 @@ importers: specifiers: '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-dev-dependencies': ^1.2.4 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/plugin-help': ^5 '@oclif/plugin-plugins': ^5.0.0 '@oclif/test': ^2.5.6 @@ -187,7 +187,7 @@ importers: packages/contentstack-auth: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@fancy-test/nock': ^0.1.1 '@oclif/plugin-help': ^5.1.19 '@oclif/test': ^2.5.6 @@ -249,9 +249,9 @@ importers: packages/contentstack-bootstrap: specifiers: - '@contentstack/cli-cm-seed': ~1.7.4 + '@contentstack/cli-cm-seed': ~1.7.5 '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 '@types/inquirer': ^9.0.3 '@types/mkdirp': ^1.0.1 @@ -304,7 +304,7 @@ importers: '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-config': ~1.6.4 '@contentstack/cli-dev-dependencies': ~1.2.4 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/core': ^2.9.3 '@oclif/plugin-help': ^5.1.19 '@oclif/test': ^2.5.6 @@ -380,7 +380,7 @@ importers: packages/contentstack-bulk-publish: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 bluebird: ^3.7.2 chai: ^4.2.0 @@ -423,10 +423,10 @@ importers: packages/contentstack-clone: specifiers: '@colors/colors': ^1.5.0 - '@contentstack/cli-cm-export': ~1.11.3 - '@contentstack/cli-cm-import': ~1.15.5 + '@contentstack/cli-cm-export': ~1.11.4 + '@contentstack/cli-cm-import': ~1.15.6 '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 async: ^3.2.4 chai: ^4.2.0 @@ -479,7 +479,7 @@ importers: packages/contentstack-command: specifiers: - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 '@types/chai': ^4.2.18 '@types/mkdirp': ^1.0.1 @@ -521,7 +521,7 @@ importers: packages/contentstack-config: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 '@types/chai': ^4.2.18 '@types/inquirer': ^9.0.3 @@ -610,7 +610,7 @@ importers: '@contentstack/cli-command': ~1.2.18 '@contentstack/cli-config': ~1.6.4 '@contentstack/cli-dev-dependencies': ~1.2.4 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/core': ^3.26.5 '@oclif/plugin-help': ^5.1.19 '@oclif/test': ^2.5.6 @@ -688,7 +688,7 @@ importers: packages/contentstack-export-to-csv: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 '@types/chai': ^4.3.6 '@types/mocha': ^10.0.1 @@ -730,9 +730,9 @@ importers: packages/contentstack-import: specifiers: - '@contentstack/cli-audit': ~1.6.1 + '@contentstack/cli-audit': ~1.6.2 '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@contentstack/management': ~1.15.3 '@oclif/core': ^3.26.5 '@oclif/test': ^2.5.6 @@ -821,7 +821,7 @@ importers: specifiers: '@apollo/client': ^3.7.9 '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/core': ^3.26.5 '@oclif/plugin-help': ^5 '@oclif/plugin-plugins': ^5.0.0 @@ -897,7 +897,7 @@ importers: packages/contentstack-migrate-rte: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@contentstack/json-rte-serializer': ~2.0.4 '@oclif/test': ^2.5.6 chai: ^4.3.4 @@ -944,7 +944,7 @@ importers: packages/contentstack-migration: specifiers: '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/test': ^2.5.6 async: ^3.2.4 callsites: ^3.1.0 @@ -990,9 +990,9 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.15.5 + '@contentstack/cli-cm-import': ~1.15.6 '@contentstack/cli-command': ~1.2.18 - '@contentstack/cli-utilities': ~1.6.1 + '@contentstack/cli-utilities': ~1.6.2 '@oclif/plugin-help': ^5.1.19 '@types/inquirer': ^9.0.3 '@types/jest': ^26.0.15 From def4ddf6455dfa18feed429df387262e6ab5b8e3 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 21 May 2024 10:33:05 +0530 Subject: [PATCH 08/12] removed unsed regex --- packages/contentstack-import/src/utils/asset-helper.ts | 2 +- packages/contentstack-utilities/src/helpers.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/contentstack-import/src/utils/asset-helper.ts b/packages/contentstack-import/src/utils/asset-helper.ts index 7c28b3ed32..924028243e 100644 --- a/packages/contentstack-import/src/utils/asset-helper.ts +++ b/packages/contentstack-import/src/utils/asset-helper.ts @@ -1,7 +1,7 @@ import Bluebird from 'bluebird'; import * as url from 'url'; import * as path from 'path'; -import { ContentstackClient, managementSDKClient, isValidURL, validateRegex } from '@contentstack/cli-utilities'; +import { ContentstackClient, managementSDKClient, validateRegex } from '@contentstack/cli-utilities'; import { ImportConfig } from '../types'; const debug = require('debug')('util:requests'); let _ = require('lodash'); diff --git a/packages/contentstack-utilities/src/helpers.ts b/packages/contentstack-utilities/src/helpers.ts index bda61760cd..4fe9289138 100644 --- a/packages/contentstack-utilities/src/helpers.ts +++ b/packages/contentstack-utilities/src/helpers.ts @@ -65,6 +65,4 @@ export const validateUids = (uid) => /^[a-zA-Z0-9]+$/.test(uid); export const validateFileName = (fileName) => /^[a-zA-Z0-9-_\.]+$/.test(fileName); // Validate Regex for ReDDos -export const validateRegex = (str) => checkSync(str, ""); - -export const isValidURL = url => /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})([\/\w .-]*)*\/?$/.test(url); \ No newline at end of file +export const validateRegex = (str) => checkSync(str, ""); \ No newline at end of file From 9a4b09adf3856e90b64111345c7f8ad6a9622163 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 21 May 2024 17:10:07 +0530 Subject: [PATCH 09/12] PR fixes and formating --- package-lock.json | 54 +++++++++------ packages/contentstack-audit/package.json | 2 +- .../src/audit-base-command.ts | 14 ++-- .../contentstack-audit/src/messages/index.ts | 2 - .../src/modules/content-types.ts | 68 +++++++++---------- .../src/modules/extensions.ts | 8 +-- .../src/modules/workflows.ts | 8 +-- 7 files changed, 85 insertions(+), 71 deletions(-) diff --git a/package-lock.json b/package-lock.json index e0f6c4d80a..730d80a59d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4939,11 +4939,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -6858,9 +6858,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.775", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.775.tgz", - "integrity": "sha512-JpOfl1aNAiZ88wFzjPczTLwYIoPIsij8S9/XQH9lqMpiJOf23kxea68B8wje4f68t4rOIq4Bh+vP4I65njiJBw==", + "version": "1.4.776", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.776.tgz", + "integrity": "sha512-s694bi3+gUzlliqxjPHpa9NRTlhzTgB34aan+pVKZmOTGy2xoZXl+8E1B8i5p5rtev3PKMK/H4asgNejC+YHNg==", "dev": true }, "node_modules/elegant-spinner": { @@ -8836,9 +8836,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -14046,17 +14046,28 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.6.tgz", + "integrity": "sha512-Y4Ypn3oujJYxJcMacVgcs92wofTHxp9FzfDpQON4msDefoC0lb3ETvQLOdLcbhSwU1bz8HrL/1sygfBIHudrkQ==", "dependencies": { - "braces": "^3.0.2", - "picomatch": "^2.3.1" + "braces": "^3.0.3", + "picomatch": "^4.0.2" }, "engines": { "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", @@ -19026,6 +19037,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, "engines": { "node": ">=8.6" }, @@ -22148,9 +22160,9 @@ } }, "node_modules/ts-jest": { - "version": "29.1.2", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.2.tgz", - "integrity": "sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==", + "version": "29.1.3", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.3.tgz", + "integrity": "sha512-6L9qz3ginTd1NKhOxmkP0qU3FyKjj5CPoY+anszfVn6Pmv/RIKzhiMCsH7Yb7UvJR9I2A64rm4zQl531s2F1iw==", "dev": true, "dependencies": { "bs-logger": "0.x", @@ -22166,10 +22178,11 @@ "ts-jest": "cli.js" }, "engines": { - "node": "^16.10.0 || ^18.0.0 || >=20.0.0" + "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0" }, "peerDependencies": { "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/transform": "^29.0.0", "@jest/types": "^29.0.0", "babel-jest": "^29.0.0", "jest": "^29.0.0", @@ -22179,6 +22192,9 @@ "@babel/core": { "optional": true }, + "@jest/transform": { + "optional": true + }, "@jest/types": { "optional": true }, diff --git a/packages/contentstack-audit/package.json b/packages/contentstack-audit/package.json index b25640e1da..c762cead2c 100644 --- a/packages/contentstack-audit/package.json +++ b/packages/contentstack-audit/package.json @@ -76,7 +76,7 @@ "prepack": "npm run build && oclif manifest && oclif readme", "test": "mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif readme && git add README.md", - "clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json", + "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinf o oclif.manifest.json", "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"" }, "engines": { diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 3951be0e17..f7f87fd7d6 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -416,7 +416,7 @@ export abstract class AuditBaseCommand extends BaseCommand, ): Promise { - if(Object.keys(config.moduleConfig).includes(moduleName)){ + if (Object.keys(config.moduleConfig).includes(moduleName)) { const csvPath = join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.csv`); return new Promise((resolve, reject) => { // file deepcode ignore MissingClose: Will auto close once csv stream end @@ -428,7 +428,7 @@ export abstract class AuditBaseCommand extends BaseCommand !userDefinedColumns.includes(val))] : defaultColumns; - + if (this.sharedConfig.flags.filter) { const [column, value]: [keyof typeof OutputColumn, string] = this.sharedConfig.flags.filter.split('='); // Filter the missingRefs array @@ -440,11 +440,11 @@ export abstract class AuditBaseCommand extends BaseCommand[] = []; for (const issue of missingRefs) { let row: Record = {}; - + for (const column of columns) { if (Object.keys(issue).includes(OutputColumn[column])) { const issueKey = OutputColumn[column] as keyof typeof issue; @@ -452,17 +452,17 @@ export abstract class AuditBaseCommand extends BaseCommand((reject)=>{ + return new Promise((reject) => { return reject() }) } diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index cba0ae2cc2..ea3ffb15b2 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -82,8 +82,6 @@ function $t(msg: string, args: Record): string { if (status === 'safe') { const sanitizedValue = args[key] ? escapeRegExp(args[key]) : ''; msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey); - } else { - } } diff --git a/packages/contentstack-audit/src/modules/content-types.ts b/packages/contentstack-audit/src/modules/content-types.ts index 069ac06920..4875aa801c 100644 --- a/packages/contentstack-audit/src/modules/content-types.ts +++ b/packages/contentstack-audit/src/modules/content-types.ts @@ -51,15 +51,15 @@ export default class ContentType { this.fix = fix ?? false; this.ctSchema = ctSchema; this.gfSchema = gfSchema; - this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); + this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); } - validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { - if(Object.keys(moduleConfig).includes(moduleName)){ + validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record): keyof typeof auditConfig.moduleConfig { + if (Object.keys(moduleConfig).includes(moduleName)) { return moduleName; - } + } return 'content-types' } /** @@ -121,7 +121,7 @@ export default class ContentType { if (existsSync(extensionPath)) { try { this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8'))); - } catch (error) {} + } catch (error) { } } if (existsSync(marketplacePath)) { @@ -134,7 +134,7 @@ export default class ContentType { ) as string[]; this.extensions.push(...metaData); } - } catch (error) {} + } catch (error) { } } } @@ -189,8 +189,8 @@ export default class ContentType { ...this.validateReferenceField( [...tree, { uid: field.uid, name: child.display_name }], child as ReferenceFieldDataType, - ), - ); + ), + ); break; case 'global_field': await this.validateGlobalField( @@ -270,19 +270,19 @@ export default class ContentType { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - ct_uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + ct_uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } @@ -398,19 +398,19 @@ export default class ContentType { return missingRefs.length ? [ - { - tree, - data_type, - missingRefs, - display_name, - ct_uid: this.currentUid, - name: this.currentTitle, - treeStr: tree - .map(({ name }) => name) - .filter((val) => val) - .join(' ➜ '), - }, - ] + { + tree, + data_type, + missingRefs, + display_name, + ct_uid: this.currentUid, + name: this.currentTitle, + treeStr: tree + .map(({ name }) => name) + .filter((val) => val) + .join(' ➜ '), + }, + ] : []; } diff --git a/packages/contentstack-audit/src/modules/extensions.ts b/packages/contentstack-audit/src/modules/extensions.ts index cbf5139fc7..d48dd4f5a5 100644 --- a/packages/contentstack-audit/src/modules/extensions.ts +++ b/packages/contentstack-audit/src/modules/extensions.ts @@ -34,7 +34,7 @@ export default class Extensions { this.fix = fix ?? false; this.ctSchema = ctSchema; this.extensionsSchema = []; - this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); + this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); @@ -42,10 +42,10 @@ export default class Extensions { this.missingCts = new Set(); this.extensionsPath = ''; } - validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { - if(Object.keys(moduleConfig).includes(moduleName)){ + validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record): keyof typeof auditConfig.moduleConfig { + if (Object.keys(moduleConfig).includes(moduleName)) { return moduleName; - } + } return 'extensions' } diff --git a/packages/contentstack-audit/src/modules/workflows.ts b/packages/contentstack-audit/src/modules/workflows.ts index d386feabba..b016ded7d6 100644 --- a/packages/contentstack-audit/src/modules/workflows.ts +++ b/packages/contentstack-audit/src/modules/workflows.ts @@ -35,7 +35,7 @@ export default class Workflows { this.fix = fix ?? false; this.ctSchema = ctSchema; this.workflowSchema = []; - this.moduleName = this.validateModules(moduleName!,this.config.moduleConfig); + this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig); this.fileName = config.moduleConfig[this.moduleName].fileName; this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName)); this.ctUidSet = new Set(['$all']); @@ -44,10 +44,10 @@ export default class Workflows { this.workflowPath = ''; this.isBranchFixDone = false; } - validateModules(moduleName:keyof typeof auditConfig.moduleConfig, moduleConfig: Record):keyof typeof auditConfig.moduleConfig { - if(Object.keys(moduleConfig).includes(moduleName)){ + validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record): keyof typeof auditConfig.moduleConfig { + if (Object.keys(moduleConfig).includes(moduleName)) { return moduleName; - } + } return 'workflows' } From 6757f5ec0306443b34ef3c036ee005fb59b8ea59 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 21 May 2024 17:57:40 +0530 Subject: [PATCH 10/12] adding sanitize path in callsite --- packages/contentstack-migration/src/utils/callsite.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-migration/src/utils/callsite.js b/packages/contentstack-migration/src/utils/callsite.js index f4d0d82d09..2fc036841a 100644 --- a/packages/contentstack-migration/src/utils/callsite.js +++ b/packages/contentstack-migration/src/utils/callsite.js @@ -2,10 +2,10 @@ const getCallsites = require('callsites'); const { parse, resolve } = require('path'); -const { pathValidator } = require('@contentstack/cli-utilities'); +const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities'); function getFileDirectory(path) { - const parentPath = pathValidator(resolve(path, '../')); // Assuming that will be 2 folders up + const parentPath = pathValidator(resolve(sanitizePath(path), '../')); // Assuming that will be 2 folders up return parse(parentPath).dir; } From a0ce69792a88e9e53f885330d3094782990bf095 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 21 May 2024 18:25:29 +0530 Subject: [PATCH 11/12] typo error --- packages/contentstack-audit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-audit/package.json b/packages/contentstack-audit/package.json index c762cead2c..05aca4ed19 100644 --- a/packages/contentstack-audit/package.json +++ b/packages/contentstack-audit/package.json @@ -76,7 +76,7 @@ "prepack": "npm run build && oclif manifest && oclif readme", "test": "mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif readme && git add README.md", - "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinf o oclif.manifest.json", + "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json", "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"" }, "engines": { From d068161f9096e9f5940285a84062fc1cd55f5d71 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 23 May 2024 15:47:11 +0530 Subject: [PATCH 12/12] fixed the generating tree structure for the assets during branches merge --- package-lock.json | 110 ++++++++---------- .../src/utils/asset-folder-create-script.ts | 2 +- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/package-lock.json b/package-lock.json index 730d80a59d..40a577931f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2707,13 +2707,13 @@ } }, "node_modules/@sigstore/sign/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -3233,9 +3233,9 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.5", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.5.tgz", - "integrity": "sha512-WXCyOcRtH37HAUkpXhUduaxdm82b4GSlyTqajXviN4EfiuPgNYR109xMCKvpl6zPIpua0DGlMEDCq+g8EdoheQ==", + "version": "7.20.6", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", + "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", "dev": true, "dependencies": { "@babel/types": "^7.20.7" @@ -3325,9 +3325,9 @@ } }, "node_modules/@types/express-serve-static-core": { - "version": "4.19.0", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.0.tgz", - "integrity": "sha512-bGyep3JqPCRry1wq+O5n7oiBgGWmeIJXPjXXCo8EK0u8duZGSYar7cGqd3ML2JUsLGeB7fmc06KYo9fLGWqPvQ==", + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.1.tgz", + "integrity": "sha512-ej0phymbFLoCB26dbbq5PGScsf2JAJ4IJHjG10LalgUV36XKTmA4GdA+PVllKvRk0sEKt64X8975qFnkSi0hqA==", "dependencies": { "@types/node": "*", "@types/qs": "*", @@ -4555,9 +4555,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1624.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1624.0.tgz", - "integrity": "sha512-SxBGDkdmsQTXLKPaY+hLqjlQyZBaGaFD34EhTd4aYuuqT952sxYeDt7w75py4o4O5z4hUUTccqTF9dtpxCPJfg==", + "version": "2.1625.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1625.0.tgz", + "integrity": "sha512-Q96jKdo9PtBYPNOXoGTYvOt78TSRouLOeeFpcVfsN38O0Lc3LmuIMz3GHMofdLZGKRSa22RnpiDTCnpp6Xx1jw==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4586,9 +4586,9 @@ } }, "node_modules/axios": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", - "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -5300,9 +5300,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001620", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz", - "integrity": "sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew==", + "version": "1.0.30001621", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001621.tgz", + "integrity": "sha512-+NLXZiviFFKX0fk8Piwv3PfLPGtRqJeq2TiNoUff/qB5KJgwecJTvCXDpmlyP/eCI/GUEmp/h/y5j0yckiiZrA==", "dev": true, "funding": [ { @@ -6858,9 +6858,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.776", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.776.tgz", - "integrity": "sha512-s694bi3+gUzlliqxjPHpa9NRTlhzTgB34aan+pVKZmOTGy2xoZXl+8E1B8i5p5rtev3PKMK/H4asgNejC+YHNg==", + "version": "1.4.777", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.777.tgz", + "integrity": "sha512-n02NCwLJ3wexLfK/yQeqfywCblZqLcXphzmid5e8yVPdtEcida7li0A5WQKghHNG0FeOMCzeFOzEbtAh5riXFw==", "dev": true }, "node_modules/elegant-spinner": { @@ -11669,9 +11669,9 @@ } }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.1.2.tgz", + "integrity": "sha512-kWmLKn2tRtfYMF/BakihVVRzBKOxz4gJMiL2Rj91WnAB5TPZumSH99R/Yf1qE1u4uRimvCSJfm6hnxohXeEXjQ==", "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -14046,28 +14046,17 @@ } }, "node_modules/micromatch": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.6.tgz", - "integrity": "sha512-Y4Ypn3oujJYxJcMacVgcs92wofTHxp9FzfDpQON4msDefoC0lb3ETvQLOdLcbhSwU1bz8HrL/1sygfBIHudrkQ==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dependencies": { "braces": "^3.0.3", - "picomatch": "^4.0.2" + "picomatch": "^2.3.1" }, "engines": { "node": ">=8.6" } }, - "node_modules/micromatch/node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, "node_modules/mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", @@ -19037,7 +19026,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, @@ -19779,13 +19767,13 @@ } }, "node_modules/read-package-json/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -20969,13 +20957,13 @@ } }, "node_modules/sigstore/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -22428,13 +22416,13 @@ } }, "node_modules/tuf-js/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -23987,13 +23975,13 @@ } }, "node_modules/yeoman-generator/node_modules/cacache/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" @@ -25400,12 +25388,12 @@ } }, "packages/contentstack-clone/node_modules/glob": { - "version": "10.3.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", - "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "version": "10.3.16", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.16.tgz", + "integrity": "sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==", "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", + "jackspeak": "^3.1.2", "minimatch": "^9.0.1", "minipass": "^7.0.4", "path-scurry": "^1.11.0" diff --git a/packages/contentstack-branches/src/utils/asset-folder-create-script.ts b/packages/contentstack-branches/src/utils/asset-folder-create-script.ts index a0c97bfd1c..a358c9e286 100644 --- a/packages/contentstack-branches/src/utils/asset-folder-create-script.ts +++ b/packages/contentstack-branches/src/utils/asset-folder-create-script.ts @@ -66,7 +66,7 @@ export function assetFolderCreateScript(contentType) { if (branch === element.parent_uid) { let childUid = element.uid; tree[branch][childUid] = {}; - return findBranches(tree[branch], [childUid], coll); + findBranches(tree[branch], [childUid], coll); } } });