This commit is contained in:
2025-11-17 14:37:50 -03:00
parent d2abaec021
commit 7f41704d90
51 changed files with 733 additions and 495 deletions

View File

@@ -45,7 +45,7 @@ export function ModeToggle() {
}
type ThemedImageProps = {
children?: string
children?: string | React.ReactNode
className?: string
}

View File

@@ -0,0 +1,15 @@
{
"name": "@repo/util",
"version": "0.0.0",
"private": true,
"exports": {
"./*": "./src/*.ts"
},
"devDependencies": {
"@repo/auth": "*",
"@types/node": "^24.9.2",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"typescript": "^5.9.3"
}
}

View File

@@ -0,0 +1,34 @@
import { Meilisearch, type SearchResponse } from 'meilisearch'
const MAX_HITS_PER_PAGE = 100
export async function createSearch({
query,
filter = undefined,
index,
page,
hitsPerPage = 25,
sort,
env
}: {
query?: string
filter?: string
index: string
page?: number
hitsPerPage?: number
sort: string[]
env: any
}): Promise<SearchResponse> {
const host = env.MEILI_HOST
const apiKey = env.MEILI_API_KEY
const client = new Meilisearch({ host, apiKey })
const index_ = client.index(index)
return index_.search(query, {
sort,
filter,
page,
hitsPerPage:
hitsPerPage > MAX_HITS_PER_PAGE ? MAX_HITS_PER_PAGE : hitsPerPage
})
}

View File

@@ -0,0 +1,49 @@
import type { User } from '@repo/auth/auth'
import { requestIdContext, userContext } from '@repo/auth/context'
import type { LoaderFunctionArgs } from 'react-router'
export enum HttpMethod {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
PATCH = 'PATCH',
DELETE = 'DELETE'
}
type RequestArgs = {
url: string
method?: HttpMethod
headers?: HeadersInit
body?: BodyInit | null
request: LoaderFunctionArgs['request']
context: LoaderFunctionArgs['context']
}
export function request({
url,
method = HttpMethod.GET,
body = null,
headers: _headers = {},
request: { signal },
context
}: RequestArgs): Promise<Response> {
const requestId = context.get(requestIdContext) as string
const user = context.get(userContext) as User
const url_ = new URL(url, context.cloudflare.env.API_URL)
const headers = new Headers({
Authorization: `Bearer ${user.accessToken}`
})
if (_headers instanceof Headers) {
_headers.forEach((value, key) => headers.set(key, value))
} else {
Object.entries(_headers).forEach(([key, value]) => headers.set(key, value))
}
console.log(
`[${new Date().toISOString()}] [${requestId}] ${method} ${url_.toString()}`
)
return fetch(url_.toString(), { method, headers, body, signal })
}

View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"moduleResolution": "bundler",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
}