tencentads-cli 1.1.0 → 1.1.2

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 +22 -217
  2. package/package.json +31 -11
package/README.md CHANGED
@@ -2,244 +2,49 @@
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
8
+ npm install -g tencentads-cli
15
9
  ```
16
10
 
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
11
+ npm 会根据当前操作系统自动安装对应平台的子包(`optionalDependencies`):
25
12
 
26
- # 方式二:通过环境变量自定义存储路径
27
- export TENCENT_ADS_CONFIG_DIR=/your/custom/path
28
- ```
29
-
30
- 查看当前鉴权状态:
31
-
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 模式
24
+ ### `tencentads`(当前版本,Go 二进制)
41
25
 
42
26
  ```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}}'
48
-
49
- # 带查询参数
50
- tencentads-cli api '{"method":"GET","path":"/v3.0/campaigns/get","account_id":"123456","params":{"page":1,"page_size":10}}'
51
- ```
52
-
53
- ### Flag 模式
54
-
55
- ```bash
56
- # GET 请求
57
- tencentads-cli api --method GET --path /v3.0/adgroups/get --account-id 123456
58
-
59
- # POST 请求
60
- tencentads-cli api --method POST --path /v3.0/adgroups/add --account-id 123456 --body '{"campaign_id":100}'
61
-
62
- # 带查询参数
63
- tencentads-cli api --method GET --path /v3.0/campaigns/get --account-id 123456 --params '{"page":1,"page_size":10}'
64
- ```
65
-
66
- ### 查看帮助
67
-
68
- ```bash
69
- tencentads-cli help
70
- ```
71
-
72
- ## SDK 使用
73
-
74
- ### callApi — 高级调用函数
75
-
76
- 自动加载本地凭证,返回结构化结果:
77
-
78
- ```typescript
79
- import { callApi } from 'tencentads-cli';
80
-
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
- });
87
-
88
- if (result.success) {
89
- console.log(result.data);
90
- } else {
91
- console.error(result.error.message);
92
- }
93
- ```
94
-
95
- ### TencentAdsClient — HTTP 客户端
27
+ # 登录鉴权
28
+ tencentads auth login
96
29
 
97
- 支持自定义鉴权、超时和重试策略:
30
+ # 查看鉴权状态
31
+ tencentads auth status
98
32
 
99
- ```typescript
100
- import { TencentAdsClient, ENDPOINTS } from 'tencentads-cli';
33
+ # 退出登录
34
+ tencentads auth logout
101
35
 
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' });
116
-
117
- // POST
118
- const resp = await client.post('/v3.0/adgroups/add', { campaign_id: 100 });
119
- ```
120
-
121
- ### TencentAdsAuth — 凭证管理
122
-
123
- ```typescript
124
- import { TencentAdsAuth } from 'tencentads-cli';
125
-
126
- const auth = new TencentAdsAuth();
127
-
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();
138
- ```
139
-
140
- ### 枚举工具
141
-
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';
153
-
154
- // 枚举名 → 数值
155
- resolveEnum('MARKETING_GOAL', 'MARKETING_GOAL_PRODUCT_SALES'); // => 2
156
-
157
- // 数值 → 枚举名
158
- resolveEnumKey('MARKETING_GOAL', 2); // => 'MARKETING_GOAL_PRODUCT_SALES'
159
-
160
- // 自动推导 product_type
161
- deriveProductType('MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT');
162
-
163
- // 智能展开定向字段(支持中文简写)
164
- resolveTargetingFields({
165
- os: 'ANDROID_10+',
166
- device_price: '2500以上',
167
- education: '本科',
168
- });
36
+ # 查看帮助
37
+ tencentads help
169
38
  ```
170
39
 
171
- **可用枚举:**
172
-
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
- ## 构建
194
-
195
- ```bash
196
- cd tools/tencent-ads-cli
197
- npm install
198
- npm run build # tsc 编译 → dist/
199
- ```
200
-
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. **验证发布结果**
40
+ ### `tencentads-cli`(旧版,不再升级)
233
41
 
234
- ```bash
235
- npm info tencentads-cli version
236
- ```
42
+ `tencentads-cli` 为早期 Node.js 版本,保留以兼容现有集成,不再接受新功能更新。
237
43
 
238
- > **注意**:发布后,使用 `release-skills.sh --cli-version <新版本>` 可以将 skills 仓库中的 `tencentads-cli` 依赖版本锁定到最新发布的版本。
239
44
 
240
45
  ## 环境要求
241
46
 
242
- - Node.js >= 20.0.0
47
+ - Node.js >= 18.0.0
243
48
 
244
49
  ## License
245
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencentads-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "通用腾讯广告 API CLI 工具 — 封装鉴权与 API 调用",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -11,10 +11,19 @@
11
11
  "api",
12
12
  "advertising"
13
13
  ],
14
+ "type": "module",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
14
17
  "bin": {
15
18
  "tencentads": "./bin/tencentads.js",
16
19
  "tencentads-cli": "./dist/bin.js"
17
20
  },
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
25
+ }
26
+ },
18
27
  "files": [
19
28
  "bin/",
20
29
  "dist/",
@@ -22,18 +31,29 @@
22
31
  "README.md"
23
32
  ],
24
33
  "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"
34
+ "tencentads-darwin-x64": "1.1.2",
35
+ "tencentads-darwin-arm64": "1.1.2",
36
+ "tencentads-linux-x64": "1.1.2",
37
+ "tencentads-linux-arm64": "1.1.2",
38
+ "tencentads-windows-amd64": "1.1.2",
39
+ "tencentads-windows-arm64": "1.1.2"
31
40
  },
32
41
  "scripts": {
33
- "publish:npm": "bash ../scripts/publish-cli-go.sh --version 1.1.0 --registry https://registry.npmjs.org",
34
- "publish:beta": "bash ../scripts/publish-cli-go.sh --version 1.1.0 --tag beta --registry https://registry.npmjs.org",
35
- "publish:npm:token": "bash ../scripts/publish-cli-go.sh --version 1.1.0 --token $NPM_TOKEN --registry https://registry.npmjs.org",
36
- "publish:beta:token": "bash ../scripts/publish-cli-go.sh --version 1.1.0 --tag beta --token $NPM_TOKEN --registry https://registry.npmjs.org"
42
+ "build": "tsc",
43
+ "build:obfuscate": "tsc && node scripts/obfuscate.mjs",
44
+ "check": "tsc --noEmit",
45
+ "clean": "rm -rf dist",
46
+ "dev": "tsc --watch",
47
+ "prepublishOnly": "npm run clean && npm run build:obfuscate",
48
+ "publish:npm": "bash ../scripts/publish-cli-go.sh --version 1.1.1 --registry https://registry.npmjs.org",
49
+ "publish:beta": "bash ../scripts/publish-cli-go.sh --version 1.1.1 --tag beta --registry https://registry.npmjs.org",
50
+ "publish:npm:token": "bash ../scripts/publish-cli-go.sh --version 1.1.1 --token $NPM_TOKEN --registry https://registry.npmjs.org",
51
+ "publish:beta:token": "bash ../scripts/publish-cli-go.sh --version 1.1.1 --tag beta --token $NPM_TOKEN --registry https://registry.npmjs.org"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^20.11.0",
55
+ "javascript-obfuscator": "^4.1.1",
56
+ "typescript": "^5.3.0"
37
57
  },
38
58
  "engines": {
39
59
  "node": ">=18.0.0"