sanitize phone number
This commit is contained in:
parent
838ca2cb23
commit
aba2aed396
@ -13,6 +13,7 @@ import { withMetrics } from "../../../common/DoormanHandler";
|
|||||||
import { z } from "zod";
|
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 { sanitizePhoneNumber } from "../../../utils/phoneUtils";
|
||||||
|
|
||||||
export const InfoRequestSchema = z.object({
|
export const InfoRequestSchema = z.object({
|
||||||
door: z.string().optional(),
|
door: z.string().optional(),
|
||||||
@ -39,7 +40,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, InfoRequestTwil
|
|||||||
const req = InfoRequestSchema.parse(event);
|
const req = InfoRequestSchema.parse(event);
|
||||||
|
|
||||||
let door = req.door;
|
let door = req.door;
|
||||||
const buzzer = req.buzzer?.slice(-10);
|
const buzzer = sanitizePhoneNumber(req.buzzer);
|
||||||
|
|
||||||
const db = createDynaBridgeClient(context);
|
const db = createDynaBridgeClient(context);
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { setResponseJson } from "../../../utils/responseUtils";
|
|||||||
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
||||||
|
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
import { sanitizePhoneNumber } from "../../../utils/phoneUtils";
|
||||||
|
|
||||||
export const LogCallRequestSchema = z.object({
|
export const LogCallRequestSchema = z.object({
|
||||||
caller: z.string(),
|
caller: z.string(),
|
||||||
@ -52,7 +53,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
|
|||||||
const response = new Twilio.Response();
|
const response = new Twilio.Response();
|
||||||
const req = LogCallRequestSchema.parse(event);
|
const req = LogCallRequestSchema.parse(event);
|
||||||
|
|
||||||
let caller = req.caller;
|
let caller = sanitizePhoneNumber(req.caller);
|
||||||
|
|
||||||
const db = createDynaBridgeClient(context);
|
const db = createDynaBridgeClient(context);
|
||||||
|
|
||||||
@ -64,14 +65,6 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
|
|||||||
msg: "Onboarding is not open",
|
msg: "Onboarding is not open",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO: best efforts cleanup
|
|
||||||
// console.log("Attempting best efforts cleanup of logged calls")
|
|
||||||
// const items = await db.entities.logCall.findAll();
|
|
||||||
// const toRemove = items.filter(item => item.SK === LOG_CALL_SK && !isTTLInFuture(item));
|
|
||||||
// console.log(`There are ${toRemove.length} old call logs to remove`);
|
|
||||||
// await db.entities.logCall.deleteBatch(toRemove);
|
|
||||||
// console.log("done cleaning up logged calls");
|
|
||||||
|
|
||||||
// log this caller
|
// log this caller
|
||||||
const otp = getCode(caller);
|
const otp = getCode(caller);
|
||||||
const logCall = LogCallSchema.parse({
|
const logCall = LogCallSchema.parse({
|
||||||
|
|||||||
6
packages/doorman-api/src/utils/phoneUtils.ts
Normal file
6
packages/doorman-api/src/utils/phoneUtils.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export const sanitizePhoneNumber = (phone?: string) => {
|
||||||
|
if (!phone) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return phone.slice(-10);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user