1+ import { z } from 'zod/v4' ;
12import type {
23 CountSuccess ,
34 GetV1RoutingConfigurationsCountData ,
@@ -16,12 +17,27 @@ import { ErrorCase } from './types/error-cases';
1617import { catchAxiosError , createAxiosClient } from './axios-client' ;
1718import { Result } from './types/result' ;
1819import { OpenApiToTemplate } from './types/open-api-helper' ;
19- import { z } from 'zod' ;
20-
21- const uuidSchema = z . uuidv4 ( ) ;
2220
2321export const httpClient = createAxiosClient ( ) ;
2422
23+ function parseId ( id : string ) : Result < string > {
24+ const { success, data } = z . uuidv4 ( ) . safeParse ( id ) ;
25+
26+ if ( ! success ) {
27+ return {
28+ error : {
29+ errorMeta : {
30+ code : ErrorCase . VALIDATION_FAILED ,
31+ description : 'Invalid routing configuration ID format' ,
32+ details : { id } ,
33+ } ,
34+ } ,
35+ } ;
36+ }
37+
38+ return { data } ;
39+ }
40+
2541export const routingConfigurationApiClient = {
2642 async create (
2743 routingConfig : CreateUpdateRoutingConfig ,
@@ -75,17 +91,10 @@ export const routingConfigurationApiClient = {
7591 token : string ,
7692 id : RoutingConfig [ 'id' ]
7793 ) : Promise < Result < RoutingConfig > > {
78- if ( ! uuidSchema . safeParse ( id ) . success ) {
79- return {
80- error : {
81- errorMeta : {
82- code : ErrorCase . VALIDATION_FAILED ,
83- description : 'Invalid routing configuration ID format' ,
84- details : { id } ,
85- } ,
86- actualError : undefined ,
87- } ,
88- } ;
94+ const parseResult = parseId ( id ) ;
95+
96+ if ( parseResult . error ) {
97+ return parseResult ;
8998 }
9099
91100 const url = `/v1/routing-configuration/${ id } ` satisfies OpenApiToTemplate <
@@ -127,18 +136,12 @@ export const routingConfigurationApiClient = {
127136 id : RoutingConfig [ 'id' ] ,
128137 routingConfig : CreateUpdateRoutingConfig
129138 ) : Promise < Result < RoutingConfig > > {
130- if ( ! uuidSchema . safeParse ( id ) . success ) {
131- return {
132- error : {
133- errorMeta : {
134- code : ErrorCase . VALIDATION_FAILED ,
135- description : 'Invalid routing configuration ID format' ,
136- details : { id } ,
137- } ,
138- actualError : undefined ,
139- } ,
140- } ;
139+ const parseResult = parseId ( id ) ;
140+
141+ if ( parseResult . error ) {
142+ return parseResult ;
141143 }
144+
142145 const url = `/v1/routing-configuration/${ id } ` satisfies OpenApiToTemplate <
143146 PutV1RoutingConfigurationByRoutingConfigIdData [ 'url' ]
144147 > ;
@@ -157,21 +160,27 @@ export const routingConfigurationApiClient = {
157160 } ,
158161
159162 async submit ( id : string , token : string ) : Promise < Result < RoutingConfig > > {
163+ const parseResult = parseId ( id ) ;
164+
165+ if ( parseResult . error ) {
166+ return parseResult ;
167+ }
168+
160169 const url =
161170 `/v1/routing-configuration/${ id } /submit` satisfies OpenApiToTemplate <
162171 PatchV1RoutingConfigurationByRoutingConfigIdSubmitData [ 'url' ]
163172 > ;
164173
165- const result = await catchAxiosError (
174+ const { error , data } = await catchAxiosError (
166175 httpClient . patch < RoutingConfigSuccess > ( url , null , {
167176 headers : { Authorization : token } ,
168177 } )
169178 ) ;
170179
171- if ( result . error ) {
172- return result ;
180+ if ( error ) {
181+ return { error } ;
173182 }
174183
175- return result . data ;
184+ return { ... data } ;
176185 } ,
177186} ;
0 commit comments