@ikenxuan/amagi 6.5.0 → 7.0.0-beta.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/README.md +57 -36
- package/dist/default/index.cjs +84 -9638
- package/dist/default/index.d.ts +2 -28754
- package/dist/default/index.mjs +2 -9493
- package/dist/exports/axios.cjs +1 -1
- package/dist/exports/compat.cjs +267 -0
- package/dist/exports/compat.d.ts +1121 -0
- package/dist/exports/compat.mjs +168 -0
- package/dist/exports/express.cjs +1 -1
- package/dist/exports/signing.cjs +437 -0
- package/dist/exports/signing.d.ts +698 -0
- package/dist/exports/signing.mjs +380 -0
- package/dist/index-nCXqYNq0.d.ts +52366 -0
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-C0BPl7ul.cjs} +15 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/src-AA7Elfxn.mjs +56550 -0
- package/dist/src-BmVVZLDU.cjs +57029 -0
- package/dist/tokens-BFqSOfhx.mjs +1001 -0
- package/dist/tokens-DHKAuPVW.cjs +1294 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -13,41 +13,47 @@
|
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
<p align="center">
|
|
16
|
-
<a href="https://amagi
|
|
16
|
+
<a href="https://ikenxuan.github.io/amagi/docs/v7/usage">文档</a> ·
|
|
17
17
|
<a href="https://amagi.apifox.cn">API 参考</a> ·
|
|
18
18
|
<a href="https://github.com/ikenxuan/amagi/issues">反馈问题</a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
+
> **v7 处于 beta。** npm 的 `latest` 仍是 6.x 稳定线,装 v7 要带标签:
|
|
24
|
+
> `pnpm add @ikenxuan/amagi@beta`。从 v6 升级请看[迁移指南](https://ikenxuan.github.io/amagi/docs/v7/usage/migration-v7)。
|
|
25
|
+
|
|
23
26
|
`@ikenxuan/amagi` 是一个独立发布的多平台 Node.js 数据获取 SDK,同时也内置了 HTTP 服务器功能。它为应用提供稳定、类型安全且经过严格参数校验的统一数据接口。
|
|
24
27
|
|
|
25
28
|
## 特性
|
|
26
29
|
|
|
27
30
|
- **多平台支持**:深度封装抖音、B站、快手、小红书等平台的主流核心数据接口。
|
|
28
31
|
- **双模式调用**:既可以作为 Node.js SDK 在代码中直接调用,也可以一键启动本地 HTTP 服务供跨语言/跨进程使用。
|
|
29
|
-
-
|
|
30
|
-
- **参数校验**:底层基于 Zod
|
|
31
|
-
-
|
|
32
|
-
-
|
|
32
|
+
- **统一响应**:所有平台、所有调用返回同一个 `AmagiResult<T>` 判别联合 —— `success` 是唯一判别键,成功读 `data`、失败读 `error`,**顶层没有 `code`**(HTTP 状态在 `error.http.status`,平台原始码在 `error.platform.code`)。
|
|
33
|
+
- **参数校验**:底层基于 Zod,参数表由端点声明推导;校验失败返回失败信封,不抛异常。
|
|
34
|
+
- **事件与可观测**:每个实例自带一条事件总线(15 个事件),每次调用的 `meta` 带 `requestId`、耗时、重试与翻页的账本。
|
|
35
|
+
- **类型安全**:响应类型由真实响应样本派生,字段级精确;平台新增字段不算破坏性变更。
|
|
36
|
+
- **签名可验证**:抖音签名的解码与校验工具单独出一个入口 `@ikenxuan/amagi/signing`(纯函数,浏览器里也能跑),用来确认签名实现没有过期。
|
|
37
|
+
- **双模块输出**:同时支持 ESM 与 CJS。
|
|
33
38
|
|
|
34
39
|
## 安装
|
|
35
40
|
|
|
36
|
-
推荐使用 `pnpm
|
|
41
|
+
推荐使用 `pnpm`:
|
|
37
42
|
|
|
38
43
|
```bash
|
|
39
|
-
pnpm add @ikenxuan/amagi
|
|
44
|
+
pnpm add @ikenxuan/amagi@beta
|
|
40
45
|
```
|
|
41
46
|
|
|
42
47
|
<details>
|
|
43
|
-
<summary
|
|
48
|
+
<summary>其他包管理器 / 安装稳定版</summary>
|
|
44
49
|
|
|
45
50
|
```bash
|
|
46
|
-
#
|
|
47
|
-
npm install @ikenxuan/amagi
|
|
51
|
+
# 其他包管理器(同样是 v7 beta)
|
|
52
|
+
npm install @ikenxuan/amagi@beta
|
|
53
|
+
yarn add @ikenxuan/amagi@beta
|
|
48
54
|
|
|
49
|
-
#
|
|
50
|
-
|
|
55
|
+
# 稳定线(6.x)
|
|
56
|
+
pnpm add @ikenxuan/amagi
|
|
51
57
|
```
|
|
52
58
|
|
|
53
59
|
</details>
|
|
@@ -56,54 +62,69 @@ yarn add @ikenxuan/amagi
|
|
|
56
62
|
|
|
57
63
|
### 作为 SDK 调用
|
|
58
64
|
|
|
59
|
-
直接在 Node.js 环境中引入并初始化 Amagi:
|
|
60
|
-
|
|
61
65
|
```typescript
|
|
62
66
|
import amagi from '@ikenxuan/amagi'
|
|
63
67
|
|
|
64
|
-
// 1.
|
|
68
|
+
// 1. 初始化客户端并配置各平台的 Cookies
|
|
65
69
|
const client = amagi({
|
|
66
70
|
cookies: {
|
|
67
|
-
bilibili: 'SESSDATA=xxx;
|
|
68
|
-
douyin: 'ttwid
|
|
69
|
-
// xiaohongshu
|
|
70
|
-
// kuaishou: '...'
|
|
71
|
+
bilibili: 'SESSDATA=xxx; bili_jct=yyy',
|
|
72
|
+
douyin: 'ttwid=...'
|
|
73
|
+
// kuaishou / xiaohongshu 同理
|
|
71
74
|
}
|
|
72
75
|
})
|
|
73
76
|
|
|
74
|
-
// 2.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
// 2. 调用平台接口,按统一信封读结果
|
|
78
|
+
const video = await client.bilibili.fetcher.fetchVideoInfo({ bvid: 'BV1xx411c7mD' })
|
|
79
|
+
|
|
80
|
+
if (video.success) {
|
|
81
|
+
console.log(video.data) // 收窄后是端点声明里那个精确类型
|
|
82
|
+
} else {
|
|
83
|
+
console.error(video.error.kind, video.error.message) // 失败分支只有 error
|
|
80
84
|
}
|
|
85
|
+
```
|
|
81
86
|
|
|
82
|
-
|
|
87
|
+
不想建实例时用静态 fetcher,Cookie 按次传:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const video = await amagi.bilibiliFetcher.fetchVideoInfo({ bvid: 'BV1xx411c7mD' }, 'SESSDATA=xxx')
|
|
83
91
|
```
|
|
84
92
|
|
|
85
|
-
|
|
93
|
+
监听调用(实例总线,负载恒带 `meta`):
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
```typescript
|
|
96
|
+
client.on('api:success', (d) => {
|
|
97
|
+
console.log(`[${d.meta.platform}] ${d.meta.endpoint} 耗时 ${d.meta.durationMs}ms`)
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 启动 HTTP 服务
|
|
88
102
|
|
|
89
103
|
```typescript
|
|
90
104
|
import amagi from '@ikenxuan/amagi'
|
|
91
105
|
|
|
92
|
-
const client = amagi({
|
|
93
|
-
// 配置项...
|
|
94
|
-
})
|
|
106
|
+
const client = amagi({ cookies: { bilibili: 'SESSDATA=xxx' } })
|
|
95
107
|
|
|
96
|
-
// 一键启动 HTTP 服务器
|
|
97
108
|
client.startServer(4567)
|
|
98
|
-
|
|
109
|
+
|
|
110
|
+
// GET http://localhost:4567/api/bilibili/fetch_one_video?bvid=BV1xx411c7mD
|
|
111
|
+
// 路由一览与在线调试:https://amagi.apifox.cn
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 只想要签名工具
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { decodeUrl, diagnoseSalt } from '@ikenxuan/amagi/signing'
|
|
99
118
|
```
|
|
100
119
|
|
|
101
120
|
## 文档资源
|
|
102
121
|
|
|
103
122
|
更详细的接口说明和高级用法,请参阅在线文档:
|
|
104
123
|
|
|
105
|
-
- [完整文档](https://amagi
|
|
106
|
-
- [快速上手](https://
|
|
124
|
+
- [完整文档](https://ikenxuan.github.io/amagi/docs/v7/usage)
|
|
125
|
+
- [快速上手](https://ikenxuan.github.io/amagi/docs/v7/usage/getting-started)
|
|
126
|
+
- [v6 → v7 迁移指南](https://ikenxuan.github.io/amagi/docs/v7/usage/migration-v7)
|
|
127
|
+
- [开发与贡献文档](https://ikenxuan.github.io/amagi/docs/v7/dev)
|
|
107
128
|
- [Apifox 接口参考](https://amagi.apifox.cn)
|
|
108
129
|
|
|
109
130
|
## 参与贡献
|
|
@@ -113,7 +134,7 @@ client.startServer(4567)
|
|
|
113
134
|
如果你(作为下游开发者)需要封装其他未支持的接口或业务逻辑,你可以选择:
|
|
114
135
|
|
|
115
136
|
1. **自己 Fork 本项目**进行修改和定制。
|
|
116
|
-
2. 阅读 [开发与贡献文档](https://
|
|
137
|
+
2. 阅读 [开发与贡献文档](https://ikenxuan.github.io/amagi/docs/v7/dev) 后,向本项目提交 Pull Request 共同完善接口生态。
|
|
117
138
|
|
|
118
139
|
非常欢迎提交 Issue 或 Pull Request!
|
|
119
140
|
|