@kevisual/kv-login 0.1.2 → 0.1.3
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/app.d.ts +4 -1
- package/dist/app.js +55 -24
- package/package.json +2 -2
- package/src/main.ts +1 -2
package/dist/app.d.ts
CHANGED
package/dist/app.js
CHANGED
|
@@ -2972,19 +2972,23 @@ UnsafeHTMLDirective.directiveName = "unsafeHTML";
|
|
|
2972
2972
|
UnsafeHTMLDirective.resultType = HTML_RESULT2;
|
|
2973
2973
|
var unsafeHTML = directive(UnsafeHTMLDirective);
|
|
2974
2974
|
|
|
2975
|
-
// ../../node_modules/.pnpm/@kevisual+query@0.0.
|
|
2975
|
+
// ../../node_modules/.pnpm/@kevisual+query@0.0.33/node_modules/@kevisual/query/dist/query-browser.js
|
|
2976
2976
|
var isTextForContentType = (contentType) => {
|
|
2977
2977
|
if (!contentType)
|
|
2978
2978
|
return false;
|
|
2979
|
-
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded"];
|
|
2979
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
2980
2980
|
return textTypes.some((type) => contentType.includes(type));
|
|
2981
2981
|
};
|
|
2982
2982
|
var adapter = async (opts = {}, overloadOpts) => {
|
|
2983
2983
|
const controller = new AbortController;
|
|
2984
2984
|
const signal = controller.signal;
|
|
2985
|
-
const isBlob = opts.isBlob || false;
|
|
2986
|
-
const isText = opts.isText || false;
|
|
2987
2985
|
const isPostFile = opts.isPostFile || false;
|
|
2986
|
+
let responseType = opts.responseType || "json";
|
|
2987
|
+
if (opts.isBlob) {
|
|
2988
|
+
responseType = "blob";
|
|
2989
|
+
} else if (opts.isText) {
|
|
2990
|
+
responseType = "text";
|
|
2991
|
+
}
|
|
2988
2992
|
const timeout = opts.timeout || 60000 * 3;
|
|
2989
2993
|
const timer = setTimeout(() => {
|
|
2990
2994
|
controller.abort();
|
|
@@ -3002,6 +3006,9 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3002
3006
|
const isGet = method === "GET";
|
|
3003
3007
|
if (isGet) {
|
|
3004
3008
|
url.search = new URLSearchParams(opts.body).toString();
|
|
3009
|
+
} else {
|
|
3010
|
+
const params = opts.params || {};
|
|
3011
|
+
url.search = new URLSearchParams(params).toString();
|
|
3005
3012
|
}
|
|
3006
3013
|
let body = undefined;
|
|
3007
3014
|
if (isGet) {
|
|
@@ -3023,15 +3030,16 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3023
3030
|
headers
|
|
3024
3031
|
}).then(async (response) => {
|
|
3025
3032
|
const contentType = response.headers.get("Content-Type");
|
|
3026
|
-
if (
|
|
3033
|
+
if (responseType === "blob") {
|
|
3027
3034
|
return await response.blob();
|
|
3028
3035
|
}
|
|
3036
|
+
const isText = responseType === "text";
|
|
3029
3037
|
const isJson = contentType && contentType.includes("application/json");
|
|
3030
3038
|
if (isJson && !isText) {
|
|
3031
3039
|
return await response.json();
|
|
3032
3040
|
} else if (isTextForContentType(contentType)) {
|
|
3033
3041
|
return {
|
|
3034
|
-
code:
|
|
3042
|
+
code: response.status,
|
|
3035
3043
|
status: response.status,
|
|
3036
3044
|
data: await response.text()
|
|
3037
3045
|
};
|
|
@@ -3050,15 +3058,6 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3050
3058
|
clearTimeout(timer);
|
|
3051
3059
|
});
|
|
3052
3060
|
};
|
|
3053
|
-
var setBaseResponse = (res) => {
|
|
3054
|
-
res.success = res.code === 200;
|
|
3055
|
-
res.showError = (fn) => {
|
|
3056
|
-
if (!res.success && !res.noMsg) {
|
|
3057
|
-
fn?.();
|
|
3058
|
-
}
|
|
3059
|
-
};
|
|
3060
|
-
return res;
|
|
3061
|
-
};
|
|
3062
3061
|
var wrapperError = ({ code, message }) => {
|
|
3063
3062
|
const result = {
|
|
3064
3063
|
code: code || 500,
|
|
@@ -3079,9 +3078,11 @@ class Query {
|
|
|
3079
3078
|
timeout;
|
|
3080
3079
|
stop;
|
|
3081
3080
|
qws;
|
|
3081
|
+
isClient = false;
|
|
3082
3082
|
constructor(opts) {
|
|
3083
3083
|
this.adapter = opts?.adapter || adapter;
|
|
3084
|
-
|
|
3084
|
+
const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
|
|
3085
|
+
this.url = opts?.url || defaultURL;
|
|
3085
3086
|
this.headers = opts?.headers || {
|
|
3086
3087
|
"Content-Type": "application/json"
|
|
3087
3088
|
};
|
|
@@ -3147,7 +3148,6 @@ class Query {
|
|
|
3147
3148
|
}
|
|
3148
3149
|
return _adapter(req).then(async (res) => {
|
|
3149
3150
|
try {
|
|
3150
|
-
setBaseResponse(res);
|
|
3151
3151
|
if (_afterResponse) {
|
|
3152
3152
|
return await _afterResponse(res, {
|
|
3153
3153
|
req,
|
|
@@ -3187,7 +3187,13 @@ class Query {
|
|
|
3187
3187
|
..._options?.headers || {}
|
|
3188
3188
|
}
|
|
3189
3189
|
});
|
|
3190
|
-
|
|
3190
|
+
if (res && !res.code) {
|
|
3191
|
+
return {
|
|
3192
|
+
code: 200,
|
|
3193
|
+
data: res
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3196
|
+
return res;
|
|
3191
3197
|
}
|
|
3192
3198
|
}
|
|
3193
3199
|
|
|
@@ -3216,8 +3222,8 @@ class BaseQuery {
|
|
|
3216
3222
|
}
|
|
3217
3223
|
}
|
|
3218
3224
|
|
|
3219
|
-
// ../../node_modules/.pnpm/@kevisual+query@0.0.
|
|
3220
|
-
var
|
|
3225
|
+
// ../../node_modules/.pnpm/@kevisual+query@0.0.33/node_modules/@kevisual/query/dist/query.js
|
|
3226
|
+
var setBaseResponse = (res) => {
|
|
3221
3227
|
res.success = res.code === 200;
|
|
3222
3228
|
res.showError = (fn) => {
|
|
3223
3229
|
if (!res.success && !res.noMsg) {
|
|
@@ -3407,7 +3413,7 @@ class MyCache extends CacheWorkspace {
|
|
|
3407
3413
|
}
|
|
3408
3414
|
}
|
|
3409
3415
|
|
|
3410
|
-
// ../../node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.
|
|
3416
|
+
// ../../node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.33/node_modules/@kevisual/query-login/dist/query-login-browser.js
|
|
3411
3417
|
var LoginCacheStore = class {
|
|
3412
3418
|
cache;
|
|
3413
3419
|
name;
|
|
@@ -3614,7 +3620,7 @@ var QueryLogin = class extends BaseQuery {
|
|
|
3614
3620
|
}
|
|
3615
3621
|
return this.post({ key: "refreshToken", data }, {
|
|
3616
3622
|
afterResponse: async (response, ctx) => {
|
|
3617
|
-
|
|
3623
|
+
setBaseResponse(response);
|
|
3618
3624
|
return response;
|
|
3619
3625
|
}
|
|
3620
3626
|
});
|
|
@@ -3639,7 +3645,7 @@ var QueryLogin = class extends BaseQuery {
|
|
|
3639
3645
|
body,
|
|
3640
3646
|
headers: { ...headers, Authorization: `Bearer ${accessToken}` }
|
|
3641
3647
|
});
|
|
3642
|
-
|
|
3648
|
+
setBaseResponse(res2);
|
|
3643
3649
|
return res2;
|
|
3644
3650
|
}
|
|
3645
3651
|
} else {
|
|
@@ -4238,6 +4244,8 @@ var clearCode = () => {
|
|
|
4238
4244
|
const url = new URL(window.location.href);
|
|
4239
4245
|
url.searchParams.delete("code");
|
|
4240
4246
|
url.searchParams.delete("state");
|
|
4247
|
+
url.searchParams.delete("user-check");
|
|
4248
|
+
url.searchParams.delete("redirect");
|
|
4241
4249
|
window.history.replaceState({}, document.title, url.toString());
|
|
4242
4250
|
};
|
|
4243
4251
|
var checkWechat = async () => {
|
|
@@ -4282,6 +4290,27 @@ var checkMpWechat = async () => {
|
|
|
4282
4290
|
closePage();
|
|
4283
4291
|
}
|
|
4284
4292
|
};
|
|
4293
|
+
var checkPluginLogin = async () => {
|
|
4294
|
+
const userCheck = "user-check";
|
|
4295
|
+
const url = new URL(location.href);
|
|
4296
|
+
const redirect = url.searchParams.get("redirect");
|
|
4297
|
+
const redirectUrl = redirect ? decodeURIComponent(redirect) : "";
|
|
4298
|
+
const checkKey = url.searchParams.get(userCheck);
|
|
4299
|
+
if (redirect && checkKey) {
|
|
4300
|
+
const me = await query.getMe();
|
|
4301
|
+
if (me.code === 200) {
|
|
4302
|
+
message.success("登录插件中...");
|
|
4303
|
+
const token = await query.cacheStore.getAccessToken();
|
|
4304
|
+
const newRedirectUrl = new URL(redirectUrl);
|
|
4305
|
+
newRedirectUrl.searchParams.set("token", token + "");
|
|
4306
|
+
setTimeout(() => {
|
|
4307
|
+
window.open(newRedirectUrl.toString(), "_blank");
|
|
4308
|
+
}, 2000);
|
|
4309
|
+
return;
|
|
4310
|
+
}
|
|
4311
|
+
}
|
|
4312
|
+
console.log("checkKey", checkKey, redirectUrl);
|
|
4313
|
+
};
|
|
4285
4314
|
var isWechat = () => {
|
|
4286
4315
|
const ua = navigator.userAgent.toLowerCase();
|
|
4287
4316
|
return /micromessenger/i.test(ua);
|
|
@@ -5563,5 +5592,7 @@ class KvLogin extends HTMLElement {
|
|
|
5563
5592
|
}
|
|
5564
5593
|
customElements.define("kv-login", KvLogin);
|
|
5565
5594
|
export {
|
|
5566
|
-
loginEmitter
|
|
5595
|
+
loginEmitter,
|
|
5596
|
+
clearCode,
|
|
5597
|
+
checkPluginLogin
|
|
5567
5598
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/kv-login",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
},
|
|
37
37
|
"types": "./types/index.d.ts",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/bun": "^1.3.
|
|
39
|
+
"@types/bun": "^1.3.5"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { checkPluginLogin, clearCode } from './modules/login-handle';
|
|
2
1
|
import './pages/kv-login'
|
|
3
2
|
import './pages/kv-message'
|
|
4
3
|
|
|
5
4
|
export { loginEmitter } from './pages/kv-login'
|
|
6
5
|
|
|
7
|
-
export { checkPluginLogin, clearCode }
|
|
6
|
+
export { checkPluginLogin, clearCode } from './modules/login-handle';
|