Skip to content

Commit

Permalink
Merge pull request #530 from tone-row/dev
Browse files Browse the repository at this point in the history
v1.35.2
  • Loading branch information
rob-gordon authored Jun 12, 2023
2 parents c26d6d4 + e1754ea commit 18a983c
Show file tree
Hide file tree
Showing 23 changed files with 992 additions and 1,506 deletions.
121 changes: 121 additions & 0 deletions api/cron/deleteDevUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import Stripe from "stripe";
import { User, createClient } from "@supabase/supabase-js";

/**
* In order to to keep the development environment clean,
* this function will delete all users except those that have been excluded.
*
* Deleting users is primarily to ensure people don't abuse the dev
* environment. We'll delete them from stripe and supbase.
*/

export default async function deleteDevUsers() {
// Connect to Stripe
const stripeTestModeSecretKey = process.env.STRIPE_TEST_MODE_SK;
if (!stripeTestModeSecretKey) throw new Error("Stripe secret key not found");
const stripe = new Stripe(stripeTestModeSecretKey, {
apiVersion: "2022-11-15",
});

if (!process.env.EXCLUDED_USER_FROM_DELETION)
throw new Error("No users to exclude from deletion");

// Make sure that we have a list of users to exclude
const excludedUsers = process.env.EXCLUDED_USER_FROM_DELETION.split(",");

// Stripe - load all customers in while loop
let stripeCustomers: Stripe.Customer[] = [];
let stripeHasMore = true;
let stripeStartingAfter: string | undefined;
while (stripeHasMore) {
const stripeCustomersResponse = await stripe.customers.list({
limit: 100,
starting_after: stripeStartingAfter,
});
if (!stripeCustomersResponse.data) throw new Error("No stripe customers");
stripeCustomers = stripeCustomers.concat(stripeCustomersResponse.data);
stripeHasMore = stripeCustomersResponse.has_more;
stripeStartingAfter = stripeCustomersResponse.data.slice(-1)[0].id;
}

// delete all customers except those that are excluded
const stripeCustomersToDelete = stripeCustomers.filter(
(customer) => !excludedUsers.includes(customer.email as string)
);

if (stripeCustomersToDelete.length === 0) {
console.log("No Stripe customers to delete");
}

for (const customer of stripeCustomersToDelete) {
console.log(`Deleting customer ${customer.id} (${customer.email})`);
await stripe.customers.del(customer.id);
}

// Connect to supabase
const supabaseStagingProjectUrl = process.env.SUPABASE_STAGING_PROJECT_URL;
if (!supabaseStagingProjectUrl)
throw new Error("No Supabase staging project URL");
const supabaseStagingServiceKey = process.env.SUPABASE_STAGING_SERVICE_KEY;
if (!supabaseStagingServiceKey)
throw new Error("No Supabase staging service key");

const supabase = createClient(
supabaseStagingProjectUrl,
supabaseStagingServiceKey,
{
auth: {
autoRefreshToken: false,
persistSession: false,
},
}
);

const adminAuthClient = supabase.auth.admin;

let page = 1;
let lastPage = Infinity;
let supabaseUsers: User[] = [];

while (page <= lastPage) {
// The GoTrue types appear to be out of date, confirmed that this works
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const supabaseUsersResponse = await adminAuthClient.listUsers({
page,
perPage: 1000,
});

if (!supabaseUsersResponse.data) {
console.log("Error: No users found");
lastPage = 0;
continue;
}

supabaseUsers = supabaseUsers.concat(supabaseUsersResponse.data.users);
lastPage = (supabaseUsersResponse.data as unknown as { lastPage: number })
.lastPage;

page = page + 1;
}

const supabaseUsersToDelete = supabaseUsers.filter(
(user) => !excludedUsers.includes(user.email as string)
);

// print the number of users
console.log(`Found ${supabaseUsersToDelete.length} users to delete`);

// delete all users except those that are excluded
for (const user of supabaseUsersToDelete) {
console.log(`Deleting user ${user.id} (${user.email})`);

// delete the users charts first
await supabase.from("user_charts").delete().eq("user_id", user.id);

// delete the user
await adminAuthClient.deleteUser(user.id);
}

console.log("Done");
}
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@notionhq/client": "^0.4.13",
"@octokit/core": "^4.2.0",
"@sendgrid/mail": "^7.4.6",
"@supabase/supabase-js": "^2",
"@supabase/supabase-js": "^2.24.0",
"csv-parse": "^5.3.6",
"date-fns": "^2.29.3",
"graph-selector": "^0.8.3",
Expand All @@ -31,7 +31,7 @@
"@swc/jest": "^0.2.24",
"@types/jest": "^29.0.0",
"@types/marked": "^4.0.7",
"@types/node": "^12.20.55",
"@types/node": "^18.16.17",
"@typescript-eslint/eslint-plugin": "^5",
"@typescript-eslint/parser": "^5",
"@vercel/node": "^2.8.15",
Expand Down
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "1.35.1",
"version": "1.35.2",
"main": "module/module.js",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -151,7 +151,7 @@
"@types/lz-string": "^1.3.34",
"@types/marked": "^4.0.7",
"@types/minimist": "^1.2.2",
"@types/node": "^12.20.55",
"@types/node": "^18.16.17",
"@types/node-localstorage": "^1.3.0",
"@types/pako": "^2.0.0",
"@types/papaparse": "^5.3.7",
Expand Down
14 changes: 9 additions & 5 deletions app/src/components/PaymentStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,18 @@ export function PaymentStepper() {
)}
{step === "three" && (
<div className="grid gap-4">
<Title>{t`Activate Flowchart Fun Pro`}</Title>
<Title>{t`Activate your account`}</Title>
<Description className="mb-4">
{t`Unlock the full potential of Flowchart Fun Pro and get unlimited access to all of our advanced features. Complete your subscription below and start creating amazing flowcharts today!`}
<Trans>
You&apos;re almost there! Just one more step to unlock the full
potential of <span>Flowchart Fun Pro</span>. Enter your payment
details below to complete your subscription and start creating
amazing flowcharts today.
</Trans>
</Description>
<PaymentForm
clientSecret={subscriptionDetails.data?.clientSecret || ""}
/>
<span className="text-xs text-neutral-500 dark:text-neutral-400 block text-center">{t`Your payment details are secure. You can cancel anytime.`}</span>
</div>
)}
</div>
Expand Down Expand Up @@ -265,7 +269,7 @@ function PaymentForm({ clientSecret }: { clientSecret: string }) {
disabled={!stripe || loading}
className="mt-5 justify-self-center"
>
<Trans>Complete Subscription</Trans>
<Trans>Sign Up</Trans>
{loading ? <Spinner r={5} s={1} /> : <RocketLaunch size={18} />}
</BlueButton>
{error && (
Expand Down Expand Up @@ -310,7 +314,7 @@ async function getSubscriptionDetails(

function Title({ children }: { children: React.ReactNode }) {
return (
<h2 className="text-center text-3xl font-bold text-neutral-800 dark:text-neutral-200">
<h2 className="text-center text-3xl font-bold text-neutral-800 dark:text-neutral-200 text-wrap-balance">
{children}
</h2>
);
Expand Down
5 changes: 5 additions & 0 deletions app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@ div[data-reach-tooltip] {
.editor-error code {
@apply font-mono text-xs p-1 text-red-900 rounded bg-red-100 inline-block;
}

/** Text-wrap balance utility */
.text-wrap-balance {
text-wrap: balance;
}
9 changes: 3 additions & 6 deletions app/src/locales/de/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Greifen Sie von überall aus auf diese Diagramme zu.<0/>Teilen und betten Sie Flussdiagramme ein, die synchron bleiben.",
"Accessible from any device": "Von jedem Gerät aus zugänglich",
Account: "Konto",
"Activate Flowchart Fun Pro": "Flowchart Fun Pro aktivieren",
"Activate your account": "Aktiviere dein Konto ",
Advanced: "Vorangeschritten",
Amount: "Betrag",
"An error occurred. Try resubmitting or email {0} directly.": [
Expand Down Expand Up @@ -66,7 +66,6 @@
Column: "Spalte",
"Comic Book": "Comic-Buch",
Comment: "Kommentar",
"Complete Subscription": "Abonnement abschließen",
Concentric: "Konzentrisch",
"Confirm New Email": "Neue E-Mail bestätigen",
Containers: "Behälter",
Expand Down Expand Up @@ -382,8 +381,6 @@
"Unknown Parsing Error": "Unbekannter Parser-Fehler",
"Unleash your creativity and streamline your workflow with Flowchart Fun Pro – starting at just $3/month!":
"Entfesseln Sie Ihre Kreativität und vereinfachen Sie Ihren Arbeitsablauf mit Flowchart Fun Pro – ab nur 3 $/Monat!",
"Unlock the full potential of Flowchart Fun Pro and get unlimited access to all of our advanced features. Complete your subscription below and start creating amazing flowcharts today!":
"Entsperren Sie das volle Potenzial von Flowchart Fun Pro und erhalten Sie unbegrenzten Zugang zu allen erweiterten Funktionen. Schließen Sie Ihr Abonnement unten ab und beginnen Sie heute mit dem Erstellen erstaunlicher Flussdiagramme!",
"Update Email": "E-Mail aktualisieren",
"Use AI to create flowcharts from data sets or algorithms":
"Verwenden Sie KI, um aus Datensätzen oder Algorithmen Flussdiagramme zu erstellen.",
Expand Down Expand Up @@ -425,9 +422,9 @@
'Sie können Text auch in "\\( \\)" umbrechen, um eine Kante zu erstellen',
"You must log in to create a standard flowchart.":
"Sie müssen sich anmelden, um ein Standarddiagramm zu erstellen.",
"You're almost there! Just one more step to unlock the full potential of <0>Flowchart Fun Pro</0>. Enter your payment details below to complete your subscription and start creating amazing flowcharts today.":
"Du bist fast da! Nur noch ein Schritt, um das volle Potenzial von <0>Flowchart Fun Pro</0> freizuschalten. Gib deine Zahlungsdetails unten ein, um dein Abonnement abzuschließen und heute mit dem Erstellen beeindruckender Flussdiagramme zu beginnen.",
"Your Charts": "Ihre Diagramme",
"Your payment details are secure. You can cancel anytime.":
"Ihre Zahlungsdaten sind sicher. Sie können jederzeit kündigen.",
"Your subscription is no longer active. If you want to create and edit hosted charts become a sponsor.":
"Ihr Abonnement ist nicht mehr aktiv. Wenn Sie gehostete Diagramme erstellen und bearbeiten möchten, werden Sie Sponsor.",
"Zoom In": "Vergrößern",
Expand Down
Loading

1 comment on commit 18a983c

@vercel
Copy link

@vercel vercel bot commented on 18a983c Jun 12, 2023

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.