-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified eslintrc and add prettierrc --------- Co-authored-by: Caio Borghi <[email protected]>
- Loading branch information
1 parent
f0f98b4
commit 44e0e54
Showing
62 changed files
with
3,701 additions
and
2,605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
extends: [ | ||
"next", | ||
"turbo", | ||
"prettier", | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"next/core-web-vitals", | ||
"prettier" | ||
], | ||
rules: { | ||
"@next/next/no-html-link-for-pages": "off", | ||
"@next/next/no-img-element": "off", | ||
"react/react-in-jsx-scope": 0, | ||
"no-console": "warn", | ||
}, | ||
parserOptions: { | ||
babelOptions: { | ||
presets: [require.resolve("next/babel")], | ||
}, | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["custom"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 55 additions & 51 deletions
106
apps/manual-email-sender/src/openings-email/sendEmails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,98 @@ | ||
import { createClient } from '@supabase/supabase-js'; | ||
import { Channel } from 'amqplib'; | ||
import dotenv from "dotenv" | ||
import { Entities } from 'shared'; | ||
import { EmailQueues } from 'shared/src/enums'; | ||
import { openingEmailHTML } from '../../../../packages/shared/src/email/openings-email/28-06-2023/OpeningEmail'; | ||
import { Resend } from 'resend'; | ||
import path from 'path'; | ||
import { readFileSync } from 'fs'; | ||
import { connectToQueue } from 'shared/src/queue'; | ||
import fs from 'fs'; | ||
/* eslint-disable no-console */ | ||
import { createClient } from '@supabase/supabase-js' | ||
import dotenv from 'dotenv' | ||
import { Entities } from 'shared' | ||
import { openingEmailHTML } from '../../../../packages/shared/src/email/openings-email/28-06-2023/OpeningEmail' | ||
import { Resend } from 'resend' | ||
import path from 'path' | ||
import { readFileSync } from 'fs' | ||
import fs from 'fs' | ||
|
||
dotenv.config() | ||
|
||
const SUPABASE_URL = process.env.SUPABASE_URL || '' | ||
const SUPABASE_KEY = process.env.SUPABASE_KEY || '' | ||
const SUPABASE_URL = process.env['SUPABASE_URL'] || '' | ||
const SUPABASE_KEY = process.env['SUPABASE_KEY'] || '' | ||
|
||
const sentFileName = './sent-emails-28-06-2023.txt' | ||
|
||
const getConfirmedSubscribers = async () => { | ||
const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY) | ||
const { data, error } = await supabaseClient.from(Entities.Subcribers).select('*').eq('isConfirmed', 'TRUE') | ||
if (error) | ||
throw error; | ||
const { data, error } = await supabaseClient | ||
.from(Entities.Subcribers) | ||
.select('*') | ||
.eq('isConfirmed', 'TRUE') | ||
if (error) throw error | ||
return data | ||
} | ||
|
||
async function getConfirmedNotSentSubscribers(emailsSent: string[]) { | ||
const confirmedSubscribers = await getConfirmedSubscribers(); | ||
return confirmedSubscribers.filter((subscriber) => !emailsSent.includes(subscriber.email)); | ||
const confirmedSubscribers = await getConfirmedSubscribers() | ||
return confirmedSubscribers.filter( | ||
(subscriber) => !emailsSent.includes(subscriber.email) | ||
) | ||
} | ||
|
||
const sendEmail = async (resend: Resend, email: string) => { | ||
const handleError = (err: unknown) => { | ||
console.error(`Error sending to: ${email}`, err) | ||
fs.appendFileSync(path.resolve(__dirname, './error-emails.txt'), `${email}\n`) | ||
fs.appendFileSync( | ||
path.resolve(__dirname, './error-emails.txt'), | ||
`${email}\n` | ||
) | ||
} | ||
|
||
const emailHTML = openingEmailHTML | ||
try { | ||
console.log(`Sending to ${email}...`) | ||
const response = await resend.emails.send({ | ||
from: '[email protected] (Trampar de Casa)', | ||
to: email, | ||
subject: '25 vagas para você Trampar de Casa 🔥', | ||
html: emailHTML | ||
}) | ||
if (!response) { | ||
handleError("Response is null") | ||
return | ||
} | ||
console.log(`Successfully sent to ${email}!`) | ||
fs.appendFileSync(path.resolve(__dirname, sentFileName), `${email}\n`) | ||
} catch (err) { | ||
handleError(err) | ||
console.log(err) | ||
try { | ||
console.log(`Sending to ${email}...`) | ||
const response = await resend.emails.send({ | ||
from: '[email protected] (Trampar de Casa)', | ||
to: email, | ||
subject: '25 vagas para você Trampar de Casa 🔥', | ||
html: emailHTML, | ||
}) | ||
if (!response) { | ||
handleError('Response is null') | ||
return | ||
} | ||
console.log(`Successfully sent to ${email}!`) | ||
fs.appendFileSync(path.resolve(__dirname, sentFileName), `${email}\n`) | ||
} catch (err) { | ||
handleError(err) | ||
console.log(err) | ||
} | ||
} | ||
|
||
|
||
const batchSend = async (emails: string[]) => { | ||
let i = 1; | ||
let i = 1 | ||
let promises: Promise<void>[] = [] | ||
const resend = new Resend(process.env['RESEND_KEY']) | ||
for (const email of emails) { | ||
console.log(`[${i++}/${emails.length}]`) | ||
promises.push(sendEmail(resend, email)) | ||
if(i % 10 === 0) { | ||
console.log(`Waiting for [${i/10}/${emails.length / 10}] round to finish...`) | ||
if (i % 10 === 0) { | ||
console.log( | ||
`Waiting for [${i / 10}/${emails.length / 10}] round to finish...` | ||
) | ||
await Promise.all(promises) | ||
console.log("Waiting 1s...") | ||
await new Promise(r => setTimeout(r, 1_000)) | ||
console.log('Waiting 1s...') | ||
await new Promise((r) => setTimeout(r, 1_000)) | ||
promises = [] | ||
} | ||
} | ||
|
||
if(promises.length) { | ||
console.log("Sending remaining emails...", promises.length) | ||
if (promises.length) { | ||
console.log('Sending remaining emails...', promises.length) | ||
await Promise.all(promises) | ||
} | ||
console.log("Batch send finished!") | ||
console.log('Batch send finished!') | ||
} | ||
|
||
async function main() { | ||
const successEmailsPath = path.resolve(__dirname, sentFileName); | ||
const emailsSent = readFileSync(successEmailsPath, 'utf8').split("\n"); | ||
const successEmailsPath = path.resolve(__dirname, sentFileName) | ||
const emailsSent = readFileSync(successEmailsPath, 'utf8').split('\n') | ||
const subscribers = await getConfirmedNotSentSubscribers(emailsSent) | ||
const emails = subscribers.map(s => s.email) | ||
const emails = subscribers.map((s) => s.email) | ||
await batchSend(emails) | ||
} | ||
|
||
main().catch(console.error); | ||
|
||
|
||
main().catch(console.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["custom"], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import { StatusCodes } from "http-status-codes"; | ||
import { NextResponse } from "next/server"; | ||
import Email from "vercel-email" | ||
import { StatusCodes } from 'http-status-codes' | ||
import { NextResponse } from 'next/server' | ||
import Email from 'vercel-email' | ||
|
||
export const runtime = 'edge'; | ||
export const runtime = 'edge' | ||
|
||
export async function POST (request: Request) { | ||
export async function POST(request: Request) { | ||
const body = await request.json() | ||
const field = process.env['EMAIL_KEY'] | ||
if (!body[field] || body[field] !== process.env['EMAIL_PASS']) | ||
return new NextResponse(null, { status: StatusCodes.UNAUTHORIZED }) | ||
|
||
const { to, from, subject, html, text, bcc } = body | ||
if (!("text" in body || "html" in body)) { | ||
if (!('text' in body || 'html' in body)) { | ||
return new NextResponse(null, { status: StatusCodes.BAD_REQUEST }) | ||
} | ||
|
||
if ("text" in body) { | ||
if ('text' in body) { | ||
await Email.send({ | ||
to, | ||
from, | ||
subject, | ||
text, | ||
bcc | ||
bcc, | ||
}) | ||
} else if ("html" in body) { | ||
} else if ('html' in body) { | ||
await Email.send({ | ||
to, | ||
from, | ||
subject, | ||
html, | ||
bcc | ||
bcc, | ||
}) | ||
} | ||
|
||
return new NextResponse(null, { status: StatusCodes.OK }) | ||
} | ||
} |
Oops, something went wrong.