mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { NotificationType } from '../../enums/notificationType';
|
|
|
|
export class NotificationResponse {
|
|
contextId: string;
|
|
type: NotificationType;
|
|
payload: any;
|
|
|
|
constructor(response: any) {
|
|
this.contextId = response.contextId || response.ContextId;
|
|
this.type = response.type != null ? response.type : response.Type;
|
|
|
|
const payload = response.payload || response.Payload;
|
|
switch (this.type) {
|
|
case NotificationType.SyncCipherCreate:
|
|
case NotificationType.SyncCipherDelete:
|
|
case NotificationType.SyncCipherUpdate:
|
|
case NotificationType.SyncLoginDelete:
|
|
this.payload = new SyncCipherNotification(payload);
|
|
break;
|
|
case NotificationType.SyncFolderCreate:
|
|
case NotificationType.SyncFolderDelete:
|
|
case NotificationType.SyncFolderUpdate:
|
|
this.payload = new SyncFolderNotification(payload);
|
|
break;
|
|
case NotificationType.SyncVault:
|
|
case NotificationType.SyncCiphers:
|
|
case NotificationType.SyncOrgKeys:
|
|
case NotificationType.SyncSettings:
|
|
case NotificationType.LogOut:
|
|
this.payload = new UserNotification(payload);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
export class SyncCipherNotification {
|
|
id: string;
|
|
userId: string;
|
|
organizationId: string;
|
|
collectionIds: string[];
|
|
revisionDate: Date;
|
|
|
|
constructor(response: any) {
|
|
this.id = response.id || response.Id;
|
|
this.userId = response.userId || response.UserId;
|
|
this.organizationId = response.organizationId || response.OrganizationId;
|
|
this.collectionIds = response.collectionIds || response.CollectionIds;
|
|
this.revisionDate = new Date(response.revisionDate || response.RevisionDate);
|
|
}
|
|
}
|
|
|
|
export class SyncFolderNotification {
|
|
id: string;
|
|
userId: string;
|
|
revisionDate: Date;
|
|
|
|
constructor(response: any) {
|
|
this.id = response.id || response.Id;
|
|
this.userId = response.userId || response.UserId;
|
|
this.revisionDate = new Date(response.revisionDate || response.RevisionDate);
|
|
}
|
|
}
|
|
|
|
export class UserNotification {
|
|
userId: string;
|
|
date: Date;
|
|
|
|
constructor(response: any) {
|
|
this.userId = response.userId || response.UserId;
|
|
this.date = new Date(response.date || response.Date);
|
|
}
|
|
}
|