@bitwarden/cli 2023.8.2 → 2023.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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":"2023.8.2","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/clients"},"license":"GPL-3.0-only","scripts":{"clean":"rimraf dist","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","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","test":"jest","test:watch":"jest --watch","test:watch:all":"jest --watchAll"},"bin":{"bw":"build/bw.js"},"pkg":{"assets":["./build/**/*","../../node_modules/argon2/**/*"]},"dependencies":{"@koa/multer":"3.0.2","@koa/router":"12.0.0","argon2":"0.30.3","big-integer":"1.6.51","browser-hrtime":"1.1.8","chalk":"4.1.2","commander":"7.2.0","form-data":"4.0.0","https-proxy-agent":"5.0.1","inquirer":"8.2.5","jsdom":"22.1.0","jszip":"3.10.1","koa":"2.14.2","koa-bodyparser":"4.4.0","koa-json":"2.0.2","lowdb":"1.0.0","lunr":"2.3.9","multer":"1.4.5-lts.1","node-fetch":"2.6.11","node-forge":"1.3.1","open":"8.4.2","papaparse":"5.4.1","proper-lockfile":"4.1.2","rxjs":"7.8.1","tldts":"6.0.5","zxcvbn":"4.4.2"}}');
23
+ module.exports = JSON.parse('{"name":"@bitwarden/cli","description":"A secure and free password manager for all of your devices.","version":"2023.9.0","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/clients"},"license":"GPL-3.0-only","scripts":{"clean":"rimraf dist","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","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","test":"jest","test:watch":"jest --watch","test:watch:all":"jest --watchAll"},"bin":{"bw":"build/bw.js"},"pkg":{"assets":["./build/**/*","../../node_modules/argon2/**/*"]},"dependencies":{"@koa/multer":"3.0.2","@koa/router":"12.0.0","argon2":"0.31.0","big-integer":"1.6.51","browser-hrtime":"1.1.8","chalk":"4.1.2","commander":"7.2.0","form-data":"4.0.0","https-proxy-agent":"5.0.1","inquirer":"8.2.6","jsdom":"22.1.0","jszip":"3.10.1","koa":"2.14.2","koa-bodyparser":"4.4.1","koa-json":"2.0.2","lowdb":"1.0.0","lunr":"2.3.9","multer":"1.4.5-lts.1","node-fetch":"2.6.12","node-forge":"1.3.1","open":"8.4.2","papaparse":"5.4.1","proper-lockfile":"4.1.2","rxjs":"7.8.1","tldts":"6.0.14","zxcvbn":"4.4.2"}}');
24
24
 
25
25
  /***/ })
26
26
 
@@ -1462,6 +1462,7 @@ utils_Utils.global = null;
1462
1462
  // Transpiled version of /\p{Emoji_Presentation}/gu using https://mothereff.in/regexpu. Used for compatability in older browsers.
1463
1463
  utils_Utils.regexpEmojiPresentation = /(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])/g;
1464
1464
  utils_Utils.validHosts = ["localhost"];
1465
+ utils_Utils.originalMinimumPasswordLength = 8;
1465
1466
  utils_Utils.minimumPasswordLength = 12;
1466
1467
  utils_Utils.DomainMatchBlacklist = new Map([
1467
1468
  ["google.com", new Set(["script.google.com"])],
@@ -1472,7 +1473,7 @@ utils_Utils.init();
1472
1473
 
1473
1474
 
1474
1475
  function canAccessVaultTab(org) {
1475
- return org.canViewAssignedCollections || org.canViewAllCollections || org.canManageGroups;
1476
+ return org.canViewAssignedCollections || org.canViewAllCollections;
1476
1477
  }
1477
1478
  function canAccessSettingsTab(org) {
1478
1479
  return (org.isOwner ||
@@ -2202,19 +2203,6 @@ var SecureNoteType;
2202
2203
  SecureNoteType[SecureNoteType["Generic"] = 0] = "Generic";
2203
2204
  })(SecureNoteType || (SecureNoteType = {}));
2204
2205
 
2205
- ;// CONCATENATED MODULE: ../../libs/common/src/enums/state-version.enum.ts
2206
- var StateVersion;
2207
- (function (StateVersion) {
2208
- StateVersion[StateVersion["One"] = 1] = "One";
2209
- StateVersion[StateVersion["Two"] = 2] = "Two";
2210
- StateVersion[StateVersion["Three"] = 3] = "Three";
2211
- StateVersion[StateVersion["Four"] = 4] = "Four";
2212
- StateVersion[StateVersion["Five"] = 5] = "Five";
2213
- StateVersion[StateVersion["Six"] = 6] = "Six";
2214
- StateVersion[StateVersion["Seven"] = 7] = "Seven";
2215
- StateVersion[StateVersion["Latest"] = 7] = "Latest";
2216
- })(StateVersion || (StateVersion = {}));
2217
-
2218
2206
  ;// CONCATENATED MODULE: ../../libs/common/src/enums/storage-location.enum.ts
2219
2207
  var StorageLocation;
2220
2208
  (function (StorageLocation) {
@@ -2266,7 +2254,6 @@ var UriMatchType;
2266
2254
 
2267
2255
 
2268
2256
 
2269
-
2270
2257
 
2271
2258
 
2272
2259
 
@@ -2459,7 +2446,7 @@ class Organization {
2459
2446
  return this.isAdmin || this.permissions.deleteAnyCollection;
2460
2447
  }
2461
2448
  get canViewAllCollections() {
2462
- return this.canCreateNewCollections || this.canEditAnyCollection || this.canDeleteAnyCollection;
2449
+ return this.canEditAnyCollection || this.canDeleteAnyCollection;
2463
2450
  }
2464
2451
  get canEditAssignedCollections() {
2465
2452
  return this.isManager || this.permissions.editAssignedCollections;
@@ -3893,12 +3880,29 @@ class AccountDecryptionOptions {
3893
3880
  return null;
3894
3881
  }
3895
3882
  const accountDecryptionOptions = new AccountDecryptionOptions();
3896
- accountDecryptionOptions.hasMasterPassword = response.hasMasterPassword;
3897
- if (response.trustedDeviceOption) {
3898
- accountDecryptionOptions.trustedDeviceOption = new TrustedDeviceUserDecryptionOption(response.trustedDeviceOption.hasAdminApproval, response.trustedDeviceOption.hasLoginApprovingDevice, response.trustedDeviceOption.hasManageResetPasswordPermission);
3883
+ if (response.userDecryptionOptions) {
3884
+ // If the response has userDecryptionOptions, this means it's on a post-TDE server version and can interrogate
3885
+ // the new decryption options.
3886
+ const responseOptions = response.userDecryptionOptions;
3887
+ accountDecryptionOptions.hasMasterPassword = responseOptions.hasMasterPassword;
3888
+ if (responseOptions.trustedDeviceOption) {
3889
+ accountDecryptionOptions.trustedDeviceOption = new TrustedDeviceUserDecryptionOption(responseOptions.trustedDeviceOption.hasAdminApproval, responseOptions.trustedDeviceOption.hasLoginApprovingDevice, responseOptions.trustedDeviceOption.hasManageResetPasswordPermission);
3890
+ }
3891
+ if (responseOptions.keyConnectorOption) {
3892
+ accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(responseOptions.keyConnectorOption.keyConnectorUrl);
3893
+ }
3899
3894
  }
3900
- if (response.keyConnectorOption) {
3901
- accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(response.keyConnectorOption.keyConnectorUrl);
3895
+ else {
3896
+ // If the response does not have userDecryptionOptions, this means it's on a pre-TDE server version and so
3897
+ // we must base our decryption options on the presence of the keyConnectorUrl.
3898
+ // Note that the presence of keyConnectorUrl implies that the user does not have a master password, as in pre-TDE
3899
+ // server versions, a master password short-circuited the addition of the keyConnectorUrl to the response.
3900
+ // TODO: remove this check after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
3901
+ const usingKeyConnector = response.keyConnectorUrl != null;
3902
+ accountDecryptionOptions.hasMasterPassword = !usingKeyConnector;
3903
+ if (usingKeyConnector) {
3904
+ accountDecryptionOptions.keyConnectorOption = new KeyConnectorUserDecryptionOption(response.keyConnectorUrl);
3905
+ }
3902
3906
  }
3903
3907
  return accountDecryptionOptions;
3904
3908
  }
@@ -4240,7 +4244,7 @@ class LogInStrategy {
4240
4244
  refreshToken: tokenResponse.refreshToken,
4241
4245
  }),
4242
4246
  keys: accountKeys,
4243
- decryptionOptions: AccountDecryptionOptions.fromResponse(tokenResponse.userDecryptionOptions),
4247
+ decryptionOptions: AccountDecryptionOptions.fromResponse(tokenResponse),
4244
4248
  adminAuthRequest: adminAuthRequest === null || adminAuthRequest === void 0 ? void 0 : adminAuthRequest.toJSON(),
4245
4249
  }));
4246
4250
  });
@@ -4552,23 +4556,56 @@ class SsoLogInStrategy extends LogInStrategy {
4552
4556
  }
4553
4557
  setMasterKey(tokenResponse) {
4554
4558
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4555
- // TODO: discuss how this is no longer true with TDE
4556
- // eventually we’ll need to support migration of existing TDE users to Key Connector
4557
- const newSsoUser = tokenResponse.key == null;
4558
- if (tokenResponse.keyConnectorUrl != null) {
4559
- if (!newSsoUser) {
4560
- yield this.keyConnectorService.setMasterKeyFromUrl(tokenResponse.keyConnectorUrl);
4559
+ // The only way we can be setting a master key at this point is if we are using Key Connector.
4560
+ // First, check to make sure that we should do so based on the token response.
4561
+ if (this.shouldSetMasterKeyFromKeyConnector(tokenResponse)) {
4562
+ // If we're here, we know that the user should use Key Connector (they have a KeyConnectorUrl) and does not have a master password.
4563
+ // We can now check the key on the token response to see whether they are a brand new user or an existing user.
4564
+ // The presence of a masterKeyEncryptedUserKey indicates that the user has already been provisioned in Key Connector.
4565
+ const newSsoUser = tokenResponse.key == null;
4566
+ if (newSsoUser) {
4567
+ yield this.keyConnectorService.convertNewSsoUserToKeyConnector(tokenResponse, this.orgId);
4561
4568
  }
4562
4569
  else {
4563
- yield this.keyConnectorService.convertNewSsoUserToKeyConnector(tokenResponse, this.orgId);
4570
+ const keyConnectorUrl = this.getKeyConnectorUrl(tokenResponse);
4571
+ yield this.keyConnectorService.setMasterKeyFromUrl(keyConnectorUrl);
4564
4572
  }
4565
4573
  }
4566
4574
  });
4567
4575
  }
4576
+ /**
4577
+ * Determines if it is possible set the `masterKey` from Key Connector.
4578
+ * @param tokenResponse
4579
+ * @returns `true` if the master key can be set from Key Connector, `false` otherwise
4580
+ */
4581
+ shouldSetMasterKeyFromKeyConnector(tokenResponse) {
4582
+ var _a;
4583
+ const userDecryptionOptions = tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.userDecryptionOptions;
4584
+ if (userDecryptionOptions != null) {
4585
+ const userHasMasterPassword = userDecryptionOptions.hasMasterPassword;
4586
+ const userHasKeyConnectorUrl = ((_a = userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl) != null;
4587
+ // In order for us to set the master key from Key Connector, we need to have a Key Connector URL
4588
+ // and the user must not have a master password.
4589
+ return userHasKeyConnectorUrl && !userHasMasterPassword;
4590
+ }
4591
+ else {
4592
+ // In pre-TDE versions of the server, the userDecryptionOptions will not be present.
4593
+ // In this case, we can determine if the user has a master password and has a Key Connector URL by
4594
+ // just checking the keyConnectorUrl property. This is because the server short-circuits on the response
4595
+ // and will not pass back the URL in the response if the user has a master password.
4596
+ // TODO: remove compatibility check after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
4597
+ return tokenResponse.keyConnectorUrl != null;
4598
+ }
4599
+ }
4600
+ getKeyConnectorUrl(tokenResponse) {
4601
+ var _a, _b;
4602
+ // TODO: remove tokenResponse.keyConnectorUrl reference after 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
4603
+ const userDecryptionOptions = tokenResponse === null || tokenResponse === void 0 ? void 0 : tokenResponse.userDecryptionOptions;
4604
+ return ((_a = tokenResponse.keyConnectorUrl) !== null && _a !== void 0 ? _a : (_b = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _b === void 0 ? void 0 : _b.keyConnectorUrl);
4605
+ }
4568
4606
  // TODO: future passkey login strategy will need to support setting user key (decrypting via TDE or admin approval request)
4569
4607
  // so might be worth moving this logic to a common place (base login strategy or a separate service?)
4570
4608
  setUserKey(tokenResponse) {
4571
- var _a;
4572
4609
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4573
4610
  const masterKeyEncryptedUserKey = tokenResponse.key;
4574
4611
  // Note: masterKeyEncryptedUserKey is undefined for SSO JIT provisioned users
@@ -4588,13 +4625,13 @@ class SsoLogInStrategy extends LogInStrategy {
4588
4625
  yield this.trySetUserKeyWithDeviceKey(tokenResponse);
4589
4626
  }
4590
4627
  }
4591
- else if (
4592
- // TODO: remove tokenResponse.keyConnectorUrl when it's deprecated
4593
- masterKeyEncryptedUserKey != null &&
4594
- (tokenResponse.keyConnectorUrl || ((_a = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl))) {
4628
+ else if (masterKeyEncryptedUserKey != null &&
4629
+ this.getKeyConnectorUrl(tokenResponse) != null) {
4595
4630
  // Key connector enabled for user
4596
4631
  yield this.trySetUserKeyWithMasterKey();
4597
4632
  }
4633
+ // Note: In the traditional SSO flow with MP without key connector, the lock component
4634
+ // is responsible for deriving master key from MP entry and then decrypting the user key
4598
4635
  });
4599
4636
  }
4600
4637
  trySetUserKeyWithApprovedAdminRequestIfExists() {
@@ -4659,8 +4696,12 @@ class SsoLogInStrategy extends LogInStrategy {
4659
4696
  trySetUserKeyWithMasterKey() {
4660
4697
  return sso_login_strategy_awaiter(this, void 0, void 0, function* () {
4661
4698
  const masterKey = yield this.cryptoService.getMasterKey();
4699
+ // There is a scenario in which the master key is not set here. That will occur if the user
4700
+ // has a master password and is using Key Connector. In that case, we cannot set the master key
4701
+ // because the user hasn't entered their master password yet.
4702
+ // Instead, we'll return here and let the migration to Key Connector handle setting the master key.
4662
4703
  if (!masterKey) {
4663
- throw new Error("Master key not found");
4704
+ return;
4664
4705
  }
4665
4706
  const userKey = yield this.cryptoService.decryptUserKeyWithMasterKey(masterKey);
4666
4707
  yield this.cryptoService.setUserKey(userKey);
@@ -5138,7 +5179,7 @@ class DeviceTrustCryptoService {
5138
5179
  makeDeviceKey() {
5139
5180
  return device_trust_crypto_service_implementation_awaiter(this, void 0, void 0, function* () {
5140
5181
  // Create 512-bit device key
5141
- const randomBytes = yield this.cryptoFunctionService.randomBytes(64);
5182
+ const randomBytes = yield this.cryptoFunctionService.aesGenerateKey(512);
5142
5183
  const deviceKey = new SymmetricCryptoKey(randomBytes);
5143
5184
  return deviceKey;
5144
5185
  });
@@ -5383,9 +5424,11 @@ class KeyConnectorService {
5383
5424
  });
5384
5425
  }
5385
5426
  convertNewSsoUserToKeyConnector(tokenResponse, orgId) {
5427
+ var _a;
5386
5428
  return key_connector_service_awaiter(this, void 0, void 0, function* () {
5387
- const { kdf, kdfIterations, kdfMemory, kdfParallelism, keyConnectorUrl } = tokenResponse;
5388
- const password = yield this.cryptoFunctionService.randomBytes(64);
5429
+ // TODO: Remove after tokenResponse.keyConnectorUrl is deprecated in 2023.10 release (https://bitwarden.atlassian.net/browse/PM-3537)
5430
+ const { kdf, kdfIterations, kdfMemory, kdfParallelism, keyConnectorUrl: legacyKeyConnectorUrl, userDecryptionOptions, } = tokenResponse;
5431
+ const password = yield this.cryptoFunctionService.aesGenerateKey(512);
5389
5432
  const kdfConfig = new KdfConfig(kdfIterations, kdfMemory, kdfParallelism);
5390
5433
  const masterKey = yield this.cryptoService.makeMasterKey(utils_Utils.fromBufferToB64(password), yield this.tokenService.getEmail(), kdf, kdfConfig);
5391
5434
  const keyConnectorRequest = new KeyConnectorUserKeyRequest(masterKey.encKeyB64);
@@ -5395,6 +5438,7 @@ class KeyConnectorService {
5395
5438
  yield this.cryptoService.setMasterKeyEncryptedUserKey(userKey[1].encryptedString);
5396
5439
  const [pubKey, privKey] = yield this.cryptoService.makeKeyPair();
5397
5440
  try {
5441
+ const keyConnectorUrl = legacyKeyConnectorUrl !== null && legacyKeyConnectorUrl !== void 0 ? legacyKeyConnectorUrl : (_a = userDecryptionOptions === null || userDecryptionOptions === void 0 ? void 0 : userDecryptionOptions.keyConnectorOption) === null || _a === void 0 ? void 0 : _a.keyConnectorUrl;
5398
5442
  yield this.apiService.postUserKeyToKeyConnector(keyConnectorUrl, keyConnectorRequest);
5399
5443
  }
5400
5444
  catch (e) {
@@ -5677,7 +5721,7 @@ const TwoFactorProviders = {
5677
5721
  description: null,
5678
5722
  priority: 4,
5679
5723
  sort: 5,
5680
- premium: true,
5724
+ premium: false,
5681
5725
  },
5682
5726
  };
5683
5727
  class TwoFactorService {
@@ -5977,7 +6021,6 @@ class GlobalState {
5977
6021
  constructor() {
5978
6022
  this.theme = ThemeType.System;
5979
6023
  this.window = new WindowState();
5980
- this.stateVersion = StateVersion.One;
5981
6024
  this.environmentUrls = new EnvironmentUrls();
5982
6025
  }
5983
6026
  }
@@ -14093,7 +14136,7 @@ class CryptoService {
14093
14136
  if (masterKey == null) {
14094
14137
  throw new Error("No Master Key found.");
14095
14138
  }
14096
- const newUserKey = yield this.cryptoFunctionService.randomBytes(64);
14139
+ const newUserKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14097
14140
  return this.buildProtectedSymmetricKey(masterKey, newUserKey);
14098
14141
  });
14099
14142
  }
@@ -14305,7 +14348,7 @@ class CryptoService {
14305
14348
  if (key == null) {
14306
14349
  throw new Error("No key provided");
14307
14350
  }
14308
- const newSymKey = yield this.cryptoFunctionService.randomBytes(64);
14351
+ const newSymKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14309
14352
  return this.buildProtectedSymmetricKey(key, newSymKey);
14310
14353
  });
14311
14354
  }
@@ -14391,7 +14434,7 @@ class CryptoService {
14391
14434
  }
14392
14435
  makeOrgKey() {
14393
14436
  return crypto_service_awaiter(this, void 0, void 0, function* () {
14394
- const shareKey = yield this.cryptoFunctionService.randomBytes(64);
14437
+ const shareKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14395
14438
  const publicKey = yield this.getPublicKey();
14396
14439
  const encShareKey = yield this.rsaEncrypt(shareKey, publicKey);
14397
14440
  return [encShareKey, new SymmetricCryptoKey(shareKey)];
@@ -14630,8 +14673,8 @@ class CryptoService {
14630
14673
  */
14631
14674
  initAccount() {
14632
14675
  return crypto_service_awaiter(this, void 0, void 0, function* () {
14633
- const randomBytes = yield this.cryptoFunctionService.randomBytes(64);
14634
- const userKey = new SymmetricCryptoKey(randomBytes);
14676
+ const rawKey = yield this.cryptoFunctionService.aesGenerateKey(512);
14677
+ const userKey = new SymmetricCryptoKey(rawKey);
14635
14678
  const [publicKey, privateKey] = yield this.makeKeyPair(userKey);
14636
14679
  yield this.setUserKey(userKey);
14637
14680
  yield this.stateService.setEncryptedPrivateKey(privateKey.encryptedString);
@@ -15215,7 +15258,7 @@ var environment_service_awaiter = (undefined && undefined.__awaiter) || function
15215
15258
  class environment_service_EnvironmentService {
15216
15259
  constructor(stateService) {
15217
15260
  this.stateService = stateService;
15218
- this.urlsSubject = new external_rxjs_namespaceObject.Subject();
15261
+ this.urlsSubject = new external_rxjs_namespaceObject.ReplaySubject(1);
15219
15262
  this.urls = this.urlsSubject.asObservable();
15220
15263
  this.initialized = false;
15221
15264
  this.scimUrl = null;
@@ -15835,8 +15878,32 @@ class NoopMessagingService {
15835
15878
  }
15836
15879
  }
15837
15880
 
15838
- ;// CONCATENATED MODULE: ../../libs/common/src/platform/services/state-migration.service.ts
15839
- var state_migration_service_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
15881
+ ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/data/provider.data.ts
15882
+ class ProviderData {
15883
+ constructor(response) {
15884
+ this.id = response.id;
15885
+ this.name = response.name;
15886
+ this.status = response.status;
15887
+ this.type = response.type;
15888
+ this.enabled = response.enabled;
15889
+ this.userId = response.userId;
15890
+ this.useEvents = response.useEvents;
15891
+ }
15892
+ }
15893
+
15894
+ ;// CONCATENATED MODULE: ../../libs/common/src/enums/vault-timeout-action.enum.ts
15895
+ var VaultTimeoutAction;
15896
+ (function (VaultTimeoutAction) {
15897
+ VaultTimeoutAction["Lock"] = "lock";
15898
+ VaultTimeoutAction["LogOut"] = "logOut";
15899
+ })(VaultTimeoutAction || (VaultTimeoutAction = {}));
15900
+
15901
+ ;// CONCATENATED MODULE: ../../libs/common/src/models/data/event.data.ts
15902
+ class EventData {
15903
+ }
15904
+
15905
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migration-builder.ts
15906
+ var migration_builder_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
15840
15907
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15841
15908
  return new (P || (P = Promise))(function (resolve, reject) {
15842
15909
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -15845,514 +15912,558 @@ var state_migration_service_awaiter = (undefined && undefined.__awaiter) || func
15845
15912
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15846
15913
  });
15847
15914
  };
15848
-
15849
-
15850
-
15851
- // Originally (before January 2022) storage was handled as a flat key/value pair store.
15852
- // With the move to a typed object for state storage these keys should no longer be in use anywhere outside of this migration.
15853
- const v1Keys = {
15854
- accessToken: "accessToken",
15855
- alwaysShowDock: "alwaysShowDock",
15856
- autoConfirmFingerprints: "autoConfirmFingerprints",
15857
- autoFillOnPageLoadDefault: "autoFillOnPageLoadDefault",
15858
- biometricAwaitingAcceptance: "biometricAwaitingAcceptance",
15859
- biometricFingerprintValidated: "biometricFingerprintValidated",
15860
- biometricText: "biometricText",
15861
- biometricUnlock: "biometric",
15862
- clearClipboard: "clearClipboardKey",
15863
- clientId: "apikey_clientId",
15864
- clientSecret: "apikey_clientSecret",
15865
- collapsedGroupings: "collapsedGroupings",
15866
- convertAccountToKeyConnector: "convertAccountToKeyConnector",
15867
- defaultUriMatch: "defaultUriMatch",
15868
- disableAddLoginNotification: "disableAddLoginNotification",
15869
- disableAutoBiometricsPrompt: "noAutoPromptBiometrics",
15870
- disableAutoTotpCopy: "disableAutoTotpCopy",
15871
- disableBadgeCounter: "disableBadgeCounter",
15872
- disableChangedPasswordNotification: "disableChangedPasswordNotification",
15873
- disableContextMenuItem: "disableContextMenuItem",
15874
- disableFavicon: "disableFavicon",
15875
- disableGa: "disableGa",
15876
- dontShowCardsCurrentTab: "dontShowCardsCurrentTab",
15877
- dontShowIdentitiesCurrentTab: "dontShowIdentitiesCurrentTab",
15878
- emailVerified: "emailVerified",
15879
- enableAlwaysOnTop: "enableAlwaysOnTopKey",
15880
- enableAutoFillOnPageLoad: "enableAutoFillOnPageLoad",
15881
- enableBiometric: "enabledBiometric",
15882
- enableBrowserIntegration: "enableBrowserIntegration",
15883
- enableBrowserIntegrationFingerprint: "enableBrowserIntegrationFingerprint",
15884
- enableCloseToTray: "enableCloseToTray",
15885
- enableFullWidth: "enableFullWidth",
15886
- enableMinimizeToTray: "enableMinimizeToTray",
15887
- enableStartToTray: "enableStartToTrayKey",
15888
- enableTray: "enableTray",
15889
- encKey: "encKey",
15890
- encOrgKeys: "encOrgKeys",
15891
- encPrivate: "encPrivateKey",
15892
- encProviderKeys: "encProviderKeys",
15893
- entityId: "entityId",
15894
- entityType: "entityType",
15895
- environmentUrls: "environmentUrls",
15896
- equivalentDomains: "equivalentDomains",
15897
- eventCollection: "eventCollection",
15898
- forcePasswordReset: "forcePasswordReset",
15899
- history: "generatedPasswordHistory",
15900
- installedVersion: "installedVersion",
15901
- kdf: "kdf",
15902
- kdfIterations: "kdfIterations",
15903
- key: "key",
15904
- keyHash: "keyHash",
15905
- lastActive: "lastActive",
15906
- localData: "sitesLocalData",
15907
- locale: "locale",
15908
- mainWindowSize: "mainWindowSize",
15909
- minimizeOnCopyToClipboard: "minimizeOnCopyToClipboardKey",
15910
- neverDomains: "neverDomains",
15911
- noAutoPromptBiometricsText: "noAutoPromptBiometricsText",
15912
- openAtLogin: "openAtLogin",
15913
- passwordGenerationOptions: "passwordGenerationOptions",
15914
- pinProtected: "pinProtectedKey",
15915
- protectedPin: "protectedPin",
15916
- refreshToken: "refreshToken",
15917
- ssoCodeVerifier: "ssoCodeVerifier",
15918
- ssoIdentifier: "ssoOrgIdentifier",
15919
- ssoState: "ssoState",
15920
- stamp: "securityStamp",
15921
- theme: "theme",
15922
- userEmail: "userEmail",
15923
- userId: "userId",
15924
- usesConnector: "usesKeyConnector",
15925
- vaultTimeoutAction: "vaultTimeoutAction",
15926
- vaultTimeout: "lockOption",
15927
- rememberedEmail: "rememberedEmail",
15928
- };
15929
- const v1KeyPrefixes = {
15930
- ciphers: "ciphers_",
15931
- collections: "collections_",
15932
- folders: "folders_",
15933
- lastSync: "lastSync_",
15934
- policies: "policies_",
15935
- twoFactorToken: "twoFactorToken_",
15936
- organizations: "organizations_",
15937
- providers: "providers_",
15938
- sends: "sends_",
15939
- settings: "settings_",
15940
- };
15941
- const keys = {
15942
- global: "global",
15943
- authenticatedAccounts: "authenticatedAccounts",
15944
- activeUserId: "activeUserId",
15945
- tempAccountSettings: "tempAccountSettings",
15946
- accountActivity: "accountActivity",
15947
- };
15948
- const partialKeys = {
15949
- autoKey: "_masterkey_auto",
15950
- biometricKey: "_masterkey_biometric",
15951
- masterKey: "_masterkey",
15915
+ class MigrationBuilder {
15916
+ /** Create a new MigrationBuilder with an empty buffer of migrations to perform.
15917
+ *
15918
+ * Add migrations to the buffer with {@link with} and {@link rollback}.
15919
+ * @returns A new MigrationBuilder.
15920
+ */
15921
+ static create() {
15922
+ return new MigrationBuilder([]);
15923
+ }
15924
+ constructor(migrations) {
15925
+ this.migrations = migrations;
15926
+ }
15927
+ /** Add a migrator to the MigrationBuilder. Types are updated such that the chained MigrationBuilder must currently be
15928
+ * at state version equal to the from version of the migrator. Return as MigrationBuilder<TTo> where TTo is the to
15929
+ * version of the migrator, so that the next migrator can be chained.
15930
+ *
15931
+ * @param migrate A migrator class or a tuple of a migrator class, the from version, and the to version. A tuple is
15932
+ * required to instantiate version numbers unless a default constructor is defined.
15933
+ * @returns A new MigrationBuilder with the to version of the migrator as the current version.
15934
+ */
15935
+ with(...migrate) {
15936
+ return this.addMigrator(migrate, "up");
15937
+ }
15938
+ /** Add a migrator to rollback on the MigrationBuilder's list of migrations. As with {@link with}, types of
15939
+ * MigrationBuilder and Migrator must align. However, this time the migration is reversed so TCurrent of the
15940
+ * MigrationBuilder must be equal to the to version of the migrator. Return as MigrationBuilder<TFrom> where TFrom
15941
+ * is the from version of the migrator, so that the next migrator can be chained.
15942
+ *
15943
+ * @param migrate A migrator class or a tuple of a migrator class, the from version, and the to version. A tuple is
15944
+ * required to instantiate version numbers unless a default constructor is defined.
15945
+ * @returns A new MigrationBuilder with the from version of the migrator as the current version.
15946
+ */
15947
+ rollback(...migrate) {
15948
+ if (migrate.length === 3) {
15949
+ migrate = [migrate[0], migrate[2], migrate[1]];
15950
+ }
15951
+ return this.addMigrator(migrate, "down");
15952
+ }
15953
+ /** Execute the migrations as defined in the MigrationBuilder's migrator buffer */
15954
+ migrate(helper) {
15955
+ return this.migrations.reduce((promise, migrator) => promise.then(() => migration_builder_awaiter(this, void 0, void 0, function* () {
15956
+ yield this.runMigrator(migrator.migrator, helper, migrator.direction);
15957
+ })), Promise.resolve());
15958
+ }
15959
+ addMigrator(migrate, direction = "up") {
15960
+ const newMigration = migrate.length === 1
15961
+ ? { migrator: new migrate[0](), direction }
15962
+ : { migrator: new migrate[0](migrate[1], migrate[2]), direction };
15963
+ return new MigrationBuilder([...this.migrations, newMigration]);
15964
+ }
15965
+ runMigrator(migrator, helper, direction) {
15966
+ return migration_builder_awaiter(this, void 0, void 0, function* () {
15967
+ const shouldMigrate = yield migrator.shouldMigrate(helper, direction);
15968
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) should migrate: ${shouldMigrate} - ${direction}`);
15969
+ if (shouldMigrate) {
15970
+ const method = direction === "up" ? migrator.migrate : migrator.rollback;
15971
+ yield method(helper);
15972
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) migrated - ${direction}`);
15973
+ yield migrator.updateVersion(helper, direction);
15974
+ helper.info(`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) updated version - ${direction}`);
15975
+ }
15976
+ });
15977
+ }
15978
+ }
15979
+
15980
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migration-helper.ts
15981
+ var migration_helper_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
15982
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15983
+ return new (P || (P = Promise))(function (resolve, reject) {
15984
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15985
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15986
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15987
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15988
+ });
15952
15989
  };
15953
- class StateMigrationService {
15954
- constructor(storageService, secureStorageService, stateFactory) {
15990
+ class MigrationHelper {
15991
+ constructor(currentVersion, storageService, logService) {
15992
+ this.currentVersion = currentVersion;
15955
15993
  this.storageService = storageService;
15956
- this.secureStorageService = secureStorageService;
15957
- this.stateFactory = stateFactory;
15994
+ this.logService = logService;
15995
+ }
15996
+ get(key) {
15997
+ return this.storageService.get(key);
15998
+ }
15999
+ set(key, value) {
16000
+ this.logService.info(`Setting ${key}`);
16001
+ return this.storageService.save(key, value);
15958
16002
  }
15959
- needsMigration() {
15960
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
15961
- const currentStateVersion = yield this.getCurrentStateVersion();
15962
- return currentStateVersion == null || currentStateVersion < StateVersion.Latest;
16003
+ info(message) {
16004
+ this.logService.info(message);
16005
+ }
16006
+ getAccounts() {
16007
+ var _a;
16008
+ return migration_helper_awaiter(this, void 0, void 0, function* () {
16009
+ const userIds = (_a = (yield this.get("authenticatedAccounts"))) !== null && _a !== void 0 ? _a : [];
16010
+ return Promise.all(userIds.map((userId) => migration_helper_awaiter(this, void 0, void 0, function* () {
16011
+ return ({
16012
+ userId,
16013
+ account: yield this.get(userId),
16014
+ });
16015
+ })));
15963
16016
  });
15964
16017
  }
15965
- migrate() {
15966
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
15967
- let currentStateVersion = yield this.getCurrentStateVersion();
15968
- while (currentStateVersion < StateVersion.Latest) {
15969
- switch (currentStateVersion) {
15970
- case StateVersion.One:
15971
- yield this.migrateStateFrom1To2();
15972
- break;
15973
- case StateVersion.Two:
15974
- yield this.migrateStateFrom2To3();
15975
- break;
15976
- case StateVersion.Three:
15977
- yield this.migrateStateFrom3To4();
15978
- break;
15979
- case StateVersion.Four: {
15980
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15981
- for (const account of authenticatedAccounts) {
15982
- const migratedAccount = yield this.migrateAccountFrom4To5(account);
15983
- yield this.set(account.profile.userId, migratedAccount);
15984
- }
15985
- yield this.setCurrentStateVersion(StateVersion.Five);
15986
- break;
15987
- }
15988
- case StateVersion.Five: {
15989
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15990
- for (const account of authenticatedAccounts) {
15991
- const migratedAccount = yield this.migrateAccountFrom5To6(account);
15992
- yield this.set(account.profile.userId, migratedAccount);
16018
+ }
16019
+
16020
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrator.ts
16021
+ var migrator_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16022
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16023
+ return new (P || (P = Promise))(function (resolve, reject) {
16024
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16025
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16026
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16027
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16028
+ });
16029
+ };
16030
+ const IRREVERSIBLE = new Error("Irreversible migration");
16031
+ class Migrator {
16032
+ constructor(fromVersion, toVersion) {
16033
+ this.fromVersion = fromVersion;
16034
+ this.toVersion = toVersion;
16035
+ if (fromVersion == null || toVersion == null) {
16036
+ throw new Error("Invalid migration");
16037
+ }
16038
+ if (fromVersion > toVersion) {
16039
+ throw new Error("Invalid migration");
16040
+ }
16041
+ }
16042
+ shouldMigrate(helper, direction) {
16043
+ const startVersion = direction === "up" ? this.fromVersion : this.toVersion;
16044
+ return Promise.resolve(helper.currentVersion === startVersion);
16045
+ }
16046
+ updateVersion(helper, direction) {
16047
+ return migrator_awaiter(this, void 0, void 0, function* () {
16048
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16049
+ helper.currentVersion = endVersion;
16050
+ yield helper.set("stateVersion", endVersion);
16051
+ });
16052
+ }
16053
+ }
16054
+
16055
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/3-fix-premium.ts
16056
+ var _3_fix_premium_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16057
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16058
+ return new (P || (P = Promise))(function (resolve, reject) {
16059
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16060
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16061
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16062
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16063
+ });
16064
+ };
16065
+ // eslint-disable-next-line import/no-restricted-paths -- Used for token decoding, which are valid for days. We want the latest
16066
+
16067
+
16068
+ class FixPremiumMigrator extends Migrator {
16069
+ migrate(helper) {
16070
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16071
+ const accounts = yield helper.getAccounts();
16072
+ function fixPremium(userId, account) {
16073
+ var _a, _b;
16074
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16075
+ if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.hasPremiumPersonally) === null && ((_b = account.tokens) === null || _b === void 0 ? void 0 : _b.accessToken) != null) {
16076
+ let decodedToken;
16077
+ try {
16078
+ decodedToken = yield TokenService.decodeToken(account.tokens.accessToken);
15993
16079
  }
15994
- yield this.setCurrentStateVersion(StateVersion.Six);
15995
- break;
15996
- }
15997
- case StateVersion.Six: {
15998
- const authenticatedAccounts = yield this.getAuthenticatedAccounts();
15999
- const globals = (yield this.getGlobals());
16000
- for (const account of authenticatedAccounts) {
16001
- const migratedAccount = yield this.migrateAccountFrom6To7(globals === null || globals === void 0 ? void 0 : globals.noAutoPromptBiometrics, account);
16002
- yield this.set(account.profile.userId, migratedAccount);
16080
+ catch (_c) {
16081
+ return;
16003
16082
  }
16004
- if (globals) {
16005
- delete globals.noAutoPromptBiometrics;
16083
+ if ((decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.premium) == null) {
16084
+ return;
16006
16085
  }
16007
- yield this.set(keys.global, globals);
16008
- yield this.setCurrentStateVersion(StateVersion.Seven);
16086
+ account.profile.hasPremiumPersonally = decodedToken === null || decodedToken === void 0 ? void 0 : decodedToken.premium;
16087
+ return helper.set(userId, account);
16009
16088
  }
16010
- }
16011
- currentStateVersion += 1;
16089
+ });
16012
16090
  }
16091
+ yield Promise.all(accounts.map(({ userId, account }) => fixPremium(userId, account)));
16013
16092
  });
16014
16093
  }
16015
- migrateStateFrom1To2() {
16016
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22;
16017
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16018
- const clearV1Keys = (clearingUserId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16019
- for (const key in v1Keys) {
16020
- if (key == null) {
16021
- continue;
16022
- }
16023
- yield this.set(v1Keys[key], null);
16024
- }
16025
- if (clearingUserId != null) {
16026
- for (const keyPrefix in v1KeyPrefixes) {
16027
- if (keyPrefix == null) {
16028
- continue;
16029
- }
16030
- yield this.set(v1KeyPrefixes[keyPrefix] + userId, null);
16094
+ rollback(helper) {
16095
+ throw IRREVERSIBLE;
16096
+ }
16097
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16098
+ // it is nested inside a global object.
16099
+ updateVersion(helper, direction) {
16100
+ return _3_fix_premium_awaiter(this, void 0, void 0, function* () {
16101
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16102
+ helper.currentVersion = endVersion;
16103
+ const global = (yield helper.get("global")) || {};
16104
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16105
+ });
16106
+ }
16107
+ }
16108
+
16109
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/4-remove-ever-been-unlocked.ts
16110
+ var _4_remove_ever_been_unlocked_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16111
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16112
+ return new (P || (P = Promise))(function (resolve, reject) {
16113
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16114
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16115
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16116
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16117
+ });
16118
+ };
16119
+
16120
+ class RemoveEverBeenUnlockedMigrator extends Migrator {
16121
+ migrate(helper) {
16122
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16123
+ const accounts = yield helper.getAccounts();
16124
+ function removeEverBeenUnlocked(userId, account) {
16125
+ var _a;
16126
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16127
+ if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.everBeenUnlocked) != null) {
16128
+ delete account.profile.everBeenUnlocked;
16129
+ return helper.set(userId, account);
16031
16130
  }
16032
- }
16033
- });
16034
- // Some processes, like biometrics, may have already defined a value before migrations are run.
16035
- // We don't want to null out those values if they don't exist in the old storage scheme (like for new installs)
16036
- // So, the OOO for migration is that we:
16037
- // 1. Check for an existing storage value from the old storage structure OR
16038
- // 2. Check for a value already set by processes that run before migration OR
16039
- // 3. Assign the default value
16040
- const globals = (_a = (yield this.get(keys.global))) !== null && _a !== void 0 ? _a : this.stateFactory.createGlobal(null);
16041
- globals.stateVersion = StateVersion.Two;
16042
- globals.environmentUrls =
16043
- (_b = (yield this.get(v1Keys.environmentUrls))) !== null && _b !== void 0 ? _b : globals.environmentUrls;
16044
- globals.locale = (_c = (yield this.get(v1Keys.locale))) !== null && _c !== void 0 ? _c : globals.locale;
16045
- globals.noAutoPromptBiometrics =
16046
- (_d = (yield this.get(v1Keys.disableAutoBiometricsPrompt))) !== null && _d !== void 0 ? _d : globals.noAutoPromptBiometrics;
16047
- globals.noAutoPromptBiometricsText =
16048
- (_e = (yield this.get(v1Keys.noAutoPromptBiometricsText))) !== null && _e !== void 0 ? _e : globals.noAutoPromptBiometricsText;
16049
- globals.ssoCodeVerifier =
16050
- (_f = (yield this.get(v1Keys.ssoCodeVerifier))) !== null && _f !== void 0 ? _f : globals.ssoCodeVerifier;
16051
- globals.ssoOrganizationIdentifier =
16052
- (_g = (yield this.get(v1Keys.ssoIdentifier))) !== null && _g !== void 0 ? _g : globals.ssoOrganizationIdentifier;
16053
- globals.ssoState = (_h = (yield this.get(v1Keys.ssoState))) !== null && _h !== void 0 ? _h : globals.ssoState;
16054
- globals.rememberedEmail =
16055
- (_j = (yield this.get(v1Keys.rememberedEmail))) !== null && _j !== void 0 ? _j : globals.rememberedEmail;
16056
- globals.theme = (_k = (yield this.get(v1Keys.theme))) !== null && _k !== void 0 ? _k : globals.theme;
16057
- globals.vaultTimeout = (_l = (yield this.get(v1Keys.vaultTimeout))) !== null && _l !== void 0 ? _l : globals.vaultTimeout;
16058
- globals.vaultTimeoutAction =
16059
- (_m = (yield this.get(v1Keys.vaultTimeoutAction))) !== null && _m !== void 0 ? _m : globals.vaultTimeoutAction;
16060
- globals.window = (_o = (yield this.get(v1Keys.mainWindowSize))) !== null && _o !== void 0 ? _o : globals.window;
16061
- globals.enableTray = (_p = (yield this.get(v1Keys.enableTray))) !== null && _p !== void 0 ? _p : globals.enableTray;
16062
- globals.enableMinimizeToTray =
16063
- (_q = (yield this.get(v1Keys.enableMinimizeToTray))) !== null && _q !== void 0 ? _q : globals.enableMinimizeToTray;
16064
- globals.enableCloseToTray =
16065
- (_r = (yield this.get(v1Keys.enableCloseToTray))) !== null && _r !== void 0 ? _r : globals.enableCloseToTray;
16066
- globals.enableStartToTray =
16067
- (_s = (yield this.get(v1Keys.enableStartToTray))) !== null && _s !== void 0 ? _s : globals.enableStartToTray;
16068
- globals.openAtLogin = (_t = (yield this.get(v1Keys.openAtLogin))) !== null && _t !== void 0 ? _t : globals.openAtLogin;
16069
- globals.alwaysShowDock =
16070
- (_u = (yield this.get(v1Keys.alwaysShowDock))) !== null && _u !== void 0 ? _u : globals.alwaysShowDock;
16071
- globals.enableBrowserIntegration =
16072
- (_v = (yield this.get(v1Keys.enableBrowserIntegration))) !== null && _v !== void 0 ? _v : globals.enableBrowserIntegration;
16073
- globals.enableBrowserIntegrationFingerprint =
16074
- (_w = (yield this.get(v1Keys.enableBrowserIntegrationFingerprint))) !== null && _w !== void 0 ? _w : globals.enableBrowserIntegrationFingerprint;
16075
- const userId = (_x = (yield this.get(v1Keys.userId))) !== null && _x !== void 0 ? _x : (yield this.get(v1Keys.entityId));
16076
- const defaultAccount = this.stateFactory.createAccount(null);
16077
- const accountSettings = {
16078
- autoConfirmFingerPrints: (_y = (yield this.get(v1Keys.autoConfirmFingerprints))) !== null && _y !== void 0 ? _y : defaultAccount.settings.autoConfirmFingerPrints,
16079
- autoFillOnPageLoadDefault: (_z = (yield this.get(v1Keys.autoFillOnPageLoadDefault))) !== null && _z !== void 0 ? _z : defaultAccount.settings.autoFillOnPageLoadDefault,
16080
- biometricUnlock: (_0 = (yield this.get(v1Keys.biometricUnlock))) !== null && _0 !== void 0 ? _0 : defaultAccount.settings.biometricUnlock,
16081
- clearClipboard: (_1 = (yield this.get(v1Keys.clearClipboard))) !== null && _1 !== void 0 ? _1 : defaultAccount.settings.clearClipboard,
16082
- defaultUriMatch: (_2 = (yield this.get(v1Keys.defaultUriMatch))) !== null && _2 !== void 0 ? _2 : defaultAccount.settings.defaultUriMatch,
16083
- disableAddLoginNotification: (_3 = (yield this.get(v1Keys.disableAddLoginNotification))) !== null && _3 !== void 0 ? _3 : defaultAccount.settings.disableAddLoginNotification,
16084
- disableAutoBiometricsPrompt: (_4 = (yield this.get(v1Keys.disableAutoBiometricsPrompt))) !== null && _4 !== void 0 ? _4 : defaultAccount.settings.disableAutoBiometricsPrompt,
16085
- disableAutoTotpCopy: (_5 = (yield this.get(v1Keys.disableAutoTotpCopy))) !== null && _5 !== void 0 ? _5 : defaultAccount.settings.disableAutoTotpCopy,
16086
- disableBadgeCounter: (_6 = (yield this.get(v1Keys.disableBadgeCounter))) !== null && _6 !== void 0 ? _6 : defaultAccount.settings.disableBadgeCounter,
16087
- disableChangedPasswordNotification: (_7 = (yield this.get(v1Keys.disableChangedPasswordNotification))) !== null && _7 !== void 0 ? _7 : defaultAccount.settings.disableChangedPasswordNotification,
16088
- disableContextMenuItem: (_8 = (yield this.get(v1Keys.disableContextMenuItem))) !== null && _8 !== void 0 ? _8 : defaultAccount.settings.disableContextMenuItem,
16089
- disableGa: (_9 = (yield this.get(v1Keys.disableGa))) !== null && _9 !== void 0 ? _9 : defaultAccount.settings.disableGa,
16090
- dontShowCardsCurrentTab: (_10 = (yield this.get(v1Keys.dontShowCardsCurrentTab))) !== null && _10 !== void 0 ? _10 : defaultAccount.settings.dontShowCardsCurrentTab,
16091
- dontShowIdentitiesCurrentTab: (_11 = (yield this.get(v1Keys.dontShowIdentitiesCurrentTab))) !== null && _11 !== void 0 ? _11 : defaultAccount.settings.dontShowIdentitiesCurrentTab,
16092
- enableAlwaysOnTop: (_12 = (yield this.get(v1Keys.enableAlwaysOnTop))) !== null && _12 !== void 0 ? _12 : defaultAccount.settings.enableAlwaysOnTop,
16093
- enableAutoFillOnPageLoad: (_13 = (yield this.get(v1Keys.enableAutoFillOnPageLoad))) !== null && _13 !== void 0 ? _13 : defaultAccount.settings.enableAutoFillOnPageLoad,
16094
- enableBiometric: (_14 = (yield this.get(v1Keys.enableBiometric))) !== null && _14 !== void 0 ? _14 : defaultAccount.settings.enableBiometric,
16095
- enableFullWidth: (_15 = (yield this.get(v1Keys.enableFullWidth))) !== null && _15 !== void 0 ? _15 : defaultAccount.settings.enableFullWidth,
16096
- environmentUrls: (_16 = globals.environmentUrls) !== null && _16 !== void 0 ? _16 : defaultAccount.settings.environmentUrls,
16097
- equivalentDomains: (_17 = (yield this.get(v1Keys.equivalentDomains))) !== null && _17 !== void 0 ? _17 : defaultAccount.settings.equivalentDomains,
16098
- minimizeOnCopyToClipboard: (_18 = (yield this.get(v1Keys.minimizeOnCopyToClipboard))) !== null && _18 !== void 0 ? _18 : defaultAccount.settings.minimizeOnCopyToClipboard,
16099
- neverDomains: (_19 = (yield this.get(v1Keys.neverDomains))) !== null && _19 !== void 0 ? _19 : defaultAccount.settings.neverDomains,
16100
- passwordGenerationOptions: (_20 = (yield this.get(v1Keys.passwordGenerationOptions))) !== null && _20 !== void 0 ? _20 : defaultAccount.settings.passwordGenerationOptions,
16101
- pinProtected: Object.assign(new EncryptionPair(), {
16102
- decrypted: null,
16103
- encrypted: yield this.get(v1Keys.pinProtected),
16104
- }),
16105
- protectedPin: yield this.get(v1Keys.protectedPin),
16106
- settings: userId == null
16107
- ? null
16108
- : yield this.get(v1KeyPrefixes.settings + userId),
16109
- vaultTimeout: (_21 = (yield this.get(v1Keys.vaultTimeout))) !== null && _21 !== void 0 ? _21 : defaultAccount.settings.vaultTimeout,
16110
- vaultTimeoutAction: (_22 = (yield this.get(v1Keys.vaultTimeoutAction))) !== null && _22 !== void 0 ? _22 : defaultAccount.settings.vaultTimeoutAction,
16111
- };
16112
- // (userId == null) = no logged in user (so no known userId) and we need to temporarily store account specific settings in state to migrate on first auth
16113
- // (userId != null) = we have a currently authed user (so known userId) with encrypted data and other key settings we can move, no need to temporarily store account settings
16114
- if (userId == null) {
16115
- yield this.set(keys.tempAccountSettings, accountSettings);
16116
- yield this.set(keys.global, globals);
16117
- yield this.set(keys.authenticatedAccounts, []);
16118
- yield this.set(keys.activeUserId, null);
16119
- yield clearV1Keys();
16120
- return;
16121
- }
16122
- globals.twoFactorToken = yield this.get(v1KeyPrefixes.twoFactorToken + userId);
16123
- yield this.set(keys.global, globals);
16124
- yield this.set(userId, {
16125
- data: {
16126
- addEditCipherInfo: null,
16127
- ciphers: {
16128
- decrypted: null,
16129
- encrypted: yield this.get(v1KeyPrefixes.ciphers + userId),
16130
- },
16131
- collapsedGroupings: null,
16132
- collections: {
16133
- decrypted: null,
16134
- encrypted: yield this.get(v1KeyPrefixes.collections + userId),
16135
- },
16136
- eventCollection: yield this.get(v1Keys.eventCollection),
16137
- folders: {
16138
- decrypted: null,
16139
- encrypted: yield this.get(v1KeyPrefixes.folders + userId),
16140
- },
16141
- localData: null,
16142
- organizations: yield this.get(v1KeyPrefixes.organizations + userId),
16143
- passwordGenerationHistory: {
16144
- decrypted: null,
16145
- encrypted: yield this.get(v1Keys.history),
16146
- },
16147
- policies: {
16148
- decrypted: null,
16149
- encrypted: yield this.get(v1KeyPrefixes.policies + userId),
16150
- },
16151
- providers: yield this.get(v1KeyPrefixes.providers + userId),
16152
- sends: {
16153
- decrypted: null,
16154
- encrypted: yield this.get(v1KeyPrefixes.sends + userId),
16155
- },
16156
- },
16157
- keys: {
16158
- apiKeyClientSecret: yield this.get(v1Keys.clientSecret),
16159
- cryptoMasterKey: null,
16160
- cryptoMasterKeyAuto: null,
16161
- cryptoMasterKeyB64: null,
16162
- cryptoMasterKeyBiometric: null,
16163
- cryptoSymmetricKey: {
16164
- encrypted: yield this.get(v1Keys.encKey),
16165
- decrypted: null,
16166
- },
16167
- legacyEtmKey: null,
16168
- organizationKeys: {
16169
- decrypted: null,
16170
- encrypted: yield this.get(v1Keys.encOrgKeys),
16171
- },
16172
- privateKey: {
16173
- decrypted: null,
16174
- encrypted: yield this.get(v1Keys.encPrivate),
16175
- },
16176
- providerKeys: {
16177
- decrypted: null,
16178
- encrypted: yield this.get(v1Keys.encProviderKeys),
16179
- },
16180
- publicKey: null,
16181
- },
16182
- profile: {
16183
- apiKeyClientId: yield this.get(v1Keys.clientId),
16184
- authenticationStatus: null,
16185
- convertAccountToKeyConnector: yield this.get(v1Keys.convertAccountToKeyConnector),
16186
- email: yield this.get(v1Keys.userEmail),
16187
- emailVerified: yield this.get(v1Keys.emailVerified),
16188
- entityId: null,
16189
- entityType: null,
16190
- everBeenUnlocked: null,
16191
- forcePasswordReset: null,
16192
- hasPremiumPersonally: null,
16193
- kdfIterations: yield this.get(v1Keys.kdfIterations),
16194
- kdfType: yield this.get(v1Keys.kdf),
16195
- keyHash: yield this.get(v1Keys.keyHash),
16196
- lastSync: null,
16197
- userId: userId,
16198
- usesKeyConnector: null,
16199
- },
16200
- settings: accountSettings,
16201
- tokens: {
16202
- accessToken: yield this.get(v1Keys.accessToken),
16203
- decodedToken: null,
16204
- refreshToken: yield this.get(v1Keys.refreshToken),
16205
- securityStamp: null,
16206
- },
16207
- });
16208
- yield this.set(keys.authenticatedAccounts, [userId]);
16209
- yield this.set(keys.activeUserId, userId);
16210
- const accountActivity = {
16211
- [userId]: yield this.get(v1Keys.lastActive),
16212
- };
16213
- accountActivity[userId] = yield this.get(v1Keys.lastActive);
16214
- yield this.set(keys.accountActivity, accountActivity);
16215
- yield clearV1Keys(userId);
16216
- if (yield this.secureStorageService.has(v1Keys.key, { keySuffix: "biometric" })) {
16217
- yield this.secureStorageService.save(`${userId}${partialKeys.biometricKey}`, yield this.secureStorageService.get(v1Keys.key, { keySuffix: "biometric" }), { keySuffix: "biometric" });
16218
- yield this.secureStorageService.remove(v1Keys.key, { keySuffix: "biometric" });
16219
- }
16220
- if (yield this.secureStorageService.has(v1Keys.key, { keySuffix: "auto" })) {
16221
- yield this.secureStorageService.save(`${userId}${partialKeys.autoKey}`, yield this.secureStorageService.get(v1Keys.key, { keySuffix: "auto" }), { keySuffix: "auto" });
16222
- yield this.secureStorageService.remove(v1Keys.key, { keySuffix: "auto" });
16223
- }
16224
- if (yield this.secureStorageService.has(v1Keys.key)) {
16225
- yield this.secureStorageService.save(`${userId}${partialKeys.masterKey}`, yield this.secureStorageService.get(v1Keys.key));
16226
- yield this.secureStorageService.remove(v1Keys.key);
16131
+ });
16227
16132
  }
16133
+ Promise.all(accounts.map(({ userId, account }) => removeEverBeenUnlocked(userId, account)));
16228
16134
  });
16229
16135
  }
16230
- migrateStateFrom2To3() {
16231
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16232
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16233
- yield Promise.all(authenticatedUserIds.map((userId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16234
- var _a, _b;
16235
- const account = yield this.get(userId);
16236
- if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.hasPremiumPersonally) === null &&
16237
- ((_b = account.tokens) === null || _b === void 0 ? void 0 : _b.accessToken) != null) {
16238
- const decodedToken = yield TokenService.decodeToken(account.tokens.accessToken);
16239
- account.profile.hasPremiumPersonally = decodedToken.premium;
16240
- yield this.set(userId, account);
16241
- }
16242
- })));
16243
- const globals = yield this.getGlobals();
16244
- globals.stateVersion = StateVersion.Three;
16245
- yield this.set(keys.global, globals);
16136
+ rollback(helper) {
16137
+ throw IRREVERSIBLE;
16138
+ }
16139
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16140
+ // it is nested inside a global object.
16141
+ updateVersion(helper, direction) {
16142
+ return _4_remove_ever_been_unlocked_awaiter(this, void 0, void 0, function* () {
16143
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16144
+ helper.currentVersion = endVersion;
16145
+ const global = (yield helper.get("global")) || {};
16146
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16246
16147
  });
16247
16148
  }
16248
- migrateStateFrom3To4() {
16249
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16250
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16251
- yield Promise.all(authenticatedUserIds.map((userId) => state_migration_service_awaiter(this, void 0, void 0, function* () {
16252
- var _a;
16253
- const account = yield this.get(userId);
16254
- if (((_a = account === null || account === void 0 ? void 0 : account.profile) === null || _a === void 0 ? void 0 : _a.everBeenUnlocked) != null) {
16255
- delete account.profile.everBeenUnlocked;
16256
- return this.set(userId, account);
16257
- }
16258
- })));
16259
- const globals = yield this.getGlobals();
16260
- globals.stateVersion = StateVersion.Four;
16261
- yield this.set(keys.global, globals);
16149
+ }
16150
+
16151
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/5-add-key-type-to-org-keys.ts
16152
+ var _5_add_key_type_to_org_keys_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16153
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16154
+ return new (P || (P = Promise))(function (resolve, reject) {
16155
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16156
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16157
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16158
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16159
+ });
16160
+ };
16161
+
16162
+ class AddKeyTypeToOrgKeysMigrator extends Migrator {
16163
+ migrate(helper) {
16164
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16165
+ const accounts = yield helper.getAccounts();
16166
+ function updateOrgKey(userId, account) {
16167
+ var _a, _b;
16168
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16169
+ const encryptedOrgKeys = (_b = (_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16170
+ if (encryptedOrgKeys == null) {
16171
+ return;
16172
+ }
16173
+ const newOrgKeys = {};
16174
+ Object.entries(encryptedOrgKeys).forEach(([orgId, encKey]) => {
16175
+ newOrgKeys[orgId] = {
16176
+ type: "organization",
16177
+ key: encKey,
16178
+ };
16179
+ });
16180
+ account.keys.organizationKeys.encrypted = newOrgKeys;
16181
+ yield helper.set(userId, account);
16182
+ });
16183
+ }
16184
+ Promise.all(accounts.map(({ userId, account }) => updateOrgKey(userId, account)));
16262
16185
  });
16263
16186
  }
16264
- migrateAccountFrom4To5(account) {
16265
- var _a, _b;
16266
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16267
- const encryptedOrgKeys = (_b = (_a = account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16268
- if (encryptedOrgKeys != null) {
16269
- for (const [orgId, encKey] of Object.entries(encryptedOrgKeys)) {
16270
- encryptedOrgKeys[orgId] = {
16271
- type: "organization",
16272
- key: encKey, // Account v4 does not reflect the current account model so we have to cast
16273
- };
16274
- }
16187
+ rollback(helper) {
16188
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16189
+ const accounts = yield helper.getAccounts();
16190
+ function updateOrgKey(userId, account) {
16191
+ var _a, _b;
16192
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16193
+ const encryptedOrgKeys = (_b = (_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.organizationKeys) === null || _b === void 0 ? void 0 : _b.encrypted;
16194
+ if (encryptedOrgKeys == null) {
16195
+ return;
16196
+ }
16197
+ const newOrgKeys = {};
16198
+ Object.entries(encryptedOrgKeys).forEach(([orgId, encKey]) => {
16199
+ newOrgKeys[orgId] = encKey.key;
16200
+ });
16201
+ account.keys.organizationKeys.encrypted = newOrgKeys;
16202
+ yield helper.set(userId, account);
16203
+ });
16275
16204
  }
16276
- return account;
16205
+ Promise.all(accounts.map(({ userId, account }) => _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () { return updateOrgKey(userId, account); })));
16277
16206
  });
16278
16207
  }
16279
- migrateAccountFrom5To6(account) {
16280
- var _a;
16281
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16282
- (_a = account.keys) === null || _a === void 0 ? true : delete _a.legacyEtmKey;
16283
- return account;
16208
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16209
+ // it is nested inside a global object.
16210
+ updateVersion(helper, direction) {
16211
+ return _5_add_key_type_to_org_keys_awaiter(this, void 0, void 0, function* () {
16212
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16213
+ helper.currentVersion = endVersion;
16214
+ const global = (yield helper.get("global")) || {};
16215
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16284
16216
  });
16285
16217
  }
16286
- migrateAccountFrom6To7(globalSetting, account) {
16287
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16288
- if (globalSetting) {
16289
- account.settings = Object.assign({}, account.settings, { disableAutoBiometricsPrompt: true });
16218
+ }
16219
+
16220
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/6-remove-legacy-etm-key.ts
16221
+ var _6_remove_legacy_etm_key_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16222
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16223
+ return new (P || (P = Promise))(function (resolve, reject) {
16224
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16225
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16226
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16227
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16228
+ });
16229
+ };
16230
+
16231
+ class RemoveLegacyEtmKeyMigrator extends Migrator {
16232
+ migrate(helper) {
16233
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16234
+ const accounts = yield helper.getAccounts();
16235
+ function updateAccount(userId, account) {
16236
+ var _a;
16237
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16238
+ if ((_a = account === null || account === void 0 ? void 0 : account.keys) === null || _a === void 0 ? void 0 : _a.legacyEtmKey) {
16239
+ delete account.keys.legacyEtmKey;
16240
+ yield helper.set(userId, account);
16241
+ }
16242
+ });
16290
16243
  }
16291
- return account;
16244
+ yield Promise.all(accounts.map(({ userId, account }) => updateAccount(userId, account)));
16292
16245
  });
16293
16246
  }
16294
- get options() {
16295
- return { htmlStorageLocation: HtmlStorageLocation.Local };
16247
+ rollback(helper) {
16248
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16249
+ throw IRREVERSIBLE;
16250
+ });
16296
16251
  }
16297
- get(key) {
16298
- return this.storageService.get(key, this.options);
16252
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16253
+ // it is nested inside a global object.
16254
+ updateVersion(helper, direction) {
16255
+ return _6_remove_legacy_etm_key_awaiter(this, void 0, void 0, function* () {
16256
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16257
+ helper.currentVersion = endVersion;
16258
+ const global = (yield helper.get("global")) || {};
16259
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16260
+ });
16299
16261
  }
16300
- set(key, value) {
16301
- if (value == null) {
16302
- return this.storageService.remove(key, this.options);
16303
- }
16304
- return this.storageService.save(key, value, this.options);
16262
+ }
16263
+
16264
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/7-move-biometric-auto-prompt-to-account.ts
16265
+ var _7_move_biometric_auto_prompt_to_account_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16266
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16267
+ return new (P || (P = Promise))(function (resolve, reject) {
16268
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16269
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16270
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16271
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16272
+ });
16273
+ };
16274
+
16275
+ class MoveBiometricAutoPromptToAccount extends Migrator {
16276
+ migrate(helper) {
16277
+ var _a;
16278
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16279
+ const global = yield helper.get("global");
16280
+ const noAutoPromptBiometrics = (_a = global === null || global === void 0 ? void 0 : global.noAutoPromptBiometrics) !== null && _a !== void 0 ? _a : false;
16281
+ const accounts = yield helper.getAccounts();
16282
+ function updateAccount(userId, account) {
16283
+ var _a;
16284
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16285
+ if (account == null) {
16286
+ return;
16287
+ }
16288
+ if (noAutoPromptBiometrics) {
16289
+ account.settings = Object.assign((_a = account === null || account === void 0 ? void 0 : account.settings) !== null && _a !== void 0 ? _a : {}, {
16290
+ disableAutoBiometricsPrompt: true,
16291
+ });
16292
+ yield helper.set(userId, account);
16293
+ }
16294
+ });
16295
+ }
16296
+ delete global.noAutoPromptBiometrics;
16297
+ yield Promise.all([
16298
+ ...accounts.map(({ userId, account }) => updateAccount(userId, account)),
16299
+ helper.set("global", global),
16300
+ ]);
16301
+ });
16305
16302
  }
16306
- getGlobals() {
16307
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16308
- return yield this.get(keys.global);
16303
+ rollback(helper) {
16304
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16305
+ throw IRREVERSIBLE;
16309
16306
  });
16310
16307
  }
16311
- getCurrentStateVersion() {
16312
- var _a, _b;
16313
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16314
- return (_b = (_a = (yield this.getGlobals())) === null || _a === void 0 ? void 0 : _a.stateVersion) !== null && _b !== void 0 ? _b : StateVersion.One;
16308
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but for this version
16309
+ // it is nested inside a global object.
16310
+ updateVersion(helper, direction) {
16311
+ return _7_move_biometric_auto_prompt_to_account_awaiter(this, void 0, void 0, function* () {
16312
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16313
+ helper.currentVersion = endVersion;
16314
+ const global = (yield helper.get("global")) || {};
16315
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16315
16316
  });
16316
16317
  }
16317
- setCurrentStateVersion(newVersion) {
16318
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16319
- const globals = yield this.getGlobals();
16320
- globals.stateVersion = newVersion;
16321
- yield this.set(keys.global, globals);
16318
+ }
16319
+
16320
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/8-move-state-version.ts
16321
+ var _8_move_state_version_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16322
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16323
+ return new (P || (P = Promise))(function (resolve, reject) {
16324
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16325
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16326
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16327
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16328
+ });
16329
+ };
16330
+
16331
+ class MoveStateVersionMigrator extends Migrator {
16332
+ migrate(helper) {
16333
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16334
+ const global = yield helper.get("global");
16335
+ if (global.stateVersion) {
16336
+ yield helper.set("stateVersion", global.stateVersion);
16337
+ delete global.stateVersion;
16338
+ yield helper.set("global", global);
16339
+ }
16340
+ else {
16341
+ throw new Error("Migration failed, state version not found");
16342
+ }
16322
16343
  });
16323
16344
  }
16324
- getAuthenticatedAccounts() {
16325
- return state_migration_service_awaiter(this, void 0, void 0, function* () {
16326
- const authenticatedUserIds = yield this.get(keys.authenticatedAccounts);
16327
- return Promise.all(authenticatedUserIds.map((id) => this.get(id)));
16345
+ rollback(helper) {
16346
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16347
+ const version = yield helper.get("stateVersion");
16348
+ const global = yield helper.get("global");
16349
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: version }));
16350
+ yield helper.set("stateVersion", undefined);
16351
+ });
16352
+ }
16353
+ // Override is necessary because default implementation assumes `stateVersion` at the root, but this migration moves
16354
+ // it from a `global` object to root.This makes for unique rollback versioning.
16355
+ updateVersion(helper, direction) {
16356
+ return _8_move_state_version_awaiter(this, void 0, void 0, function* () {
16357
+ const endVersion = direction === "up" ? this.toVersion : this.fromVersion;
16358
+ helper.currentVersion = endVersion;
16359
+ if (direction === "up") {
16360
+ yield helper.set("stateVersion", endVersion);
16361
+ }
16362
+ else {
16363
+ const global = (yield helper.get("global")) || {};
16364
+ yield helper.set("global", Object.assign(Object.assign({}, global), { stateVersion: endVersion }));
16365
+ }
16328
16366
  });
16329
16367
  }
16330
16368
  }
16331
16369
 
16332
- ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/data/provider.data.ts
16333
- class ProviderData {
16334
- constructor(response) {
16335
- this.id = response.id;
16336
- this.name = response.name;
16337
- this.status = response.status;
16338
- this.type = response.type;
16339
- this.enabled = response.enabled;
16340
- this.userId = response.userId;
16341
- this.useEvents = response.useEvents;
16370
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrations/min-version.ts
16371
+ var min_version_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16372
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16373
+ return new (P || (P = Promise))(function (resolve, reject) {
16374
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16375
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16376
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16377
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16378
+ });
16379
+ };
16380
+
16381
+
16382
+ function minVersionError(current) {
16383
+ return `Your local data is too old to be migrated. Your current state version is ${current}, but minimum version is ${MIN_VERSION}.`;
16384
+ }
16385
+ class MinVersionMigrator extends Migrator {
16386
+ constructor() {
16387
+ super(0, MIN_VERSION);
16388
+ }
16389
+ // Overrides the default implementation to catch any version that may be passed in.
16390
+ shouldMigrate(helper) {
16391
+ return Promise.resolve(helper.currentVersion < MIN_VERSION);
16392
+ }
16393
+ migrate(helper) {
16394
+ return min_version_awaiter(this, void 0, void 0, function* () {
16395
+ if (helper.currentVersion < MIN_VERSION) {
16396
+ throw new Error(minVersionError(helper.currentVersion));
16397
+ }
16398
+ });
16399
+ }
16400
+ rollback(helper) {
16401
+ return min_version_awaiter(this, void 0, void 0, function* () {
16402
+ throw IRREVERSIBLE;
16403
+ });
16342
16404
  }
16343
16405
  }
16344
16406
 
16345
- ;// CONCATENATED MODULE: ../../libs/common/src/enums/vault-timeout-action.enum.ts
16346
- var VaultTimeoutAction;
16347
- (function (VaultTimeoutAction) {
16348
- VaultTimeoutAction["Lock"] = "lock";
16349
- VaultTimeoutAction["LogOut"] = "logOut";
16350
- })(VaultTimeoutAction || (VaultTimeoutAction = {}));
16351
-
16352
- ;// CONCATENATED MODULE: ../../libs/common/src/models/data/event.data.ts
16353
- class EventData {
16407
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/migrate.ts
16408
+ var migrate_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
16409
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16410
+ return new (P || (P = Promise))(function (resolve, reject) {
16411
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16412
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16413
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16414
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16415
+ });
16416
+ };
16417
+
16418
+
16419
+
16420
+
16421
+
16422
+
16423
+
16424
+
16425
+
16426
+ const MIN_VERSION = 2;
16427
+ const CURRENT_VERSION = 8;
16428
+ function migrate(storageService, logService) {
16429
+ return migrate_awaiter(this, void 0, void 0, function* () {
16430
+ const migrationHelper = new MigrationHelper(yield currentVersion(storageService, logService), storageService, logService);
16431
+ if (migrationHelper.currentVersion < 0) {
16432
+ // Cannot determine state, assuming empty so we don't repeatedly apply a migration.
16433
+ yield storageService.save("stateVersion", CURRENT_VERSION);
16434
+ return;
16435
+ }
16436
+ MigrationBuilder.create()
16437
+ .with(MinVersionMigrator)
16438
+ .with(FixPremiumMigrator, 2, 3)
16439
+ .with(RemoveEverBeenUnlockedMigrator, 3, 4)
16440
+ .with(AddKeyTypeToOrgKeysMigrator, 4, 5)
16441
+ .with(RemoveLegacyEtmKeyMigrator, 5, 6)
16442
+ .with(MoveBiometricAutoPromptToAccount, 6, 7)
16443
+ .with(MoveStateVersionMigrator, 7, CURRENT_VERSION)
16444
+ .migrate(migrationHelper);
16445
+ });
16446
+ }
16447
+ function currentVersion(storageService, logService) {
16448
+ var _a;
16449
+ return migrate_awaiter(this, void 0, void 0, function* () {
16450
+ let state = yield storageService.get("stateVersion");
16451
+ if (state == null) {
16452
+ // Pre v8
16453
+ state = (_a = (yield storageService.get("global"))) === null || _a === void 0 ? void 0 : _a.stateVersion;
16454
+ }
16455
+ if (state == null) {
16456
+ logService.info("No state version found, assuming empty state.");
16457
+ return -1;
16458
+ }
16459
+ logService.info(`State version: ${state}`);
16460
+ return state;
16461
+ });
16354
16462
  }
16355
16463
 
16464
+ ;// CONCATENATED MODULE: ../../libs/common/src/state-migrations/index.ts
16465
+
16466
+
16356
16467
  ;// CONCATENATED MODULE: ../../libs/common/src/admin-console/models/domain/password-generator-policy-options.ts
16357
16468
 
16358
16469
  class PasswordGeneratorPolicyOptions extends Domain {
@@ -18301,15 +18412,17 @@ var state_service_awaiter = (undefined && undefined.__awaiter) || function (this
18301
18412
 
18302
18413
 
18303
18414
 
18304
- const state_service_keys = {
18415
+
18416
+ const keys = {
18305
18417
  state: "state",
18418
+ stateVersion: "stateVersion",
18306
18419
  global: "global",
18307
18420
  authenticatedAccounts: "authenticatedAccounts",
18308
18421
  activeUserId: "activeUserId",
18309
18422
  tempAccountSettings: "tempAccountSettings",
18310
18423
  accountActivity: "accountActivity",
18311
18424
  };
18312
- const state_service_partialKeys = {
18425
+ const partialKeys = {
18313
18426
  userAutoKey: "_user_auto",
18314
18427
  userBiometricKey: "_user_biometric",
18315
18428
  autoKey: "_masterkey_auto",
@@ -18318,12 +18431,11 @@ const state_service_partialKeys = {
18318
18431
  };
18319
18432
  const DDG_SHARED_KEY = "DuckDuckGoSharedKey";
18320
18433
  class StateService {
18321
- constructor(storageService, secureStorageService, memoryStorageService, logService, stateMigrationService, stateFactory, useAccountCache = true) {
18434
+ constructor(storageService, secureStorageService, memoryStorageService, logService, stateFactory, useAccountCache = true) {
18322
18435
  this.storageService = storageService;
18323
18436
  this.secureStorageService = secureStorageService;
18324
18437
  this.memoryStorageService = memoryStorageService;
18325
18438
  this.logService = logService;
18326
- this.stateMigrationService = stateMigrationService;
18327
18439
  this.stateFactory = stateFactory;
18328
18440
  this.useAccountCache = useAccountCache;
18329
18441
  this.accountsSubject = new external_rxjs_namespaceObject.BehaviorSubject({});
@@ -18358,9 +18470,7 @@ class StateService {
18358
18470
  if (this.hasBeenInited) {
18359
18471
  return;
18360
18472
  }
18361
- if (yield this.stateMigrationService.needsMigration()) {
18362
- yield this.stateMigrationService.migrate();
18363
- }
18473
+ yield migrate(this.storageService, this.logService);
18364
18474
  yield this.state().then((state) => state_service_awaiter(this, void 0, void 0, function* () {
18365
18475
  if (state == null) {
18366
18476
  yield this.setState(new State(this.createGlobals()));
@@ -18381,13 +18491,13 @@ class StateService {
18381
18491
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18382
18492
  var _a;
18383
18493
  state.authenticatedAccounts =
18384
- (_a = (yield this.storageService.get(state_service_keys.authenticatedAccounts))) !== null && _a !== void 0 ? _a : [];
18494
+ (_a = (yield this.storageService.get(keys.authenticatedAccounts))) !== null && _a !== void 0 ? _a : [];
18385
18495
  for (const i in state.authenticatedAccounts) {
18386
18496
  if (i != null) {
18387
18497
  yield this.syncAccountFromDisk(state.authenticatedAccounts[i]);
18388
18498
  }
18389
18499
  }
18390
- const storedActiveUser = yield this.storageService.get(state_service_keys.activeUserId);
18500
+ const storedActiveUser = yield this.storageService.get(keys.activeUserId);
18391
18501
  if (storedActiveUser != null) {
18392
18502
  state.activeUserId = storedActiveUser;
18393
18503
  }
@@ -18418,7 +18528,7 @@ class StateService {
18418
18528
  account = yield this.setAccountEnvironment(account);
18419
18529
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18420
18530
  state.authenticatedAccounts.push(account.profile.userId);
18421
- yield this.storageService.save(state_service_keys.authenticatedAccounts, state.authenticatedAccounts);
18531
+ yield this.storageService.save(keys.authenticatedAccounts, state.authenticatedAccounts);
18422
18532
  state.accounts[account.profile.userId] = account;
18423
18533
  return state;
18424
18534
  }));
@@ -18433,7 +18543,7 @@ class StateService {
18433
18543
  this.clearDecryptedDataForActiveUser();
18434
18544
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
18435
18545
  state.activeUserId = userId;
18436
- yield this.storageService.save(state_service_keys.activeUserId, userId);
18546
+ yield this.storageService.save(keys.activeUserId, userId);
18437
18547
  this.activeAccountSubject.next(state.activeUserId);
18438
18548
  return state;
18439
18549
  }));
@@ -18797,7 +18907,7 @@ class StateService {
18797
18907
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18798
18908
  return null;
18799
18909
  }
18800
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.userAutoKey}`, options);
18910
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.userAutoKey}`, options);
18801
18911
  });
18802
18912
  }
18803
18913
  /**
@@ -18809,7 +18919,7 @@ class StateService {
18809
18919
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18810
18920
  return;
18811
18921
  }
18812
- yield this.saveSecureStorageKey(state_service_partialKeys.userAutoKey, value, options);
18922
+ yield this.saveSecureStorageKey(partialKeys.userAutoKey, value, options);
18813
18923
  });
18814
18924
  }
18815
18925
  /**
@@ -18821,7 +18931,7 @@ class StateService {
18821
18931
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18822
18932
  return null;
18823
18933
  }
18824
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.userBiometricKey}`, options);
18934
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.userBiometricKey}`, options);
18825
18935
  });
18826
18936
  }
18827
18937
  hasUserKeyBiometric(options) {
@@ -18830,7 +18940,7 @@ class StateService {
18830
18940
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18831
18941
  return false;
18832
18942
  }
18833
- return yield this.secureStorageService.has(`${options.userId}${state_service_partialKeys.userBiometricKey}`, options);
18943
+ return yield this.secureStorageService.has(`${options.userId}${partialKeys.userBiometricKey}`, options);
18834
18944
  });
18835
18945
  }
18836
18946
  setUserKeyBiometric(value, options) {
@@ -18839,7 +18949,7 @@ class StateService {
18839
18949
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18840
18950
  return;
18841
18951
  }
18842
- yield this.saveSecureStorageKey(state_service_partialKeys.userBiometricKey, value, options);
18952
+ yield this.saveSecureStorageKey(partialKeys.userBiometricKey, value, options);
18843
18953
  });
18844
18954
  }
18845
18955
  getPinKeyEncryptedUserKey(options) {
@@ -18877,7 +18987,7 @@ class StateService {
18877
18987
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18878
18988
  return null;
18879
18989
  }
18880
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.autoKey}`, options);
18990
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.autoKey}`, options);
18881
18991
  });
18882
18992
  }
18883
18993
  /**
@@ -18889,7 +18999,7 @@ class StateService {
18889
18999
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18890
19000
  return;
18891
19001
  }
18892
- yield this.saveSecureStorageKey(state_service_partialKeys.autoKey, value, options);
19002
+ yield this.saveSecureStorageKey(partialKeys.autoKey, value, options);
18893
19003
  });
18894
19004
  }
18895
19005
  /**
@@ -18901,7 +19011,7 @@ class StateService {
18901
19011
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18902
19012
  return null;
18903
19013
  }
18904
- return yield this.secureStorageService.get(`${options === null || options === void 0 ? void 0 : options.userId}${state_service_partialKeys.masterKey}`, options);
19014
+ return yield this.secureStorageService.get(`${options === null || options === void 0 ? void 0 : options.userId}${partialKeys.masterKey}`, options);
18905
19015
  });
18906
19016
  }
18907
19017
  /**
@@ -18913,7 +19023,7 @@ class StateService {
18913
19023
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18914
19024
  return;
18915
19025
  }
18916
- yield this.saveSecureStorageKey(state_service_partialKeys.masterKey, value, options);
19026
+ yield this.saveSecureStorageKey(partialKeys.masterKey, value, options);
18917
19027
  });
18918
19028
  }
18919
19029
  /**
@@ -18925,7 +19035,7 @@ class StateService {
18925
19035
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18926
19036
  return null;
18927
19037
  }
18928
- return yield this.secureStorageService.get(`${options.userId}${state_service_partialKeys.biometricKey}`, options);
19038
+ return yield this.secureStorageService.get(`${options.userId}${partialKeys.biometricKey}`, options);
18929
19039
  });
18930
19040
  }
18931
19041
  /**
@@ -18937,7 +19047,7 @@ class StateService {
18937
19047
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18938
19048
  return false;
18939
19049
  }
18940
- return yield this.secureStorageService.has(`${options.userId}${state_service_partialKeys.biometricKey}`, options);
19050
+ return yield this.secureStorageService.has(`${options.userId}${partialKeys.biometricKey}`, options);
18941
19051
  });
18942
19052
  }
18943
19053
  /**
@@ -18949,7 +19059,7 @@ class StateService {
18949
19059
  if ((options === null || options === void 0 ? void 0 : options.userId) == null) {
18950
19060
  return;
18951
19061
  }
18952
- yield this.saveSecureStorageKey(state_service_partialKeys.biometricKey, value, options);
19062
+ yield this.saveSecureStorageKey(partialKeys.biometricKey, value, options);
18953
19063
  });
18954
19064
  }
18955
19065
  getDecryptedCiphers(options) {
@@ -19875,7 +19985,7 @@ class StateService {
19875
19985
  getLastActive(options) {
19876
19986
  return state_service_awaiter(this, void 0, void 0, function* () {
19877
19987
  options = this.reconcileOptions(options, yield this.defaultOnDiskOptions());
19878
- const accountActivity = yield this.storageService.get(state_service_keys.accountActivity, options);
19988
+ const accountActivity = yield this.storageService.get(keys.accountActivity, options);
19879
19989
  if (accountActivity == null || Object.keys(accountActivity).length < 1) {
19880
19990
  return null;
19881
19991
  }
@@ -19889,9 +19999,9 @@ class StateService {
19889
19999
  if (options.userId == null) {
19890
20000
  return;
19891
20001
  }
19892
- const accountActivity = (_a = (yield this.storageService.get(state_service_keys.accountActivity, options))) !== null && _a !== void 0 ? _a : {};
20002
+ const accountActivity = (_a = (yield this.storageService.get(keys.accountActivity, options))) !== null && _a !== void 0 ? _a : {};
19893
20003
  accountActivity[options.userId] = value;
19894
- yield this.storageService.save(state_service_keys.accountActivity, accountActivity, options);
20004
+ yield this.storageService.save(keys.accountActivity, accountActivity, options);
19895
20005
  });
19896
20006
  }
19897
20007
  getLastSync(options) {
@@ -20316,19 +20426,6 @@ class StateService {
20316
20426
  yield this.saveAccount(account, this.reconcileOptions(options, yield this.defaultOnDiskLocalOptions()));
20317
20427
  });
20318
20428
  }
20319
- getStateVersion() {
20320
- var _a;
20321
- return state_service_awaiter(this, void 0, void 0, function* () {
20322
- return (_a = (yield this.getGlobals(yield this.defaultOnDiskLocalOptions())).stateVersion) !== null && _a !== void 0 ? _a : 1;
20323
- });
20324
- }
20325
- setStateVersion(value) {
20326
- return state_service_awaiter(this, void 0, void 0, function* () {
20327
- const globals = yield this.getGlobals(yield this.defaultOnDiskOptions());
20328
- globals.stateVersion = value;
20329
- yield this.saveGlobals(globals, yield this.defaultOnDiskOptions());
20330
- });
20331
- }
20332
20429
  getWindow() {
20333
20430
  return state_service_awaiter(this, void 0, void 0, function* () {
20334
20431
  const globals = yield this.getGlobals(yield this.defaultOnDiskOptions());
@@ -20405,7 +20502,10 @@ class StateService {
20405
20502
  if (this.useDisk && globals == null) {
20406
20503
  globals = yield this.getGlobalsFromDisk(options);
20407
20504
  }
20408
- return globals !== null && globals !== void 0 ? globals : this.createGlobals();
20505
+ if (globals == null) {
20506
+ globals = this.createGlobals();
20507
+ }
20508
+ return globals;
20409
20509
  });
20410
20510
  }
20411
20511
  saveGlobals(globals, options) {
@@ -20422,7 +20522,7 @@ class StateService {
20422
20522
  }
20423
20523
  getGlobalsFromDisk(options) {
20424
20524
  return state_service_awaiter(this, void 0, void 0, function* () {
20425
- return yield this.storageService.get(state_service_keys.global, options);
20525
+ return yield this.storageService.get(keys.global, options);
20426
20526
  });
20427
20527
  }
20428
20528
  saveGlobalsToMemory(globals) {
@@ -20436,10 +20536,10 @@ class StateService {
20436
20536
  saveGlobalsToDisk(globals, options) {
20437
20537
  return state_service_awaiter(this, void 0, void 0, function* () {
20438
20538
  if (options.useSecureStorage) {
20439
- yield this.secureStorageService.save(state_service_keys.global, globals, options);
20539
+ yield this.secureStorageService.save(keys.global, globals, options);
20440
20540
  }
20441
20541
  else {
20442
- yield this.storageService.save(state_service_keys.global, globals, options);
20542
+ yield this.storageService.save(keys.global, globals, options);
20443
20543
  }
20444
20544
  });
20445
20545
  }
@@ -20557,9 +20657,9 @@ class StateService {
20557
20657
  if ((storedAccount === null || storedAccount === void 0 ? void 0 : storedAccount.settings) != null) {
20558
20658
  account.settings = storedAccount.settings;
20559
20659
  }
20560
- else if (yield this.storageService.has(state_service_keys.tempAccountSettings)) {
20561
- account.settings = yield this.storageService.get(state_service_keys.tempAccountSettings);
20562
- yield this.storageService.remove(state_service_keys.tempAccountSettings);
20660
+ else if (yield this.storageService.has(keys.tempAccountSettings)) {
20661
+ account.settings = yield this.storageService.get(keys.tempAccountSettings);
20662
+ yield this.storageService.remove(keys.tempAccountSettings);
20563
20663
  }
20564
20664
  account.settings.environmentUrls = environmentUrls;
20565
20665
  account.settings.region = region;
@@ -20678,7 +20778,7 @@ class StateService {
20678
20778
  }
20679
20779
  getActiveUserIdFromStorage() {
20680
20780
  return state_service_awaiter(this, void 0, void 0, function* () {
20681
- return yield this.storageService.get(state_service_keys.activeUserId);
20781
+ return yield this.storageService.get(keys.activeUserId);
20682
20782
  });
20683
20783
  }
20684
20784
  removeAccountFromLocalStorage(userId = null) {
@@ -20784,7 +20884,7 @@ class StateService {
20784
20884
  yield this.setLastActive(null, { userId: userId });
20785
20885
  yield this.updateState((state) => state_service_awaiter(this, void 0, void 0, function* () {
20786
20886
  state.authenticatedAccounts = state.authenticatedAccounts.filter((id) => id !== userId);
20787
- yield this.storageService.save(state_service_keys.authenticatedAccounts, state.authenticatedAccounts);
20887
+ yield this.storageService.save(keys.authenticatedAccounts, state.authenticatedAccounts);
20788
20888
  return state;
20789
20889
  }));
20790
20890
  });
@@ -20835,7 +20935,7 @@ class StateService {
20835
20935
  }
20836
20936
  state() {
20837
20937
  return state_service_awaiter(this, void 0, void 0, function* () {
20838
- const state = yield this.memoryStorageService.get(state_service_keys.state, {
20938
+ const state = yield this.memoryStorageService.get(keys.state, {
20839
20939
  deserializer: (s) => State.fromJSON(s, this.accountDeserializer),
20840
20940
  });
20841
20941
  return state;
@@ -20843,7 +20943,7 @@ class StateService {
20843
20943
  }
20844
20944
  setState(state) {
20845
20945
  return state_service_awaiter(this, void 0, void 0, function* () {
20846
- yield this.memoryStorageService.save(state_service_keys.state, state);
20946
+ yield this.memoryStorageService.save(keys.state, state);
20847
20947
  });
20848
20948
  }
20849
20949
  updateState(stateUpdater) {
@@ -22821,7 +22921,7 @@ class SendService {
22821
22921
  send.hideEmail = model.hideEmail;
22822
22922
  send.maxAccessCount = model.maxAccessCount;
22823
22923
  if (model.key == null) {
22824
- model.key = yield this.cryptoFunctionService.randomBytes(16);
22924
+ model.key = yield this.cryptoFunctionService.aesGenerateKey(128);
22825
22925
  model.cryptoKey = yield this.cryptoService.makeSendKey(model.key);
22826
22926
  }
22827
22927
  if (password != null) {
@@ -24625,7 +24725,7 @@ class CipherService {
24625
24725
  createWithServer(cipher, orgAdmin) {
24626
24726
  return cipher_service_awaiter(this, void 0, void 0, function* () {
24627
24727
  let response;
24628
- if (orgAdmin) {
24728
+ if (orgAdmin && cipher.organizationId != null) {
24629
24729
  const request = new CipherCreateRequest(cipher);
24630
24730
  response = yield this.apiService.postCipherAdmin(request);
24631
24731
  }
@@ -26707,6 +26807,43 @@ class LoginExport {
26707
26807
  }
26708
26808
  }
26709
26809
 
26810
+ ;// CONCATENATED MODULE: ../../libs/common/src/models/export/password-history.export.ts
26811
+
26812
+
26813
+
26814
+ class PasswordHistoryExport {
26815
+ static template() {
26816
+ const req = new PasswordHistoryExport();
26817
+ req.password = null;
26818
+ req.lastUsedDate = null;
26819
+ return req;
26820
+ }
26821
+ static toView(req, view = new PasswordHistoryView()) {
26822
+ view.password = req.password;
26823
+ view.lastUsedDate = req.lastUsedDate;
26824
+ return view;
26825
+ }
26826
+ static toDomain(req, domain = new Password()) {
26827
+ domain.password = req.password != null ? new EncString(req.password) : null;
26828
+ domain.lastUsedDate = req.lastUsedDate;
26829
+ return domain;
26830
+ }
26831
+ constructor(o) {
26832
+ var _a;
26833
+ this.lastUsedDate = null;
26834
+ if (o == null) {
26835
+ return;
26836
+ }
26837
+ if (o instanceof PasswordHistoryView) {
26838
+ this.password = o.password;
26839
+ }
26840
+ else {
26841
+ this.password = (_a = o.password) === null || _a === void 0 ? void 0 : _a.encryptedString;
26842
+ }
26843
+ this.lastUsedDate = o.lastUsedDate;
26844
+ }
26845
+ }
26846
+
26710
26847
  ;// CONCATENATED MODULE: ../../libs/common/src/models/export/secure-note.export.ts
26711
26848
 
26712
26849
 
@@ -26744,7 +26881,14 @@ class SecureNoteExport {
26744
26881
 
26745
26882
 
26746
26883
 
26884
+
26747
26885
  class CipherExport {
26886
+ constructor() {
26887
+ this.passwordHistory = null;
26888
+ this.revisionDate = null;
26889
+ this.creationDate = null;
26890
+ this.deletedDate = null;
26891
+ }
26748
26892
  static template() {
26749
26893
  const req = new CipherExport();
26750
26894
  req.organizationId = null;
@@ -26760,6 +26904,10 @@ class CipherExport {
26760
26904
  req.card = null;
26761
26905
  req.identity = null;
26762
26906
  req.reprompt = CipherRepromptType.None;
26907
+ req.passwordHistory = [];
26908
+ req.creationDate = null;
26909
+ req.revisionDate = null;
26910
+ req.deletedDate = null;
26763
26911
  return req;
26764
26912
  }
26765
26913
  static toView(req, view = new CipherView()) {
@@ -26794,6 +26942,12 @@ class CipherExport {
26794
26942
  view.identity = IdentityExport.toView(req.identity);
26795
26943
  break;
26796
26944
  }
26945
+ if (req.passwordHistory != null) {
26946
+ view.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toView(ph));
26947
+ }
26948
+ view.creationDate = req.creationDate;
26949
+ view.revisionDate = req.revisionDate;
26950
+ view.deletedDate = req.deletedDate;
26797
26951
  return view;
26798
26952
  }
26799
26953
  static toDomain(req, domain = new Cipher()) {
@@ -26824,6 +26978,12 @@ class CipherExport {
26824
26978
  domain.identity = IdentityExport.toDomain(req.identity);
26825
26979
  break;
26826
26980
  }
26981
+ if (req.passwordHistory != null) {
26982
+ domain.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toDomain(ph));
26983
+ }
26984
+ domain.creationDate = req.creationDate;
26985
+ domain.revisionDate = req.revisionDate;
26986
+ domain.deletedDate = req.deletedDate;
26827
26987
  return domain;
26828
26988
  }
26829
26989
  // Use build method instead of ctor so that we can control order of JSON stringify for pretty print
@@ -26864,6 +27024,17 @@ class CipherExport {
26864
27024
  this.identity = new IdentityExport(o.identity);
26865
27025
  break;
26866
27026
  }
27027
+ if (o.passwordHistory != null) {
27028
+ if (o instanceof CipherView) {
27029
+ this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
27030
+ }
27031
+ else {
27032
+ this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
27033
+ }
27034
+ }
27035
+ this.creationDate = o.creationDate;
27036
+ this.revisionDate = o.revisionDate;
27037
+ this.deletedDate = o.deletedDate;
26867
27038
  }
26868
27039
  }
26869
27040
 
@@ -27287,17 +27458,14 @@ class VaultExportService {
27287
27458
  const ciphers = [];
27288
27459
  const promises = [];
27289
27460
  promises.push(this.apiService.getCollections(organizationId).then((c) => {
27290
- const collectionPromises = [];
27291
27461
  if (c != null && c.data != null && c.data.length > 0) {
27292
27462
  c.data.forEach((r) => {
27293
27463
  const collection = new Collection(new CollectionData(r));
27294
27464
  collections.push(collection);
27295
27465
  });
27296
27466
  }
27297
- return Promise.all(collectionPromises);
27298
27467
  }));
27299
27468
  promises.push(this.apiService.getCiphersOrganization(organizationId).then((c) => {
27300
- const cipherPromises = [];
27301
27469
  if (c != null && c.data != null && c.data.length > 0) {
27302
27470
  c.data
27303
27471
  .filter((item) => item.deletedDate === null)
@@ -27306,7 +27474,6 @@ class VaultExportService {
27306
27474
  ciphers.push(cipher);
27307
27475
  });
27308
27476
  }
27309
- return Promise.all(cipherPromises);
27310
27477
  }));
27311
27478
  yield Promise.all(promises);
27312
27479
  const orgKey = yield this.cryptoService.getOrgKey(organizationId);
@@ -27802,6 +27969,9 @@ class base_importer_BaseImporter {
27802
27969
  if (cipher.fields != null && cipher.fields.length === 0) {
27803
27970
  cipher.fields = null;
27804
27971
  }
27972
+ if (cipher.passwordHistory != null && cipher.passwordHistory.length === 0) {
27973
+ cipher.passwordHistory = null;
27974
+ }
27805
27975
  }
27806
27976
  processKvp(cipher, key, value, type = FieldType.Text) {
27807
27977
  if (this.isNullOrWhitespace(value)) {
@@ -28247,25 +28417,25 @@ class BitwardenJsonImporter extends base_importer_BaseImporter {
28247
28417
  parse(data) {
28248
28418
  return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28249
28419
  this.result = new import_result_ImportResult();
28250
- this.results = JSON.parse(data);
28251
- if (this.results == null || this.results.items == null) {
28420
+ const results = JSON.parse(data);
28421
+ if (results == null || results.items == null) {
28252
28422
  this.result.success = false;
28253
28423
  return this.result;
28254
28424
  }
28255
- if (this.results.encrypted) {
28256
- yield this.parseEncrypted();
28425
+ if (results.encrypted) {
28426
+ yield this.parseEncrypted(results);
28257
28427
  }
28258
28428
  else {
28259
- this.parseDecrypted();
28429
+ yield this.parseDecrypted(results);
28260
28430
  }
28261
28431
  return this.result;
28262
28432
  });
28263
28433
  }
28264
- parseEncrypted() {
28434
+ parseEncrypted(results) {
28265
28435
  return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28266
- if (this.results.encKeyValidation_DO_NOT_EDIT != null) {
28436
+ if (results.encKeyValidation_DO_NOT_EDIT != null) {
28267
28437
  const orgKey = yield this.cryptoService.getOrgKey(this.organizationId);
28268
- const encKeyValidation = new EncString(this.results.encKeyValidation_DO_NOT_EDIT);
28438
+ const encKeyValidation = new EncString(results.encKeyValidation_DO_NOT_EDIT);
28269
28439
  const encKeyValidationDecrypt = yield this.cryptoService.decryptToUtf8(encKeyValidation, orgKey);
28270
28440
  if (encKeyValidationDecrypt === null) {
28271
28441
  this.result.success = false;
@@ -28273,29 +28443,10 @@ class BitwardenJsonImporter extends base_importer_BaseImporter {
28273
28443
  return;
28274
28444
  }
28275
28445
  }
28276
- const groupingsMap = new Map();
28277
- if (this.organization && this.results.collections != null) {
28278
- for (const c of this.results.collections) {
28279
- const collection = CollectionWithIdExport.toDomain(c);
28280
- if (collection != null) {
28281
- collection.organizationId = this.organizationId;
28282
- const view = yield collection.decrypt();
28283
- groupingsMap.set(c.id, this.result.collections.length);
28284
- this.result.collections.push(view);
28285
- }
28286
- }
28287
- }
28288
- else if (!this.organization && this.results.folders != null) {
28289
- for (const f of this.results.folders) {
28290
- const folder = FolderWithIdExport.toDomain(f);
28291
- if (folder != null) {
28292
- const view = yield folder.decrypt();
28293
- groupingsMap.set(f.id, this.result.folders.length);
28294
- this.result.folders.push(view);
28295
- }
28296
- }
28297
- }
28298
- for (const c of this.results.items) {
28446
+ const groupingsMap = this.organization
28447
+ ? yield this.parseCollections(results)
28448
+ : yield this.parseFolders(results);
28449
+ for (const c of results.items) {
28299
28450
  const cipher = CipherWithIdExport.toDomain(c);
28300
28451
  // reset ids incase they were set for some reason
28301
28452
  cipher.id = null;
@@ -28328,57 +28479,92 @@ class BitwardenJsonImporter extends base_importer_BaseImporter {
28328
28479
  this.result.success = true;
28329
28480
  });
28330
28481
  }
28331
- parseDecrypted() {
28332
- const groupingsMap = new Map();
28333
- if (this.organization && this.results.collections != null) {
28334
- this.results.collections.forEach((c) => {
28335
- const collection = CollectionWithIdExport.toView(c);
28336
- if (collection != null) {
28337
- collection.organizationId = null;
28338
- groupingsMap.set(c.id, this.result.collections.length);
28339
- this.result.collections.push(collection);
28482
+ parseDecrypted(results) {
28483
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28484
+ const groupingsMap = this.organization
28485
+ ? yield this.parseCollections(results)
28486
+ : yield this.parseFolders(results);
28487
+ results.items.forEach((c) => {
28488
+ const cipher = CipherWithIdExport.toView(c);
28489
+ // reset ids incase they were set for some reason
28490
+ cipher.id = null;
28491
+ cipher.organizationId = null;
28492
+ cipher.collectionIds = null;
28493
+ // make sure password history is limited
28494
+ if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) {
28495
+ cipher.passwordHistory = cipher.passwordHistory.slice(0, 5);
28340
28496
  }
28341
- });
28342
- }
28343
- else if (!this.organization && this.results.folders != null) {
28344
- this.results.folders.forEach((f) => {
28345
- const folder = FolderWithIdExport.toView(f);
28346
- if (folder != null) {
28347
- groupingsMap.set(f.id, this.result.folders.length);
28348
- this.result.folders.push(folder);
28497
+ if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) {
28498
+ this.result.folderRelationships.push([
28499
+ this.result.ciphers.length,
28500
+ groupingsMap.get(c.folderId),
28501
+ ]);
28502
+ }
28503
+ else if (this.organization && c.collectionIds != null) {
28504
+ c.collectionIds.forEach((cId) => {
28505
+ if (groupingsMap.has(cId)) {
28506
+ this.result.collectionRelationships.push([
28507
+ this.result.ciphers.length,
28508
+ groupingsMap.get(cId),
28509
+ ]);
28510
+ }
28511
+ });
28349
28512
  }
28513
+ this.cleanupCipher(cipher);
28514
+ this.result.ciphers.push(cipher);
28350
28515
  });
28351
- }
28352
- this.results.items.forEach((c) => {
28353
- const cipher = CipherWithIdExport.toView(c);
28354
- // reset ids incase they were set for some reason
28355
- cipher.id = null;
28356
- cipher.organizationId = null;
28357
- cipher.collectionIds = null;
28358
- // make sure password history is limited
28359
- if (cipher.passwordHistory != null && cipher.passwordHistory.length > 5) {
28360
- cipher.passwordHistory = cipher.passwordHistory.slice(0, 5);
28361
- }
28362
- if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) {
28363
- this.result.folderRelationships.push([
28364
- this.result.ciphers.length,
28365
- groupingsMap.get(c.folderId),
28366
- ]);
28516
+ this.result.success = true;
28517
+ });
28518
+ }
28519
+ parseFolders(data) {
28520
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28521
+ if (data.folders == null) {
28522
+ return null;
28367
28523
  }
28368
- else if (this.organization && c.collectionIds != null) {
28369
- c.collectionIds.forEach((cId) => {
28370
- if (groupingsMap.has(cId)) {
28371
- this.result.collectionRelationships.push([
28372
- this.result.ciphers.length,
28373
- groupingsMap.get(cId),
28374
- ]);
28524
+ const groupingsMap = new Map();
28525
+ for (const f of data.folders) {
28526
+ let folderView;
28527
+ if (data.encrypted) {
28528
+ const folder = FolderWithIdExport.toDomain(f);
28529
+ if (folder != null) {
28530
+ folderView = yield folder.decrypt();
28375
28531
  }
28376
- });
28532
+ }
28533
+ else {
28534
+ folderView = FolderWithIdExport.toView(f);
28535
+ }
28536
+ if (folderView != null) {
28537
+ groupingsMap.set(f.id, this.result.folders.length);
28538
+ this.result.folders.push(folderView);
28539
+ }
28377
28540
  }
28378
- this.cleanupCipher(cipher);
28379
- this.result.ciphers.push(cipher);
28541
+ return groupingsMap;
28542
+ });
28543
+ }
28544
+ parseCollections(data) {
28545
+ return bitwarden_json_importer_awaiter(this, void 0, void 0, function* () {
28546
+ if (data.collections == null) {
28547
+ return null;
28548
+ }
28549
+ const groupingsMap = new Map();
28550
+ for (const c of data.collections) {
28551
+ let collectionView;
28552
+ if (data.encrypted) {
28553
+ const collection = CollectionWithIdExport.toDomain(c);
28554
+ collection.organizationId = this.organizationId;
28555
+ collectionView = yield collection.decrypt();
28556
+ }
28557
+ else {
28558
+ collectionView = CollectionWithIdExport.toView(c);
28559
+ collectionView.organizationId = null;
28560
+ }
28561
+ if (collectionView != null) {
28562
+ groupingsMap.set(c.id, this.result.collections.length);
28563
+ this.result.collections.push(collectionView);
28564
+ }
28565
+ }
28566
+ return groupingsMap;
28380
28567
  });
28381
- this.result.success = true;
28382
28568
  }
28383
28569
  }
28384
28570
 
@@ -32366,6 +32552,97 @@ class PasswordWalletTxtImporter extends base_importer_BaseImporter {
32366
32552
  }
32367
32553
  }
32368
32554
 
32555
+ ;// CONCATENATED MODULE: ../../libs/importer/src/importers/protonpass/types/protonpass-json-type.ts
32556
+ var ProtonPassItemState;
32557
+ (function (ProtonPassItemState) {
32558
+ ProtonPassItemState[ProtonPassItemState["ACTIVE"] = 1] = "ACTIVE";
32559
+ ProtonPassItemState[ProtonPassItemState["TRASHED"] = 2] = "TRASHED";
32560
+ })(ProtonPassItemState || (ProtonPassItemState = {}));
32561
+
32562
+ ;// CONCATENATED MODULE: ../../libs/importer/src/importers/protonpass/protonpass-json-importer.ts
32563
+
32564
+
32565
+
32566
+
32567
+
32568
+
32569
+
32570
+ class ProtonPassJsonImporter extends base_importer_BaseImporter {
32571
+ constructor(i18nService) {
32572
+ super();
32573
+ this.i18nService = i18nService;
32574
+ }
32575
+ parse(data) {
32576
+ const result = new import_result_ImportResult();
32577
+ const results = JSON.parse(data);
32578
+ if (results == null || results.vaults == null) {
32579
+ result.success = false;
32580
+ return Promise.resolve(result);
32581
+ }
32582
+ if (results.encrypted) {
32583
+ result.success = false;
32584
+ result.errorMessage = this.i18nService.t("unsupportedEncryptedImport");
32585
+ return Promise.resolve(result);
32586
+ }
32587
+ for (const [, vault] of Object.entries(results.vaults)) {
32588
+ for (const item of vault.items) {
32589
+ if (item.state == ProtonPassItemState.TRASHED) {
32590
+ continue;
32591
+ }
32592
+ this.processFolder(result, vault.name);
32593
+ const cipher = this.initLoginCipher();
32594
+ cipher.name = item.data.metadata.name;
32595
+ cipher.notes = item.data.metadata.note;
32596
+ switch (item.data.type) {
32597
+ case "login": {
32598
+ const loginContent = item.data.content;
32599
+ cipher.login.uris = this.makeUriArray(loginContent.urls);
32600
+ cipher.login.username = loginContent.username;
32601
+ cipher.login.password = loginContent.password;
32602
+ if (loginContent.totpUri != "") {
32603
+ cipher.login.totp = new URL(loginContent.totpUri).searchParams.get("secret");
32604
+ }
32605
+ for (const extraField of item.data.extraFields) {
32606
+ this.processKvp(cipher, extraField.fieldName, extraField.type == "totp" ? extraField.data.totpUri : extraField.data.content, extraField.type == "text" ? FieldType.Text : FieldType.Hidden);
32607
+ }
32608
+ break;
32609
+ }
32610
+ case "note":
32611
+ cipher.type = CipherType.SecureNote;
32612
+ cipher.secureNote = new SecureNoteView();
32613
+ cipher.secureNote.type = SecureNoteType.Generic;
32614
+ break;
32615
+ case "creditCard": {
32616
+ const creditCardContent = item.data.content;
32617
+ cipher.type = CipherType.Card;
32618
+ cipher.card = new CardView();
32619
+ cipher.card.cardholderName = creditCardContent.cardholderName;
32620
+ cipher.card.number = creditCardContent.number;
32621
+ cipher.card.brand = CardView.getCardBrandByPatterns(creditCardContent.number);
32622
+ cipher.card.code = creditCardContent.verificationNumber;
32623
+ if (!this.isNullOrWhitespace(creditCardContent.expirationDate)) {
32624
+ cipher.card.expMonth = creditCardContent.expirationDate.substring(0, 2);
32625
+ cipher.card.expMonth = cipher.card.expMonth.replace(/^0+/, "");
32626
+ cipher.card.expYear = creditCardContent.expirationDate.substring(2, 6);
32627
+ }
32628
+ if (!this.isNullOrWhitespace(creditCardContent.pin)) {
32629
+ this.processKvp(cipher, "PIN", creditCardContent.pin, FieldType.Hidden);
32630
+ }
32631
+ break;
32632
+ }
32633
+ }
32634
+ this.cleanupCipher(cipher);
32635
+ result.ciphers.push(cipher);
32636
+ }
32637
+ }
32638
+ if (this.organization) {
32639
+ this.moveFoldersToCollections(result);
32640
+ }
32641
+ result.success = true;
32642
+ return Promise.resolve(result);
32643
+ }
32644
+ }
32645
+
32369
32646
  ;// CONCATENATED MODULE: ../../libs/importer/src/importers/psono/psono-json-importer.ts
32370
32647
 
32371
32648
 
@@ -32490,6 +32767,7 @@ class PsonoJsonImporter extends base_importer_BaseImporter {
32490
32767
  return cipher;
32491
32768
  }
32492
32769
  parseWebsiteLogins(entry, cipher) {
32770
+ var _a;
32493
32771
  if (entry == null || entry.type != "website_password") {
32494
32772
  return;
32495
32773
  }
@@ -32498,7 +32776,7 @@ class PsonoJsonImporter extends base_importer_BaseImporter {
32498
32776
  cipher.login.username = entry.website_password_username;
32499
32777
  cipher.login.password = entry.website_password_password;
32500
32778
  cipher.login.uris = this.makeUriArray(entry.website_password_url);
32501
- this.processKvp(cipher, "website_password_auto_submit", entry.website_password_auto_submit.toString(), FieldType.Boolean);
32779
+ this.processKvp(cipher, "website_password_auto_submit", (_a = entry.website_password_auto_submit) === null || _a === void 0 ? void 0 : _a.toString(), FieldType.Boolean);
32502
32780
  this.processKvp(cipher, "website_password_url_filter", entry.website_password_url_filter);
32503
32781
  this.importUnmappedFields(cipher, entry, this.WEBSITE_mappedValues);
32504
32782
  }
@@ -33276,6 +33554,7 @@ class ZohoVaultCsvImporter extends base_importer_BaseImporter {
33276
33554
 
33277
33555
 
33278
33556
 
33557
+
33279
33558
 
33280
33559
 
33281
33560
 
@@ -33303,6 +33582,7 @@ const regularImportOptions = [
33303
33582
  // { id: "keeperjson", name: "Keeper (json)" },
33304
33583
  { id: "enpasscsv", name: "Enpass (csv)" },
33305
33584
  { id: "enpassjson", name: "Enpass (json)" },
33585
+ { id: "protonpass", name: "ProtonPass (zip/json)" },
33306
33586
  { id: "safeincloudxml", name: "SafeInCloud (xml)" },
33307
33587
  { id: "pwsafexml", name: "Password Safe (xml)" },
33308
33588
  { id: "stickypasswordxml", name: "Sticky Password (xml)" },
@@ -33572,6 +33852,8 @@ class ImportService {
33572
33852
  return new PsonoJsonImporter();
33573
33853
  case "passkyjson":
33574
33854
  return new PasskyJsonImporter();
33855
+ case "protonpass":
33856
+ return new ProtonPassJsonImporter(this.i18nService);
33575
33857
  default:
33576
33858
  return null;
33577
33859
  }
@@ -33942,6 +34224,9 @@ class NodeCryptoFunctionService {
33942
34224
  });
33943
34225
  });
33944
34226
  }
34227
+ aesGenerateKey(bitLength) {
34228
+ return this.randomBytes(bitLength / 8);
34229
+ }
33945
34230
  randomBytes(length) {
33946
34231
  return new Promise((resolve, reject) => {
33947
34232
  external_crypto_namespaceObject.randomBytes(length, (error, bytes) => {
@@ -37729,7 +38014,7 @@ class CliUtils {
37729
38014
  });
37730
38015
  });
37731
38016
  }
37732
- static extract1PuxContent(input) {
38017
+ static extractZipContent(input, filepath) {
37733
38018
  return new Promise((resolve, reject) => {
37734
38019
  let p = null;
37735
38020
  if (input != null && input !== "") {
@@ -37749,7 +38034,7 @@ class CliUtils {
37749
38034
  reject(err);
37750
38035
  }
37751
38036
  external_jszip_namespaceObject.loadAsync(data).then((zip) => {
37752
- resolve(zip.file("export.data").async("string"));
38037
+ resolve(zip.file(filepath).async("string"));
37753
38038
  }, (reason) => {
37754
38039
  reject(reason);
37755
38040
  });
@@ -37923,6 +38208,21 @@ class CliUtils {
37923
38208
  static convertBooleanOption(optionValue) {
37924
38209
  return optionValue || optionValue === "" ? true : false;
37925
38210
  }
38211
+ static convertNumberOption(optionValue, defaultValue) {
38212
+ try {
38213
+ if (optionValue != null) {
38214
+ const numVal = parseInt(optionValue);
38215
+ return !Number.isNaN(numVal) ? numVal : defaultValue;
38216
+ }
38217
+ return defaultValue;
38218
+ }
38219
+ catch (_a) {
38220
+ return defaultValue;
38221
+ }
38222
+ }
38223
+ static convertStringOption(optionValue, defaultValue) {
38224
+ return optionValue != null ? String(optionValue) : defaultValue;
38225
+ }
37926
38226
  }
37927
38227
 
37928
38228
  ;// CONCATENATED MODULE: ./src/auth/commands/unlock.command.ts
@@ -38480,6 +38780,9 @@ class GenerateCommand {
38480
38780
  numWords: normalizedOptions.words,
38481
38781
  capitalize: normalizedOptions.capitalize,
38482
38782
  includeNumber: normalizedOptions.includeNumber,
38783
+ minNumber: normalizedOptions.minNumber,
38784
+ minSpecial: normalizedOptions.minSpecial,
38785
+ ambiguous: normalizedOptions.ambiguous,
38483
38786
  };
38484
38787
  const enforcedOptions = (yield this.stateService.getIsAuthenticated())
38485
38788
  ? (yield this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0]
@@ -38498,10 +38801,13 @@ class generate_command_Options {
38498
38801
  this.special = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.special);
38499
38802
  this.capitalize = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.capitalize);
38500
38803
  this.includeNumber = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.includeNumber);
38501
- this.length = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length) != null ? parseInt(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length, null) : 14;
38804
+ this.ambiguous = CliUtils.convertBooleanOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.ambiguous);
38805
+ this.length = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.length, 14);
38502
38806
  this.type = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.passphrase) ? "passphrase" : "password";
38503
- this.separator = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.separator) == null ? "-" : passedOptions.separator + "";
38504
- this.words = (passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.words) != null ? parseInt(passedOptions.words, null) : 3;
38807
+ this.separator = CliUtils.convertStringOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.separator, "-");
38808
+ this.words = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.words, 3);
38809
+ this.minNumber = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.minNumber, 1);
38810
+ this.minSpecial = CliUtils.convertNumberOption(passedOptions === null || passedOptions === void 0 ? void 0 : passedOptions.minSpecial, 1);
38505
38811
  if (!this.uppercase && !this.lowercase && !this.special && !this.number) {
38506
38812
  this.lowercase = true;
38507
38813
  this.uppercase = true;
@@ -41490,9 +41796,12 @@ class Program {
41490
41796
  .option("-p, --passphrase", "Generate a passphrase.")
41491
41797
  .option("--length <length>", "Length of the password.")
41492
41798
  .option("--words <words>", "Number of words.")
41799
+ .option("--minNumber <count>", "Minimum number of numeric characters.")
41800
+ .option("--minSpecial <count>", "Minimum number of special characters.")
41493
41801
  .option("--separator <separator>", "Word separator.")
41494
41802
  .option("-c, --capitalize", "Title case passphrase.")
41495
41803
  .option("--includeNumber", "Passphrase includes number.")
41804
+ .option("--ambiguous", "Avoid ambiguous characters.")
41496
41805
  .on("--help", () => {
41497
41806
  writeLn("\n Notes:");
41498
41807
  writeLn("");
@@ -42206,7 +42515,10 @@ class ImportCommand {
42206
42515
  try {
42207
42516
  let contents;
42208
42517
  if (format === "1password1pux") {
42209
- contents = yield CliUtils.extract1PuxContent(filepath);
42518
+ contents = yield CliUtils.extractZipContent(filepath, "export.data");
42519
+ }
42520
+ else if (format === "protonpass" && filepath.endsWith(".zip")) {
42521
+ contents = yield CliUtils.extractZipContent(filepath, "Proton Pass/data.json");
42210
42522
  }
42211
42523
  else {
42212
42524
  contents = yield CliUtils.readFile(filepath);
@@ -42720,7 +43032,6 @@ var bw_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argum
42720
43032
 
42721
43033
 
42722
43034
 
42723
-
42724
43035
 
42725
43036
 
42726
43037
  // Polyfills
@@ -42757,8 +43068,7 @@ class Main {
42757
43068
  this.storageService = new LowdbStorageService(this.logService, null, p, false, true);
42758
43069
  this.secureStorageService = new NodeEnvSecureStorageService(this.storageService, this.logService, () => this.cryptoService);
42759
43070
  this.memoryStorageService = new MemoryStorageService();
42760
- this.stateMigrationService = new StateMigrationService(this.storageService, this.secureStorageService, new StateFactory(GlobalState, Account));
42761
- this.stateService = new StateService(this.storageService, this.secureStorageService, this.memoryStorageService, this.logService, this.stateMigrationService, new StateFactory(GlobalState, Account));
43071
+ this.stateService = new StateService(this.storageService, this.secureStorageService, this.memoryStorageService, this.logService, new StateFactory(GlobalState, Account));
42762
43072
  this.cryptoService = new CryptoService(this.cryptoFunctionService, this.encryptService, this.platformUtilsService, this.logService, this.stateService);
42763
43073
  this.appIdService = new AppIdService(this.storageService);
42764
43074
  this.tokenService = new TokenService(this.stateService);