@newbeebox/newbeebox-client-web-sdk 1.0.7 → 1.0.9
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 +76 -34
- package/index.js +73 -8
- package/package.json +29 -29
- package/types/index.d.ts +16 -0
package/README.md
CHANGED
|
@@ -1,45 +1,87 @@
|
|
|
1
1
|
## 新手盒子客户端SDK
|
|
2
|
+
|
|
2
3
|
用于Web类第三方应用调用新手盒子客户端相关功能的开发组件。
|
|
3
4
|
|
|
4
5
|
### 安装
|
|
6
|
+
|
|
5
7
|
```bash
|
|
6
8
|
npm install @newbeebox/newbeebox-client-web-sdk
|
|
7
9
|
```
|
|
8
10
|
|
|
9
11
|
### 快速上手
|
|
10
|
-
代码示例:
|
|
11
12
|
|
|
12
13
|
```javascript
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
14
|
+
// 引用
|
|
15
|
+
import { NewBeeClient } from "@newbeebox/newbeebox-client-web-sdk"
|
|
16
|
+
|
|
17
|
+
// 1.初始化客户端
|
|
18
|
+
let client = new NewBeeClient();
|
|
19
|
+
await client.Init("your_app_id");
|
|
20
|
+
|
|
21
|
+
// 2.功能调用
|
|
22
|
+
// 打开应用订阅界面
|
|
23
|
+
await client.ShowSubscriptionPage();
|
|
24
|
+
|
|
25
|
+
// 获取当前用户订阅信息
|
|
26
|
+
let info = await client.GetUserSubscription();
|
|
27
|
+
console.log(info);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### API
|
|
31
|
+
|
|
32
|
+
#### `Init(app_id: string): Promise<void>`
|
|
33
|
+
|
|
34
|
+
初始化SDK,扫描本地端口连接新手盒子客户端。
|
|
35
|
+
|
|
36
|
+
| 参数 | 类型 | 说明 |
|
|
37
|
+
|------|------|------|
|
|
38
|
+
| app_id | string | 应用ID,从后台获取 |
|
|
39
|
+
|
|
40
|
+
#### `ShowSubscriptionPage(): Promise<boolean>`
|
|
41
|
+
|
|
42
|
+
打开应用订阅界面。
|
|
43
|
+
|
|
44
|
+
#### `GetUserSubscription(): Promise<UserSubscribeInfo>`
|
|
45
|
+
|
|
46
|
+
获取当前用户的订阅信息。
|
|
47
|
+
|
|
48
|
+
#### `InstallWoWAddon(game_version_id, mod_id): Promise<any>`
|
|
49
|
+
|
|
50
|
+
安装魔兽世界插件。
|
|
51
|
+
|
|
52
|
+
| 参数 | 类型 | 说明 |
|
|
53
|
+
|------|------|------|
|
|
54
|
+
| game_version_id | string \| number | 游戏版本ID |
|
|
55
|
+
| mod_id | string \| number | 插件ID |
|
|
56
|
+
|
|
57
|
+
#### `Patch(tool_name, data?): Promise<any>`
|
|
58
|
+
|
|
59
|
+
通用请求接口,当SDK未导出指定接口时可使用此方法。
|
|
60
|
+
|
|
61
|
+
| 参数 | 类型 | 说明 |
|
|
62
|
+
|------|------|------|
|
|
63
|
+
| tool_name | string | 完整API路径,如 `/tool/some_api` |
|
|
64
|
+
| data | object | 请求数据(可选) |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
**订阅信息返回结构**:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
{
|
|
72
|
+
"app_id": "nb1721e87",
|
|
73
|
+
"user": {
|
|
74
|
+
"open_id": "nb0d968311...",
|
|
75
|
+
"nickname": "Kyuu",
|
|
76
|
+
"avatar": "https://cdn8.newbeebox.com/...."
|
|
77
|
+
},
|
|
78
|
+
"subscribe_mode": 1, // 1=作者订阅, 2=应用订阅
|
|
79
|
+
"end_time": 0, // 到期时间戳
|
|
80
|
+
"level": 0, // 订阅等级
|
|
81
|
+
"level_label": "", // 等级标签
|
|
82
|
+
"is_yearly": false, // 是否年订阅
|
|
83
|
+
"timestamp": 1758613861250,
|
|
84
|
+
"nonce": 6363921989,
|
|
85
|
+
"sign": "485d82860578ff..." // 签名,用于服务端验证
|
|
86
|
+
}
|
|
87
|
+
```
|
package/index.js
CHANGED
|
@@ -13,6 +13,13 @@ export class NewBeeClient {
|
|
|
13
13
|
|
|
14
14
|
constructor() {}
|
|
15
15
|
|
|
16
|
+
// 检测客户端是否已初始化
|
|
17
|
+
_ensureInitialized() {
|
|
18
|
+
if (!this.newbee_client_port) {
|
|
19
|
+
throw new Error("SDK未初始化或者未检测到新手盒子客户端");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
16
23
|
async Init(app_id) {
|
|
17
24
|
if (!app_id || typeof app_id !== "string") {
|
|
18
25
|
throw new Error("APPID格式不正确 请前往后台获取");
|
|
@@ -43,7 +50,7 @@ export class NewBeeClient {
|
|
|
43
50
|
|
|
44
51
|
clearTimeout(timeoutId);
|
|
45
52
|
} catch (e) {
|
|
46
|
-
console.error(port, "
|
|
53
|
+
console.error(port, "端口检查失败:", e);
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
console.log("端口检查:", check_response);
|
|
@@ -63,10 +70,7 @@ export class NewBeeClient {
|
|
|
63
70
|
|
|
64
71
|
// 打开应用订阅界面
|
|
65
72
|
async ShowSubscriptionPage() {
|
|
66
|
-
|
|
67
|
-
throw new Error("SDK未初始化或者未检测到新手盒子客户端");
|
|
68
|
-
}
|
|
69
|
-
|
|
73
|
+
this._ensureInitialized();
|
|
70
74
|
|
|
71
75
|
// 创建 AbortController 实例
|
|
72
76
|
const controller = new AbortController();
|
|
@@ -111,9 +115,7 @@ export class NewBeeClient {
|
|
|
111
115
|
|
|
112
116
|
// 获取当前使用的用户的订阅信息
|
|
113
117
|
async GetUserSubscription() {
|
|
114
|
-
|
|
115
|
-
throw new Error("SDK未初始化或者未检测到新手盒子客户端");
|
|
116
|
-
}
|
|
118
|
+
this._ensureInitialized();
|
|
117
119
|
|
|
118
120
|
let user_subscribe_response = null;
|
|
119
121
|
try {
|
|
@@ -141,4 +143,67 @@ export class NewBeeClient {
|
|
|
141
143
|
|
|
142
144
|
return user_subscribe_response.data
|
|
143
145
|
}
|
|
146
|
+
|
|
147
|
+
// 安装魔兽世界插件
|
|
148
|
+
async InstallWoWAddon(game_version_id, mod_id) {
|
|
149
|
+
this._ensureInitialized();
|
|
150
|
+
|
|
151
|
+
let install_response = null;
|
|
152
|
+
try {
|
|
153
|
+
let response = await fetch(CLIENT_SERVICE_BASE_URL + ":" + this.newbee_client_port + "/tool/wow_install_addon", {
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: {
|
|
156
|
+
"Content-Type": 'application/json',
|
|
157
|
+
},
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
app_id: this.app_id,
|
|
160
|
+
game_version_id: game_version_id,
|
|
161
|
+
mod_id: mod_id
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
install_response = await response.json();
|
|
166
|
+
|
|
167
|
+
console.log("安装插件响应:", install_response);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.log("安装插件错误:", e);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!install_response || install_response?.code !== 1) {
|
|
173
|
+
throw new Error("安装魔兽世界插件发生错误:" + (install_response?.message || "未知错误"));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return install_response.data;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 通用请求 当没有导出指定接口时可以使用这个函数补充请求
|
|
180
|
+
async Patch(tool_name, data) {
|
|
181
|
+
this._ensureInitialized();
|
|
182
|
+
|
|
183
|
+
let patch_response = null;
|
|
184
|
+
try {
|
|
185
|
+
let response = await fetch(CLIENT_SERVICE_BASE_URL + ":" + this.newbee_client_port + tool_name, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: {
|
|
188
|
+
"Content-Type": 'application/json',
|
|
189
|
+
},
|
|
190
|
+
body: JSON.stringify({
|
|
191
|
+
app_id: this.app_id,
|
|
192
|
+
...data
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
patch_response = await response.json();
|
|
197
|
+
|
|
198
|
+
console.log("Patch响应:", patch_response);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.log("Patch请求错误:", e);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!patch_response || patch_response?.code !== 1) {
|
|
204
|
+
throw new Error("Patch请求发生错误:" + (patch_response?.message || "未知错误"));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return patch_response.data;
|
|
208
|
+
}
|
|
144
209
|
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@newbeebox/newbeebox-client-web-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "NewBeeBox Client SDK for Web",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"types": "./types/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"*.js",
|
|
10
|
-
"types/*.d.ts"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"release:patch": "npm version patch && npm publish",
|
|
14
|
-
"release:minor": "npm version minor && npm publish",
|
|
15
|
-
"release:major": "npm version major && npm publish"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"newbeebox",
|
|
19
|
-
"wow",
|
|
20
|
-
"sdk",
|
|
21
|
-
"client"
|
|
22
|
-
],
|
|
23
|
-
"author": "NewBeeBoxTeam",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"registry": "https://registry.npmjs.org/",
|
|
27
|
-
"access": "public"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@newbeebox/newbeebox-client-web-sdk",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "NewBeeBox Client SDK for Web",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"*.js",
|
|
10
|
+
"types/*.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"release:patch": "npm version patch && npm publish",
|
|
14
|
+
"release:minor": "npm version minor && npm publish",
|
|
15
|
+
"release:major": "npm version major && npm publish"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"newbeebox",
|
|
19
|
+
"wow",
|
|
20
|
+
"sdk",
|
|
21
|
+
"client"
|
|
22
|
+
],
|
|
23
|
+
"author": "NewBeeBoxTeam",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"registry": "https://registry.npmjs.org/",
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -33,6 +33,22 @@ export class NewBeeClient {
|
|
|
33
33
|
* @return {Promise<UserSubscribeInfo>}
|
|
34
34
|
*/
|
|
35
35
|
GetUserSubscription(): Promise<UserSubscribeInfo>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 安装魔兽世界插件
|
|
39
|
+
* @param game_version_id 游戏版本ID
|
|
40
|
+
* @param mod_id 插件ID
|
|
41
|
+
* @return {Promise<any>}
|
|
42
|
+
*/
|
|
43
|
+
InstallWoWAddon(game_version_id: string | number, mod_id: string | number): Promise<any>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 通用请求接口
|
|
47
|
+
* @param tool_name 完整API路径,如 /tool/some_api
|
|
48
|
+
* @param data 请求数据
|
|
49
|
+
* @return {Promise<any>}
|
|
50
|
+
*/
|
|
51
|
+
Patch(tool_name: string, data?: Record<string, any>): Promise<any>;
|
|
36
52
|
}
|
|
37
53
|
|
|
38
54
|
/**
|