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
|
|
|
|
2023-10-28 00:14:35 +00:00
|
|
|
import type { JOB_STATUS } from './JobQueue';
|
2021-04-29 23:02:27 +00:00
|
|
|
import { JobQueue } from './JobQueue';
|
2023-10-28 00:14:35 +00:00
|
|
|
|
2021-04-29 23:02:27 +00:00
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
|
|
|
const removeStorageKeyJobDataSchema = z.object({
|
2023-07-14 16:53:20 +00:00
|
|
|
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,
|
2023-10-28 00:14:35 +00:00
|
|
|
}: 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);
|
2023-10-28 00:14:35 +00:00
|
|
|
|
|
|
|
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
|
|
|
});
|