11import type { AxiosError } from "axios" ;
22
33import { client } from "@app/axios-config/apiInit" ;
4- import { getApiV1ArtifactsImage , type _Error , type ImageMetadataResponse } from "@app/client" ;
4+ import {
5+ getApiV1ArtifactsImage ,
6+ type PostApiV1ArtifactsVerifyResponse ,
7+ type _Error ,
8+ type ImageMetadataResponse ,
9+ postApiV1ArtifactsVerify ,
10+ type VerifyArtifactRequest ,
11+ } from "@app/client" ;
512import { useMockableQuery } from "./helpers" ;
613import { artifactsImageDataMock } from "./mocks/artifacts.mock" ;
14+ import { useMutation , useQueryClient } from "@tanstack/react-query" ;
715
8- export const ArtifactsKey = "Artifacts" ;
16+ export const ArtifactsKeys = {
17+ all : [ "Artifacts" as const ] ,
18+ image : ( uri : string ) => [ "Artifacts" , "image" , uri ] as const ,
19+ verify : ( id : string | number ) => [ "Artifacts" , "verify" , id ] as const ,
20+ } ;
21+
22+ // transitional payload while backend/types evolve
23+ interface VerifyArtifactDraft {
24+ uri : string ;
25+ expectedSAN ?: string ; // optional for now
26+ [ k : string ] : unknown ;
27+ }
928
1029export const useFetchArtifactsImageData = ( { uri } : { uri : string | null | undefined } ) => {
1130 const enabled = typeof uri === "string" && uri . trim ( ) . length > 0 ;
1231 const { data, isLoading, error, refetch } = useMockableQuery < ImageMetadataResponse | null , AxiosError < _Error > > (
1332 {
14- queryKey : [ ArtifactsKey , " image" , uri ?? "" ] ,
33+ queryKey : ArtifactsKeys . image ( uri ?? "" ) ,
1534 queryFn : async ( ) => {
1635 const response = await getApiV1ArtifactsImage ( { client, query : { uri : uri ! } } ) ;
1736 return response . data ?? null ;
@@ -25,3 +44,30 @@ export const useFetchArtifactsImageData = ({ uri }: { uri: string | null | undef
2544
2645 return { artifact : data , isFetching : isLoading , fetchError : error , refetch } ;
2746} ;
47+
48+ export const useVerifyArtifact = ( ) => {
49+ const queryClient = useQueryClient ( ) ;
50+ return useMutation < PostApiV1ArtifactsVerifyResponse | null , AxiosError < _Error > , VerifyArtifactDraft > ( {
51+ mutationFn : async ( draft ) => {
52+ // if the backend/types aren't ready (e.g., missing SAN), return a mock/null
53+ if ( ! draft . expectedSAN ) {
54+ return null ;
55+ }
56+
57+ // map the draft payload into the SDK body shape. Include only fields we know.
58+ const res = await postApiV1ArtifactsVerify ( {
59+ client,
60+ body : {
61+ // the SDK requires `expectedSAN` (string | null); ensure it exists when we reach here
62+ expectedSAN : draft . expectedSAN ?? null ,
63+ // use `ociImage` for the artifact reference (since `uri` isn't in the SDK type)
64+ ociImage : draft . uri ,
65+ } as VerifyArtifactRequest ,
66+ } ) ;
67+ return res . data ?? null ;
68+ } ,
69+ onSuccess : ( ) => {
70+ void queryClient . invalidateQueries ( { queryKey : ArtifactsKeys . all } ) ;
71+ } ,
72+ } ) ;
73+ } ;
0 commit comments