lxns-rhythm-api 0.1.9 → 0.1.11

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # lxns-rhythm-api
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/lxns-rhythm-api.svg)](https://www.npmjs.com/package/lxns-rhythm-api)
4
+
3
5
  一个面向 [落雪咖啡屋查分器](https://maimai.lxns.net/) 的 TypeScript SDK,当前支持 `maimai` 与 `chunithm`。
4
6
 
5
7
  ## 特性
@@ -72,6 +74,45 @@ const jacket = await client.maimai.getAsset("jacket", 114);
72
74
  const icon = await client.chunithm.getAsset("icon", 1);
73
75
  ```
74
76
 
77
+ ## OAuth 流程
78
+
79
+ ```ts
80
+ import { LxnsOAuthClient } from "lxns-rhythm-api";
81
+
82
+ const client = new LxnsOAuthClient({
83
+ clientId: "<your-client-id>",
84
+ redirectURI: "https://example.com/callback",
85
+ clientSecret: "<your-client-secret>", // PKCE 可不传
86
+ });
87
+
88
+ // 1) 生成授权链接,跳转给用户
89
+ const authorizeURL = client.createAuthorizeURL({
90
+ scope: ["read_user_profile", "read_player"],
91
+ state: "nonce", // 可选
92
+ codeChallenge: "<code-challenge>", // PKCE 可选
93
+ codeChallengeMethod: "S256",
94
+ });
95
+
96
+ // 2) 回调拿到 code 后换 token
97
+ const token = await client.exchangeCodeForToken({
98
+ code: "<auth-code>",
99
+ codeVerifier: "<code-verifier>", // PKCE 模式传这个
100
+ });
101
+
102
+ // 3) 用 access_token 创建授权态客户端
103
+ const authorized = client.createAuthorizedClient(token.access_token);
104
+
105
+ // 4) 调用 OAuth 用户接口和 personal 接口
106
+ const profile = await authorized.user.getProfile();
107
+ const maimaiPlayer = await authorized.maimai.getPlayer();
108
+ const chunithmPlayer = await authorized.chunithm.getPlayer();
109
+
110
+ // 5) 刷新 token
111
+ const nextToken = await client.refreshAccessToken({
112
+ refreshToken: token.refresh_token,
113
+ });
114
+ ```
115
+
75
116
  ## 错误处理
76
117
 
77
118
  SDK 会将 API 错误统一抛为 `LxnsApiError`。
@@ -112,6 +153,7 @@ try {
112
153
  ```ts
113
154
  import {
114
155
  LxnsApiClient,
156
+ LxnsOAuthClient,
115
157
  LxnsApiError,
116
158
  isLxnsApiError,
117
159
  MaimaiModels,
@@ -123,6 +165,8 @@ import {
123
165
 
124
166
  - [Lxns maimai API](https://maimai.lxns.net/docs/api/maimai)
125
167
  - [Lxns chunithm API](https://maimai.lxns.net/docs/api/chunithm)
168
+ - [Lxns OAuth API](https://maimai.lxns.net/docs/api/oauth)
169
+ - [Lxns OAuth 接入指南](https://maimai.lxns.net/docs/oauth-guide)
126
170
 
127
171
  ## 构建与测试
128
172
 
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };