2018-01-09 22:19:55 +01:00
|
|
|
import { UtilsService } from './utils.service';
|
|
|
|
|
2018-04-04 14:22:18 +02:00
|
|
|
import { AppIdService as AppIdServiceAbstraction } from '../abstractions/appId.service';
|
2018-02-19 19:07:19 +01:00
|
|
|
import { StorageService } from '../abstractions/storage.service';
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-04-04 14:22:18 +02:00
|
|
|
export class AppIdService implements AppIdServiceAbstraction {
|
2018-01-09 22:19:55 +01:00
|
|
|
constructor(private storageService: StorageService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
getAppId(): Promise<string> {
|
|
|
|
return this.makeAndGetAppId('appId');
|
|
|
|
}
|
|
|
|
|
|
|
|
getAnonymousAppId(): Promise<string> {
|
|
|
|
return this.makeAndGetAppId('anonymousAppId');
|
|
|
|
}
|
|
|
|
|
|
|
|
private async makeAndGetAppId(key: string) {
|
|
|
|
const existingId = await this.storageService.get<string>(key);
|
|
|
|
if (existingId != null) {
|
|
|
|
return existingId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const guid = UtilsService.newGuid();
|
|
|
|
await this.storageService.save(key, guid);
|
|
|
|
return guid;
|
|
|
|
}
|
|
|
|
}
|