Skip to content

Commit

Permalink
Whitelist inbox zero
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Dec 23, 2024
1 parent 6fadf47 commit 9d03237
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/web/app/(app)/assess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import { useEffect } from "react";
import type { AssessUserResponse } from "@/app/api/user/assess/route";
import { postRequest } from "@/utils/api";
import { whitelistInboxZeroAction } from "@/utils/actions/whitelist";

export function AssessUser() {
useEffect(() => {
postRequest<AssessUserResponse>("/api/user/assess", {});
}, []);

useEffect(() => {
whitelistInboxZeroAction();
}, []);

return null;
}
1 change: 1 addition & 0 deletions apps/web/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const env = createEnv({
.transform((value) => value?.split(",")),
WEBHOOK_URL: z.string().optional(),
INTERNAL_API_KEY: z.string().optional(),
WHITELIST_FROM: z.string().optional(),

// license
LICENSE_1_SEAT_VARIANT_ID: z.coerce.number().optional(),
Expand Down
32 changes: 32 additions & 0 deletions apps/web/utils/actions/whitelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use server";

import { env } from "@/env";
import { getSessionAndGmailClient } from "@/utils/actions/helpers";
import { withActionInstrumentation } from "@/utils/actions/middleware";
import { isActionError } from "@/utils/error";
import { createFilter } from "@/utils/gmail/filter";
import { INBOX_LABEL_ID, SPAM_LABEL_ID } from "@/utils/gmail/label";

export const whitelistInboxZeroAction = withActionInstrumentation(
"whitelistInboxZero",
async () => {
if (!env.WHITELIST_FROM) return;

const sessionResult = await getSessionAndGmailClient();
if (isActionError(sessionResult)) return sessionResult;
const { gmail } = sessionResult;

await createFilter({
gmail,
from: env.WHITELIST_FROM,
addLabelIds: [INBOX_LABEL_ID],
removeLabelIds: [
"CATEGORY_PROMOTIONS",
"CATEGORY_SOCIAL",
"CATEGORY_UPDATES",
"CATEGORY_FORUMS",
SPAM_LABEL_ID,
],
});
},
);

1 comment on commit 9d03237

@vercel
Copy link

@vercel vercel bot commented on 9d03237 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.