@yuntower/yuntower-account-web-sdk 0.0.12 → 0.0.14
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 +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +42 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
云塔账号通行证官方Web SDK
|
|
4
4
|
|
|
5
|
-
- 官网:[https://account.yuntower.com](https://account.yuntower.
|
|
6
|
-
- 文档:[https://yuntower.
|
|
5
|
+
- 官网:[https://account.yuntower.com](https://account.yuntower.com)
|
|
6
|
+
- 文档:[https://docs.yuntower.com/account/open.html](https://docs.yuntower.com/account/open.html)
|
|
7
7
|
- NPM:[https://www.npmjs.com/package/@yuntower/yuntower-account-web-sdk](https://www.npmjs.com/package/@yuntower/yuntower-account-web-sdk)
|
|
8
8
|
|
|
9
9
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -32,9 +32,11 @@ declare class YunTowerAccountSDK {
|
|
|
32
32
|
private setupMessageListener;
|
|
33
33
|
/**
|
|
34
34
|
* 弹窗授权模式
|
|
35
|
-
* @param
|
|
35
|
+
* @param optionsOrCallback 配置(可选)或回调;传 { autoCloseOnFinish: false } 可关闭「成功/失败时自动关窗」
|
|
36
|
+
* @param callback 授权回调(当第一个参数为 options 时必传)
|
|
37
|
+
* @returns 返回 { close },由接入方在需要时调用 close() 关闭授权窗口
|
|
36
38
|
*/
|
|
37
|
-
window(callback?: (response: CallbackResponse) => void):
|
|
39
|
+
window(optionsOrCallback?: WindowOptions | ((response: CallbackResponse) => void), callback?: (response: CallbackResponse) => void): WindowController;
|
|
38
40
|
/**
|
|
39
41
|
* 重定向授权模式
|
|
40
42
|
* @param redirectUrl 授权完成后的重定向URL
|
package/dist/index.js
CHANGED
|
@@ -104,35 +104,68 @@ class YunTowerAccountSDK {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* 弹窗授权模式
|
|
107
|
-
* @param
|
|
107
|
+
* @param optionsOrCallback 配置(可选)或回调;传 { autoCloseOnFinish: false } 可关闭「成功/失败时自动关窗」
|
|
108
|
+
* @param callback 授权回调(当第一个参数为 options 时必传)
|
|
109
|
+
* @returns 返回 { close },由接入方在需要时调用 close() 关闭授权窗口
|
|
108
110
|
*/
|
|
109
|
-
window(callback
|
|
111
|
+
window(optionsOrCallback, callback) {
|
|
112
|
+
const options = optionsOrCallback && typeof optionsOrCallback === "object"
|
|
113
|
+
? optionsOrCallback
|
|
114
|
+
: {};
|
|
115
|
+
const userCallback = typeof optionsOrCallback === "function"
|
|
116
|
+
? optionsOrCallback
|
|
117
|
+
: callback ?? (() => { });
|
|
118
|
+
const autoCloseOnFinish = options.autoCloseOnFinish !== false;
|
|
110
119
|
const authUrl = this.buildAuthUrl("window");
|
|
111
120
|
const authWindow = window.open(authUrl, "_blank", "width=500,height=600");
|
|
112
121
|
if (!authWindow) {
|
|
113
122
|
throw new Error("[YunTowerAccountSDK] 无法打开授权窗口,可能被浏览器拦截");
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
let intervalId = null;
|
|
125
|
+
const cleanup = this.setupMessageListener((response) => {
|
|
126
|
+
if (intervalId != null) {
|
|
127
|
+
clearInterval(intervalId);
|
|
128
|
+
intervalId = null;
|
|
129
|
+
}
|
|
130
|
+
cleanup();
|
|
131
|
+
if (autoCloseOnFinish && authWindow && !authWindow.closed) {
|
|
132
|
+
authWindow.close();
|
|
133
|
+
}
|
|
134
|
+
userCallback(response);
|
|
135
|
+
});
|
|
136
|
+
intervalId = setInterval(() => {
|
|
118
137
|
if (authWindow.closed) {
|
|
119
|
-
|
|
138
|
+
if (intervalId != null) {
|
|
139
|
+
clearInterval(intervalId);
|
|
140
|
+
intervalId = null;
|
|
141
|
+
}
|
|
120
142
|
cleanup();
|
|
121
|
-
|
|
143
|
+
userCallback({
|
|
122
144
|
event: "closed",
|
|
123
145
|
status: "success",
|
|
124
146
|
});
|
|
125
147
|
}
|
|
126
148
|
else {
|
|
127
|
-
// 发送状态检查消息
|
|
128
149
|
try {
|
|
129
150
|
authWindow.postMessage({ action: "status" }, "*");
|
|
130
151
|
}
|
|
131
152
|
catch {
|
|
132
|
-
//
|
|
153
|
+
// 窗口可能已关闭,忽略
|
|
133
154
|
}
|
|
134
155
|
}
|
|
135
156
|
}, 3000);
|
|
157
|
+
return {
|
|
158
|
+
close() {
|
|
159
|
+
if (intervalId != null) {
|
|
160
|
+
clearInterval(intervalId);
|
|
161
|
+
intervalId = null;
|
|
162
|
+
}
|
|
163
|
+
cleanup();
|
|
164
|
+
if (authWindow && !authWindow.closed) {
|
|
165
|
+
authWindow.close();
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
136
169
|
}
|
|
137
170
|
/**
|
|
138
171
|
* 重定向授权模式
|