Skip to content

Commit

Permalink
Updated URLs, fixed bug w/ addScans (handling updated response schema)
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Jul 29, 2024
1 parent c8949d2 commit 72ff61f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://equalify.dev/equalify.svg" alt="Equalify Logo" width="300">
<img src="https://dashboard.equalify.app/equalify.svg" alt="Equalify Logo" width="300">

# Equalify API

Expand All @@ -13,10 +13,10 @@ Our API is stateless and is intended to run ephemerally on serverless environmen
## Important Links

[Postman Collection](https://documenter.getpostman.com/view/26880150/2sA3BoarvB)
[GitBook Documentation](https://docs.equalify.dev/)
[GitBook Documentation](https://docs.equalify.app/)

Production environment: https://api.equalify.dev
Staging environment: https://api-staging.equalify.dev
Production environment: https://api.equalify.app +
Staging environment: https://api.equalify.dev
Local environment: http://localhost:3000

## Setup
Expand Down
2 changes: 1 addition & 1 deletion src/cognito/customMessageForgotPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { formatEmail } from '#src/utils';

export const customMessageForgotPassword = async (event) => {
event.response.emailSubject = `Please reset your password`;
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name'] ?? 'Hello there'},</p><p>Please reset your password by <a href="https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/reset?username=${event.userName}&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` });
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name'] ?? 'Hello there'},</p><p>Please reset your password by <a href="https://${process.env.STAGING ? 'equalify.dev' : 'dashboard.equalify.app'}/reset?username=${event.userName}&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` });
return event;
}
2 changes: 1 addition & 1 deletion src/cognito/customMessageUpdateUserAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatEmail } from '#src/utils';

export const customMessageUpdateUserAttribute = async (event) => {
event.response.emailSubject = `Please confirm your new email address`;
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name']},</p><p>Please confirm your new email address by <a href="https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/verify?type=email&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` });
event.response.emailMessage = formatEmail({ body: `<p>${event.request.userAttributes['name']},</p><p>Please confirm your new email address by <a href="https://${process.env.STAGING ? 'equalify.dev' : 'dashboard.equalify.app'}/verify?type=email&code=${event.request.codeParameter}">clicking here</a>.<p>Thank you,<br/>Equalify<div style="display:none"><a>${event.request.codeParameter}</a><a>${event.request.codeParameter}</a></div>` });

return event;
}
2 changes: 1 addition & 1 deletion src/cognito/customMessageVerifyUserAttribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const customMessageVerifyUserAttribute = async (event) => {
event.response.smsMessage = `Equalify: Verify your phone number by visting "https://${process.env.STAGING ? 'staging.' : ''}equalify.dev/verify?type=phone_number&code=${event.request.codeParameter}"`;
event.response.smsMessage = `Equalify: Verify your phone number by visting "https://${process.env.STAGING ? 'equalify.dev' : 'dashboard.equalify.app'}/verify?type=phone_number&code=${event.request.codeParameter}"`;

return event;
}
5 changes: 2 additions & 3 deletions src/routes/addScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export const addScans = async ({ request, reply }) => {
body: JSON.stringify({ url: (propertyDiscovery === 'sitemap' && !url.endsWith('.xml')) ? `${url}/sitemap.xml` : url })
})).json();
console.log(JSON.stringify({ scanResponse }));
const scanArray = scanResponse?.jobID ? [{ JobID: scanResponse?.jobID, url: url }] : scanResponse.map(obj => ({ JobID: obj.JobID, url: obj.URL }));

for (const { JobID, url } of scanArray) {
for (const { jobId, url } of scanResponse?.jobs ?? []) {
const urlId = (await db.query({
text: `SELECT "id" FROM "urls" WHERE "user_id"=$1 AND "url"=$2 AND "property_id"=$3`,
values: [jwtClaims.sub, url, propertyId],
Expand All @@ -52,7 +51,7 @@ export const addScans = async ({ request, reply }) => {

await db.query({
text: `INSERT INTO "scans" ("user_id", "property_id", "url_id", "job_id") VALUES ($1, $2, $3, $4) RETURNING "id"`,
values: [jwtClaims.sub, propertyId, urlId, parseInt(JobID)]
values: [jwtClaims.sub, propertyId, urlId, parseInt(jobId)]
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/scheduled/processScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const processScans = async () => {
// This route is called once every minute by Amazon EventBridge Scheduler
await db.connect();
const scans = (await db.query(`SELECT "id", "job_id", "property_id", "user_id" FROM "scans" WHERE "processing"=TRUE ORDER BY "created_at" DESC`)).rows;
console.log(scans);
await Promise.allSettled(scans.map(scan => new Promise(async (res) => {
try {
const { result, status } = await (await fetch(`https://scan.equalify.app/results/${scan.job_id}`)).json();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatEmail.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const formatEmail = ({ body }) => {
return `<p><img style="width:300px" src="https://equalify.dev/social.jpg"/></p>${body}`;
return `<p><img style="width:300px" src="https://dashboard.equalify.app/social.jpg"/></p>${body}`;
};

0 comments on commit 72ff61f

Please sign in to comment.