@ccw-api/api 0.4.2 → 0.6.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/README.md +591 -367
- package/dist/esm/community-web/ccw-mall/ccw/product/fe/query.js +34 -0
- package/dist/esm/community-web/ccw-mall/ccw/product/fe/query.test.js +8 -0
- package/dist/esm/community-web/comment/page_by_topic.js +1 -1
- package/dist/esm/community-web/extensions/creation-like/detail.js +14 -0
- package/dist/esm/community-web/extensions/creation-like/detail.test.js +4 -0
- package/dist/esm/community-web/extensions/following/status.js +14 -0
- package/dist/esm/community-web/extensions/following/status.test.js +4 -0
- package/dist/esm/community-web/great_creation/update.js +13 -0
- package/dist/esm/community-web/great_creation/update.test.js +4 -0
- package/dist/esm/community-web/index.js +22 -0
- package/dist/esm/community-web/post/post.test.js +0 -1
- package/dist/esm/community-web/smart_contract/account.js +13 -0
- package/dist/esm/community-web/smart_contract/account.test.js +4 -0
- package/dist/esm/community-web/smart_contract/detail.js +13 -0
- package/dist/esm/community-web/smart_contract/detail.test.js +4 -0
- package/dist/esm/community-web/smart_contract/execute.js +17 -0
- package/dist/esm/community-web/smart_contract/execute.test.js +4 -0
- package/dist/esm/community-web/smart_contract/list.js +14 -0
- package/dist/esm/community-web/smart_contract/list.test.js +4 -0
- package/dist/esm/community-web/study-community/following/follow.js +13 -0
- package/dist/esm/community-web/study-community/following/follow.test.js +4 -0
- package/dist/esm/community-web/user_package/status.js +14 -0
- package/dist/esm/community-web/user_package/status.test.js +4 -0
- package/dist/esm/community-web/user_package/user_product.js +29 -0
- package/dist/esm/community-web/user_package/user_product.test.js +9 -0
- package/dist/esm/community-web-cloud-database/cloud_variable/detail/v2.js +16 -0
- package/dist/esm/community-web-cloud-database/cloud_variable/detail/v2.test.js +4 -0
- package/dist/esm/community-web-cloud-database/cloud_variable/save.js +29 -0
- package/dist/esm/community-web-cloud-database/cloud_variable/save.test.js +13 -0
- package/dist/esm/community-web-cloud-database/index.js +7 -0
- package/dist/esm/gandi-main/creation/leaderboards/{oid}/records.js +28 -0
- package/dist/esm/gandi-main/creation/leaderboards/{oid}/records.test.js +11 -0
- package/dist/esm/gandi-main/index.js +3 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/op-parent-api/captcha/check.js +15 -0
- package/dist/esm/op-parent-api/captcha/check.test.js +12 -0
- package/dist/esm/op-parent-api/captcha/create.js +13 -0
- package/dist/esm/op-parent-api/captcha/create.test.js +13 -0
- package/dist/esm/op-parent-api/index.js +6 -0
- package/dist/esm/sso/index.js +4 -0
- package/dist/esm/sso/web/auth/assistant/captcha/v2/create.js +17 -0
- package/dist/esm/sso/web/auth/assistant/captcha/v2/create.test.js +8 -0
- package/dist/esm/sso/web/auth/login-by-password.js +4 -3
- package/dist/esm/sso/web/auth/v3/login/by-phone.js +33 -0
- package/dist/esm/sso/web/auth/v3/login/by-phone.test.js +7 -0
- package/dist/node/community-web/ccw-mall/ccw/product/fe/query.js +38 -0
- package/dist/node/community-web/ccw-mall/ccw/product/fe/query.test.js +10 -0
- package/dist/node/community-web/comment/page_by_topic.js +1 -1
- package/dist/node/community-web/extensions/creation-like/detail.js +18 -0
- package/dist/node/community-web/extensions/creation-like/detail.test.js +6 -0
- package/dist/node/community-web/extensions/following/status.js +18 -0
- package/dist/node/community-web/extensions/following/status.test.js +6 -0
- package/dist/node/community-web/great_creation/update.js +17 -0
- package/dist/node/community-web/great_creation/update.test.js +6 -0
- package/dist/node/community-web/index.js +22 -0
- package/dist/node/community-web/post/post.test.js +0 -1
- package/dist/node/community-web/smart_contract/account.js +17 -0
- package/dist/node/community-web/smart_contract/account.test.js +6 -0
- package/dist/node/community-web/smart_contract/detail.js +17 -0
- package/dist/node/community-web/smart_contract/detail.test.js +6 -0
- package/dist/node/community-web/smart_contract/execute.js +21 -0
- package/dist/node/community-web/smart_contract/execute.test.js +6 -0
- package/dist/node/community-web/smart_contract/list.js +18 -0
- package/dist/node/community-web/smart_contract/list.test.js +6 -0
- package/dist/node/community-web/study-community/following/follow.js +17 -0
- package/dist/node/community-web/study-community/following/follow.test.js +6 -0
- package/dist/node/community-web/user_package/status.js +18 -0
- package/dist/node/community-web/user_package/status.test.js +6 -0
- package/dist/node/community-web/user_package/user_product.js +33 -0
- package/dist/node/community-web/user_package/user_product.test.js +11 -0
- package/dist/node/community-web-cloud-database/cloud_variable/detail/v2.js +20 -0
- package/dist/node/community-web-cloud-database/cloud_variable/detail/v2.test.js +6 -0
- package/dist/node/community-web-cloud-database/cloud_variable/save.js +34 -0
- package/dist/node/community-web-cloud-database/cloud_variable/save.test.js +15 -0
- package/dist/node/community-web-cloud-database/index.js +10 -0
- package/dist/node/gandi-main/creation/leaderboards/{oid}/records.js +33 -0
- package/dist/node/gandi-main/creation/leaderboards/{oid}/records.test.js +13 -0
- package/dist/node/gandi-main/index.js +3 -0
- package/dist/node/index.js +7 -1
- package/dist/node/op-parent-api/captcha/check.js +19 -0
- package/dist/node/op-parent-api/captcha/check.test.js +14 -0
- package/dist/node/op-parent-api/captcha/create.js +17 -0
- package/dist/node/op-parent-api/captcha/create.test.js +15 -0
- package/dist/node/op-parent-api/index.js +9 -0
- package/dist/node/sso/index.js +4 -0
- package/dist/node/sso/web/auth/assistant/captcha/v2/create.js +21 -0
- package/dist/node/sso/web/auth/assistant/captcha/v2/create.test.js +10 -0
- package/dist/node/sso/web/auth/login-by-password.js +4 -3
- package/dist/node/sso/web/auth/v3/login/by-phone.js +37 -0
- package/dist/node/sso/web/auth/v3/login/by-phone.test.js +9 -0
- package/dist/types/community-web/ccw-mall/ccw/product/fe/query.d.ts +54 -0
- package/dist/types/community-web/comment/page_by_topic.d.ts +1 -1
- package/dist/types/community-web/extensions/creation-like/detail.d.ts +18 -0
- package/dist/types/community-web/extensions/following/status.d.ts +19 -0
- package/dist/types/community-web/great_creation/update.d.ts +12 -0
- package/dist/types/community-web/index.d.ts +22 -0
- package/dist/types/community-web/post/detail.d.ts +1 -1
- package/dist/types/community-web/smart_contract/account.d.ts +13 -0
- package/dist/types/community-web/smart_contract/detail.d.ts +24 -0
- package/dist/types/community-web/smart_contract/execute.d.ts +25 -0
- package/dist/types/community-web/smart_contract/list.d.ts +49 -0
- package/dist/types/community-web/study-community/following/follow.d.ts +12 -0
- package/dist/types/community-web/user_package/status.d.ts +13 -0
- package/dist/types/community-web/user_package/user_product.d.ts +40 -0
- package/dist/types/community-web-cloud-database/cloud_variable/detail/v2.d.ts +17 -0
- package/dist/types/community-web-cloud-database/cloud_variable/save.d.ts +26 -0
- package/dist/types/community-web-cloud-database/index.d.ts +7 -0
- package/dist/types/gandi-main/creation/leaderboards/{oid}/records.d.ts +62 -0
- package/dist/types/gandi-main/index.d.ts +3 -0
- package/dist/types/index.d.ts +27 -1
- package/dist/types/op-parent-api/captcha/check.d.ts +21 -0
- package/dist/types/op-parent-api/captcha/create.d.ts +24 -0
- package/dist/types/op-parent-api/index.d.ts +6 -0
- package/dist/types/sso/index.d.ts +4 -0
- package/dist/types/sso/web/auth/assistant/captcha/v2/create.d.ts +34 -0
- package/dist/types/sso/web/auth/login-by-password.d.ts +2 -18
- package/dist/types/sso/web/auth/v3/login/by-phone.d.ts +38 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,367 +1,591 @@
|
|
|
1
|
-
# @ccw-api/api
|
|
2
|
-
|
|
3
|
-
CCW(创作社区)前后端接口 SDK,整合 `sso.ccw.site
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# 或
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
###
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
//
|
|
103
|
-
const
|
|
104
|
-
"
|
|
105
|
-
);
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
//
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
"
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
1
|
+
# @ccw-api/api
|
|
2
|
+
|
|
3
|
+
CCW(创作社区)前后端接口 SDK,整合 `sso.ccw.site`、`community-web.ccw.site`、
|
|
4
|
+
`gandi-main.ccw.site`、`bfs-web.ccw.site`、`community-web-cloud-database.ccw.site`、
|
|
5
|
+
`op-parent-api.xiguacity.cn`
|
|
6
|
+
六大服务的常用 API,提供完整的 TypeScript 类型与开箱即用的分页封装。
|
|
7
|
+
|
|
8
|
+
- 包格式:**ESM + CJS + .d.ts 三产物**同时产出
|
|
9
|
+
- 类型:所有请求 / 响应字段**强类型**,后端 key 固定约束(如 `MongoDBId`、`CNameOssUrl`、`UUID`)
|
|
10
|
+
- 分页:统一返回 `PagesRes<T>`(含 `totalNum` / `totalPages` / `sortField` 等元信息)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @ccw-api/api
|
|
18
|
+
# 或
|
|
19
|
+
pnpm add @ccw-api/api
|
|
20
|
+
# 或
|
|
21
|
+
yarn add @ccw-api/api
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> 唯一运行时依赖:`@ccw-api/axios`(内置鉴权 header 注入的 axios 封装)。
|
|
25
|
+
> `@ccw-api/api` 已将常用的 token 设置方法 **`setToken` 重新导出**,无需再单独依赖 axios 包。
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 快速开始
|
|
30
|
+
|
|
31
|
+
### 1. 初始化 Token(前置条件)
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { setToken } from "@ccw-api/api";
|
|
35
|
+
|
|
36
|
+
// 直接传入后端下发的 session token
|
|
37
|
+
setToken("abcdefgfoo");
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
所有 `@ccw-api/api` 的方法都会复用同一个 axios 单例,**调用 API 时无需再传入鉴权参数**。
|
|
41
|
+
|
|
42
|
+
### 2. 调用方式
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import {
|
|
46
|
+
sso,
|
|
47
|
+
communityWeb,
|
|
48
|
+
gandiMain,
|
|
49
|
+
bfsWeb,
|
|
50
|
+
communityWebCloudDatabase,
|
|
51
|
+
opParentApi,
|
|
52
|
+
} from "@ccw-api/api"; // ✅ 推荐:具名导入
|
|
53
|
+
// 或
|
|
54
|
+
import api from "@ccw-api/api";
|
|
55
|
+
// ✅ default 导入:api.sso / api.communityWeb / api.gandiMain / api.bfsWeb / api.communityWebCloudDatabase / api.opParentApi
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 模块一:SSO(sso.ccw.site)
|
|
61
|
+
|
|
62
|
+
账号认证相关,共 **5 个 API**:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const {
|
|
66
|
+
loginByPassword,
|
|
67
|
+
logout,
|
|
68
|
+
logoutBySession,
|
|
69
|
+
loginByPhone,
|
|
70
|
+
createSmsCaptcha,
|
|
71
|
+
} = sso;
|
|
72
|
+
|
|
73
|
+
// 账号密码登录
|
|
74
|
+
await loginByPassword("student_number", "xxxxx", {
|
|
75
|
+
device: "WEB",
|
|
76
|
+
browser: "Chrome",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// 登出当前 session
|
|
80
|
+
await logout();
|
|
81
|
+
|
|
82
|
+
// 强制某个 session 下线用于登陆设备管理
|
|
83
|
+
await logoutBySession(12345);
|
|
84
|
+
|
|
85
|
+
// 手机号+短信验证码登录(V3)
|
|
86
|
+
await loginByPhone("12345671145", "123456");
|
|
87
|
+
|
|
88
|
+
// 发送短信验证码(图形验证码可选)
|
|
89
|
+
await createSmsCaptcha("10011451919");
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 模块二:Community-Web(community-web.ccw.site)
|
|
95
|
+
|
|
96
|
+
覆盖作品 / 学生 / 星球 / 评论 / 通知 / 任务 / 表情 / 签到 / 云资产 / 学科专区 / 打赏 / 商城 / 商品 等业务领域,共 **106 个 API**。
|
|
97
|
+
下面是常用场景示例。
|
|
98
|
+
|
|
99
|
+
### 学生与作品
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
// 拉取学生档案
|
|
103
|
+
const profile = await communityWeb.getStudentProfile(
|
|
104
|
+
"63c2807d669fa967f17f5559",
|
|
105
|
+
);
|
|
106
|
+
// ^? StudentOverview(包含头像、简介、统计字段等)
|
|
107
|
+
|
|
108
|
+
// 我的创作分
|
|
109
|
+
const score = await communityWeb.getCreatorScore();
|
|
110
|
+
console.log(score.rank); // "ORDINARY" | "HACKER" | "ADVANCED"
|
|
111
|
+
|
|
112
|
+
// 分页拉取某学生的作品列表(含 totalNum / totalPages)
|
|
113
|
+
const creations = await communityWeb.getCreationsByStudent(
|
|
114
|
+
"63c2807d669fa967f17f5559",
|
|
115
|
+
{ page: 1, perPage: 12, sortField: "createdAt", sortType: "DESC" },
|
|
116
|
+
);
|
|
117
|
+
// creations: PagesRes<CreationSimple>
|
|
118
|
+
console.log(creations.totalNum, creations.data[0].title);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 星球(HashTag)与作品关联
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
// 查询某作品加入了哪些星球
|
|
125
|
+
const planets = await communityWeb.getPlanetsOfCreation(
|
|
126
|
+
"69929185f8d6142487fd4b2e",
|
|
127
|
+
);
|
|
128
|
+
// planets: HashTagCreationRelation[]
|
|
129
|
+
// planets[0].rank → "ORDINARY"(星球审核等级,与创作分 CreatorScore.rank 概念不同)
|
|
130
|
+
|
|
131
|
+
// 查询我加入某星球的作品分页(排除一个星球 + 过滤状态)
|
|
132
|
+
const mine = await communityWeb.getMyHashTagCreations(
|
|
133
|
+
"蔚蓝档案",
|
|
134
|
+
["PUBLISHED"],
|
|
135
|
+
{ page: 1, perPage: 8, sortField: "lastPassedAt", sortType: "DESC" },
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 通知(细化了 15 种 contentCategory)
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import type {
|
|
143
|
+
NotificationContent,
|
|
144
|
+
PostCommentContent,
|
|
145
|
+
FollowedContent,
|
|
146
|
+
} from "@ccw-api/api";
|
|
147
|
+
|
|
148
|
+
const page = await communityWeb.getNotificationPage("COMMENT_TO_ME", {
|
|
149
|
+
page: 1,
|
|
150
|
+
perPage: 20,
|
|
151
|
+
});
|
|
152
|
+
// page.data[].content 类型是 NotificationContent(判别联合)
|
|
153
|
+
// 用 contentCategory 做类型收窄:
|
|
154
|
+
|
|
155
|
+
for (const notif of page.data) {
|
|
156
|
+
switch (notif.contentCategory) {
|
|
157
|
+
case "POST_COMMENT": {
|
|
158
|
+
const c = notif.content as PostCommentContent;
|
|
159
|
+
console.log("评论者:", c.sender, "文章:", c.subject_outline);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case "FOLLOWED": {
|
|
163
|
+
const c = notif.content as FollowedContent;
|
|
164
|
+
console.log("新粉丝:", c.sender, c.sender_id);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "CREATION_SHARE":
|
|
168
|
+
case "SESSION_CREATED":
|
|
169
|
+
case "COMMUNITY_ACTIVITY":
|
|
170
|
+
case "POST_VISIBILITY_CHANGED":
|
|
171
|
+
// ……共 15 种,可按 IDE 补全逐项处理
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 拉取所有分组的未读统计
|
|
176
|
+
const stats = await communityWeb.getNotificationStats();
|
|
177
|
+
// stats.creationInteraction stats.commentToMe stats.followMe ……
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 任务、表情、金币、签到
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
// 我的任务列表
|
|
184
|
+
const tasks = await communityWeb.getMyTasks();
|
|
185
|
+
|
|
186
|
+
// 领取某个任务奖励
|
|
187
|
+
await communityWeb.acceptAward("61273ccf1730f4308e853f6a");
|
|
188
|
+
|
|
189
|
+
// 个人金币余额(充值 / 赠送 / 提现 三栏分离)
|
|
190
|
+
const coin = await communityWeb.getPersonalCurrencyAccount();
|
|
191
|
+
// coin: { internalCurrencyBalance, topUpCurrencyBalance, withdrawCurrencyBalance }
|
|
192
|
+
|
|
193
|
+
// 全部表情包 + 分页 + 分类
|
|
194
|
+
const [allEmoji, emojiPage, categories] = await Promise.all([
|
|
195
|
+
communityWeb.getAllEmojis(),
|
|
196
|
+
communityWeb.getEmojiPage("ENABLED", { page: 1, perPage: 50 }),
|
|
197
|
+
communityWeb.getEmojiCategoryList(),
|
|
198
|
+
]);
|
|
199
|
+
|
|
200
|
+
// 签到
|
|
201
|
+
await communityWeb.insertCheckInRecord(); // 今日打卡
|
|
202
|
+
const history = await communityWeb.getCheckInRecords();
|
|
203
|
+
|
|
204
|
+
// 作品 / 评论 打赏(需要token,消耗账户金币)
|
|
205
|
+
// 给某个作品打赏 1 金币(objectType 默认 "CREATION")
|
|
206
|
+
await communityWeb.donateTrade(1, "68ce4849811b737483bf7027", "CREATION");
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### 黑名单、封禁、禁言查询
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
const STUDENT = "63c2807d669fa967f17f5559";
|
|
213
|
+
|
|
214
|
+
// 轻量:是否拉黑(只返回 NOT_BLOCKED / BLOCKING)
|
|
215
|
+
const s = await communityWeb.getStudentBlockStatus(STUDENT);
|
|
216
|
+
|
|
217
|
+
// 详细:完整的 BlockActionRecord(拉黑动作记录,oid / createdAt / fromEntityId)
|
|
218
|
+
const detail = await communityWeb.getStudentBlockRecordDetail(STUDENT);
|
|
219
|
+
|
|
220
|
+
// 封禁详情(带泛型,locked=false 时其他字段全为 null)
|
|
221
|
+
const locked = await communityWeb.getLockedUserDetail<true>(
|
|
222
|
+
"642c0e8a59230841adf62406",
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// 禁言详情(studentNumber 是 244373873 这种数字字符串,null 表示未禁言)
|
|
226
|
+
const muted = await communityWeb.getMutedUserDetail("244373873");
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 智能金币合约
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
// 列出作品中的智能金币合约
|
|
233
|
+
const contracts = await communityWeb.getSmartContractList(
|
|
234
|
+
"6a3fa1ed159ed52f170c34d2",
|
|
235
|
+
);
|
|
236
|
+
// contracts: SmartCoinContract[]
|
|
237
|
+
|
|
238
|
+
// 查询合约账户余额
|
|
239
|
+
const account = await communityWeb.getSmartContractAccount(2022277721908162);
|
|
240
|
+
// account: { balance: 300 }
|
|
241
|
+
|
|
242
|
+
// 获取合约详情
|
|
243
|
+
const detail = await communityWeb.getSmartContractDetail(2022277721908162);
|
|
244
|
+
// detail: { accountId, bizId, rules, status, title, type, ... }
|
|
245
|
+
|
|
246
|
+
// 执行合约(领取试玩奖励 / 玩家投币)
|
|
247
|
+
const result = await communityWeb.executeSmartContract(
|
|
248
|
+
"6a3fa1ed159ed52f170c34d2", // bizId
|
|
249
|
+
2022277721908162, // contract id
|
|
250
|
+
378074, // rule id(award)
|
|
251
|
+
1, // bucks
|
|
252
|
+
);
|
|
253
|
+
// result: { success: true }
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 连接社区扩展
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
// 查询是否关注了创作者
|
|
260
|
+
const following = await communityWeb.getConnectCommunityFollowingStatus(
|
|
261
|
+
"6a3fa1ed159ed52f170c34d2", // 当前播放的作品 OID
|
|
262
|
+
"651e3f7310b0530e7f80fe7a", // 目标用户 OID
|
|
263
|
+
);
|
|
264
|
+
// following: { avatar, isFollowing: boolean, name, oid }
|
|
265
|
+
|
|
266
|
+
// 查询用户对作品的点赞交互状态
|
|
267
|
+
const like = await communityWeb.getConnectCommunityCreationLikeStatus(
|
|
268
|
+
"6a3fa1ed159ed52f170c34d2", // 当前播放的作品 OID
|
|
269
|
+
"6a3fa1ed159ed52f170c34d2", // 目标作品 OID
|
|
270
|
+
);
|
|
271
|
+
// like: { interactionStatus: boolean, oid, title }
|
|
272
|
+
|
|
273
|
+
// 关注创作者(需要 token)
|
|
274
|
+
await communityWeb.followCreator("651e3f7310b0530e7f80fe7a");
|
|
275
|
+
// → "FOLLOWED"
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### 商城商品 & 用户商店(头像框 / 表情 / 周边)
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
// ====== CCW 官方商城(商品分页查询) ======
|
|
282
|
+
// ProductCategory: 5=头像框, 7=周边商品, 10=表情
|
|
283
|
+
// ProductSource: "CCW_OFFICIAL"
|
|
284
|
+
|
|
285
|
+
// 查询周边商品分类的商城列表
|
|
286
|
+
const mallPage1 = await communityWeb.queryMallProductPage(
|
|
287
|
+
7, // productCategory: 周边商品
|
|
288
|
+
"CCW_OFFICIAL", // source
|
|
289
|
+
{ page: 1, perPage: 30, sortType: "DESC" },
|
|
290
|
+
);
|
|
291
|
+
// mallPage1: PagesRes<Product>
|
|
292
|
+
console.log(mallPage1.totalNum); // 293
|
|
293
|
+
console.log(mallPage1.data[0].name); // "运动好物|Star世达足球"
|
|
294
|
+
console.log(mallPage1.data[0].pointPrice); // 13299(金币价格)
|
|
295
|
+
console.log(mallPage1.data[0].stockNum); // 库存
|
|
296
|
+
|
|
297
|
+
// 查询头像框分类
|
|
298
|
+
const avatarFrames = await communityWeb.queryMallProductPage(
|
|
299
|
+
5, // productCategory: 头像框
|
|
300
|
+
"CCW_OFFICIAL",
|
|
301
|
+
{ page: 1, perPage: 8, sortType: "DESC" },
|
|
302
|
+
);
|
|
303
|
+
// avatarFrames.data[0].virtualValue → 头像框图片 URL
|
|
304
|
+
|
|
305
|
+
// 查询表情分类
|
|
306
|
+
const emojis = await communityWeb.queryMallProductPage(
|
|
307
|
+
10, // productCategory: 表情
|
|
308
|
+
"CCW_OFFICIAL",
|
|
309
|
+
);
|
|
310
|
+
// emojis.data[0].virtualValue → 表情包 ID(如 "13")
|
|
311
|
+
|
|
312
|
+
// ====== 用户已拥有的商品(需要 token) ======
|
|
313
|
+
// 拉取用户拥有的头像框列表
|
|
314
|
+
const myProducts = await communityWeb.getUserProductsPage(
|
|
315
|
+
5, // productCategory=5 头像框
|
|
316
|
+
{ page: 1, perPage: 8, sortType: "DESC", sortField: "" },
|
|
317
|
+
);
|
|
318
|
+
// myProducts: PagesRes<UserProduct>
|
|
319
|
+
// myProducts.data[0].status → 1=已佩戴, 0=未佩戴
|
|
320
|
+
|
|
321
|
+
// 切换商品佩戴状态(需要 token)
|
|
322
|
+
// 卸下头像框
|
|
323
|
+
await communityWeb.setUserProductStatus(false, 105847); // id, status=false
|
|
324
|
+
// 佩戴头像框
|
|
325
|
+
await communityWeb.setUserProductStatus(true, 105847);
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### 更换代表作
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
// 将指定作品设为个人代表作(需要 token,creationOid 必须是自己的作品)
|
|
332
|
+
await communityWeb.updateGreatCreation("68ce4849811b737483bf7027");
|
|
333
|
+
// → true 表示成功
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## 模块三:Gandi-Main(gandi-main.ccw.site)
|
|
339
|
+
|
|
340
|
+
公告、服务器时间与作品排行榜相关,共 **5 个 API**:
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
const {
|
|
344
|
+
getCurrentTimestamp,
|
|
345
|
+
getBulletinsPage,
|
|
346
|
+
getBulletinDetail,
|
|
347
|
+
submitLeaderboardRecord,
|
|
348
|
+
getLeaderboardRecords,
|
|
349
|
+
} = gandiMain;
|
|
350
|
+
|
|
351
|
+
// 服务端当前毫秒级时间戳(比客户端时间更可靠,可用于签到、排行榜等需要严格时间判断的场景)
|
|
352
|
+
const ts = await gandiMain.getCurrentTimestamp();
|
|
353
|
+
|
|
354
|
+
// 分页拉取公告列表(默认按 publishedAt 倒序,过滤已发布)
|
|
355
|
+
const bulletins = await gandiMain.getBulletinsPage("PUBLISHED", {
|
|
356
|
+
page: 1,
|
|
357
|
+
perPage: 10,
|
|
358
|
+
});
|
|
359
|
+
// bulletins.data[0].title / id / publishedAt
|
|
360
|
+
|
|
361
|
+
// 某条公告详情
|
|
362
|
+
const detail = await gandiMain.getBulletinDetail(123);
|
|
363
|
+
|
|
364
|
+
// ====== 作品排行榜 ======
|
|
365
|
+
|
|
366
|
+
// 获取排行榜记录(含榜单配置、当前用户排名、完整记录分页列表)
|
|
367
|
+
const board = await gandiMain.getLeaderboardRecords("65a2314daa96bd09b5beae5a");
|
|
368
|
+
console.log(board.title); // "总收益"
|
|
369
|
+
console.log(board.scoreUnit); // "币"
|
|
370
|
+
console.log(board.sortType); // "DESC"
|
|
371
|
+
console.log(board.leaderboardRecordTotalNum); // 834
|
|
372
|
+
console.log(board.curUserLeaderboardRecord?.ranking); // 139
|
|
373
|
+
console.log(board.leaderboardRecords[0].ranking); // 1
|
|
374
|
+
console.log(board.leaderboardRecords[0].score); // 排行榜最高分
|
|
375
|
+
console.log(board.leaderboardRecords[0].user?.nickname); // 榜首昵称
|
|
376
|
+
|
|
377
|
+
// 向排行榜提交分数记录(需要token:userOid必须对应当前登录用户)
|
|
378
|
+
await gandiMain.submitLeaderboardRecord(
|
|
379
|
+
"65a2314daa96bd09b5beae5a", // 排行榜oid
|
|
380
|
+
1500, // 分数
|
|
381
|
+
"6a42413ccc79993c436d04b6", // 用户oid
|
|
382
|
+
"", // 扩展信息(可选)
|
|
383
|
+
);
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## 模块四:BFS-Web(bfs-web.ccw.site)
|
|
389
|
+
|
|
390
|
+
用户扩展(extension)管理与扩展打赏,共 **2 个 API**:
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
const { getUserExtensions, donateExtension } = bfsWeb;
|
|
394
|
+
|
|
395
|
+
// 分页查询某用户上传/使用过的扩展列表(默认按 updatedAt 倒序)
|
|
396
|
+
const exts = await bfsWeb.getUserExtensions("63c2807d669fa967f17f5559", {
|
|
397
|
+
page: 1,
|
|
398
|
+
perPage: 20,
|
|
399
|
+
});
|
|
400
|
+
// exts: PagesRes<Extension>
|
|
401
|
+
|
|
402
|
+
// 给某个扩展打赏(需要token,消耗账户金币)
|
|
403
|
+
await bfsWeb.donateExtension(
|
|
404
|
+
"spineAnimation", // 扩展id(eid)
|
|
405
|
+
5, // 打赏金币数量
|
|
406
|
+
);
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## 模块五:Community-Web-Cloud-Database(community-web-cloud-database.ccw.site)
|
|
412
|
+
|
|
413
|
+
作品 / 用户的云变量(键值对存储)管理,共 **3 个 API**:
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
const {
|
|
417
|
+
saveProjectCloudVariable,
|
|
418
|
+
saveUserCloudVariable,
|
|
419
|
+
getCloudVariableDetailV2,
|
|
420
|
+
} = communityWebCloudDatabase;
|
|
421
|
+
|
|
422
|
+
// 保存作品云变量(无需token,主键是作品id;value结构任意,泛型自动推导返回)
|
|
423
|
+
const saved1 = await communityWebCloudDatabase.saveProjectCloudVariable(
|
|
424
|
+
"651c9a5142f8fb5ada70fad2",
|
|
425
|
+
"backup_65d31eaeb2ce1b785ebea87b_云时间",
|
|
426
|
+
{ v: "2025-07-05T17:40:53.057+0800" },
|
|
427
|
+
);
|
|
428
|
+
// saved1: { v: string }
|
|
429
|
+
// ^? 泛型自动匹配 value 传入的结构
|
|
430
|
+
|
|
431
|
+
// 保存用户云变量(需要token,主键内部自动为 userId 拼接 "-u" 后缀)
|
|
432
|
+
const saved2 = await communityWebCloudDatabase.saveUserCloudVariable(
|
|
433
|
+
"68dddc63d28b025cb53fae25",
|
|
434
|
+
"256053228",
|
|
435
|
+
{ key2: "0" },
|
|
436
|
+
);
|
|
437
|
+
// saved2: { key2: string }
|
|
438
|
+
|
|
439
|
+
// 查询云变量详情 V2
|
|
440
|
+
const detail = await communityWebCloudDatabase.getCloudVariableDetailV2(
|
|
441
|
+
"6a3fa1ed159ed52f170c34d2", // accessKey
|
|
442
|
+
"6a3fa1ed159ed52f170c34d2-u", // primaryKey
|
|
443
|
+
"244373873", // secondaryKey
|
|
444
|
+
["4576y!!2"], // filterKeys
|
|
445
|
+
);
|
|
446
|
+
// detail: { ... } // 具体结构取决于存储的数据
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
## 模块六:OP-Parent-API(op-parent-api.xiguacity.cn)
|
|
452
|
+
|
|
453
|
+
家长端图形验证码服务,共 **2 个 API**:
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
const { createCaptcha, checkCaptcha } = opParentApi;
|
|
457
|
+
|
|
458
|
+
// 创建图形验证码(滑块拼图)
|
|
459
|
+
const captcha = await opParentApi.createCaptcha("BLOCK_PUZZLE");
|
|
460
|
+
// captcha: { data: { bgImg: string, jigsawImg: string }, token: string }
|
|
461
|
+
|
|
462
|
+
// 校验图形验证码(拼图滑块坐标)
|
|
463
|
+
const result = await opParentApi.checkCaptcha(captcha.token, 120, 5);
|
|
464
|
+
// result: { captchaExpired: boolean, errorMsg: string | null, success: boolean }
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
### 通用工具型 API
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
// 生成短链
|
|
473
|
+
await communityWeb.createShortUrl("https://ccw.site/detail/xxx");
|
|
474
|
+
|
|
475
|
+
// 生成邀请码(api/v1/short_code/encode)
|
|
476
|
+
await communityWeb.encodeShortCode("hello world", 1, 6);
|
|
477
|
+
|
|
478
|
+
// 服务器时间
|
|
479
|
+
await communityWeb.getTime();
|
|
480
|
+
|
|
481
|
+
// 埋点事件上报
|
|
482
|
+
await communityWeb.sendEvent("creation_detail_view_6880873d2211fa69e41c9d19");
|
|
483
|
+
|
|
484
|
+
// 广告横幅
|
|
485
|
+
await communityWeb.getLeafletsItemList(1001);
|
|
486
|
+
|
|
487
|
+
// 学科专区(分页 / 按频道)
|
|
488
|
+
await communityWeb.getSubjectAreaPage({ page: 1, perPage: 20 });
|
|
489
|
+
await communityWeb.getSubjectAreaPageByChannel("PRIMARY");
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## 类型系统
|
|
495
|
+
|
|
496
|
+
### 原语类型(`types/api.d.ts`)
|
|
497
|
+
|
|
498
|
+
可直接从包顶层作为 `type` 导入:
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
import type {
|
|
502
|
+
MongoDBId, // 24 位 hex 字符串(ObjectId)
|
|
503
|
+
CNameOssUrl, // https://m.ccw.site/... 或 https://m.xiguacity.cn/... OSS URL
|
|
504
|
+
UUID, // `${string}-${string}-${string}-${string}-${string}` 类型体操
|
|
505
|
+
ApiResponse, // { code, msg, body: T } 后端统一响应壳(SDK 内部已拆)
|
|
506
|
+
} from "@ccw-api/api";
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### 领域命名空间
|
|
510
|
+
|
|
511
|
+
每个 `types/*.d.ts` 作为一个命名空间重新导出,**避免同名类型冲突**(典型如 `Student` vs `StudentOverview` vs `Account.Types.Student`):
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
import type {
|
|
515
|
+
Api, // 原语类型(MongoDBId / CNameOssUrl / UUID / ApiResponse ...)
|
|
516
|
+
UserData, // Student / StudentOverview / CreatorScore / UserCard ...
|
|
517
|
+
Creation, // Creation / HashTag / HashTagCreationRank / CreationRelease ...
|
|
518
|
+
Comment, // Comment / CommentStatus ...
|
|
519
|
+
Notification, // Notification / NotificationSenderInfo / NotificationGroup ...
|
|
520
|
+
NotificationContent, // 15 种通知 content 判别联合
|
|
521
|
+
Pages, // PageArgs / PagesRes
|
|
522
|
+
Session, // StudentSession / SessionArea
|
|
523
|
+
Account, // AccountTypes
|
|
524
|
+
Approval, // ApprovalTag
|
|
525
|
+
} from "@ccw-api/api";
|
|
526
|
+
|
|
527
|
+
type Score = UserData.CreatorScore["rank"]; // "ORDINARY" | "HACKER" | "ADVANCED"
|
|
528
|
+
type PlanetRank = Creation.HashTagCreationRank; // "ORDINARY"
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## 分页约定
|
|
534
|
+
|
|
535
|
+
所有分页 API 都遵循同一套形状(详见 `types/pages.d.ts` + `src/queryPages.ts`):
|
|
536
|
+
|
|
537
|
+
```ts
|
|
538
|
+
import type { PageArgs, PagesRes } from "@ccw-api/api";
|
|
539
|
+
|
|
540
|
+
// 入参 T extends string
|
|
541
|
+
// Partial<PageArgs<SortField|T>>,默认 { page:1, perPage:20, sortType:"DESC" }
|
|
542
|
+
// 出参 PagesRes<T> 完整结构:
|
|
543
|
+
const p: PagesRes<Creation.Creation> = {
|
|
544
|
+
data: [], // 当前页数据
|
|
545
|
+
page: 1,
|
|
546
|
+
perPage: 20,
|
|
547
|
+
offset: 0,
|
|
548
|
+
totalNum: 1234, // 总条数 —— 之前版本被截断,目前 SDK 已完整透出
|
|
549
|
+
totalPages: 62, // 总页数
|
|
550
|
+
sortField: "createdAt",
|
|
551
|
+
sortType: "DESC",
|
|
552
|
+
};
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## 开发 & 发布
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
# 三产物构建(node / esm / .d.ts)
|
|
561
|
+
npm run build
|
|
562
|
+
|
|
563
|
+
# 跑测试(Jest 30 + ts-jest,121 suites / 128 tests)
|
|
564
|
+
npm test
|
|
565
|
+
npm run test:dev # watch 模式
|
|
566
|
+
|
|
567
|
+
# 文档(TypeDoc,生成到 doc/ 或默认输出目录)
|
|
568
|
+
npm run doc
|
|
569
|
+
npm run doc:dev
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
`npm publish` 会自动触发 `prepublishOnly` → **build + test** 全跑一遍,失败会阻断发布。
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## 目录与规范
|
|
577
|
+
|
|
578
|
+
所有 API 文件严格遵循 `AGENT.md` 规范:
|
|
579
|
+
|
|
580
|
+
- **按域名分组**:`src/sso` / `src/community-web` / `src/gandi-main` / `src/bfs-web` / `src/community-web-cloud-database` / `src/op-parent-api`,内部子目录对应 URL 路径
|
|
581
|
+
- **单文件单接口**:文件名 `kebab-case`,对应 endpoint 最后一段
|
|
582
|
+
- **7 段式模板**(每个 API 文件内部固定顺序):
|
|
583
|
+
1. `import`
|
|
584
|
+
2. `export const url = "https://..."`(调试 & 测试直接引用)
|
|
585
|
+
3. `export type Req = { ... }`
|
|
586
|
+
4. `export type Res = { ... }`(响应体内部,不含 `ApiResponse` 外层)
|
|
587
|
+
5. 辅助类型
|
|
588
|
+
6. JSDoc(`@param` / `@returns`)
|
|
589
|
+
7. `export async function xxx(): Promise<Res>`
|
|
590
|
+
|
|
591
|
+
新增 API 时,**最后记得在对应服务的 `index.ts`(如 `src/community-web/index.ts`、`src/gandi-main/index.ts` 等)里 `import + 对象字面量聚合导出`**,否则外部访问不到。
|