signal-desktop/ts/jobs/removeStorageKeyJobQueue.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-29 23:02:27 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2021-05-25 22:40:04 +00:00
import { z } from 'zod';
2021-04-29 23:02:27 +00:00
import type { JOB_STATUS } from './JobQueue';
2021-04-29 23:02:27 +00:00
import { JobQueue } from './JobQueue';
2021-04-29 23:02:27 +00:00
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
const removeStorageKeyJobDataSchema = z.object({
key: z.enum([
'challenge:retry-message-ids',
'nextSignedKeyRotationTime',
'senderCertificateWithUuid',
'signedKeyRotationRejected',
]),
2021-04-29 23:02:27 +00:00
});
type RemoveStorageKeyJobData = z.infer<typeof removeStorageKeyJobDataSchema>;
2021-07-21 21:10:08 +00:00
export class RemoveStorageKeyJobQueue extends JobQueue<RemoveStorageKeyJobData> {
protected parseData(data: unknown): RemoveStorageKeyJobData {
2021-04-29 23:02:27 +00:00
return removeStorageKeyJobDataSchema.parse(data);
2021-07-21 21:10:08 +00:00
}
2021-04-29 23:02:27 +00:00
2021-07-21 21:10:08 +00:00
protected async run({
2021-04-29 23:02:27 +00:00
data,
}: Readonly<{ data: RemoveStorageKeyJobData }>): Promise<
typeof JOB_STATUS.NEEDS_RETRY | undefined
> {
2021-04-29 23:02:27 +00:00
await new Promise<void>(resolve => {
window.storage.onready(resolve);
});
await window.storage.remove(data.key);
return undefined;
2021-07-21 21:10:08 +00:00
}
}
export const removeStorageKeyJobQueue = new RemoveStorageKeyJobQueue({
store: jobQueueDatabaseStore,
queueType: 'remove storage key',
maxAttempts: 100,
2021-04-29 23:02:27 +00:00
});