@laiye_packages/uci 1.0.8 → 1.1.0
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.
|
@@ -10,6 +10,8 @@ export interface LYUserQueryParams extends LYRangeQueryParams {
|
|
|
10
10
|
/** 用户唯一名称,英文和数字组合 */
|
|
11
11
|
name?: string;
|
|
12
12
|
display_name?: string;
|
|
13
|
+
/** 用户来源 */
|
|
14
|
+
utm_source?: string;
|
|
13
15
|
/** 角色ID */
|
|
14
16
|
role_id?: string;
|
|
15
17
|
/** 邮箱,仅精确匹配 */
|
|
@@ -171,6 +173,8 @@ interface LYRegisterRequest {
|
|
|
171
173
|
password: string;
|
|
172
174
|
/** 显示名称 */
|
|
173
175
|
display_name: string;
|
|
176
|
+
/** 用户来源 */
|
|
177
|
+
utm_source?: string;
|
|
174
178
|
}
|
|
175
179
|
/**
|
|
176
180
|
* 密码重置请求
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { LYBaseAuthorizer, type LYSigninArgs, LYSignoutArgs } from './base';
|
|
2
|
+
interface LYQueryParams {
|
|
3
|
+
code: string;
|
|
4
|
+
code_verifier: string;
|
|
5
|
+
redirect_uri: string;
|
|
6
|
+
state: string;
|
|
7
|
+
utm_source?: string;
|
|
8
|
+
}
|
|
2
9
|
export interface LYRedirectSessionPostRequest {
|
|
3
10
|
authentication_name: string;
|
|
4
|
-
query_params:
|
|
5
|
-
code: string;
|
|
6
|
-
code_verifier: string;
|
|
7
|
-
redirect_uri: string;
|
|
8
|
-
state: string;
|
|
9
|
-
};
|
|
11
|
+
query_params: LYQueryParams;
|
|
10
12
|
}
|
|
11
13
|
export declare class LYRedirectAuthorizer extends LYBaseAuthorizer {
|
|
12
14
|
_signin(args: LYSigninArgs): Promise<void>;
|
|
@@ -16,3 +18,4 @@ export declare class LYRedirectAuthorizer extends LYBaseAuthorizer {
|
|
|
16
18
|
signout(args?: LYSignoutArgs): Promise<void>;
|
|
17
19
|
_signout(): Promise<void>;
|
|
18
20
|
}
|
|
21
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -9708,7 +9708,7 @@ class LYAppPermission extends LYObject {
|
|
|
9708
9708
|
super(), this._codes = {};
|
|
9709
9709
|
this._app_name = app_name;
|
|
9710
9710
|
this._codes = codes;
|
|
9711
|
-
this._allCodes = allCodes;
|
|
9711
|
+
this._allCodes = allCodes || [];
|
|
9712
9712
|
}
|
|
9713
9713
|
get app_name() {
|
|
9714
9714
|
return this._app_name;
|
|
@@ -9727,7 +9727,7 @@ class LYAppPermission extends LYObject {
|
|
|
9727
9727
|
return this._codes[code];
|
|
9728
9728
|
}
|
|
9729
9729
|
hasPermission(code) {
|
|
9730
|
-
if (
|
|
9730
|
+
if (!this._allCodes.includes(code)) return true;
|
|
9731
9731
|
return code in this._codes;
|
|
9732
9732
|
}
|
|
9733
9733
|
}
|
|
@@ -9745,12 +9745,6 @@ class LYSession extends LYObject {
|
|
|
9745
9745
|
static{
|
|
9746
9746
|
this._CHECK_INTERVAL = 10000;
|
|
9747
9747
|
}
|
|
9748
|
-
static setAllCodesProvider(provider) {
|
|
9749
|
-
LYSession._allCodesProvider = provider;
|
|
9750
|
-
}
|
|
9751
|
-
static setOnSessionCreated(callback) {
|
|
9752
|
-
LYSession._onSessionCreated = callback;
|
|
9753
|
-
}
|
|
9754
9748
|
static get() {
|
|
9755
9749
|
if (!LYSession._session) {
|
|
9756
9750
|
const session = sharedLocalStorage.getSync(SESSION_KEY);
|
|
@@ -9782,9 +9776,6 @@ class LYSession extends LYObject {
|
|
|
9782
9776
|
country_code: country_code || ''
|
|
9783
9777
|
});
|
|
9784
9778
|
LYSession._startRefreshTimer();
|
|
9785
|
-
if (LYSession._onSessionCreated) LYSession._onSessionCreated().catch((err)=>{
|
|
9786
|
-
console.error('Session created callback error:', err);
|
|
9787
|
-
});
|
|
9788
9779
|
return LYSession._session;
|
|
9789
9780
|
}
|
|
9790
9781
|
static clear() {
|
|
@@ -9808,8 +9799,7 @@ class LYSession extends LYObject {
|
|
|
9808
9799
|
this._phone = phone || '';
|
|
9809
9800
|
this._country_code = country_code || '';
|
|
9810
9801
|
this._permissions = Object.entries(permissions || {}).reduce((acc, [app_name, codes])=>{
|
|
9811
|
-
|
|
9812
|
-
acc[app_name] = new LYAppPermission(app_name, codes, allCodes);
|
|
9802
|
+
acc[app_name] = new LYAppPermission(app_name, codes, []);
|
|
9813
9803
|
return acc;
|
|
9814
9804
|
}, {});
|
|
9815
9805
|
}
|
|
@@ -9903,8 +9893,7 @@ class LYSession extends LYObject {
|
|
|
9903
9893
|
if (void 0 !== phone) LYSession._session._phone = phone;
|
|
9904
9894
|
if (void 0 !== country_code) LYSession._session._country_code = country_code;
|
|
9905
9895
|
LYSession._session._permissions = Object.entries(permissions || {}).reduce((acc, [app_name, codes])=>{
|
|
9906
|
-
|
|
9907
|
-
acc[app_name] = new LYAppPermission(app_name, codes, allCodes);
|
|
9896
|
+
acc[app_name] = new LYAppPermission(app_name, codes, []);
|
|
9908
9897
|
return acc;
|
|
9909
9898
|
}, {});
|
|
9910
9899
|
sharedLocalStorage.setSync(SESSION_KEY, {
|
|
@@ -10624,9 +10613,8 @@ class LYSMCrypto extends LYBaseCrypto {
|
|
|
10624
10613
|
signature(data, privateKey) {
|
|
10625
10614
|
try {
|
|
10626
10615
|
this._validateKey(privateKey, 32, 'SM2 private');
|
|
10627
|
-
const dataHex = this._uint8ArrayToHex(data);
|
|
10628
10616
|
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10629
|
-
const signature = sm2.doSignature(
|
|
10617
|
+
const signature = sm2.doSignature(Array.from(data), privateKeyHex);
|
|
10630
10618
|
if (!signature) throw new LYCryptoError('SM2 signature failed');
|
|
10631
10619
|
return signature;
|
|
10632
10620
|
} catch (error) {
|
|
@@ -10637,9 +10625,8 @@ class LYSMCrypto extends LYBaseCrypto {
|
|
|
10637
10625
|
verify(data, publicKey, signature) {
|
|
10638
10626
|
try {
|
|
10639
10627
|
this._validatePublicKey(publicKey);
|
|
10640
|
-
const dataHex = this._uint8ArrayToHex(data);
|
|
10641
10628
|
const publicKeyHex = this._uint8ArrayToHex(publicKey);
|
|
10642
|
-
return sm2.doVerifySignature(
|
|
10629
|
+
return sm2.doVerifySignature(Array.from(data), signature, publicKeyHex);
|
|
10643
10630
|
} catch (error) {
|
|
10644
10631
|
if (error instanceof LYCryptoError) throw error;
|
|
10645
10632
|
throw new LYCryptoError(`SM2 verify error: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -10648,9 +10635,8 @@ class LYSMCrypto extends LYBaseCrypto {
|
|
|
10648
10635
|
encryptAsymmetric(data, publicKey) {
|
|
10649
10636
|
try {
|
|
10650
10637
|
this._validatePublicKey(publicKey);
|
|
10651
|
-
const dataHex = this._uint8ArrayToHex(data);
|
|
10652
10638
|
const publicKeyHex = this._uint8ArrayToHex(publicKey);
|
|
10653
|
-
const encrypted = sm2.doEncrypt(
|
|
10639
|
+
const encrypted = sm2.doEncrypt(Array.from(data), publicKeyHex);
|
|
10654
10640
|
if (!encrypted) throw new LYCryptoError('SM2 encryption failed');
|
|
10655
10641
|
return this._hexToUint8Array(encrypted);
|
|
10656
10642
|
} catch (error) {
|
|
@@ -10665,7 +10651,7 @@ class LYSMCrypto extends LYBaseCrypto {
|
|
|
10665
10651
|
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10666
10652
|
const decrypted = sm2.doDecrypt(dataHex, privateKeyHex);
|
|
10667
10653
|
if (!decrypted) throw new LYCryptoError('SM2 decryption failed');
|
|
10668
|
-
return
|
|
10654
|
+
return new TextEncoder().encode(decrypted);
|
|
10669
10655
|
} catch (error) {
|
|
10670
10656
|
if (error instanceof LYCryptoError) throw error;
|
|
10671
10657
|
throw new LYCryptoError(`SM2 decryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -11647,20 +11633,23 @@ class LYRedirectAuthorizer extends LYBaseAuthorizer {
|
|
|
11647
11633
|
const queryParams = this._getQueryParams();
|
|
11648
11634
|
const code = queryParams.code;
|
|
11649
11635
|
const state = queryParams.state;
|
|
11636
|
+
const utm_source = queryParams.utm_source;
|
|
11650
11637
|
const locale = queryParams.ui_locales;
|
|
11651
11638
|
if (code && state) {
|
|
11652
11639
|
if (state !== redirectInfo.state) throw new Error('Invalid state parameter');
|
|
11653
11640
|
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11654
11641
|
if (locale) await app.i18n.changeLanguage(locale);
|
|
11655
11642
|
try {
|
|
11643
|
+
const params = {
|
|
11644
|
+
code: code,
|
|
11645
|
+
state: state,
|
|
11646
|
+
code_verifier: redirectInfo.code_verifier,
|
|
11647
|
+
redirect_uri: redirectInfo.redirect_uri
|
|
11648
|
+
};
|
|
11649
|
+
if (utm_source) params.utm_source = utm_source;
|
|
11656
11650
|
const response = await app.httpClient.post('sso/redirect/session', {
|
|
11657
11651
|
authentication_name: redirectInfo.authentication_name,
|
|
11658
|
-
query_params:
|
|
11659
|
-
code: code,
|
|
11660
|
-
code_verifier: redirectInfo.code_verifier,
|
|
11661
|
-
redirect_uri: redirectInfo.redirect_uri,
|
|
11662
|
-
state: redirectInfo.state
|
|
11663
|
-
}
|
|
11652
|
+
query_params: params
|
|
11664
11653
|
});
|
|
11665
11654
|
if (!response || !response.data.access_token) throw new Error('Invalid SSO response: missing access token');
|
|
11666
11655
|
LYSession.create('redirect', redirectInfo.authentication_name, response.data.id, response.data.access_token, response.data.user_id, response.data.user_name, response.data.expires_in, response.data.permission_codes, response.data.is_first_login, response.data.display_name, response.data.email, response.data.phone, response.data.country_code);
|
|
@@ -12035,10 +12024,6 @@ class LYOrganizationApp extends LYBaseOrganizationApp {
|
|
|
12035
12024
|
}
|
|
12036
12025
|
async doLoad() {
|
|
12037
12026
|
await super.doLoad();
|
|
12038
|
-
LYSession.setAllCodesProvider((appName)=>this.getAllPermissionCodes(appName));
|
|
12039
|
-
LYSession.setOnSessionCreated(async ()=>{
|
|
12040
|
-
await this.loadPermissionMeta();
|
|
12041
|
-
});
|
|
12042
12027
|
}
|
|
12043
12028
|
async loadPermissionMeta() {
|
|
12044
12029
|
try {
|