@innertia-solutions/innertia-nuxt 0.1.90 → 0.1.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/components/Ai/ModelPrices.vue +105 -0
- package/components/Ai/UsageReport.vue +127 -0
- package/components/Ai/UsageSummary.vue +13 -0
- package/components/Ai/__tests__/sfc-compile.test.ts +26 -0
- package/components/Billing/ClientTotals.vue +65 -0
- package/components/Billing/Invoices.vue +271 -0
- package/components/Billing/Overview.vue +124 -0
- package/components/Billing/Plans.vue +146 -0
- package/components/Billing/Settings.vue +79 -0
- package/components/Billing/SpaceSubscription.vue +202 -0
- package/components/Billing/StatusBanner.vue +36 -0
- package/components/Billing/UsageTable.vue +32 -0
- package/components/Billing/__tests__/sfc-compile.test.ts +26 -0
- package/components/Integrations/ApiKeys.vue +297 -0
- package/components/Integrations/Developers.vue +60 -0
- package/components/Integrations/Webhooks.vue +458 -0
- package/components/Integrations/__tests__/sfc-compile.test.ts +31 -0
- package/composables/useAiUsage/index.ts +48 -0
- package/composables/useAiUsage/internal/__tests__/aiUsage.test.ts +50 -0
- package/composables/useAiUsage/internal/aiUsage.ts +140 -0
- package/composables/useBilling/index.ts +147 -0
- package/composables/useBilling/internal/__tests__/billing.test.ts +78 -0
- package/composables/useBilling/internal/billing.ts +264 -0
- package/composables/useIntegrations/index.ts +136 -0
- package/composables/useIntegrations/internal/__tests__/integrations.test.ts +112 -0
- package/composables/useIntegrations/internal/integrations.ts +276 -0
- package/docs/ai-usage.md +38 -0
- package/docs/billing.md +75 -0
- package/docs/webhooks-api.md +88 -0
- package/nuxt.config.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import { parse, compileScript, compileTemplate } from 'vue/compiler-sfc'
|
|
5
|
+
|
|
6
|
+
// Billing components compile (script + template) without errors.
|
|
7
|
+
const COMPONENTS = ['../Plans.vue', '../Invoices.vue', '../SpaceSubscription.vue', '../ClientTotals.vue', '../Settings.vue', '../Overview.vue', '../StatusBanner.vue', '../UsageTable.vue']
|
|
8
|
+
|
|
9
|
+
describe('SFC de Billing compilan', () => {
|
|
10
|
+
for (const rel of COMPONENTS) {
|
|
11
|
+
it(rel, () => {
|
|
12
|
+
const filename = resolve(__dirname, rel)
|
|
13
|
+
const { descriptor, errors } = parse(readFileSync(filename, 'utf8'), { filename })
|
|
14
|
+
expect(errors).toEqual([])
|
|
15
|
+
|
|
16
|
+
const script = compileScript(descriptor, { id: rel })
|
|
17
|
+
const tpl = compileTemplate({
|
|
18
|
+
source: descriptor.template!.content,
|
|
19
|
+
filename,
|
|
20
|
+
id: rel,
|
|
21
|
+
compilerOptions: { bindingMetadata: script.bindings },
|
|
22
|
+
})
|
|
23
|
+
expect(tpl.errors).toEqual([])
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
})
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { IconKey, IconPlus, IconRefresh, IconBan, IconAlertTriangle, IconBook } from '@tabler/icons-vue'
|
|
3
|
+
import {
|
|
4
|
+
apiKeyStatus, groupScopes, toggleValue, expiryLabel, relativeTime, formatDateTime, httpSeverity,
|
|
5
|
+
EXPIRY_PRESETS, expiryFromPreset, appendPage, type ApiKey,
|
|
6
|
+
} from '../../composables/useIntegrations/internal/integrations'
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Integrations.ApiKeys — API keys of the active space: list, create (scopes, optional site,
|
|
10
|
+
* expiry), key shown ONCE, request log, rotate (24 h coexistence) and revoke.
|
|
11
|
+
* Backend: \Innertia\PublicApi\Routes::manage() (GET|POST api-keys, …).
|
|
12
|
+
*
|
|
13
|
+
* <Integrations.ApiKeys :organizations="sites" developers-url="/developers" />
|
|
14
|
+
*/
|
|
15
|
+
const props = withDefaults(defineProps<{
|
|
16
|
+
endpoint?: string
|
|
17
|
+
organizations?: { value: string | number; label: string }[]
|
|
18
|
+
canManage?: boolean
|
|
19
|
+
developersUrl?: string
|
|
20
|
+
}>(), { endpoint: 'integrations', organizations: () => [], canManage: true, developersUrl: '' })
|
|
21
|
+
|
|
22
|
+
const toast = useToast()
|
|
23
|
+
const { confirm } = useModal()
|
|
24
|
+
const { list, scopes, create, rotate, revoke, requests } = useApiKeys({ base: props.endpoint })
|
|
25
|
+
|
|
26
|
+
const keys = computed<ApiKey[]>(() => (list.data.value as ApiKey[] | undefined) ?? [])
|
|
27
|
+
const scopeGroups = computed(() => groupScopes((scopes.data.value as any[]) ?? []))
|
|
28
|
+
const orgLabel = (id: any) => props.organizations.find(o => String(o.value) === String(id))?.label ?? id
|
|
29
|
+
|
|
30
|
+
const errorMessage = (e: any, fallback: string) =>
|
|
31
|
+
e?.data?.message ?? (e?.data?.errors ? Object.values(e.data.errors).flat()[0] : null) ?? fallback
|
|
32
|
+
|
|
33
|
+
// ── Create ──────────────────────────────────────────────────────────────────
|
|
34
|
+
const showCreate = ref(false)
|
|
35
|
+
const form = reactive({ name: '', scopes: [] as string[], organization_id: '' as string | number, expiry: '' })
|
|
36
|
+
|
|
37
|
+
function openCreate() {
|
|
38
|
+
Object.assign(form, { name: '', scopes: [], organization_id: '', expiry: '' })
|
|
39
|
+
showCreate.value = true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function submitCreate() {
|
|
43
|
+
if (!form.name.trim() || !form.scopes.length) return
|
|
44
|
+
try {
|
|
45
|
+
const res = await create.mutateAsync({
|
|
46
|
+
name: form.name.trim(),
|
|
47
|
+
scopes: form.scopes,
|
|
48
|
+
organization_id: form.organization_id === '' ? null : form.organization_id,
|
|
49
|
+
expires_at: expiryFromPreset(form.expiry),
|
|
50
|
+
})
|
|
51
|
+
showCreate.value = false
|
|
52
|
+
revealSecret(res.secret, 'API key creada')
|
|
53
|
+
} catch (e: any) {
|
|
54
|
+
toast.error(errorMessage(e, 'No se pudo crear la API key.'))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ── Secret shown once ───────────────────────────────────────────────────────
|
|
59
|
+
const secret = ref<{ value: string; title: string; note?: string } | null>(null)
|
|
60
|
+
function revealSecret(value: string, title: string, note?: string) {
|
|
61
|
+
secret.value = { value, title, note }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── Rotate / revoke ─────────────────────────────────────────────────────────
|
|
65
|
+
async function doRotate(k: ApiKey) {
|
|
66
|
+
const ok = await confirm({
|
|
67
|
+
severity: 'warning',
|
|
68
|
+
title: 'Rotar API key',
|
|
69
|
+
message: `Se generará una clave nueva para "${k.name}". La actual seguirá funcionando 24 horas para que alcances a reemplazarla en tu integración.`,
|
|
70
|
+
confirmText: 'Rotar',
|
|
71
|
+
})
|
|
72
|
+
if (!ok) return
|
|
73
|
+
try {
|
|
74
|
+
const res = await rotate.mutateAsync(k.id)
|
|
75
|
+
if (detail.value?.id === k.id) detail.value = null
|
|
76
|
+
revealSecret(res.secret, 'Nueva API key',
|
|
77
|
+
res.previous?.expires_at ? `La clave anterior deja de funcionar ${relativeTime(res.previous.expires_at)} (${formatDateTime(res.previous.expires_at)}).` : undefined)
|
|
78
|
+
} catch (e: any) {
|
|
79
|
+
toast.error(errorMessage(e, 'No se pudo rotar la API key.'))
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function doRevoke(k: ApiKey) {
|
|
84
|
+
const ok = await confirm({
|
|
85
|
+
severity: 'danger',
|
|
86
|
+
title: 'Revocar API key',
|
|
87
|
+
message: `"${k.name}" dejará de funcionar de inmediato. Esta acción no se puede deshacer.`,
|
|
88
|
+
confirmText: 'Revocar',
|
|
89
|
+
})
|
|
90
|
+
if (!ok) return
|
|
91
|
+
try {
|
|
92
|
+
await revoke.mutateAsync(k.id)
|
|
93
|
+
if (detail.value?.id === k.id) detail.value = null
|
|
94
|
+
toast.success('API key revocada.')
|
|
95
|
+
} catch (e: any) {
|
|
96
|
+
toast.error(errorMessage(e, 'No se pudo revocar la API key.'))
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── Detail + request log ────────────────────────────────────────────────────
|
|
101
|
+
const detail = ref<ApiKey | null>(null)
|
|
102
|
+
const log = reactive({ items: [] as any[], cursor: null as string | null, loading: false, loaded: false })
|
|
103
|
+
|
|
104
|
+
async function openDetail(k: ApiKey) {
|
|
105
|
+
detail.value = k
|
|
106
|
+
Object.assign(log, { items: [], cursor: null, loading: false, loaded: false })
|
|
107
|
+
await loadMore()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function loadMore() {
|
|
111
|
+
if (!detail.value || log.loading) return
|
|
112
|
+
log.loading = true
|
|
113
|
+
try {
|
|
114
|
+
const res = await requests(detail.value.id, log.cursor)
|
|
115
|
+
log.items = appendPage(log.items, res?.data ?? [])
|
|
116
|
+
log.cursor = res?.meta?.next_cursor ?? null
|
|
117
|
+
} catch {
|
|
118
|
+
toast.error('No se pudo cargar el registro de uso.')
|
|
119
|
+
} finally {
|
|
120
|
+
log.loading = false
|
|
121
|
+
log.loaded = true
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const showDetail = computed({ get: () => detail.value !== null, set: (v) => { if (!v) detail.value = null } })
|
|
126
|
+
const showSecret = computed({ get: () => secret.value !== null, set: (v) => { if (!v) secret.value = null } })
|
|
127
|
+
const inputClass = 'w-full h-9 rounded-control border border-card-line bg-card text-sm text-foreground px-3 focus:outline-hidden focus:ring-2 focus:ring-primary/30'
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<template>
|
|
131
|
+
<div class="space-y-4">
|
|
132
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
133
|
+
<p class="flex-1 text-sm text-muted-foreground">
|
|
134
|
+
Las API keys permiten que sistemas externos consulten y operen este espacio. Cada clave tiene permisos (scopes) acotados.
|
|
135
|
+
</p>
|
|
136
|
+
<a v-if="developersUrl" :href="developersUrl" target="_blank" rel="noopener" class="inline-flex items-center gap-1 text-sm text-primary hover:underline">
|
|
137
|
+
<IconBook class="size-4" :stroke-width="1.75" /> Documentación de la API
|
|
138
|
+
</a>
|
|
139
|
+
<App.Button v-if="canManage" text="Nueva API key" severity="primary" size="sm" :icon="IconPlus" @click="openCreate" />
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<div class="bg-card border border-card-line rounded-card overflow-hidden">
|
|
143
|
+
<div v-if="list.isPending.value" class="p-8 text-center text-sm text-muted-foreground">Cargando…</div>
|
|
144
|
+
<div v-else-if="list.isError.value" class="p-8 text-center text-sm text-muted-foreground">
|
|
145
|
+
No se pudieron cargar las API keys.
|
|
146
|
+
<button type="button" class="text-primary hover:underline" @click="list.refetch()">Reintentar</button>
|
|
147
|
+
</div>
|
|
148
|
+
<div v-else-if="!keys.length" class="p-8 text-center text-sm text-muted-foreground">
|
|
149
|
+
<IconKey class="size-6 mx-auto mb-2 text-muted-foreground" :stroke-width="1.5" />
|
|
150
|
+
Aún no hay API keys.
|
|
151
|
+
</div>
|
|
152
|
+
<ul v-else class="divide-y divide-card-line">
|
|
153
|
+
<li v-for="k in keys" :key="k.id" class="flex flex-wrap items-center gap-3 px-5 py-3">
|
|
154
|
+
<button type="button" class="flex-1 min-w-0 text-left" @click="openDetail(k)">
|
|
155
|
+
<p class="text-sm font-medium text-foreground flex items-center gap-2">
|
|
156
|
+
{{ k.name }}
|
|
157
|
+
<App.Tag :text="apiKeyStatus(k.status).label" :severity="apiKeyStatus(k.status).severity" size="xs" />
|
|
158
|
+
</p>
|
|
159
|
+
<p class="text-xs text-muted-foreground font-mono">{{ k.prefix }}{{ k.hint ? ` ${k.hint}` : '' }}</p>
|
|
160
|
+
<p class="text-xs text-muted-foreground">
|
|
161
|
+
{{ k.scopes.length }} {{ k.scopes.length === 1 ? 'permiso' : 'permisos' }}
|
|
162
|
+
<template v-if="k.organization_id"> · Sede {{ orgLabel(k.organization_id) }}</template>
|
|
163
|
+
· {{ expiryLabel(k.expires_at) }}
|
|
164
|
+
· Último uso {{ k.last_used_at ? relativeTime(k.last_used_at) : 'nunca' }}
|
|
165
|
+
</p>
|
|
166
|
+
</button>
|
|
167
|
+
<div v-if="canManage && (k.status === 'active' || k.status === 'expiring')" class="flex gap-2">
|
|
168
|
+
<App.Button text="Rotar" size="xs" :icon="IconRefresh" @click="doRotate(k)" />
|
|
169
|
+
<App.Button text="Revocar" size="xs" severity="danger" outline :icon="IconBan" @click="doRevoke(k)" />
|
|
170
|
+
</div>
|
|
171
|
+
</li>
|
|
172
|
+
</ul>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
<!-- Create -->
|
|
176
|
+
<Modal v-model="showCreate" title="Nueva API key" size="lg" show-footer>
|
|
177
|
+
<form class="space-y-4" @submit.prevent="submitCreate">
|
|
178
|
+
<label class="block space-y-1">
|
|
179
|
+
<span class="text-sm font-medium text-foreground">Nombre</span>
|
|
180
|
+
<input v-model="form.name" type="text" maxlength="100" placeholder="Ej: ERP, Panel de reportes" :class="inputClass" />
|
|
181
|
+
</label>
|
|
182
|
+
|
|
183
|
+
<label v-if="organizations.length" class="block space-y-1">
|
|
184
|
+
<span class="text-sm font-medium text-foreground">Sede</span>
|
|
185
|
+
<select v-model="form.organization_id" :class="inputClass">
|
|
186
|
+
<option value="">Todas las sedes</option>
|
|
187
|
+
<option v-for="o in organizations" :key="o.value" :value="o.value">{{ o.label }}</option>
|
|
188
|
+
</select>
|
|
189
|
+
<span class="text-xs text-muted-foreground">Limita la clave a los datos de una sede.</span>
|
|
190
|
+
</label>
|
|
191
|
+
|
|
192
|
+
<label class="block space-y-1">
|
|
193
|
+
<span class="text-sm font-medium text-foreground">Vencimiento</span>
|
|
194
|
+
<select v-model="form.expiry" :class="inputClass">
|
|
195
|
+
<option v-for="p in EXPIRY_PRESETS" :key="p.value" :value="p.value">{{ p.label }}</option>
|
|
196
|
+
</select>
|
|
197
|
+
</label>
|
|
198
|
+
|
|
199
|
+
<div class="space-y-2">
|
|
200
|
+
<span class="text-sm font-medium text-foreground">Permisos</span>
|
|
201
|
+
<div v-if="scopes.isPending.value" class="text-sm text-muted-foreground">Cargando permisos…</div>
|
|
202
|
+
<div v-else class="border border-card-line rounded-card divide-y divide-card-line">
|
|
203
|
+
<div v-for="g in scopeGroups" :key="g.group" class="px-4 py-2">
|
|
204
|
+
<p class="text-xs font-semibold uppercase text-muted-foreground mb-1">{{ g.group }}</p>
|
|
205
|
+
<label v-for="s in g.items" :key="s.key" class="flex items-start gap-2 py-1">
|
|
206
|
+
<input
|
|
207
|
+
type="checkbox"
|
|
208
|
+
class="mt-0.5 size-4 rounded border-card-line text-primary focus:ring-primary/30"
|
|
209
|
+
:checked="form.scopes.includes(s.key)"
|
|
210
|
+
@change="form.scopes = toggleValue(form.scopes, s.key, ($event.target as HTMLInputElement).checked)"
|
|
211
|
+
/>
|
|
212
|
+
<span class="text-sm">
|
|
213
|
+
<code class="text-xs font-mono text-foreground">{{ s.key }}</code>
|
|
214
|
+
<span v-if="s.description" class="block text-xs text-muted-foreground">{{ s.description }}</span>
|
|
215
|
+
</span>
|
|
216
|
+
</label>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
</form>
|
|
221
|
+
<template #footer>
|
|
222
|
+
<div class="flex justify-end gap-2">
|
|
223
|
+
<App.Button text="Cancelar" size="sm" @click="showCreate = false" />
|
|
224
|
+
<App.Button text="Crear API key" severity="primary" size="sm" :disabled="!form.name.trim() || !form.scopes.length" :loading="create.isPending.value" @click="submitCreate" />
|
|
225
|
+
</div>
|
|
226
|
+
</template>
|
|
227
|
+
</Modal>
|
|
228
|
+
|
|
229
|
+
<!-- Secret (once) -->
|
|
230
|
+
<Modal v-model="showSecret" :title="secret?.title ?? ''" size="lg" show-footer :backdrop-dismiss="false">
|
|
231
|
+
<div v-if="secret" class="space-y-3">
|
|
232
|
+
<div class="flex items-start gap-2 rounded-card border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-100">
|
|
233
|
+
<IconAlertTriangle class="size-5 shrink-0 text-amber-500" :stroke-width="1.75" />
|
|
234
|
+
<span>Copia la clave ahora: <strong>no se volverá a mostrar</strong>. Guárdala en un lugar seguro (gestor de secretos).</span>
|
|
235
|
+
</div>
|
|
236
|
+
<div class="flex items-center gap-2 rounded-control border border-card-line bg-muted/30 px-3 py-2">
|
|
237
|
+
<code class="flex-1 break-all text-sm font-mono text-foreground">{{ secret.value }}</code>
|
|
238
|
+
<CopyButton :value="secret.value" />
|
|
239
|
+
</div>
|
|
240
|
+
<p v-if="secret.note" class="text-xs text-muted-foreground">{{ secret.note }}</p>
|
|
241
|
+
<p class="text-xs text-muted-foreground">Úsala en el header <code class="font-mono">Authorization: Bearer <clave></code>.</p>
|
|
242
|
+
</div>
|
|
243
|
+
<template #footer>
|
|
244
|
+
<div class="flex justify-end">
|
|
245
|
+
<App.Button text="Ya la copié" severity="primary" size="sm" @click="secret = null" />
|
|
246
|
+
</div>
|
|
247
|
+
</template>
|
|
248
|
+
</Modal>
|
|
249
|
+
|
|
250
|
+
<!-- Detail -->
|
|
251
|
+
<Modal v-model="showDetail" :title="detail?.name ?? ''" size="3xl" variant="drawer-right">
|
|
252
|
+
<div v-if="detail" class="space-y-5">
|
|
253
|
+
<dl class="grid grid-cols-2 gap-3 text-sm">
|
|
254
|
+
<div><dt class="text-xs text-muted-foreground">Estado</dt><dd><App.Tag :text="apiKeyStatus(detail.status).label" :severity="apiKeyStatus(detail.status).severity" size="xs" /></dd></div>
|
|
255
|
+
<div><dt class="text-xs text-muted-foreground">Clave</dt><dd class="font-mono">{{ detail.prefix }} {{ detail.hint }}</dd></div>
|
|
256
|
+
<div><dt class="text-xs text-muted-foreground">Vencimiento</dt><dd>{{ expiryLabel(detail.expires_at) }}</dd></div>
|
|
257
|
+
<div><dt class="text-xs text-muted-foreground">Último uso</dt><dd>{{ formatDateTime(detail.last_used_at) }}<span v-if="detail.last_used_ip" class="text-muted-foreground"> · {{ detail.last_used_ip }}</span></dd></div>
|
|
258
|
+
<div v-if="detail.organization_id"><dt class="text-xs text-muted-foreground">Sede</dt><dd>{{ orgLabel(detail.organization_id) }}</dd></div>
|
|
259
|
+
<div><dt class="text-xs text-muted-foreground">Creada</dt><dd>{{ formatDateTime(detail.created_at) }}</dd></div>
|
|
260
|
+
<div class="col-span-2">
|
|
261
|
+
<dt class="text-xs text-muted-foreground mb-1">Permisos</dt>
|
|
262
|
+
<dd class="flex flex-wrap gap-1"><code v-for="s in detail.scopes" :key="s" class="text-xs font-mono rounded bg-muted px-1.5 py-0.5">{{ s }}</code></dd>
|
|
263
|
+
</div>
|
|
264
|
+
</dl>
|
|
265
|
+
|
|
266
|
+
<div v-if="canManage && (detail.status === 'active' || detail.status === 'expiring')" class="flex gap-2">
|
|
267
|
+
<App.Button text="Rotar" size="xs" :icon="IconRefresh" @click="doRotate(detail)" />
|
|
268
|
+
<App.Button text="Revocar" size="xs" severity="danger" outline :icon="IconBan" @click="doRevoke(detail)" />
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<div>
|
|
272
|
+
<p class="text-sm font-semibold text-foreground mb-2">Registro de uso (30 días)</p>
|
|
273
|
+
<div class="border border-card-line rounded-card overflow-hidden">
|
|
274
|
+
<div v-if="log.loaded && !log.items.length" class="p-6 text-center text-sm text-muted-foreground">Sin solicitudes registradas.</div>
|
|
275
|
+
<table v-else class="w-full text-sm">
|
|
276
|
+
<thead class="bg-muted/30 text-xs text-muted-foreground">
|
|
277
|
+
<tr><th class="text-left px-3 py-2">Fecha</th><th class="text-left px-3 py-2">Solicitud</th><th class="text-left px-3 py-2">Estado</th><th class="text-right px-3 py-2">ms</th></tr>
|
|
278
|
+
</thead>
|
|
279
|
+
<tbody class="divide-y divide-card-line">
|
|
280
|
+
<tr v-for="r in log.items" :key="r.id">
|
|
281
|
+
<td class="px-3 py-2 whitespace-nowrap text-muted-foreground">{{ formatDateTime(r.created_at) }}</td>
|
|
282
|
+
<td class="px-3 py-2 font-mono text-xs break-all">{{ r.method }} {{ r.path }}</td>
|
|
283
|
+
<td class="px-3 py-2"><App.Tag :text="String(r.status)" :severity="httpSeverity(r.status)" size="xs" /></td>
|
|
284
|
+
<td class="px-3 py-2 text-right text-muted-foreground">{{ r.duration_ms ?? '—' }}</td>
|
|
285
|
+
</tr>
|
|
286
|
+
</tbody>
|
|
287
|
+
</table>
|
|
288
|
+
</div>
|
|
289
|
+
<div class="mt-2 flex justify-center">
|
|
290
|
+
<App.Button v-if="log.cursor" text="Cargar más" size="xs" :loading="log.loading" @click="loadMore" />
|
|
291
|
+
<span v-else-if="log.loading" class="text-xs text-muted-foreground">Cargando…</span>
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
</Modal>
|
|
296
|
+
</div>
|
|
297
|
+
</template>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/*
|
|
3
|
+
* Integrations.Developers — interactive API reference (OpenAPI 3.1 + webhook events) rendered with
|
|
4
|
+
* Scalar, loaded client-side from the pinned CDN build (jsdelivr, allowlisted).
|
|
5
|
+
* Backend: \Innertia\PublicApi\Routes::docs() serves GET v1/openapi.json.
|
|
6
|
+
*
|
|
7
|
+
* <Integrations.Developers :spec-url="`${apiBase}/v1/openapi.json`" />
|
|
8
|
+
*/
|
|
9
|
+
const props = defineProps<{ specUrl: string }>()
|
|
10
|
+
|
|
11
|
+
const SCALAR_SRC = 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.76.4/dist/browser/standalone.js'
|
|
12
|
+
|
|
13
|
+
const el = ref<HTMLElement | null>(null)
|
|
14
|
+
const state = ref<'loading' | 'ready' | 'error'>('loading')
|
|
15
|
+
let app: any = null
|
|
16
|
+
|
|
17
|
+
function loadScript(): Promise<void> {
|
|
18
|
+
const w = window as any
|
|
19
|
+
if (w.Scalar?.createApiReference) return Promise.resolve()
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
let script = document.querySelector<HTMLScriptElement>(`script[src="${SCALAR_SRC}"]`)
|
|
22
|
+
if (!script) {
|
|
23
|
+
script = document.createElement('script')
|
|
24
|
+
script.src = SCALAR_SRC
|
|
25
|
+
script.async = true
|
|
26
|
+
document.head.appendChild(script)
|
|
27
|
+
}
|
|
28
|
+
script.addEventListener('load', () => resolve(), { once: true })
|
|
29
|
+
script.addEventListener('error', () => reject(new Error('scalar')), { once: true })
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function mount() {
|
|
34
|
+
if (!el.value) return
|
|
35
|
+
state.value = 'loading'
|
|
36
|
+
try {
|
|
37
|
+
await loadScript()
|
|
38
|
+
app?.destroy?.()
|
|
39
|
+
app = (window as any).Scalar.createApiReference(el.value, { url: props.specUrl, hideClientButton: false })
|
|
40
|
+
state.value = 'ready'
|
|
41
|
+
} catch {
|
|
42
|
+
state.value = 'error'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onMounted(mount)
|
|
47
|
+
watch(() => props.specUrl, mount)
|
|
48
|
+
onBeforeUnmount(() => { app?.destroy?.(); app = null })
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div class="relative min-h-[60vh]">
|
|
53
|
+
<div v-if="state === 'loading'" class="p-8 text-center text-sm text-muted-foreground">Cargando documentación…</div>
|
|
54
|
+
<div v-else-if="state === 'error'" class="p-8 text-center text-sm text-muted-foreground">
|
|
55
|
+
No se pudo cargar el visor de la documentación.
|
|
56
|
+
<a :href="specUrl" target="_blank" rel="noopener" class="text-primary hover:underline">Descargar openapi.json</a>
|
|
57
|
+
</div>
|
|
58
|
+
<div ref="el" />
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|