|
1 | 1 | import { |
2 | 2 | AuthorizationRequestStateStatus, |
3 | | - AuthorizationResponseStateStatus, |
| 3 | + AuthorizationResponseStateStatus, AuthStatusResponse, AuthStatusResponsePayload, |
4 | 4 | CallbackOpts, |
5 | 5 | CallbackOptsPayload, |
6 | 6 | CreateAuthorizationRequest, |
7 | 7 | CreateAuthorizationRequestPayload, |
8 | 8 | CreateAuthorizationResponse, |
9 | 9 | CreateAuthorizationResponsePayload, |
10 | 10 | QRCodeOpts, |
11 | | - QRCodeOptsPayload, |
| 11 | + QRCodeOptsPayload, RequestError, RequestErrorPayload, |
12 | 12 | RequestUriMethod, |
13 | 13 | ResponseMode, |
14 | 14 | ResponseType, |
@@ -196,3 +196,78 @@ export const createAuthorizationResponseToPayload = (internal: CreateAuthorizati |
196 | 196 | qr_uri: parsed.qrUri |
197 | 197 | } |
198 | 198 | } |
| 199 | + |
| 200 | + |
| 201 | +export const RequestErrorSchema = z.object({ |
| 202 | + status: z.number(), |
| 203 | + message: z.string(), |
| 204 | + errorDetails: z.string().optional() |
| 205 | +}) |
| 206 | + |
| 207 | +export const AuthStatusResponseSchema = z.object({ |
| 208 | + status: AuthorizationStatusSchema, |
| 209 | + correlationId: z.string(), |
| 210 | + queryId: z.string(), |
| 211 | + lastUpdated: z.number(), |
| 212 | + verifiedData: z.any().optional(), // Replace with actual VerifiedDataSchema when available |
| 213 | + error: RequestErrorSchema.optional() |
| 214 | +}) |
| 215 | + |
| 216 | + |
| 217 | +export const RequestErrorPayloadSchema = z.object({ |
| 218 | + status: z.number(), |
| 219 | + message: z.string(), |
| 220 | + error_details: z.string().optional() |
| 221 | +}) |
| 222 | + |
| 223 | +export const AuthStatusResponsePayloadSchema = z.object({ |
| 224 | + status: AuthorizationStatusSchema, |
| 225 | + correlation_id: z.string(), |
| 226 | + query_id: z.string(), |
| 227 | + last_updated: z.number(), |
| 228 | + verified_data: z.any().optional(), // Replace with actual VerifiedDataSchema when available |
| 229 | + error: RequestErrorPayloadSchema.optional() |
| 230 | +}) |
| 231 | + |
| 232 | + |
| 233 | +export const requestErrorFromPayload = (payload: RequestError): RequestError => { |
| 234 | + const parsed = RequestErrorPayloadSchema.parse(payload) |
| 235 | + return { |
| 236 | + status: parsed.status, |
| 237 | + message: parsed.message, |
| 238 | + errorDetails: parsed.error_details |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +export const requestErrorToPayload = (internal: RequestError): RequestErrorPayload => { |
| 243 | + const parsed = RequestErrorSchema.parse(internal) |
| 244 | + return { |
| 245 | + status: parsed.status, |
| 246 | + message: parsed.message, |
| 247 | + error_details: parsed.errorDetails |
| 248 | + } |
| 249 | +} |
| 250 | + |
| 251 | +export const authStatusResponseFromPayload = (payload: AuthStatusResponse): AuthStatusResponse => { |
| 252 | + const parsed = AuthStatusResponsePayloadSchema.parse(payload) |
| 253 | + return { |
| 254 | + status: parsed.status, |
| 255 | + correlationId: parsed.correlation_id, |
| 256 | + queryId: parsed.query_id, |
| 257 | + lastUpdated: parsed.last_updated, |
| 258 | + verifiedData: parsed.verified_data, |
| 259 | + error: parsed.error ? requestErrorFromPayload(parsed.error) : undefined |
| 260 | + } |
| 261 | +} |
| 262 | + |
| 263 | +export const authStatusResponseToPayload = (internal: AuthStatusResponse): AuthStatusResponsePayload => { |
| 264 | + const parsed = AuthStatusResponseSchema.parse(internal) |
| 265 | + return { |
| 266 | + status: parsed.status, |
| 267 | + correlation_id: parsed.correlationId, |
| 268 | + query_id: parsed.queryId, |
| 269 | + last_updated: parsed.lastUpdated, |
| 270 | + verified_data: parsed.verifiedData, |
| 271 | + error: parsed.error ? requestErrorToPayload(parsed.error) : undefined |
| 272 | + } |
| 273 | +} |
0 commit comments