Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable bulk #481

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/app/[lang]/dashboard/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Dictionary } from "@/dictionaries";
import Mail from "@geist-ui/react-icons/mail";
import Database from "@geist-ui/react-icons/database";
import Lock from "@geist-ui/react-icons/lock";
import { ENABLE_BULK } from "@/util/helpers";
import { useRouter } from "next/navigation";

export interface TabsProps {
Expand All @@ -23,7 +22,7 @@ export function Tabs({ bulkDisabled, tab, ...props }: TabsProps) {
router.push(`/${props.d.lang}/dashboard/${value}`);
};

return ENABLE_BULK === 1 ? (
return (
<GTabs onChange={handler} value={tab}>
<GTabs.Item
label={
Expand Down Expand Up @@ -52,5 +51,5 @@ export function Tabs({ bulkDisabled, tab, ...props }: TabsProps) {
value="bulk"
/>
</GTabs>
) : null;
);
}
5 changes: 0 additions & 5 deletions src/app/[lang]/dashboard/bulk/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import { Dashboard } from "../Dashboard";
import { ENABLE_BULK } from "@/util/helpers";
import { getSession, getSubscription } from "@/supabase/supabaseServer";
import { dictionary } from "@/dictionaries";
import { cookies } from "next/headers";
Expand All @@ -23,10 +22,6 @@ export default async function Bulk({
const subscription = await getSubscription();
const d = await dictionary(lang);

if (ENABLE_BULK === 0) {
return <p>Bulk is disabled</p>;
}

const cookieStore = cookies();
const supabase = createClient(cookieStore);
const res = await supabase.from("bulk_jobs_info").select("*");
Expand Down
5 changes: 1 addition & 4 deletions src/app/[lang]/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getSubscription } from "@/supabase/supabaseServer";
import { ENABLE_BULK } from "@/util/helpers";
import {
COMMERCIAL_LICENSE_PRODUCT_ID,
SAAS_100K_PRODUCT_ID,
Expand All @@ -20,9 +19,7 @@ export default async function Dashboard({
RedirectType.replace
);
case SAAS_100K_PRODUCT_ID:
return ENABLE_BULK === 1
? redirect(`/${lang}/dashboard/bulk`, RedirectType.replace)
: redirect(`/${lang}/dashboard/verify`, RedirectType.replace);
return redirect(`/${lang}/dashboard/bulk`, RedirectType.replace);
default:
return redirect(`/${lang}/dashboard/verify`, RedirectType.replace);
}
Expand Down
1 change: 1 addition & 0 deletions src/app/[lang]/pricing/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function ProductCard({
const d = props.d.pricing;

const active = !!subscription;
console.log("AAA", product.prices);
const price = product.prices.find(({ currency: c }) => currency === c);
if (!price || !price.unit_amount) {
return <p>Error: No price found for product {product.id}.</p>;
Expand Down
5 changes: 4 additions & 1 deletion src/app/[lang]/pricing/SaaS100k.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SpanRenderer } from "@/components/Markdown";
export function SaaS100k(
props: Omit<ProductCardProps, "title">
): React.ReactElement {
const d = props.d.pricing.saas10k;
const d = props.d.pricing.saas100k;

return (
<ProductCard
Expand All @@ -19,6 +19,9 @@ export function SaaS100k(
</Text>
}
features={[
<Markdown renderer={SpanRenderer} key="licenseFeatures-1">
{d.bulk}
</Markdown>,
d.reacher_ip,
<Markdown renderer={SpanRenderer} key="saasFeatures-2">
{d.full_feature}
Expand Down
18 changes: 6 additions & 12 deletions src/app/api/v1/bulk/[jobId]/download/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isEarlyResponse } from "@/app/api/v0/check_email/checkUserInDb";
import { CheckEmailOutput } from "@reacherhq/api";
import { components } from "@reacherhq/api/lib/types";
import { NextRequest } from "next/server";
import { ENABLE_BULK } from "@/util/helpers";
import { cookies } from "next/headers";
import { createClient } from "@/supabase/server";

Expand All @@ -13,21 +12,13 @@ type MxD = components["schemas"]["MxDetails"];
type ReacherError = components["schemas"]["Error"];

export const GET = async (
req: NextRequest,
_req: NextRequest,
{
params,
}: {
params: { jobId: string };
}
): Promise<Response> => {
// TODO Remove this once we allow Bulk.
if (ENABLE_BULK === 0) {
return Response.json(
{ error: "Not available in production" },
{ status: 403 }
);
}

try {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
Expand Down Expand Up @@ -81,12 +72,15 @@ export const GET = async (
["misc.error"]: formatCsvError(result.misc),
// Mx
["mx.accepts_mail"]: (result.mx as MxD)?.accepts_mail,
["mx.records"]: (result.mx as MxD)?.records,
["mx.records"]: (result.mx as MxD)?.records.join(";"), // Don't join using commas, to avoid messing up with CSV
["mx.error"]: formatCsvError(result.mx),
// Syntax
["syntax.is_valid_syntax"]: result.syntax.is_valid_syntax,
["syntax.domain"]: result.syntax.domain,
["syntax.username"]: result.syntax.username,
// Debug
["debug.smtp.verif_method"]:
result.debug?.smtp?.verif_method?.type,
};
});

Expand Down Expand Up @@ -130,7 +124,7 @@ function formatCsvError(err: unknown): string | null {
if ((err as ReacherError)?.type && (err as ReacherError)?.message) {
return `${(err as ReacherError).type}: ${
(err as ReacherError).message
}`;
}`.replaceAll(",", ";"); // Don't use commas to avoid messing up with CSV
}

return null;
Expand Down
10 changes: 1 addition & 9 deletions src/app/api/v1/bulk/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextRequest } from "next/server";
import amqplib from "amqplib";
import { supabaseAdmin } from "@/supabase/supabaseAdmin";
import { sentryException } from "@/util/sentry";
import { ENABLE_BULK, getWebappURL } from "@/util/helpers";
import { getWebappURL } from "@/util/helpers";
import { isEarlyResponse } from "@/app/api/v0/check_email/checkUserInDb";
import { SAAS_100K_PRODUCT_ID, getApiUsage } from "@/util/subs";
import { Json } from "@/supabase/database.types";
Expand All @@ -16,14 +16,6 @@ interface BulkPayload {
}

export const POST = async (req: NextRequest): Promise<Response> => {
// TODO Remove this once we allow Bulk.
if (ENABLE_BULK === 0) {
return Response.json(
{ error: "Not available in production" },
{ status: 403 }
);
}

try {
const cookieStore = cookies();
const supabase = createClient(cookieStore);
Expand Down
1 change: 1 addition & 0 deletions src/dictionaries/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"overtitle": "✨ New ✨",
"subtitle": "100,000 email verifications / mo",
"reacher_ip": "Use Reacher's servers with high IP reputation.",
"bulk": "💪 **Bulk** email verification via CSV list upload.",
"full_feature": "[Full-featured](https://help.reacher.email/email-attributes-inside-json) email verifications.",
"support": "**Customer support** by email/chat.",
"cancel": "Cancel anytime."
Expand Down
3 changes: 2 additions & 1 deletion src/dictionaries/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"what_need_to_do": "Ce que vous devez faire :",
"purchase_server": "Acheter vous-même des serveurs pour auto-héberger Reacher. [Lisez comment](https://help.reacher.email/self-host-guide).",
"unlimited_emails": "Vérifications d'emails **illimitées** [complètes]((https://help.reacher.email/email-attributes-inside-json)).",
"bulk": "💪 Vérifications d'emails **en bulk**. [En savoir plus](https://help.reacher.email/bulk-email-verification).",
"bulk": "💪 Vérifications d'emails **en Bulk**. [En savoir plus](https://help.reacher.email/bulk-email-verification).",
"no_data_reacher": "Aucune donnée renvoyée à Reacher.",
"support": "**Support client** par email/chat.",
"cancel": "Annulez à tout moment.",
Expand All @@ -191,6 +191,7 @@
"overtitle": "✨ Nouveau ✨",
"subtitle": "100 000 vérifications d'emails / mois",
"reacher_ip": "Utilisez les serveurs de Reacher avec une haute réputation IP.",
"bulk": "💪 **Verifications d'emails en Bulk** avec upload de fichier CSV.",
"full_feature": "Vérifications d'emails [complètes](https://help.reacher.email/email-attributes-inside-json).",
"support": "**Support client** par email/chat.",
"cancel": "Annulez à tout moment."
Expand Down
2 changes: 1 addition & 1 deletion src/supabase/supabaseServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const getActiveProductsWithPrices = async () => {
.eq("active", true)
.eq("prices.active", true)
.order("metadata->index")
.order("unit_amount", { foreignTable: "prices" });
.order("unit_amount", { referencedTable: "prices", ascending: false });
if (error) throw error;
return (data as unknown as ProductWithPrice[]) ?? [];
};
4 changes: 0 additions & 4 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,3 @@ export function formatDate(d: string | Date, locale?: string): string {
locale: locale === "fr" ? fr : enUS,
});
}

// TODO This is a temporary solution to enable bulk actions in development,
// but disable them in production.
export const ENABLE_BULK = 1 as 0 | 1;
Loading