Skip to content

Commit aa7f63f

Browse files
naman-contentstackclaude
andcommitted
fix(bulk-operations): publish only to scoped targets
Per-item environments/locales were collapsed into batch-level arrays, so every item inherited the batch union: backup-dir assets published to every environment found in the backup, and revert unpublished using the first log entry's environments. Batches are now keyed on (locale, environment set). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d1aaa7e commit aa7f63f

22 files changed

Lines changed: 820 additions & 382 deletions

‎.talismanrc‎

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,15 @@
11
fileignoreconfig:
2-
- filename: packages/contentstack-audit/test/unit/mock/am-contents-no-stack/environments/environments.json
3-
checksum: fe82c708f5f4d0b05694a601855fb7950661048eef8d7f9f794713e3a665064e
4-
- filename: packages/contentstack-audit/test/unit/mock/am-contents/environments/environments.json
5-
checksum: ffaaee9269a6e833cd3dbe337ddc5c060cce948519873c7a2777754519a31b52
6-
- filename: pnpm-lock.yaml
7-
checksum: 649aae748e3ae8c157439dc6c7c9ea402cc19b4dab7ca64b7e4d839d1375df53
8-
- filename: packages/contentstack-audit/src/types/content-types.ts
9-
checksum: d16a65415c3184f15a807d58e5858310aeb5633794fc9075e36f89c94da636c3
10-
- filename: packages/contentstack-audit/src/audit-base-command.ts
11-
checksum: b706ea114a3cb5e4c0e7e163f32ceffa3356a6b0766bf5b8fe387c3c72f44c36
12-
- filename: packages/contentstack-audit/test/unit/mock/am-contents-no-stack/spaces/space_one/assets/chunk0-assets.json
13-
checksum: a276dc984efd49c097b4c38a02a17cfd1d28d704bd403d65af2b7673b8e9dbe9
14-
- filename: packages/contentstack-audit/src/modules/entries.ts
15-
checksum: 13072df0872f8c098d23f49b02f9e8f3e492ab2f483d67a5ea5e423ab406ad94
16-
- filename: packages/contentstack-audit/src/modules/assets.ts
17-
checksum: 9cdc568453a3926d866de4d3d56e6fbc4629eafcaca1c51536c11d937a0bf126
18-
- filename: packages/contentstack-audit/test/unit/modules/assets.test.ts
19-
checksum: 203bb83afa84a696b84066dc6959712289e9fc4135c8cba641f9ff634f32b3db
20-
- filename: packages/contentstack-audit/test/unit/modules/entries.test.ts
21-
checksum: 31d9767d87e4e9db54f641e8cb9d3360f591acdaa8b089a83eaa4aacdf0c3a35
22-
- filename: packages/contentstack-audit/test/unit/mock/am-contents/spaces/space_clean/assets/chunk0-assets.json
23-
checksum: f02886c04ea1097ebc5965fa9a63a878adb9437d56a5b1797be1967fae35f9e4
2+
3+
- filename: packages/contentstack-bulk-operations/src/utils/backup-dir-asset-fetcher.ts
4+
checksum: fbf1ef882bf4ea8f06a7a28b9248a07e01f5a5d2d4da98dbb9ee52bc16ce318a
5+
- filename: packages/contentstack-bulk-operations/test/unit/utils/backup-dir-asset-fetcher.test.ts
6+
checksum: b905524c952aff0f089fa5347e0db18479b75a438cd9ae77e2dfe1cb203d7e59
7+
- filename: packages/contentstack-bulk-operations/test/unit/utils/revert-retry-handler.test.ts
8+
checksum: 142e7b67a06bc13b6b4191b17f2ea8ae31a3bce20086ea35a92f3e3671eb603d
9+
- filename: packages/contentstack-bulk-operations/src/utils/batch-helper.ts
10+
checksum: ddcd8ef7c56d1122df88075883a2768a28813147e8fdef5b8e72a1ec118c045a
2411
- filename: packages/contentstack-import/src/import/modules/assets.ts
25-
checksum: d213265909a1b163ce733b9e2534e3a74304a2589c2d85e059f10fa0acfdee11
26-
- filename: packages/contentstack-import/src/utils/import-config-handler.ts
27-
checksum: 5b2050b283ea3d990e8ad3207b054c6932b76d2bd82a9f659b287ef11dec9f83
28-
- filename: packages/contentstack-audit/test/unit/mock/am-contents/spaces/space_cross_only/assets/chunk0-assets.json
29-
checksum: 27d5398f5d81bd3af53da9a5d10475a36c08e8fd8ad29df24e8f267494419a20
30-
- filename: packages/contentstack-audit/test/unit/mock/am-contents/spaces/space_one/assets/chunk0-assets.json
31-
checksum: 9fc8b266ef58ecce8d3c4182632d1f7d088dfbce81b3fcea46b087cde3129b91
32-
- filename: packages/contentstack-audit/test/unit/mock/am-contents/stack/stack.json
33-
checksum: c4ac3ff80eb38b1c58eb0db21a232bd84f856d4647093542296199036945083c
12+
checksum: 014f612c3e8db21c891da0c17a1a3b4cd340c026c58034791d86cd5f73aa9f90
3413
- filename: packages/contentstack-bulk-operations/src/commands/cm/stacks/bulk-assets.ts
35-
checksum: 60f33657cc6e2664c17397a2f6b4b54a3f7bf71618931d63cd2811822bd4837e
36-
- filename: packages/contentstack-bulk-operations/src/utils/data-dir-asset-fetcher.ts
37-
checksum: ddcf4601ac47be300eba0eb901e4d45d748c2c4eab676c56677cb9a802fe3db0
38-
- filename: packages/contentstack-migration/src/commands/cm/stacks/migration.ts
39-
checksum: a64a4d396eddd936a63b799eff58c5c6660b5dcaa3a310fd8b09a027932f1789
40-
- filename: packages/contentstack-migration/README.md
41-
checksum: e96006c1a948f766c88ae972b29582fa58eaf8184606bf011eebddc5a06cd7b6
42-
version: ""
14+
checksum: 9392511b337c361b86c36eb2431d8fea9129a61f6b7d70dcb4a633fea339ca61
15+
version: ""

‎packages/contentstack-bulk-operations/README.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Bulk operations for assets: publish/unpublish/cross-publish (CMS) and delete/mov
4141

4242
```
4343
USAGE
44-
$ csdx cm:stacks:bulk-assets [-a <value>] [-k <value>] [--operation publish|unpublish|delete|move] [--environments
45-
<value>...] [--locales <value>...] [--source-env <value>] [--source-alias <value>] [--publish-mode bulk|single]
46-
[--branch <value>] [-c <value>] [-y] [--retry-failed <value>] [--revert <value>] [--bulk-operation-file <value>]
47-
[--folder-uid <value>] [-d <value>] [--dry-run] [--space-uid <value>] [--org-uid <value>] [--workspace <value>]
48-
[--asset-uids-file <value>] [--locale <value>] [--target-folder-uid <value>]
44+
$ csdx cm:stacks:bulk-assets [-a <value>] [-k <value>] [--operation publish|unpublish|delete|move] [--source-alias
45+
<value>] [--publish-mode bulk|single] [--branch <value>] [-c <value>] [-y] [--retry-failed <value>] [--revert
46+
<value>] [--bulk-operation-file <value>] [--backup-dir <value> | --source-env <value> | --folder-uid <value> |
47+
--environments <value>... | --locales <value>...] [--dry-run] [--space-uid <value>] [--org-uid <value>] [--workspace
48+
<value>] [--asset-uids-file <value>] [--locale <value>] [--target-folder-uid <value>]
4949
5050
FLAGS
5151
-a, --alias=<value> Uses the name of a saved Management Token to authenticate the command. The command
@@ -54,13 +54,16 @@ FLAGS
5454
-c, --config=<value> (optional) Specifies the path to a JSON configuration file that defines the options
5555
for the command. Use this file instead of passing multiple CLI flags for a single
5656
run.
57-
-d, --data-dir=<value> Path to exported content folder containing asset publish details.
5857
-k, --stack-api-key=<value> API key of the source stack. You must use either the --stack-api-key flag or the
5958
--alias flag.
6059
-y, --yes Skips interactive confirmation prompts and runs the command immediately using the
6160
provided options. Useful for automation and scripts.
6261
--asset-uids-file=<value> Path to UTF-8 JSON file: exactly `{ "uids": ["uid1", "uid2"] }` (non-empty string
6362
array, no trimming; large lists: see docs for NODE_OPTIONS)
63+
--backup-dir=<value> Path to the import backup directory. Each imported asset is published only to the
64+
environments and locales it was published to in the source stack (read from the
65+
backup publish details and asset UID mapping), with asset-scan gating applied.
66+
Intended for the post-import publish flow.
6467
--branch=<value> [default: main] The name of the branch where you want to perform the bulk publish
6568
operation. If you don't mention the branch name, then by default the content from
6669
main branch will be published.
@@ -114,7 +117,7 @@ EXAMPLES
114117
115118
$ csdx cm:stacks:bulk-assets --revert ./bulk-operation -a myAlias
116119
117-
$ csdx cm:stacks:bulk-assets --data-dir ./content --operation publish -k blt123
120+
$ csdx cm:stacks:bulk-assets --backup-dir ./content --operation publish -k blt123
118121
119122
$ csdx cm:stacks:bulk-assets --operation delete --space-uid am123 --org-uid bltOrg --locale en-us --asset-uids-file ./assets.json
120123

‎packages/contentstack-bulk-operations/src/base-bulk-command.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ import {
2727
setupStackConfig,
2828
setupBatchQueueListeners,
2929
confirmOperation as confirmOperationUtil,
30-
getUniqueEnvironments,
31-
getUniqueLocales,
3230
batchItems,
31+
hasPublishTargets,
3332
handleCrossPublishOperation,
3433
logOperationInfo,
3534
validateBatch,
@@ -519,9 +518,12 @@ export abstract class BaseBulkCommand extends Command {
519518
* Execute operation in BULK mode - processes items in batches
520519
*/
521520
private async executeBulkMode(items: any[], startTime: number): Promise<BulkOperationResult> {
522-
const environments = getUniqueEnvironments(items);
523-
const locales = getUniqueLocales(items);
524-
const batches = batchItems(items, environments, locales);
521+
const untargeted = items.filter((item) => !hasPublishTargets(item)).length;
522+
if (untargeted > 0) {
523+
this.logger.warn(`Skipping ${untargeted} item(s) with no publish target (missing publish_details).`);
524+
}
525+
526+
const batches = batchItems(items);
525527

526528
batches.forEach((batch) => validateBatch(batch));
527529
this.logger.debug(`Created ${batches.length} batches for processing`, this.loggerContext);

0 commit comments

Comments
 (0)