cleanup old code
All checks were successful
Build and push image for doorman-homeassistant / docker (push) Successful in 29s
Build and push Doorman UI / API / docker (push) Successful in 2m2s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 5s

This commit is contained in:
Martin Dimitrov 2025-05-31 21:50:31 -07:00
parent aeefd6f5d3
commit 2f45005a8a
3 changed files with 0 additions and 197 deletions

View File

@ -1,14 +0,0 @@
export interface DoorConfig {
buzzer: string;
buzzerCode: string;
discordUsers: string[];
fallbackNumbers: string[];
pin: string;
pressKey: string;
timeout: number;
greeting: string;
}
export interface EditDoorConfig extends DoorConfig {
approvalId: string;
}

View File

@ -1,3 +0,0 @@
export interface Lock {
fingerprint: any;
}

View File

@ -1,22 +1,9 @@
import { randomUUID } from "crypto";
import { DynamoDBClient, GetItemCommand, DeleteItemCommand, PutItemCommand, UpdateItemCommand, GetItemOutput } from "@aws-sdk/client-dynamodb";
import { TwilioContext } from "../types/TwilioContext"; import { TwilioContext } from "../types/TwilioContext";
import { DoorConfig } from "../types/DoorConfig";
import { DynaBridge } from "dynabridge"; import { DynaBridge } from "dynabridge";
import { DoorConfigEntity, EditDoorConfigEntity } from "../schema/DoorConfig"; import { DoorConfigEntity, EditDoorConfigEntity } from "../schema/DoorConfig";
import { DoorAliasEntity } from "../schema/DoorAlias"; import { DoorAliasEntity } from "../schema/DoorAlias";
import { LockStatusEntity } from "../schema/LockStatus"; import { LockStatusEntity } from "../schema/LockStatus";
export const createDDBClient = (context: TwilioContext) => {
return new DynamoDBClient({
region: "us-east-1" ,
credentials: {
accessKeyId: context.AWS_ACCESS_KEY,
secretAccessKey: context.AWS_SECRET_ACCESS_KEY,
},
});
};
export const createDynaBridgeClient = (context: TwilioContext) => { export const createDynaBridgeClient = (context: TwilioContext) => {
// register all entities here // register all entities here
return new DynaBridge({ return new DynaBridge({
@ -46,170 +33,3 @@ export const createDynaBridgeClient = (context: TwilioContext) => {
}, },
}); });
}; };
export const getLockStatusCommand = (door: string) => {
return new GetItemCommand({
TableName: "doorman",
Key: {
"PK": {
S: door,
},
"SK": {
S: "lock",
}
},
});
};
export const getDoorAliasCommand = (buzzerNumber: string) => {
return new GetItemCommand({
TableName: "doorman",
Key: {
"PK": {
S: buzzerNumber,
},
"SK": {
S: "alias",
}
},
});
};
export const getDoorConfigCommand = (door: string) => {
return new GetItemCommand({
TableName: "doorman",
Key: {
"PK": {
S: `door-${door}`,
},
"SK": {
S: "config",
},
},
});
};
export const isLockOpen = (lock: GetItemOutput) => {
// ttl is a UTC ms time for how long it is unlocked
const ttl = lock.Item?.TTL?.N || 0;
return parseInt("" + ttl) > Date.now();
};
export const clearLockStatusCommand = (lock: GetItemOutput) => {
return new DeleteItemCommand({
TableName: "doorman",
Key: {
"PK": {
S: lock?.Item?.PK.S as string,
},
"SK": {
S: "lock",
}
}
});
};
export const setLockStatusCommand = (door: string, timeoutSeconds: number, fingerprintObj: any) => {
return new PutItemCommand({
TableName: "doorman",
Item: {
"PK": {
S: door,
},
"SK": {
S: "lock",
},
"TTL": {
N: `${Date.now() + timeoutSeconds * 1000}`,
},
"fingerprint": {
S: JSON.stringify(fingerprintObj),
}
}
});
};
export const putDoorUpdateConfigCommand = (door: string, config: DoorConfig) => {
return new PutItemCommand({
TableName: "doorman",
Item: {
"PK": {
S: "door-" + door,
},
"SK": {
S: "config-update",
},
"buzzer": {
S: config.buzzer,
},
"buzzerCode": {
S: config.buzzerCode,
},
"discordUsers": {
SS: config.discordUsers,
},
"fallbackNumbers": {
SS: config.fallbackNumbers,
},
"pin": {
S: config.pin,
},
"pressKey": {
S: config.pressKey,
},
"timeout": {
N: `${config.timeout}`,
},
"greeting": {
S: config.greeting,
},
"approvalId": {
S: randomUUID().toString(),
}
}
});
};
export function ddbItemToJSON<T extends Record<string, any>>(ddbItem: GetItemOutput): T {
let obj: any = {};
if (!ddbItem.Item) {
return obj;
}
const Item = ddbItem.Item;
Object.keys(Item).forEach(key => {
obj[key] = Object.values(Item[key])[0];
});
return obj;
};
export const getDoorConfigUpdateCommand = (door: string) => {
return new GetItemCommand({
TableName: "doorman",
Key: {
"PK": {
S: `door-${door}`,
},
"SK": {
S: "config-update",
},
},
});
};
export const replaceDoorConfigWithUpdateItem = (newConfigItem: GetItemOutput & { Item: { approvalId?: { S: string } }}) => {
const newItem = {
...newConfigItem.Item,
SK: { S: "config" },
};
delete newItem.approvalId;
return new PutItemCommand({
TableName: "doorman",
Item: newItem,
});
};