remove cleanup for now
This commit is contained in:
parent
975c47b174
commit
838ca2cb23
@ -12,7 +12,8 @@ import { z } from "zod";
|
|||||||
import { UserAgentHeader } from "../../../utils/blockUserAgent";
|
import { UserAgentHeader } from "../../../utils/blockUserAgent";
|
||||||
import { setResponseJson } from "../../../utils/responseUtils";
|
import { setResponseJson } from "../../../utils/responseUtils";
|
||||||
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
||||||
import { isTTLInFuture } from "../../../common/TTLHelper";
|
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
export const LogCallRequestSchema = z.object({
|
export const LogCallRequestSchema = z.object({
|
||||||
caller: z.string(),
|
caller: z.string(),
|
||||||
@ -27,8 +28,24 @@ export const LogCallResponseSchema = z.object({
|
|||||||
|
|
||||||
export type LogCallResponse = z.infer<typeof LogCallResponseSchema>;
|
export type LogCallResponse = z.infer<typeof LogCallResponseSchema>;
|
||||||
|
|
||||||
function getCode() {
|
// hash is 4 digit number based on todays date + phone number caller
|
||||||
return `${Math.floor(Math.random() * 10000)}`.padStart(4, '0');
|
// cost saving so we don't generate a new OTP for every caller even if its the same caller
|
||||||
|
function getCode(caller: string) {
|
||||||
|
const hash = crypto.createHash("sha256");
|
||||||
|
const today = new Date();
|
||||||
|
|
||||||
|
hash.update(today.toLocaleDateString('en-US'));
|
||||||
|
hash.update(caller);
|
||||||
|
|
||||||
|
const hashHex = hash.digest('hex');
|
||||||
|
|
||||||
|
// 2. Convert the hexadecimal string to a BigInt
|
||||||
|
// This is necessary for large hash values that exceed JavaScript's Number limit.
|
||||||
|
const hashBigInt = BigInt(`0x${hashHex}`);
|
||||||
|
|
||||||
|
// 3. Convert the BigInt to a decimal string
|
||||||
|
const hashDecimal = hashBigInt.toString();
|
||||||
|
return hashDecimal.substring(hashDecimal.length - 4,);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestTwilio> = withMetrics("logCall", async (context, event, callback, metricsRegistry) => {
|
export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestTwilio> = withMetrics("logCall", async (context, event, callback, metricsRegistry) => {
|
||||||
@ -47,17 +64,16 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
|
|||||||
msg: "Onboarding is not open",
|
msg: "Onboarding is not open",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// best efforts cleanup
|
// TODO: best efforts cleanup
|
||||||
// TODO: make this use an INDEX instead of scan
|
// console.log("Attempting best efforts cleanup of logged calls")
|
||||||
console.log("Attempting best efforts cleanup of logged calls")
|
// const items = await db.entities.logCall.findAll();
|
||||||
const logs = await db.entities.logCall.findAll();
|
// const toRemove = items.filter(item => item.SK === LOG_CALL_SK && !isTTLInFuture(item));
|
||||||
const toRemove = logs.filter(log => !isTTLInFuture(log));
|
// console.log(`There are ${toRemove.length} old call logs to remove`);
|
||||||
console.log(`There are ${toRemove.length} old call logs to remove`);
|
// await db.entities.logCall.deleteBatch(toRemove);
|
||||||
await db.entities.logCall.deleteBatch(toRemove);
|
// console.log("done cleaning up logged calls");
|
||||||
console.log("done cleaning up logged calls");
|
|
||||||
|
|
||||||
// log this caller
|
// log this caller
|
||||||
const otp = getCode();
|
const otp = getCode(caller);
|
||||||
const logCall = LogCallSchema.parse({
|
const logCall = LogCallSchema.parse({
|
||||||
PK: otp,
|
PK: otp,
|
||||||
SK: LOG_CALL_SK,
|
SK: LOG_CALL_SK,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { AppLayout, BreadcrumbGroup, Container, Flashbar, FlashbarProps, Header,
|
|||||||
import OtpInput from 'react-otp-input';
|
import OtpInput from 'react-otp-input';
|
||||||
import { CountdownBar } from "../components/CountdownBar";
|
import { CountdownBar } from "../components/CountdownBar";
|
||||||
import { fetchUrlEncoded } from "../helpers/FetchHelper";
|
import { fetchUrlEncoded } from "../helpers/FetchHelper";
|
||||||
|
import { readSync } from "fs";
|
||||||
|
|
||||||
export function OnboardingPage() {
|
export function OnboardingPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -111,10 +112,13 @@ export function OnboardingPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (detail.requestedStepIndex === 2) {
|
if (detail.requestedStepIndex === 2) {
|
||||||
fetch('/api/door/auth?door=onboardingflag&key=1234')
|
fetchUrlEncoded('/api/door/auth', {
|
||||||
|
door: "onboardingflag",
|
||||||
|
key: 1234
|
||||||
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status === "CLOSED") {
|
if (res.status === "CLOSED" || !res.msg) {
|
||||||
addAlert('error', 'Something went wrong, please try again');
|
addAlert('error', 'Something went wrong, please try again');
|
||||||
} else {
|
} else {
|
||||||
addAlert("in-progress", (
|
addAlert("in-progress", (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user