diff --git a/.github/workflows/secrets-scan.yml b/.github/workflows/secrets-scan.yml deleted file mode 100644 index c0d8140ce5..0000000000 --- a/.github/workflows/secrets-scan.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Secrets Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security-secrets: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install Expect, jq and Python - run: sudo apt-get update --fix-missing && sudo apt-get install -y expect jq python3 python3-pip wkhtmltopdf - - - name: Install Python packages - run: pip install pandas json2html tabulate - - - name: Install Talisman - run: | - curl --silent https://raw.githubusercontent.com/thoughtworks/talisman/v1.32.0/install.sh > install.bash - chmod +x install.bash - ./install.bash - - - name: Run Talisman - id: run_talisman - run: /usr/local/bin/talisman --scan - continue-on-error: true - - - name: Convert JSON to HTML - run: | - python3 -c " - import json - import os - from json2html import * - with open('talisman_report/talisman_reports/data/report.json') as f: - data = json.load(f) - html = json2html.convert(json = data) - os.makedirs('talisman_html_report', exist_ok=True) - with open('talisman_html_report/report.html', 'w') as f: - f.write(html) - " && wkhtmltopdf talisman_html_report/report.html talisman_report.pdf - - - name: Upload Report - id: upload_report - uses: actions/upload-artifact@v4 - with: - name: talisman-report-pdf - path: talisman_report.pdf - - - name: Check the status of talisman scan - run: | - # if [[ ${{ steps.run_talisman.outcome }} == "success" ]]; then exit 0; else echo "Download the Talisman scan report from Artifact: ${{ steps.upload_report.outputs.artifact-url }}" && exit 1; fi - echo "Download the Talisman scan report from Artifact: ${{ steps.upload_report.outputs.artifact-url }}"; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4d78ce0192..206872ba15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4383,9 +4383,10 @@ } }, "node_modules/axios": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", - "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -24439,7 +24440,7 @@ "@contentstack/cli-config": "~1.6.5", "@contentstack/cli-launch": "~1.1.0", "@contentstack/cli-migration": "~1.6.1", - "@contentstack/cli-utilities": "~1.7.1", + "@contentstack/cli-utilities": "~1.7.2", "@contentstack/management": "~1.17.0", "@oclif/core": "^3.26.5", "@oclif/plugin-help": "^5", @@ -26612,7 +26613,7 @@ "@types/node": "^14.14.32", "@types/tar": "^6.1.3", "@types/tmp": "^0.2.0", - "axios": "^1.6.4", + "axios": "^1.7.4", "eslint": "^8.18.0", "eslint-config-oclif": "^4.0.0", "eslint-config-oclif-typescript": "^3.0.8", @@ -26673,13 +26674,13 @@ }, "packages/contentstack-utilities": { "name": "@contentstack/cli-utilities", - "version": "1.7.1", + "version": "1.7.2", "license": "MIT", "dependencies": { - "@contentstack/management": "~1.17.0", + "@contentstack/management": "file:../../contentstack-management-1.18.0.tgz", "@contentstack/marketplace-sdk": "^1.2.1", "@oclif/core": "^3.26.5", - "axios": "^1.6.4", + "axios": "^1.7.4", "chalk": "^4.0.0", "cli-cursor": "^3.1.0", "cli-table": "^0.3.11", @@ -26729,6 +26730,20 @@ "typescript": "^4.9.3" } }, + "packages/contentstack-utilities/node_modules/@contentstack/management": { + "version": "1.18.0", + "resolved": "file:contentstack-management-1.18.0.tgz", + "integrity": "sha512-46Y69W9rb3PQMDg6Tr96G1+GgW/Q1Gn5ZDXauVFFqKHlsPTOoBiOazRLUvb+T+71xNQfUMUKT2Fye1MdSfSgfA==", + "dependencies": { + "axios": "^1.6.8", + "form-data": "^4.0.0", + "lodash": "^4.17.21", + "qs": "^6.12.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, "packages/contentstack-utilities/node_modules/fancy-test": { "version": "2.0.42", "resolved": "https://registry.npmjs.org/fancy-test/-/fancy-test-2.0.42.tgz", diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 7780bea08b..adafc8060f 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -37,13 +37,13 @@ USAGE * [`csdx cm:bulk-publish:clear`](#csdx-cmbulk-publishclear) * [`csdx cm:bulk-publish:configure`](#csdx-cmbulk-publishconfigure) * [`csdx cm:bulk-publish:cross-publish [-a ] [--retry-failed ] [--bulk-publish ] [--content-type ] [--locales ] [--source-env ] [--environments ] [--delivery-token ] [-c ] [-y] [--branch ] [--onlyAssets] [--onlyEntries]`](#csdx-cmbulk-publishcross-publish--a-value---retry-failed-value---bulk-publish-value---content-type-value---locales-value---source-env-value---environments-value---delivery-token-value--c-value--y---branch-value---onlyassets---onlyentries) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value) +* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants) * [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) * [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value) * [`csdx cm:bulk-publish:revert`](#csdx-cmbulk-publishrevert) * [`csdx csdx cm:stacks:unpublish [-a ] [-e ] [-c ] [-y] [--locale ] [--branch ] [--retry-failed ] [--bulk-unpublish ] [--content-type ] [--delivery-token ] [--only-assets] [--only-entries]`](#csdx-csdx-cmstacksunpublish--a-value--e-value--c-value--y---locale-value---branch-value---retry-failed-value---bulk-unpublish-value---content-type-value---delivery-token-value---only-assets---only-entries) * [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value) -* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value-1) +* [`csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]`](#csdx-cmentriespublish--a-value---retry-failed-value---bulk-publish-value---publish-all-content-types---content-types-value---locales-value--e-value--c-value--y---branch-value---delivery-token-value---source-env-value---entry-uid-value---include-variants-1) * [`csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-modified--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value-1) * [`csdx cm:entries:publish-non-localized-fields [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-non-localized-fields--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value--e-value--c-value--y---branch-value-1) * [`csdx cm:entries:publish-only-unpublished [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]`](#csdx-cmentriespublish-only-unpublished--a-value---retry-failed-value---bulk-publish-value---source-env-value---content-types-value---locales-value--e-value--c-value--y---branch-value-1) @@ -499,7 +499,7 @@ EXAMPLES _See code: [src/commands/cm/bulk-publish/cross-publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/bulk-publish/cross-publish.js)_ -## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]` +## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]` Publish entries from multiple contenttypes to multiple environments and locales @@ -507,7 +507,7 @@ Publish entries from multiple contenttypes to multiple environments and locales USAGE $ csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch - ] [--delivery-token ] [--source-env ] + ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants] FLAGS -B, --branch= [default: main] Specify the branch to fetch the content (by default the main branch is @@ -524,6 +524,8 @@ FLAGS bulkpublish API will be used to publish the entries --content-types=... The Contenttypes from which entries need to be published --delivery-token= Delivery token for source environment + --entry-uid= Entry Uid for publish all associated variant entries. + --include-variants Include Variants flag will publish all associated variant entries. --publish-all-content-types (optional) Publish all contenttypes (cannot be set when contentTypes flag is set) --retry-failed= (optional) Retry failed entries from the logfile (overrides all other flags) This flag is used to retry publishing entries that failed to publish in a previous attempt. A log @@ -582,6 +584,18 @@ EXAMPLES Using --stack-api-key $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] + + + + Using --include-variants + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants] + + + + Using --entry-uid and --include-variants + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants] ``` ## `csdx cm:entries:publish-modified [-a ] [--retry-failed ] [--bulk-publish ] [--source-env ] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ]` @@ -931,7 +945,7 @@ EXAMPLES $ csdx cm:entries:publish-only-unpublished -b --content-types [CONTENT TYPES] -e [ENVIRONMENTS] --locales LOCALE -a [MANAGEMENT TOKEN ALIAS] --stack-api-key [STACK API KEY] -source-env [SOURCE ENV] ``` -## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]` +## `csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]` Publish entries from multiple contenttypes to multiple environments and locales @@ -939,7 +953,7 @@ Publish entries from multiple contenttypes to multiple environments and locales USAGE $ csdx cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch - ] [--delivery-token ] [--source-env ] + ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants] FLAGS -B, --branch= [default: main] Specify the branch to fetch the content (by default the main branch is @@ -956,6 +970,8 @@ FLAGS bulkpublish API will be used to publish the entries --content-types=... The Contenttypes from which entries need to be published --delivery-token= Delivery token for source environment + --entry-uid= Entry Uid for publish all associated variant entries. + --include-variants Include Variants flag will publish all associated variant entries. --publish-all-content-types (optional) Publish all contenttypes (cannot be set when contentTypes flag is set) --retry-failed= (optional) Retry failed entries from the logfile (overrides all other flags) This flag is used to retry publishing entries that failed to publish in a previous attempt. A log @@ -1014,6 +1030,18 @@ EXAMPLES Using --stack-api-key $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] + + + + Using --include-variants + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants] + + + + Using --entry-uid and --include-variants + + $ csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants] ``` _See code: [src/commands/cm/entries/publish.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js)_ diff --git a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js index 8b50c8b1ee..21a19a5b34 100644 --- a/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js +++ b/packages/contentstack-bulk-publish/src/commands/cm/entries/publish.js @@ -21,6 +21,8 @@ class PublishEntriesCommand extends Command { entriesFlags.publishAllContentTypes = entriesFlags['publish-all-content-types'] || entriesFlags.publishAllContentTypes || false; entriesFlags.apiVersion = entriesFlags['api-version'] || '3'; + entriesFlags.includeVariants = entriesFlags['include-variants'] || entriesFlags.includeVariants || false; + entriesFlags.entryUid = entriesFlags['entry-uid'] || entriesFlags.entryUid; delete entriesFlags['api-version']; delete entriesFlags['retry-failed']; delete entriesFlags['content-types']; @@ -57,6 +59,8 @@ class PublishEntriesCommand extends Command { } else { this.error('Please use `--alias` or `--stack-api-key` to proceed.', { exit: 2 }); } + updatedFlags.includeVariantsFlag = entriesFlags.includeVariants; + updatedFlags.entry_uid = entriesFlags.entryUid; updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'; stack = await getStack(config); } @@ -244,6 +248,11 @@ PublishEntriesCommand.flags = { }), 'delivery-token': flags.string({ description: 'Delivery token for source environment' }), 'source-env': flags.string({ description: 'Source environment' }), + 'entry-uid': flags.string({ description: 'Entry Uid for publish all associated variant entries.' }), + 'include-variants': flags.boolean({ + default: false, // set the default value to false + description: 'Include Variants flag will publish all associated variant entries.' + }), }; PublishEntriesCommand.examples = [ @@ -267,11 +276,17 @@ PublishEntriesCommand.examples = [ '', 'Using --stack-api-key', 'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]', + '', + 'Using --include-variants', + 'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] [--include-variants]', + '', + 'Using --entry-uid and --include-variants', + 'csdx cm:entries:publish -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] --stack-api-key [STACK API KEY] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN] --entry-uid [ENTRY UID] [--include-variants]', ]; PublishEntriesCommand.aliases = ['cm:bulk-publish:entries']; PublishEntriesCommand.usage = - 'cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ]'; + 'cm:entries:publish [-a ] [--retry-failed ] [--bulk-publish ] [--publish-all-content-types] [--content-types ] [--locales ] [-e ] [-c ] [-y] [--branch ] [--delivery-token ] [--source-env ] [--entry-uid ] [--include-variants]'; module.exports = PublishEntriesCommand; diff --git a/packages/contentstack-bulk-publish/src/producer/publish-entries.js b/packages/contentstack-bulk-publish/src/producer/publish-entries.js index 126260ce73..de96b43b76 100644 --- a/packages/contentstack-bulk-publish/src/producer/publish-entries.js +++ b/packages/contentstack-bulk-publish/src/producer/publish-entries.js @@ -8,6 +8,7 @@ const { performBulkPublish, publishEntry, initializeLogger } = require('../consu const retryFailedLogs = require('../util/retryfailed'); const { validateFile } = require('../util/fs'); const { isEmpty } = require('../util'); +const VARIANTS_PUBLISH_API_VERSION = '3.2'; const queue = getQueue(); @@ -18,7 +19,7 @@ let allContentTypes = []; let bulkPublishSet = []; let filePath; -async function getEntries(stack, contentType, locale, bulkPublish, environments, apiVersion, skip = 0) { +async function getEntries(stack, contentType, locale, bulkPublish, environments, apiVersion, variantsFlag = false, entry_uid = undefined, skip = 0) { return new Promise((resolve, reject) => { skipCount = skip; @@ -29,6 +30,13 @@ async function getEntries(stack, contentType, locale, bulkPublish, environments, include_publish_details: true, }; + if (variantsFlag) { + queryParams.apiVersion = VARIANTS_PUBLISH_API_VERSION; + } + if (entry_uid) { + queryParams.uid = entry_uid; + } + stack .contentType(contentType) .entry() @@ -37,16 +45,32 @@ async function getEntries(stack, contentType, locale, bulkPublish, environments, .then(async (entriesResponse) => { skipCount += entriesResponse.items.length; let entries = entriesResponse.items; - for (let index = 0; index < entriesResponse.items.length; index++) { + + for (let index = 0; index < entries.length; index++) { + let variants = []; + + + if (bulkPublish) { + let entry; if (bulkPublishSet.length < 10) { - bulkPublishSet.push({ + entry = { uid: entries[index].uid, content_type: contentType, locale, publish_details: entries[index].publish_details || [], - }); + }; + + if (variantsFlag) { + variants = await getVariantEntries(stack, contentType, entries, index, queryParams); + if(variants.length > 0){ + entry.publish_with_base_entry = true; + entry.variants = variants; + } + + } } + bulkPublishSet.push(entry); if (bulkPublishSet.length === 10) { await queue.Enqueue({ @@ -55,13 +79,13 @@ async function getEntries(stack, contentType, locale, bulkPublish, environments, Type: 'entry', environments: environments, stack: stack, - apiVersion + apiVersion, }); bulkPublishSet = []; } if ( - index === entriesResponse.items.length - 1 && + index === entries.length - 1 && bulkPublishSet.length <= 10 && bulkPublishSet.length > 0 ) { @@ -71,10 +95,10 @@ async function getEntries(stack, contentType, locale, bulkPublish, environments, Type: 'entry', environments: environments, stack: stack, - apiVersion + apiVersion, }); bulkPublishSet = []; - } // bulkPublish + } } else { await queue.Enqueue({ content_type: contentType, @@ -92,13 +116,52 @@ async function getEntries(stack, contentType, locale, bulkPublish, environments, bulkPublishSet = []; return resolve(); } - await getEntries(stack, contentType, locale, bulkPublish, environments, apiVersion, skipCount); + await getEntries(stack, contentType, locale, bulkPublish, environments, apiVersion, variantsFlag, skipCount); return resolve(); }) .catch((error) => reject(error)); }); } +async function getVariantEntries(stack, contentType, entries, index, queryParams, skip = 0) { + try { + let variantQueryParams = { + locale: queryParams.locale || 'en-us', + include_count: true, + skip: skip, // Adding skip parameter for pagination + limit: 100, // Set a limit to fetch up to 100 entries per request + include_publish_details: true, + }; + + const variantsEntriesResponse = await stack + .contentType(contentType) + .entry(entries[index].uid) + .variants() + .query(variantQueryParams) + .find(); + + // Map the response items to extract variant UIDs + const variants = variantsEntriesResponse.items.map(entry => ({ + uid: entry.variants_uid, + })); + + // Check if there are more entries to fetch + if (variantsEntriesResponse.items.length === variantQueryParams.limit) { + // Recursively fetch the next set of variants with updated skip value + const nextVariants = await getVariantEntries(stack, contentType, entries, index, queryParams, skip + variantQueryParams.limit); + + // Ensure nextVariants is an array before concatenation + return Array.isArray(nextVariants) ? variants.concat(nextVariants) : variants; + } + + return variants; + } catch (error) { + // Handle error message retrieval from different properties + const errorMessage = error?.errorMessage || error?.message || error?.errors || 'Falied to fetch the variant entries, Please contact the admin for support.'; + throw new Error(`Error fetching variants: ${errorMessage}`); + } +} + async function getContentTypes(stack, skip = 0, contentTypes = []) { return new Promise((resolve, reject) => { skipCount = skip; @@ -135,7 +198,7 @@ function setConfig(conf, bp) { } async function start( - { retryFailed, bulkPublish, publishAllContentTypes, contentTypes, locales, environments, apiVersion }, + { retryFailed, bulkPublish, publishAllContentTypes, contentTypes, locales, environments, apiVersion, includeVariantsFlag, entry_uid }, stack, config, ) { @@ -149,6 +212,11 @@ async function start( } process.exit(0); }); + + if (includeVariantsFlag) { + apiVersion = VARIANTS_PUBLISH_API_VERSION; + } + if (retryFailed) { if (typeof retryFailed === 'string') { if (!validateFile(retryFailed, ['publish-entries', 'bulk-publish-entries'])) { @@ -173,7 +241,7 @@ async function start( for (let loc = 0; loc < locales.length; loc += 1) { for (let i = 0; i < allContentTypes.length; i += 1) { /* eslint-disable no-await-in-loop */ - await getEntries(stack, allContentTypes[i].uid || allContentTypes[i], locales[loc], bulkPublish, environments, apiVersion); + await getEntries(stack, allContentTypes[i].uid || allContentTypes[i], locales[loc], bulkPublish, environments, apiVersion, includeVariantsFlag, entry_uid); /* eslint-enable no-await-in-loop */ } } diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 140880ded0..8a777f1c97 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -22,7 +22,7 @@ "@types/node": "^14.14.32", "@types/tar": "^6.1.3", "@types/tmp": "^0.2.0", - "axios": "^1.6.4", + "axios": "^1.7.4", "eslint": "^8.18.0", "eslint-config-oclif": "^4.0.0", "eslint-config-oclif-typescript": "^3.0.8",