import { v4 } from "uuid";
import { createHash } from "crypto";
import { getAccessTokenStore } from "./store.js";
// TODO: is this the best way to create an access token string?
function createAccessTokenString(type) {
    const value = v4();
    const hash = createHash("sha512");
    hash.update(value);
    const buffer = hash.digest();
    const hex = buffer.toString("hex");
    if (!type)
        return hex;
    return `${type}_${hex}`;
}
export async function createPartnerAccessToken(partnerId) {
    return createAccessToken({
        partnerId,
        accessTokenType: "partner"
    });
}
export async function createAccessToken(data) {
    const createdAt = new Date().toISOString();
    const accessToken = createAccessTokenString(data.accessTokenType);
    const token = {
        ...data,
        accessToken,
        createdAt
    };
    const store = getAccessTokenStore();
    await store.set(accessToken, token);
    return {
        accessToken
    };
}
//# sourceMappingURL=create-access-token.js.map