lxns-rhythm-api 0.1.4 → 0.1.8
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/README.md +85 -53
- package/dist/index.d.ts +430 -89
- package/dist/index.js +451 -132
- package/package.json +18 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 amatsuka
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# lxns-rhythm-api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个面向 [落雪咖啡屋查分器](https://maimai.lxns.net/) 的 TypeScript SDK,当前支持 `maimai` 与 `chunithm`。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 基于 `ky` 的轻量 HTTP 客户端。
|
|
8
|
+
- 统一的 `public / dev / personal` 命名空间。
|
|
9
|
+
- 完善的类型支持,根据是否传入 token 自动推断可用 API 类型。
|
|
10
|
+
- 统一错误类型:`LxnsApiError`。
|
|
8
11
|
|
|
9
12
|
## 安装
|
|
10
13
|
|
|
@@ -24,73 +27,102 @@ yarn add lxns-rhythm-api
|
|
|
24
27
|
```ts
|
|
25
28
|
import { LxnsApiClient } from "lxns-rhythm-api";
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
const client = new LxnsApiClient();
|
|
29
|
-
const song = await client.maimai.public.getSong(114);
|
|
30
|
-
console.log(song.standard?.master);
|
|
31
|
-
|
|
32
|
-
// 开发者 API:传入 devAccessToken 后可用 maimai.dev
|
|
33
|
-
const devClient = new LxnsApiClient({
|
|
30
|
+
const client = new LxnsApiClient({
|
|
34
31
|
devAccessToken: "<your-dev-token>",
|
|
35
|
-
});
|
|
36
|
-
const player = await devClient.maimai.dev.getPlayerByQQ(1507524536);
|
|
37
|
-
console.log(player);
|
|
38
|
-
|
|
39
|
-
// 个人 API:传入 personalAccessToken 后可用 maimai.personal
|
|
40
|
-
const personalClient = new LxnsApiClient({
|
|
41
32
|
personalAccessToken: "<your-personal-token>",
|
|
42
33
|
});
|
|
43
|
-
const me = await personalClient.maimai.personal.getPlayer();
|
|
44
|
-
console.log(me);
|
|
45
|
-
```
|
|
46
34
|
|
|
47
|
-
|
|
35
|
+
// maimai public
|
|
36
|
+
const maimaiSong = await client.maimai.public.getSong(114);
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
// maimai dev
|
|
39
|
+
const maimaiPlayer = await client.maimai.dev.getPlayerByQQ(1234567890);
|
|
40
|
+
|
|
41
|
+
// chunithm public
|
|
42
|
+
const chunithmSong = await client.chunithm.public.getSong(1);
|
|
43
|
+
|
|
44
|
+
// chunithm personal
|
|
45
|
+
const me = await client.chunithm.personal.getPlayer();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 配置
|
|
50
49
|
|
|
51
50
|
```ts
|
|
52
|
-
new LxnsApiClient(
|
|
51
|
+
new LxnsApiClient({
|
|
53
52
|
personalAccessToken?: string;
|
|
54
53
|
devAccessToken?: string;
|
|
55
|
-
baseURL?: string; //
|
|
54
|
+
baseURL?: string; // 默认: https://maimai.lxns.net/api/v0/
|
|
56
55
|
});
|
|
57
56
|
```
|
|
58
57
|
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- SDK 会在 `maimai.personal` 命名空间下启用个人接口。
|
|
65
|
-
- 认证头:`X-User-Token: <personalAccessToken>`。
|
|
66
|
-
- 基础路径:`<baseURL>/user/maimai/`。
|
|
67
|
-
- `public` 始终可用:
|
|
68
|
-
- 基础路径:`<baseURL>/maimai/`。
|
|
58
|
+
- `devAccessToken`:启用 `*.dev` 命名空间。
|
|
59
|
+
- `personalAccessToken`:启用 `*.personal` 命名空间。
|
|
60
|
+
- `baseURL`:默认 `https://maimai.lxns.net/api/v0/`。
|
|
61
|
+
|
|
62
|
+
## 资源接口
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
两个游戏命名空间都提供:
|
|
71
65
|
|
|
72
|
-
|
|
66
|
+
- `getAsset(type, id): Promise<Uint8Array>`
|
|
73
67
|
|
|
74
|
-
|
|
75
|
-
- [x] 支持 Maimai API
|
|
68
|
+
示例:
|
|
76
69
|
|
|
77
|
-
|
|
70
|
+
```ts
|
|
71
|
+
const jacket = await client.maimai.getAsset("jacket", 114);
|
|
72
|
+
const icon = await client.chunithm.getAsset("icon", 1);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 错误处理
|
|
76
|
+
|
|
77
|
+
SDK 会将 API 错误统一抛为 `LxnsApiError`。
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import {
|
|
81
|
+
LxnsApiError,
|
|
82
|
+
isAuthError,
|
|
83
|
+
isNotFoundError,
|
|
84
|
+
isRateLimitError,
|
|
85
|
+
isServerError,
|
|
86
|
+
} from "lxns-rhythm-api";
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
await client.maimai.dev.getPlayer(1234567890);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof LxnsApiError) {
|
|
92
|
+
console.error(error.code, error.status, error.message);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (isNotFoundError(error)) {
|
|
96
|
+
// 404
|
|
97
|
+
}
|
|
98
|
+
if (isAuthError(error)) {
|
|
99
|
+
// 401 / 403
|
|
100
|
+
}
|
|
101
|
+
if (isRateLimitError(error)) {
|
|
102
|
+
// 429
|
|
103
|
+
}
|
|
104
|
+
if (isServerError(error)) {
|
|
105
|
+
// >= 500
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 导出
|
|
78
111
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
```ts
|
|
113
|
+
import {
|
|
114
|
+
LxnsApiClient,
|
|
115
|
+
LxnsApiError,
|
|
116
|
+
isLxnsApiError,
|
|
117
|
+
MaimaiModels,
|
|
118
|
+
ChunithmModels,
|
|
119
|
+
} from "lxns-rhythm-api";
|
|
120
|
+
```
|
|
88
121
|
|
|
89
|
-
|
|
122
|
+
## 相关文档
|
|
90
123
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
- `src/apis/maimai/personal.ts`
|
|
124
|
+
- [Lxns maimai API](https://maimai.lxns.net/docs/api/maimai)
|
|
125
|
+
- [Lxns chunithm API](https://maimai.lxns.net/docs/api/chunithm)
|
|
94
126
|
|
|
95
127
|
## 构建与测试
|
|
96
128
|
|
|
@@ -99,6 +131,6 @@ pnpm run build
|
|
|
99
131
|
pnpm run test
|
|
100
132
|
```
|
|
101
133
|
|
|
102
|
-
##
|
|
134
|
+
## License
|
|
103
135
|
|
|
104
136
|
MIT
|