@optima-chat/commerce-cli 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/commerce-storefront/SKILL.md +183 -3
- package/dist/api/rest/commerce.d.ts +171 -2
- package/dist/api/rest/commerce.d.ts.map +1 -1
- package/dist/api/rest/commerce.js +167 -0
- package/dist/api/rest/commerce.js.map +1 -1
- package/dist/commands/merchant/info.js +3 -3
- package/dist/commands/merchant/info.js.map +1 -1
- package/dist/commands/merchant/setup.js +3 -3
- package/dist/commands/merchant/setup.js.map +1 -1
- package/dist/commands/merchant/update.js +5 -5
- package/dist/commands/merchant/update.js.map +1 -1
- package/dist/commands/section/create.d.ts +3 -0
- package/dist/commands/section/create.d.ts.map +1 -0
- package/dist/commands/section/create.js +218 -0
- package/dist/commands/section/create.js.map +1 -0
- package/dist/commands/section/delete.d.ts +3 -0
- package/dist/commands/section/delete.d.ts.map +1 -0
- package/dist/commands/section/delete.js +86 -0
- package/dist/commands/section/delete.js.map +1 -0
- package/dist/commands/section/hide.d.ts +3 -0
- package/dist/commands/section/hide.d.ts.map +1 -0
- package/dist/commands/section/hide.js +82 -0
- package/dist/commands/section/hide.js.map +1 -0
- package/dist/commands/section/index.d.ts +4 -0
- package/dist/commands/section/index.d.ts.map +1 -0
- package/dist/commands/section/index.js +23 -0
- package/dist/commands/section/index.js.map +1 -0
- package/dist/commands/section/list.d.ts +3 -0
- package/dist/commands/section/list.d.ts.map +1 -0
- package/dist/commands/section/list.js +164 -0
- package/dist/commands/section/list.js.map +1 -0
- package/dist/commands/section/product/create.d.ts +3 -0
- package/dist/commands/section/product/create.d.ts.map +1 -0
- package/dist/commands/section/product/create.js +208 -0
- package/dist/commands/section/product/create.js.map +1 -0
- package/dist/commands/section/product/delete.d.ts +3 -0
- package/dist/commands/section/product/delete.d.ts.map +1 -0
- package/dist/commands/section/product/delete.js +85 -0
- package/dist/commands/section/product/delete.js.map +1 -0
- package/dist/commands/section/product/hide.d.ts +3 -0
- package/dist/commands/section/product/hide.d.ts.map +1 -0
- package/dist/commands/section/product/hide.js +78 -0
- package/dist/commands/section/product/hide.js.map +1 -0
- package/dist/commands/section/product/index.d.ts +4 -0
- package/dist/commands/section/product/index.d.ts.map +1 -0
- package/dist/commands/section/product/index.js +17 -0
- package/dist/commands/section/product/index.js.map +1 -0
- package/dist/commands/section/product/list.d.ts +3 -0
- package/dist/commands/section/product/list.d.ts.map +1 -0
- package/dist/commands/section/product/list.js +157 -0
- package/dist/commands/section/product/list.js.map +1 -0
- package/dist/commands/section/product/reorder.d.ts +3 -0
- package/dist/commands/section/product/reorder.d.ts.map +1 -0
- package/dist/commands/section/product/reorder.js +110 -0
- package/dist/commands/section/product/reorder.js.map +1 -0
- package/dist/commands/section/product/update.d.ts +3 -0
- package/dist/commands/section/product/update.d.ts.map +1 -0
- package/dist/commands/section/product/update.js +127 -0
- package/dist/commands/section/product/update.js.map +1 -0
- package/dist/commands/section/reorder.d.ts +3 -0
- package/dist/commands/section/reorder.d.ts.map +1 -0
- package/dist/commands/section/reorder.js +111 -0
- package/dist/commands/section/reorder.js.map +1 -0
- package/dist/commands/section/translation/delete.d.ts +3 -0
- package/dist/commands/section/translation/delete.d.ts.map +1 -0
- package/dist/commands/section/translation/delete.js +97 -0
- package/dist/commands/section/translation/delete.js.map +1 -0
- package/dist/commands/section/translation/index.d.ts +4 -0
- package/dist/commands/section/translation/index.d.ts.map +1 -0
- package/dist/commands/section/translation/index.js +11 -0
- package/dist/commands/section/translation/index.js.map +1 -0
- package/dist/commands/section/translation/list.d.ts +3 -0
- package/dist/commands/section/translation/list.d.ts.map +1 -0
- package/dist/commands/section/translation/list.js +104 -0
- package/dist/commands/section/translation/list.js.map +1 -0
- package/dist/commands/section/translation/set.d.ts +3 -0
- package/dist/commands/section/translation/set.d.ts.map +1 -0
- package/dist/commands/section/translation/set.js +151 -0
- package/dist/commands/section/translation/set.js.map +1 -0
- package/dist/commands/section/update.d.ts +3 -0
- package/dist/commands/section/update.d.ts.map +1 -0
- package/dist/commands/section/update.js +137 -0
- package/dist/commands/section/update.js.map +1 -0
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import inquirer from 'inquirer';
|
|
4
|
+
import { commerceApi } from '../../../api/rest/commerce.js';
|
|
5
|
+
import { handleError, createApiError, ValidationError } from '../../../utils/error.js';
|
|
6
|
+
import { output } from '../../../utils/output.js';
|
|
7
|
+
import { addEnhancedHelp } from '../../../utils/helpText.js';
|
|
8
|
+
import { isInteractiveEnvironment } from '../../../utils/interactive.js';
|
|
9
|
+
const cmd = new Command('delete')
|
|
10
|
+
.description('Delete a product page section override (product-level)')
|
|
11
|
+
.argument('<product-id>', 'Product ID')
|
|
12
|
+
.argument('<handle>', 'Section handle to delete')
|
|
13
|
+
.option('-y, --yes', 'Skip confirmation prompt')
|
|
14
|
+
.action(async (productId, handle, options) => {
|
|
15
|
+
try {
|
|
16
|
+
await deleteProductSection(productId, handle, options);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
handleError(error);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
addEnhancedHelp(cmd, {
|
|
23
|
+
examples: [
|
|
24
|
+
'# Delete with confirmation',
|
|
25
|
+
'$ commerce section product delete prod-123 care',
|
|
26
|
+
'',
|
|
27
|
+
'# Delete without confirmation',
|
|
28
|
+
'$ commerce section product delete prod-123 care --yes',
|
|
29
|
+
],
|
|
30
|
+
output: {
|
|
31
|
+
example: JSON.stringify({
|
|
32
|
+
success: true,
|
|
33
|
+
message: '商品区块覆盖已删除',
|
|
34
|
+
}, null, 2),
|
|
35
|
+
},
|
|
36
|
+
relatedCommands: [
|
|
37
|
+
{ command: 'section product list', description: 'View product overrides' },
|
|
38
|
+
{ command: 'section product create', description: 'Create product override' },
|
|
39
|
+
{ command: 'section product hide', description: 'Hide section instead of deleting' },
|
|
40
|
+
],
|
|
41
|
+
notes: [
|
|
42
|
+
'This deletes the product-level override only',
|
|
43
|
+
'After deletion, the section will fall back to merchant-level or system default',
|
|
44
|
+
'Use --yes to skip confirmation in non-interactive environments',
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
export const deleteProductSectionCommand = cmd;
|
|
48
|
+
async function deleteProductSection(productId, handle, options) {
|
|
49
|
+
if (!isInteractiveEnvironment() && !options.yes) {
|
|
50
|
+
throw new ValidationError('非交互模式下需要 --yes 确认删除操作', 'yes');
|
|
51
|
+
}
|
|
52
|
+
if (isInteractiveEnvironment() && !options.yes) {
|
|
53
|
+
const { confirm } = await inquirer.prompt([
|
|
54
|
+
{
|
|
55
|
+
type: 'confirm',
|
|
56
|
+
name: 'confirm',
|
|
57
|
+
message: `确定要删除商品 "${productId}" 的区块 "${handle}" 覆盖吗?删除后将回退到商户级或系统默认。`,
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
60
|
+
]);
|
|
61
|
+
if (!confirm) {
|
|
62
|
+
console.log(chalk.yellow('已取消删除操作'));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const spinner = output.spinner('正在删除商品区块覆盖...');
|
|
67
|
+
try {
|
|
68
|
+
await commerceApi.productSections.product.delete(productId, handle);
|
|
69
|
+
spinner.succeed('商品区块覆盖已删除!');
|
|
70
|
+
if (output.isJson()) {
|
|
71
|
+
output.success({ product_id: productId, handle }, '商品区块覆盖已删除');
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log();
|
|
75
|
+
console.log(chalk.green(`✓ 商品 "${productId}" 的区块 "${handle}" 覆盖已删除`));
|
|
76
|
+
console.log(chalk.gray('提示: 区块将回退到商户级配置或系统默认'));
|
|
77
|
+
console.log();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
spinner.fail('删除商品区块失败');
|
|
82
|
+
throw createApiError(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../src/commands/section/product/delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAMzE,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC9B,WAAW,CAAC,wDAAwD,CAAC;KACrE,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;KACtC,QAAQ,CAAC,UAAU,EAAE,0BAA0B,CAAC;KAChD,MAAM,CAAC,WAAW,EAAE,0BAA0B,CAAC;KAC/C,MAAM,CAAC,KAAK,EAAE,SAAiB,EAAE,MAAc,EAAE,OAAsB,EAAE,EAAE;IAC1E,IAAI,CAAC;QACH,MAAM,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,eAAe,CAAC,GAAG,EAAE;IACnB,QAAQ,EAAE;QACR,4BAA4B;QAC5B,iDAAiD;QACjD,EAAE;QACF,+BAA+B;QAC/B,uDAAuD;KACxD;IACD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MAAM,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACpE,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE9B,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACpB,MAAM,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,SAAS,UAAU,MAAM,SAAS,CAAC,CAAC,CAAC;YACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;YAChD,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzB,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hide.d.ts","sourceRoot":"","sources":["../../../../src/commands/section/product/hide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwDpC,eAAO,MAAM,yBAAyB,SAAM,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { commerceApi } from '../../../api/rest/commerce.js';
|
|
4
|
+
import { handleError, createApiError } from '../../../utils/error.js';
|
|
5
|
+
import { output } from '../../../utils/output.js';
|
|
6
|
+
import { addEnhancedHelp } from '../../../utils/helpText.js';
|
|
7
|
+
const cmd = new Command('hide')
|
|
8
|
+
.description('Hide a product page section (product-level)')
|
|
9
|
+
.argument('<product-id>', 'Product ID')
|
|
10
|
+
.argument('<handle>', 'Section handle to hide')
|
|
11
|
+
.action(async (productId, handle) => {
|
|
12
|
+
try {
|
|
13
|
+
await hideProductSection(productId, handle);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
handleError(error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
addEnhancedHelp(cmd, {
|
|
20
|
+
examples: [
|
|
21
|
+
'# Hide return policy for a specific product',
|
|
22
|
+
'$ commerce section product hide prod-123 return',
|
|
23
|
+
'',
|
|
24
|
+
'# Hide eco-friendly section for this product only',
|
|
25
|
+
'$ commerce section product hide prod-123 eco-friendly',
|
|
26
|
+
],
|
|
27
|
+
output: {
|
|
28
|
+
example: JSON.stringify({
|
|
29
|
+
success: true,
|
|
30
|
+
data: {
|
|
31
|
+
id: 'override-uuid',
|
|
32
|
+
product_id: 'prod-123',
|
|
33
|
+
handle: 'return',
|
|
34
|
+
operation_type: 'hidden',
|
|
35
|
+
},
|
|
36
|
+
message: '商品区块已隐藏',
|
|
37
|
+
}, null, 2),
|
|
38
|
+
},
|
|
39
|
+
relatedCommands: [
|
|
40
|
+
{ command: 'section product list --resolved', description: 'View product sections (shows hidden status)' },
|
|
41
|
+
{ command: 'section product delete', description: 'Delete override to unhide' },
|
|
42
|
+
{ command: 'section hide', description: 'Hide for all products (merchant-level)' },
|
|
43
|
+
],
|
|
44
|
+
notes: [
|
|
45
|
+
'This hides the section for this product only',
|
|
46
|
+
'Other products will still show the section',
|
|
47
|
+
'To unhide, delete the override: section product delete <product-id> <handle>',
|
|
48
|
+
'For hiding across all products, use: section hide',
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
export const hideProductSectionCommand = cmd;
|
|
52
|
+
async function hideProductSection(productId, handle) {
|
|
53
|
+
const spinner = output.spinner('正在隐藏商品区块...');
|
|
54
|
+
try {
|
|
55
|
+
const result = await commerceApi.productSections.product.hide(productId, handle);
|
|
56
|
+
spinner.succeed('商品区块已隐藏!');
|
|
57
|
+
if (output.isJson()) {
|
|
58
|
+
output.success(result, '商品区块已隐藏');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log();
|
|
62
|
+
console.log(chalk.green(`✓ 商品 "${productId}" 的区块 "${handle}" 已隐藏`));
|
|
63
|
+
console.log();
|
|
64
|
+
console.log(chalk.gray('ID: ') + chalk.cyan(result.id));
|
|
65
|
+
console.log(chalk.gray('商品ID: ') + chalk.white(result.product_id));
|
|
66
|
+
console.log(chalk.gray('Handle: ') + chalk.white(result.handle));
|
|
67
|
+
console.log(chalk.gray('操作类型: ') + chalk.white(result.operation_type));
|
|
68
|
+
console.log();
|
|
69
|
+
console.log(chalk.gray(`提示: 要取消隐藏,使用 commerce section product delete ${productId} ${handle}`));
|
|
70
|
+
console.log();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
spinner.fail('隐藏商品区块失败');
|
|
75
|
+
throw createApiError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=hide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hide.js","sourceRoot":"","sources":["../../../../src/commands/section/product/hide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC5B,WAAW,CAAC,6CAA6C,CAAC;KAC1D,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;KACtC,Q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M,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/section/product/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,QAAA,MAAM,cAAc,SACmE,CAAC;AASxF,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { listProductSectionsCommand } from './list.js';
|
|
3
|
+
import { createProductSectionCommand } from './create.js';
|
|
4
|
+
import { updateProductSectionCommand } from './update.js';
|
|
5
|
+
import { deleteProductSectionCommand } from './delete.js';
|
|
6
|
+
import { hideProductSectionCommand } from './hide.js';
|
|
7
|
+
import { reorderProductSectionsCommand } from './reorder.js';
|
|
8
|
+
const productCommand = new Command('product')
|
|
9
|
+
.description('Product-level section management (overrides merchant/system defaults)');
|
|
10
|
+
productCommand.addCommand(listProductSectionsCommand);
|
|
11
|
+
productCommand.addCommand(createProductSectionCommand);
|
|
12
|
+
productCommand.addCommand(updateProductSectionCommand);
|
|
13
|
+
productCommand.addCommand(deleteProductSectionCommand);
|
|
14
|
+
productCommand.addCommand(hideProductSectionCommand);
|
|
15
|
+
productCommand.addCommand(reorderProductSectionsCommand);
|
|
16
|
+
export { productCommand };
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/section/product/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE7D,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;KAC1C,WAAW,CAAC,uEAAuE,CAAC,CAAC;AAExF,cAAc,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;AACtD,cAAc,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACvD,cAAc,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACvD,cAAc,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACvD,cAAc,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC;AACrD,cAAc,CAAC,UAAU,CAAC,6BAA6B,CAAC,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/commands/section/product/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAuEpC,eAAO,MAAM,0BAA0B,SAAM,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { commerceApi } from '../../../api/rest/commerce.js';
|
|
4
|
+
import { handleError, createApiError } from '../../../utils/error.js';
|
|
5
|
+
import { output } from '../../../utils/output.js';
|
|
6
|
+
import { addEnhancedHelp } from '../../../utils/helpText.js';
|
|
7
|
+
const cmd = new Command('list')
|
|
8
|
+
.description('List product page sections (product-level)')
|
|
9
|
+
.argument('<product-id>', 'Product ID')
|
|
10
|
+
.option('--resolved', 'Show merged view with System + Merchant + Product layers (recommended)')
|
|
11
|
+
.action(async (productId, options) => {
|
|
12
|
+
try {
|
|
13
|
+
await listProductSections(productId, options);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
handleError(error);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
addEnhancedHelp(cmd, {
|
|
20
|
+
examples: [
|
|
21
|
+
'# List product-level overrides only',
|
|
22
|
+
'$ commerce section product list prod-123',
|
|
23
|
+
'',
|
|
24
|
+
'# List merged view with all sections (recommended)',
|
|
25
|
+
'$ commerce section product list prod-123 --resolved',
|
|
26
|
+
],
|
|
27
|
+
output: {
|
|
28
|
+
example: JSON.stringify({
|
|
29
|
+
success: true,
|
|
30
|
+
data: {
|
|
31
|
+
sections: [
|
|
32
|
+
{
|
|
33
|
+
handle: 'highlights',
|
|
34
|
+
source: 'system',
|
|
35
|
+
type: 'static',
|
|
36
|
+
position: 1,
|
|
37
|
+
is_hidden: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
handle: 'care',
|
|
41
|
+
source: 'product',
|
|
42
|
+
type: 'collapsible',
|
|
43
|
+
position: 4,
|
|
44
|
+
is_hidden: false,
|
|
45
|
+
content: 'Special care for this product...',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
available_languages: ['en-US', 'zh-CN', 'ja-JP'],
|
|
49
|
+
},
|
|
50
|
+
}, null, 2),
|
|
51
|
+
},
|
|
52
|
+
relatedCommands: [
|
|
53
|
+
{ command: 'section product create', description: 'Create product-level override' },
|
|
54
|
+
{ command: 'section list --resolved', description: 'View merchant-level sections' },
|
|
55
|
+
],
|
|
56
|
+
notes: [
|
|
57
|
+
'Without --resolved: shows only product-level overrides',
|
|
58
|
+
'With --resolved: shows System + Merchant + Product merged view',
|
|
59
|
+
'source field: system | merchant | product (indicates origin)',
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
export const listProductSectionsCommand = cmd;
|
|
63
|
+
async function listProductSections(productId, options) {
|
|
64
|
+
const spinner = output.spinner('正在获取商品区块配置...');
|
|
65
|
+
try {
|
|
66
|
+
if (options.resolved) {
|
|
67
|
+
const result = await commerceApi.productSections.product.listResolved(productId);
|
|
68
|
+
spinner.succeed('区块配置获取成功');
|
|
69
|
+
if (!result.sections || result.sections.length === 0) {
|
|
70
|
+
if (output.isJson()) {
|
|
71
|
+
output.success({ sections: [], available_languages: result.available_languages || [] }, '暂无区块配置');
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(chalk.yellow('\n暂无区块配置\n'));
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (output.isJson()) {
|
|
79
|
+
output.success(result);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(chalk.bold(`商品 ${productId} 区块配置(合并视图):\n`));
|
|
84
|
+
result.sections.forEach((section, index) => {
|
|
85
|
+
const sourceColor = section.source === 'system' ? chalk.gray :
|
|
86
|
+
section.source === 'merchant' ? chalk.blue :
|
|
87
|
+
chalk.cyan;
|
|
88
|
+
const hiddenBadge = section.is_hidden ? chalk.red(' [已隐藏]') : '';
|
|
89
|
+
console.log(chalk.white(`${index + 1}. ${section.handle}`) + hiddenBadge);
|
|
90
|
+
console.log(chalk.gray(` 来源: `) + sourceColor(section.source));
|
|
91
|
+
console.log(chalk.gray(` 类型: ${section.type}`));
|
|
92
|
+
console.log(chalk.gray(` 位置: ${section.position}`));
|
|
93
|
+
if (section.tab_group) {
|
|
94
|
+
console.log(chalk.gray(` Tab分组: ${section.tab_group}`));
|
|
95
|
+
}
|
|
96
|
+
if (section.content) {
|
|
97
|
+
const preview = section.content.length > 50 ? section.content.substring(0, 50) + '...' : section.content;
|
|
98
|
+
console.log(chalk.gray(` 内容: ${preview}`));
|
|
99
|
+
}
|
|
100
|
+
const langCount = Object.keys(section.translations || {}).length;
|
|
101
|
+
if (langCount > 0) {
|
|
102
|
+
console.log(chalk.gray(` 翻译: ${langCount} 种语言`));
|
|
103
|
+
}
|
|
104
|
+
console.log();
|
|
105
|
+
});
|
|
106
|
+
console.log(chalk.gray(`共 ${result.sections.length} 个区块`));
|
|
107
|
+
if (result.available_languages && result.available_languages.length > 0) {
|
|
108
|
+
console.log(chalk.gray(`支持语言: ${result.available_languages.join(', ')}`));
|
|
109
|
+
}
|
|
110
|
+
console.log();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const overrides = await commerceApi.productSections.product.list(productId);
|
|
115
|
+
spinner.succeed('商品级覆盖获取成功');
|
|
116
|
+
if (!overrides || overrides.length === 0) {
|
|
117
|
+
if (output.isJson()) {
|
|
118
|
+
output.success({ overrides: [] }, '暂无商品级覆盖(提示: 使用 --resolved 查看完整视图)');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log(chalk.yellow('\n暂无商品级覆盖'));
|
|
122
|
+
console.log(chalk.gray('提示: 使用 --resolved 查看 System + Merchant + Product 合并后的完整视图\n'));
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (output.isJson()) {
|
|
127
|
+
output.success({ overrides });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
console.log();
|
|
131
|
+
console.log(chalk.bold(`商品 ${productId} 的覆盖配置:\n`));
|
|
132
|
+
overrides.forEach((override, index) => {
|
|
133
|
+
console.log(chalk.cyan(`${index + 1}. ${override.handle}`));
|
|
134
|
+
console.log(chalk.gray(` ID: ${override.id}`));
|
|
135
|
+
console.log(chalk.gray(` 操作类型: ${override.operation_type}`));
|
|
136
|
+
console.log(chalk.gray(` 区块类型: ${override.type}`));
|
|
137
|
+
console.log(chalk.gray(` 位置: ${override.position}`));
|
|
138
|
+
if (override.tab_group) {
|
|
139
|
+
console.log(chalk.gray(` Tab分组: ${override.tab_group}`));
|
|
140
|
+
}
|
|
141
|
+
if (override.content) {
|
|
142
|
+
const preview = override.content.length > 50 ? override.content.substring(0, 50) + '...' : override.content;
|
|
143
|
+
console.log(chalk.gray(` 内容: ${preview}`));
|
|
144
|
+
}
|
|
145
|
+
console.log();
|
|
146
|
+
});
|
|
147
|
+
console.log(chalk.gray(`共 ${overrides.length} 个覆盖`));
|
|
148
|
+
console.log(chalk.gray('提示: 使用 --resolved 查看完整的合并视图\n'));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
spinner.fail('获取区块配置失败');
|
|
154
|
+
throw createApiError(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../src/commands/section/product/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAM7D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC5B,WAAW,CAAC,4CAA4C,CAAC;KACzD,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;KACtC,MAAM,CAAC,YAAY,EAAE,wEAAwE,CAAC;KAC9F,MAAM,CAAC,KAAK,EAAE,SAAiB,EAAE,OAAoB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,eAAe,CAAC,GAAG,EAAE;IACnB,QAAQ,EAAE;QACR,qCAAqC;QACrC,0CAA0C;QAC1C,EAA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AAC;gBACrD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzB,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reorder.d.ts","sourceRoot":"","sources":["../../../../src/commands/section/product/reorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwDpC,eAAO,MAAM,6BAA6B,SAAM,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { commerceApi } from '../../../api/rest/commerce.js';
|
|
4
|
+
import { handleError, createApiError, ValidationError } from '../../../utils/error.js';
|
|
5
|
+
import { output } from '../../../utils/output.js';
|
|
6
|
+
import { addEnhancedHelp } from '../../../utils/helpText.js';
|
|
7
|
+
import { isInteractiveEnvironment } from '../../../utils/interactive.js';
|
|
8
|
+
const cmd = new Command('reorder')
|
|
9
|
+
.description('Reorder product page sections (product-level)')
|
|
10
|
+
.argument('<product-id>', 'Product ID')
|
|
11
|
+
.option('--sections <json>', 'JSON array of {handle, position} objects (required)')
|
|
12
|
+
.option('--tab-group <group>', 'Only reorder within this tab group (optional)')
|
|
13
|
+
.action(async (productId, options) => {
|
|
14
|
+
try {
|
|
15
|
+
await reorderProductSections(productId, options);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
handleError(error);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
addEnhancedHelp(cmd, {
|
|
22
|
+
examples: [
|
|
23
|
+
'# Reorder sections for a specific product',
|
|
24
|
+
'$ commerce section product reorder prod-123 --sections \'[{"handle":"highlights","position":1},{"handle":"care","position":2}]\'',
|
|
25
|
+
'',
|
|
26
|
+
'# Reorder within a tab group',
|
|
27
|
+
'$ commerce section product reorder prod-123 --tab-group product-info --sections \'[...]\'',
|
|
28
|
+
],
|
|
29
|
+
output: {
|
|
30
|
+
example: JSON.stringify({
|
|
31
|
+
success: true,
|
|
32
|
+
message: '商品区块顺序已更新',
|
|
33
|
+
}, null, 2),
|
|
34
|
+
},
|
|
35
|
+
relatedCommands: [
|
|
36
|
+
{ command: 'section product list --resolved', description: 'View current section order' },
|
|
37
|
+
{ command: 'section product update', description: 'Update individual section' },
|
|
38
|
+
{ command: 'section reorder', description: 'Reorder for all products (merchant-level)' },
|
|
39
|
+
],
|
|
40
|
+
notes: [
|
|
41
|
+
'sections must be a valid JSON array',
|
|
42
|
+
'Each item needs: handle (string), position (number)',
|
|
43
|
+
'This only affects the specified product',
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
export const reorderProductSectionsCommand = cmd;
|
|
47
|
+
async function reorderProductSections(productId, options) {
|
|
48
|
+
const { sections, tabGroup } = options;
|
|
49
|
+
if (!sections || sections.trim().length === 0) {
|
|
50
|
+
if (!isInteractiveEnvironment()) {
|
|
51
|
+
throw new ValidationError('缺少必需参数: --sections (JSON数组)', 'sections');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log(chalk.yellow('请指定 --sections 参数'));
|
|
55
|
+
console.log(chalk.gray('格式: \'[{"handle":"highlights","position":1},{"handle":"details","position":2}]\''));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let parsedSections;
|
|
60
|
+
try {
|
|
61
|
+
parsedSections = JSON.parse(sections);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new ValidationError('--sections 必须是有效的 JSON 数组', 'sections');
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(parsedSections)) {
|
|
67
|
+
throw new ValidationError('--sections 必须是数组', 'sections');
|
|
68
|
+
}
|
|
69
|
+
for (const item of parsedSections) {
|
|
70
|
+
if (!item.handle || typeof item.handle !== 'string') {
|
|
71
|
+
throw new ValidationError('每个 section 必须有 handle 字段(字符串)', 'sections');
|
|
72
|
+
}
|
|
73
|
+
if (typeof item.position !== 'number' || item.position < 1) {
|
|
74
|
+
throw new ValidationError('每个 section 必须有 position 字段(正整数)', 'sections');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const spinner = output.spinner('正在更新商品区块顺序...');
|
|
78
|
+
try {
|
|
79
|
+
const data = {
|
|
80
|
+
sections: parsedSections,
|
|
81
|
+
};
|
|
82
|
+
if (tabGroup !== undefined) {
|
|
83
|
+
data.tab_group = tabGroup || null;
|
|
84
|
+
}
|
|
85
|
+
await commerceApi.productSections.product.reorder(productId, data);
|
|
86
|
+
spinner.succeed('商品区块顺序已更新!');
|
|
87
|
+
if (output.isJson()) {
|
|
88
|
+
output.success({ product_id: productId, sections: parsedSections, tab_group: tabGroup || null }, '商品区块顺序已更新');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log();
|
|
92
|
+
console.log(chalk.green('✓ 商品区块顺序已更新!'));
|
|
93
|
+
console.log();
|
|
94
|
+
console.log(chalk.gray('商品ID: ') + chalk.white(productId));
|
|
95
|
+
if (tabGroup) {
|
|
96
|
+
console.log(chalk.gray('Tab分组: ') + chalk.white(tabGroup));
|
|
97
|
+
}
|
|
98
|
+
console.log(chalk.gray('新顺序:'));
|
|
99
|
+
parsedSections.forEach((item) => {
|
|
100
|
+
console.log(chalk.gray(` ${item.position}. `) + chalk.cyan(item.handle));
|
|
101
|
+
});
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
spinner.fail('更新商品区块顺序失败');
|
|
107
|
+
throw createApiError(error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=reorder.js.map
|
|
@@ -0,0 +1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