Release 202505311113

This commit is contained in:
pluja
2025-05-31 11:13:24 +00:00
parent 0c40d8eec5
commit aacd4c3265
3 changed files with 69 additions and 1 deletions

View File

@@ -114,7 +114,13 @@ export class ErrorBanners {
return result
} catch (error) {
this.handler(uiMessage)(error)
return fallback as F
return fallback as F extends never[]
? T extends [infer _First, ...infer _Rest]
? []
: T extends unknown[]
? T[number][]
: F
: F
}
}

View File

@@ -0,0 +1,27 @@
import type { Misc } from 'ts-toolbelt'
export async function makeAdminApiCallInfo<T extends Misc.JSON.Object>({
method,
path,
input,
baseUrl,
}: {
method: 'POST' | 'QUERY'
path: `/${string}`
input: T
baseUrl: URL | string
}) {
const fullPath = new URL(`/api/v1${path}`, baseUrl).href
return {
method,
path,
fullPath,
input,
output: await fetch(fullPath, {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(input),
}).then((res) => res.json() as Promise<Misc.JSON.Value>),
}
}

View File

@@ -33,6 +33,7 @@ import {
verificationStepStatuses,
} from '../../../../constants/verificationStepStatus'
import BaseLayout from '../../../../layouts/BaseLayout.astro'
import { makeAdminApiCallInfo } from '../../../../lib/makeAdminApiCallInfo'
import { pluralize } from '../../../../lib/pluralize'
import { prisma } from '../../../../lib/prisma'
@@ -181,6 +182,20 @@ const [service, categories, attributes] = await Astro.locals.banners.tryMany([
])
if (!service) return Astro.rewrite('/404')
const apiCalls = await Astro.locals.banners.try(
'Error fetching api calls',
() =>
Promise.all([
makeAdminApiCallInfo({
method: 'QUERY',
path: '/service/get',
input: { slug: service.slug },
baseUrl: Astro.url,
}),
]),
[]
)
---
<BaseLayout pageTitle={`Edit Service: ${service.name}`}>
@@ -1100,5 +1115,25 @@ if (!service) return Astro.rewrite('/404')
</form>
</FormSubSection>
</FormSection>
<FormSection title="API">
{
apiCalls.map((call) => (
<FormSubSection title={`${call.method} ${call.path}`}>
<p class="text-day-400 text-sm">Input:</p>
<pre
class="bg-night-800 border-night-500 text-day-300 overflow-x-auto rounded-md border p-3"
set:text={JSON.stringify(call.input, null, 2)}
/>
<p class="text-day-400 text-sm">Output:</p>
<pre
class="bg-night-800 border-night-500 text-day-300 overflow-x-auto rounded-md border p-3"
set:text={JSON.stringify(call.output, null, 2)}
/>
</FormSubSection>
))
}
</FormSection>
</div>
</BaseLayout>