@laiye_packages/uci 1.0.3 → 1.0.4
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 +3 -5
- package/dist/app/index.d.ts +2 -2
- package/dist/app/organization/app/index.d.ts +5 -4
- package/dist/app/tenant/app/index.d.ts +2 -0
- package/dist/http/index.d.ts +1 -1
- package/dist/index.js +1097 -1100
- 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,1221 @@ 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
|
-
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
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._httpClient = this._createHttpClient();
|
|
10661
10675
|
}
|
|
10662
|
-
|
|
10663
|
-
return this.
|
|
10676
|
+
get location() {
|
|
10677
|
+
return this._name;
|
|
10664
10678
|
}
|
|
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);
|
|
10679
|
+
get name() {
|
|
10680
|
+
return this._name;
|
|
10684
10681
|
}
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
10688
|
-
urlParams.forEach((value, key)=>{
|
|
10689
|
-
params[key] = value;
|
|
10690
|
-
});
|
|
10691
|
-
return params;
|
|
10682
|
+
get tenantName() {
|
|
10683
|
+
return this._tenantName;
|
|
10692
10684
|
}
|
|
10693
|
-
|
|
10694
|
-
|
|
10685
|
+
get version() {
|
|
10686
|
+
return this._version;
|
|
10695
10687
|
}
|
|
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
|
-
}
|
|
10688
|
+
get description() {
|
|
10689
|
+
return this._description;
|
|
10709
10690
|
}
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
register('LYRedirectAuthorizer')
|
|
10713
|
-
], LYRedirectAuthorizer);
|
|
10714
|
-
class LYLicenseApi {
|
|
10715
|
-
constructor(httpClient){
|
|
10716
|
-
this._httpClient = httpClient;
|
|
10691
|
+
get httpClient() {
|
|
10692
|
+
return this._httpClient;
|
|
10717
10693
|
}
|
|
10718
|
-
|
|
10719
|
-
const
|
|
10720
|
-
|
|
10694
|
+
get permission() {
|
|
10695
|
+
const session = LYSession.get();
|
|
10696
|
+
if (!session) throw new Error('session not found');
|
|
10697
|
+
return session.permissions[this._name];
|
|
10721
10698
|
}
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
return response.data;
|
|
10699
|
+
get provider() {
|
|
10700
|
+
return this._provider || new LYDefaultAppProvider();
|
|
10725
10701
|
}
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
return response.data.id;
|
|
10702
|
+
get i18n() {
|
|
10703
|
+
return this._i18n;
|
|
10729
10704
|
}
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
return response.data;
|
|
10705
|
+
get localStore() {
|
|
10706
|
+
return this._localStore;
|
|
10733
10707
|
}
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
return response.data;
|
|
10708
|
+
get sessionStore() {
|
|
10709
|
+
return this._sessionStore;
|
|
10737
10710
|
}
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
return response.data.count;
|
|
10711
|
+
get cloudStore() {
|
|
10712
|
+
return this._cloudStore;
|
|
10741
10713
|
}
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
return response.data;
|
|
10714
|
+
get isLoaded() {
|
|
10715
|
+
return this._isLoaded;
|
|
10745
10716
|
}
|
|
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;
|
|
10717
|
+
get env() {
|
|
10718
|
+
return this._env;
|
|
10795
10719
|
}
|
|
10796
|
-
|
|
10797
|
-
|
|
10720
|
+
get crypto() {
|
|
10721
|
+
return crypto_crypto;
|
|
10798
10722
|
}
|
|
10799
|
-
|
|
10800
|
-
|
|
10723
|
+
_createHttpClient() {
|
|
10724
|
+
return new http_LYAppHttpClient(this._name, {
|
|
10725
|
+
get headers () {
|
|
10726
|
+
return base_LYBaseApp.getHeaderProvider().headers;
|
|
10727
|
+
}
|
|
10728
|
+
});
|
|
10801
10729
|
}
|
|
10802
|
-
|
|
10803
|
-
return
|
|
10730
|
+
async load() {
|
|
10731
|
+
if (this._isLoaded) return;
|
|
10732
|
+
this.logger.info(`start run ${this._name} app`);
|
|
10733
|
+
await this.doLoad();
|
|
10734
|
+
this._isLoaded = true;
|
|
10735
|
+
this.logger.info(`run ${this._name} app completed`);
|
|
10804
10736
|
}
|
|
10805
|
-
|
|
10806
|
-
|
|
10737
|
+
async doLoad() {
|
|
10738
|
+
await this.initI18n();
|
|
10807
10739
|
}
|
|
10808
|
-
|
|
10740
|
+
async initI18n() {
|
|
10809
10741
|
try {
|
|
10810
|
-
this.
|
|
10811
|
-
|
|
10812
|
-
const
|
|
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);
|
|
10742
|
+
const resources = await this.provider.provideI18nResource(this);
|
|
10743
|
+
await this._i18n.initialize();
|
|
10744
|
+
for(const key in resources)this._i18n.loadResource(resources[key] || {}, key);
|
|
10822
10745
|
} catch (error) {
|
|
10823
|
-
|
|
10824
|
-
|
|
10746
|
+
this.logger.error('initI18n error');
|
|
10747
|
+
this.logger.error(error);
|
|
10825
10748
|
}
|
|
10826
10749
|
}
|
|
10827
|
-
|
|
10750
|
+
getI18nResourceUrl(relativeUrl, lang) {
|
|
10751
|
+
const baseUrl = this.provider.provideI18nResourcePath(this, lang) || '';
|
|
10828
10752
|
try {
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
const keyHex = this._uint8ArrayToHex(key);
|
|
10832
|
-
const ivHex = this._uint8ArrayToHex(paddedIv);
|
|
10833
|
-
const dataHex = this._uint8ArrayToHex(data);
|
|
10834
|
-
const decrypted = sm4.decrypt(dataHex, keyHex, {
|
|
10835
|
-
iv: ivHex,
|
|
10836
|
-
mode: 'cbc',
|
|
10837
|
-
padding: 'pkcs#7'
|
|
10838
|
-
});
|
|
10839
|
-
if (!decrypted) throw new LYCryptoError('SM4 decryption failed');
|
|
10840
|
-
return this._hexToUint8Array(decrypted);
|
|
10753
|
+
const url = new URL(relativeUrl, baseUrl);
|
|
10754
|
+
return url.toString();
|
|
10841
10755
|
} catch (error) {
|
|
10842
|
-
|
|
10843
|
-
throw new LYCryptoError(`SM4 decryption error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10756
|
+
return `${baseUrl}/${relativeUrl}`;
|
|
10844
10757
|
}
|
|
10845
10758
|
}
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
const privateKeyHex = this._uint8ArrayToHex(privateKey);
|
|
10851
|
-
const signature = sm2.doSignature(dataHex, privateKeyHex);
|
|
10852
|
-
if (!signature) throw new LYCryptoError('SM2 signature failed');
|
|
10853
|
-
return signature;
|
|
10854
|
-
} catch (error) {
|
|
10855
|
-
if (error instanceof LYCryptoError) throw error;
|
|
10856
|
-
throw new LYCryptoError(`SM2 signature error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10857
|
-
}
|
|
10759
|
+
async getComponent(componentName) {
|
|
10760
|
+
if (this._remoteComponents) return this._remoteComponents[componentName];
|
|
10761
|
+
await this.loadRemoteComponents();
|
|
10762
|
+
return this._remoteComponents[componentName];
|
|
10858
10763
|
}
|
|
10859
|
-
|
|
10764
|
+
async loadRemoteComponents() {
|
|
10765
|
+
const isLoaded = this._isLoadingComponent;
|
|
10766
|
+
while(this._isLoadingComponent)await wait();
|
|
10767
|
+
if (isLoaded) return this._remoteComponents;
|
|
10768
|
+
this._isLoadingComponent = true;
|
|
10860
10769
|
try {
|
|
10861
|
-
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10770
|
+
(0, runtime.registerRemotes)([
|
|
10771
|
+
{
|
|
10772
|
+
name: this.name,
|
|
10773
|
+
entry: `${this.env.baseUrl}/mf-manifest.json`
|
|
10774
|
+
}
|
|
10775
|
+
]);
|
|
10776
|
+
const remoteModule = await (0, runtime.loadRemote)(`${this.name}/Index`);
|
|
10777
|
+
this._remoteComponents = await remoteModule.default(this);
|
|
10865
10778
|
} catch (error) {
|
|
10866
|
-
|
|
10867
|
-
|
|
10779
|
+
this._remoteComponents = {};
|
|
10780
|
+
this.logger.error("loadRemoteComponents error:", error);
|
|
10781
|
+
} finally{
|
|
10782
|
+
this._isLoadingComponent = false;
|
|
10868
10783
|
}
|
|
10784
|
+
return this._remoteComponents;
|
|
10869
10785
|
}
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10786
|
+
}
|
|
10787
|
+
base_LYBaseApp = app_base_ts_decorate([
|
|
10788
|
+
register('LYBaseApp'),
|
|
10789
|
+
base_ts_metadata("design:type", Function),
|
|
10790
|
+
base_ts_metadata("design:paramtypes", [
|
|
10791
|
+
String,
|
|
10792
|
+
String,
|
|
10793
|
+
String
|
|
10794
|
+
])
|
|
10795
|
+
], base_LYBaseApp);
|
|
10796
|
+
class session_LYSessionApi {
|
|
10797
|
+
constructor(httpClient){
|
|
10798
|
+
this._httpClient = httpClient;
|
|
10882
10799
|
}
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
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
|
-
}
|
|
10800
|
+
async create(request) {
|
|
10801
|
+
if (!request.name) request = {
|
|
10802
|
+
...request,
|
|
10803
|
+
name: ""
|
|
10804
|
+
};
|
|
10805
|
+
const result = await this._httpClient.post("/session", request);
|
|
10806
|
+
return result.data;
|
|
10895
10807
|
}
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
const hmacResult = sm3(data, {
|
|
10900
|
-
key,
|
|
10901
|
-
mode: 'hmac'
|
|
10902
|
-
});
|
|
10903
|
-
if (!hmacResult) throw new LYCryptoError('SM3 HMAC failed');
|
|
10904
|
-
return this._hexToUint8Array(hmacResult);
|
|
10905
|
-
}
|
|
10906
|
-
{
|
|
10907
|
-
const hashResult = sm3(data);
|
|
10908
|
-
if (!hashResult) throw new LYCryptoError('SM3 hash failed');
|
|
10909
|
-
return this._hexToUint8Array(hashResult);
|
|
10910
|
-
}
|
|
10911
|
-
} catch (error) {
|
|
10912
|
-
if (error instanceof LYCryptoError) throw error;
|
|
10913
|
-
throw new LYCryptoError(`SM3 hash error: ${error instanceof Error ? error.message : String(error)}`);
|
|
10914
|
-
}
|
|
10808
|
+
async update(id) {
|
|
10809
|
+
const response = await this._httpClient.post(`/session/patch/${id}`);
|
|
10810
|
+
return response.data;
|
|
10915
10811
|
}
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
], LYSMCrypto);
|
|
10920
|
-
function gm_ts_decorate(decorators, target, key, desc) {
|
|
10921
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10922
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10923
|
-
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;
|
|
10924
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10925
|
-
}
|
|
10926
|
-
class LYGMCrypto extends LYSMCrypto {
|
|
10927
|
-
}
|
|
10928
|
-
LYGMCrypto = gm_ts_decorate([
|
|
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);
|
|
10812
|
+
async delete(id) {
|
|
10813
|
+
const response = await this._httpClient.post(`/session/delete/${id}`);
|
|
10814
|
+
return response.data.count;
|
|
10946
10815
|
}
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
return this._impl;
|
|
10951
|
-
}
|
|
10952
|
-
_createImpl() {
|
|
10953
|
-
try {
|
|
10954
|
-
const config = this._getCryptoConfig();
|
|
10955
|
-
const implClass = cryptoImpl[config.type];
|
|
10956
|
-
if (!implClass) throw new LYCryptoError(`Crypto implementation ${config.type} not found`);
|
|
10957
|
-
this._impl = new implClass();
|
|
10958
|
-
} catch (error) {
|
|
10959
|
-
throw new LYCryptoError(`Failed to create crypto implementation: ${error instanceof Error ? error.message : String(error)}`);
|
|
10960
|
-
}
|
|
10961
|
-
}
|
|
10962
|
-
_getCryptoConfig() {
|
|
10963
|
-
const config = new LYCryptoConfig();
|
|
10964
|
-
config.type = 'sm';
|
|
10965
|
-
return config;
|
|
10966
|
-
}
|
|
10967
|
-
_uint8ArrayToHex(array) {
|
|
10968
|
-
return Array.from(array).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
10969
|
-
}
|
|
10970
|
-
_hexToUint8Array(hex) {
|
|
10971
|
-
if (hex.length % 2 !== 0) throw new LYCryptoError('Invalid hex string length');
|
|
10972
|
-
const result = new Uint8Array(hex.length / 2);
|
|
10973
|
-
for(let i = 0; i < hex.length; i += 2)result[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
10974
|
-
return result;
|
|
10816
|
+
async getLoginWays() {
|
|
10817
|
+
const response = await this._httpClient.get("/loginways");
|
|
10818
|
+
return response.data;
|
|
10975
10819
|
}
|
|
10976
|
-
|
|
10977
|
-
|
|
10820
|
+
}
|
|
10821
|
+
class LYUserApi {
|
|
10822
|
+
constructor(httpClient){
|
|
10823
|
+
this._httpClient = httpClient;
|
|
10978
10824
|
}
|
|
10979
|
-
|
|
10980
|
-
|
|
10825
|
+
async query(params) {
|
|
10826
|
+
const response = await this._httpClient.get('/user', params);
|
|
10827
|
+
return response.data;
|
|
10981
10828
|
}
|
|
10982
|
-
|
|
10983
|
-
const
|
|
10984
|
-
|
|
10985
|
-
for(let i = 0; i < binaryString.length; i++)bytes[i] = binaryString.charCodeAt(i);
|
|
10986
|
-
return bytes;
|
|
10829
|
+
async get(name1) {
|
|
10830
|
+
const response = await this._httpClient.get(`/user/${name1}`);
|
|
10831
|
+
return response.data;
|
|
10987
10832
|
}
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10833
|
+
async add(user) {
|
|
10834
|
+
const response = await this._httpClient.post("/user", {
|
|
10835
|
+
...user,
|
|
10836
|
+
password: user.password
|
|
10992
10837
|
});
|
|
10993
|
-
return
|
|
10838
|
+
return response.data.id;
|
|
10994
10839
|
}
|
|
10995
|
-
|
|
10996
|
-
const
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
];
|
|
10840
|
+
async update(name1, user) {
|
|
10841
|
+
const response = await this._httpClient.post(`/user/patch/${name1}`, {
|
|
10842
|
+
...user,
|
|
10843
|
+
password: user.password
|
|
10844
|
+
});
|
|
10845
|
+
return response.data.count;
|
|
11002
10846
|
}
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
throw new LYCryptoError('Key not provided and no default key available');
|
|
10847
|
+
async remove(name1) {
|
|
10848
|
+
const response = await this._httpClient.post(`/user/delete/${name1}`);
|
|
10849
|
+
return response.data.count;
|
|
11007
10850
|
}
|
|
11008
|
-
|
|
11009
|
-
const
|
|
11010
|
-
|
|
10851
|
+
async accountCheck(request) {
|
|
10852
|
+
const response = await this._httpClient.post("/user/account-check", {
|
|
10853
|
+
...request
|
|
10854
|
+
});
|
|
10855
|
+
return response.data.exists;
|
|
11011
10856
|
}
|
|
11012
|
-
|
|
11013
|
-
const
|
|
11014
|
-
|
|
10857
|
+
async register(request) {
|
|
10858
|
+
const response = await this._httpClient.post("/user/registration", {
|
|
10859
|
+
...request
|
|
10860
|
+
});
|
|
10861
|
+
return response.data;
|
|
11015
10862
|
}
|
|
11016
|
-
|
|
11017
|
-
const
|
|
11018
|
-
return
|
|
10863
|
+
async userNameCheck(name1) {
|
|
10864
|
+
const response = await this._httpClient.get(`/user/username-check/${name1}`);
|
|
10865
|
+
return response.data.available;
|
|
11019
10866
|
}
|
|
11020
|
-
|
|
11021
|
-
const
|
|
11022
|
-
|
|
10867
|
+
async changePassword(currentPassword, newPassword) {
|
|
10868
|
+
const response = await this._httpClient.post("/user/password/change", {
|
|
10869
|
+
current_password: currentPassword,
|
|
10870
|
+
new_password: newPassword
|
|
10871
|
+
});
|
|
10872
|
+
return response.data;
|
|
11023
10873
|
}
|
|
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;
|
|
10874
|
+
async resetPassword(request) {
|
|
10875
|
+
const response = await this._httpClient.post("/user/password", {
|
|
10876
|
+
...request
|
|
10877
|
+
});
|
|
10878
|
+
return response.data;
|
|
11037
10879
|
}
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
10880
|
+
}
|
|
10881
|
+
const base_ORGANIZATION_APP_NAME = 'organization';
|
|
10882
|
+
class LYBaseAuthorizer extends LYObject {
|
|
10883
|
+
constructor(app, name1){
|
|
10884
|
+
super();
|
|
10885
|
+
this._app = app;
|
|
10886
|
+
this._name = name1;
|
|
11041
10887
|
}
|
|
11042
|
-
|
|
11043
|
-
|
|
10888
|
+
get app() {
|
|
10889
|
+
return this._app;
|
|
11044
10890
|
}
|
|
11045
|
-
|
|
11046
|
-
|
|
10891
|
+
get name() {
|
|
10892
|
+
return this._name;
|
|
11047
10893
|
}
|
|
11048
|
-
|
|
11049
|
-
|
|
10894
|
+
async signin(args) {
|
|
10895
|
+
await this._signin(args);
|
|
10896
|
+
this.emit('status-change', 'signed-in');
|
|
10897
|
+
if (args.redirect_uri) setTimeout(()=>{
|
|
10898
|
+
window.location.href = args.redirect_uri;
|
|
10899
|
+
}, 0);
|
|
11050
10900
|
}
|
|
11051
|
-
|
|
11052
|
-
|
|
10901
|
+
async signout(args) {
|
|
10902
|
+
await this._signout(args);
|
|
10903
|
+
this.emit('status-change', 'signed-out');
|
|
10904
|
+
setTimeout(()=>{
|
|
10905
|
+
const baseUrl = new URL(this.app.env.baseUrl);
|
|
10906
|
+
baseUrl.searchParams.set('returnUrl', encodeURIComponent(args.redirect_uri || window.location.href));
|
|
10907
|
+
window.location.href = baseUrl.toString();
|
|
10908
|
+
}, 0);
|
|
11053
10909
|
}
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
10910
|
+
}
|
|
10911
|
+
function web_ts_decorate(decorators, target, key, desc) {
|
|
10912
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10913
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10914
|
+
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;
|
|
10915
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10916
|
+
}
|
|
10917
|
+
function web_ts_metadata(k, v) {
|
|
10918
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
10919
|
+
}
|
|
10920
|
+
class LYWebAuthorizer extends LYBaseAuthorizer {
|
|
10921
|
+
constructor(app, name1, sessionApi){
|
|
10922
|
+
super(app, name1);
|
|
10923
|
+
this._sessionApi = sessionApi;
|
|
10924
|
+
LYSession.setRefreshCallback(this._refreshSession.bind(this));
|
|
11058
10925
|
}
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
10926
|
+
async _signin(args) {
|
|
10927
|
+
const response = await this._sessionApi.create({
|
|
10928
|
+
name: args.name,
|
|
10929
|
+
password: args.password,
|
|
10930
|
+
email: args.email,
|
|
10931
|
+
phone: args.phone,
|
|
10932
|
+
country_code: args.country_code,
|
|
10933
|
+
account_type: args.account_type,
|
|
10934
|
+
verification_code: args.verification_code,
|
|
10935
|
+
verification_code_id: args.verification_code_id
|
|
10936
|
+
});
|
|
10937
|
+
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
10938
|
}
|
|
11064
|
-
|
|
11065
|
-
const
|
|
11066
|
-
|
|
11067
|
-
|
|
10939
|
+
async _signout(args) {
|
|
10940
|
+
const session = LYSession.get();
|
|
10941
|
+
if (!session) throw new Error('Session not found');
|
|
10942
|
+
const count = await this._sessionApi.delete(session.id);
|
|
10943
|
+
if (0 === count) throw new Error('Session not found');
|
|
10944
|
+
LYSession.clear();
|
|
11068
10945
|
}
|
|
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
|
-
}
|
|
10946
|
+
async _refreshSession(session) {
|
|
10947
|
+
const response = await this._sessionApi.update(session.id);
|
|
10948
|
+
LYSession.update(response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11084
10949
|
}
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
10950
|
+
}
|
|
10951
|
+
LYWebAuthorizer = web_ts_decorate([
|
|
10952
|
+
register('LYWebAuthorizer'),
|
|
10953
|
+
web_ts_metadata("design:type", Function),
|
|
10954
|
+
web_ts_metadata("design:paramtypes", [
|
|
10955
|
+
"undefined" == typeof LYBaseApp ? Object : LYBaseApp,
|
|
10956
|
+
String,
|
|
10957
|
+
"undefined" == typeof LYSessionApi ? Object : LYSessionApi
|
|
10958
|
+
])
|
|
10959
|
+
], LYWebAuthorizer);
|
|
10960
|
+
function gateway_ts_decorate(decorators, target, key, desc) {
|
|
10961
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10962
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10963
|
+
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;
|
|
10964
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10965
|
+
}
|
|
10966
|
+
class LYGatewayAuthorizer extends LYBaseAuthorizer {
|
|
10967
|
+
async _signin(args) {
|
|
10968
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10969
|
+
const response = await app.httpClient.post('sso/gateway/session');
|
|
10970
|
+
LYSession.create('gateway', '', response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11089
10971
|
}
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
10972
|
+
async _signout(args) {
|
|
10973
|
+
const session = LYSession.get();
|
|
10974
|
+
if (!session) throw new Error('Session not found');
|
|
10975
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10976
|
+
const response = await app.httpClient.post(`sso/gateway/session/delete/${session.id}`);
|
|
10977
|
+
if (0 === response.count) throw new Error('Session not found');
|
|
10978
|
+
LYSession.clear();
|
|
11094
10979
|
}
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
10980
|
+
}
|
|
10981
|
+
LYGatewayAuthorizer = gateway_ts_decorate([
|
|
10982
|
+
register('LYGatewayAuthorizer')
|
|
10983
|
+
], LYGatewayAuthorizer);
|
|
10984
|
+
function direct_ts_decorate(decorators, target, key, desc) {
|
|
10985
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10986
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
10987
|
+
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;
|
|
10988
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10989
|
+
}
|
|
10990
|
+
class LYDirectAuthorizer extends LYBaseAuthorizer {
|
|
10991
|
+
async _signin(args) {
|
|
10992
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
10993
|
+
const response = await app.httpClient.post('sso/direct/session', {
|
|
10994
|
+
authentication_name: args.authentication_name,
|
|
10995
|
+
user_name: args.user_name,
|
|
10996
|
+
password: args.password
|
|
10997
|
+
});
|
|
10998
|
+
LYSession.create('direct', args.authentication_name, response.id, response.access_token, response.user_id, response.user_name, response.expires_in, response.permission_codes);
|
|
11099
10999
|
}
|
|
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);
|
|
11000
|
+
async _signout(args) {
|
|
11001
|
+
const session = LYSession.get();
|
|
11002
|
+
if (!session) throw new Error('Session not found');
|
|
11003
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11004
|
+
const response = await app.httpClient.post(`sso/direct/session/delete/${session.id}`, {
|
|
11005
|
+
authentication_name: session.authentication_name
|
|
11006
|
+
});
|
|
11007
|
+
if (0 === response.count) throw new Error('Session not found');
|
|
11008
|
+
LYSession.clear();
|
|
11124
11009
|
}
|
|
11125
|
-
|
|
11126
|
-
|
|
11127
|
-
|
|
11128
|
-
|
|
11010
|
+
}
|
|
11011
|
+
LYDirectAuthorizer = direct_ts_decorate([
|
|
11012
|
+
register('LYDirectAuthorizer')
|
|
11013
|
+
], LYDirectAuthorizer);
|
|
11014
|
+
function redirect_ts_decorate(decorators, target, key, desc) {
|
|
11015
|
+
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11016
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11017
|
+
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;
|
|
11018
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11019
|
+
}
|
|
11020
|
+
const REDIRECT_STORAGE_KEY = 'sso_redirect_info';
|
|
11021
|
+
const REDIRECT_STORAGE_EXPIRES_IN = 600000;
|
|
11022
|
+
class PKCEUtils {
|
|
11023
|
+
static generateCodeVerifier() {
|
|
11024
|
+
const array = new Uint8Array(32);
|
|
11025
|
+
crypto.getRandomValues(array);
|
|
11026
|
+
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11129
11027
|
}
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
const
|
|
11133
|
-
|
|
11028
|
+
static async generateCodeChallenge(codeVerifier) {
|
|
11029
|
+
const encoder = new TextEncoder();
|
|
11030
|
+
const data = encoder.encode(codeVerifier);
|
|
11031
|
+
let digest;
|
|
11032
|
+
digest = crypto.subtle ? await crypto.subtle.digest('SHA-256', data) : js_sha256.sha256.arrayBuffer(data);
|
|
11033
|
+
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(digest)))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11134
11034
|
}
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
return this._uint8ArrayToBase64(result);
|
|
11035
|
+
static generateState() {
|
|
11036
|
+
const array = new Uint8Array(16);
|
|
11037
|
+
crypto.getRandomValues(array);
|
|
11038
|
+
return btoa(String.fromCharCode.apply(null, Array.from(array))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11140
11039
|
}
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11040
|
+
}
|
|
11041
|
+
class LYRedirectAuthorizer extends LYBaseAuthorizer {
|
|
11042
|
+
async _signin(args) {
|
|
11043
|
+
const redirectInfo = sharedLocalStorage.getSync(REDIRECT_STORAGE_KEY);
|
|
11044
|
+
if (redirectInfo) if (redirectInfo.expires_at < new Date()) sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11045
|
+
else {
|
|
11046
|
+
const queryParams = this._getQueryParams();
|
|
11047
|
+
const code = queryParams.code;
|
|
11048
|
+
const state = queryParams.state;
|
|
11049
|
+
const locale = queryParams.ui_locales;
|
|
11050
|
+
if (code && state) {
|
|
11051
|
+
if (state !== redirectInfo.state) throw new Error('Invalid state parameter');
|
|
11052
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11053
|
+
if (locale) await app.i18n.changeLanguage(locale);
|
|
11054
|
+
try {
|
|
11055
|
+
const response = await app.httpClient.post('sso/redirect/session', {
|
|
11056
|
+
authentication_name: redirectInfo.authentication_name,
|
|
11057
|
+
query_params: {
|
|
11058
|
+
code: code,
|
|
11059
|
+
code_verifier: redirectInfo.code_verifier,
|
|
11060
|
+
redirect_uri: redirectInfo.redirect_uri,
|
|
11061
|
+
state: redirectInfo.state
|
|
11062
|
+
}
|
|
11063
|
+
});
|
|
11064
|
+
if (!response || !response.data.access_token) throw new Error('Invalid SSO response: missing access token');
|
|
11065
|
+
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);
|
|
11066
|
+
this.emit('status-change', 'signed-in');
|
|
11067
|
+
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11068
|
+
setTimeout(()=>{
|
|
11069
|
+
window.location.href = redirectInfo.redirect_uri;
|
|
11070
|
+
}, 0);
|
|
11071
|
+
return;
|
|
11072
|
+
} catch (error) {
|
|
11073
|
+
console.error('SSO login failed:', error);
|
|
11074
|
+
sharedLocalStorage.removeSync(REDIRECT_STORAGE_KEY);
|
|
11148
11075
|
}
|
|
11149
|
-
yield this.impl.encryptAsymmetric(chunk, key);
|
|
11150
11076
|
}
|
|
11151
|
-
} catch (error) {
|
|
11152
|
-
throw new LYCryptoError(`Stream asymmetric encryption failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
11153
11077
|
}
|
|
11078
|
+
if (args.sso_config) await this._jumpToSSO(args.sso_config, args.redirect_uri);
|
|
11079
|
+
else throw new Error('SSO configuration not provided');
|
|
11154
11080
|
}
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
if (data instanceof Uint8Array) return this._decryptAsymmetricBytes(data, privateKey);
|
|
11158
|
-
return this._decryptAsymmetricStream(data, privateKey);
|
|
11081
|
+
signin(args) {
|
|
11082
|
+
return this._signin(args);
|
|
11159
11083
|
}
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
const
|
|
11163
|
-
|
|
11084
|
+
async _jumpToSSO(ssoConfig, redirectUri) {
|
|
11085
|
+
const codeVerifier = PKCEUtils.generateCodeVerifier();
|
|
11086
|
+
const codeChallenge = await PKCEUtils.generateCodeChallenge(codeVerifier);
|
|
11087
|
+
const state = PKCEUtils.generateState();
|
|
11088
|
+
const ssoUrl = new URL(ssoConfig.auth_url);
|
|
11089
|
+
ssoUrl.searchParams.set('code_challenge', codeChallenge);
|
|
11090
|
+
ssoUrl.searchParams.set('code_challenge_method', 'S256');
|
|
11091
|
+
ssoUrl.searchParams.set('state', state);
|
|
11092
|
+
sharedLocalStorage.setSync(REDIRECT_STORAGE_KEY, {
|
|
11093
|
+
authentication_name: ssoConfig.name,
|
|
11094
|
+
redirect_uri: redirectUri,
|
|
11095
|
+
expires_at: new Date(Date.now() + REDIRECT_STORAGE_EXPIRES_IN),
|
|
11096
|
+
code_verifier: codeVerifier,
|
|
11097
|
+
state: state,
|
|
11098
|
+
sso_config: ssoConfig
|
|
11099
|
+
});
|
|
11100
|
+
setTimeout(()=>{
|
|
11101
|
+
window.location.href = ssoUrl.toString();
|
|
11102
|
+
}, 0);
|
|
11164
11103
|
}
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
const
|
|
11168
|
-
|
|
11169
|
-
|
|
11104
|
+
_getQueryParams() {
|
|
11105
|
+
const params = {};
|
|
11106
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
11107
|
+
urlParams.forEach((value, key)=>{
|
|
11108
|
+
params[key] = value;
|
|
11109
|
+
});
|
|
11110
|
+
return params;
|
|
11170
11111
|
}
|
|
11171
|
-
async
|
|
11172
|
-
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11112
|
+
async signout(args) {
|
|
11113
|
+
await this._signout();
|
|
11114
|
+
}
|
|
11115
|
+
async _signout() {
|
|
11116
|
+
const session = LYSession.get();
|
|
11117
|
+
if (!session) throw new Error('Session not found');
|
|
11118
|
+
const app = base_LYBaseApp.get(base_ORGANIZATION_APP_NAME);
|
|
11119
|
+
const response = await app.httpClient.post(`sso/redirect/session/delete/${session.id}`, {
|
|
11120
|
+
authentication_name: session.authentication_name
|
|
11121
|
+
});
|
|
11122
|
+
if (0 === response.data.count) throw new Error('Session not found');
|
|
11123
|
+
LYSession.clear();
|
|
11124
|
+
if (response.data.logout_url) {
|
|
11125
|
+
this.emit('status-change', 'signed-out');
|
|
11126
|
+
window.location.href = response.data.logout_url;
|
|
11183
11127
|
}
|
|
11184
11128
|
}
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11129
|
+
}
|
|
11130
|
+
LYRedirectAuthorizer = redirect_ts_decorate([
|
|
11131
|
+
register('LYRedirectAuthorizer')
|
|
11132
|
+
], LYRedirectAuthorizer);
|
|
11133
|
+
class LYLicenseApi {
|
|
11134
|
+
constructor(httpClient){
|
|
11135
|
+
this._httpClient = httpClient;
|
|
11188
11136
|
}
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
return this.impl.signature(data, key);
|
|
11137
|
+
async queryFiles() {
|
|
11138
|
+
const response = await this._httpClient.get("/license/file");
|
|
11139
|
+
return response.data;
|
|
11193
11140
|
}
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
return this._signatureBytes(dataBytes, privateKey);
|
|
11141
|
+
async getFileContent(id) {
|
|
11142
|
+
const response = await this._httpClient.get(`/license/file/content/${id}`);
|
|
11143
|
+
return response.data;
|
|
11198
11144
|
}
|
|
11199
|
-
|
|
11200
|
-
|
|
11201
|
-
return
|
|
11145
|
+
async add(license) {
|
|
11146
|
+
const response = await this._httpClient.post("/license", license);
|
|
11147
|
+
return response.data.id;
|
|
11202
11148
|
}
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
return this.impl.verify(data, key, signature);
|
|
11149
|
+
async getAll() {
|
|
11150
|
+
const response = await this._httpClient.get("/license");
|
|
11151
|
+
return response.data;
|
|
11207
11152
|
}
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
|
|
11211
|
-
return this._verifyBytes(dataBytes, signature, publicKey);
|
|
11153
|
+
async get(id) {
|
|
11154
|
+
const response = await this._httpClient.get(`/license/${id}`);
|
|
11155
|
+
return response.data;
|
|
11212
11156
|
}
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
return
|
|
11157
|
+
async remove(id) {
|
|
11158
|
+
const response = await this._httpClient.post(`/license/delete/${id}`);
|
|
11159
|
+
return response.data.count;
|
|
11216
11160
|
}
|
|
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;
|
|
11161
|
+
async getTokens() {
|
|
11162
|
+
const response = await this._httpClient.get("/license/token");
|
|
11163
|
+
return response.data;
|
|
11223
11164
|
}
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11165
|
+
async getToken(id) {
|
|
11166
|
+
const response = await this._httpClient.get(`/license/token/${id}`);
|
|
11167
|
+
return response.data;
|
|
11168
|
+
}
|
|
11169
|
+
async getLogs(licenseId, tokenId) {
|
|
11170
|
+
const response = await this._httpClient.get("/license/log", {
|
|
11171
|
+
license_id: licenseId,
|
|
11172
|
+
token_id: tokenId
|
|
11173
|
+
});
|
|
11174
|
+
return response.data;
|
|
11229
11175
|
}
|
|
11230
11176
|
}
|
|
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
11177
|
class LYOEMApi {
|
|
11238
11178
|
constructor(httpClient){
|
|
11239
11179
|
this._httpClient = httpClient;
|
|
@@ -11307,9 +11247,10 @@ function app_ts_decorate(decorators, target, key, desc) {
|
|
|
11307
11247
|
function app_ts_metadata(k, v) {
|
|
11308
11248
|
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
11309
11249
|
}
|
|
11310
|
-
class LYOrganizationApp extends
|
|
11250
|
+
class LYOrganizationApp extends base_LYBaseApp {
|
|
11311
11251
|
constructor(name1, version, description){
|
|
11312
11252
|
super(name1, version, description);
|
|
11253
|
+
this.env.baseUrl = this.getBaseUrl();
|
|
11313
11254
|
LYOrganizationApp._instance = this;
|
|
11314
11255
|
this._sessionApi = new session_LYSessionApi(this.httpClient);
|
|
11315
11256
|
this._userApi = new LYUserApi(this.httpClient);
|
|
@@ -11327,6 +11268,19 @@ class LYOrganizationApp extends LYBaseTenantApp {
|
|
|
11327
11268
|
if (!LYOrganizationApp._instance) throw new Error('LYOrganizationApp not initialized');
|
|
11328
11269
|
return LYOrganizationApp._instance;
|
|
11329
11270
|
}
|
|
11271
|
+
_createHttpClient() {
|
|
11272
|
+
const lang = this._i18n.lang;
|
|
11273
|
+
return new LYOrganizationHttpClient(this.name, {
|
|
11274
|
+
get headers () {
|
|
11275
|
+
const session = LYSession.get();
|
|
11276
|
+
if (!session) return;
|
|
11277
|
+
return {
|
|
11278
|
+
Authorization: `Bearer ${session.token}`,
|
|
11279
|
+
'Accept-Language': lang
|
|
11280
|
+
};
|
|
11281
|
+
}
|
|
11282
|
+
});
|
|
11283
|
+
}
|
|
11330
11284
|
get sessionApi() {
|
|
11331
11285
|
return this._sessionApi;
|
|
11332
11286
|
}
|
|
@@ -11339,9 +11293,6 @@ class LYOrganizationApp extends LYBaseTenantApp {
|
|
|
11339
11293
|
get licenseApi() {
|
|
11340
11294
|
return this._licenseApi;
|
|
11341
11295
|
}
|
|
11342
|
-
get crypto() {
|
|
11343
|
-
return crypto_crypto;
|
|
11344
|
-
}
|
|
11345
11296
|
get verificationCodesApi() {
|
|
11346
11297
|
return this._verificationCodesApi;
|
|
11347
11298
|
}
|
|
@@ -11364,6 +11315,50 @@ class LYOrganizationApp extends LYBaseTenantApp {
|
|
|
11364
11315
|
if (!this._authorizers[type]) throw new Error(`Authorizer ${type} not found`);
|
|
11365
11316
|
return this._authorizers[type];
|
|
11366
11317
|
}
|
|
11318
|
+
getBaseUrl() {
|
|
11319
|
+
const config = LYConfig.get();
|
|
11320
|
+
const url = new URL(window.location.href);
|
|
11321
|
+
let baseUrl = "";
|
|
11322
|
+
for (const pattern of config.host_patterns){
|
|
11323
|
+
if (!pattern.includes("{tenant_name}") && pattern.startsWith(url.origin)) {
|
|
11324
|
+
const parts = url.pathname.split('/');
|
|
11325
|
+
const index = parts.findIndex((part)=>'view' === part);
|
|
11326
|
+
let tenantName = parts[index + 2];
|
|
11327
|
+
if (!tenantName) throw new Error('tenantName not found');
|
|
11328
|
+
baseUrl = `${pattern}/view/${this.name}/${tenantName}`;
|
|
11329
|
+
this._tenantName = tenantName;
|
|
11330
|
+
return baseUrl;
|
|
11331
|
+
}
|
|
11332
|
+
let filterhost = pattern.replace(/\./g, "\\.").replace("{tenant_name}", "([a-zA-Z0-9_\\-]+)");
|
|
11333
|
+
const reg = new RegExp(`^${filterhost}(?::\\d+)?(?:/.*)?$`);
|
|
11334
|
+
const matched = url.toString().match(reg);
|
|
11335
|
+
if (matched && matched[1]) {
|
|
11336
|
+
const tenantName = matched[1];
|
|
11337
|
+
const host = pattern.replace("{tenant_name}", tenantName);
|
|
11338
|
+
baseUrl = `${host}/view/${this.name}`;
|
|
11339
|
+
this._tenantName = tenantName;
|
|
11340
|
+
return baseUrl;
|
|
11341
|
+
}
|
|
11342
|
+
}
|
|
11343
|
+
try {
|
|
11344
|
+
if ('development' === process.env.NODE_ENV) {
|
|
11345
|
+
baseUrl = `${window.origin}/view/${this.name}/laiye`;
|
|
11346
|
+
this._tenantName = "laiye";
|
|
11347
|
+
return baseUrl;
|
|
11348
|
+
}
|
|
11349
|
+
const parts = url.pathname.split('/');
|
|
11350
|
+
const index = parts.findIndex((part)=>'view' === part);
|
|
11351
|
+
if (-1 === index) throw new Error('view not found in URL');
|
|
11352
|
+
let tenantName = parts[index + 2];
|
|
11353
|
+
if (!tenantName) throw new Error('tenantName not found');
|
|
11354
|
+
baseUrl = `${window.origin}/view/${this.name}/${tenantName}`;
|
|
11355
|
+
this._tenantName = tenantName;
|
|
11356
|
+
return baseUrl;
|
|
11357
|
+
} catch (error) {
|
|
11358
|
+
console.error('Error getting base URL:', error);
|
|
11359
|
+
}
|
|
11360
|
+
return window.origin;
|
|
11361
|
+
}
|
|
11367
11362
|
}
|
|
11368
11363
|
LYOrganizationApp = app_ts_decorate([
|
|
11369
11364
|
register('LYOrganizationApp'),
|
|
@@ -11726,6 +11721,19 @@ 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
|
+
}
|
|
11729
11737
|
static get instance() {
|
|
11730
11738
|
if (!LYTenantApp._instance) throw new Error('LYTenantApp not initialized');
|
|
11731
11739
|
return LYTenantApp._instance;
|
|
@@ -11755,24 +11763,13 @@ LYTenantApp = tenant_app_ts_decorate([
|
|
|
11755
11763
|
String
|
|
11756
11764
|
])
|
|
11757
11765
|
], 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
11766
|
function src_app_ts_decorate(decorators, target, key, desc) {
|
|
11770
11767
|
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11771
11768
|
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
11772
11769
|
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
11770
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11774
11771
|
}
|
|
11775
|
-
class LYApp extends
|
|
11772
|
+
class LYApp extends base_LYBaseApp {
|
|
11776
11773
|
}
|
|
11777
11774
|
LYApp = src_app_ts_decorate([
|
|
11778
11775
|
register('LYApp')
|
|
@@ -12175,7 +12172,7 @@ http_LYAppHttpClient = src_http_ts_decorate([
|
|
|
12175
12172
|
"undefined" == typeof IHeaderProvider ? Object : IHeaderProvider
|
|
12176
12173
|
])
|
|
12177
12174
|
], http_LYAppHttpClient);
|
|
12178
|
-
class
|
|
12175
|
+
class LYOrganizationHttpClient extends http_LYAppHttpClient {
|
|
12179
12176
|
static getTenantName() {
|
|
12180
12177
|
const url = window.location.pathname;
|
|
12181
12178
|
const parts = url.split('/');
|
|
@@ -12185,15 +12182,15 @@ class LYTenantHttpClient extends http_LYAppHttpClient {
|
|
|
12185
12182
|
}
|
|
12186
12183
|
_getUrl(url) {
|
|
12187
12184
|
url = super._getUrl(url);
|
|
12188
|
-
const tenantName =
|
|
12185
|
+
const tenantName = LYOrganizationHttpClient.getTenantName();
|
|
12189
12186
|
if (tenantName) url = url.startsWith('/') ? `${tenantName}${url}` : `${tenantName}/${url}`;
|
|
12190
12187
|
return url;
|
|
12191
12188
|
}
|
|
12192
12189
|
}
|
|
12193
|
-
|
|
12194
|
-
register('
|
|
12195
|
-
],
|
|
12190
|
+
LYOrganizationHttpClient = src_http_ts_decorate([
|
|
12191
|
+
register('LOrganizationHttpClient')
|
|
12192
|
+
], LYOrganizationHttpClient);
|
|
12196
12193
|
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,
|
|
12194
|
+
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
12195
|
|
|
12199
12196
|
//# sourceMappingURL=index.js.map
|