@yuntower/yuntower-account-node-sdk 0.0.13 → 0.0.15

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/dist/index.d.ts CHANGED
@@ -1,18 +1,13 @@
1
1
  declare class YunTowerAccountSDK {
2
2
  config: {
3
- auth: string;
4
3
  api: string;
5
4
  origin_white_list: string[];
6
5
  appid: string;
7
6
  appsecret: string;
8
- scope: string;
9
- state: any;
10
7
  };
11
- constructor({ appid, appsecret, state, scope, }: {
8
+ constructor({ appid, appsecret, }: {
12
9
  appid: string;
13
10
  appsecret: string;
14
- scope: string;
15
- state?: any;
16
11
  });
17
12
  /**
18
13
  * fetch
@@ -22,40 +17,39 @@ declare class YunTowerAccountSDK {
22
17
  * @param {Object} [headers] - 自定义请求头
23
18
  * @returns {Promise<any>} - 解析后的响应体
24
19
  */
25
- fetch(url: string, method: 'GET' | 'POST', data?: object, headers?: object): Promise<any>;
20
+ fetch(url: string, method: "GET" | "POST", data?: object, headers?: object): Promise<any>;
26
21
  /**
27
22
  * 获取用户访问凭证
28
- * @param {string} token 临时Token
29
- * @param {string} tuid 临时UID
30
- * @param {string} appid 应用ID
31
- * @param {string} appsecret 应用密钥
23
+ * @param {string} code 授权码
32
24
  * @returns
33
25
  */
34
- getUserToken(token: string, tuid: string, appid?: string, appsecret?: string): Promise<any>;
26
+ getUserToken(code: string): Promise<any>;
35
27
  /**
36
28
  * 获取用户数据
37
29
  * @param {string} access_token 用户访问凭证
38
- * @param {string} appid 应用ID
39
- * @param {string} appsecret 应用密钥
40
30
  * @returns
41
31
  */
42
- getUserInfo(access_token: string, appid?: string, appsecret?: string): Promise<any>;
32
+ getUserInfo(access_token: string): Promise<any>;
43
33
  /**
44
34
  * 刷新用户访问凭证
45
35
  * @param {string} refresh_token 用户刷新凭证
46
- * @param {string} appid 应用ID
47
- * @param {string} appsecret 应用密钥
48
36
  * @returns
49
37
  */
50
- refreshUserToken(refresh_token: string, appid?: string, appsecret?: string): Promise<any>;
38
+ refreshUserToken(refresh_token: string): Promise<any>;
51
39
  /**
52
40
  * 退出登录状态
53
41
  * @param {string} access_token 用户访问凭证
54
42
  */
55
- logout(access_token: string, appid?: string, appsecret?: string): Promise<{
43
+ logout(access_token: string): Promise<{
56
44
  code: number;
57
45
  msg: string;
58
46
  data: any;
59
47
  }>;
48
+ /**
49
+ * 获取用户关联账号UID
50
+ * @param {string} access_token 用户访问凭证
51
+ * @returns
52
+ */
53
+ getThirdPartyAccount(access_token: string): Promise<any>;
60
54
  }
61
55
  export default YunTowerAccountSDK;
package/dist/index.js CHANGED
@@ -1,22 +1,20 @@
1
1
  class YunTowerAccountSDK {
2
2
  config;
3
- constructor({ appid, appsecret, state = null, scope = 'user_profile', }) {
4
- if (!appid || !appsecret || !scope) {
5
- console.error('[YunTowerAccountSDK] 参数缺失');
6
- }
7
- if (!['user_profile'].includes(scope)) {
8
- console.error('[YunTowerAccountSDK] scope参数错误,目前只支持[user_profile]');
3
+ constructor({ appid, appsecret, }) {
4
+ if (!appid || !appsecret) {
5
+ console.error("[YunTowerAccountSDK] 参数缺失");
9
6
  }
10
7
  this.config = {
11
- auth: 'https://account.yuntower.com',
12
- api: 'https://v1.api.account.yuntower.cn',
8
+ api: "https://v1.api.account.yuntower.cn",
13
9
  // auth:'http://localhost:3000',
14
10
  // api:'http://127.0.0.1:8787',
15
- origin_white_list: ['account.yuntower.cn', 'account.yuntower.com', 'localhost:3000'],
11
+ origin_white_list: [
12
+ "account.yuntower.cn",
13
+ "account.yuntower.com",
14
+ "localhost:3000",
15
+ ],
16
16
  appid,
17
17
  appsecret,
18
- scope,
19
- state,
20
18
  };
21
19
  }
22
20
  /**
@@ -31,7 +29,7 @@ class YunTowerAccountSDK {
31
29
  try {
32
30
  // 设置默认请求头
33
31
  const defaultHeaders = {
34
- 'Content-Type': 'application/json',
32
+ "Content-Type": "application/json",
35
33
  ...headers,
36
34
  };
37
35
  // 构建fetch选项
@@ -40,7 +38,7 @@ class YunTowerAccountSDK {
40
38
  headers: defaultHeaders,
41
39
  };
42
40
  // 如果是POST请求,需要设置body
43
- if (method.toUpperCase() === 'POST') {
41
+ if (method.toUpperCase() === "POST") {
44
42
  options.body = JSON.stringify(data);
45
43
  }
46
44
  // 发起请求
@@ -51,60 +49,50 @@ class YunTowerAccountSDK {
51
49
  }
52
50
  // 解析响应体
53
51
  const responseBody = await response.json();
54
- console.log('[YunTowerAccountSDK]: ', responseBody);
52
+ console.log("[YunTowerAccountSDK]: ", responseBody);
55
53
  return responseBody;
56
54
  }
57
55
  catch (error) {
58
- console.error('Fetch error:', error);
56
+ console.error("Fetch error:", error);
59
57
  throw error;
60
58
  }
61
59
  }
62
60
  /**
63
61
  * 获取用户访问凭证
64
- * @param {string} token 临时Token
65
- * @param {string} tuid 临时UID
66
- * @param {string} appid 应用ID
67
- * @param {string} appsecret 应用密钥
62
+ * @param {string} code 授权码
68
63
  * @returns
69
64
  */
70
- async getUserToken(token, tuid, appid = this.config.appid, appsecret = this.config.appsecret) {
65
+ async getUserToken(code) {
71
66
  const res = await this.fetch(`${this.config.api}/user/token/get`, "POST", {
72
- token,
73
- tuid,
74
- appid,
75
- appsecret
67
+ appid: this.config.appid,
68
+ appsecret: this.config.appsecret,
69
+ code,
76
70
  });
77
71
  return res;
78
72
  }
79
73
  /**
80
74
  * 获取用户数据
81
75
  * @param {string} access_token 用户访问凭证
82
- * @param {string} appid 应用ID
83
- * @param {string} appsecret 应用密钥
84
76
  * @returns
85
77
  */
86
- async getUserInfo(access_token, appid = this.config.appid, appsecret = this.config.appsecret) {
78
+ async getUserInfo(access_token) {
87
79
  const res = await this.fetch(`${this.config.api}/user/data`, "POST", {
88
- appid,
89
- appsecret
90
- }, {
91
- Authorization: `Bearer ${access_token}`
80
+ appid: this.config.appid,
81
+ appsecret: this.config.appsecret,
82
+ access_token,
92
83
  });
93
84
  return res;
94
85
  }
95
86
  /**
96
87
  * 刷新用户访问凭证
97
88
  * @param {string} refresh_token 用户刷新凭证
98
- * @param {string} appid 应用ID
99
- * @param {string} appsecret 应用密钥
100
89
  * @returns
101
90
  */
102
- async refreshUserToken(refresh_token, appid = this.config.appid, appsecret = this.config.appsecret) {
91
+ async refreshUserToken(refresh_token) {
103
92
  const res = await this.fetch(`${this.config.api}/user/token/refresh`, "POST", {
104
- appid,
105
- appsecret
106
- }, {
107
- Authorization: `Bearer ${refresh_token}`
93
+ appid: this.config.appid,
94
+ appsecret: this.config.appsecret,
95
+ refresh_token,
108
96
  });
109
97
  return res;
110
98
  }
@@ -112,12 +100,24 @@ class YunTowerAccountSDK {
112
100
  * 退出登录状态
113
101
  * @param {string} access_token 用户访问凭证
114
102
  */
115
- async logout(access_token, appid = this.config.appid, appsecret = this.config.appsecret) {
103
+ async logout(access_token) {
116
104
  const res = await this.fetch(`${this.config.api}/user/logout`, "POST", {
117
- appid,
118
- appsecret
119
- }, {
120
- Authorization: `Bearer ${access_token}`
105
+ appid: this.config.appid,
106
+ appsecret: this.config.appsecret,
107
+ access_token,
108
+ });
109
+ return res;
110
+ }
111
+ /**
112
+ * 获取用户关联账号UID
113
+ * @param {string} access_token 用户访问凭证
114
+ * @returns
115
+ */
116
+ async getThirdPartyAccount(access_token) {
117
+ const res = await this.fetch(`${this.config.api}/user/connect`, "POST", {
118
+ appid: this.config.appid,
119
+ appsecret: this.config.appsecret,
120
+ access_token,
121
121
  });
122
122
  return res;
123
123
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yuntower/yuntower-account-node-sdk",
3
3
  "description": "YunTower Account Node SDK",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "private": false,
6
6
  "author": "yuntower",
7
7
  "license": "Apache-2.0",
@@ -26,5 +26,8 @@
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.9.3"
29
32
  }
30
33
  }
@@ -1,61 +0,0 @@
1
- declare class YunTowerAccountSDK {
2
- config: {
3
- auth: string;
4
- api: string;
5
- origin_white_list: string[];
6
- appid: string;
7
- appsecret: string;
8
- scope: string;
9
- state: any;
10
- };
11
- constructor({ appid, appsecret, state, scope, }: {
12
- appid: string;
13
- appsecret: string;
14
- scope: string;
15
- state?: any;
16
- });
17
- /**
18
- * fetch
19
- * @param {string} url - 请求URL
20
- * @param {string} method - 请求方法 (GET | POST)
21
- * @param {Object} [data] - POST请求时的数据
22
- * @param {Object} [headers] - 自定义请求头
23
- * @returns {Promise<any>} - 解析后的响应体
24
- */
25
- fetch(url: string, method: 'GET' | 'POST', data?: object, headers?: object): Promise<any>;
26
- /**
27
- * 获取用户访问凭证
28
- * @param {string} token 临时Token
29
- * @param {string} tuid 临时UID
30
- * @param {string} appid 应用ID
31
- * @param {string} appsecret 应用密钥
32
- * @returns
33
- */
34
- getUserToken(token: string, tuid: string, appid?: string, appsecret?: string): Promise<any>;
35
- /**
36
- * 获取用户数据
37
- * @param {string} access_token 用户访问凭证
38
- * @param {string} appid 应用ID
39
- * @param {string} appsecret 应用密钥
40
- * @returns
41
- */
42
- getUserInfo(access_token: string, appid?: string, appsecret?: string): Promise<any>;
43
- /**
44
- * 刷新用户访问凭证
45
- * @param {string} refresh_token 用户刷新凭证
46
- * @param {string} appid 应用ID
47
- * @param {string} appsecret 应用密钥
48
- * @returns
49
- */
50
- refreshUserToken(refresh_token: string, appid?: string, appsecret?: string): Promise<any>;
51
- /**
52
- * 退出登录状态
53
- * @param {string} access_token 用户访问凭证
54
- */
55
- logout(access_token: string, appid?: string, appsecret?: string): Promise<{
56
- code: number;
57
- msg: string;
58
- data: any;
59
- }>;
60
- }
61
- export default YunTowerAccountSDK;