lxns-rhythm-api 0.1.3 → 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 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
- 一个用于访问 Lxns API 的轻量 TypeScript SDK
3
+ 一个面向 [落雪咖啡屋查分器](https://maimai.lxns.net/) TypeScript SDK,当前支持 `maimai` 与 `chunithm`。
4
4
 
5
- - 零运行时依赖(仅使用 `ky` 发起请求)。
6
- - 类型安全:根据传入的 token 自动在 `maimai` 命名空间上暴露 `public` / `dev` / `personal` 子 API。
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
- // token:仅可用 public API
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(options?: {
51
+ new LxnsApiClient({
53
52
  personalAccessToken?: string;
54
53
  devAccessToken?: string;
55
- baseURL?: string; // 默认:https://maimai.lxns.net/api/v0/
54
+ baseURL?: string; // 默认: https://maimai.lxns.net/api/v0/
56
55
  });
57
56
  ```
58
57
 
59
- - 当提供 `devAccessToken` 时:
60
- - SDK 会在 `maimai.dev` 命名空间下启用开发者接口。
61
- - 认证头:`Authorization: <devAccessToken>`。
62
- - 基础路径:`<baseURL>/maimai/`。
63
- - 当提供 `personalAccessToken` 时:
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
- > 注意:`baseURL` 默认值为 `https://maimai.lxns.net/api/v0/`。
64
+ 两个游戏命名空间都提供:
71
65
 
72
- ## TODO
66
+ - `getAsset(type, id): Promise<Uint8Array>`
73
67
 
74
- - [ ] 支持 Chuni API
75
- - [x] 支持 Maimai API
68
+ 示例:
76
69
 
77
- ## API 概览
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
- - `maimai.public`
80
- - `getSongList(version?: number, notes?: boolean)`
81
- - `getSong(id: number)`
82
- - `getAliasList()`
83
- - `getCollectionList(type, options)` 等
84
- - `maimai.dev`(需 `devAccessToken`)
85
- - `getPlayer(friendCode)`、`getPlayerByQQ(qq)`、`getBests(...)` 等
86
- - `maimai.personal`(需 `personalAccessToken`)
87
- - `getPlayer()`、`getScores()`、`postScores(scores)` 等
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
- - `src/apis/maimai/public.ts`
92
- - `src/apis/maimai/dev.ts`
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