lxns-rhythm-api 0.1.0 → 0.1.2

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  - 零运行时依赖(仅使用 `ky` 发起请求)。
6
6
  - 类型安全:根据传入的 token 自动在 `maimai` 命名空间上暴露 `public` / `dev` / `personal` 子 API。
7
- - 现代构建(ESM/CJS/类型声明)。
7
+ - 现代构建
8
8
 
9
9
  ## 安装
10
10
 
@@ -44,12 +44,6 @@ const me = await personalClient.maimai.personal.getPlayer();
44
44
  console.log(me);
45
45
  ```
46
46
 
47
- CommonJS 引用:
48
-
49
- ```js
50
- const { LxnsApiClient } = require("lxns-sdk");
51
- ```
52
-
53
47
  ## 配置项
54
48
 
55
49
  构造函数签名:
package/dist/index.js CHANGED
@@ -1 +1,351 @@
1
- var h=Object.defineProperty;var x=(s,e)=>{for(var t in e)h(s,t,{get:e[t],enumerable:!0})};var b={};x(b,{LevelIndex:()=>f});var f=(r=>(r[r.BASIC=0]="BASIC",r[r.ADVANCED=1]="ADVANCED",r[r.EXPERT=2]="EXPERT",r[r.MASTER=3]="MASTER",r[r.RE_MASTER=4]="RE_MASTER",r))(f||{});import d from"ky";var S=["basic","advanced","expert","master","remaster"];function u(s){return s.reduce((e,t)=>(e[S[t.difficulty]]=t,e),{})}var o=class{id;title;artist;genre;version;bpm;difficulties;locked;disabled;rights;constructor(e){this.id=e.id,this.title=e.title,this.artist=e.artist,this.genre=e.genre,this.version=e.version,this.bpm=e.bpm,this.difficulties=e.difficulties,this.locked=e.locked??!1,this.disabled=e.disabled??!1,this.rights=e.rights}get standard(){return this.difficulties.standard.length===0?null:u(this.difficulties.standard)}get dx(){return this.difficulties.dx.length===0?null:u(this.difficulties.dx)}get utage(){return this.difficulties.utage?u(this.difficulties.utage):null}};var a=class{constructor(e){this.http=e}async getSongList(e,t){return this.http.get("song/list?",{searchParams:{version:e,notes:t}}).json()}async getSong(e){let t=await this.http.get(`song/${e}`).json();return new o(t)}async getAliasList(){return this.http.get("alias/list").json()}async getCollectionList(e,t){let n={trophy:"trophies",icon:"icons",plate:"plates",frame:"frames"};return this.http.get(`${e}/list`,{searchParams:{...t}}).json().then(i=>i[n[e]])}async getCollectionInfo(e,t,n){return this.http.get(`${e}/${t}`,{searchParams:{...n}}).json()}async getCollectionGenreList(e){return this.http.get("collection-genre/list",{searchParams:{...e}}).json()}async getCollectionGenreInfo(e,t){return this.http.get(`collection-genre/${e}`,{searchParams:{...t}}).json()}};var l=class{constructor(e){this.http=e}async postPlayer(e){return this.http.post("player",{json:e}).json()}async getPlayer(e){return this.http.get(`player/${e}`).json()}async getPlayerByQQ(e){return this.http.get(`player/qq/${e}`).json()}async getBests(e){return this.http.get(`player/${e}/bests`).json()}async getApBests(e){return this.http.get(`player/${e}/bests/ap`).json()}async getRecents(e){return this.http.get(`player/${e}/recents`).json()}async getAllBestScores(e){return this.http.get(`player/${e}/scores`).json()}async getHeatmap(e){return this.http.get(`player/${e}/heatmap`).json()}async getTrend(e){return this.http.get(`player/${e}/trend`).json()}async getScoreHistory(e){return this.http.get(`player/${e}/score/history`).json()}async getCollectionProgress(e,t,n){return this.http.get(`player/${e}/${t}/${n}`).json()}async postScores(e,t){let n={scores:t};return this.http.post(`player/${e}/scores`,{json:n}).json()}async postHtml(e,t){return this.http.post(`player/${e}/html`,{body:t,headers:{"content-type":"text/plain"}}).json()}};var c=class{constructor(e){this.http=e}async getPlayer(){return this.http.get("player").json()}async getScores(){return this.http.get("scores").json()}async postScores(e){let t={scores:e};return this.http.post("scores",{json:t}).json()}};var m=class{config={baseURL:"https://maimai.lxns.net/api/v0/"};maimai;constructor(e){this.config={baseURL:e?.baseURL??this.config.baseURL,personalAccessToken:e?.personalAccessToken,devAccessToken:e?.devAccessToken};let{baseURL:t,devAccessToken:n,personalAccessToken:i}=this.config,r=d.create({prefixUrl:new URL("maimai/",t)}),y=n?d.create({prefixUrl:new URL("maimai/",t),headers:{Authorization:n}}):void 0,g=i?d.create({prefixUrl:new URL("user/maimai/",t),headers:{"X-User-Token":i}}):void 0,p={public:new a(r)};y&&(p.dev=new l(y)),g&&(p.personal=new c(g)),this.maimai=p}};export{m as LxnsApiClient,b as MaimaiModels};
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/apis/maimai/models.ts
8
+ var models_exports = {};
9
+ __export(models_exports, {
10
+ LevelIndex: () => LevelIndex
11
+ });
12
+ var LevelIndex = /* @__PURE__ */ ((LevelIndex2) => {
13
+ LevelIndex2[LevelIndex2["BASIC"] = 0] = "BASIC";
14
+ LevelIndex2[LevelIndex2["ADVANCED"] = 1] = "ADVANCED";
15
+ LevelIndex2[LevelIndex2["EXPERT"] = 2] = "EXPERT";
16
+ LevelIndex2[LevelIndex2["MASTER"] = 3] = "MASTER";
17
+ LevelIndex2[LevelIndex2["RE_MASTER"] = 4] = "RE_MASTER";
18
+ return LevelIndex2;
19
+ })(LevelIndex || {});
20
+
21
+ // src/client/LxnsApiCLient.ts
22
+ import ky from "ky";
23
+
24
+ // src/apis/maimai/entities/Song.ts
25
+ var LevelArray = [
26
+ "basic",
27
+ "advanced",
28
+ "expert",
29
+ "master",
30
+ "remaster"
31
+ ];
32
+ function convertDifficulty(difficulty) {
33
+ return difficulty.reduce(
34
+ (acc, cur) => {
35
+ acc[LevelArray[cur.difficulty]] = cur;
36
+ return acc;
37
+ },
38
+ {}
39
+ );
40
+ }
41
+ var Song = class {
42
+ id;
43
+ title;
44
+ artist;
45
+ genre;
46
+ version;
47
+ bpm;
48
+ difficulties;
49
+ locked;
50
+ disabled;
51
+ rights;
52
+ constructor(song) {
53
+ this.id = song.id;
54
+ this.title = song.title;
55
+ this.artist = song.artist;
56
+ this.genre = song.genre;
57
+ this.version = song.version;
58
+ this.bpm = song.bpm;
59
+ this.difficulties = song.difficulties;
60
+ this.locked = song.locked ?? false;
61
+ this.disabled = song.disabled ?? false;
62
+ this.rights = song.rights;
63
+ }
64
+ get standard() {
65
+ if (this.difficulties.standard.length === 0) return null;
66
+ return convertDifficulty(this.difficulties.standard);
67
+ }
68
+ get dx() {
69
+ if (this.difficulties.dx.length === 0) return null;
70
+ return convertDifficulty(this.difficulties.dx);
71
+ }
72
+ get utage() {
73
+ if (!this.difficulties.utage) return null;
74
+ return convertDifficulty(this.difficulties.utage);
75
+ }
76
+ };
77
+
78
+ // src/apis/maimai/public.ts
79
+ var MaimaiPublicApi = class {
80
+ constructor(http) {
81
+ this.http = http;
82
+ }
83
+ /**
84
+ * 获取歌曲列表
85
+ * @param version 版本,不填写遵循api默认行为
86
+ * @param notes 是否包含谱面信息,不填写遵循api默认行为
87
+ * @returns 歌曲列表
88
+ */
89
+ async getSongList(version, notes) {
90
+ return this.http.get("song/list?", { searchParams: { version, notes } }).json();
91
+ }
92
+ /**
93
+ * 获取歌曲信息
94
+ * @param id 歌曲 ID
95
+ * @returns 歌曲信息
96
+ */
97
+ async getSong(id) {
98
+ const songInfo = await this.http.get(`song/${id}`).json();
99
+ return new Song(songInfo);
100
+ }
101
+ /**
102
+ * 获取歌曲别名列表
103
+ * @returns 歌曲别名列表
104
+ */
105
+ async getAliasList() {
106
+ return this.http.get("alias/list").json();
107
+ }
108
+ /**
109
+ * 获取收藏品列表
110
+ * @param collectionType trophy | icon | plate | frame
111
+ * @param options.version 版本,不填写遵循api默认行为
112
+ * @param options.required 是否包含曲目需求,默认值为 false
113
+ * @returns 收藏品列表
114
+ */
115
+ async getCollectionList(collectionType, options) {
116
+ const collectionMap = {
117
+ trophy: "trophies",
118
+ icon: "icons",
119
+ plate: "plates",
120
+ frame: "frames"
121
+ };
122
+ return this.http.get(`${collectionType}/list`, { searchParams: { ...options } }).json().then((res) => res[collectionMap[collectionType]]);
123
+ }
124
+ /**
125
+ * 获取收藏品信息
126
+ * @param collectionType trophy | icon | plate | frame
127
+ * @param id 收藏品 ID
128
+ * @param options.version 版本,不填写遵循api默认行为
129
+ * @returns 收藏品信息
130
+ */
131
+ async getCollectionInfo(collectionType, id, options) {
132
+ return this.http.get(`${collectionType}/${id}`, { searchParams: { ...options } }).json();
133
+ }
134
+ /**
135
+ * 获取收藏品分类列表
136
+ * @param options.version 版本,不填写遵循api默认行为
137
+ * @returns 收藏品分类列表
138
+ */
139
+ async getCollectionGenreList(options) {
140
+ return this.http.get("collection-genre/list", { searchParams: { ...options } }).json();
141
+ }
142
+ /**
143
+ * 获取收藏品分类信息
144
+ * @param id 收藏品分类 ID
145
+ * @param options.version 版本,不填写遵循api默认行为
146
+ * @returns 收藏品分类信息
147
+ */
148
+ async getCollectionGenreInfo(id, options) {
149
+ return this.http.get(`collection-genre/${id}`, { searchParams: { ...options } }).json();
150
+ }
151
+ };
152
+
153
+ // src/apis/maimai/dev.ts
154
+ var MaimaiDevApi = class {
155
+ constructor(http) {
156
+ this.http = http;
157
+ }
158
+ /**
159
+ * 创建或修改玩家信息
160
+ * @param body 玩家信息
161
+ * @returns 玩家信息
162
+ */
163
+ async postPlayer(body) {
164
+ return this.http.post("player", { json: body }).json();
165
+ }
166
+ /**
167
+ * 获取玩家信息(通过好友码)
168
+ * @param friendCode 好友码
169
+ * @returns 玩家信息
170
+ */
171
+ async getPlayer(friendCode) {
172
+ return this.http.get(`player/${friendCode}`).json();
173
+ }
174
+ /**
175
+ * 获取玩家信息(通过 QQ 号)
176
+ * @param qq QQ 号
177
+ * @returns 玩家信息
178
+ */
179
+ async getPlayerByQQ(qq) {
180
+ return this.http.get(`player/qq/${qq}`).json();
181
+ }
182
+ /**
183
+ * 获取 Best 50(standard 35 + dx 15)
184
+ * @param friendCode 好友码
185
+ * @returns Best 50
186
+ */
187
+ async getBests(friendCode) {
188
+ return this.http.get(`player/${friendCode}/bests`).json();
189
+ }
190
+ /**
191
+ * 获取 AP 50
192
+ * @param friendCode 好友码
193
+ * @returns AP 50
194
+ */
195
+ async getApBests(friendCode) {
196
+ return this.http.get(`player/${friendCode}/bests/ap`).json();
197
+ }
198
+ /**
199
+ * 获取 Recent 50(仅增量爬取可用)
200
+ * @param friendCode 好友码
201
+ * @returns Recent 50
202
+ */
203
+ async getRecents(friendCode) {
204
+ return this.http.get(`player/${friendCode}/recents`).json();
205
+ }
206
+ /**
207
+ * 获取玩家缓存的所有最佳成绩(简化)
208
+ * @param friendCode 好友码
209
+ * @returns BestScoreList
210
+ */
211
+ async getAllBestScores(friendCode) {
212
+ return this.http.get(`player/${friendCode}/scores`).json();
213
+ }
214
+ /**
215
+ * 成绩上传热力图(YYYY-MM-DD -> 数量)
216
+ * @param friendCode 好友码
217
+ * @returns Heatmap
218
+ */
219
+ async getHeatmap(friendCode) {
220
+ return this.http.get(`player/${friendCode}/heatmap`).json();
221
+ }
222
+ /**
223
+ * DX Rating 趋势
224
+ * @param friendCode 好友码
225
+ * @returns TrendList
226
+ */
227
+ async getTrend(friendCode) {
228
+ return this.http.get(`player/${friendCode}/trend`).json();
229
+ }
230
+ /**
231
+ * 成绩游玩历史记录(仅返回带有 play_time 的成绩)
232
+ * @param friendCode 好友码
233
+ * @returns 游玩历史记录
234
+ */
235
+ async getScoreHistory(friendCode) {
236
+ return this.http.get(`player/${friendCode}/score/history`).json();
237
+ }
238
+ /**
239
+ * 获取玩家收藏品进度
240
+ * @param friendCode 好友码
241
+ * @param collectionType 收藏品类型
242
+ * @param collectionId 收藏品 ID
243
+ * @returns 收藏品进度
244
+ */
245
+ async getCollectionProgress(friendCode, collectionType, collectionId) {
246
+ return this.http.get(`player/${friendCode}/${collectionType}/${collectionId}`).json();
247
+ }
248
+ /**
249
+ * 上传玩家成绩
250
+ * @param friendCode 好友码
251
+ * @param scores 成绩列表
252
+ * @returns 上传结果
253
+ */
254
+ async postScores(friendCode, scores) {
255
+ const body = { scores };
256
+ return this.http.post(`player/${friendCode}/scores`, { json: body }).json();
257
+ }
258
+ /**
259
+ * 通过 NET 的 HTML 源代码上传玩家数据
260
+ * @param friendCode 好友码
261
+ * @param htmlSource HTML 源代码
262
+ * @returns 上传结果
263
+ */
264
+ async postHtml(friendCode, htmlSource) {
265
+ return this.http.post(`player/${friendCode}/html`, {
266
+ body: htmlSource,
267
+ headers: { "content-type": "text/plain" }
268
+ }).json();
269
+ }
270
+ };
271
+
272
+ // src/apis/maimai/personal.ts
273
+ var MaimaiPersonalApi = class {
274
+ constructor(http) {
275
+ this.http = http;
276
+ }
277
+ /**
278
+ * 获取玩家信息
279
+ * GET /api/v0/user/maimai/player
280
+ * @returns PlayerInfo
281
+ */
282
+ async getPlayer() {
283
+ return this.http.get("player").json();
284
+ }
285
+ /**
286
+ * 获取玩家所有成绩
287
+ * GET /api/v0/user/maimai/player/scores
288
+ * @returns PlayerScores
289
+ */
290
+ async getScores() {
291
+ return this.http.get("scores").json();
292
+ }
293
+ /**
294
+ * 上传玩家成绩
295
+ * POST /api/v0/user/maimai/player/scores
296
+ * @param scores 成绩列表
297
+ * @returns 上传结果
298
+ */
299
+ async postScores(scores) {
300
+ const body = { scores };
301
+ return this.http.post("scores", { json: body }).json();
302
+ }
303
+ };
304
+
305
+ // src/client/LxnsApiCLient.ts
306
+ var LxnsApiClient = class {
307
+ config = {
308
+ baseURL: "https://maimai.lxns.net/api/v0/"
309
+ };
310
+ /**
311
+ * maimai API
312
+ */
313
+ maimai;
314
+ constructor(config) {
315
+ this.config = {
316
+ baseURL: config?.baseURL ?? this.config.baseURL,
317
+ personalAccessToken: config?.personalAccessToken,
318
+ devAccessToken: config?.devAccessToken
319
+ };
320
+ const { baseURL, devAccessToken, personalAccessToken } = this.config;
321
+ const httpPublic = ky.create({
322
+ prefixUrl: new URL("maimai/", baseURL)
323
+ });
324
+ const httpDev = devAccessToken ? ky.create({
325
+ prefixUrl: new URL("maimai/", baseURL),
326
+ headers: {
327
+ Authorization: devAccessToken
328
+ }
329
+ }) : void 0;
330
+ const httpPersonal = personalAccessToken ? ky.create({
331
+ prefixUrl: new URL("user/maimai/", baseURL),
332
+ headers: {
333
+ "X-User-Token": personalAccessToken
334
+ }
335
+ }) : void 0;
336
+ const maimai = {
337
+ public: new MaimaiPublicApi(httpPublic)
338
+ };
339
+ if (httpDev) {
340
+ maimai.dev = new MaimaiDevApi(httpDev);
341
+ }
342
+ if (httpPersonal) {
343
+ maimai.personal = new MaimaiPersonalApi(httpPersonal);
344
+ }
345
+ this.maimai = maimai;
346
+ }
347
+ };
348
+ export {
349
+ LxnsApiClient,
350
+ models_exports as MaimaiModels
351
+ };
package/package.json CHANGED
@@ -2,15 +2,14 @@
2
2
  "name": "lxns-rhythm-api",
3
3
  "description": "A simple SDK for lxns api.",
4
4
  "author": "amatsuka <amatsukamao@qq.com>",
5
- "version": "0.1.0",
5
+ "version": "0.1.2",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/wsyzxjn/lxns-rhythm-api.git"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
12
+ "import": "./dist/index.js"
14
13
  },
15
14
  "./package.json": "./package.json"
16
15
  },
@@ -21,7 +20,7 @@
21
20
  "LICENSE"
22
21
  ],
23
22
  "type": "module",
24
- "main": "./dist/index.cjs",
23
+ "main": "./dist/index.js",
25
24
  "module": "./dist/index.js",
26
25
  "types": "./dist/index.d.ts",
27
26
  "devDependencies": {
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";var v=Object.create;var o=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var t in e)o(r,t,{get:e[t],enumerable:!0})},x=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T(e))!R.call(r,i)&&i!==t&&o(r,i,{get:()=>e[i],enumerable:!(n=P(e,i))||n.enumerable});return r};var C=(r,e,t)=>(t=r!=null?v(j(r)):{},x(e||!r||!r.__esModule?o(t,"default",{value:r,enumerable:!0}):t,r)),A=r=>x(o({},"__esModule",{value:!0}),r);var L={};h(L,{LxnsApiClient:()=>d,MaimaiModels:()=>y});module.exports=A(L);var y={};h(y,{LevelIndex:()=>S});var S=(s=>(s[s.BASIC=0]="BASIC",s[s.ADVANCED=1]="ADVANCED",s[s.EXPERT=2]="EXPERT",s[s.MASTER=3]="MASTER",s[s.RE_MASTER=4]="RE_MASTER",s))(S||{});var u=C(require("ky"),1);var D=["basic","advanced","expert","master","remaster"];function g(r){return r.reduce((e,t)=>(e[D[t.difficulty]]=t,e),{})}var a=class{id;title;artist;genre;version;bpm;difficulties;locked;disabled;rights;constructor(e){this.id=e.id,this.title=e.title,this.artist=e.artist,this.genre=e.genre,this.version=e.version,this.bpm=e.bpm,this.difficulties=e.difficulties,this.locked=e.locked??!1,this.disabled=e.disabled??!1,this.rights=e.rights}get standard(){return this.difficulties.standard.length===0?null:g(this.difficulties.standard)}get dx(){return this.difficulties.dx.length===0?null:g(this.difficulties.dx)}get utage(){return this.difficulties.utage?g(this.difficulties.utage):null}};var l=class{constructor(e){this.http=e}async getSongList(e,t){return this.http.get("song/list?",{searchParams:{version:e,notes:t}}).json()}async getSong(e){let t=await this.http.get(`song/${e}`).json();return new a(t)}async getAliasList(){return this.http.get("alias/list").json()}async getCollectionList(e,t){let n={trophy:"trophies",icon:"icons",plate:"plates",frame:"frames"};return this.http.get(`${e}/list`,{searchParams:{...t}}).json().then(i=>i[n[e]])}async getCollectionInfo(e,t,n){return this.http.get(`${e}/${t}`,{searchParams:{...n}}).json()}async getCollectionGenreList(e){return this.http.get("collection-genre/list",{searchParams:{...e}}).json()}async getCollectionGenreInfo(e,t){return this.http.get(`collection-genre/${e}`,{searchParams:{...t}}).json()}};var c=class{constructor(e){this.http=e}async postPlayer(e){return this.http.post("player",{json:e}).json()}async getPlayer(e){return this.http.get(`player/${e}`).json()}async getPlayerByQQ(e){return this.http.get(`player/qq/${e}`).json()}async getBests(e){return this.http.get(`player/${e}/bests`).json()}async getApBests(e){return this.http.get(`player/${e}/bests/ap`).json()}async getRecents(e){return this.http.get(`player/${e}/recents`).json()}async getAllBestScores(e){return this.http.get(`player/${e}/scores`).json()}async getHeatmap(e){return this.http.get(`player/${e}/heatmap`).json()}async getTrend(e){return this.http.get(`player/${e}/trend`).json()}async getScoreHistory(e){return this.http.get(`player/${e}/score/history`).json()}async getCollectionProgress(e,t,n){return this.http.get(`player/${e}/${t}/${n}`).json()}async postScores(e,t){let n={scores:t};return this.http.post(`player/${e}/scores`,{json:n}).json()}async postHtml(e,t){return this.http.post(`player/${e}/html`,{body:t,headers:{"content-type":"text/plain"}}).json()}};var p=class{constructor(e){this.http=e}async getPlayer(){return this.http.get("player").json()}async getScores(){return this.http.get("scores").json()}async postScores(e){let t={scores:e};return this.http.post("scores",{json:t}).json()}};var d=class{config={baseURL:"https://maimai.lxns.net/api/v0/"};maimai;constructor(e){this.config={baseURL:e?.baseURL??this.config.baseURL,personalAccessToken:e?.personalAccessToken,devAccessToken:e?.devAccessToken};let{baseURL:t,devAccessToken:n,personalAccessToken:i}=this.config,s=u.default.create({prefixUrl:new URL("maimai/",t)}),f=n?u.default.create({prefixUrl:new URL("maimai/",t),headers:{Authorization:n}}):void 0,b=i?u.default.create({prefixUrl:new URL("user/maimai/",t),headers:{"X-User-Token":i}}):void 0,m={public:new l(s)};f&&(m.dev=new c(f)),b&&(m.personal=new p(b)),this.maimai=m}};0&&(module.exports={LxnsApiClient,MaimaiModels});