@bitwarden/cli 1.21.0 → 1.21.1
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/build/bw.js +352 -297
- package/build/bw.js.map +1 -1
- package/package.json +1 -1
package/build/bw.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = require("url");
|
|
|
20
20
|
/***/ 147:
|
|
21
21
|
/***/ ((module) => {
|
|
22
22
|
|
|
23
|
-
module.exports = JSON.parse('{"name":"@bitwarden/cli","description":"A secure and free password manager for all of your devices.","version":"1.21.
|
|
23
|
+
module.exports = JSON.parse('{"name":"@bitwarden/cli","description":"A secure and free password manager for all of your devices.","version":"1.21.1","keywords":["bitwarden","password","vault","password manager","cli"],"author":"Bitwarden Inc. <hello@bitwarden.com> (https://bitwarden.com)","homepage":"https://bitwarden.com","repository":{"type":"git","url":"https://github.com/bitwarden/cli"},"license":"GPL-3.0-only","scripts":{"sub:init":"git submodule update --init --recursive","sub:update":"git submodule update --remote","sub:pull":"git submodule foreach git pull origin master","clean":"rimraf dist/**/*","symlink:win":"rmdir /S /Q ./jslib && cmd /c mklink /J .\\\\jslib ..\\\\jslib","symlink:mac":"npm run symlink:lin","symlink:lin":"rm -rf ./jslib && ln -s ../jslib ./jslib","build":"webpack","build:debug":"npm run build && node --inspect ./build/bw.js","build:watch":"webpack --watch","build:prod":"cross-env NODE_ENV=production webpack","build:prod:watch":"cross-env NODE_ENV=production webpack --watch","package":"npm run package:win && npm run package:mac && npm run package:lin","package:win":"pkg . --targets win-x64 --output ./dist/windows/bw.exe --build","package:mac":"pkg . --targets macos-x64 --output ./dist/macos/bw","package:lin":"pkg . --targets linux-x64 --output ./dist/linux/bw","debug":"node --inspect ./build/bw.js","dist":"npm run build:prod && npm run clean && npm run package","dist:win":"npm run build:prod && npm run clean && npm run package:win","dist:mac":"npm run build:prod && npm run clean && npm run package:mac","dist:lin":"npm run build:prod && npm run clean && npm run package:lin","publish:npm":"npm run build:prod && npm publish --access public","lint":"tslint \'src/**/*.ts\' \'spec/**/*.ts\' && prettier --check .","lint:fix":"tslint \'src/**/*.ts\' \'spec/**/*.ts\' --fix","prettier":"prettier --write .","prepare":"husky install","test":"jasmine-ts -r tsconfig-paths/register -P spec/tsconfig.json","test:watch":"nodemon -w ./spec -w ./src -w ./jslib --ext \\"ts,js,mjs,json\\" --exec jasmine-ts -r tsconfig-paths/register -P spec/tsconfig.json"},"bin":{"bw":"build/bw.js"},"pkg":{"assets":"./build/**/*"},"devDependencies":{"@fluffy-spoon/substitute":"^1.208.0","@types/express":"^4.17.13","@types/inquirer":"^7.3.1","@types/jasmine":"^3.7.0","@types/jsdom":"^16.2.10","@types/lowdb":"^1.0.10","@types/lunr":"^2.3.3","@types/multer":"^1.4.7","@types/node":"^16.11.12","@types/node-fetch":"^2.5.10","@types/node-forge":"^0.9.7","@types/papaparse":"^5.2.5","@types/proper-lockfile":"^4.1.2","@types/retry":"^0.12.1","@types/tldjs":"^2.3.0","@types/zxcvbn":"^4.4.1","clean-webpack-plugin":"^4.0.0","copy-webpack-plugin":"^10.2.0","cross-env":"^7.0.3","husky":"^7.0.4","jasmine":"^3.7.0","jasmine-core":"^3.7.1","jasmine-ts":"^0.4.0","jasmine-ts-console-reporter":"^3.1.1","lint-staged":"^12.1.3","pkg":"^5.5.1","prettier":"^2.5.1","rimraf":"^3.0.2","ts-loader":"^8.2.0","ts-node":"^10.4.0","tsconfig-paths":"^3.12.0","tsconfig-paths-webpack-plugin":"^3.5.2","tslint":"^6.1.3","tslint-loader":"^3.5.4","typescript":"4.1.5","webpack":"^5.65.0","webpack-cli":"^4.9.1","webpack-node-externals":"^3.0.0"},"dependencies":{"big-integer":"1.6.48","browser-hrtime":"^1.1.8","chalk":"^4.1.1","commander":"7.2.0","express":"^4.17.1","form-data":"4.0.0","https-proxy-agent":"5.0.0","inquirer":"8.0.0","jsdom":"^16.5.3","lowdb":"1.0.0","lunr":"^2.3.9","multer":"^1.4.3","node-fetch":"^2.6.1","node-forge":"0.10.0","open":"^8.0.8","papaparse":"^5.3.0","proper-lockfile":"^4.1.2","rxjs":"6.6.7","tldjs":"^2.3.1","zxcvbn":"^4.4.2"},"engines":{"node":"~16","npm":">=7 <=8"},"lint-staged":{"*":"prettier --ignore-unknown --write"}}');
|
|
24
24
|
|
|
25
25
|
/***/ })
|
|
26
26
|
|
|
@@ -1940,6 +1940,14 @@ class ConsoleLogService extends consoleLog_service_ConsoleLogService {
|
|
|
1940
1940
|
}
|
|
1941
1941
|
}
|
|
1942
1942
|
|
|
1943
|
+
;// CONCATENATED MODULE: ./jslib/common/src/enums/htmlStorageLocation.ts
|
|
1944
|
+
var HtmlStorageLocation;
|
|
1945
|
+
(function (HtmlStorageLocation) {
|
|
1946
|
+
HtmlStorageLocation["Local"] = "local";
|
|
1947
|
+
HtmlStorageLocation["Memory"] = "memory";
|
|
1948
|
+
HtmlStorageLocation["Session"] = "session";
|
|
1949
|
+
})(HtmlStorageLocation || (HtmlStorageLocation = {}));
|
|
1950
|
+
|
|
1943
1951
|
;// CONCATENATED MODULE: ./jslib/common/src/services/appId.service.ts
|
|
1944
1952
|
var appId_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1945
1953
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -1951,6 +1959,7 @@ var appId_service_awaiter = (undefined && undefined.__awaiter) || function (this
|
|
|
1951
1959
|
});
|
|
1952
1960
|
};
|
|
1953
1961
|
|
|
1962
|
+
|
|
1954
1963
|
class AppIdService {
|
|
1955
1964
|
constructor(storageService) {
|
|
1956
1965
|
this.storageService = storageService;
|
|
@@ -1963,12 +1972,16 @@ class AppIdService {
|
|
|
1963
1972
|
}
|
|
1964
1973
|
makeAndGetAppId(key) {
|
|
1965
1974
|
return appId_service_awaiter(this, void 0, void 0, function* () {
|
|
1966
|
-
const existingId = yield this.storageService.get(key
|
|
1975
|
+
const existingId = yield this.storageService.get(key, {
|
|
1976
|
+
htmlStorageLocation: HtmlStorageLocation.Local,
|
|
1977
|
+
});
|
|
1967
1978
|
if (existingId != null) {
|
|
1968
1979
|
return existingId;
|
|
1969
1980
|
}
|
|
1970
1981
|
const guid = Utils.newGuid();
|
|
1971
|
-
yield this.storageService.save(key, guid
|
|
1982
|
+
yield this.storageService.save(key, guid, {
|
|
1983
|
+
htmlStorageLocation: HtmlStorageLocation.Local,
|
|
1984
|
+
});
|
|
1972
1985
|
return guid;
|
|
1973
1986
|
});
|
|
1974
1987
|
}
|
|
@@ -13832,10 +13845,14 @@ class CryptoService {
|
|
|
13832
13845
|
}
|
|
13833
13846
|
hasKeyStored(keySuffix, userId) {
|
|
13834
13847
|
return crypto_service_awaiter(this, void 0, void 0, function* () {
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
13838
|
-
|
|
13848
|
+
switch (keySuffix) {
|
|
13849
|
+
case KeySuffixOptions.Auto:
|
|
13850
|
+
return (yield this.stateService.getCryptoMasterKeyAuto({ userId: userId })) != null;
|
|
13851
|
+
case KeySuffixOptions.Biometric:
|
|
13852
|
+
return (yield this.stateService.hasCryptoMasterKeyBiometric({ userId: userId })) === true;
|
|
13853
|
+
default:
|
|
13854
|
+
return false;
|
|
13855
|
+
}
|
|
13839
13856
|
});
|
|
13840
13857
|
}
|
|
13841
13858
|
hasEncKey() {
|
|
@@ -23266,14 +23283,6 @@ class SettingsService {
|
|
|
23266
23283
|
}
|
|
23267
23284
|
}
|
|
23268
23285
|
|
|
23269
|
-
;// CONCATENATED MODULE: ./jslib/common/src/enums/htmlStorageLocation.ts
|
|
23270
|
-
var HtmlStorageLocation;
|
|
23271
|
-
(function (HtmlStorageLocation) {
|
|
23272
|
-
HtmlStorageLocation["Local"] = "local";
|
|
23273
|
-
HtmlStorageLocation["Memory"] = "memory";
|
|
23274
|
-
HtmlStorageLocation["Session"] = "session";
|
|
23275
|
-
})(HtmlStorageLocation || (HtmlStorageLocation = {}));
|
|
23276
|
-
|
|
23277
23286
|
;// CONCATENATED MODULE: ./jslib/common/src/enums/storageLocation.ts
|
|
23278
23287
|
var StorageLocation;
|
|
23279
23288
|
(function (StorageLocation) {
|
|
@@ -23336,6 +23345,7 @@ class StateService {
|
|
|
23336
23345
|
this.activeAccount = new external_rxjs_namespaceObject.BehaviorSubject(null);
|
|
23337
23346
|
this.state = new State(this.createGlobals());
|
|
23338
23347
|
this.hasBeenInited = false;
|
|
23348
|
+
this.accountDiskCache = new Map();
|
|
23339
23349
|
}
|
|
23340
23350
|
init() {
|
|
23341
23351
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
@@ -23412,19 +23422,13 @@ class StateService {
|
|
|
23412
23422
|
getAccessToken(options) {
|
|
23413
23423
|
var _a, _b;
|
|
23414
23424
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23415
|
-
|
|
23416
|
-
? this.defaultInMemoryOptions
|
|
23417
|
-
: yield this.defaultOnDiskOptions();
|
|
23418
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23425
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23419
23426
|
return (_b = (_a = (yield this.getAccount(options))) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.accessToken;
|
|
23420
23427
|
});
|
|
23421
23428
|
}
|
|
23422
23429
|
setAccessToken(value, options) {
|
|
23423
23430
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23424
|
-
|
|
23425
|
-
? this.defaultInMemoryOptions
|
|
23426
|
-
: yield this.defaultOnDiskOptions();
|
|
23427
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23431
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23428
23432
|
const account = yield this.getAccount(options);
|
|
23429
23433
|
account.tokens.accessToken = value;
|
|
23430
23434
|
yield this.saveAccount(account, options);
|
|
@@ -23459,19 +23463,13 @@ class StateService {
|
|
|
23459
23463
|
getApiKeyClientId(options) {
|
|
23460
23464
|
var _a, _b;
|
|
23461
23465
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23462
|
-
|
|
23463
|
-
? this.defaultInMemoryOptions
|
|
23464
|
-
: yield this.defaultOnDiskOptions();
|
|
23465
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23466
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23466
23467
|
return (_b = (_a = (yield this.getAccount(options))) === null || _a === void 0 ? void 0 : _a.profile) === null || _b === void 0 ? void 0 : _b.apiKeyClientId;
|
|
23467
23468
|
});
|
|
23468
23469
|
}
|
|
23469
23470
|
setApiKeyClientId(value, options) {
|
|
23470
23471
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23471
|
-
|
|
23472
|
-
? this.defaultInMemoryOptions
|
|
23473
|
-
: yield this.defaultOnDiskOptions();
|
|
23474
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23472
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23475
23473
|
const account = yield this.getAccount(options);
|
|
23476
23474
|
account.profile.apiKeyClientId = value;
|
|
23477
23475
|
yield this.saveAccount(account, options);
|
|
@@ -23480,19 +23478,13 @@ class StateService {
|
|
|
23480
23478
|
getApiKeyClientSecret(options) {
|
|
23481
23479
|
var _a, _b;
|
|
23482
23480
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23483
|
-
|
|
23484
|
-
? this.defaultInMemoryOptions
|
|
23485
|
-
: yield this.defaultOnDiskOptions();
|
|
23486
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23481
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23487
23482
|
return (_b = (_a = (yield this.getAccount(options))) === null || _a === void 0 ? void 0 : _a.keys) === null || _b === void 0 ? void 0 : _b.apiKeyClientSecret;
|
|
23488
23483
|
});
|
|
23489
23484
|
}
|
|
23490
23485
|
setApiKeyClientSecret(value, options) {
|
|
23491
23486
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
23492
|
-
|
|
23493
|
-
? this.defaultInMemoryOptions
|
|
23494
|
-
: yield this.defaultOnDiskOptions();
|
|
23495
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
23487
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
23496
23488
|
const account = yield this.getAccount(options);
|
|
23497
23489
|
account.keys.apiKeyClientSecret = value;
|
|
23498
23490
|
yield this.saveAccount(account, options);
|
|
@@ -24416,14 +24408,14 @@ class StateService {
|
|
|
24416
24408
|
getEverBeenUnlocked(options) {
|
|
24417
24409
|
var _a, _b, _c;
|
|
24418
24410
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24419
|
-
return ((_c = (_b = (_a = (yield this.getAccount(this.reconcileOptions(options,
|
|
24411
|
+
return ((_c = (_b = (_a = (yield this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions)))) === null || _a === void 0 ? void 0 : _a.profile) === null || _b === void 0 ? void 0 : _b.everBeenUnlocked) !== null && _c !== void 0 ? _c : false);
|
|
24420
24412
|
});
|
|
24421
24413
|
}
|
|
24422
24414
|
setEverBeenUnlocked(value, options) {
|
|
24423
24415
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24424
|
-
const account = yield this.getAccount(this.reconcileOptions(options,
|
|
24416
|
+
const account = yield this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions));
|
|
24425
24417
|
account.profile.everBeenUnlocked = value;
|
|
24426
|
-
yield this.saveAccount(account, this.reconcileOptions(options,
|
|
24418
|
+
yield this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
|
24427
24419
|
});
|
|
24428
24420
|
}
|
|
24429
24421
|
getForcePasswordReset(options) {
|
|
@@ -24716,14 +24708,14 @@ class StateService {
|
|
|
24716
24708
|
getProviders(options) {
|
|
24717
24709
|
var _a, _b;
|
|
24718
24710
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24719
|
-
return (_b = (_a = (yield this.getAccount(this.reconcileOptions(options, this.
|
|
24711
|
+
return (_b = (_a = (yield this.getAccount(this.reconcileOptions(options, yield this.defaultOnDiskOptions())))) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.providers;
|
|
24720
24712
|
});
|
|
24721
24713
|
}
|
|
24722
24714
|
setProviders(value, options) {
|
|
24723
24715
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24724
|
-
const account = yield this.getAccount(this.reconcileOptions(options, this.
|
|
24716
|
+
const account = yield this.getAccount(this.reconcileOptions(options, yield this.defaultOnDiskOptions()));
|
|
24725
24717
|
account.data.providers = value;
|
|
24726
|
-
yield this.saveAccount(account, this.reconcileOptions(options, this.
|
|
24718
|
+
yield this.saveAccount(account, this.reconcileOptions(options, yield this.defaultOnDiskOptions()));
|
|
24727
24719
|
});
|
|
24728
24720
|
}
|
|
24729
24721
|
getPublicKey(options) {
|
|
@@ -24742,19 +24734,13 @@ class StateService {
|
|
|
24742
24734
|
getRefreshToken(options) {
|
|
24743
24735
|
var _a, _b;
|
|
24744
24736
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24745
|
-
|
|
24746
|
-
? this.defaultInMemoryOptions
|
|
24747
|
-
: yield this.defaultOnDiskOptions();
|
|
24748
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
24737
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
24749
24738
|
return (_b = (_a = (yield this.getAccount(options))) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.refreshToken;
|
|
24750
24739
|
});
|
|
24751
24740
|
}
|
|
24752
24741
|
setRefreshToken(value, options) {
|
|
24753
24742
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
24754
|
-
|
|
24755
|
-
? this.defaultInMemoryOptions
|
|
24756
|
-
: yield this.defaultOnDiskOptions();
|
|
24757
|
-
options = this.reconcileOptions(options, defaultOptions);
|
|
24743
|
+
options = yield this.getTimeoutBasedStorageOptions(options);
|
|
24758
24744
|
const account = yield this.getAccount(options);
|
|
24759
24745
|
account.tokens.refreshToken = value;
|
|
24760
24746
|
yield this.saveAccount(account, options);
|
|
@@ -25014,7 +25000,12 @@ class StateService {
|
|
|
25014
25000
|
if ((options === null || options === void 0 ? void 0 : options.userId) == null && this.state.activeUserId == null) {
|
|
25015
25001
|
return null;
|
|
25016
25002
|
}
|
|
25003
|
+
const cachedAccount = this.accountDiskCache.get(options.userId);
|
|
25004
|
+
if (cachedAccount != null) {
|
|
25005
|
+
return cachedAccount;
|
|
25006
|
+
}
|
|
25017
25007
|
const account = (options === null || options === void 0 ? void 0 : options.useSecureStorage) ? (_a = (yield this.secureStorageService.get(options.userId, options))) !== null && _a !== void 0 ? _a : (yield this.storageService.get(options.userId, this.reconcileOptions(options, { htmlStorageLocation: HtmlStorageLocation.Local }))) : yield this.storageService.get(options.userId, options);
|
|
25008
|
+
this.accountDiskCache.set(options.userId, account);
|
|
25018
25009
|
return account;
|
|
25019
25010
|
});
|
|
25020
25011
|
}
|
|
@@ -25040,6 +25031,7 @@ class StateService {
|
|
|
25040
25031
|
? this.secureStorageService
|
|
25041
25032
|
: this.storageService;
|
|
25042
25033
|
yield storageLocation.save(`${options.userId}`, account, options);
|
|
25034
|
+
this.accountDiskCache.delete(options.userId);
|
|
25043
25035
|
});
|
|
25044
25036
|
}
|
|
25045
25037
|
saveAccountToMemory(account) {
|
|
@@ -25063,7 +25055,7 @@ class StateService {
|
|
|
25063
25055
|
// For now these methods exist with some redundancy to facilitate this special web requirement.
|
|
25064
25056
|
scaffoldNewAccountLocalStorage(account) {
|
|
25065
25057
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25066
|
-
const storedAccount = yield this.
|
|
25058
|
+
const storedAccount = yield this.getAccount(this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskLocalOptions()));
|
|
25067
25059
|
// EnvironmentUrls are set before authenticating and should override whatever is stored from any previous session
|
|
25068
25060
|
const environmentUrls = account.settings.environmentUrls;
|
|
25069
25061
|
if ((storedAccount === null || storedAccount === void 0 ? void 0 : storedAccount.settings) != null) {
|
|
@@ -25074,33 +25066,35 @@ class StateService {
|
|
|
25074
25066
|
yield this.storageService.remove(keys.tempAccountSettings);
|
|
25075
25067
|
}
|
|
25076
25068
|
account.settings.environmentUrls = environmentUrls;
|
|
25077
|
-
if (account.settings.vaultTimeoutAction === "logOut") {
|
|
25069
|
+
if (account.settings.vaultTimeoutAction === "logOut" && account.settings.vaultTimeout != null) {
|
|
25078
25070
|
account.tokens.accessToken = null;
|
|
25079
25071
|
account.tokens.refreshToken = null;
|
|
25080
25072
|
account.profile.apiKeyClientId = null;
|
|
25081
25073
|
account.keys.apiKeyClientSecret = null;
|
|
25082
25074
|
}
|
|
25083
|
-
yield this.
|
|
25075
|
+
yield this.saveAccount(account, this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskLocalOptions()));
|
|
25084
25076
|
});
|
|
25085
25077
|
}
|
|
25086
25078
|
scaffoldNewAccountMemoryStorage(account) {
|
|
25087
25079
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25088
|
-
const storedAccount = yield this.
|
|
25080
|
+
const storedAccount = yield this.getAccount(this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskMemoryOptions()));
|
|
25089
25081
|
if ((storedAccount === null || storedAccount === void 0 ? void 0 : storedAccount.settings) != null) {
|
|
25090
25082
|
storedAccount.settings.environmentUrls = account.settings.environmentUrls;
|
|
25091
25083
|
account.settings = storedAccount.settings;
|
|
25092
25084
|
}
|
|
25093
25085
|
yield this.storageService.save(account.profile.userId, account, yield this.defaultOnDiskMemoryOptions());
|
|
25086
|
+
yield this.saveAccount(account, this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskMemoryOptions()));
|
|
25094
25087
|
});
|
|
25095
25088
|
}
|
|
25096
25089
|
scaffoldNewAccountSessionStorage(account) {
|
|
25097
25090
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25098
|
-
const storedAccount = yield this.
|
|
25091
|
+
const storedAccount = yield this.getAccount(this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskOptions()));
|
|
25099
25092
|
if ((storedAccount === null || storedAccount === void 0 ? void 0 : storedAccount.settings) != null) {
|
|
25100
25093
|
storedAccount.settings.environmentUrls = account.settings.environmentUrls;
|
|
25101
25094
|
account.settings = storedAccount.settings;
|
|
25102
25095
|
}
|
|
25103
|
-
yield this.storageService.save(account.profile.userId, account, yield this.
|
|
25096
|
+
yield this.storageService.save(account.profile.userId, account, yield this.defaultOnDiskMemoryOptions());
|
|
25097
|
+
yield this.saveAccount(account, this.reconcileOptions({ userId: account.profile.userId }, yield this.defaultOnDiskOptions()));
|
|
25104
25098
|
});
|
|
25105
25099
|
}
|
|
25106
25100
|
//
|
|
@@ -25180,18 +25174,14 @@ class StateService {
|
|
|
25180
25174
|
}
|
|
25181
25175
|
removeAccountFromLocalStorage(userId = this.state.activeUserId) {
|
|
25182
25176
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25183
|
-
const storedAccount = yield this.
|
|
25184
|
-
|
|
25185
|
-
});
|
|
25186
|
-
yield this.storageService.save(userId, this.resetAccount(storedAccount), yield this.defaultOnDiskLocalOptions());
|
|
25177
|
+
const storedAccount = yield this.getAccount(this.reconcileOptions({ userId: userId }, yield this.defaultOnDiskLocalOptions()));
|
|
25178
|
+
yield this.saveAccount(this.resetAccount(storedAccount), this.reconcileOptions({ userId: userId }, yield this.defaultOnDiskLocalOptions()));
|
|
25187
25179
|
});
|
|
25188
25180
|
}
|
|
25189
25181
|
removeAccountFromSessionStorage(userId = this.state.activeUserId) {
|
|
25190
25182
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25191
|
-
const storedAccount = yield this.
|
|
25192
|
-
|
|
25193
|
-
});
|
|
25194
|
-
yield this.storageService.save(userId, this.resetAccount(storedAccount), yield this.defaultOnDiskOptions());
|
|
25183
|
+
const storedAccount = yield this.getAccount(this.reconcileOptions({ userId: userId }, yield this.defaultOnDiskOptions()));
|
|
25184
|
+
yield this.saveAccount(this.resetAccount(storedAccount), this.reconcileOptions({ userId: userId }, yield this.defaultOnDiskOptions()));
|
|
25195
25185
|
});
|
|
25196
25186
|
}
|
|
25197
25187
|
removeAccountFromSecureStorage(userId = this.state.activeUserId) {
|
|
@@ -25203,13 +25193,14 @@ class StateService {
|
|
|
25203
25193
|
}
|
|
25204
25194
|
removeAccountFromMemory(userId = this.state.activeUserId) {
|
|
25205
25195
|
delete this.state.accounts[userId];
|
|
25196
|
+
this.accountDiskCache.delete(userId);
|
|
25206
25197
|
}
|
|
25207
25198
|
pruneInMemoryAccounts() {
|
|
25208
25199
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25209
25200
|
// We preserve settings for logged out accounts, but we don't want to consider them when thinking about active account state
|
|
25210
25201
|
for (const userId in this.state.accounts) {
|
|
25211
25202
|
if (!(yield this.getIsAuthenticated({ userId: userId }))) {
|
|
25212
|
-
|
|
25203
|
+
this.removeAccountFromMemory(userId);
|
|
25213
25204
|
}
|
|
25214
25205
|
}
|
|
25215
25206
|
});
|
|
@@ -25266,6 +25257,10 @@ class StateService {
|
|
|
25266
25257
|
}
|
|
25267
25258
|
dynamicallySetActiveUser() {
|
|
25268
25259
|
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25260
|
+
if (this.state.accounts == null || Object.keys(this.state.accounts).length < 1) {
|
|
25261
|
+
yield this.setActiveUser(null);
|
|
25262
|
+
return;
|
|
25263
|
+
}
|
|
25269
25264
|
for (const userId in this.state.accounts) {
|
|
25270
25265
|
if (userId == null) {
|
|
25271
25266
|
continue;
|
|
@@ -25278,6 +25273,16 @@ class StateService {
|
|
|
25278
25273
|
}
|
|
25279
25274
|
});
|
|
25280
25275
|
}
|
|
25276
|
+
getTimeoutBasedStorageOptions(options) {
|
|
25277
|
+
return state_service_awaiter(this, void 0, void 0, function* () {
|
|
25278
|
+
const timeoutAction = yield this.getVaultTimeoutAction({ userId: options === null || options === void 0 ? void 0 : options.userId });
|
|
25279
|
+
const timeout = yield this.getVaultTimeout({ userId: options === null || options === void 0 ? void 0 : options.userId });
|
|
25280
|
+
const defaultOptions = timeoutAction === "logOut" && timeout != null
|
|
25281
|
+
? this.defaultInMemoryOptions
|
|
25282
|
+
: yield this.defaultOnDiskOptions();
|
|
25283
|
+
return this.reconcileOptions(options, defaultOptions);
|
|
25284
|
+
});
|
|
25285
|
+
}
|
|
25281
25286
|
}
|
|
25282
25287
|
|
|
25283
25288
|
;// CONCATENATED MODULE: ./jslib/common/src/enums/stateVersion.ts
|
|
@@ -25285,9 +25290,236 @@ var StateVersion;
|
|
|
25285
25290
|
(function (StateVersion) {
|
|
25286
25291
|
StateVersion[StateVersion["One"] = 1] = "One";
|
|
25287
25292
|
StateVersion[StateVersion["Two"] = 2] = "Two";
|
|
25288
|
-
StateVersion[StateVersion["
|
|
25293
|
+
StateVersion[StateVersion["Three"] = 3] = "Three";
|
|
25294
|
+
StateVersion[StateVersion["Four"] = 4] = "Four";
|
|
25295
|
+
StateVersion[StateVersion["Latest"] = 4] = "Latest";
|
|
25289
25296
|
})(StateVersion || (StateVersion = {}));
|
|
25290
25297
|
|
|
25298
|
+
;// CONCATENATED MODULE: ./jslib/common/src/services/token.service.ts
|
|
25299
|
+
var token_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25300
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25301
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25302
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25303
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25304
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25305
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25306
|
+
});
|
|
25307
|
+
};
|
|
25308
|
+
|
|
25309
|
+
class TokenService {
|
|
25310
|
+
constructor(stateService) {
|
|
25311
|
+
this.stateService = stateService;
|
|
25312
|
+
}
|
|
25313
|
+
static decodeToken(token) {
|
|
25314
|
+
if (token == null) {
|
|
25315
|
+
throw new Error("Token not provided.");
|
|
25316
|
+
}
|
|
25317
|
+
const parts = token.split(".");
|
|
25318
|
+
if (parts.length !== 3) {
|
|
25319
|
+
throw new Error("JWT must have 3 parts");
|
|
25320
|
+
}
|
|
25321
|
+
const decoded = Utils.fromUrlB64ToUtf8(parts[1]);
|
|
25322
|
+
if (decoded == null) {
|
|
25323
|
+
throw new Error("Cannot decode the token");
|
|
25324
|
+
}
|
|
25325
|
+
const decodedToken = JSON.parse(decoded);
|
|
25326
|
+
return decodedToken;
|
|
25327
|
+
}
|
|
25328
|
+
setTokens(accessToken, refreshToken, clientIdClientSecret) {
|
|
25329
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25330
|
+
yield this.setToken(accessToken);
|
|
25331
|
+
yield this.setRefreshToken(refreshToken);
|
|
25332
|
+
if (clientIdClientSecret != null) {
|
|
25333
|
+
yield this.setClientId(clientIdClientSecret[0]);
|
|
25334
|
+
yield this.setClientSecret(clientIdClientSecret[1]);
|
|
25335
|
+
}
|
|
25336
|
+
});
|
|
25337
|
+
}
|
|
25338
|
+
setClientId(clientId) {
|
|
25339
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25340
|
+
return yield this.stateService.setApiKeyClientId(clientId);
|
|
25341
|
+
});
|
|
25342
|
+
}
|
|
25343
|
+
getClientId() {
|
|
25344
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25345
|
+
return yield this.stateService.getApiKeyClientId();
|
|
25346
|
+
});
|
|
25347
|
+
}
|
|
25348
|
+
setClientSecret(clientSecret) {
|
|
25349
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25350
|
+
return yield this.stateService.setApiKeyClientSecret(clientSecret);
|
|
25351
|
+
});
|
|
25352
|
+
}
|
|
25353
|
+
getClientSecret() {
|
|
25354
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25355
|
+
return yield this.stateService.getApiKeyClientSecret();
|
|
25356
|
+
});
|
|
25357
|
+
}
|
|
25358
|
+
setToken(token) {
|
|
25359
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25360
|
+
yield this.stateService.setAccessToken(token);
|
|
25361
|
+
});
|
|
25362
|
+
}
|
|
25363
|
+
getToken() {
|
|
25364
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25365
|
+
return yield this.stateService.getAccessToken();
|
|
25366
|
+
});
|
|
25367
|
+
}
|
|
25368
|
+
setRefreshToken(refreshToken) {
|
|
25369
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25370
|
+
return yield this.stateService.setRefreshToken(refreshToken);
|
|
25371
|
+
});
|
|
25372
|
+
}
|
|
25373
|
+
getRefreshToken() {
|
|
25374
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25375
|
+
return yield this.stateService.getRefreshToken();
|
|
25376
|
+
});
|
|
25377
|
+
}
|
|
25378
|
+
toggleTokens() {
|
|
25379
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25380
|
+
const token = yield this.getToken();
|
|
25381
|
+
const refreshToken = yield this.getRefreshToken();
|
|
25382
|
+
const clientId = yield this.getClientId();
|
|
25383
|
+
const clientSecret = yield this.getClientSecret();
|
|
25384
|
+
const timeout = yield this.stateService.getVaultTimeout();
|
|
25385
|
+
const action = yield this.stateService.getVaultTimeoutAction();
|
|
25386
|
+
if ((timeout != null || timeout === 0) && action === "logOut") {
|
|
25387
|
+
// if we have a vault timeout and the action is log out, reset tokens
|
|
25388
|
+
yield this.clearToken();
|
|
25389
|
+
}
|
|
25390
|
+
yield this.setToken(token);
|
|
25391
|
+
yield this.setRefreshToken(refreshToken);
|
|
25392
|
+
yield this.setClientId(clientId);
|
|
25393
|
+
yield this.setClientSecret(clientSecret);
|
|
25394
|
+
});
|
|
25395
|
+
}
|
|
25396
|
+
setTwoFactorToken(token) {
|
|
25397
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25398
|
+
return yield this.stateService.setTwoFactorToken(token);
|
|
25399
|
+
});
|
|
25400
|
+
}
|
|
25401
|
+
getTwoFactorToken() {
|
|
25402
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25403
|
+
return yield this.stateService.getTwoFactorToken();
|
|
25404
|
+
});
|
|
25405
|
+
}
|
|
25406
|
+
clearTwoFactorToken() {
|
|
25407
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25408
|
+
return yield this.stateService.setTwoFactorToken(null);
|
|
25409
|
+
});
|
|
25410
|
+
}
|
|
25411
|
+
clearToken(userId) {
|
|
25412
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25413
|
+
yield this.stateService.setAccessToken(null, { userId: userId });
|
|
25414
|
+
yield this.stateService.setRefreshToken(null, { userId: userId });
|
|
25415
|
+
yield this.stateService.setApiKeyClientId(null, { userId: userId });
|
|
25416
|
+
yield this.stateService.setApiKeyClientSecret(null, { userId: userId });
|
|
25417
|
+
});
|
|
25418
|
+
}
|
|
25419
|
+
// jwthelper methods
|
|
25420
|
+
// ref https://github.com/auth0/angular-jwt/blob/master/src/angularJwt/services/jwt.js
|
|
25421
|
+
decodeToken(token) {
|
|
25422
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25423
|
+
const storedToken = yield this.stateService.getDecodedToken();
|
|
25424
|
+
if (token === null && storedToken != null) {
|
|
25425
|
+
return storedToken;
|
|
25426
|
+
}
|
|
25427
|
+
token = token !== null && token !== void 0 ? token : (yield this.stateService.getAccessToken());
|
|
25428
|
+
if (token == null) {
|
|
25429
|
+
throw new Error("Token not found.");
|
|
25430
|
+
}
|
|
25431
|
+
return TokenService.decodeToken(token);
|
|
25432
|
+
});
|
|
25433
|
+
}
|
|
25434
|
+
getTokenExpirationDate() {
|
|
25435
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25436
|
+
const decoded = yield this.decodeToken();
|
|
25437
|
+
if (typeof decoded.exp === "undefined") {
|
|
25438
|
+
return null;
|
|
25439
|
+
}
|
|
25440
|
+
const d = new Date(0); // The 0 here is the key, which sets the date to the epoch
|
|
25441
|
+
d.setUTCSeconds(decoded.exp);
|
|
25442
|
+
return d;
|
|
25443
|
+
});
|
|
25444
|
+
}
|
|
25445
|
+
tokenSecondsRemaining(offsetSeconds = 0) {
|
|
25446
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25447
|
+
const d = yield this.getTokenExpirationDate();
|
|
25448
|
+
if (d == null) {
|
|
25449
|
+
return 0;
|
|
25450
|
+
}
|
|
25451
|
+
const msRemaining = d.valueOf() - (new Date().valueOf() + offsetSeconds * 1000);
|
|
25452
|
+
return Math.round(msRemaining / 1000);
|
|
25453
|
+
});
|
|
25454
|
+
}
|
|
25455
|
+
tokenNeedsRefresh(minutes = 5) {
|
|
25456
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25457
|
+
const sRemaining = yield this.tokenSecondsRemaining();
|
|
25458
|
+
return sRemaining < 60 * minutes;
|
|
25459
|
+
});
|
|
25460
|
+
}
|
|
25461
|
+
getUserId() {
|
|
25462
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25463
|
+
const decoded = yield this.decodeToken();
|
|
25464
|
+
if (typeof decoded.sub === "undefined") {
|
|
25465
|
+
throw new Error("No user id found");
|
|
25466
|
+
}
|
|
25467
|
+
return decoded.sub;
|
|
25468
|
+
});
|
|
25469
|
+
}
|
|
25470
|
+
getEmail() {
|
|
25471
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25472
|
+
const decoded = yield this.decodeToken();
|
|
25473
|
+
if (typeof decoded.email === "undefined") {
|
|
25474
|
+
throw new Error("No email found");
|
|
25475
|
+
}
|
|
25476
|
+
return decoded.email;
|
|
25477
|
+
});
|
|
25478
|
+
}
|
|
25479
|
+
getEmailVerified() {
|
|
25480
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25481
|
+
const decoded = yield this.decodeToken();
|
|
25482
|
+
if (typeof decoded.email_verified === "undefined") {
|
|
25483
|
+
throw new Error("No email verification found");
|
|
25484
|
+
}
|
|
25485
|
+
return decoded.email_verified;
|
|
25486
|
+
});
|
|
25487
|
+
}
|
|
25488
|
+
getName() {
|
|
25489
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25490
|
+
const decoded = yield this.decodeToken();
|
|
25491
|
+
if (typeof decoded.name === "undefined") {
|
|
25492
|
+
return null;
|
|
25493
|
+
}
|
|
25494
|
+
return decoded.name;
|
|
25495
|
+
});
|
|
25496
|
+
}
|
|
25497
|
+
getPremium() {
|
|
25498
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25499
|
+
const decoded = yield this.decodeToken();
|
|
25500
|
+
if (typeof decoded.premium === "undefined") {
|
|
25501
|
+
return false;
|
|
25502
|
+
}
|
|
25503
|
+
return decoded.premium;
|
|
25504
|
+
});
|
|
25505
|
+
}
|
|
25506
|
+
getIssuer() {
|
|
25507
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25508
|
+
const decoded = yield this.decodeToken();
|
|
25509
|
+
if (typeof decoded.iss === "undefined") {
|
|
25510
|
+
throw new Error("No issuer found");
|
|
25511
|
+
}
|
|
25512
|
+
return decoded.iss;
|
|
25513
|
+
});
|
|
25514
|
+
}
|
|
25515
|
+
getIsExternal() {
|
|
25516
|
+
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
25517
|
+
const decoded = yield this.decodeToken();
|
|
25518
|
+
return Array.isArray(decoded.amr) && decoded.amr.includes("external");
|
|
25519
|
+
});
|
|
25520
|
+
}
|
|
25521
|
+
}
|
|
25522
|
+
|
|
25291
25523
|
;// CONCATENATED MODULE: ./jslib/common/src/services/stateMigration.service.ts
|
|
25292
25524
|
var stateMigration_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25293
25525
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -25300,6 +25532,7 @@ var stateMigration_service_awaiter = (undefined && undefined.__awaiter) || funct
|
|
|
25300
25532
|
};
|
|
25301
25533
|
|
|
25302
25534
|
|
|
25535
|
+
|
|
25303
25536
|
// Originally (before January 2022) storage was handled as a flat key/value pair store.
|
|
25304
25537
|
// With the move to a typed object for state storage these keys should no longer be in use anywhere outside of this migration.
|
|
25305
25538
|
const v1Keys = {
|
|
@@ -25423,6 +25656,12 @@ class StateMigrationService {
|
|
|
25423
25656
|
case StateVersion.One:
|
|
25424
25657
|
yield this.migrateStateFrom1To2();
|
|
25425
25658
|
break;
|
|
25659
|
+
case StateVersion.Two:
|
|
25660
|
+
yield this.migrateStateFrom2To3();
|
|
25661
|
+
break;
|
|
25662
|
+
case StateVersion.Three:
|
|
25663
|
+
yield this.migrateStateFrom3To4();
|
|
25664
|
+
break;
|
|
25426
25665
|
}
|
|
25427
25666
|
currentStateVersion += 1;
|
|
25428
25667
|
}
|
|
@@ -25630,6 +25869,40 @@ class StateMigrationService {
|
|
|
25630
25869
|
}
|
|
25631
25870
|
});
|
|
25632
25871
|
}
|
|
25872
|
+
migrateStateFrom2To3() {
|
|
25873
|
+
return stateMigration_service_awaiter(this, void 0, void 0, function* () {
|
|
25874
|
+
const authenticatedUserIds = yield this.get(stateMigration_service_keys.authenticatedAccounts);
|
|
25875
|
+
yield Promise.all(authenticatedUserIds.map((userId) => stateMigration_service_awaiter(this, void 0, void 0, function* () {
|
|
25876
|
+
var _a, _b;
|
|
25877
|
+
const account = yield this.get(userId);
|
|
25878
|
+
if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.hasPremiumPersonally) === null &&
|
|
25879
|
+
((_b = account.tokens) === null || _b === void 0 ? void 0 : _b.accessToken) != null) {
|
|
25880
|
+
const decodedToken = yield TokenService.decodeToken(account.tokens.accessToken);
|
|
25881
|
+
account.profile.hasPremiumPersonally = decodedToken.premium;
|
|
25882
|
+
yield this.set(userId, account);
|
|
25883
|
+
}
|
|
25884
|
+
})));
|
|
25885
|
+
const globals = yield this.getGlobals();
|
|
25886
|
+
globals.stateVersion = StateVersion.Three;
|
|
25887
|
+
yield this.set(stateMigration_service_keys.global, globals);
|
|
25888
|
+
});
|
|
25889
|
+
}
|
|
25890
|
+
migrateStateFrom3To4() {
|
|
25891
|
+
return stateMigration_service_awaiter(this, void 0, void 0, function* () {
|
|
25892
|
+
const authenticatedUserIds = yield this.get(stateMigration_service_keys.authenticatedAccounts);
|
|
25893
|
+
yield Promise.all(authenticatedUserIds.map((userId) => stateMigration_service_awaiter(this, void 0, void 0, function* () {
|
|
25894
|
+
var _a;
|
|
25895
|
+
const account = yield this.get(userId);
|
|
25896
|
+
if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.everBeenUnlocked) != null) {
|
|
25897
|
+
delete account.profile.everBeenUnlocked;
|
|
25898
|
+
return this.set(userId, account);
|
|
25899
|
+
}
|
|
25900
|
+
})));
|
|
25901
|
+
const globals = yield this.getGlobals();
|
|
25902
|
+
globals.stateVersion = StateVersion.Four;
|
|
25903
|
+
yield this.set(stateMigration_service_keys.global, globals);
|
|
25904
|
+
});
|
|
25905
|
+
}
|
|
25633
25906
|
get options() {
|
|
25634
25907
|
return { htmlStorageLocation: HtmlStorageLocation.Local };
|
|
25635
25908
|
}
|
|
@@ -26007,10 +26280,8 @@ class SyncService {
|
|
|
26007
26280
|
organizations[o.id].isProviderUser = true;
|
|
26008
26281
|
}
|
|
26009
26282
|
});
|
|
26010
|
-
yield
|
|
26011
|
-
|
|
26012
|
-
this.providerService.save(providers),
|
|
26013
|
-
]);
|
|
26283
|
+
yield this.organizationService.save(organizations);
|
|
26284
|
+
yield this.providerService.save(providers);
|
|
26014
26285
|
if (yield this.keyConnectorService.userNeedsMigration()) {
|
|
26015
26286
|
yield this.keyConnectorService.setConvertAccountRequired(true);
|
|
26016
26287
|
this.messagingService.send("convertAccountToKeyConnector");
|
|
@@ -26085,225 +26356,6 @@ class SyncService {
|
|
|
26085
26356
|
}
|
|
26086
26357
|
}
|
|
26087
26358
|
|
|
26088
|
-
;// CONCATENATED MODULE: ./jslib/common/src/services/token.service.ts
|
|
26089
|
-
var token_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26090
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26091
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26092
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26093
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26094
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26095
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26096
|
-
});
|
|
26097
|
-
};
|
|
26098
|
-
|
|
26099
|
-
class TokenService {
|
|
26100
|
-
constructor(stateService) {
|
|
26101
|
-
this.stateService = stateService;
|
|
26102
|
-
}
|
|
26103
|
-
setTokens(accessToken, refreshToken, clientIdClientSecret) {
|
|
26104
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26105
|
-
yield this.setToken(accessToken);
|
|
26106
|
-
yield this.setRefreshToken(refreshToken);
|
|
26107
|
-
if (clientIdClientSecret != null) {
|
|
26108
|
-
yield this.setClientId(clientIdClientSecret[0]);
|
|
26109
|
-
yield this.setClientSecret(clientIdClientSecret[1]);
|
|
26110
|
-
}
|
|
26111
|
-
});
|
|
26112
|
-
}
|
|
26113
|
-
setClientId(clientId) {
|
|
26114
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26115
|
-
return yield this.stateService.setApiKeyClientId(clientId);
|
|
26116
|
-
});
|
|
26117
|
-
}
|
|
26118
|
-
getClientId() {
|
|
26119
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26120
|
-
return yield this.stateService.getApiKeyClientId();
|
|
26121
|
-
});
|
|
26122
|
-
}
|
|
26123
|
-
setClientSecret(clientSecret) {
|
|
26124
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26125
|
-
return yield this.stateService.setApiKeyClientSecret(clientSecret);
|
|
26126
|
-
});
|
|
26127
|
-
}
|
|
26128
|
-
getClientSecret() {
|
|
26129
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26130
|
-
return yield this.stateService.getApiKeyClientSecret();
|
|
26131
|
-
});
|
|
26132
|
-
}
|
|
26133
|
-
setToken(token) {
|
|
26134
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26135
|
-
yield this.stateService.setAccessToken(token);
|
|
26136
|
-
});
|
|
26137
|
-
}
|
|
26138
|
-
getToken() {
|
|
26139
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26140
|
-
return yield this.stateService.getAccessToken();
|
|
26141
|
-
});
|
|
26142
|
-
}
|
|
26143
|
-
setRefreshToken(refreshToken) {
|
|
26144
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26145
|
-
return yield this.stateService.setRefreshToken(refreshToken);
|
|
26146
|
-
});
|
|
26147
|
-
}
|
|
26148
|
-
getRefreshToken() {
|
|
26149
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26150
|
-
return yield this.stateService.getRefreshToken();
|
|
26151
|
-
});
|
|
26152
|
-
}
|
|
26153
|
-
toggleTokens() {
|
|
26154
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26155
|
-
const token = yield this.getToken();
|
|
26156
|
-
const refreshToken = yield this.getRefreshToken();
|
|
26157
|
-
const clientId = yield this.getClientId();
|
|
26158
|
-
const clientSecret = yield this.getClientSecret();
|
|
26159
|
-
const timeout = yield this.stateService.getVaultTimeout();
|
|
26160
|
-
const action = yield this.stateService.getVaultTimeoutAction();
|
|
26161
|
-
if ((timeout != null || timeout === 0) && action === "logOut") {
|
|
26162
|
-
// if we have a vault timeout and the action is log out, reset tokens
|
|
26163
|
-
yield this.clearToken();
|
|
26164
|
-
}
|
|
26165
|
-
yield this.setToken(token);
|
|
26166
|
-
yield this.setRefreshToken(refreshToken);
|
|
26167
|
-
yield this.setClientId(clientId);
|
|
26168
|
-
yield this.setClientSecret(clientSecret);
|
|
26169
|
-
});
|
|
26170
|
-
}
|
|
26171
|
-
setTwoFactorToken(token) {
|
|
26172
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26173
|
-
return yield this.stateService.setTwoFactorToken(token);
|
|
26174
|
-
});
|
|
26175
|
-
}
|
|
26176
|
-
getTwoFactorToken() {
|
|
26177
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26178
|
-
return yield this.stateService.getTwoFactorToken();
|
|
26179
|
-
});
|
|
26180
|
-
}
|
|
26181
|
-
clearTwoFactorToken() {
|
|
26182
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26183
|
-
return yield this.stateService.setTwoFactorToken(null);
|
|
26184
|
-
});
|
|
26185
|
-
}
|
|
26186
|
-
clearToken(userId) {
|
|
26187
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26188
|
-
yield this.stateService.setAccessToken(null, { userId: userId });
|
|
26189
|
-
yield this.stateService.setRefreshToken(null, { userId: userId });
|
|
26190
|
-
yield this.stateService.setApiKeyClientId(null, { userId: userId });
|
|
26191
|
-
yield this.stateService.setApiKeyClientSecret(null, { userId: userId });
|
|
26192
|
-
});
|
|
26193
|
-
}
|
|
26194
|
-
// jwthelper methods
|
|
26195
|
-
// ref https://github.com/auth0/angular-jwt/blob/master/src/angularJwt/services/jwt.js
|
|
26196
|
-
decodeToken(token) {
|
|
26197
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26198
|
-
const storedToken = yield this.stateService.getDecodedToken();
|
|
26199
|
-
if (token === null && storedToken != null) {
|
|
26200
|
-
return storedToken;
|
|
26201
|
-
}
|
|
26202
|
-
token = token !== null && token !== void 0 ? token : (yield this.stateService.getAccessToken());
|
|
26203
|
-
if (token == null) {
|
|
26204
|
-
throw new Error("Token not found.");
|
|
26205
|
-
}
|
|
26206
|
-
const parts = token.split(".");
|
|
26207
|
-
if (parts.length !== 3) {
|
|
26208
|
-
throw new Error("JWT must have 3 parts");
|
|
26209
|
-
}
|
|
26210
|
-
const decoded = Utils.fromUrlB64ToUtf8(parts[1]);
|
|
26211
|
-
if (decoded == null) {
|
|
26212
|
-
throw new Error("Cannot decode the token");
|
|
26213
|
-
}
|
|
26214
|
-
const decodedToken = JSON.parse(decoded);
|
|
26215
|
-
return decodedToken;
|
|
26216
|
-
});
|
|
26217
|
-
}
|
|
26218
|
-
getTokenExpirationDate() {
|
|
26219
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26220
|
-
const decoded = yield this.decodeToken();
|
|
26221
|
-
if (typeof decoded.exp === "undefined") {
|
|
26222
|
-
return null;
|
|
26223
|
-
}
|
|
26224
|
-
const d = new Date(0); // The 0 here is the key, which sets the date to the epoch
|
|
26225
|
-
d.setUTCSeconds(decoded.exp);
|
|
26226
|
-
return d;
|
|
26227
|
-
});
|
|
26228
|
-
}
|
|
26229
|
-
tokenSecondsRemaining(offsetSeconds = 0) {
|
|
26230
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26231
|
-
const d = yield this.getTokenExpirationDate();
|
|
26232
|
-
if (d == null) {
|
|
26233
|
-
return 0;
|
|
26234
|
-
}
|
|
26235
|
-
const msRemaining = d.valueOf() - (new Date().valueOf() + offsetSeconds * 1000);
|
|
26236
|
-
return Math.round(msRemaining / 1000);
|
|
26237
|
-
});
|
|
26238
|
-
}
|
|
26239
|
-
tokenNeedsRefresh(minutes = 5) {
|
|
26240
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26241
|
-
const sRemaining = yield this.tokenSecondsRemaining();
|
|
26242
|
-
return sRemaining < 60 * minutes;
|
|
26243
|
-
});
|
|
26244
|
-
}
|
|
26245
|
-
getUserId() {
|
|
26246
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26247
|
-
const decoded = yield this.decodeToken();
|
|
26248
|
-
if (typeof decoded.sub === "undefined") {
|
|
26249
|
-
throw new Error("No user id found");
|
|
26250
|
-
}
|
|
26251
|
-
return decoded.sub;
|
|
26252
|
-
});
|
|
26253
|
-
}
|
|
26254
|
-
getEmail() {
|
|
26255
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26256
|
-
const decoded = yield this.decodeToken();
|
|
26257
|
-
if (typeof decoded.email === "undefined") {
|
|
26258
|
-
throw new Error("No email found");
|
|
26259
|
-
}
|
|
26260
|
-
return decoded.email;
|
|
26261
|
-
});
|
|
26262
|
-
}
|
|
26263
|
-
getEmailVerified() {
|
|
26264
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26265
|
-
const decoded = yield this.decodeToken();
|
|
26266
|
-
if (typeof decoded.email_verified === "undefined") {
|
|
26267
|
-
throw new Error("No email verification found");
|
|
26268
|
-
}
|
|
26269
|
-
return decoded.email_verified;
|
|
26270
|
-
});
|
|
26271
|
-
}
|
|
26272
|
-
getName() {
|
|
26273
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26274
|
-
const decoded = yield this.decodeToken();
|
|
26275
|
-
if (typeof decoded.name === "undefined") {
|
|
26276
|
-
return null;
|
|
26277
|
-
}
|
|
26278
|
-
return decoded.name;
|
|
26279
|
-
});
|
|
26280
|
-
}
|
|
26281
|
-
getPremium() {
|
|
26282
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26283
|
-
const decoded = yield this.decodeToken();
|
|
26284
|
-
if (typeof decoded.premium === "undefined") {
|
|
26285
|
-
return false;
|
|
26286
|
-
}
|
|
26287
|
-
return decoded.premium;
|
|
26288
|
-
});
|
|
26289
|
-
}
|
|
26290
|
-
getIssuer() {
|
|
26291
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26292
|
-
const decoded = yield this.decodeToken();
|
|
26293
|
-
if (typeof decoded.iss === "undefined") {
|
|
26294
|
-
throw new Error("No issuer found");
|
|
26295
|
-
}
|
|
26296
|
-
return decoded.iss;
|
|
26297
|
-
});
|
|
26298
|
-
}
|
|
26299
|
-
getIsExternal() {
|
|
26300
|
-
return token_service_awaiter(this, void 0, void 0, function* () {
|
|
26301
|
-
const decoded = yield this.decodeToken();
|
|
26302
|
-
return Array.isArray(decoded.amr) && decoded.amr.includes("external");
|
|
26303
|
-
});
|
|
26304
|
-
}
|
|
26305
|
-
}
|
|
26306
|
-
|
|
26307
26359
|
;// CONCATENATED MODULE: ./jslib/common/src/services/totp.service.ts
|
|
26308
26360
|
var totp_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26309
26361
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -30365,8 +30417,9 @@ var generate_command_awaiter = (undefined && undefined.__awaiter) || function (t
|
|
|
30365
30417
|
|
|
30366
30418
|
|
|
30367
30419
|
class GenerateCommand {
|
|
30368
|
-
constructor(passwordGenerationService) {
|
|
30420
|
+
constructor(passwordGenerationService, stateService) {
|
|
30369
30421
|
this.passwordGenerationService = passwordGenerationService;
|
|
30422
|
+
this.stateService = stateService;
|
|
30370
30423
|
}
|
|
30371
30424
|
run(cmdOptions) {
|
|
30372
30425
|
return generate_command_awaiter(this, void 0, void 0, function* () {
|
|
@@ -30383,8 +30436,10 @@ class GenerateCommand {
|
|
|
30383
30436
|
capitalize: normalizedOptions.capitalize,
|
|
30384
30437
|
includeNumber: normalizedOptions.includeNumber,
|
|
30385
30438
|
};
|
|
30386
|
-
const enforcedOptions = yield this.
|
|
30387
|
-
|
|
30439
|
+
const enforcedOptions = (yield this.stateService.getIsAuthenticated())
|
|
30440
|
+
? (yield this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0]
|
|
30441
|
+
: options;
|
|
30442
|
+
const password = yield this.passwordGenerationService.generatePassword(enforcedOptions);
|
|
30388
30443
|
const res = new StringResponse(password);
|
|
30389
30444
|
return Response.success(res);
|
|
30390
30445
|
});
|
|
@@ -33549,7 +33604,7 @@ class ServeCommand {
|
|
|
33549
33604
|
this.listCommand = new ListCommand(this.main.cipherService, this.main.folderService, this.main.collectionService, this.main.organizationService, this.main.searchService, this.main.apiService);
|
|
33550
33605
|
this.createCommand = new CreateCommand(this.main.cipherService, this.main.folderService, this.main.stateService, this.main.cryptoService, this.main.apiService);
|
|
33551
33606
|
this.editCommand = new EditCommand(this.main.cipherService, this.main.folderService, this.main.cryptoService, this.main.apiService);
|
|
33552
|
-
this.generateCommand = new GenerateCommand(this.main.passwordGenerationService);
|
|
33607
|
+
this.generateCommand = new GenerateCommand(this.main.passwordGenerationService, this.main.stateService);
|
|
33553
33608
|
this.syncCommand = new SyncCommand(this.main.syncService);
|
|
33554
33609
|
this.statusCommand = new StatusCommand(this.main.environmentService, this.main.syncService, this.main.stateService, this.main.vaultTimeoutService);
|
|
33555
33610
|
this.deleteCommand = new DeleteCommand(this.main.cipherService, this.main.folderService, this.main.stateService, this.main.apiService);
|
|
@@ -34290,7 +34345,7 @@ class Program extends BaseProgram {
|
|
|
34290
34345
|
writeLn("", true);
|
|
34291
34346
|
})
|
|
34292
34347
|
.action((options) => program_awaiter(this, void 0, void 0, function* () {
|
|
34293
|
-
const command = new GenerateCommand(this.main.passwordGenerationService);
|
|
34348
|
+
const command = new GenerateCommand(this.main.passwordGenerationService, this.main.stateService);
|
|
34294
34349
|
const response = yield command.run(options);
|
|
34295
34350
|
this.processResponse(response);
|
|
34296
34351
|
}));
|