@optima-chat/ads-cli 0.6.0 → 0.8.0
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/LICENSE +21 -0
- package/dist/commands/account/check.d.ts.map +1 -1
- package/dist/commands/account/check.js +12 -62
- package/dist/commands/account/check.js.map +1 -1
- package/dist/commands/account/index.d.ts.map +1 -1
- package/dist/commands/account/index.js +2 -2
- package/dist/commands/account/index.js.map +1 -1
- package/dist/commands/account/link.d.ts +6 -0
- package/dist/commands/account/link.d.ts.map +1 -0
- package/dist/commands/account/link.js +57 -0
- package/dist/commands/account/link.js.map +1 -0
- package/dist/commands/ad/create.d.ts.map +1 -1
- package/dist/commands/ad/create.js +29 -28
- package/dist/commands/ad/create.js.map +1 -1
- package/dist/commands/ad/delete.d.ts.map +1 -1
- package/dist/commands/ad/delete.js +1 -28
- package/dist/commands/ad/delete.js.map +1 -1
- package/dist/commands/ad/info.d.ts.map +1 -1
- package/dist/commands/ad/info.js +3 -66
- package/dist/commands/ad/info.js.map +1 -1
- package/dist/commands/ad/list.d.ts.map +1 -1
- package/dist/commands/ad/list.js +1 -65
- package/dist/commands/ad/list.js.map +1 -1
- package/dist/commands/ad/update.d.ts.map +1 -1
- package/dist/commands/ad/update.js +8 -17
- package/dist/commands/ad/update.js.map +1 -1
- package/dist/commands/ad-group/create.d.ts.map +1 -1
- package/dist/commands/ad-group/create.js +1 -23
- package/dist/commands/ad-group/create.js.map +1 -1
- package/dist/commands/ad-group/delete.d.ts.map +1 -1
- package/dist/commands/ad-group/delete.js +1 -28
- package/dist/commands/ad-group/delete.js.map +1 -1
- package/dist/commands/ad-group/info.d.ts.map +1 -1
- package/dist/commands/ad-group/info.js +4 -37
- package/dist/commands/ad-group/info.js.map +1 -1
- package/dist/commands/ad-group/list.d.ts.map +1 -1
- package/dist/commands/ad-group/list.js +1 -57
- package/dist/commands/ad-group/list.js.map +1 -1
- package/dist/commands/ad-group/update.d.ts.map +1 -1
- package/dist/commands/ad-group/update.js +11 -28
- package/dist/commands/ad-group/update.js.map +1 -1
- package/dist/commands/auth/status.d.ts +0 -2
- package/dist/commands/auth/status.d.ts.map +1 -1
- package/dist/commands/auth/status.js +12 -47
- package/dist/commands/auth/status.js.map +1 -1
- package/dist/commands/campaign/create.d.ts.map +1 -1
- package/dist/commands/campaign/create.js +1 -24
- package/dist/commands/campaign/create.js.map +1 -1
- package/dist/commands/campaign/delete.d.ts.map +1 -1
- package/dist/commands/campaign/delete.js +1 -28
- package/dist/commands/campaign/delete.js.map +1 -1
- package/dist/commands/campaign/info.d.ts.map +1 -1
- package/dist/commands/campaign/info.js +3 -34
- package/dist/commands/campaign/info.js.map +1 -1
- package/dist/commands/campaign/list.d.ts.map +1 -1
- package/dist/commands/campaign/list.js +1 -46
- package/dist/commands/campaign/list.js.map +1 -1
- package/dist/commands/campaign/update.d.ts.map +1 -1
- package/dist/commands/campaign/update.js +11 -28
- package/dist/commands/campaign/update.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +16 -72
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/keyword/add.d.ts.map +1 -1
- package/dist/commands/keyword/add.js +1 -20
- package/dist/commands/keyword/add.js.map +1 -1
- package/dist/commands/keyword/delete.d.ts.map +1 -1
- package/dist/commands/keyword/delete.js +1 -28
- package/dist/commands/keyword/delete.js.map +1 -1
- package/dist/commands/keyword/list.d.ts.map +1 -1
- package/dist/commands/keyword/list.js +1 -51
- package/dist/commands/keyword/list.js.map +1 -1
- package/dist/commands/keyword/update.d.ts.map +1 -1
- package/dist/commands/keyword/update.js +10 -24
- package/dist/commands/keyword/update.js.map +1 -1
- package/dist/index.js +0 -0
- package/package.json +9 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Optima Chat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../src/commands/account/check.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../src/commands/account/check.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,YAAY,SA2BrB,CAAC"}
|
|
@@ -2,80 +2,30 @@
|
|
|
2
2
|
* Account Check Command - 检查账号配置状态
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import ora from 'ora';
|
|
7
|
-
import Table from 'cli-table3';
|
|
8
5
|
import { getApiClient } from '../../lib/api-client.js';
|
|
9
6
|
import { handleError } from '../../utils/errors.js';
|
|
10
7
|
import { getCustomerId } from '../../utils/customer-id.js';
|
|
11
8
|
export const checkCommand = new Command('check')
|
|
12
9
|
.description('检查账号配置状态(账单、权限等)')
|
|
13
|
-
.
|
|
14
|
-
.action(async (options) => {
|
|
15
|
-
const spinner = ora('检查账号状态...').start();
|
|
10
|
+
.action(async () => {
|
|
16
11
|
try {
|
|
17
12
|
const customerId = getCustomerId();
|
|
18
13
|
const client = getApiClient();
|
|
19
14
|
// Check account via backend API
|
|
20
15
|
const accountCheck = await client.checkAccount(customerId);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'top-left': '┌',
|
|
33
|
-
'top-right': '┐',
|
|
34
|
-
bottom: '─',
|
|
35
|
-
'bottom-mid': '┴',
|
|
36
|
-
'bottom-left': '└',
|
|
37
|
-
'bottom-right': '┘',
|
|
38
|
-
left: '│',
|
|
39
|
-
'left-mid': '├',
|
|
40
|
-
mid: '─',
|
|
41
|
-
'mid-mid': '┼',
|
|
42
|
-
right: '│',
|
|
43
|
-
'right-mid': '┤',
|
|
44
|
-
middle: '│',
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
const checkResult = accountCheck;
|
|
48
|
-
// Customer info
|
|
49
|
-
table.push([chalk.gray('账号 ID'), chalk.white(checkResult.customerId || customerId)], [chalk.gray('连接状态'), checkResult.connected ? chalk.green('✅ 已连接') : chalk.red('❌ 未连接')]);
|
|
50
|
-
if (checkResult.info) {
|
|
51
|
-
const info = checkResult.info;
|
|
52
|
-
if (info.descriptive_name) {
|
|
53
|
-
table.push([chalk.gray('账号名称'), chalk.white(info.descriptive_name)]);
|
|
54
|
-
}
|
|
55
|
-
if (info.currency_code) {
|
|
56
|
-
table.push([chalk.gray('货币'), chalk.white(info.currency_code)]);
|
|
57
|
-
}
|
|
58
|
-
if (info.time_zone) {
|
|
59
|
-
table.push([chalk.gray('时区'), chalk.white(info.time_zone)]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
console.log(table.toString());
|
|
63
|
-
// Recommendations
|
|
64
|
-
console.log(chalk.cyan.bold('\n💡 建议\n'));
|
|
65
|
-
if (checkResult.connected) {
|
|
66
|
-
console.log(chalk.green('✅ 账号已连接,可以开始使用 Google Ads API!\n'));
|
|
67
|
-
console.log(chalk.gray('快速开始:'));
|
|
68
|
-
console.log(chalk.cyan(` google-ads campaign list\n`));
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
console.log(chalk.yellow('⚠️ 账号未连接\n'));
|
|
72
|
-
console.log(chalk.gray('请确保已登录并完成 Google Ads 连接:'));
|
|
73
|
-
console.log(chalk.cyan(' google-ads auth login\n'));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
16
|
+
const checkResult = accountCheck;
|
|
17
|
+
const result = {
|
|
18
|
+
customer_id: checkResult.customerId || customerId,
|
|
19
|
+
connected: checkResult.connected || false,
|
|
20
|
+
info: checkResult.info ? {
|
|
21
|
+
name: checkResult.info.descriptive_name || null,
|
|
22
|
+
currency: checkResult.info.currency_code || null,
|
|
23
|
+
timezone: checkResult.info.time_zone || null,
|
|
24
|
+
} : null,
|
|
25
|
+
};
|
|
26
|
+
console.log(JSON.stringify(result, null, 2));
|
|
76
27
|
}
|
|
77
28
|
catch (error) {
|
|
78
|
-
spinner.fail('检查失败');
|
|
79
29
|
handleError(error);
|
|
80
30
|
}
|
|
81
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/commands/account/check.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,
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AC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/account/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/account/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,cAAc,SAGD,CAAC"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
5
|
import { checkCommand } from './check.js';
|
|
6
|
-
import {
|
|
6
|
+
import { linkCommand } from './link.js';
|
|
7
7
|
export const accountCommand = new Command('account')
|
|
8
8
|
.description('账号管理')
|
|
9
9
|
.addCommand(checkCommand)
|
|
10
|
-
.addCommand(
|
|
10
|
+
.addCommand(linkCommand);
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/account/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/account/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;KACjD,WAAW,CAAC,MAAM,CAAC;KACnB,UAAU,CAAC,YAAY,CAAC;KACxB,UAAU,CAAC,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../src/commands/account/link.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,eAAO,MAAM,WAAW,SAoDpB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Link Command - 关联已有的 Google Ads 账号
|
|
3
|
+
*/
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import Conf from 'conf';
|
|
6
|
+
import { handleError } from '../../utils/errors.js';
|
|
7
|
+
const config = new Conf({ projectName: 'google-ads-cli' });
|
|
8
|
+
export const linkCommand = new Command('link')
|
|
9
|
+
.description('关联已有的 Google Ads 账号(保存 Customer ID 到本地配置)')
|
|
10
|
+
.requiredOption('--customer-id <id>', 'Customer ID(10位数字,如 1234567890 或 123-456-7890)')
|
|
11
|
+
.option('--name <name>', '账号名称(可选)')
|
|
12
|
+
.option('--force', '强制覆盖已有配置')
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
try {
|
|
15
|
+
// 检查是否已经配置过账号
|
|
16
|
+
const existingCustomerId = config.get('customerId');
|
|
17
|
+
if (existingCustomerId && !options.force) {
|
|
18
|
+
console.log(JSON.stringify({
|
|
19
|
+
success: false,
|
|
20
|
+
error: 'already_linked',
|
|
21
|
+
message: '已存在账号配置',
|
|
22
|
+
existing_customer_id: existingCustomerId,
|
|
23
|
+
hint: '使用 --force 覆盖,或运行 google-ads config reset'
|
|
24
|
+
}, null, 2));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
// 验证 Customer ID 格式
|
|
28
|
+
const cleanId = options.customerId.replace(/-/g, '');
|
|
29
|
+
if (!/^\d{10}$/.test(cleanId)) {
|
|
30
|
+
console.log(JSON.stringify({
|
|
31
|
+
success: false,
|
|
32
|
+
error: 'invalid_customer_id',
|
|
33
|
+
message: '无效的 Customer ID 格式',
|
|
34
|
+
provided: options.customerId,
|
|
35
|
+
hint: '请提供 10 位数字(如 1234567890 或 123-456-7890)'
|
|
36
|
+
}, null, 2));
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
// 保存到 config
|
|
40
|
+
config.set('customerId', cleanId);
|
|
41
|
+
if (options.name) {
|
|
42
|
+
config.set('accountName', options.name);
|
|
43
|
+
}
|
|
44
|
+
config.set('linkedAt', new Date().toISOString());
|
|
45
|
+
const formattedCustomerId = cleanId.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
|
|
46
|
+
console.log(JSON.stringify({
|
|
47
|
+
success: true,
|
|
48
|
+
customer_id: formattedCustomerId,
|
|
49
|
+
account_name: options.name || null,
|
|
50
|
+
next_step: '运行 google-ads account check 验证连接'
|
|
51
|
+
}, null, 2));
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
handleError(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../../src/commands/account/link.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,2CAA2C,CAAC;KACxD,cAAc,CAAC,oBAAoB,EAAE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Aa,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QAEjD,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,UAAU,CAAC,CAAC;QAEjF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;YACzB,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,mBAAmB;YAChC,YAAY,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;YAClC,SAAS,EAAE,kCAAkC;SAC9C,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAEf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,aAAa,SAyEtB,CAAC"}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Ad Create Command - 创建广告
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import ora from 'ora';
|
|
7
5
|
import { getApiClient } from '../../lib/api-client.js';
|
|
8
6
|
import { handleError } from '../../utils/errors.js';
|
|
9
7
|
import { getCustomerId } from '../../utils/customer-id.js';
|
|
@@ -16,37 +14,50 @@ export const createCommand = new Command('create')
|
|
|
16
14
|
.option('--path1 <path>', '显示路径1')
|
|
17
15
|
.option('--path2 <path>', '显示路径2')
|
|
18
16
|
.option('--status <status>', '状态 (ENABLED, PAUSED)', 'PAUSED')
|
|
19
|
-
.option('--json', '以 JSON 格式输出')
|
|
20
17
|
.action(async (options) => {
|
|
21
|
-
const spinner = ora('创建广告...').start();
|
|
22
18
|
try {
|
|
23
19
|
const customerId = getCustomerId();
|
|
24
20
|
const client = getApiClient();
|
|
25
|
-
// 解析标题和描述
|
|
26
21
|
const headlines = options.headlines.split(',').map((h) => h.trim());
|
|
27
22
|
const descriptions = options.descriptions.split(',').map((d) => d.trim());
|
|
28
23
|
// 验证数量
|
|
29
|
-
if (headlines.length < 3) {
|
|
30
|
-
|
|
24
|
+
if (headlines.length < 3 || headlines.length > 15) {
|
|
25
|
+
console.log(JSON.stringify({
|
|
26
|
+
error: 'invalid_headlines',
|
|
27
|
+
message: '标题数量必须在 3-15 个之间',
|
|
28
|
+
provided: headlines.length
|
|
29
|
+
}, null, 2));
|
|
30
|
+
process.exit(1);
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error('最多 4 个描述');
|
|
32
|
+
if (descriptions.length < 2 || descriptions.length > 4) {
|
|
33
|
+
console.log(JSON.stringify({
|
|
34
|
+
error: 'invalid_descriptions',
|
|
35
|
+
message: '描述数量必须在 2-4 个之间',
|
|
36
|
+
provided: descriptions.length
|
|
37
|
+
}, null, 2));
|
|
38
|
+
process.exit(1);
|
|
40
39
|
}
|
|
41
40
|
// 验证长度
|
|
42
41
|
for (const headline of headlines) {
|
|
43
42
|
if (headline.length > 30) {
|
|
44
|
-
|
|
43
|
+
console.log(JSON.stringify({
|
|
44
|
+
error: 'headline_too_long',
|
|
45
|
+
message: `标题超过 30 字符限制`,
|
|
46
|
+
headline,
|
|
47
|
+
length: headline.length
|
|
48
|
+
}, null, 2));
|
|
49
|
+
process.exit(1);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
for (const desc of descriptions) {
|
|
48
53
|
if (desc.length > 90) {
|
|
49
|
-
|
|
54
|
+
console.log(JSON.stringify({
|
|
55
|
+
error: 'description_too_long',
|
|
56
|
+
message: `描述超过 90 字符限制`,
|
|
57
|
+
description: desc,
|
|
58
|
+
length: desc.length
|
|
59
|
+
}, null, 2));
|
|
60
|
+
process.exit(1);
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
const result = await client.createAd(customerId, {
|
|
@@ -58,19 +69,9 @@ export const createCommand = new Command('create')
|
|
|
58
69
|
path2: options.path2,
|
|
59
70
|
status: options.status,
|
|
60
71
|
});
|
|
61
|
-
|
|
62
|
-
if (options.json) {
|
|
63
|
-
console.log(JSON.stringify(result, null, 2));
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.log(chalk.green('\n✅ 响应式搜索广告已创建'));
|
|
67
|
-
console.log(chalk.gray(`标题数量: ${headlines.length}`));
|
|
68
|
-
console.log(chalk.gray(`描述数量: ${descriptions.length}`));
|
|
69
|
-
console.log(chalk.gray(`最终网址: ${options.finalUrl}\n`));
|
|
70
|
-
}
|
|
72
|
+
console.log(JSON.stringify(result, null, 2));
|
|
71
73
|
}
|
|
72
74
|
catch (error) {
|
|
73
|
-
spinner.fail('创建广告失败');
|
|
74
75
|
handleError(error);
|
|
75
76
|
}
|
|
76
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/commands/ad/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/commands/ad/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE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C;gBACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC/C,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,SAAS;YACT,YAAY;YACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/delete.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/delete.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,aAAa,SAetB,CAAC"}
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* Ad Delete Command - 删除广告
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import ora from 'ora';
|
|
7
|
-
import inquirer from 'inquirer';
|
|
8
5
|
import { getApiClient } from '../../lib/api-client.js';
|
|
9
6
|
import { handleError } from '../../utils/errors.js';
|
|
10
7
|
import { getCustomerId } from '../../utils/customer-id.js';
|
|
@@ -12,36 +9,12 @@ export const deleteCommand = new Command('delete')
|
|
|
12
9
|
.description('删除广告')
|
|
13
10
|
.requiredOption('--ad-group-id <id>', '广告组 ID')
|
|
14
11
|
.requiredOption('--ad-id <id>', '广告 ID')
|
|
15
|
-
.option('-y, --yes', '跳过确认')
|
|
16
|
-
.option('--json', '以 JSON 格式输出')
|
|
17
12
|
.action(async (options) => {
|
|
18
13
|
try {
|
|
19
14
|
const customerId = getCustomerId();
|
|
20
|
-
// 确认删除
|
|
21
|
-
if (!options.yes) {
|
|
22
|
-
const { confirm } = await inquirer.prompt([
|
|
23
|
-
{
|
|
24
|
-
type: 'confirm',
|
|
25
|
-
name: 'confirm',
|
|
26
|
-
message: `确定要删除广告 ${options.adId} 吗?`,
|
|
27
|
-
default: false,
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
if (!confirm) {
|
|
31
|
-
console.log(chalk.yellow('已取消'));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const spinner = ora('删除广告...').start();
|
|
36
15
|
const client = getApiClient();
|
|
37
16
|
const result = await client.deleteAd(customerId, options.adGroupId, options.adId);
|
|
38
|
-
|
|
39
|
-
if (options.json) {
|
|
40
|
-
console.log(JSON.stringify(result, null, 2));
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
console.log(chalk.green(`\n✅ 广告 ${options.adId} 已删除`));
|
|
44
|
-
}
|
|
17
|
+
console.log(JSON.stringify(result, null, 2));
|
|
45
18
|
}
|
|
46
19
|
catch (error) {
|
|
47
20
|
handleError(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/commands/ad/delete.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/commands/ad/delete.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,MAAM,CAAC;KACnB,cAAc,CAAC,oBAAoB,EAAE,QAAQ,CAAC;KAC9C,cAAc,CAAC,cAAc,EAAE,OAAO,CAAC;KACvC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAE9B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAElF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/info.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/info.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,WAAW,SAoBpB,CAAC"}
|
package/dist/commands/ad/info.js
CHANGED
|
@@ -2,86 +2,23 @@
|
|
|
2
2
|
* Ad Info Command - 查看广告详情
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import ora from 'ora';
|
|
7
5
|
import { getApiClient } from '../../lib/api-client.js';
|
|
8
6
|
import { handleError } from '../../utils/errors.js';
|
|
9
|
-
import { warn } from '../../utils/logger.js';
|
|
10
7
|
import { getCustomerId } from '../../utils/customer-id.js';
|
|
11
8
|
export const infoCommand = new Command('info')
|
|
12
9
|
.description('查看广告详情')
|
|
13
10
|
.requiredOption('--ad-group-id <id>', '广告组 ID')
|
|
14
11
|
.argument('<ad-id>', '广告 ID')
|
|
15
|
-
.option('--json', '以 JSON 格式输出')
|
|
16
12
|
.action(async (adId, options) => {
|
|
17
13
|
try {
|
|
18
14
|
const customerId = getCustomerId();
|
|
19
15
|
const client = getApiClient();
|
|
20
|
-
const spinner = ora('正在获取广告信息...').start();
|
|
21
16
|
const result = await client.getAd(customerId, options.adGroupId, adId);
|
|
22
|
-
spinner.stop();
|
|
23
17
|
if (!result) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (options.json) {
|
|
28
|
-
console.log(JSON.stringify(result, null, 2));
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
const adGroupAd = result.ad_group_ad;
|
|
32
|
-
const ad = adGroupAd?.ad;
|
|
33
|
-
const adGroup = result.ad_group;
|
|
34
|
-
const campaign = result.campaign;
|
|
35
|
-
const metrics = result.metrics;
|
|
36
|
-
const statusMap = {
|
|
37
|
-
2: 'ENABLED',
|
|
38
|
-
3: 'PAUSED',
|
|
39
|
-
4: 'REMOVED',
|
|
40
|
-
};
|
|
41
|
-
const typeMap = {
|
|
42
|
-
3: 'TEXT_AD',
|
|
43
|
-
4: 'IMAGE_AD',
|
|
44
|
-
5: 'CALL_AD',
|
|
45
|
-
6: 'RESPONSIVE_DISPLAY_AD',
|
|
46
|
-
15: 'RESPONSIVE_SEARCH_AD',
|
|
47
|
-
};
|
|
48
|
-
console.log(chalk.cyan.bold('\n广告详情\n'));
|
|
49
|
-
console.log(chalk.gray('广告 ID:'), chalk.white(ad?.id));
|
|
50
|
-
console.log(chalk.gray('类型:'), chalk.white(typeMap[ad?.type] || ad?.type));
|
|
51
|
-
console.log(chalk.gray('状态:'), chalk.white(statusMap[adGroupAd?.status] || adGroupAd?.status));
|
|
52
|
-
console.log(chalk.gray('广告组:'), chalk.white(adGroup?.name));
|
|
53
|
-
console.log(chalk.gray('广告系列:'), chalk.white(campaign?.name));
|
|
54
|
-
// 响应式搜索广告内容
|
|
55
|
-
if (ad?.responsive_search_ad) {
|
|
56
|
-
const rsa = ad.responsive_search_ad;
|
|
57
|
-
console.log(chalk.cyan.bold('\n广告内容 (响应式搜索广告)\n'));
|
|
58
|
-
if (rsa.headlines?.length > 0) {
|
|
59
|
-
console.log(chalk.gray('标题:'));
|
|
60
|
-
rsa.headlines.forEach((h, i) => {
|
|
61
|
-
console.log(chalk.white(` ${i + 1}. ${h.text}`));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (rsa.descriptions?.length > 0) {
|
|
65
|
-
console.log(chalk.gray('描述:'));
|
|
66
|
-
rsa.descriptions.forEach((d, i) => {
|
|
67
|
-
console.log(chalk.white(` ${i + 1}. ${d.text}`));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (rsa.path1)
|
|
71
|
-
console.log(chalk.gray('路径 1:'), chalk.white(rsa.path1));
|
|
72
|
-
if (rsa.path2)
|
|
73
|
-
console.log(chalk.gray('路径 2:'), chalk.white(rsa.path2));
|
|
74
|
-
}
|
|
75
|
-
if (ad?.final_urls?.length > 0) {
|
|
76
|
-
console.log(chalk.gray('落地页:'), chalk.white(ad.final_urls[0]));
|
|
77
|
-
}
|
|
78
|
-
console.log(chalk.cyan.bold('\n效果数据\n'));
|
|
79
|
-
console.log(chalk.gray('展示量:'), chalk.white(metrics?.impressions || 0));
|
|
80
|
-
console.log(chalk.gray('点击量:'), chalk.white(metrics?.clicks || 0));
|
|
81
|
-
console.log(chalk.gray('费用:'), chalk.white(`$${((metrics?.cost_micros || 0) / 1000000).toFixed(2)}`));
|
|
82
|
-
console.log(chalk.gray('转化:'), chalk.white(metrics?.conversions || 0));
|
|
83
|
-
console.log();
|
|
18
|
+
console.log(JSON.stringify({ error: 'not_found', ad_id: adId }, null, 2));
|
|
19
|
+
process.exit(1);
|
|
84
20
|
}
|
|
21
|
+
console.log(JSON.stringify(result, null, 2));
|
|
85
22
|
}
|
|
86
23
|
catch (error) {
|
|
87
24
|
handleError(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../../src/commands/ad/info.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../../src/commands/ad/info.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,QAAQ,CAAC;KACrB,cAAc,CAAC,oBAAoB,EAAE,QAAQ,CAAC;KAC9C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;KAC5B,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAC9B,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAE9B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/list.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/ad/list.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,WAAW,SAsBpB,CAAC"}
|
package/dist/commands/ad/list.js
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
* Ad List Command - 列出广告
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import Table from 'cli-table3';
|
|
7
|
-
import ora from 'ora';
|
|
8
5
|
import { getApiClient } from '../../lib/api-client.js';
|
|
9
6
|
import { handleError } from '../../utils/errors.js';
|
|
10
|
-
import { warn } from '../../utils/logger.js';
|
|
11
7
|
import { getCustomerId } from '../../utils/customer-id.js';
|
|
12
8
|
export const listCommand = new Command('list')
|
|
13
9
|
.description('列出广告')
|
|
@@ -15,77 +11,17 @@ export const listCommand = new Command('list')
|
|
|
15
11
|
.option('--ad-group-id <id>', '按广告组过滤')
|
|
16
12
|
.option('--status <status>', '按状态过滤 (ENABLED/PAUSED/REMOVED)')
|
|
17
13
|
.option('--limit <number>', '限制返回数量', '100')
|
|
18
|
-
.option('--json', '以 JSON 格式输出')
|
|
19
14
|
.action(async (options) => {
|
|
20
15
|
try {
|
|
21
16
|
const customerId = getCustomerId();
|
|
22
17
|
const client = getApiClient();
|
|
23
|
-
const spinner = ora('正在获取广告列表...').start();
|
|
24
18
|
const ads = await client.listAds(customerId, {
|
|
25
19
|
campaignId: options.campaignId,
|
|
26
20
|
adGroupId: options.adGroupId,
|
|
27
21
|
status: options.status,
|
|
28
22
|
limit: parseInt(options.limit),
|
|
29
23
|
});
|
|
30
|
-
|
|
31
|
-
if (ads.length === 0) {
|
|
32
|
-
warn('未找到广告');
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (options.json) {
|
|
36
|
-
console.log(JSON.stringify(ads, null, 2));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const table = new Table({
|
|
40
|
-
head: [
|
|
41
|
-
chalk.cyan('广告 ID'),
|
|
42
|
-
chalk.cyan('类型'),
|
|
43
|
-
chalk.cyan('广告组'),
|
|
44
|
-
chalk.cyan('状态'),
|
|
45
|
-
chalk.cyan('标题预览'),
|
|
46
|
-
chalk.cyan('展示量'),
|
|
47
|
-
chalk.cyan('点击量'),
|
|
48
|
-
],
|
|
49
|
-
colWidths: [15, 12, 18, 10, 25, 12, 10],
|
|
50
|
-
});
|
|
51
|
-
ads.forEach((item) => {
|
|
52
|
-
const adGroupAd = item.ad_group_ad;
|
|
53
|
-
const ad = adGroupAd?.ad;
|
|
54
|
-
const adGroup = item.ad_group;
|
|
55
|
-
const metrics = item.metrics;
|
|
56
|
-
// 获取广告标题预览
|
|
57
|
-
let titlePreview = 'N/A';
|
|
58
|
-
if (ad?.responsive_search_ad?.headlines?.length > 0) {
|
|
59
|
-
titlePreview = ad.responsive_search_ad.headlines[0].text || 'N/A';
|
|
60
|
-
}
|
|
61
|
-
else if (ad?.expanded_text_ad?.headline_part1) {
|
|
62
|
-
titlePreview = ad.expanded_text_ad.headline_part1;
|
|
63
|
-
}
|
|
64
|
-
const statusMap = {
|
|
65
|
-
2: 'ENABLED',
|
|
66
|
-
3: 'PAUSED',
|
|
67
|
-
4: 'REMOVED',
|
|
68
|
-
};
|
|
69
|
-
const typeMap = {
|
|
70
|
-
3: 'TEXT',
|
|
71
|
-
4: 'IMAGE',
|
|
72
|
-
5: 'CALL',
|
|
73
|
-
6: 'RESP_DISPLAY',
|
|
74
|
-
15: 'RESP_SEARCH',
|
|
75
|
-
};
|
|
76
|
-
table.push([
|
|
77
|
-
ad?.id || 'N/A',
|
|
78
|
-
typeMap[ad?.type] || ad?.type || 'N/A',
|
|
79
|
-
(adGroup?.name || 'N/A').substring(0, 16),
|
|
80
|
-
statusMap[adGroupAd?.status] || adGroupAd?.status || 'N/A',
|
|
81
|
-
titlePreview.substring(0, 23),
|
|
82
|
-
metrics?.impressions || 0,
|
|
83
|
-
metrics?.clicks || 0,
|
|
84
|
-
]);
|
|
85
|
-
});
|
|
86
|
-
console.log('\n' + table.toString() + '\n');
|
|
87
|
-
console.log(chalk.gray(`共 ${ads.length} 个广告\n`));
|
|
88
|
-
}
|
|
24
|
+
console.log(JSON.stringify(ads, null, 2));
|
|
89
25
|
}
|
|
90
26
|
catch (error) {
|
|
91
27
|
handleError(error);
|