aboutsummaryrefslogtreecommitdiff
path: root/src/server/database.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/database.ts')
-rw-r--r--src/server/database.ts39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/server/database.ts b/src/server/database.ts
index 2372cbcf2..7fbab357b 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -304,7 +304,8 @@ export namespace Database {
*/
export enum AuxiliaryCollections {
GooglePhotosUploadHistory = "uploadedFromGooglePhotos",
- GoogleAccess = "googleAuthentication"
+ GoogleAccess = "googleAuthentication",
+ HypothesisAccess = "hypothesisAuthentication"
}
/**
@@ -405,6 +406,42 @@ export namespace Database {
}
+ export namespace HypothesisAccessToken {
+ /**
+ * Format stored in database.
+ */
+ interface StoredCredentials {
+ userId: string;
+ hypothesisApiKey: string;
+ _id?: string;
+ }
+
+ /**
+ * Writes the @param enrichedCredentials to the database, associated
+ * with @param userId for later retrieval and updating.
+ */
+ export const Write = async (userId: string, hypothesisApiKey: string) => {
+ return Instance.insert({ userId, hypothesisApiKey }, AuxiliaryCollections.HypothesisAccess);
+ };
+
+ /**
+ * Retrieves the credentials associaed with @param userId
+ * and optionally removes their database id according to @param removeId.
+ */
+ export const Fetch = async (userId: string, removeId = true): Promise<Opt<StoredCredentials>> => {
+ return SanitizedSingletonQuery<StoredCredentials>({ userId }, AuxiliaryCollections.HypothesisAccess, removeId);
+ };
+
+ /**
+ * Revokes the credentials associated with @param userId.
+ */
+ export const Revoke = async (userId: string) => {
+ const entry = await Fetch(userId, false);
+ if (entry) {
+ Instance.delete({ _id: entry._id }, AuxiliaryCollections.HypothesisAccess);
+ }
+ };
+ }
}
}