"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseCookieStore = void 0;
const uuid_1 = require("uuid");
/**
 * A {@link CookieStore} that uses an {@link ExpiringStorage} to keep track of the stored cookies.
 * Cookies have a specified time to live in seconds, default is 14 days,
 * after which they will be removed.
 */
class BaseCookieStore {
    storage;
    ttl;
    constructor(storage, ttl = 14 * 24 * 60 * 60) {
        this.storage = storage;
        this.ttl = ttl * 1000;
    }
    async generate(accountId) {
        const cookie = (0, uuid_1.v4)();
        await this.storage.set(cookie, accountId, this.ttl);
        return cookie;
    }
    async get(cookie) {
        return await this.storage.get(cookie);
    }
    async refresh(cookie) {
        const accountId = await this.storage.get(cookie);
        if (accountId) {
            await this.storage.set(cookie, accountId, this.ttl);
            return new Date(Date.now() + this.ttl);
        }
    }
    async delete(cookie) {
        return this.storage.delete(cookie);
    }
}
exports.BaseCookieStore = BaseCookieStore;
//# sourceMappingURL=BaseCookieStore.js.map