tencentads-cli 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/README.md +57 -193
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -2,244 +2,108 @@
2
2
 
3
3
  通用腾讯广告 API CLI 工具 — 封装鉴权与 API 调用。
4
4
 
5
- 零运行时依赖,同时提供 **CLI 命令行** 和 **Node.js SDK** 两种使用方式。
6
-
7
5
  ## 安装
8
6
 
9
7
  ```bash
10
- # 全局安装(CLI 工具)
11
- npm install -g tencentads-cli@1.0.0
12
-
13
- # 项目依赖(SDK)
14
- npm install tencentads-cli@1.0.0
15
- ```
16
-
17
- ## 配置鉴权
18
-
19
- 在使用之前,需要保存 API Key 到本地凭证文件 `~/.tencent-ads/credentials.json`:
20
-
21
- ```bash
22
- # 方式一:手动创建
23
- mkdir -p ~/.tencent-ads
24
- echo '{"apiKey":"YOUR_API_KEY"}' > ~/.tencent-ads/credentials.json
25
-
26
- # 方式二:通过环境变量自定义存储路径
27
- export TENCENT_ADS_CONFIG_DIR=/your/custom/path
8
+ npm install -g tencentads-cli
28
9
  ```
29
10
 
30
- 查看当前鉴权状态:
11
+ npm 会根据当前操作系统自动安装对应平台的子包(`optionalDependencies`):
31
12
 
32
- ```bash
33
- tencentads-cli auth status
34
- ```
13
+ | 子包 | 平台 |
14
+ |------|------|
15
+ | `tencentads-darwin-x64` | macOS Intel |
16
+ | `tencentads-darwin-arm64` | macOS Apple Silicon |
17
+ | `tencentads-linux-x64` | Linux x64 |
18
+ | `tencentads-linux-arm64` | Linux ARM64 |
19
+ | `tencentads-windows-amd64` | Windows x64 |
20
+ | `tencentads-windows-arm64` | Windows ARM64 |
35
21
 
36
22
  ## CLI 使用
37
23
 
38
- > 全局安装后可用的命令为 `tencentads-cli`(对应 `package.json` 的 `bin` 字段)。
39
-
40
- ### JSON 模式
41
-
42
24
  ```bash
43
- # GET 请求
44
- tencentads-cli api '{"method":"GET","path":"/v3.0/adgroups/get","account_id":"123456"}'
45
-
46
- # POST 请求
47
- tencentads-cli api '{"method":"POST","path":"/v3.0/adgroups/add","account_id":"123456","body":{"campaign_id":100}}'
25
+ # 登录鉴权
26
+ tencentads auth login
48
27
 
49
- # 带查询参数
50
- tencentads-cli api '{"method":"GET","path":"/v3.0/campaigns/get","account_id":"123456","params":{"page":1,"page_size":10}}'
51
- ```
28
+ # 查看鉴权状态
29
+ tencentads auth status
52
30
 
53
- ### Flag 模式
31
+ # 退出登录
32
+ tencentads auth logout
54
33
 
55
- ```bash
56
- # GET 请求
57
- tencentads-cli api --method GET --path /v3.0/adgroups/get --account-id 123456
34
+ # API 调用(JSON 模式)
35
+ tencentads api '{"method":"GET","path":"/v3.0/adgroups/get","account_id":123456}'
58
36
 
59
- # POST 请求
60
- tencentads-cli api --method POST --path /v3.0/adgroups/add --account-id 123456 --body '{"campaign_id":100}'
37
+ # API 调用(Flag 模式)
38
+ tencentads api --method GET --path /v3.0/adgroups/get --account-id 123456
61
39
 
62
- # 带查询参数
63
- tencentads-cli api --method GET --path /v3.0/campaigns/get --account-id 123456 --params '{"page":1,"page_size":10}'
40
+ # 查看帮助
41
+ tencentads help
64
42
  ```
65
43
 
66
- ### 查看帮助
67
-
68
- ```bash
69
- tencentads-cli help
70
- ```
44
+ ## 发布流程
71
45
 
72
- ## SDK 使用
46
+ > 源码位于 `marketing-legion/`,发布脚本位于本仓库 `scripts/publish-cli-go.sh`。
73
47
 
74
- ### callApi — 高级调用函数
48
+ ### 前置条件
75
49
 
76
- 自动加载本地凭证,返回结构化结果:
50
+ 在 [npmjs.com → Access Tokens](https://www.npmjs.com/settings/~/tokens) 生成一个 **Granular Access Token**,对 `tencentads-*` 包授予 Read and Write 权限。
77
51
 
78
- ```typescript
79
- import { callApi } from 'tencentads-cli';
52
+ ### 完整发布步骤
80
53
 
81
- const result = await callApi({
82
- method: 'GET',
83
- path: '/v3.0/adgroups/get',
84
- accountId: '123456',
85
- params: { page: 1, page_size: 10 },
86
- });
54
+ **1. 更新版本号**
87
55
 
88
- if (result.success) {
89
- console.log(result.data);
90
- } else {
91
- console.error(result.error.message);
92
- }
56
+ ```bash
57
+ # 修改 tencentads/VERSION
58
+ echo "1.x.x" > /path/to/tencentads/VERSION
93
59
  ```
94
60
 
95
- ### TencentAdsClient HTTP 客户端
96
-
97
- 支持自定义鉴权、超时和重试策略:
98
-
99
- ```typescript
100
- import { TencentAdsClient, ENDPOINTS } from 'tencentads-cli';
101
-
102
- const client = new TencentAdsClient({
103
- auth: {
104
- applyAuth(headers) {
105
- headers.set('X-MKT-API-Key', 'YOUR_API_KEY');
106
- headers.set('Host', 'api.e.qq.com');
107
- },
108
- },
109
- baseUrl: ENDPOINTS.MARKETING_API,
110
- timeout: 30000,
111
- retry: { maxRetries: 3, baseDelay: 1000 },
112
- });
113
-
114
- // GET
115
- const data = await client.get('/v3.0/campaigns/get', { account_id: '123456' });
61
+ **2. 编译 Go 二进制(全平台)**
116
62
 
117
- // POST
118
- const resp = await client.post('/v3.0/adgroups/add', { campaign_id: 100 });
63
+ ```bash
64
+ cd /path/to/tencentads
65
+ bash build.sh --mode=release
119
66
  ```
120
67
 
121
- ### TencentAdsAuth 凭证管理
122
-
123
- ```typescript
124
- import { TencentAdsAuth } from 'tencentads-cli';
125
-
126
- const auth = new TencentAdsAuth();
68
+ **3. 打包 npm 子包**
127
69
 
128
- // 保存 API Key
129
- auth.saveApiKey('your-api-key');
130
-
131
- // 读取凭证
132
- const cred = auth.read();
133
- // => { apiKey: 'your-api-key', updatedAt: '2025-01-01T00:00:00.000Z' }
134
-
135
- // 查看鉴权状态
136
- const status = auth.getStatus(); // 'active' | 'not_configured'
137
- const info = auth.getInfo();
70
+ ```bash
71
+ cd /path/to/marketing-legion
72
+ node scripts/build-cli-go.mjs # 默认 multi 模式,输出到 dist/tencentads-skills/tencentads-cli-npmjs/packages/
138
73
  ```
139
74
 
140
- ### 枚举工具
75
+ **4. 同步到发布仓库**
141
76
 
142
- 内置腾讯广告 API 常用枚举及转换工具:
143
-
144
- ```typescript
145
- import {
146
- resolveEnum,
147
- resolveEnumKey,
148
- deriveProductType,
149
- resolveTargetingFields,
150
- MARKETING_GOAL,
151
- MARKETING_CARRIER_TYPE,
152
- } from 'tencentads-cli';
77
+ ```bash
78
+ bash release-skills.sh --sync
79
+ ```
153
80
 
154
- // 枚举名 → 数值
155
- resolveEnum('MARKETING_GOAL', 'MARKETING_GOAL_PRODUCT_SALES'); // => 2
81
+ **5. 发布到 npm**
156
82
 
157
- // 数值 → 枚举名
158
- resolveEnumKey('MARKETING_GOAL', 2); // => 'MARKETING_GOAL_PRODUCT_SALES'
83
+ ```bash
84
+ cd dist/tencentads-skills-repo
159
85
 
160
- // 自动推导 product_type
161
- deriveProductType('MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT');
86
+ # 使用 Access Token(推荐)
87
+ bash scripts/publish-cli-go.sh --version 1.x.x --token <NPM_TOKEN>
162
88
 
163
- // 智能展开定向字段(支持中文简写)
164
- resolveTargetingFields({
165
- os: 'ANDROID_10+',
166
- device_price: '2500以上',
167
- education: '本科',
168
- });
89
+ # 或通过环境变量
90
+ export NPM_TOKEN=<your-token>
91
+ bash scripts/publish-cli-go.sh --version 1.x.x
169
92
  ```
170
93
 
171
- **可用枚举:**
94
+ 发布脚本会依次发布 6 个平台子包 + 主包 `tencentads-cli`,共 7 个包。
172
95
 
173
- | 枚举 | 说明 |
174
- |------|------|
175
- | `MARKETING_GOAL` | 营销目标(拉新、促销、品牌等) |
176
- | `MARKETING_SUB_GOAL` | 营销子目标 |
177
- | `MARKETING_CARRIER_TYPE` | 推广载体类型(Android/iOS/微信等) |
178
- | `MARKETING_TARGET_TYPE` | 推广业务类型 |
179
- | `SITE_SET` | 广告投放版位 |
180
- | `SMART_DELIVERY_PLATFORM` | 智能投放平台 |
181
- | `EXPLORATION_STRATEGY` | 探索策略 |
182
- | `CONFIGURED_STATUS` | 配置状态 |
183
-
184
- ## 特性
185
-
186
- - **零运行时依赖** — 仅使用 Node.js 内置模块
187
- - **TypeScript** — 完整类型定义,开箱即用
188
- - **自动重试** — 指数退避策略,默认重试 3 次
189
- - **鉴权管理** — API Key 凭证自动加载
190
- - **枚举映射** — 双向转换 + 中文定向字段智能展开
191
- - **ESM 模块** — 原生 ES Module 支持
192
-
193
- ## 构建
96
+ **6. 验证发布结果**
194
97
 
195
98
  ```bash
196
- cd tools/tencent-ads-cli
197
- npm install
198
- npm run build # tsc 编译 → dist/
99
+ for pkg in tencentads-cli tencentads-darwin-x64 tencentads-darwin-arm64 tencentads-linux-x64 tencentads-linux-arm64 tencentads-windows-amd64 tencentads-windows-arm64; do
100
+ echo -n "$pkg: "; npm view $pkg version
101
+ done
199
102
  ```
200
103
 
201
- 构建产物在 `dist/` 目录,包含 `.js` 和 `.d.ts` 文件。
202
-
203
- ## 发布到 npm
204
-
205
- 1. **登录 npm**
206
-
207
- ```bash
208
- npm login
209
- ```
210
-
211
- 2. **确认当前已发布版本**
212
-
213
- ```bash
214
- npm info tencentads-cli
215
- ```
216
-
217
- 3. **更新版本号**
218
-
219
- ```bash
220
- npm version patch # 修复:0.1.0 → 0.1.1
221
- npm version minor # 新功能:0.1.0 → 0.2.0
222
- npm version major # 破坏性变更:0.1.0 → 1.0.0
223
- ```
224
-
225
- 4. **构建并发布**
226
-
227
- ```bash
228
- npm run build
229
- npm publish
230
- ```
231
-
232
- 5. **验证发布结果**
233
-
234
- ```bash
235
- npm info tencentads-cli version
236
- ```
237
-
238
- > **注意**:发布后,使用 `release-skills.sh --cli-version <新版本>` 可以将 skills 仓库中的 `tencentads-cli` 依赖版本锁定到最新发布的版本。
239
-
240
104
  ## 环境要求
241
105
 
242
- - Node.js >= 20.0.0
106
+ - Node.js >= 18.0.0
243
107
 
244
108
  ## License
245
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencentads-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "通用腾讯广告 API CLI 工具 — 封装鉴权与 API 调用",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -22,12 +22,12 @@
22
22
  "README.md"
23
23
  ],
24
24
  "optionalDependencies": {
25
- "tencentads-darwin-x64": "1.1.0",
26
- "tencentads-darwin-arm64": "1.1.0",
27
- "tencentads-linux-x64": "1.1.0",
28
- "tencentads-linux-arm64": "1.1.0",
29
- "tencentads-windows-amd64": "1.1.0",
30
- "tencentads-windows-arm64": "1.1.0"
25
+ "tencentads-darwin-x64": "1.1.1",
26
+ "tencentads-darwin-arm64": "1.1.1",
27
+ "tencentads-linux-x64": "1.1.1",
28
+ "tencentads-linux-arm64": "1.1.1",
29
+ "tencentads-windows-amd64": "1.1.1",
30
+ "tencentads-windows-arm64": "1.1.1"
31
31
  },
32
32
  "scripts": {
33
33
  "publish:npm": "bash ../scripts/publish-cli-go.sh --version 1.1.0 --registry https://registry.npmjs.org",