code share accross packages
This commit is contained in:
parent
9a8e37824e
commit
bb103d3290
@ -18,6 +18,14 @@ export interface InfoRequest extends ServerlessEventObject {
|
||||
json: string;
|
||||
}
|
||||
|
||||
export interface InfoResponseClient {
|
||||
buzzer: string;
|
||||
door: string;
|
||||
pressKey: string;
|
||||
fallbackNumbers: string[];
|
||||
discordUsers: string[];
|
||||
}
|
||||
|
||||
export const handler: ServerlessFunctionSignature<TwilioContext, InfoRequest> = async function(context, event, callback) {
|
||||
const response = new Twilio.Response();
|
||||
|
||||
|
||||
@ -12,6 +12,11 @@ export interface StatusRequest extends ServerlessEventObject {
|
||||
door: string;
|
||||
}
|
||||
|
||||
export interface StatusResponse {
|
||||
status: DoorStatus,
|
||||
fingerprint: any;
|
||||
}
|
||||
|
||||
export const handler: ServerlessFunctionSignature<TwilioContext, StatusRequest> = async function(context, event, callback) {
|
||||
const response = new Twilio.Response();
|
||||
|
||||
|
||||
@ -11,14 +11,15 @@ import { BuzzerDialEvent } from '../types/BuzzerDialEvent';
|
||||
import { getConfig, notifyAllDiscord, notifyDiscord } from '../utils/DoormanUtils';
|
||||
import { dialFallbackTwiml, doorOpenTwiml } from '../utils/TwimlUtils';
|
||||
import { TwilioContext } from '../types/TwilioContext';
|
||||
import { DoorConfig } from '../types/DoorConfig';
|
||||
import { DoorStatus, DoorStatusResponse } from '../types/DoorStatusResponse';
|
||||
import VoiceResponse from 'twilio/lib/twiml/VoiceResponse';
|
||||
import { DoorStatus } from '../../../doorman-api/src/types/DoorStatus';
|
||||
import { StatusResponse } from '../../../doorman-api/src/functions/api/door/status';
|
||||
import { InfoResponseClient } from '../../../doorman-api/src/functions/api/door/info';
|
||||
|
||||
export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent> = async function(context, event, callback) {
|
||||
let invokeId = `[${randomUUID()}]`;
|
||||
let configString = event.config;
|
||||
let config: DoorConfig | undefined;
|
||||
let config: InfoResponseClient | undefined;
|
||||
console.log(invokeId, "starting execution");
|
||||
|
||||
// get by api or parse it out from query
|
||||
@ -57,7 +58,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent
|
||||
fetch(context.DOORMAN_URL + `/api/door/status?door=${config.door}`)
|
||||
.then(res => res.json())
|
||||
.then(async (rawBody) => {
|
||||
let body = rawBody as DoorStatusResponse;
|
||||
let body = rawBody as StatusResponse;
|
||||
if (body?.status === DoorStatus.OPEN) {
|
||||
clearInterval(intervals[0]);
|
||||
const twiml = doorOpenTwiml(config);
|
||||
|
||||
@ -1,9 +1,21 @@
|
||||
import { readdirSync } from "node:fs";
|
||||
import path from "path";
|
||||
|
||||
const paths = [
|
||||
'./src/functions'
|
||||
];
|
||||
|
||||
const functionFiles = paths.map(path => readdirSync(path).map(file => path + "/" + file)).flat();
|
||||
|
||||
// for hot reload to work, we import all the files we want to build
|
||||
const imports = functionFiles.forEach(file => require('./' + path.relative('src', file)));
|
||||
|
||||
console.log("functions to build:", functionFiles);
|
||||
console.log("Building functions...");
|
||||
await Bun.build({
|
||||
entrypoints: ['./src/functions/buzzer-activated.ts'],
|
||||
entrypoints: functionFiles,
|
||||
outdir: './build/functions',
|
||||
packages: 'external',
|
||||
naming: '[dir]/[name].[ext]' ,
|
||||
target: 'node',
|
||||
format: 'cjs',
|
||||
});
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
export interface DoorConfig {
|
||||
door: string;
|
||||
pressKey: string;
|
||||
fallbackNumbers: string[];
|
||||
discordUsers: string[];
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
export enum DoorStatus {
|
||||
OPEN = "OPEN",
|
||||
CLOSED = "CLOSED",
|
||||
}
|
||||
|
||||
export interface DoorStatusResponse {
|
||||
status: DoorStatus,
|
||||
fingerprint: any;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user