@ybgnb/bili-api 0.0.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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/dist/client/api.d.ts +23 -0
  3. package/dist/client/api.d.ts.map +1 -0
  4. package/dist/client/api.js +128 -0
  5. package/dist/client/api.js.map +1 -0
  6. package/dist/client/client.d.ts +25 -0
  7. package/dist/client/client.d.ts.map +1 -0
  8. package/dist/client/client.js +22 -0
  9. package/dist/client/client.js.map +1 -0
  10. package/dist/client/common.d.ts +6 -0
  11. package/dist/client/common.d.ts.map +1 -0
  12. package/dist/client/common.js +13 -0
  13. package/dist/client/common.js.map +1 -0
  14. package/dist/config/index.d.ts +22 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +32 -0
  17. package/dist/config/index.js.map +1 -0
  18. package/dist/error/handle-error.d.ts +6 -0
  19. package/dist/error/handle-error.d.ts.map +1 -0
  20. package/dist/error/handle-error.js +32 -0
  21. package/dist/error/handle-error.js.map +1 -0
  22. package/dist/error/index.d.ts +40 -0
  23. package/dist/error/index.d.ts.map +1 -0
  24. package/dist/error/index.js +79 -0
  25. package/dist/error/index.js.map +1 -0
  26. package/dist/index.d.ts +9 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +7 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/index.mjs +704 -0
  31. package/dist/index.mjs.map +1 -0
  32. package/dist/index.umd.js +742 -0
  33. package/dist/index.umd.js.map +1 -0
  34. package/dist/service/base.d.ts +17 -0
  35. package/dist/service/base.d.ts.map +1 -0
  36. package/dist/service/base.js +34 -0
  37. package/dist/service/base.js.map +1 -0
  38. package/dist/service/user/index.d.ts +28 -0
  39. package/dist/service/user/index.d.ts.map +1 -0
  40. package/dist/service/user/index.js +148 -0
  41. package/dist/service/user/index.js.map +1 -0
  42. package/dist/service/user/qrcode-login.d.ts +13 -0
  43. package/dist/service/user/qrcode-login.d.ts.map +1 -0
  44. package/dist/service/user/qrcode-login.js +88 -0
  45. package/dist/service/user/qrcode-login.js.map +1 -0
  46. package/dist/stores/mixinkey.d.ts +8 -0
  47. package/dist/stores/mixinkey.d.ts.map +1 -0
  48. package/dist/stores/mixinkey.js +86 -0
  49. package/dist/stores/mixinkey.js.map +1 -0
  50. package/dist/test.d.ts +2 -0
  51. package/dist/test.d.ts.map +1 -0
  52. package/dist/test.js +4 -0
  53. package/dist/test.js.map +1 -0
  54. package/dist/types/business/auth.d.ts +15 -0
  55. package/dist/types/business/auth.d.ts.map +1 -0
  56. package/dist/types/business/auth.js +2 -0
  57. package/dist/types/business/auth.js.map +1 -0
  58. package/dist/types/business/level.d.ts +22 -0
  59. package/dist/types/business/level.d.ts.map +1 -0
  60. package/dist/types/business/level.js +2 -0
  61. package/dist/types/business/level.js.map +1 -0
  62. package/dist/types/business/login.d.ts +35 -0
  63. package/dist/types/business/login.d.ts.map +1 -0
  64. package/dist/types/business/login.js +2 -0
  65. package/dist/types/business/login.js.map +1 -0
  66. package/dist/types/business/misc.d.ts +9 -0
  67. package/dist/types/business/misc.d.ts.map +1 -0
  68. package/dist/types/business/misc.js +2 -0
  69. package/dist/types/business/misc.js.map +1 -0
  70. package/dist/types/business/user.d.ts +34 -0
  71. package/dist/types/business/user.d.ts.map +1 -0
  72. package/dist/types/business/user.js +10 -0
  73. package/dist/types/business/user.js.map +1 -0
  74. package/dist/types/business/vip.d.ts +36 -0
  75. package/dist/types/business/vip.d.ts.map +1 -0
  76. package/dist/types/business/vip.js +19 -0
  77. package/dist/types/business/vip.js.map +1 -0
  78. package/dist/types/core/client.d.ts +38 -0
  79. package/dist/types/core/client.d.ts.map +1 -0
  80. package/dist/types/core/client.js +2 -0
  81. package/dist/types/core/client.js.map +1 -0
  82. package/dist/types/core/request.d.ts +87 -0
  83. package/dist/types/core/request.d.ts.map +1 -0
  84. package/dist/types/core/request.js +2 -0
  85. package/dist/types/core/request.js.map +1 -0
  86. package/dist/types/core/response.d.ts +26 -0
  87. package/dist/types/core/response.d.ts.map +1 -0
  88. package/dist/types/core/response.js +2 -0
  89. package/dist/types/core/response.js.map +1 -0
  90. package/dist/utils/cookies.d.ts +3 -0
  91. package/dist/utils/cookies.d.ts.map +1 -0
  92. package/dist/utils/cookies.js +26 -0
  93. package/dist/utils/cookies.js.map +1 -0
  94. package/dist/utils/time.d.ts +3 -0
  95. package/dist/utils/time.d.ts.map +1 -0
  96. package/dist/utils/time.js +26 -0
  97. package/dist/utils/time.js.map +1 -0
  98. package/dist/utils/url.d.ts +31 -0
  99. package/dist/utils/url.d.ts.map +1 -0
  100. package/dist/utils/url.js +93 -0
  101. package/dist/utils/url.js.map +1 -0
  102. package/package.json +50 -0
  103. package/readme.md +3 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 hzhilong
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.
@@ -0,0 +1,23 @@
1
+ import type { BiliClient } from './client.js';
2
+ import type { ApiResponse, ApiResponseData, RawResponse, ReturnFormat, ReturnFormatMap } from '../types/core/response.js';
3
+ import type { RequestBody, RequestOptions, RequestParams } from '../types/core/request.js';
4
+ /**
5
+ * bili 接口
6
+ */
7
+ export declare class BiliApi {
8
+ private client;
9
+ constructor(client: BiliClient);
10
+ get clientConfig(): import("../index.js").BiliClientConfig;
11
+ get logging(): import("../index.js").ClientLogging;
12
+ get isDebug(): boolean;
13
+ /**
14
+ * 记录接口成功的日志
15
+ */
16
+ logApiSuccess(prefix: string, returnFormat: ReturnFormat, response: RawResponse | ApiResponse | ApiResponseData): void;
17
+ /**
18
+ * 记录接口错误的日志
19
+ */
20
+ logApiError(prefix: string, error: unknown): void;
21
+ request<RData extends ApiResponseData = ApiResponseData, QParams extends RequestParams = RequestParams, QData extends RequestBody = RequestBody, RRFormat extends ReturnFormat | undefined = undefined>(url: string, options?: Partial<RequestOptions<QParams, QData, RRFormat>>): Promise<ReturnFormatMap<RData, RRFormat>>;
22
+ }
23
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,WAAW,EACX,YAAY,EACZ,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAI1F;;GAEG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC,IAAW,YAAY,2CAEtB;IAED,IAAI,OAAO,wCAEV;IAED,IAAI,OAAO,YAEV;IAED;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,GAAG,WAAW,GAAG,eAAe;IAU/G;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAapC,OAAO,CACX,KAAK,SAAS,eAAe,GAAG,eAAe,EAC/C,OAAO,SAAS,aAAa,GAAG,aAAa,EAC7C,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,QAAQ,SAAS,YAAY,GAAG,SAAS,GAAG,SAAS,EAErD,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,GAC1D,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;CAsF7C"}
@@ -0,0 +1,128 @@
1
+ import { handleUrlParams, mergeParams, parseURL } from '../utils/url.js';
2
+ import { BiliAbortError, BiliApiBusinessError, BiliApiHttpError, BiliError } from '../error/index.js';
3
+ import { defaultRequestOptions } from '../config/index.js';
4
+ /**
5
+ * bili 接口
6
+ */
7
+ export class BiliApi {
8
+ constructor(client) {
9
+ this.client = client;
10
+ }
11
+ get clientConfig() {
12
+ return this.client.config;
13
+ }
14
+ get logging() {
15
+ return this.clientConfig.logging;
16
+ }
17
+ get isDebug() {
18
+ return this.clientConfig.logLevel === 'debug';
19
+ }
20
+ /**
21
+ * 记录接口成功的日志
22
+ */
23
+ logApiSuccess(prefix, returnFormat, response) {
24
+ if (returnFormat === 'RawResponse') {
25
+ this.logging.info(`${prefix} 请求成功 [RawResponse]`);
26
+ }
27
+ else if (returnFormat === 'ApiResponse') {
28
+ this.logging.info(`${prefix} 请求成功 [ApiResponse]`, this.isDebug ? JSON.stringify(response) : '');
29
+ }
30
+ else {
31
+ this.logging.info(`${prefix} 请求成功`, this.isDebug ? JSON.stringify(response) : '');
32
+ }
33
+ }
34
+ /**
35
+ * 记录接口错误的日志
36
+ */
37
+ logApiError(prefix, error) {
38
+ // 规范化日志输出
39
+ if (error instanceof BiliAbortError) {
40
+ this.logging.info(`${prefix} [${error.message}]`);
41
+ }
42
+ else if (error instanceof BiliApiHttpError) {
43
+ this.logging.info(`${prefix} [http error]:${error.message}(${error.status})`);
44
+ }
45
+ else if (error instanceof BiliError) {
46
+ this.logging.info(`${prefix} ${error.message}`);
47
+ }
48
+ else {
49
+ this.logging.info(`${prefix} 出现未知错误`, error);
50
+ }
51
+ }
52
+ async request(url, options) {
53
+ const { context, userAgent, timeout: timeoutMS, referer } = this.clientConfig;
54
+ // 合并默认选项
55
+ const finalOptions = { ...defaultRequestOptions, url: url, ...options };
56
+ // 构建日志前缀
57
+ const userInfo = context?.userInfo.mid ? ` [${context?.userInfo.mid}]` : '';
58
+ const prefix = `[bili API]${userInfo} ${finalOptions.method} ${new URL(url).pathname}`;
59
+ try {
60
+ // 解析 url
61
+ const { baseUrl, searchParams } = parseURL(url);
62
+ // 构建查询字符串
63
+ const mergedParams = mergeParams(searchParams, finalOptions.query);
64
+ const searchStr = handleUrlParams(mergedParams, finalOptions.skipWbiSign);
65
+ // 最终的 url
66
+ const finalUrl = `${baseUrl}?${searchStr}`;
67
+ finalOptions.url = finalUrl;
68
+ this.logging.info(`${prefix} 请求中 ${Object.keys(mergedParams)
69
+ .map((key) => `${key}=${String(mergedParams[key])}`)
70
+ .join(', ')}`);
71
+ // FormData 请求时,判断是否需要自动添加 csrf 参数
72
+ if (finalOptions.method === 'POST' && finalOptions.data && finalOptions.autoCsrf) {
73
+ if (finalOptions.data instanceof FormData) {
74
+ finalOptions.data.set('csrf', context?.userCookie.bili_jct ?? '');
75
+ }
76
+ }
77
+ // 初始化 fetch 的配置
78
+ const fetchInit = {
79
+ signal: options?.signal
80
+ ? AbortSignal.any([options?.signal, AbortSignal.timeout(timeoutMS)])
81
+ : AbortSignal.timeout(timeoutMS),
82
+ headers: {
83
+ 'User-Agent': userAgent,
84
+ cookie: finalOptions.cookie?.cookie || context?.userCookie.cookie || '',
85
+ Referer: typeof referer === 'function' ? referer(finalUrl) : referer,
86
+ },
87
+ method: finalOptions.method,
88
+ body: finalOptions.data,
89
+ ...(options?.init ?? {}),
90
+ };
91
+ const httpResponse = await fetch(finalUrl, fetchInit);
92
+ if (!httpResponse.ok) {
93
+ // http 请求错误
94
+ throw new BiliApiHttpError(this.clientConfig, finalOptions, httpResponse);
95
+ }
96
+ if (finalOptions.returnFormat === 'RawResponse') {
97
+ // 直接返回原始响应
98
+ this.logApiSuccess(prefix, 'RawResponse', httpResponse);
99
+ return httpResponse;
100
+ }
101
+ let biliResponse;
102
+ try {
103
+ // 解析 bili 响应数据
104
+ biliResponse = await httpResponse.json();
105
+ }
106
+ catch (e) {
107
+ throw new BiliApiHttpError(this.clientConfig, finalOptions, httpResponse, '解析响应数据错误', e);
108
+ }
109
+ // 业务操作失败
110
+ if (!finalOptions.ignoreBusinessError && biliResponse.code !== 0) {
111
+ throw new BiliApiBusinessError(this.clientConfig, finalOptions, biliResponse);
112
+ }
113
+ if (finalOptions.returnFormat === 'ApiResponse') {
114
+ // 只需要返回响应数据
115
+ this.logApiSuccess(prefix, 'ApiResponse', biliResponse);
116
+ return biliResponse;
117
+ }
118
+ // 返回业务数据
119
+ this.logApiSuccess(prefix, 'ApiResponseData', biliResponse.data);
120
+ return biliResponse.data;
121
+ }
122
+ catch (error) {
123
+ this.logApiError('', error);
124
+ throw error;
125
+ }
126
+ }
127
+ }
128
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/client/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAWxE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACrG,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAE1D;;GAEG;AACH,MAAM,OAAO,OAAO;I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AC,CAAA;YAChE,OAAO,YAAY,CAAC,IAAwC,CAAA;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YAC3B,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import type { BiliClientConfig } from '../types/core/client.js';
2
+ import { BiliApi } from './api.js';
3
+ import { UserService } from '../service/user/index.js';
4
+ import type { RequestContext } from '../types/core/request.js';
5
+ /**
6
+ * bili 客户端
7
+ */
8
+ export declare class BiliClient {
9
+ /**
10
+ * 客户端配置
11
+ */
12
+ config: BiliClientConfig;
13
+ /**
14
+ * 基础的api接口
15
+ */
16
+ api: BiliApi;
17
+ /**
18
+ * 用户模块
19
+ */
20
+ user: UserService;
21
+ get logging(): import("../types/core/client.js").ClientLogging;
22
+ constructor(config?: Partial<BiliClientConfig>);
23
+ updateRequestContext(requestContext: RequestContext): void;
24
+ }
25
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAI9D;;GAEG;AACH,qBAAa,UAAU;IACrB;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAA;IACxB;;OAEG;IACH,GAAG,EAAE,OAAO,CAAA;IACZ;;OAEG;IACH,IAAI,EAAE,WAAW,CAAA;IAEjB,IAAI,OAAO,oDAEV;gBAEW,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAQ9C,oBAAoB,CAAC,cAAc,EAAE,cAAc;CAGpD"}
@@ -0,0 +1,22 @@
1
+ import { BiliApi } from './api.js';
2
+ import { UserService } from '../service/user/index.js';
3
+ import { defaultClientConfig } from '../config/index.js';
4
+ import { mixinKeyStore } from '../stores/mixinkey.js';
5
+ /**
6
+ * bili 客户端
7
+ */
8
+ export class BiliClient {
9
+ get logging() {
10
+ return this.config.logging;
11
+ }
12
+ constructor(config) {
13
+ this.config = { ...defaultClientConfig, ...(config ?? {}) };
14
+ this.api = new BiliApi(this);
15
+ this.user = new UserService(this);
16
+ mixinKeyStore.setAutoRefresh(this.config.autoMixinKey);
17
+ }
18
+ updateRequestContext(requestContext) {
19
+ this.config.context = requestContext;
20
+ }
21
+ }
22
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGrD;;GAEG;AACH,MAAM,OAAO,UAAU;IAcrB,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAA;IAC5B,CAAC;IAED,YAAY,MAAkC;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,mBAAmB,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAA;QAC3D,IAAI,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;QAEjC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IACxD,CAAC;IAED,oBAAoB,CAAC,cAA8B;QACjD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,cAAc,CAAA;IACtC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { BiliClient } from './client.js';
2
+ /**
3
+ * 公用的Bili客户端
4
+ */
5
+ export declare const getCommonBiliClient: () => BiliClient;
6
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/client/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAKxC;;GAEG;AACH,eAAO,MAAM,mBAAmB,kBAK/B,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { BiliClient } from './client.js';
2
+ // 不要直接在顶层new完导出。 BiliApi会出现循环引用的问题。
3
+ let _commonClient = null;
4
+ /**
5
+ * 公用的Bili客户端
6
+ */
7
+ export const getCommonBiliClient = () => {
8
+ if (!_commonClient) {
9
+ _commonClient = new BiliClient();
10
+ }
11
+ return _commonClient;
12
+ };
13
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/client/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,oCAAoC;AACpC,IAAI,aAAa,GAAsB,IAAI,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,UAAU,EAAE,CAAA;IAClC,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { ConsoleMethod } from '../types/core/client.js';
2
+ import type { RequestBody, RequestOptions, RequestParams } from '../types/core/request.js';
3
+ /**
4
+ * 默认的客户端配置
5
+ */
6
+ export declare const defaultClientConfig: {
7
+ timeout: number;
8
+ userAgent: string;
9
+ referer: string;
10
+ logLevel: "info";
11
+ logging: {
12
+ debug: (...data: Parameters<ConsoleMethod>) => void;
13
+ info: (...data: Parameters<ConsoleMethod>) => void;
14
+ error: (...data: Parameters<ConsoleMethod>) => void;
15
+ };
16
+ autoMixinKey: false;
17
+ };
18
+ /**
19
+ * 默认的请求选项
20
+ */
21
+ export declare const defaultRequestOptions: Omit<RequestOptions<RequestParams, RequestBody, 'ApiResponseData'>, 'url'>;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE1F;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;yBAMX,UAAU,CAAC,aAAa,CAAC;wBAG1B,UAAU,CAAC,aAAa,CAAC;yBAGxB,UAAU,CAAC,aAAa,CAAC;;;CAKlB,CAAA;AAE5B;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,KAAK,CAM5G,CAAA"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 默认的客户端配置
3
+ */
4
+ export const defaultClientConfig = {
5
+ timeout: 5000,
6
+ userAgent: '"Chromium";v="146", "Not-A.Brand";v="24", "Google Chrome";v="146"',
7
+ referer: 'https://space.bilibili.com/10000',
8
+ logLevel: 'info',
9
+ logging: {
10
+ debug: (...data) => {
11
+ console.error(`[${new Date().toLocaleString()}]`, ...data);
12
+ },
13
+ info: (...data) => {
14
+ console.info(`[${new Date().toLocaleString()}]`, ...data);
15
+ },
16
+ error: (...data) => {
17
+ console.error(`[${new Date().toLocaleString()}]`, ...data);
18
+ },
19
+ },
20
+ autoMixinKey: false,
21
+ };
22
+ /**
23
+ * 默认的请求选项
24
+ */
25
+ export const defaultRequestOptions = {
26
+ method: 'GET',
27
+ returnFormat: 'ApiResponseData',
28
+ ignoreBusinessError: false,
29
+ skipWbiSign: false,
30
+ autoCsrf: true,
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,mEAAmE;IAC9E,OAAO,EAAE,kCAAkC;IAC3C,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE;QACP,KAAK,EAAE,CAAC,GAAG,IAA+B,EAAE,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC5D,CAAC;QACD,IAAI,EAAE,CAAC,GAAG,IAA+B,EAAE,EAAE;YAC3C,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC3D,CAAC;QACD,KAAK,EAAE,CAAC,GAAG,IAA+B,EAAE,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC5D,CAAC;KACF;IACD,YAAY,EAAE,KAAK;CACO,CAAA;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA+E;IAC/G,MAAM,EAAE,KAAK;IACb,YAAY,EAAE,iBAAiB;IAC/B,mBAAmB,EAAE,KAAK;IAC1B,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,IAAI;CACf,CAAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 错误处理装饰器
3
+ * @constructor
4
+ */
5
+ export declare function CatchError(): (originalMethod: any, context: ClassMethodDecoratorContext) => (this: any, ...args: any[]) => any;
6
+ //# sourceMappingURL=handle-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.d.ts","sourceRoot":"","sources":["../../src/error/handle-error.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,UAAU,KACP,gBAAgB,GAAG,EAAE,SAAS,2BAA2B,MAGvD,MAAM,GAAG,EAAE,GAAG,MAAM,GAAG,EAAE,SAmB7C"}
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * 错误处理装饰器
4
+ * @constructor
5
+ */
6
+ export function CatchError() {
7
+ return function (originalMethod, context) {
8
+ const methodName = String(context.name);
9
+ return function (...args) {
10
+ const className = this.constructor.name;
11
+ try {
12
+ // 调用原始方法,并保持 this 上下文
13
+ return originalMethod.call(this, ...args);
14
+ }
15
+ catch (error) {
16
+ // 检查当前实例是否包含基类定义的 handleError 方法
17
+ if (typeof this.handleError === 'function') {
18
+ // 调用基类的错误处理方法,传入错误对象和方法名
19
+ ;
20
+ this.handleError(error, className, methodName);
21
+ }
22
+ else {
23
+ // 降级:输出错误到控制台
24
+ console.error(`${className}.${methodName} 未知错误`, error);
25
+ // 重新抛出错误,让上层业务感知
26
+ throw error;
27
+ }
28
+ }
29
+ };
30
+ };
31
+ }
32
+ //# sourceMappingURL=handle-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../../src/error/handle-error.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,UAAU,cAAmB,EAAE,OAAoC;QACxE,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAEvC,OAAO,UAAqB,GAAG,IAAW;YACxC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;YACvC,IAAI,CAAC;gBACH,sBAAsB;gBACtB,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;YAC3C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,iCAAiC;gBACjC,IAAI,OAAQ,IAAY,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC;oBACpD,yBAAyB;oBACzB,CAAC;oBAAC,IAAY,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;gBAC1D,CAAC;qBAAM,CAAC;oBACN,cAAc;oBACd,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,IAAI,UAAU,OAAO,EAAE,KAAK,CAAC,CAAA;oBACvD,iBAAiB;oBACjB,MAAM,KAAK,CAAA;gBACb,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { BiliClientConfig, BiliClientConfigSnapshot } from '../types/core/client.js';
2
+ import type { RequestBody, RequestOptions, RequestOptionsSnapshot, RequestParams } from '../types/core/request.js';
3
+ import type { ApiResponse, ApiResponseData, ReturnFormat } from '../types/core/response.js';
4
+ /**
5
+ * bili 错误
6
+ */
7
+ export declare class BiliError extends Error {
8
+ rawError?: Error;
9
+ clientConfig: BiliClientConfigSnapshot;
10
+ constructor(clientConfig: BiliClientConfig, errorMsg?: string, rawError?: unknown);
11
+ }
12
+ /**
13
+ * bili api 错误
14
+ */
15
+ export declare class BiliApiError<QParams extends RequestParams = RequestParams, QData extends RequestBody = RequestBody, RRFormat extends ReturnFormat | undefined = undefined> extends BiliError {
16
+ requestOptions: RequestOptionsSnapshot;
17
+ constructor(clientConfig: BiliClientConfig, requestOptions: RequestOptions<QParams, QData, RRFormat>, errorMsg?: string, rawError?: unknown);
18
+ }
19
+ /**
20
+ * bili api HTTP 网络请求层面的错误(网络错误、超时、状态码超出2xx)
21
+ */
22
+ export declare class BiliApiHttpError<QParams extends RequestParams = RequestParams, QData extends RequestBody = RequestBody, RRFormat extends ReturnFormat | undefined = undefined> extends BiliApiError<QParams, QData, RRFormat> {
23
+ status: number;
24
+ constructor(clientConfig: BiliClientConfig, requestOptions: RequestOptions<QParams, QData, RRFormat>, response: Response, errorMsg?: string, rawError?: unknown);
25
+ }
26
+ /**
27
+ * bili api 业务出错
28
+ */
29
+ export declare class BiliApiBusinessError<RD extends ApiResponseData = ApiResponseData, QParams extends RequestParams = RequestParams, QData extends RequestBody = RequestBody, RRFormat extends ReturnFormat | undefined = undefined> extends BiliApiError<QParams, QData, RRFormat> {
30
+ responseCode?: number;
31
+ responseData?: RD;
32
+ constructor(clientConfig: BiliClientConfig, requestOptions: RequestOptions<QParams, QData, RRFormat>, apiResponse: ApiResponse, errorMsg?: string, rawError?: unknown);
33
+ }
34
+ /**
35
+ * 操作取消
36
+ */
37
+ export declare class BiliAbortError extends BiliError {
38
+ constructor(clientConfig: BiliClientConfig, errorMsg?: string);
39
+ }
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AACzF,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAClH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE3F;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAElC,QAAQ,CAAC,EAAE,KAAK,CAAA;IAEhB,YAAY,EAAE,wBAAwB,CAAA;gBAE1B,YAAY,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO;CAuBlF;AAED;;GAEG;AACH,qBA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,EAAE,WAAW,EACxB,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,OAAO;CAOrB;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;gBAC/B,YAAY,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM;CAI9D"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * bili 错误
3
+ */
4
+ export class BiliError extends Error {
5
+ constructor(clientConfig, errorMsg, rawError) {
6
+ super(errorMsg || '操作失败');
7
+ this.name = 'BiliError';
8
+ this.rawError = rawError instanceof Error ? rawError : new Error(String(rawError));
9
+ const { timeout, userAgent, context } = clientConfig;
10
+ if (context) {
11
+ const { userInfo, userCookie } = context;
12
+ this.clientConfig = {
13
+ timeout,
14
+ userAgent,
15
+ context: {
16
+ userInfo,
17
+ userCookie,
18
+ },
19
+ };
20
+ }
21
+ else {
22
+ this.clientConfig = {
23
+ timeout,
24
+ userAgent,
25
+ };
26
+ }
27
+ }
28
+ }
29
+ /**
30
+ * bili api 错误
31
+ */
32
+ export class BiliApiError extends BiliError {
33
+ constructor(clientConfig, requestOptions, errorMsg, rawError) {
34
+ super(clientConfig, errorMsg, rawError);
35
+ this.name = 'BiliApiError';
36
+ const { url, method, query, data, skipWbiSign, autoCsrf } = requestOptions;
37
+ this.requestOptions = {
38
+ url,
39
+ method,
40
+ query,
41
+ data,
42
+ skipWbiSign,
43
+ autoCsrf,
44
+ };
45
+ }
46
+ }
47
+ /**
48
+ * bili api HTTP 网络请求层面的错误(网络错误、超时、状态码超出2xx)
49
+ */
50
+ export class BiliApiHttpError extends BiliApiError {
51
+ constructor(clientConfig, requestOptions, response, errorMsg, rawError) {
52
+ super(clientConfig, requestOptions, errorMsg || response.statusText || `HTTP ${response.status}`, rawError);
53
+ // 初始值 0 (表示网络层错误,非 HTTP 状态)
54
+ this.status = 0;
55
+ this.name = 'BiliApiHttpError';
56
+ this.status = response.status;
57
+ }
58
+ }
59
+ /**
60
+ * bili api 业务出错
61
+ */
62
+ export class BiliApiBusinessError extends BiliApiError {
63
+ constructor(clientConfig, requestOptions, apiResponse, errorMsg, rawError) {
64
+ super(clientConfig, requestOptions, errorMsg || apiResponse.message, rawError);
65
+ this.name = 'BiliApiBusinessError';
66
+ this.responseCode = apiResponse.code ?? -1;
67
+ this.responseData = apiResponse.data;
68
+ }
69
+ }
70
+ /**
71
+ * 操作取消
72
+ */
73
+ export class BiliAbortError extends BiliError {
74
+ constructor(clientConfig, errorMsg) {
75
+ super(clientConfig, errorMsg || '操作已取消');
76
+ this.name = 'BiliAbortError';
77
+ }
78
+ }
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAMlC,YAAY,YAA8B,EAAE,QAAiB,EAAE,QAAkB;QAC/E,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAA;QAElF,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,YAAY,CAAA;QACpD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAA;YACxC,IAAI,CAAC,YAAY,GAAG;gBAClB,OAAO;gBACP,SAAS;gBACT,OAAO,EAAE;oBACP,QAAQ;oBACR,UAAU;iBACX;aACF,CAAA;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,GAAG;gBAClB,OAAO;gBACP,SAAS;aACV,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MA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AAW,CAAC,IAAI,CAAA;IACtC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC3C,YAAY,YAA8B,EAAE,QAAiB;QAC3D,KAAK,CAAC,YAAY,EAAE,QAAQ,IAAI,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export { BaseService } from './service/base.js';
2
+ export { BiliApi } from './client/api.js';
3
+ export { UserService } from './service/user/index.js';
4
+ export { BiliClient } from './client/client.js';
5
+ export { BiliError } from './error/index.js';
6
+ export type * from './types/core/client.js';
7
+ export type * from './types/business/user.js';
8
+ export * from './utils/time.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,mBAAmB,wBAAwB,CAAA;AAC3C,mBAAmB,0BAA0B,CAAA;AAE7C,cAAc,iBAAiB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { BaseService } from './service/base.js';
2
+ export { BiliApi } from './client/api.js';
3
+ export { UserService } from './service/user/index.js';
4
+ export { BiliClient } from './client/client.js';
5
+ export { BiliError } from './error/index.js';
6
+ export * from './utils/time.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAK5C,cAAc,iBAAiB,CAAA"}