import { bearerAuth } from "npm:hono/bearer-auth";
import { cors } from "npm:hono/cors";
import { Hono } from "npm:hono@3";
import Typesense from "npm:typesense";
import type { SearchParams, SearchParamsWithPreset, SearchResponseHit } from "npm:typesense/lib/Typesense/Documents";
const MAX_SEARCH_RADIUS_IN_MILES = 10;
const COLLECTIONS = {
"resources": "resources",
};
const typesenseClient = new Typesense.Client({
"nodes": [{
"host": Deno.env.get("TYPESENSE_HOST") || "",
"port": 443,
"protocol": "https",
}],
"apiKey": Deno.env.get("TYPESENSE_API_KEY") || "",
"connectionTimeoutSeconds": 10,
"retryIntervalSeconds": 0.1,
"healthcheckIntervalSeconds": 2,
"logLevel": "debug",
});
interface Resource {
id: string;
name: string;
address: {
full_address: string;
latitude: number;
longitude: number;
};
website: string;
phone: string;
user_email: string;
description: string;
utc_offset: number;
featured_image_url: string;
hours_text: string | null;
hours: {
day: string;
day_int: number;
open_time: string | null;
close_time: string | null;
}[];
services: {
id: string | number;
name: string;
description: string;
category: {
icon: string;
name: ResourceTypes;
};
}[];
qualifications: {
id: string | number;
name: string;
}[];
distance_between: number;
}
const CATEGORY_IDS_FROM_TYPESENSE = {
"Favorites": -1,
"Food": 53,
"Shelter": 52,
"Churches": 56,
"Resources": 57,
"Medical": 54,
"Addiction Recovery": 58,
"Domestic Violence": 51,
"Housing": 69,
};
type ResourceTypes = keyof typeof CATEGORY_IDS_FROM_TYPESENSE;
function convertMetersToMiles(meters: number): number {
return 0.000621371 * meters;
}
function roundToQuarter(number: number) {
let remainder = number % 1;
if (number < 1 && remainder <= 0.125) {
return Math.floor(number) + 0.125;
} else if (remainder <= 0.375) {
return Math.floor(number) + 0.25;
} else if (remainder <= 0.625) {
return Math.floor(number) + 0.50;
} else if (remainder <= 0.875) {
return Math.floor(number) + 0.75;
} else {