reports
This commit is contained in:
parent
d272ae0bd3
commit
ff01efe4bb
17 changed files with 1378 additions and 21 deletions
|
|
@ -493,6 +493,7 @@ export type AgentMessageSendResponse = {
|
|||
template: string
|
||||
to: string
|
||||
customer_name: string
|
||||
report_group: string
|
||||
report_id: string
|
||||
report_url: string | null
|
||||
wa_message_id: string | null
|
||||
|
|
@ -511,7 +512,7 @@ export const agentTemplatesApi = {
|
|||
jsonRequest<{ template: string; allowed: boolean; retry_after?: string | null; last_tested_at?: string | null }>(
|
||||
`/api/v1/agent-templates/${slug}/test-status`,
|
||||
),
|
||||
test: (slug: string, payload: { to: string; customer_name: string; report_id?: string }) =>
|
||||
test: (slug: string, payload: { to: string; customer_name: string; report_group: string; report_id?: string }) =>
|
||||
jsonRequest<AgentMessageSendResponse>(`/api/v1/agent-templates/${slug}/test`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
|
|
@ -522,7 +523,7 @@ export const agentMessagesApi = {
|
|||
docs: () => jsonRequest<AgentMessageApiDoc>('/api/v1/agent/messages/docs/send'),
|
||||
send: (
|
||||
apiKey: string,
|
||||
payload: { template: string; to: string; customer_name: string; report_id?: string },
|
||||
payload: { template: string; to: string; customer_name: string; report_group: string; report_id?: string },
|
||||
) =>
|
||||
fetch(`${API_BASE_URL}/api/v1/agent/messages/send`, {
|
||||
method: 'POST',
|
||||
|
|
@ -540,6 +541,119 @@ export const agentMessagesApi = {
|
|||
}),
|
||||
}
|
||||
|
||||
export type UrmiportGroup = {
|
||||
id: string
|
||||
report_group: string
|
||||
display_name: string | null
|
||||
default_access: 'public' | 'password'
|
||||
password_protected: boolean
|
||||
id_mode: 'auto' | 'manual'
|
||||
report_count: number
|
||||
url_pattern: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type UrmiportReport = {
|
||||
id: string
|
||||
report_group: string
|
||||
report_id: string
|
||||
access: 'public' | 'password'
|
||||
password_protected: boolean
|
||||
url: string
|
||||
updated_at: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type UrmiportApiDoc = {
|
||||
id: string
|
||||
method: string
|
||||
path: string
|
||||
title: string
|
||||
summary: string
|
||||
authentication: {
|
||||
type: string
|
||||
header: string
|
||||
format: string
|
||||
alternate_header?: string
|
||||
}
|
||||
request_body: Record<string, {
|
||||
type: string
|
||||
required: boolean
|
||||
description: string
|
||||
example?: string
|
||||
}>
|
||||
responses: Record<string, { description: string; example?: Record<string, unknown> }>
|
||||
notes?: string[]
|
||||
}
|
||||
|
||||
export type UrmiportPublishResponse = UrmiportReport & { success: boolean }
|
||||
|
||||
export const urmiportApi = {
|
||||
docs: () => jsonRequest<UrmiportApiDoc>('/api/v1/urmiport/docs'),
|
||||
listGroups: () => jsonRequest<UrmiportGroup[]>('/api/v1/urmiport/groups'),
|
||||
createGroup: (payload: {
|
||||
report_group: string
|
||||
display_name?: string
|
||||
default_access: 'public' | 'password'
|
||||
password?: string
|
||||
id_mode: 'auto' | 'manual'
|
||||
}) => jsonRequest<UrmiportGroup>('/api/v1/urmiport/groups', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
listReports: (slug: string) => jsonRequest<UrmiportReport[]>(`/api/v1/urmiport/groups/${slug}/reports`),
|
||||
viewReport: (group: string, reportId: string) =>
|
||||
fetch(`${API_BASE_URL}/api/v1/urmiport/view/${group}/${reportId}`).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => null)
|
||||
throw new Error(typeof body?.detail === 'string' ? body.detail : 'Report not found')
|
||||
}
|
||||
return response.json() as Promise<{
|
||||
report_group: string
|
||||
report_id: string
|
||||
access: string
|
||||
requires_password: boolean
|
||||
html: string | null
|
||||
}>
|
||||
}),
|
||||
unlockReport: (group: string, reportId: string, password: string) =>
|
||||
fetch(`${API_BASE_URL}/api/v1/urmiport/view/${group}/${reportId}/unlock`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password }),
|
||||
}).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => null)
|
||||
throw new Error(typeof body?.detail === 'string' ? body.detail : 'Unable to unlock report')
|
||||
}
|
||||
return response.json() as Promise<{ html: string }>
|
||||
}),
|
||||
publish: (
|
||||
apiKey: string,
|
||||
payload: {
|
||||
report_group: string
|
||||
report_id?: string
|
||||
body: string
|
||||
access?: 'public' | 'password'
|
||||
password?: string
|
||||
},
|
||||
) =>
|
||||
fetch(`${API_BASE_URL}/api/v1/urmiport/reports`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
}).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => null)
|
||||
throw new Error(typeof body?.detail === 'string' ? body.detail : 'Request failed')
|
||||
}
|
||||
return response.json() as Promise<UrmiportPublishResponse>
|
||||
}),
|
||||
}
|
||||
|
||||
export const urmiOtpApi = {
|
||||
listProjects: () => jsonRequest<UrmiOtpProject[]>('/api/v1/urmiotp/projects'),
|
||||
createProject: (payload: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue