1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

convert appid service to ts

This commit is contained in:
Kyle Spearrin 2017-11-02 15:51:05 -04:00
parent 8eeb5821f0
commit 5fd850929d
4 changed files with 43 additions and 3 deletions

View File

@ -14,7 +14,6 @@
<script type="text/javascript" src="services/cipherService.js"></script> <script type="text/javascript" src="services/cipherService.js"></script>
<script type="text/javascript" src="services/syncService.js"></script> <script type="text/javascript" src="services/syncService.js"></script>
<script type="text/javascript" src="services/autofillService.js"></script> <script type="text/javascript" src="services/autofillService.js"></script>
<script type="text/javascript" src="services/appIdService.js"></script>
<script type="text/javascript" src="services/totpService.js"></script> <script type="text/javascript" src="services/totpService.js"></script>
<script type="text/javascript" src="services/environmentService.js"></script> <script type="text/javascript" src="services/environmentService.js"></script>
</head> </head>

View File

@ -1,4 +1,5 @@
// Service imports // Service imports
import AppIdService from './services/appId.service';
import ConstantsService from './services/constants.service'; import ConstantsService from './services/constants.service';
import i18nService from './services/i18nService.js'; import i18nService from './services/i18nService.js';
import LockService from './services/lockService.js'; import LockService from './services/lockService.js';
@ -73,9 +74,9 @@ var bg_isBackground = true,
window.bg_utilsService = bg_utilsService = new UtilsService(); window.bg_utilsService = bg_utilsService = new UtilsService();
window.bg_i18nService = bg_i18nService = new i18nService(bg_utilsService); window.bg_i18nService = bg_i18nService = new i18nService(bg_utilsService);
window.bg_constantsService = bg_constantsService = new ConstantsService(bg_i18nService); window.bg_constantsService = bg_constantsService = new ConstantsService(bg_i18nService);
window.bg_cryptoService = bg_cryptoService = new CryptoService(bg_utilsService); window.bg_cryptoService = bg_cryptoService = new CryptoService();
window.bg_tokenService = bg_tokenService = new TokenService(bg_utilsService); window.bg_tokenService = bg_tokenService = new TokenService(bg_utilsService);
window.bg_appIdService = bg_appIdService = new AppIdService(bg_utilsService); window.bg_appIdService = bg_appIdService = new AppIdService();
window.bg_apiService = bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout); window.bg_apiService = bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
window.bg_environmentService = bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService); window.bg_environmentService = bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
window.bg_userService = bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService); window.bg_userService = bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);

View File

@ -0,0 +1,31 @@
import UtilsService from './utils.service';
export default class AppIdService {
static getAppId(): Promise<string> {
return AppIdService.makeAndGetAppId('appId');
}
static getAnonymousAppId(): Promise<string> {
return AppIdService.makeAndGetAppId('anonymousAppId');
}
private static async makeAndGetAppId(key: string) {
const existingId = await UtilsService.getObjFromStorage<string>(key);
if(existingId != null) {
return existingId;
}
const guid = UtilsService.newGuid();
await UtilsService.saveObjToStorage(key, guid);
return guid;
}
// TODO: remove these in favor of static methods
getAppId(): Promise<string> {
return AppIdService.getAppId();
}
getAnonymousAppId(): Promise<string> {
return AppIdService.getAnonymousAppId();
}
}

View File

@ -8,6 +8,15 @@ const AnalyticsIds = {
}; };
export default class UtilsService { export default class UtilsService {
// ref: http://stackoverflow.com/a/2117523/1090359
static newGuid(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
static extendObject(...objects: any[]): any { static extendObject(...objects: any[]): any {
for (let i = 1; i < objects.length; i++) { for (let i = 1; i < objects.length; i++) {
for (const key in objects[i]) { for (const key in objects[i]) {