@laiye_packages/uci 1.0.3 → 1.0.5
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/base/index.d.ts +4 -5
- package/dist/app/index.d.ts +2 -2
- package/dist/app/organization/app/index.d.ts +4 -4
- package/dist/app/tenant/app/index.d.ts +3 -0
- package/dist/http/index.d.ts +1 -1
- package/dist/index.js +1094 -1094
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@ import { openDB } from "idb";
|
|
|
2
2
|
import events, { EventEmitter } from "events";
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import { cloneDeep } from "lodash";
|
|
5
|
+
import { sm2, sm3, sm4 } from "sm-crypto";
|
|
5
6
|
import i18next from "i18next";
|
|
6
7
|
import js_sha256 from "js-sha256";
|
|
7
|
-
import { sm2, sm3, sm4 } from "sm-crypto";
|
|
8
8
|
import qs from "qs";
|
|
9
9
|
import downloadjs from "downloadjs";
|
|
10
10
|
var __webpack_modules__ = {
|
|
@@ -9959,1281 +9959,1266 @@ LYSession = session_ts_decorate([
|
|
|
9959
9959
|
String
|
|
9960
9960
|
])
|
|
9961
9961
|
], LYSession);
|
|
9962
|
-
|
|
9962
|
+
class LYBaseCrypto {
|
|
9963
|
+
}
|
|
9964
|
+
function registerCryptoImpl(name1) {
|
|
9965
|
+
return function(impl) {
|
|
9966
|
+
if (cryptoImpl[name1]) throw new Error(`Crypto implementation for ${name1} already registered`);
|
|
9967
|
+
cryptoImpl[name1] = impl;
|
|
9968
|
+
return impl;
|
|
9969
|
+
};
|
|
9970
|
+
}
|
|
9971
|
+
const cryptoImpl = {
|
|
9972
|
+
default: void 0,
|
|
9973
|
+
sm: void 0,
|
|
9974
|
+
gm: void 0
|
|
9975
|
+
};
|
|
9976
|
+
function sm_ts_decorate(decorators, target, key, desc) {
|
|
9963
9977
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
9964
9978
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
9965
9979
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9966
9980
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9967
9981
|
}
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
const i18n_langKeys = Object.keys(i18n_LYLangEnum);
|
|
9977
|
-
const languages = {};
|
|
9978
|
-
const LANG_KEY = 'lang';
|
|
9979
|
-
class LYi18n extends LYObject {
|
|
9980
|
-
constructor(namespace){
|
|
9981
|
-
super();
|
|
9982
|
-
this._namespace = namespace || 'LY.';
|
|
9982
|
+
class LYSMCrypto extends LYBaseCrypto {
|
|
9983
|
+
_paddingIv(iv) {
|
|
9984
|
+
if (iv.length < 16) {
|
|
9985
|
+
const padded = new Uint8Array(16);
|
|
9986
|
+
padded.set(iv);
|
|
9987
|
+
return padded;
|
|
9988
|
+
}
|
|
9989
|
+
return iv.slice(0, 16);
|
|
9983
9990
|
}
|
|
9984
|
-
|
|
9985
|
-
return (
|
|
9986
|
-
if (!rest) return "<Null>";
|
|
9987
|
-
if (rest.includes(':')) return rest.startsWith(`${this.namespace}:`) ? i18next.t(rest, options) : i18next.t(`${this.namespace}.${rest}`, options);
|
|
9988
|
-
return i18next.t(`${this.namespace}:${rest}`, options);
|
|
9989
|
-
};
|
|
9991
|
+
_uint8ArrayToHex(array) {
|
|
9992
|
+
return Array.from(array).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
9990
9993
|
}
|
|
9991
|
-
|
|
9992
|
-
|
|
9994
|
+
_hexToUint8Array(hex) {
|
|
9995
|
+
if (hex.length % 2 !== 0) throw new LYCryptoError('Invalid hex string length');
|
|
9996
|
+
const result = new Uint8Array(hex.length / 2);
|
|
9997
|
+
for(let i = 0; i < hex.length; i += 2)result[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
9998
|
+
return result;
|
|
9993
9999
|
}
|
|
9994
|
-
|
|
9995
|
-
|
|
10000
|
+
_validateKey(key, expectedLength, keyType) {
|
|
10001
|
+
if (key.length !== expectedLength) throw new LYCryptoError(`Invalid ${keyType} key length: expected ${expectedLength}, got ${key.length}`);
|
|
9996
10002
|
}
|
|
9997
|
-
|
|
9998
|
-
|
|
10003
|
+
_validatePublicKey(key) {
|
|
10004
|
+
if (64 !== key.length && 65 !== key.length) throw new LYCryptoError(`Invalid SM2 public key length: expected 64 or 65, got ${key.length}`);
|
|
9999
10005
|
}
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
i18next.on('languageChanged', (lang)=>{
|
|
10003
|
-
if (this._lang !== lang) {
|
|
10004
|
-
this._lang = lang;
|
|
10005
|
-
this.emit('lang-changed', lang);
|
|
10006
|
-
}
|
|
10007
|
-
});
|
|
10008
|
-
if (i18next.isInitialized) return;
|
|
10009
|
-
const defaultVariables = {};
|
|
10010
|
-
const env = LYEnv.getInstance(this._namespace);
|
|
10011
|
-
for(const key in env)defaultVariables['$' + key] = env[key];
|
|
10012
|
-
await i18next.init({
|
|
10013
|
-
fallbackLng: 'zh-CN',
|
|
10014
|
-
lng: this._lang,
|
|
10015
|
-
defaultNS: this.namespace,
|
|
10016
|
-
returnObjects: true,
|
|
10017
|
-
interpolation: {
|
|
10018
|
-
escapeValue: false,
|
|
10019
|
-
defaultVariables
|
|
10020
|
-
}
|
|
10021
|
-
});
|
|
10022
|
-
await this.changeLanguage(this._lang);
|
|
10006
|
+
getSymmetricBlockSize(iv, key) {
|
|
10007
|
+
return 16;
|
|
10023
10008
|
}
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
return 'zh-CN';
|
|
10009
|
+
getAsymmetricBlockSize(publicKey) {
|
|
10010
|
+
return 16;
|
|
10027
10011
|
}
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10012
|
+
encryptSymmetric(data, iv, key) {
|
|
10013
|
+
try {
|
|
10014
|
+
this._validateKey(key, 16, 'SM4');
|
|
10015
|
+
const paddedIv = this._paddingIv(iv);
|
|
10016
|
+
const keyHex = this._uint8ArrayToHex(key);
|
|
10017
|
+
const ivHex = this._uint8ArrayToHex(paddedIv);
|
|
10018
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10019
|
+
const encrypted = sm4.encrypt(dataHex, keyHex, {
|
|
10020
|
+
iv: ivHex,
|
|
10021
|
+
mode: 'cbc',
|
|
10022
|
+
padding: 'pkcs#7'
|
|
10023
|
+
});
|
|
10024
|
+
if (!encrypted) throw new LYCryptoError('SM4 encryption failed');
|
|
10025
|
+
return this._hexToUint8Array(encrypted);
|
|
10026
|
+
} catch (error) {
|
|
10027
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10028
|
+
throw new LYCryptoError(`SM4 encryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10036
10029
|
}
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10030
|
+
}
|
|
10031
|
+
decryptSymmetric(data, iv, key) {
|
|
10032
|
+
try {
|
|
10033
|
+
this._validateKey(key, 16, 'SM4');
|
|
10034
|
+
const paddedIv = this._paddingIv(iv);
|
|
10035
|
+
const keyHex = this._uint8ArrayToHex(key);
|
|
10036
|
+
const ivHex = this._uint8ArrayToHex(paddedIv);
|
|
10037
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10038
|
+
const decrypted = sm4.decrypt(dataHex, keyHex, {
|
|
10039
|
+
iv: ivHex,
|
|
10040
|
+
mode: 'cbc',
|
|
10041
|
+
padding: 'pkcs#7'
|
|
10042
|
+
});
|
|
10043
|
+
if (!decrypted) throw new LYCryptoError('SM4 decryption failed');
|
|
10044
|
+
return this._hexToUint8Array(decrypted);
|
|
10045
|
+
} catch (error) {
|
|
10046
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10047
|
+
throw new LYCryptoError(`SM4 decryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10040
10048
|
}
|
|
10041
|
-
lang = sharedLocalStorage.getSync(LANG_KEY) || 'zh-CN';
|
|
10042
|
-
return lang;
|
|
10043
10049
|
}
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10050
|
+
signature(data, privateKey) {
|
|
10051
|
+
try {
|
|
10052
|
+
this._validateKey(privateKey, 32, 'SM2 private');
|
|
10053
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10054
|
+
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10055
|
+
const signature = sm2.doSignature(dataHex, privateKeyHex);
|
|
10056
|
+
if (!signature) throw new LYCryptoError('SM2 signature failed');
|
|
10057
|
+
return signature;
|
|
10058
|
+
} catch (error) {
|
|
10059
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10060
|
+
throw new LYCryptoError(`SM2 signature error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10049
10061
|
}
|
|
10050
|
-
if (!urlOrJson) return;
|
|
10051
|
-
lang = lang || this._lang;
|
|
10052
|
-
namespace = namespace ? `${this.namespace}.${namespace}` : this.namespace;
|
|
10053
|
-
i18next.addResourceBundle(lang, namespace, urlOrJson);
|
|
10054
10062
|
}
|
|
10055
|
-
|
|
10063
|
+
verify(data, publicKey, signature) {
|
|
10056
10064
|
try {
|
|
10057
|
-
|
|
10058
|
-
|
|
10065
|
+
this._validatePublicKey(publicKey);
|
|
10066
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10067
|
+
const publicKeyHex = this._uint8ArrayToHex(publicKey);
|
|
10068
|
+
return sm2.doVerifySignature(dataHex, signature, publicKeyHex);
|
|
10059
10069
|
} catch (error) {
|
|
10060
|
-
|
|
10061
|
-
|
|
10070
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10071
|
+
throw new LYCryptoError(`SM2 verify error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10062
10072
|
}
|
|
10063
10073
|
}
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
|
|
10074
|
+
encryptAsymmetric(data, publicKey) {
|
|
10075
|
+
try {
|
|
10076
|
+
this._validatePublicKey(publicKey);
|
|
10077
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10078
|
+
const publicKeyHex = this._uint8ArrayToHex(publicKey);
|
|
10079
|
+
const encrypted = sm2.doEncrypt(dataHex, publicKeyHex);
|
|
10080
|
+
if (!encrypted) throw new LYCryptoError('SM2 encryption failed');
|
|
10081
|
+
return this._hexToUint8Array(encrypted);
|
|
10082
|
+
} catch (error) {
|
|
10083
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10084
|
+
throw new LYCryptoError(`SM2 encryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10085
|
+
}
|
|
10073
10086
|
}
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
+
decryptAsymmetric(data, privateKey) {
|
|
10088
|
+
try {
|
|
10089
|
+
this._validateKey(privateKey, 32, 'SM2 private');
|
|
10090
|
+
const dataHex = this._uint8ArrayToHex(data);
|
|
10091
|
+
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10092
|
+
const decrypted = sm2.doDecrypt(dataHex, privateKeyHex);
|
|
10093
|
+
if (!decrypted) throw new LYCryptoError('SM2 decryption failed');
|
|
10094
|
+
return this._hexToUint8Array(decrypted);
|
|
10095
|
+
} catch (error) {
|
|
10096
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10097
|
+
throw new LYCryptoError(`SM2 decryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10098
|
+
}
|
|
10099
|
+
}
|
|
10100
|
+
hash(data, key) {
|
|
10101
|
+
try {
|
|
10102
|
+
if (key) {
|
|
10103
|
+
const hmacResult = sm3(data, {
|
|
10104
|
+
key,
|
|
10105
|
+
mode: 'hmac'
|
|
10106
|
+
});
|
|
10107
|
+
if (!hmacResult) throw new LYCryptoError('SM3 HMAC failed');
|
|
10108
|
+
return this._hexToUint8Array(hmacResult);
|
|
10109
|
+
}
|
|
10110
|
+
{
|
|
10111
|
+
const hashResult = sm3(data);
|
|
10112
|
+
if (!hashResult) throw new LYCryptoError('SM3 hash failed');
|
|
10113
|
+
return this._hexToUint8Array(hashResult);
|
|
10114
|
+
}
|
|
10115
|
+
} catch (error) {
|
|
10116
|
+
if (error instanceof LYCryptoError) throw error;
|
|
10117
|
+
throw new LYCryptoError(`SM3 hash error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10118
|
+
}
|
|
10087
10119
|
}
|
|
10088
10120
|
}
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
String
|
|
10094
|
-
])
|
|
10095
|
-
], LYi18n);
|
|
10096
|
-
function app_base_ts_decorate(decorators, target, key, desc) {
|
|
10121
|
+
LYSMCrypto = sm_ts_decorate([
|
|
10122
|
+
registerCryptoImpl("sm")
|
|
10123
|
+
], LYSMCrypto);
|
|
10124
|
+
function gm_ts_decorate(decorators, target, key, desc) {
|
|
10097
10125
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10098
10126
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10099
10127
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10100
10128
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10101
10129
|
}
|
|
10102
|
-
|
|
10103
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10130
|
+
class LYGMCrypto extends LYSMCrypto {
|
|
10104
10131
|
}
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
(
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
provideI18nResourcePath(app, lang) {
|
|
10114
|
-
const { i18n } = app;
|
|
10115
|
-
return `${app.env.baseUrl}/i18n/assets/${lang || i18n.lang}/`;
|
|
10116
|
-
}
|
|
10117
|
-
async provideI18nResource(app) {
|
|
10118
|
-
const { i18n } = app;
|
|
10119
|
-
const result = {};
|
|
10120
|
-
for (const key of i18n_langKeys){
|
|
10121
|
-
const lang = key;
|
|
10122
|
-
const resource = await i18n.getUrlResource(`${app.env.baseUrl}/i18n/locale/${lang}.json`);
|
|
10123
|
-
result[lang] = resource;
|
|
10124
|
-
}
|
|
10125
|
-
return result;
|
|
10126
|
-
}
|
|
10132
|
+
LYGMCrypto = gm_ts_decorate([
|
|
10133
|
+
registerCryptoImpl("gm")
|
|
10134
|
+
], LYGMCrypto);
|
|
10135
|
+
function crypto_ts_decorate(decorators, target, key, desc) {
|
|
10136
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10137
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10138
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10139
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10127
10140
|
}
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
this.
|
|
10137
|
-
}
|
|
10138
|
-
static get apps() {
|
|
10139
|
-
return base_LYBaseApp._apps;
|
|
10141
|
+
function crypto_ts_metadata(k, v) {
|
|
10142
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10143
|
+
}
|
|
10144
|
+
const LENGTH_SIZE = 2;
|
|
10145
|
+
class LYCrypto extends LYObject {
|
|
10146
|
+
constructor(){
|
|
10147
|
+
super();
|
|
10148
|
+
this._ivGetter = ()=>new Uint8Array(16);
|
|
10149
|
+
this._keyGetter = ()=>new Uint8Array(16);
|
|
10140
10150
|
}
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10151
|
+
get impl() {
|
|
10152
|
+
if (!this._impl) this._createImpl();
|
|
10153
|
+
if (!this._impl) throw new LYCryptoError('Crypto implementation not available');
|
|
10154
|
+
return this._impl;
|
|
10144
10155
|
}
|
|
10145
|
-
|
|
10146
|
-
if (this._initLock) throw new LYError('Application initialization in progress');
|
|
10147
|
-
this._initLock = true;
|
|
10156
|
+
_createImpl() {
|
|
10148
10157
|
try {
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
const Constructor = LYObject.getClass('LYOrganizationApp');
|
|
10156
|
-
base_LYBaseApp._apps[app.name] = new Constructor(app.name, app.version, '');
|
|
10157
|
-
} else {
|
|
10158
|
-
const specificAppClassName = this.getAppClassName(app.name);
|
|
10159
|
-
let Constructor;
|
|
10160
|
-
try {
|
|
10161
|
-
Constructor = LYObject.getClass(specificAppClassName);
|
|
10162
|
-
} catch {
|
|
10163
|
-
Constructor = LYObject.getClass('LYApp');
|
|
10164
|
-
}
|
|
10165
|
-
base_LYBaseApp._apps[app.name] = new Constructor(app.name, app.version, '');
|
|
10166
|
-
}
|
|
10167
|
-
}
|
|
10168
|
-
} finally{
|
|
10169
|
-
this._initLock = false;
|
|
10158
|
+
const config = this._getCryptoConfig();
|
|
10159
|
+
const implClass = cryptoImpl[config.type];
|
|
10160
|
+
if (!implClass) throw new LYCryptoError(`Crypto implementation ${config.type} not found`);
|
|
10161
|
+
this._impl = new implClass();
|
|
10162
|
+
} catch (error) {
|
|
10163
|
+
throw new LYCryptoError(`Failed to create crypto implementation: ${error instanceof Error ? error.message : String(error)}`);
|
|
10170
10164
|
}
|
|
10171
10165
|
}
|
|
10172
|
-
|
|
10173
|
-
|
|
10166
|
+
_getCryptoConfig() {
|
|
10167
|
+
const config = new LYCryptoConfig();
|
|
10168
|
+
config.type = 'sm';
|
|
10169
|
+
return config;
|
|
10174
10170
|
}
|
|
10175
|
-
|
|
10176
|
-
return
|
|
10171
|
+
_uint8ArrayToHex(array) {
|
|
10172
|
+
return Array.from(array).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
10177
10173
|
}
|
|
10178
|
-
|
|
10179
|
-
|
|
10174
|
+
_hexToUint8Array(hex) {
|
|
10175
|
+
if (hex.length % 2 !== 0) throw new LYCryptoError('Invalid hex string length');
|
|
10176
|
+
const result = new Uint8Array(hex.length / 2);
|
|
10177
|
+
for(let i = 0; i < hex.length; i += 2)result[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
10178
|
+
return result;
|
|
10180
10179
|
}
|
|
10181
|
-
|
|
10182
|
-
return
|
|
10180
|
+
_stringToUint8Array(str) {
|
|
10181
|
+
return new TextEncoder().encode(str);
|
|
10183
10182
|
}
|
|
10184
|
-
|
|
10185
|
-
|
|
10186
|
-
this._name = name1;
|
|
10187
|
-
this._version = version;
|
|
10188
|
-
this._description = description;
|
|
10189
|
-
this._i18n = new LYi18n(name1);
|
|
10190
|
-
const prefix = `${this._name}.`;
|
|
10191
|
-
this._localStore = new LYLocalStorage(prefix);
|
|
10192
|
-
this._sessionStore = new LYSessionStorage(prefix);
|
|
10193
|
-
this._cloudStore = new LYCloudStorage(prefix);
|
|
10194
|
-
this._env = new LYEnv(this._name);
|
|
10195
|
-
this._env.baseUrl = this.getBaseUrl();
|
|
10196
|
-
this._httpClient = this._createHttpClient();
|
|
10183
|
+
_uint8ArrayToString(array) {
|
|
10184
|
+
return new TextDecoder().decode(array);
|
|
10197
10185
|
}
|
|
10198
|
-
|
|
10199
|
-
|
|
10186
|
+
_base64ToUint8Array(base64) {
|
|
10187
|
+
const binaryString = atob(base64);
|
|
10188
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
10189
|
+
for(let i = 0; i < binaryString.length; i++)bytes[i] = binaryString.charCodeAt(i);
|
|
10190
|
+
return bytes;
|
|
10200
10191
|
}
|
|
10201
|
-
|
|
10202
|
-
|
|
10192
|
+
_uint8ArrayToBase64(array) {
|
|
10193
|
+
let binaryString = '';
|
|
10194
|
+
array.forEach((byte)=>{
|
|
10195
|
+
binaryString += String.fromCharCode(byte);
|
|
10196
|
+
});
|
|
10197
|
+
return btoa(binaryString);
|
|
10203
10198
|
}
|
|
10204
|
-
|
|
10205
|
-
|
|
10199
|
+
_getIvAndKey(iv, key) {
|
|
10200
|
+
const actualIv = iv ? 'string' == typeof iv ? this._hexToUint8Array(iv) : iv : this._ivGetter();
|
|
10201
|
+
const actualKey = key ? 'string' == typeof key ? this._hexToUint8Array(key) : key : this._keyGetter();
|
|
10202
|
+
return [
|
|
10203
|
+
actualIv,
|
|
10204
|
+
actualKey
|
|
10205
|
+
];
|
|
10206
10206
|
}
|
|
10207
|
-
|
|
10208
|
-
return this.
|
|
10207
|
+
_getKey(key, defaultKey) {
|
|
10208
|
+
if (key) return 'string' == typeof key ? this._hexToUint8Array(key) : key;
|
|
10209
|
+
if (defaultKey) return defaultKey;
|
|
10210
|
+
throw new LYCryptoError('Key not provided and no default key available');
|
|
10209
10211
|
}
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
+
_getEncryptPublicKey(publicKey) {
|
|
10213
|
+
const key = this._getKey(publicKey, this._encryptPublicKey);
|
|
10214
|
+
return key;
|
|
10212
10215
|
}
|
|
10213
|
-
|
|
10214
|
-
|
|
10216
|
+
_getDecryptPrivateKey(privateKey) {
|
|
10217
|
+
const key = this._getKey(privateKey, this._decryptPrivateKey);
|
|
10218
|
+
return key;
|
|
10215
10219
|
}
|
|
10216
|
-
|
|
10217
|
-
const
|
|
10218
|
-
|
|
10219
|
-
return session.permissions[this._name];
|
|
10220
|
+
_getSignaturePrivateKey(privateKey) {
|
|
10221
|
+
const key = this._getKey(privateKey, this._signaturePrivateKey);
|
|
10222
|
+
return key;
|
|
10220
10223
|
}
|
|
10221
|
-
|
|
10222
|
-
|
|
10224
|
+
_getVerifyPublicKey(publicKey) {
|
|
10225
|
+
const key = this._getKey(publicKey, this._verifyPublicKey);
|
|
10226
|
+
return key;
|
|
10223
10227
|
}
|
|
10224
|
-
|
|
10225
|
-
|
|
10228
|
+
async *_makeSize(data, size) {
|
|
10229
|
+
let buffer = new Uint8Array(0);
|
|
10230
|
+
for await (const chunk of data){
|
|
10231
|
+
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
10232
|
+
newBuffer.set(buffer);
|
|
10233
|
+
newBuffer.set(chunk, buffer.length);
|
|
10234
|
+
buffer = newBuffer;
|
|
10235
|
+
while(buffer.length >= size){
|
|
10236
|
+
yield buffer.slice(0, size);
|
|
10237
|
+
buffer = buffer.slice(size);
|
|
10238
|
+
}
|
|
10239
|
+
}
|
|
10240
|
+
if (buffer.length > 0) yield buffer;
|
|
10226
10241
|
}
|
|
10227
|
-
|
|
10228
|
-
|
|
10242
|
+
setSymmetricKeyGetter(ivGetter, keyGetter) {
|
|
10243
|
+
this._ivGetter = ivGetter;
|
|
10244
|
+
this._keyGetter = keyGetter;
|
|
10229
10245
|
}
|
|
10230
|
-
|
|
10231
|
-
|
|
10246
|
+
setEncryptPublicKey(publicKey) {
|
|
10247
|
+
this._encryptPublicKey = 'string' == typeof publicKey ? this._hexToUint8Array(publicKey) : publicKey;
|
|
10232
10248
|
}
|
|
10233
|
-
|
|
10234
|
-
|
|
10249
|
+
setDecryptPrivateKey(privateKey) {
|
|
10250
|
+
this._decryptPrivateKey = 'string' == typeof privateKey ? this._hexToUint8Array(privateKey) : privateKey;
|
|
10235
10251
|
}
|
|
10236
|
-
|
|
10237
|
-
|
|
10252
|
+
setSignaturePrivateKey(privateKey) {
|
|
10253
|
+
this._signaturePrivateKey = 'string' == typeof privateKey ? this._hexToUint8Array(privateKey) : privateKey;
|
|
10238
10254
|
}
|
|
10239
|
-
|
|
10240
|
-
|
|
10255
|
+
setVerifyPublicKey(publicKey) {
|
|
10256
|
+
this._verifyPublicKey = 'string' == typeof publicKey ? this._hexToUint8Array(publicKey) : publicKey;
|
|
10241
10257
|
}
|
|
10242
|
-
|
|
10243
|
-
return
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
}
|
|
10247
|
-
});
|
|
10258
|
+
encryptSymmetric(data, iv, key) {
|
|
10259
|
+
if ('string' == typeof data) return this._encryptSymmetricStr(data, iv, key);
|
|
10260
|
+
if (ArrayBuffer.isView(data)) return this._encryptSymmetricBytes(data, iv, key);
|
|
10261
|
+
return this._encryptSymmetricStream(data, iv, key);
|
|
10248
10262
|
}
|
|
10249
|
-
|
|
10250
|
-
if (
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
this._isLoaded = true;
|
|
10254
|
-
this.logger.info(`run ${this._name} app completed`);
|
|
10263
|
+
_encryptSymmetricBytes(data, iv, key) {
|
|
10264
|
+
if (!data || 0 === data.length) return new Uint8Array(data);
|
|
10265
|
+
const [actualIv, actualKey] = this._getIvAndKey(iv, key);
|
|
10266
|
+
return this.impl.encryptSymmetric(data, actualIv, actualKey);
|
|
10255
10267
|
}
|
|
10256
|
-
|
|
10257
|
-
const
|
|
10258
|
-
const
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
return baseUrl;
|
|
10269
|
-
}
|
|
10270
|
-
let filterhost = pattern.replace(/\./g, "\\.").replace("{tenant_name}", "([a-zA-Z0-9_\\-]+)");
|
|
10271
|
-
const reg = new RegExp(`^${filterhost}(?::\\d+)?(?:/.*)?$`);
|
|
10272
|
-
const matched = url.toString().match(reg);
|
|
10273
|
-
if (matched && matched[1]) {
|
|
10274
|
-
const tenantName = matched[1];
|
|
10275
|
-
const host = pattern.replace("{tenant_name}", tenantName);
|
|
10276
|
-
baseUrl = `${host}/view/${this.name}`;
|
|
10277
|
-
this._tenantName = tenantName;
|
|
10278
|
-
return baseUrl;
|
|
10268
|
+
_encryptSymmetricStr(data, iv, key) {
|
|
10269
|
+
const dataBytes = this._stringToUint8Array(data);
|
|
10270
|
+
const result = this._encryptSymmetricBytes(dataBytes, iv, key);
|
|
10271
|
+
return this._uint8ArrayToBase64(result);
|
|
10272
|
+
}
|
|
10273
|
+
async *_encryptSymmetricStream(data, iv, key) {
|
|
10274
|
+
const [actualIv, actualKey] = this._getIvAndKey(iv, key);
|
|
10275
|
+
const blockSize = this.impl.getSymmetricBlockSize(actualIv, actualKey);
|
|
10276
|
+
for await (const chunk of this._makeSize(data, blockSize)){
|
|
10277
|
+
if (!chunk || 0 === chunk.length) {
|
|
10278
|
+
yield chunk;
|
|
10279
|
+
continue;
|
|
10279
10280
|
}
|
|
10281
|
+
const buffer = this.impl.encryptSymmetric(chunk, actualIv, actualKey);
|
|
10282
|
+
const lengthBytes = new Uint8Array(LENGTH_SIZE);
|
|
10283
|
+
const view = new DataView(lengthBytes.buffer);
|
|
10284
|
+
view.setUint16(0, buffer.length, false);
|
|
10285
|
+
yield lengthBytes;
|
|
10286
|
+
yield buffer;
|
|
10280
10287
|
}
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10288
|
+
}
|
|
10289
|
+
decryptSymmetric(data, iv, key) {
|
|
10290
|
+
if ('string' == typeof data) return this._decryptSymmetricStr(data, iv, key);
|
|
10291
|
+
if (ArrayBuffer.isView(data)) return this._decryptSymmetricBytes(data, iv, key);
|
|
10292
|
+
return this._decryptSymmetricStream(data, iv, key);
|
|
10293
|
+
}
|
|
10294
|
+
_decryptSymmetricBytes(data, iv, key) {
|
|
10295
|
+
if (!data || 0 === data.length) return new Uint8Array(data);
|
|
10296
|
+
const [actualIv, actualKey] = this._getIvAndKey(iv, key);
|
|
10297
|
+
return this.impl.decryptSymmetric(data, actualIv, actualKey);
|
|
10298
|
+
}
|
|
10299
|
+
_decryptSymmetricStr(data, iv, key) {
|
|
10300
|
+
const dataBytes = this._base64ToUint8Array(data);
|
|
10301
|
+
const result = this._decryptSymmetricBytes(dataBytes, iv, key);
|
|
10302
|
+
return this._uint8ArrayToString(result);
|
|
10303
|
+
}
|
|
10304
|
+
async *_decryptSymmetricStream(data, iv, key) {
|
|
10305
|
+
const [actualIv, actualKey] = this._getIvAndKey(iv, key);
|
|
10306
|
+
let buffer = new Uint8Array(0);
|
|
10307
|
+
let size = -1;
|
|
10308
|
+
for await (const chunk of data){
|
|
10309
|
+
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
10310
|
+
newBuffer.set(buffer);
|
|
10311
|
+
newBuffer.set(chunk, buffer.length);
|
|
10312
|
+
buffer = newBuffer;
|
|
10313
|
+
while(true){
|
|
10314
|
+
if (size <= 0 && buffer.length < LENGTH_SIZE) break;
|
|
10315
|
+
if (size <= 0) {
|
|
10316
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset);
|
|
10317
|
+
size = view.getUint16(0, false);
|
|
10318
|
+
buffer = buffer.slice(LENGTH_SIZE);
|
|
10319
|
+
}
|
|
10320
|
+
if (buffer.length < size) break;
|
|
10321
|
+
const encryptedChunk = buffer.slice(0, size);
|
|
10322
|
+
yield this.impl.decryptSymmetric(encryptedChunk, actualIv, actualKey);
|
|
10323
|
+
buffer = buffer.slice(size);
|
|
10324
|
+
size = -1;
|
|
10286
10325
|
}
|
|
10287
|
-
const parts = url.pathname.split('/');
|
|
10288
|
-
const index = parts.findIndex((part)=>'view' === part);
|
|
10289
|
-
if (-1 === index) throw new Error('view not found in URL');
|
|
10290
|
-
let tenantName = parts[index + 2];
|
|
10291
|
-
if (!tenantName) throw new Error('tenantName not found');
|
|
10292
|
-
baseUrl = `${window.origin}/view/${this.name}/${tenantName}`;
|
|
10293
|
-
this._tenantName = tenantName;
|
|
10294
|
-
return baseUrl;
|
|
10295
|
-
} catch (error) {
|
|
10296
|
-
console.error('Error getting base URL:', error);
|
|
10297
10326
|
}
|
|
10298
|
-
|
|
10327
|
+
if (buffer.length > 0) yield this.impl.decryptSymmetric(buffer, actualIv, actualKey);
|
|
10299
10328
|
}
|
|
10300
|
-
|
|
10301
|
-
|
|
10329
|
+
encryptAsymmetric(data, publicKey) {
|
|
10330
|
+
if ('string' == typeof data) return this._encryptAsymmetricStr(data, publicKey);
|
|
10331
|
+
if (data instanceof Uint8Array) return this._encryptAsymmetricBytes(data, publicKey);
|
|
10332
|
+
return this._encryptAsymmetricStream(data, publicKey);
|
|
10302
10333
|
}
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
for(const key in resources)this._i18n.loadResource(resources[key] || {}, key);
|
|
10308
|
-
} catch (error) {
|
|
10309
|
-
this.logger.error('initI18n error');
|
|
10310
|
-
this.logger.error(error);
|
|
10311
|
-
}
|
|
10334
|
+
_encryptAsymmetricBytes(data, publicKey) {
|
|
10335
|
+
if (!data || 0 === data.length) return new Uint8Array(0);
|
|
10336
|
+
const key = this._getEncryptPublicKey(publicKey);
|
|
10337
|
+
return this.impl.encryptAsymmetric(data, key);
|
|
10312
10338
|
}
|
|
10313
|
-
|
|
10314
|
-
|
|
10339
|
+
_encryptAsymmetricStr(data, publicKey) {
|
|
10340
|
+
if (!data) return '';
|
|
10341
|
+
const dataBytes = this._stringToUint8Array(data);
|
|
10342
|
+
const result = this._encryptAsymmetricBytes(dataBytes, publicKey);
|
|
10343
|
+
return this._uint8ArrayToBase64(result);
|
|
10344
|
+
}
|
|
10345
|
+
async *_encryptAsymmetricStream(data, publicKey) {
|
|
10315
10346
|
try {
|
|
10316
|
-
const
|
|
10317
|
-
|
|
10347
|
+
const key = this._getEncryptPublicKey(publicKey);
|
|
10348
|
+
for await (const chunk of data){
|
|
10349
|
+
if (!chunk || 0 === chunk.length) {
|
|
10350
|
+
yield new Uint8Array(0);
|
|
10351
|
+
continue;
|
|
10352
|
+
}
|
|
10353
|
+
yield this.impl.encryptAsymmetric(chunk, key);
|
|
10354
|
+
}
|
|
10318
10355
|
} catch (error) {
|
|
10319
|
-
|
|
10356
|
+
throw new LYCryptoError(`Stream asymmetric encryption failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
10320
10357
|
}
|
|
10321
10358
|
}
|
|
10322
|
-
|
|
10323
|
-
if (
|
|
10324
|
-
|
|
10325
|
-
return this.
|
|
10359
|
+
decryptAsymmetric(data, privateKey) {
|
|
10360
|
+
if ('string' == typeof data) return this._decryptAsymmetricStr(data, privateKey);
|
|
10361
|
+
if (data instanceof Uint8Array) return this._decryptAsymmetricBytes(data, privateKey);
|
|
10362
|
+
return this._decryptAsymmetricStream(data, privateKey);
|
|
10326
10363
|
}
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10364
|
+
_decryptAsymmetricBytes(data, privateKey) {
|
|
10365
|
+
if (!data || 0 === data.length) return new Uint8Array(0);
|
|
10366
|
+
const key = this._getDecryptPrivateKey(privateKey);
|
|
10367
|
+
return this.impl.decryptAsymmetric(data, key);
|
|
10368
|
+
}
|
|
10369
|
+
_decryptAsymmetricStr(data, privateKey) {
|
|
10370
|
+
if (!data) return '';
|
|
10371
|
+
const dataBytes = this._base64ToUint8Array(data);
|
|
10372
|
+
const result = this._decryptAsymmetricBytes(dataBytes, privateKey);
|
|
10373
|
+
return this._uint8ArrayToString(result);
|
|
10374
|
+
}
|
|
10375
|
+
async *_decryptAsymmetricStream(data, privateKey) {
|
|
10332
10376
|
try {
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10377
|
+
const key = this._getDecryptPrivateKey(privateKey);
|
|
10378
|
+
for await (const chunk of data){
|
|
10379
|
+
if (!chunk || 0 === chunk.length) {
|
|
10380
|
+
yield new Uint8Array(0);
|
|
10381
|
+
continue;
|
|
10337
10382
|
}
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
this._remoteComponents = await remoteModule.default(this);
|
|
10383
|
+
yield this.impl.decryptAsymmetric(chunk, key);
|
|
10384
|
+
}
|
|
10341
10385
|
} catch (error) {
|
|
10342
|
-
|
|
10343
|
-
this.logger.error("loadRemoteComponents error:", error);
|
|
10344
|
-
} finally{
|
|
10345
|
-
this._isLoadingComponent = false;
|
|
10386
|
+
throw new LYCryptoError(`Stream asymmetric decryption failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
10346
10387
|
}
|
|
10347
|
-
return this._remoteComponents;
|
|
10348
|
-
}
|
|
10349
|
-
}
|
|
10350
|
-
base_LYBaseApp = app_base_ts_decorate([
|
|
10351
|
-
register('LYBaseApp'),
|
|
10352
|
-
base_ts_metadata("design:type", Function),
|
|
10353
|
-
base_ts_metadata("design:paramtypes", [
|
|
10354
|
-
String,
|
|
10355
|
-
String,
|
|
10356
|
-
String
|
|
10357
|
-
])
|
|
10358
|
-
], base_LYBaseApp);
|
|
10359
|
-
class LYBaseTenantApp extends base_LYBaseApp {
|
|
10360
|
-
_createHttpClient() {
|
|
10361
|
-
const lang = this._i18n.lang;
|
|
10362
|
-
return new LYTenantHttpClient(this.name, {
|
|
10363
|
-
get headers () {
|
|
10364
|
-
const session = LYSession.get();
|
|
10365
|
-
if (!session) return;
|
|
10366
|
-
return {
|
|
10367
|
-
Authorization: `Bearer ${session.token}`,
|
|
10368
|
-
'Accept-Language': lang
|
|
10369
|
-
};
|
|
10370
|
-
}
|
|
10371
|
-
});
|
|
10372
|
-
}
|
|
10373
|
-
}
|
|
10374
|
-
LYBaseTenantApp = app_base_ts_decorate([
|
|
10375
|
-
register('LYBaseTenantApp')
|
|
10376
|
-
], LYBaseTenantApp);
|
|
10377
|
-
class session_LYSessionApi {
|
|
10378
|
-
constructor(httpClient){
|
|
10379
|
-
this._httpClient = httpClient;
|
|
10380
10388
|
}
|
|
10381
|
-
|
|
10382
|
-
if (
|
|
10383
|
-
|
|
10384
|
-
name: ""
|
|
10385
|
-
};
|
|
10386
|
-
const result = await this._httpClient.post("/session", request);
|
|
10387
|
-
return result.data;
|
|
10389
|
+
signature(data, privateKey) {
|
|
10390
|
+
if ('string' == typeof data) return this._signatureStr(data, privateKey);
|
|
10391
|
+
return this._signatureBytes(data, privateKey);
|
|
10388
10392
|
}
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10393
|
+
_signatureBytes(data, privateKey) {
|
|
10394
|
+
if (!data || 0 === data.length) return '';
|
|
10395
|
+
const key = this._getSignaturePrivateKey(privateKey);
|
|
10396
|
+
return this.impl.signature(data, key);
|
|
10392
10397
|
}
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10398
|
+
_signatureStr(data, privateKey) {
|
|
10399
|
+
if (!data) return '';
|
|
10400
|
+
const dataBytes = this._stringToUint8Array(data);
|
|
10401
|
+
return this._signatureBytes(dataBytes, privateKey);
|
|
10396
10402
|
}
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
return
|
|
10403
|
+
verify(data, signature, publicKey) {
|
|
10404
|
+
if ('string' == typeof data) return this._verifyStr(data, signature, publicKey);
|
|
10405
|
+
return this._verifyBytes(data, signature, publicKey);
|
|
10400
10406
|
}
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
this.
|
|
10407
|
+
_verifyBytes(data, signature, publicKey) {
|
|
10408
|
+
if (!data || 0 === data.length || !signature) return false;
|
|
10409
|
+
const key = this._getVerifyPublicKey(publicKey);
|
|
10410
|
+
return this.impl.verify(data, key, signature);
|
|
10405
10411
|
}
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10412
|
+
_verifyStr(data, signature, publicKey) {
|
|
10413
|
+
if (!data || !signature) return false;
|
|
10414
|
+
const dataBytes = this._stringToUint8Array(data);
|
|
10415
|
+
return this._verifyBytes(dataBytes, signature, publicKey);
|
|
10409
10416
|
}
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
return
|
|
10417
|
+
hash(data, key, iterations) {
|
|
10418
|
+
if ('string' == typeof data) return this._hashStr(data, key, iterations);
|
|
10419
|
+
return this._hashBytes(data, key, iterations);
|
|
10413
10420
|
}
|
|
10414
|
-
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
return
|
|
10421
|
+
_hashBytes(data, key, iterations = 1) {
|
|
10422
|
+
if (!data || 0 === data.length) return new Uint8Array(0);
|
|
10423
|
+
const actualKey = key ? 'string' == typeof key ? this._hexToUint8Array(key) : key : void 0;
|
|
10424
|
+
let result = new Uint8Array(data);
|
|
10425
|
+
for(let i = 0; i < iterations; i++)result = new Uint8Array(this.impl.hash(result, actualKey));
|
|
10426
|
+
return result;
|
|
10420
10427
|
}
|
|
10421
|
-
|
|
10422
|
-
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
|
|
10426
|
-
return response.data.count;
|
|
10428
|
+
_hashStr(data, key, iterations = 1) {
|
|
10429
|
+
if (!data) return '';
|
|
10430
|
+
const dataBytes = this._stringToUint8Array(data);
|
|
10431
|
+
const result = this._hashBytes(dataBytes, key, iterations);
|
|
10432
|
+
return this._uint8ArrayToBase64(result);
|
|
10427
10433
|
}
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10434
|
+
}
|
|
10435
|
+
LYCrypto = crypto_ts_decorate([
|
|
10436
|
+
register('LYCrypto'),
|
|
10437
|
+
crypto_ts_metadata("design:type", Function),
|
|
10438
|
+
crypto_ts_metadata("design:paramtypes", [])
|
|
10439
|
+
], LYCrypto);
|
|
10440
|
+
const crypto_crypto = new LYCrypto();
|
|
10441
|
+
function i18n_ts_decorate(decorators, target, key, desc) {
|
|
10442
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10443
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10444
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10445
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10446
|
+
}
|
|
10447
|
+
function i18n_ts_metadata(k, v) {
|
|
10448
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10449
|
+
}
|
|
10450
|
+
var i18n_LYLangEnum = /*#__PURE__*/ function(LYLangEnum) {
|
|
10451
|
+
LYLangEnum["zh-CN"] = "简体中文";
|
|
10452
|
+
LYLangEnum["en-US"] = "English";
|
|
10453
|
+
return LYLangEnum;
|
|
10454
|
+
}({});
|
|
10455
|
+
const i18n_langKeys = Object.keys(i18n_LYLangEnum);
|
|
10456
|
+
const languages = {};
|
|
10457
|
+
const LANG_KEY = 'lang';
|
|
10458
|
+
class LYi18n extends LYObject {
|
|
10459
|
+
constructor(namespace){
|
|
10460
|
+
super();
|
|
10461
|
+
this._namespace = namespace || 'LY.';
|
|
10431
10462
|
}
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10463
|
+
get t() {
|
|
10464
|
+
return (rest, options)=>{
|
|
10465
|
+
if (!rest) return "<Null>";
|
|
10466
|
+
if (rest.includes(':')) return rest.startsWith(`${this.namespace}:`) ? i18next.t(rest, options) : i18next.t(`${this.namespace}.${rest}`, options);
|
|
10467
|
+
return i18next.t(`${this.namespace}:${rest}`, options);
|
|
10468
|
+
};
|
|
10437
10469
|
}
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
...request
|
|
10441
|
-
});
|
|
10442
|
-
return response.data;
|
|
10470
|
+
get lang() {
|
|
10471
|
+
return this._lang || this.resolveLanguage();
|
|
10443
10472
|
}
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
return response.data.available;
|
|
10473
|
+
get languages() {
|
|
10474
|
+
return languages;
|
|
10447
10475
|
}
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
current_password: currentPassword,
|
|
10451
|
-
new_password: newPassword
|
|
10452
|
-
});
|
|
10453
|
-
return response.data;
|
|
10476
|
+
get namespace() {
|
|
10477
|
+
return this._namespace;
|
|
10454
10478
|
}
|
|
10455
|
-
async
|
|
10456
|
-
|
|
10457
|
-
|
|
10479
|
+
async initialize() {
|
|
10480
|
+
if (!this._lang) this._lang = this.resolveLanguage();
|
|
10481
|
+
i18next.on('languageChanged', (lang)=>{
|
|
10482
|
+
if (this._lang !== lang) {
|
|
10483
|
+
this._lang = lang;
|
|
10484
|
+
this.emit('lang-changed', lang);
|
|
10485
|
+
}
|
|
10458
10486
|
});
|
|
10459
|
-
|
|
10487
|
+
if (i18next.isInitialized) return;
|
|
10488
|
+
const defaultVariables = {};
|
|
10489
|
+
const env = LYEnv.getInstance(this._namespace);
|
|
10490
|
+
for(const key in env)defaultVariables['$' + key] = env[key];
|
|
10491
|
+
await i18next.init({
|
|
10492
|
+
fallbackLng: 'zh-CN',
|
|
10493
|
+
lng: this._lang,
|
|
10494
|
+
defaultNS: this.namespace,
|
|
10495
|
+
returnObjects: true,
|
|
10496
|
+
interpolation: {
|
|
10497
|
+
escapeValue: false,
|
|
10498
|
+
defaultVariables
|
|
10499
|
+
}
|
|
10500
|
+
});
|
|
10501
|
+
await this.changeLanguage(this._lang);
|
|
10460
10502
|
}
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
constructor(app, name1){
|
|
10465
|
-
super();
|
|
10466
|
-
this._app = app;
|
|
10467
|
-
this._name = name1;
|
|
10503
|
+
fallbackLng(lang) {
|
|
10504
|
+
if (lang.includes('en')) return 'en-US';
|
|
10505
|
+
return 'zh-CN';
|
|
10468
10506
|
}
|
|
10469
|
-
|
|
10470
|
-
|
|
10507
|
+
resolveLanguage() {
|
|
10508
|
+
const langKeys = Object.keys(this.languages);
|
|
10509
|
+
if (1 === langKeys.length) return this.fallbackLng(langKeys[0]);
|
|
10510
|
+
const searchParams = new URLSearchParams(location.search);
|
|
10511
|
+
let lang = searchParams.get(LANG_KEY);
|
|
10512
|
+
if (lang) {
|
|
10513
|
+
lang = this.fallbackLng(lang);
|
|
10514
|
+
return lang;
|
|
10515
|
+
}
|
|
10516
|
+
if (!sharedLocalStorage.getSync(LANG_KEY)) {
|
|
10517
|
+
lang = this.fallbackLng(navigator.language);
|
|
10518
|
+
return lang;
|
|
10519
|
+
}
|
|
10520
|
+
lang = sharedLocalStorage.getSync(LANG_KEY) || 'zh-CN';
|
|
10521
|
+
return lang;
|
|
10471
10522
|
}
|
|
10472
|
-
|
|
10473
|
-
|
|
10523
|
+
async loadResource(urlOrJson, lang, namespace) {
|
|
10524
|
+
if ('string' == typeof urlOrJson) {
|
|
10525
|
+
const res = await this.getUrlResource(urlOrJson);
|
|
10526
|
+
if (!res) return;
|
|
10527
|
+
urlOrJson = res;
|
|
10528
|
+
}
|
|
10529
|
+
if (!urlOrJson) return;
|
|
10530
|
+
lang = lang || this._lang;
|
|
10531
|
+
namespace = namespace ? `${this.namespace}.${namespace}` : this.namespace;
|
|
10532
|
+
i18next.addResourceBundle(lang, namespace, urlOrJson);
|
|
10474
10533
|
}
|
|
10475
|
-
async
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10534
|
+
async getUrlResource(resourceUrl) {
|
|
10535
|
+
try {
|
|
10536
|
+
const res = await axios.get(resourceUrl);
|
|
10537
|
+
return res.data;
|
|
10538
|
+
} catch (error) {
|
|
10539
|
+
this.logger.error("loadUrlResource error");
|
|
10540
|
+
this.logger.error(error);
|
|
10541
|
+
}
|
|
10481
10542
|
}
|
|
10482
|
-
async
|
|
10483
|
-
|
|
10484
|
-
this.
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10543
|
+
async changeLanguage(lang) {
|
|
10544
|
+
this.logger.info(`changeLanguage lang to ${lang}`);
|
|
10545
|
+
this._lang = lang;
|
|
10546
|
+
i18next.isInitialized && await i18next.changeLanguage(lang);
|
|
10547
|
+
sharedLocalStorage.setSync(LANG_KEY, lang);
|
|
10548
|
+
const url = new URL(window.location.href);
|
|
10549
|
+
url.searchParams.delete(LANG_KEY);
|
|
10550
|
+
window.history.replaceState(null, '', url);
|
|
10551
|
+
i18next.isInitialized && this.emit('lang-changed', lang);
|
|
10552
|
+
}
|
|
10553
|
+
getResource(key, lang) {
|
|
10554
|
+
lang = lang || this._lang;
|
|
10555
|
+
let index = key.indexOf(':');
|
|
10556
|
+
key = index <= 0 ? `${this.namespace}:${key}` : key.startsWith(`${this.namespace}:`) ? key : `${this.namespace}.${key}`;
|
|
10557
|
+
index = key.indexOf(':');
|
|
10558
|
+
const ns = key.substring(0, index);
|
|
10559
|
+
const keys = key.substring(index + 1);
|
|
10560
|
+
if (!ns || !keys) return {};
|
|
10561
|
+
const res = i18next.getResourceBundle(lang, ns);
|
|
10562
|
+
if (!res) return {};
|
|
10563
|
+
const resource = keys.split('.').reduce((result, key)=>result[key], res);
|
|
10564
|
+
if (!resource && keys === this.namespace) return res;
|
|
10565
|
+
return resource;
|
|
10490
10566
|
}
|
|
10491
10567
|
}
|
|
10492
|
-
|
|
10568
|
+
LYi18n = i18n_ts_decorate([
|
|
10569
|
+
register('LYi18n'),
|
|
10570
|
+
i18n_ts_metadata("design:type", Function),
|
|
10571
|
+
i18n_ts_metadata("design:paramtypes", [
|
|
10572
|
+
String
|
|
10573
|
+
])
|
|
10574
|
+
], LYi18n);
|
|
10575
|
+
function app_base_ts_decorate(decorators, target, key, desc) {
|
|
10493
10576
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10494
10577
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10495
10578
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10496
10579
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10497
10580
|
}
|
|
10498
|
-
function
|
|
10581
|
+
function base_ts_metadata(k, v) {
|
|
10499
10582
|
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10500
10583
|
}
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10584
|
+
const CONFIG_URL = "/uci/system_info";
|
|
10585
|
+
const TENANT_APP_NAME = 'tenant';
|
|
10586
|
+
const ORGANIZATION_APP_NAME = 'organization';
|
|
10587
|
+
(0, runtime.init)({
|
|
10588
|
+
name: 'uci',
|
|
10589
|
+
remotes: []
|
|
10590
|
+
});
|
|
10591
|
+
class LYDefaultAppProvider extends LYObject {
|
|
10592
|
+
provideI18nResourcePath(app, lang) {
|
|
10593
|
+
const { i18n } = app;
|
|
10594
|
+
return `${app.env.baseUrl}/i18n/assets/${lang || i18n.lang}/`;
|
|
10506
10595
|
}
|
|
10507
|
-
async
|
|
10508
|
-
const
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
verification_code_id: args.verification_code_id
|
|
10517
|
-
});
|
|
10518
|
-
LYSession.create('web', '', response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes, response.is_first_login, response.display_name, response.email, response.phone, response.country_code);
|
|
10596
|
+
async provideI18nResource(app) {
|
|
10597
|
+
const { i18n } = app;
|
|
10598
|
+
const result = {};
|
|
10599
|
+
for (const key of i18n_langKeys){
|
|
10600
|
+
const lang = key;
|
|
10601
|
+
const resource = await i18n.getUrlResource(`${app.env.baseUrl}/i18n/locale/${lang}.json`);
|
|
10602
|
+
result[lang] = resource;
|
|
10603
|
+
}
|
|
10604
|
+
return result;
|
|
10519
10605
|
}
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10606
|
+
}
|
|
10607
|
+
LYDefaultAppProvider = app_base_ts_decorate([
|
|
10608
|
+
register('LYDefaultAppProvider')
|
|
10609
|
+
], LYDefaultAppProvider);
|
|
10610
|
+
class base_LYBaseApp extends LYObject {
|
|
10611
|
+
static{
|
|
10612
|
+
this._apps = {};
|
|
10526
10613
|
}
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
LYSession.update(response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
10614
|
+
static{
|
|
10615
|
+
this._initLock = false;
|
|
10530
10616
|
}
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
register('LYWebAuthorizer'),
|
|
10534
|
-
web_ts_metadata("design:type", Function),
|
|
10535
|
-
web_ts_metadata("design:paramtypes", [
|
|
10536
|
-
"undefined" == typeof LYBaseApp ? Object : LYBaseApp,
|
|
10537
|
-
String,
|
|
10538
|
-
"undefined" == typeof LYSessionApi ? Object : LYSessionApi
|
|
10539
|
-
])
|
|
10540
|
-
], LYWebAuthorizer);
|
|
10541
|
-
function gateway_ts_decorate(decorators, target, key, desc) {
|
|
10542
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10543
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10544
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10545
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10546
|
-
}
|
|
10547
|
-
class LYGatewayAuthorizer extends LYBaseAuthorizer {
|
|
10548
|
-
async _signin(args) {
|
|
10549
|
-
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10550
|
-
const response = await app.httpClient.post('sso/gateway/session');
|
|
10551
|
-
LYSession.create('gateway', '', response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
10617
|
+
static get apps() {
|
|
10618
|
+
return base_LYBaseApp._apps;
|
|
10552
10619
|
}
|
|
10553
|
-
|
|
10554
|
-
const
|
|
10555
|
-
|
|
10556
|
-
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10557
|
-
const response = await app.httpClient.post(`sso/gateway/session/delete/${session.id}`);
|
|
10558
|
-
if (0 === response.count) throw new Error('Session not found');
|
|
10559
|
-
LYSession.clear();
|
|
10620
|
+
static getAppClassName(appName) {
|
|
10621
|
+
const camelCase = appName.replace(/_([a-z])/g, (_, letter)=>letter.toUpperCase());
|
|
10622
|
+
return `LY${camelCase.charAt(0).toUpperCase() + camelCase.slice(1)}App`;
|
|
10560
10623
|
}
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
}
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10624
|
+
static async init(config_url = CONFIG_URL) {
|
|
10625
|
+
if (this._initLock) throw new LYError('Application initialization in progress');
|
|
10626
|
+
this._initLock = true;
|
|
10627
|
+
try {
|
|
10628
|
+
if (0 === Object.keys(base_LYBaseApp._apps).length) {
|
|
10629
|
+
const config = await LYConfig.load(config_url);
|
|
10630
|
+
for (const app of config.apps)if (app.name === TENANT_APP_NAME) {
|
|
10631
|
+
const Constructor = LYObject.getClass('LYTenantApp');
|
|
10632
|
+
base_LYBaseApp._apps[app.name] = new Constructor(app.name, app.version, '');
|
|
10633
|
+
} else if (app.name === ORGANIZATION_APP_NAME) {
|
|
10634
|
+
const Constructor = LYObject.getClass('LYOrganizationApp');
|
|
10635
|
+
base_LYBaseApp._apps[app.name] = new Constructor(app.name, app.version, '');
|
|
10636
|
+
} else {
|
|
10637
|
+
const specificAppClassName = this.getAppClassName(app.name);
|
|
10638
|
+
let Constructor;
|
|
10639
|
+
try {
|
|
10640
|
+
Constructor = LYObject.getClass(specificAppClassName);
|
|
10641
|
+
} catch {
|
|
10642
|
+
Constructor = LYObject.getClass('LYApp');
|
|
10643
|
+
}
|
|
10644
|
+
base_LYBaseApp._apps[app.name] = new Constructor(app.name, app.version, '');
|
|
10645
|
+
}
|
|
10646
|
+
}
|
|
10647
|
+
} finally{
|
|
10648
|
+
this._initLock = false;
|
|
10649
|
+
}
|
|
10580
10650
|
}
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
if (!session) throw new Error('Session not found');
|
|
10584
|
-
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10585
|
-
const response = await app.httpClient.post(`sso/direct/session/delete/${session.id}`, {
|
|
10586
|
-
authentication_name: session.authentication_name
|
|
10587
|
-
});
|
|
10588
|
-
if (0 === response.count) throw new Error('Session not found');
|
|
10589
|
-
LYSession.clear();
|
|
10651
|
+
static getAll() {
|
|
10652
|
+
return this._apps;
|
|
10590
10653
|
}
|
|
10591
|
-
|
|
10592
|
-
|
|
10593
|
-
register('LYDirectAuthorizer')
|
|
10594
|
-
], LYDirectAuthorizer);
|
|
10595
|
-
function redirect_ts_decorate(decorators, target, key, desc) {
|
|
10596
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10597
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10598
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10599
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10600
|
-
}
|
|
10601
|
-
const REDIRECT_STORAGE_KEY = 'sso_redirect_info';
|
|
10602
|
-
const REDIRECT_STORAGE_EXPIRES_IN = 600000;
|
|
10603
|
-
class PKCEUtils {
|
|
10604
|
-
static generateCodeVerifier() {
|
|
10605
|
-
const array = new Uint8Array(32);
|
|
10606
|
-
crypto.getRandomValues(array);
|
|
10607
|
-
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
10654
|
+
static get(name1) {
|
|
10655
|
+
return this._apps[name1];
|
|
10608
10656
|
}
|
|
10609
|
-
static
|
|
10610
|
-
|
|
10611
|
-
const data = encoder.encode(codeVerifier);
|
|
10612
|
-
let digest;
|
|
10613
|
-
digest = crypto.subtle ? await crypto.subtle.digest('SHA-256', data) : js_sha256.sha256.arrayBuffer(data);
|
|
10614
|
-
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(digest)))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
10657
|
+
static setHeaderProvider(headerProvider) {
|
|
10658
|
+
base_LYBaseApp._headerProvider = headerProvider;
|
|
10615
10659
|
}
|
|
10616
|
-
static
|
|
10617
|
-
|
|
10618
|
-
crypto.getRandomValues(array);
|
|
10619
|
-
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
10660
|
+
static getHeaderProvider() {
|
|
10661
|
+
return base_LYBaseApp._headerProvider;
|
|
10620
10662
|
}
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
if (locale) await app.i18n.changeLanguage(locale);
|
|
10635
|
-
try {
|
|
10636
|
-
const response = await app.httpClient.post('sso/redirect/session', {
|
|
10637
|
-
authentication_name: redirectInfo.authentication_name,
|
|
10638
|
-
query_params: {
|
|
10639
|
-
code: code,
|
|
10640
|
-
code_verifier: redirectInfo.code_verifier,
|
|
10641
|
-
redirect_uri: redirectInfo.redirect_uri,
|
|
10642
|
-
state: redirectInfo.state
|
|
10643
|
-
}
|
|
10644
|
-
});
|
|
10645
|
-
if (!response || !response.data.access_token) throw new Error('Invalid SSO response: missing access token');
|
|
10646
|
-
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);
|
|
10647
|
-
this.emit('status-change', 'signed-in');
|
|
10648
|
-
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
10649
|
-
setTimeout(()=>{
|
|
10650
|
-
window.location.href = redirectInfo.redirect_uri;
|
|
10651
|
-
}, 0);
|
|
10652
|
-
return;
|
|
10653
|
-
} catch (error) {
|
|
10654
|
-
console.error('SSO login failed:', error);
|
|
10655
|
-
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
10656
|
-
}
|
|
10657
|
-
}
|
|
10658
|
-
}
|
|
10659
|
-
if (args.sso_config) await this._jumpToSSO(args.sso_config, args.redirect_uri);
|
|
10660
|
-
else throw new Error('SSO configuration not provided');
|
|
10663
|
+
constructor(name1, version, description){
|
|
10664
|
+
super(), this._isLoaded = false;
|
|
10665
|
+
this._name = name1;
|
|
10666
|
+
this._version = version;
|
|
10667
|
+
this._description = description;
|
|
10668
|
+
this._i18n = new LYi18n(name1);
|
|
10669
|
+
const prefix = `${this._name}.`;
|
|
10670
|
+
this._localStore = new LYLocalStorage(prefix);
|
|
10671
|
+
this._sessionStore = new LYSessionStorage(prefix);
|
|
10672
|
+
this._cloudStore = new LYCloudStorage(prefix);
|
|
10673
|
+
this._env = new LYEnv(this._name);
|
|
10674
|
+
this.env.baseUrl = this.getBaseUrl();
|
|
10675
|
+
this._httpClient = this._createHttpClient();
|
|
10661
10676
|
}
|
|
10662
|
-
|
|
10663
|
-
return this.
|
|
10677
|
+
get location() {
|
|
10678
|
+
return this._name;
|
|
10664
10679
|
}
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
const codeChallenge = await PKCEUtils.generateCodeChallenge(codeVerifier);
|
|
10668
|
-
const state = PKCEUtils.generateState();
|
|
10669
|
-
const ssoUrl = new URL(ssoConfig.auth_url);
|
|
10670
|
-
ssoUrl.searchParams.set('code_challenge', codeChallenge);
|
|
10671
|
-
ssoUrl.searchParams.set('code_challenge_method', 'S256');
|
|
10672
|
-
ssoUrl.searchParams.set('state', state);
|
|
10673
|
-
sharedLocalStorage.setSync(REDIRECT_STORAGE_KEY, {
|
|
10674
|
-
authentication_name: ssoConfig.name,
|
|
10675
|
-
redirect_uri: redirectUri,
|
|
10676
|
-
expires_at: new Date(Date.now() + REDIRECT_STORAGE_EXPIRES_IN),
|
|
10677
|
-
code_verifier: codeVerifier,
|
|
10678
|
-
state: state,
|
|
10679
|
-
sso_config: ssoConfig
|
|
10680
|
-
});
|
|
10681
|
-
setTimeout(()=>{
|
|
10682
|
-
window.location.href = ssoUrl.toString();
|
|
10683
|
-
}, 0);
|
|
10680
|
+
get name() {
|
|
10681
|
+
return this._name;
|
|
10684
10682
|
}
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
10688
|
-
urlParams.forEach((value, key)=>{
|
|
10689
|
-
params[key] = value;
|
|
10690
|
-
});
|
|
10691
|
-
return params;
|
|
10683
|
+
get tenantName() {
|
|
10684
|
+
return this._tenantName;
|
|
10692
10685
|
}
|
|
10693
|
-
|
|
10694
|
-
|
|
10686
|
+
get version() {
|
|
10687
|
+
return this._version;
|
|
10695
10688
|
}
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
if (!session) throw new Error('Session not found');
|
|
10699
|
-
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10700
|
-
const response = await app.httpClient.post(`sso/redirect/session/delete/${session.id}`, {
|
|
10701
|
-
authentication_name: session.authentication_name
|
|
10702
|
-
});
|
|
10703
|
-
if (0 === response.data.count) throw new Error('Session not found');
|
|
10704
|
-
LYSession.clear();
|
|
10705
|
-
if (response.data.logout_url) {
|
|
10706
|
-
this.emit('status-change', 'signed-out');
|
|
10707
|
-
window.location.href = response.data.logout_url;
|
|
10708
|
-
}
|
|
10689
|
+
get description() {
|
|
10690
|
+
return this._description;
|
|
10709
10691
|
}
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
register('LYRedirectAuthorizer')
|
|
10713
|
-
], LYRedirectAuthorizer);
|
|
10714
|
-
class LYLicenseApi {
|
|
10715
|
-
constructor(httpClient){
|
|
10716
|
-
this._httpClient = httpClient;
|
|
10692
|
+
get httpClient() {
|
|
10693
|
+
return this._httpClient;
|
|
10717
10694
|
}
|
|
10718
|
-
|
|
10719
|
-
const
|
|
10720
|
-
|
|
10695
|
+
get permission() {
|
|
10696
|
+
const session = LYSession.get();
|
|
10697
|
+
if (!session) throw new Error('session not found');
|
|
10698
|
+
return session.permissions[this._name];
|
|
10721
10699
|
}
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
return response.data;
|
|
10700
|
+
get provider() {
|
|
10701
|
+
return this._provider || new LYDefaultAppProvider();
|
|
10725
10702
|
}
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
return response.data.id;
|
|
10703
|
+
get i18n() {
|
|
10704
|
+
return this._i18n;
|
|
10729
10705
|
}
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
return response.data;
|
|
10706
|
+
get localStore() {
|
|
10707
|
+
return this._localStore;
|
|
10733
10708
|
}
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
return response.data;
|
|
10709
|
+
get sessionStore() {
|
|
10710
|
+
return this._sessionStore;
|
|
10737
10711
|
}
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
return response.data.count;
|
|
10712
|
+
get cloudStore() {
|
|
10713
|
+
return this._cloudStore;
|
|
10741
10714
|
}
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
return response.data;
|
|
10715
|
+
get isLoaded() {
|
|
10716
|
+
return this._isLoaded;
|
|
10745
10717
|
}
|
|
10746
|
-
|
|
10747
|
-
|
|
10748
|
-
return response.data;
|
|
10749
|
-
}
|
|
10750
|
-
async getLogs(licenseId, tokenId) {
|
|
10751
|
-
const response = await this._httpClient.get("/license/log", {
|
|
10752
|
-
license_id: licenseId,
|
|
10753
|
-
token_id: tokenId
|
|
10754
|
-
});
|
|
10755
|
-
return response.data;
|
|
10756
|
-
}
|
|
10757
|
-
}
|
|
10758
|
-
class LYBaseCrypto {
|
|
10759
|
-
}
|
|
10760
|
-
function registerCryptoImpl(name1) {
|
|
10761
|
-
return function(impl) {
|
|
10762
|
-
if (cryptoImpl[name1]) throw new Error(`Crypto implementation for ${name1} already registered`);
|
|
10763
|
-
cryptoImpl[name1] = impl;
|
|
10764
|
-
return impl;
|
|
10765
|
-
};
|
|
10766
|
-
}
|
|
10767
|
-
const cryptoImpl = {
|
|
10768
|
-
default: void 0,
|
|
10769
|
-
sm: void 0,
|
|
10770
|
-
gm: void 0
|
|
10771
|
-
};
|
|
10772
|
-
function sm_ts_decorate(decorators, target, key, desc) {
|
|
10773
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10774
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10775
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10776
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10777
|
-
}
|
|
10778
|
-
class LYSMCrypto extends LYBaseCrypto {
|
|
10779
|
-
_paddingIv(iv) {
|
|
10780
|
-
if (iv.length < 16) {
|
|
10781
|
-
const padded = new Uint8Array(16);
|
|
10782
|
-
padded.set(iv);
|
|
10783
|
-
return padded;
|
|
10784
|
-
}
|
|
10785
|
-
return iv.slice(0, 16);
|
|
10786
|
-
}
|
|
10787
|
-
_uint8ArrayToHex(array) {
|
|
10788
|
-
return Array.from(array).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
10789
|
-
}
|
|
10790
|
-
_hexToUint8Array(hex) {
|
|
10791
|
-
if (hex.length % 2 !== 0) throw new LYCryptoError('Invalid hex string length');
|
|
10792
|
-
const result = new Uint8Array(hex.length / 2);
|
|
10793
|
-
for(let i = 0; i < hex.length; i += 2)result[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
10794
|
-
return result;
|
|
10795
|
-
}
|
|
10796
|
-
_validateKey(key, expectedLength, keyType) {
|
|
10797
|
-
if (key.length !== expectedLength) throw new LYCryptoError(`Invalid ${keyType} key length: expected ${expectedLength}, got ${key.length}`);
|
|
10718
|
+
get env() {
|
|
10719
|
+
return this._env;
|
|
10798
10720
|
}
|
|
10799
|
-
|
|
10800
|
-
|
|
10721
|
+
get crypto() {
|
|
10722
|
+
return crypto_crypto;
|
|
10801
10723
|
}
|
|
10802
|
-
|
|
10803
|
-
return
|
|
10724
|
+
_createHttpClient() {
|
|
10725
|
+
return new http_LYAppHttpClient(this._name, {
|
|
10726
|
+
get headers () {
|
|
10727
|
+
return base_LYBaseApp.getHeaderProvider().headers;
|
|
10728
|
+
}
|
|
10729
|
+
});
|
|
10804
10730
|
}
|
|
10805
|
-
|
|
10806
|
-
return
|
|
10731
|
+
async load() {
|
|
10732
|
+
if (this._isLoaded) return;
|
|
10733
|
+
this.logger.info(`start run ${this._name} app`);
|
|
10734
|
+
await this.doLoad();
|
|
10735
|
+
this._isLoaded = true;
|
|
10736
|
+
this.logger.info(`run ${this._name} app completed`);
|
|
10807
10737
|
}
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
this._validateKey(key, 16, 'SM4');
|
|
10811
|
-
const paddedIv = this._paddingIv(iv);
|
|
10812
|
-
const keyHex = this._uint8ArrayToHex(key);
|
|
10813
|
-
const ivHex = this._uint8ArrayToHex(paddedIv);
|
|
10814
|
-
const dataHex = this._uint8ArrayToHex(data);
|
|
10815
|
-
const encrypted = sm4.encrypt(dataHex, keyHex, {
|
|
10816
|
-
iv: ivHex,
|
|
10817
|
-
mode: 'cbc',
|
|
10818
|
-
padding: 'pkcs#7'
|
|
10819
|
-
});
|
|
10820
|
-
if (!encrypted) throw new LYCryptoError('SM4 encryption failed');
|
|
10821
|
-
return this._hexToUint8Array(encrypted);
|
|
10822
|
-
} catch (error) {
|
|
10823
|
-
if (error instanceof LYCryptoError) throw error;
|
|
10824
|
-
throw new LYCryptoError(`SM4 encryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10825
|
-
}
|
|
10738
|
+
async doLoad() {
|
|
10739
|
+
await this.initI18n();
|
|
10826
10740
|
}
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10741
|
+
getBaseUrl() {
|
|
10742
|
+
const config = LYConfig.get();
|
|
10743
|
+
const url = new URL(window.location.href);
|
|
10744
|
+
let baseUrl = "";
|
|
10745
|
+
for (const pattern of config.host_patterns){
|
|
10746
|
+
if (!pattern.includes("{tenant_name}") && pattern.startsWith(url.origin)) {
|
|
10747
|
+
const parts = url.pathname.split('/');
|
|
10748
|
+
const index = parts.findIndex((part)=>'view' === part);
|
|
10749
|
+
let tenantName = parts[index + 2];
|
|
10750
|
+
if (!tenantName) throw new Error('tenantName not found');
|
|
10751
|
+
baseUrl = `${pattern}/view/${this.name}/${tenantName}`;
|
|
10752
|
+
this._tenantName = tenantName;
|
|
10753
|
+
return baseUrl;
|
|
10754
|
+
}
|
|
10755
|
+
let filterhost = pattern.replace(/\./g, "\\.").replace("{tenant_name}", "([a-zA-Z0-9_\\-]+)");
|
|
10756
|
+
const reg = new RegExp(`^${filterhost}(?::\\d+)?(?:/.*)?$`);
|
|
10757
|
+
const matched = url.toString().match(reg);
|
|
10758
|
+
if (matched && matched[1]) {
|
|
10759
|
+
const tenantName = matched[1];
|
|
10760
|
+
const host = pattern.replace("{tenant_name}", tenantName);
|
|
10761
|
+
baseUrl = `${host}/view/${this.name}`;
|
|
10762
|
+
this._tenantName = tenantName;
|
|
10763
|
+
return baseUrl;
|
|
10764
|
+
}
|
|
10844
10765
|
}
|
|
10845
|
-
}
|
|
10846
|
-
signature(data, privateKey) {
|
|
10847
10766
|
try {
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10767
|
+
if ('development' === process.env.NODE_ENV) {
|
|
10768
|
+
baseUrl = `${window.origin}/view/${this.name}/laiye`;
|
|
10769
|
+
this._tenantName = "laiye";
|
|
10770
|
+
return baseUrl;
|
|
10771
|
+
}
|
|
10772
|
+
const parts = url.pathname.split('/');
|
|
10773
|
+
const index = parts.findIndex((part)=>'view' === part);
|
|
10774
|
+
if (-1 === index) throw new Error('view not found in URL');
|
|
10775
|
+
let tenantName = parts[index + 2];
|
|
10776
|
+
if (!tenantName) throw new Error('tenantName not found');
|
|
10777
|
+
baseUrl = `${window.origin}/view/${this.name}/${tenantName}`;
|
|
10778
|
+
this._tenantName = tenantName;
|
|
10779
|
+
return baseUrl;
|
|
10854
10780
|
} catch (error) {
|
|
10855
|
-
|
|
10856
|
-
throw new LYCryptoError(`SM2 signature error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10781
|
+
console.error('Error getting base URL:', error);
|
|
10857
10782
|
}
|
|
10783
|
+
return window.origin;
|
|
10858
10784
|
}
|
|
10859
|
-
|
|
10785
|
+
async initI18n() {
|
|
10860
10786
|
try {
|
|
10861
|
-
this.
|
|
10862
|
-
|
|
10863
|
-
const
|
|
10864
|
-
return sm2.doVerifySignature(dataHex, signature, publicKeyHex);
|
|
10787
|
+
const resources = await this.provider.provideI18nResource(this);
|
|
10788
|
+
await this._i18n.initialize();
|
|
10789
|
+
for(const key in resources)this._i18n.loadResource(resources[key] || {}, key);
|
|
10865
10790
|
} catch (error) {
|
|
10866
|
-
|
|
10867
|
-
|
|
10791
|
+
this.logger.error('initI18n error');
|
|
10792
|
+
this.logger.error(error);
|
|
10868
10793
|
}
|
|
10869
10794
|
}
|
|
10870
|
-
|
|
10795
|
+
getI18nResourceUrl(relativeUrl, lang) {
|
|
10796
|
+
const baseUrl = this.provider.provideI18nResourcePath(this, lang) || '';
|
|
10871
10797
|
try {
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
const publicKeyHex = this._uint8ArrayToHex(publicKey);
|
|
10875
|
-
const encrypted = sm2.doEncrypt(dataHex, publicKeyHex);
|
|
10876
|
-
if (!encrypted) throw new LYCryptoError('SM2 encryption failed');
|
|
10877
|
-
return this._hexToUint8Array(encrypted);
|
|
10798
|
+
const url = new URL(relativeUrl, baseUrl);
|
|
10799
|
+
return url.toString();
|
|
10878
10800
|
} catch (error) {
|
|
10879
|
-
|
|
10880
|
-
throw new LYCryptoError(`SM2 encryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10801
|
+
return `${baseUrl}/${relativeUrl}`;
|
|
10881
10802
|
}
|
|
10882
10803
|
}
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10888
|
-
const decrypted = sm2.doDecrypt(dataHex, privateKeyHex);
|
|
10889
|
-
if (!decrypted) throw new LYCryptoError('SM2 decryption failed');
|
|
10890
|
-
return this._hexToUint8Array(decrypted);
|
|
10891
|
-
} catch (error) {
|
|
10892
|
-
if (error instanceof LYCryptoError) throw error;
|
|
10893
|
-
throw new LYCryptoError(`SM2 decryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10894
|
-
}
|
|
10804
|
+
async getComponent(componentName) {
|
|
10805
|
+
if (this._remoteComponents) return this._remoteComponents[componentName];
|
|
10806
|
+
await this.loadRemoteComponents();
|
|
10807
|
+
return this._remoteComponents[componentName];
|
|
10895
10808
|
}
|
|
10896
|
-
|
|
10809
|
+
async loadRemoteComponents() {
|
|
10810
|
+
const isLoaded = this._isLoadingComponent;
|
|
10811
|
+
while(this._isLoadingComponent)await wait();
|
|
10812
|
+
if (isLoaded) return this._remoteComponents;
|
|
10813
|
+
this._isLoadingComponent = true;
|
|
10897
10814
|
try {
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
}
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
{
|
|
10907
|
-
const hashResult = sm3(data);
|
|
10908
|
-
if (!hashResult) throw new LYCryptoError('SM3 hash failed');
|
|
10909
|
-
return this._hexToUint8Array(hashResult);
|
|
10910
|
-
}
|
|
10815
|
+
(0, runtime.registerRemotes)([
|
|
10816
|
+
{
|
|
10817
|
+
name: this.name,
|
|
10818
|
+
entry: `${this.env.baseUrl}/mf-manifest.json`
|
|
10819
|
+
}
|
|
10820
|
+
]);
|
|
10821
|
+
const remoteModule = await (0, runtime.loadRemote)(`${this.name}/Index`);
|
|
10822
|
+
this._remoteComponents = await remoteModule.default(this);
|
|
10911
10823
|
} catch (error) {
|
|
10912
|
-
|
|
10913
|
-
|
|
10824
|
+
this._remoteComponents = {};
|
|
10825
|
+
this.logger.error("loadRemoteComponents error:", error);
|
|
10826
|
+
} finally{
|
|
10827
|
+
this._isLoadingComponent = false;
|
|
10914
10828
|
}
|
|
10829
|
+
return this._remoteComponents;
|
|
10915
10830
|
}
|
|
10916
10831
|
}
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
class
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
registerCryptoImpl("gm")
|
|
10930
|
-
], LYGMCrypto);
|
|
10931
|
-
function crypto_ts_decorate(decorators, target, key, desc) {
|
|
10932
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10933
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10934
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10935
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10936
|
-
}
|
|
10937
|
-
function crypto_ts_metadata(k, v) {
|
|
10938
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10939
|
-
}
|
|
10940
|
-
const LENGTH_SIZE = 2;
|
|
10941
|
-
class LYCrypto extends LYObject {
|
|
10942
|
-
constructor(){
|
|
10943
|
-
super();
|
|
10944
|
-
this._ivGetter = ()=>new Uint8Array(16);
|
|
10945
|
-
this._keyGetter = ()=>new Uint8Array(16);
|
|
10946
|
-
}
|
|
10947
|
-
get impl() {
|
|
10948
|
-
if (!this._impl) this._createImpl();
|
|
10949
|
-
if (!this._impl) throw new LYCryptoError('Crypto implementation not available');
|
|
10950
|
-
return this._impl;
|
|
10832
|
+
base_LYBaseApp = app_base_ts_decorate([
|
|
10833
|
+
register('LYBaseApp'),
|
|
10834
|
+
base_ts_metadata("design:type", Function),
|
|
10835
|
+
base_ts_metadata("design:paramtypes", [
|
|
10836
|
+
String,
|
|
10837
|
+
String,
|
|
10838
|
+
String
|
|
10839
|
+
])
|
|
10840
|
+
], base_LYBaseApp);
|
|
10841
|
+
class session_LYSessionApi {
|
|
10842
|
+
constructor(httpClient){
|
|
10843
|
+
this._httpClient = httpClient;
|
|
10951
10844
|
}
|
|
10952
|
-
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
throw new LYCryptoError(`Failed to create crypto implementation: ${error instanceof Error ? error.message : String(error)}`);
|
|
10960
|
-
}
|
|
10845
|
+
async create(request) {
|
|
10846
|
+
if (!request.name) request = {
|
|
10847
|
+
...request,
|
|
10848
|
+
name: ""
|
|
10849
|
+
};
|
|
10850
|
+
const result = await this._httpClient.post("/session", request);
|
|
10851
|
+
return result.data;
|
|
10961
10852
|
}
|
|
10962
|
-
|
|
10963
|
-
const
|
|
10964
|
-
|
|
10965
|
-
return config;
|
|
10853
|
+
async update(id) {
|
|
10854
|
+
const response = await this._httpClient.post(`/session/patch/${id}`);
|
|
10855
|
+
return response.data;
|
|
10966
10856
|
}
|
|
10967
|
-
|
|
10968
|
-
|
|
10857
|
+
async delete(id) {
|
|
10858
|
+
const response = await this._httpClient.post(`/session/delete/${id}`);
|
|
10859
|
+
return response.data.count;
|
|
10969
10860
|
}
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
for(let i = 0; i < hex.length; i += 2)result[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
10974
|
-
return result;
|
|
10861
|
+
async getLoginWays() {
|
|
10862
|
+
const response = await this._httpClient.get("/loginways");
|
|
10863
|
+
return response.data;
|
|
10975
10864
|
}
|
|
10976
|
-
|
|
10977
|
-
|
|
10865
|
+
}
|
|
10866
|
+
class LYUserApi {
|
|
10867
|
+
constructor(httpClient){
|
|
10868
|
+
this._httpClient = httpClient;
|
|
10978
10869
|
}
|
|
10979
|
-
|
|
10980
|
-
|
|
10870
|
+
async query(params) {
|
|
10871
|
+
const response = await this._httpClient.get('/user', params);
|
|
10872
|
+
return response.data;
|
|
10981
10873
|
}
|
|
10982
|
-
|
|
10983
|
-
const
|
|
10984
|
-
|
|
10985
|
-
for(let i = 0; i < binaryString.length; i++)bytes[i] = binaryString.charCodeAt(i);
|
|
10986
|
-
return bytes;
|
|
10874
|
+
async get(name1) {
|
|
10875
|
+
const response = await this._httpClient.get(`/user/${name1}`);
|
|
10876
|
+
return response.data;
|
|
10987
10877
|
}
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10878
|
+
async add(user) {
|
|
10879
|
+
const response = await this._httpClient.post("/user", {
|
|
10880
|
+
...user,
|
|
10881
|
+
password: user.password
|
|
10992
10882
|
});
|
|
10993
|
-
return
|
|
10883
|
+
return response.data.id;
|
|
10994
10884
|
}
|
|
10995
|
-
|
|
10996
|
-
const
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
];
|
|
10885
|
+
async update(name1, user) {
|
|
10886
|
+
const response = await this._httpClient.post(`/user/patch/${name1}`, {
|
|
10887
|
+
...user,
|
|
10888
|
+
password: user.password
|
|
10889
|
+
});
|
|
10890
|
+
return response.data.count;
|
|
11002
10891
|
}
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
throw new LYCryptoError('Key not provided and no default key available');
|
|
10892
|
+
async remove(name1) {
|
|
10893
|
+
const response = await this._httpClient.post(`/user/delete/${name1}`);
|
|
10894
|
+
return response.data.count;
|
|
11007
10895
|
}
|
|
11008
|
-
|
|
11009
|
-
const
|
|
11010
|
-
|
|
10896
|
+
async accountCheck(request) {
|
|
10897
|
+
const response = await this._httpClient.post("/user/account-check", {
|
|
10898
|
+
...request
|
|
10899
|
+
});
|
|
10900
|
+
return response.data.exists;
|
|
11011
10901
|
}
|
|
11012
|
-
|
|
11013
|
-
const
|
|
11014
|
-
|
|
10902
|
+
async register(request) {
|
|
10903
|
+
const response = await this._httpClient.post("/user/registration", {
|
|
10904
|
+
...request
|
|
10905
|
+
});
|
|
10906
|
+
return response.data;
|
|
11015
10907
|
}
|
|
11016
|
-
|
|
11017
|
-
const
|
|
11018
|
-
return
|
|
10908
|
+
async userNameCheck(name1) {
|
|
10909
|
+
const response = await this._httpClient.get(`/user/username-check/${name1}`);
|
|
10910
|
+
return response.data.available;
|
|
11019
10911
|
}
|
|
11020
|
-
|
|
11021
|
-
const
|
|
11022
|
-
|
|
10912
|
+
async changePassword(currentPassword, newPassword) {
|
|
10913
|
+
const response = await this._httpClient.post("/user/password/change", {
|
|
10914
|
+
current_password: currentPassword,
|
|
10915
|
+
new_password: newPassword
|
|
10916
|
+
});
|
|
10917
|
+
return response.data;
|
|
11023
10918
|
}
|
|
11024
|
-
async
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
newBuffer.set(chunk, buffer.length);
|
|
11030
|
-
buffer = newBuffer;
|
|
11031
|
-
while(buffer.length >= size){
|
|
11032
|
-
yield buffer.slice(0, size);
|
|
11033
|
-
buffer = buffer.slice(size);
|
|
11034
|
-
}
|
|
11035
|
-
}
|
|
11036
|
-
if (buffer.length > 0) yield buffer;
|
|
10919
|
+
async resetPassword(request) {
|
|
10920
|
+
const response = await this._httpClient.post("/user/password", {
|
|
10921
|
+
...request
|
|
10922
|
+
});
|
|
10923
|
+
return response.data;
|
|
11037
10924
|
}
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
10925
|
+
}
|
|
10926
|
+
const base_ORGANIZATION_APP_NAME = 'organization';
|
|
10927
|
+
class LYBaseAuthorizer extends LYObject {
|
|
10928
|
+
constructor(app, name1){
|
|
10929
|
+
super();
|
|
10930
|
+
this._app = app;
|
|
10931
|
+
this._name = name1;
|
|
11041
10932
|
}
|
|
11042
|
-
|
|
11043
|
-
|
|
10933
|
+
get app() {
|
|
10934
|
+
return this._app;
|
|
11044
10935
|
}
|
|
11045
|
-
|
|
11046
|
-
|
|
10936
|
+
get name() {
|
|
10937
|
+
return this._name;
|
|
11047
10938
|
}
|
|
11048
|
-
|
|
11049
|
-
|
|
10939
|
+
async signin(args) {
|
|
10940
|
+
await this._signin(args);
|
|
10941
|
+
this.emit('status-change', 'signed-in');
|
|
10942
|
+
if (args.redirect_uri) setTimeout(()=>{
|
|
10943
|
+
window.location.href = args.redirect_uri;
|
|
10944
|
+
}, 0);
|
|
11050
10945
|
}
|
|
11051
|
-
|
|
11052
|
-
|
|
10946
|
+
async signout(args) {
|
|
10947
|
+
await this._signout(args);
|
|
10948
|
+
this.emit('status-change', 'signed-out');
|
|
10949
|
+
setTimeout(()=>{
|
|
10950
|
+
const baseUrl = new URL(this.app.env.baseUrl);
|
|
10951
|
+
baseUrl.searchParams.set('returnUrl', encodeURIComponent(args.redirect_uri || window.location.href));
|
|
10952
|
+
window.location.href = baseUrl.toString();
|
|
10953
|
+
}, 0);
|
|
11053
10954
|
}
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
10955
|
+
}
|
|
10956
|
+
function web_ts_decorate(decorators, target, key, desc) {
|
|
10957
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10958
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10959
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10960
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10961
|
+
}
|
|
10962
|
+
function web_ts_metadata(k, v) {
|
|
10963
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10964
|
+
}
|
|
10965
|
+
class LYWebAuthorizer extends LYBaseAuthorizer {
|
|
10966
|
+
constructor(app, name1, sessionApi){
|
|
10967
|
+
super(app, name1);
|
|
10968
|
+
this._sessionApi = sessionApi;
|
|
10969
|
+
LYSession.setRefreshCallback(this._refreshSession.bind(this));
|
|
11058
10970
|
}
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
10971
|
+
async _signin(args) {
|
|
10972
|
+
const response = await this._sessionApi.create({
|
|
10973
|
+
name: args.name,
|
|
10974
|
+
password: args.password,
|
|
10975
|
+
email: args.email,
|
|
10976
|
+
phone: args.phone,
|
|
10977
|
+
country_code: args.country_code,
|
|
10978
|
+
account_type: args.account_type,
|
|
10979
|
+
verification_code: args.verification_code,
|
|
10980
|
+
verification_code_id: args.verification_code_id
|
|
10981
|
+
});
|
|
10982
|
+
LYSession.create('web', '', response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes, response.is_first_login, response.display_name, response.email, response.phone, response.country_code);
|
|
11063
10983
|
}
|
|
11064
|
-
|
|
11065
|
-
const
|
|
11066
|
-
|
|
11067
|
-
|
|
10984
|
+
async _signout(args) {
|
|
10985
|
+
const session = LYSession.get();
|
|
10986
|
+
if (!session) throw new Error('Session not found');
|
|
10987
|
+
const count = await this._sessionApi.delete(session.id);
|
|
10988
|
+
if (0 === count) throw new Error('Session not found');
|
|
10989
|
+
LYSession.clear();
|
|
11068
10990
|
}
|
|
11069
|
-
async
|
|
11070
|
-
const
|
|
11071
|
-
|
|
11072
|
-
for await (const chunk of this._makeSize(data, blockSize)){
|
|
11073
|
-
if (!chunk || 0 === chunk.length) {
|
|
11074
|
-
yield chunk;
|
|
11075
|
-
continue;
|
|
11076
|
-
}
|
|
11077
|
-
const buffer = this.impl.encryptSymmetric(chunk, actualIv, actualKey);
|
|
11078
|
-
const lengthBytes = new Uint8Array(LENGTH_SIZE);
|
|
11079
|
-
const view = new DataView(lengthBytes.buffer);
|
|
11080
|
-
view.setUint16(0, buffer.length, false);
|
|
11081
|
-
yield lengthBytes;
|
|
11082
|
-
yield buffer;
|
|
11083
|
-
}
|
|
10991
|
+
async _refreshSession(session) {
|
|
10992
|
+
const response = await this._sessionApi.update(session.id);
|
|
10993
|
+
LYSession.update(response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11084
10994
|
}
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
10995
|
+
}
|
|
10996
|
+
LYWebAuthorizer = web_ts_decorate([
|
|
10997
|
+
register('LYWebAuthorizer'),
|
|
10998
|
+
web_ts_metadata("design:type", Function),
|
|
10999
|
+
web_ts_metadata("design:paramtypes", [
|
|
11000
|
+
"undefined" == typeof LYBaseApp ? Object : LYBaseApp,
|
|
11001
|
+
String,
|
|
11002
|
+
"undefined" == typeof LYSessionApi ? Object : LYSessionApi
|
|
11003
|
+
])
|
|
11004
|
+
], LYWebAuthorizer);
|
|
11005
|
+
function gateway_ts_decorate(decorators, target, key, desc) {
|
|
11006
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11007
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11008
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11009
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11010
|
+
}
|
|
11011
|
+
class LYGatewayAuthorizer extends LYBaseAuthorizer {
|
|
11012
|
+
async _signin(args) {
|
|
11013
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11014
|
+
const response = await app.httpClient.post('sso/gateway/session');
|
|
11015
|
+
LYSession.create('gateway', '', response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11089
11016
|
}
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11017
|
+
async _signout(args) {
|
|
11018
|
+
const session = LYSession.get();
|
|
11019
|
+
if (!session) throw new Error('Session not found');
|
|
11020
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11021
|
+
const response = await app.httpClient.post(`sso/gateway/session/delete/${session.id}`);
|
|
11022
|
+
if (0 === response.count) throw new Error('Session not found');
|
|
11023
|
+
LYSession.clear();
|
|
11094
11024
|
}
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11025
|
+
}
|
|
11026
|
+
LYGatewayAuthorizer = gateway_ts_decorate([
|
|
11027
|
+
register('LYGatewayAuthorizer')
|
|
11028
|
+
], LYGatewayAuthorizer);
|
|
11029
|
+
function direct_ts_decorate(decorators, target, key, desc) {
|
|
11030
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11031
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11032
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11033
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11034
|
+
}
|
|
11035
|
+
class LYDirectAuthorizer extends LYBaseAuthorizer {
|
|
11036
|
+
async _signin(args) {
|
|
11037
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11038
|
+
const response = await app.httpClient.post('sso/direct/session', {
|
|
11039
|
+
authentication_name: args.authentication_name,
|
|
11040
|
+
user_name: args.user_name,
|
|
11041
|
+
password: args.password
|
|
11042
|
+
});
|
|
11043
|
+
LYSession.create('direct', args.authentication_name, response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11099
11044
|
}
|
|
11100
|
-
async
|
|
11101
|
-
const
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11109
|
-
while(true){
|
|
11110
|
-
if (size <= 0 && buffer.length < LENGTH_SIZE) break;
|
|
11111
|
-
if (size <= 0) {
|
|
11112
|
-
const view = new DataView(buffer.buffer, buffer.byteOffset);
|
|
11113
|
-
size = view.getUint16(0, false);
|
|
11114
|
-
buffer = buffer.slice(LENGTH_SIZE);
|
|
11115
|
-
}
|
|
11116
|
-
if (buffer.length < size) break;
|
|
11117
|
-
const encryptedChunk = buffer.slice(0, size);
|
|
11118
|
-
yield this.impl.decryptSymmetric(encryptedChunk, actualIv, actualKey);
|
|
11119
|
-
buffer = buffer.slice(size);
|
|
11120
|
-
size = -1;
|
|
11121
|
-
}
|
|
11122
|
-
}
|
|
11123
|
-
if (buffer.length > 0) yield this.impl.decryptSymmetric(buffer, actualIv, actualKey);
|
|
11045
|
+
async _signout(args) {
|
|
11046
|
+
const session = LYSession.get();
|
|
11047
|
+
if (!session) throw new Error('Session not found');
|
|
11048
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11049
|
+
const response = await app.httpClient.post(`sso/direct/session/delete/${session.id}`, {
|
|
11050
|
+
authentication_name: session.authentication_name
|
|
11051
|
+
});
|
|
11052
|
+
if (0 === response.count) throw new Error('Session not found');
|
|
11053
|
+
LYSession.clear();
|
|
11124
11054
|
}
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11055
|
+
}
|
|
11056
|
+
LYDirectAuthorizer = direct_ts_decorate([
|
|
11057
|
+
register('LYDirectAuthorizer')
|
|
11058
|
+
], LYDirectAuthorizer);
|
|
11059
|
+
function redirect_ts_decorate(decorators, target, key, desc) {
|
|
11060
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11061
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11062
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11063
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11064
|
+
}
|
|
11065
|
+
const REDIRECT_STORAGE_KEY = 'sso_redirect_info';
|
|
11066
|
+
const REDIRECT_STORAGE_EXPIRES_IN = 600000;
|
|
11067
|
+
class PKCEUtils {
|
|
11068
|
+
static generateCodeVerifier() {
|
|
11069
|
+
const array = new Uint8Array(32);
|
|
11070
|
+
crypto.getRandomValues(array);
|
|
11071
|
+
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11129
11072
|
}
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
const
|
|
11133
|
-
|
|
11073
|
+
static async generateCodeChallenge(codeVerifier) {
|
|
11074
|
+
const encoder = new TextEncoder();
|
|
11075
|
+
const data = encoder.encode(codeVerifier);
|
|
11076
|
+
let digest;
|
|
11077
|
+
digest = crypto.subtle ? await crypto.subtle.digest('SHA-256', data) : js_sha256.sha256.arrayBuffer(data);
|
|
11078
|
+
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(digest)))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11134
11079
|
}
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
return this._uint8ArrayToBase64(result);
|
|
11080
|
+
static generateState() {
|
|
11081
|
+
const array = new Uint8Array(16);
|
|
11082
|
+
crypto.getRandomValues(array);
|
|
11083
|
+
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11140
11084
|
}
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11085
|
+
}
|
|
11086
|
+
class LYRedirectAuthorizer extends LYBaseAuthorizer {
|
|
11087
|
+
async _signin(args) {
|
|
11088
|
+
const redirectInfo = sharedLocalStorage.getSync(REDIRECT_STORAGE_KEY);
|
|
11089
|
+
if (redirectInfo) if (redirectInfo.expires_at < new Date()) sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11090
|
+
else {
|
|
11091
|
+
const queryParams = this._getQueryParams();
|
|
11092
|
+
const code = queryParams.code;
|
|
11093
|
+
const state = queryParams.state;
|
|
11094
|
+
const locale = queryParams.ui_locales;
|
|
11095
|
+
if (code && state) {
|
|
11096
|
+
if (state !== redirectInfo.state) throw new Error('Invalid state parameter');
|
|
11097
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11098
|
+
if (locale) await app.i18n.changeLanguage(locale);
|
|
11099
|
+
try {
|
|
11100
|
+
const response = await app.httpClient.post('sso/redirect/session', {
|
|
11101
|
+
authentication_name: redirectInfo.authentication_name,
|
|
11102
|
+
query_params: {
|
|
11103
|
+
code: code,
|
|
11104
|
+
code_verifier: redirectInfo.code_verifier,
|
|
11105
|
+
redirect_uri: redirectInfo.redirect_uri,
|
|
11106
|
+
state: redirectInfo.state
|
|
11107
|
+
}
|
|
11108
|
+
});
|
|
11109
|
+
if (!response || !response.data.access_token) throw new Error('Invalid SSO response: missing access token');
|
|
11110
|
+
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);
|
|
11111
|
+
this.emit('status-change', 'signed-in');
|
|
11112
|
+
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11113
|
+
setTimeout(()=>{
|
|
11114
|
+
window.location.href = redirectInfo.redirect_uri;
|
|
11115
|
+
}, 0);
|
|
11116
|
+
return;
|
|
11117
|
+
} catch (error) {
|
|
11118
|
+
console.error('SSO login failed:', error);
|
|
11119
|
+
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11148
11120
|
}
|
|
11149
|
-
yield this.impl.encryptAsymmetric(chunk, key);
|
|
11150
11121
|
}
|
|
11151
|
-
} catch (error) {
|
|
11152
|
-
throw new LYCryptoError(`Stream asymmetric encryption failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
11153
11122
|
}
|
|
11123
|
+
if (args.sso_config) await this._jumpToSSO(args.sso_config, args.redirect_uri);
|
|
11124
|
+
else throw new Error('SSO configuration not provided');
|
|
11154
11125
|
}
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
if (data instanceof Uint8Array) return this._decryptAsymmetricBytes(data, privateKey);
|
|
11158
|
-
return this._decryptAsymmetricStream(data, privateKey);
|
|
11126
|
+
signin(args) {
|
|
11127
|
+
return this._signin(args);
|
|
11159
11128
|
}
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
const
|
|
11163
|
-
|
|
11129
|
+
async _jumpToSSO(ssoConfig, redirectUri) {
|
|
11130
|
+
const codeVerifier = PKCEUtils.generateCodeVerifier();
|
|
11131
|
+
const codeChallenge = await PKCEUtils.generateCodeChallenge(codeVerifier);
|
|
11132
|
+
const state = PKCEUtils.generateState();
|
|
11133
|
+
const ssoUrl = new URL(ssoConfig.auth_url);
|
|
11134
|
+
ssoUrl.searchParams.set('code_challenge', codeChallenge);
|
|
11135
|
+
ssoUrl.searchParams.set('code_challenge_method', 'S256');
|
|
11136
|
+
ssoUrl.searchParams.set('state', state);
|
|
11137
|
+
sharedLocalStorage.setSync(REDIRECT_STORAGE_KEY, {
|
|
11138
|
+
authentication_name: ssoConfig.name,
|
|
11139
|
+
redirect_uri: redirectUri,
|
|
11140
|
+
expires_at: new Date(Date.now() + REDIRECT_STORAGE_EXPIRES_IN),
|
|
11141
|
+
code_verifier: codeVerifier,
|
|
11142
|
+
state: state,
|
|
11143
|
+
sso_config: ssoConfig
|
|
11144
|
+
});
|
|
11145
|
+
setTimeout(()=>{
|
|
11146
|
+
window.location.href = ssoUrl.toString();
|
|
11147
|
+
}, 0);
|
|
11164
11148
|
}
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
const
|
|
11168
|
-
|
|
11169
|
-
|
|
11149
|
+
_getQueryParams() {
|
|
11150
|
+
const params = {};
|
|
11151
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
11152
|
+
urlParams.forEach((value, key)=>{
|
|
11153
|
+
params[key] = value;
|
|
11154
|
+
});
|
|
11155
|
+
return params;
|
|
11170
11156
|
}
|
|
11171
|
-
async
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11157
|
+
async signout(args) {
|
|
11158
|
+
await this._signout();
|
|
11159
|
+
}
|
|
11160
|
+
async _signout() {
|
|
11161
|
+
const session = LYSession.get();
|
|
11162
|
+
if (!session) throw new Error('Session not found');
|
|
11163
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11164
|
+
const response = await app.httpClient.post(`sso/redirect/session/delete/${session.id}`, {
|
|
11165
|
+
authentication_name: session.authentication_name
|
|
11166
|
+
});
|
|
11167
|
+
if (0 === response.data.count) throw new Error('Session not found');
|
|
11168
|
+
LYSession.clear();
|
|
11169
|
+
if (response.data.logout_url) {
|
|
11170
|
+
this.emit('status-change', 'signed-out');
|
|
11171
|
+
window.location.href = response.data.logout_url;
|
|
11183
11172
|
}
|
|
11184
11173
|
}
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11174
|
+
}
|
|
11175
|
+
LYRedirectAuthorizer = redirect_ts_decorate([
|
|
11176
|
+
register('LYRedirectAuthorizer')
|
|
11177
|
+
], LYRedirectAuthorizer);
|
|
11178
|
+
class LYLicenseApi {
|
|
11179
|
+
constructor(httpClient){
|
|
11180
|
+
this._httpClient = httpClient;
|
|
11188
11181
|
}
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
return this.impl.signature(data, key);
|
|
11182
|
+
async queryFiles() {
|
|
11183
|
+
const response = await this._httpClient.get("/license/file");
|
|
11184
|
+
return response.data;
|
|
11193
11185
|
}
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
return this._signatureBytes(dataBytes, privateKey);
|
|
11186
|
+
async getFileContent(id) {
|
|
11187
|
+
const response = await this._httpClient.get(`/license/file/content/${id}`);
|
|
11188
|
+
return response.data;
|
|
11198
11189
|
}
|
|
11199
|
-
|
|
11200
|
-
|
|
11201
|
-
return
|
|
11190
|
+
async add(license) {
|
|
11191
|
+
const response = await this._httpClient.post("/license", license);
|
|
11192
|
+
return response.data.id;
|
|
11202
11193
|
}
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
return this.impl.verify(data, key, signature);
|
|
11194
|
+
async getAll() {
|
|
11195
|
+
const response = await this._httpClient.get("/license");
|
|
11196
|
+
return response.data;
|
|
11207
11197
|
}
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
|
|
11211
|
-
return this._verifyBytes(dataBytes, signature, publicKey);
|
|
11198
|
+
async get(id) {
|
|
11199
|
+
const response = await this._httpClient.get(`/license/${id}`);
|
|
11200
|
+
return response.data;
|
|
11212
11201
|
}
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
return
|
|
11202
|
+
async remove(id) {
|
|
11203
|
+
const response = await this._httpClient.post(`/license/delete/${id}`);
|
|
11204
|
+
return response.data.count;
|
|
11216
11205
|
}
|
|
11217
|
-
|
|
11218
|
-
|
|
11219
|
-
|
|
11220
|
-
let result = new Uint8Array(data);
|
|
11221
|
-
for(let i = 0; i < iterations; i++)result = new Uint8Array(this.impl.hash(result, actualKey));
|
|
11222
|
-
return result;
|
|
11206
|
+
async getTokens() {
|
|
11207
|
+
const response = await this._httpClient.get("/license/token");
|
|
11208
|
+
return response.data;
|
|
11223
11209
|
}
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11210
|
+
async getToken(id) {
|
|
11211
|
+
const response = await this._httpClient.get(`/license/token/${id}`);
|
|
11212
|
+
return response.data;
|
|
11213
|
+
}
|
|
11214
|
+
async getLogs(licenseId, tokenId) {
|
|
11215
|
+
const response = await this._httpClient.get("/license/log", {
|
|
11216
|
+
license_id: licenseId,
|
|
11217
|
+
token_id: tokenId
|
|
11218
|
+
});
|
|
11219
|
+
return response.data;
|
|
11229
11220
|
}
|
|
11230
11221
|
}
|
|
11231
|
-
LYCrypto = crypto_ts_decorate([
|
|
11232
|
-
register('LYCrypto'),
|
|
11233
|
-
crypto_ts_metadata("design:type", Function),
|
|
11234
|
-
crypto_ts_metadata("design:paramtypes", [])
|
|
11235
|
-
], LYCrypto);
|
|
11236
|
-
const crypto_crypto = new LYCrypto();
|
|
11237
11222
|
class LYOEMApi {
|
|
11238
11223
|
constructor(httpClient){
|
|
11239
11224
|
this._httpClient = httpClient;
|
|
@@ -11307,7 +11292,7 @@ function app_ts_decorate(decorators, target, key, desc) {
|
|
|
11307
11292
|
function app_ts_metadata(k, v) {
|
|
11308
11293
|
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
11309
11294
|
}
|
|
11310
|
-
class LYOrganizationApp extends
|
|
11295
|
+
class LYOrganizationApp extends base_LYBaseApp {
|
|
11311
11296
|
constructor(name1, version, description){
|
|
11312
11297
|
super(name1, version, description);
|
|
11313
11298
|
LYOrganizationApp._instance = this;
|
|
@@ -11327,6 +11312,19 @@ class LYOrganizationApp extends LYBaseTenantApp {
|
|
|
11327
11312
|
if (!LYOrganizationApp._instance) throw new Error('LYOrganizationApp not initialized');
|
|
11328
11313
|
return LYOrganizationApp._instance;
|
|
11329
11314
|
}
|
|
11315
|
+
_createHttpClient() {
|
|
11316
|
+
const lang = this._i18n.lang;
|
|
11317
|
+
return new LYOrganizationHttpClient(this.name, {
|
|
11318
|
+
get headers () {
|
|
11319
|
+
const session = LYSession.get();
|
|
11320
|
+
if (!session) return;
|
|
11321
|
+
return {
|
|
11322
|
+
Authorization: `Bearer ${session.token}`,
|
|
11323
|
+
'Accept-Language': lang
|
|
11324
|
+
};
|
|
11325
|
+
}
|
|
11326
|
+
});
|
|
11327
|
+
}
|
|
11330
11328
|
get sessionApi() {
|
|
11331
11329
|
return this._sessionApi;
|
|
11332
11330
|
}
|
|
@@ -11339,9 +11337,6 @@ class LYOrganizationApp extends LYBaseTenantApp {
|
|
|
11339
11337
|
get licenseApi() {
|
|
11340
11338
|
return this._licenseApi;
|
|
11341
11339
|
}
|
|
11342
|
-
get crypto() {
|
|
11343
|
-
return crypto_crypto;
|
|
11344
|
-
}
|
|
11345
11340
|
get verificationCodesApi() {
|
|
11346
11341
|
return this._verificationCodesApi;
|
|
11347
11342
|
}
|
|
@@ -11726,6 +11721,22 @@ class LYTenantApp extends base_LYBaseApp {
|
|
|
11726
11721
|
this._authorizer = new LYTenantAuthorizer(this.httpClient);
|
|
11727
11722
|
LYTenantApp._instance = this;
|
|
11728
11723
|
}
|
|
11724
|
+
_createHttpClient() {
|
|
11725
|
+
const lang = this._i18n.lang;
|
|
11726
|
+
return new http_LYAppHttpClient(this.name, {
|
|
11727
|
+
get headers () {
|
|
11728
|
+
const session = LYTenantSession.get();
|
|
11729
|
+
if (!session) return;
|
|
11730
|
+
return {
|
|
11731
|
+
Authorization: `Bearer ${session.token}`,
|
|
11732
|
+
'Accept-Language': lang
|
|
11733
|
+
};
|
|
11734
|
+
}
|
|
11735
|
+
});
|
|
11736
|
+
}
|
|
11737
|
+
getBaseUrl() {
|
|
11738
|
+
return window.origin;
|
|
11739
|
+
}
|
|
11729
11740
|
static get instance() {
|
|
11730
11741
|
if (!LYTenantApp._instance) throw new Error('LYTenantApp not initialized');
|
|
11731
11742
|
return LYTenantApp._instance;
|
|
@@ -11755,24 +11766,13 @@ LYTenantApp = tenant_app_ts_decorate([
|
|
|
11755
11766
|
String
|
|
11756
11767
|
])
|
|
11757
11768
|
], LYTenantApp);
|
|
11758
|
-
base_LYBaseApp.setHeaderProvider({
|
|
11759
|
-
get headers () {
|
|
11760
|
-
const lang = LYTenantApp.instance.i18n.lang;
|
|
11761
|
-
const session = LYTenantSession.get();
|
|
11762
|
-
if (!session) return;
|
|
11763
|
-
return {
|
|
11764
|
-
Authorization: `Bearer ${session.token}`,
|
|
11765
|
-
'Accept-Language': lang
|
|
11766
|
-
};
|
|
11767
|
-
}
|
|
11768
|
-
});
|
|
11769
11769
|
function src_app_ts_decorate(decorators, target, key, desc) {
|
|
11770
11770
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11771
11771
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11772
11772
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11773
11773
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11774
11774
|
}
|
|
11775
|
-
class LYApp extends
|
|
11775
|
+
class LYApp extends base_LYBaseApp {
|
|
11776
11776
|
}
|
|
11777
11777
|
LYApp = src_app_ts_decorate([
|
|
11778
11778
|
register('LYApp')
|
|
@@ -12175,7 +12175,7 @@ http_LYAppHttpClient = src_http_ts_decorate([
|
|
|
12175
12175
|
"undefined" == typeof IHeaderProvider ? Object : IHeaderProvider
|
|
12176
12176
|
])
|
|
12177
12177
|
], http_LYAppHttpClient);
|
|
12178
|
-
class
|
|
12178
|
+
class LYOrganizationHttpClient extends http_LYAppHttpClient {
|
|
12179
12179
|
static getTenantName() {
|
|
12180
12180
|
const url = window.location.pathname;
|
|
12181
12181
|
const parts = url.split('/');
|
|
@@ -12185,15 +12185,15 @@ class LYTenantHttpClient extends http_LYAppHttpClient {
|
|
|
12185
12185
|
}
|
|
12186
12186
|
_getUrl(url) {
|
|
12187
12187
|
url = super._getUrl(url);
|
|
12188
|
-
const tenantName =
|
|
12188
|
+
const tenantName = LYOrganizationHttpClient.getTenantName();
|
|
12189
12189
|
if (tenantName) url = url.startsWith('/') ? `${tenantName}${url}` : `${tenantName}/${url}`;
|
|
12190
12190
|
return url;
|
|
12191
12191
|
}
|
|
12192
12192
|
}
|
|
12193
|
-
|
|
12194
|
-
register('
|
|
12195
|
-
],
|
|
12193
|
+
LYOrganizationHttpClient = src_http_ts_decorate([
|
|
12194
|
+
register('LOrganizationHttpClient')
|
|
12195
|
+
], LYOrganizationHttpClient);
|
|
12196
12196
|
var __webpack_exports__FRAMEWORK_NAME = "uci";
|
|
12197
|
-
export { LANG_KEY, LYApp, http_LYAppHttpClient as LYAppHttpClient, LYAppPermission, base_LYBaseApp as LYBaseApp, LYCloudStorage, LYConfig, LYCrypto, LYCryptoError, LYDefaultLogFormatter, LYDirectAuthorizer, LYEnv, LYError, LYGatewayAuthorizer, LYIndexedDBLogStorage, i18n_LYLangEnum as LYLangEnum, LYLocalStorage, logger_LYLogLevel as LYLogLevel, LYLogger, LYObject, LYObservable, LYOrganizationApp, LYOwnerObservable, LYRedirectAuthorizer, LYSession, LYSessionStorage, LYTenantApp, LYTenantAuthorizer,
|
|
12197
|
+
export { LANG_KEY, LYApp, http_LYAppHttpClient as LYAppHttpClient, LYAppPermission, base_LYBaseApp as LYBaseApp, LYCloudStorage, LYConfig, LYCrypto, LYCryptoError, LYDefaultLogFormatter, LYDirectAuthorizer, LYEnv, LYError, LYGatewayAuthorizer, LYIndexedDBLogStorage, i18n_LYLangEnum as LYLangEnum, LYLocalStorage, logger_LYLogLevel as LYLogLevel, LYLogger, LYObject, LYObservable, LYOrganizationApp, LYOrganizationHttpClient, LYOwnerObservable, LYRedirectAuthorizer, LYSession, LYSessionStorage, LYTenantApp, LYTenantAuthorizer, LYTenantSession, LYWebAuthorizer, LYi18n, ORGANIZATION_APP_NAME, REMOTE_ENTRY, REMOTE_MODULE, TENANT_APP_NAME, crypto_crypto as crypto, isElectron, isIframe, i18n_langKeys as langKeys, languages, logger, observable_observe as observe, register, setCloudStorageImpl, setFormatter, setPrintToConsole, setStorage, sharedCloudStorage, sharedLocalStorage, wait, __webpack_exports__FRAMEWORK_NAME as FRAMEWORK_NAME };
|
|
12198
12198
|
|
|
12199
12199
|
//# sourceMappingURL=index.js.map
|