@yuntower/yuntower-account-web-sdk 0.0.14 → 0.0.16

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
@@ -32,11 +32,11 @@ declare class YunTowerAccountSDK {
32
32
  private setupMessageListener;
33
33
  /**
34
34
  * 弹窗授权模式
35
- * @param optionsOrCallback 配置(可选)或回调;传 { autoCloseOnFinish: false } 可关闭「成功/失败时自动关窗」
36
- * @param callback 授权回调(当第一个参数为 options 时必传)
35
+ * @param options 可选配置,如 { autoCloseOnFinish: false } 关闭成功/失败时自动关窗
36
+ * @param callback 授权回调
37
37
  * @returns 返回 { close },由接入方在需要时调用 close() 关闭授权窗口
38
38
  */
39
- window(optionsOrCallback?: WindowOptions | ((response: CallbackResponse) => void), callback?: (response: CallbackResponse) => void): WindowController;
39
+ window(options?: WindowOptions, callback?: (response: CallbackResponse) => void): WindowController;
40
40
  /**
41
41
  * 重定向授权模式
42
42
  * @param redirectUrl 授权完成后的重定向URL
package/dist/index.js CHANGED
@@ -72,15 +72,19 @@ class YunTowerAccountSDK {
72
72
  if (!this.isValidOrigin(event.origin)) {
73
73
  return false;
74
74
  }
75
- if (event.data?.action === "status") {
76
- const { status, data, msg } = event.data;
75
+ const data = event.data;
76
+ const isStatusMessage = data?.action === "status" || data?.type === "status";
77
+ if (isStatusMessage) {
78
+ const status = data.status;
79
+ const msg = data.msg;
80
+ const responseData = data.data;
77
81
  if (status === "success") {
78
82
  this.authStatus = true;
79
83
  }
80
84
  callback({
81
85
  event: "auth",
82
86
  status,
83
- data,
87
+ data: responseData,
84
88
  msg,
85
89
  });
86
90
  return true;
@@ -104,18 +108,14 @@ class YunTowerAccountSDK {
104
108
  }
105
109
  /**
106
110
  * 弹窗授权模式
107
- * @param optionsOrCallback 配置(可选)或回调;传 { autoCloseOnFinish: false } 可关闭「成功/失败时自动关窗」
108
- * @param callback 授权回调(当第一个参数为 options 时必传)
111
+ * @param options 可选配置,如 { autoCloseOnFinish: false } 关闭成功/失败时自动关窗
112
+ * @param callback 授权回调
109
113
  * @returns 返回 { close },由接入方在需要时调用 close() 关闭授权窗口
110
114
  */
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;
115
+ window(options, callback) {
116
+ const opts = options ?? {};
117
+ const userCallback = callback ?? (() => { });
118
+ const autoCloseOnFinish = opts?.autoCloseOnFinish !== false;
119
119
  const authUrl = this.buildAuthUrl("window");
120
120
  const authWindow = window.open(authUrl, "_blank", "width=500,height=600");
121
121
  if (!authWindow) {
@@ -129,10 +129,16 @@ class YunTowerAccountSDK {
129
129
  }
130
130
  cleanup();
131
131
  if (autoCloseOnFinish && authWindow && !authWindow.closed) {
132
- authWindow.close();
132
+ // 延后关窗,避免部分浏览器在 message 回调里同步 close 不生效
133
+ setTimeout(() => {
134
+ if (authWindow && !authWindow.closed) {
135
+ authWindow.close();
136
+ }
137
+ }, 0);
133
138
  }
134
139
  userCallback(response);
135
140
  });
141
+ // 轮询授权窗状态,间隔 1s 便于尽快收到授权页回复
136
142
  intervalId = setInterval(() => {
137
143
  if (authWindow.closed) {
138
144
  if (intervalId != null) {
@@ -153,7 +159,7 @@ class YunTowerAccountSDK {
153
159
  // 窗口可能已关闭,忽略
154
160
  }
155
161
  }
156
- }, 3000);
162
+ }, 1000);
157
163
  return {
158
164
  close() {
159
165
  if (intervalId != null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yuntower/yuntower-account-web-sdk",
3
3
  "description": "YunTower Account Web SDK",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "private": false,
6
6
  "author": "yuntower",
7
7
  "license": "Apache-2.0",