2018-01-09 22:19:55 +01:00
|
|
|
import { UtilsService } from './utils.service';
|
|
|
|
|
2018-02-19 18:33:32 +01:00
|
|
|
import {
|
|
|
|
AppIdService as AppIdServiceInterface,
|
|
|
|
StorageService,
|
|
|
|
} from '../abstractions';
|
2018-01-09 22:19:55 +01:00
|
|
|
|
|
|
|
export class AppIdService implements AppIdServiceInterface {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|