11import { acceptHMRUpdate , defineStore , storeToRefs } from "pinia" ;
2- import { computed , reactive , ref , watch } from "vue" ;
2+ import { computed , reactive , Ref , ref , watch } from "vue" ;
33import Header from "@/resources/Header" ;
44import type EndpointDetails from "@/resources/EndpointDetails" ;
55import { FailedMessage , ExceptionDetails , FailedMessageStatus } from "@/resources/FailedMessage" ;
@@ -11,6 +11,9 @@ import xmlFormat from "xml-formatter";
1111import { DataContainer } from "./DataContainer" ;
1212import { useServiceControlStore } from "./ServiceControlStore" ;
1313import { EditAndRetryConfig } from "@/resources/Configuration" ;
14+ import EditRetryResponse from "@/resources/EditRetryResponse" ;
15+ import { EditedMessage } from "@/resources/EditMessage" ;
16+ import useEnvironmentAndVersionsAutoRefresh from "@/composables/useEnvironmentAndVersionsAutoRefresh" ;
1417
1518interface Model {
1619 id ?: string ;
@@ -65,12 +68,15 @@ export const useMessageStore = defineStore("MessageStore", () => {
6568 const edit_and_retry_config = ref < EditAndRetryConfig > ( { enabled : false , locked_headers : [ ] , sensitive_headers : [ ] } ) ;
6669 const conversationData = ref < DataContainer < Message [ ] > > ( { data : [ ] } ) ;
6770
71+ const editRetryResponse = ref < EditRetryResponse | null > ( null ) ;
6872 let bodyLoadedId = "" ;
6973 let conversationLoadedId = "" ;
7074
7175 const configStore = useConfigurationStore ( ) ;
7276 const serviceControlStore = useServiceControlStore ( ) ;
7377 const { serviceControlUrl } = storeToRefs ( serviceControlStore ) ;
78+ const { store : environmentStore } = useEnvironmentAndVersionsAutoRefresh ( ) ;
79+ const areSimpleHeadersSupported = environmentStore . serviceControlIsGreaterThan ( "5.2.0" ) ;
7480
7581 const { configuration } = storeToRefs ( configStore ) ;
7682 const error_retention_period = computed ( ( ) => moment . duration ( configuration . value ?. data_retention ?. error_retention_period ) . asHours ( ) ) ;
@@ -89,6 +95,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
8995 bodyLoadedId = "" ;
9096 conversationLoadedId = "" ;
9197 conversationData . value . data = [ ] ;
98+ editRetryResponse . value = null ;
9299 }
93100
94101 async function loadFailedMessage ( id : string ) {
@@ -267,6 +274,36 @@ export const useMessageStore = defineStore("MessageStore", () => {
267274 }
268275 }
269276
277+ async function retryEditedMessage ( id : string , editedMessage : Ref < EditedMessage > ) {
278+ const payload = {
279+ message_body : editedMessage . value . messageBody ,
280+ message_headers : areSimpleHeadersSupported . value
281+ ? editedMessage . value . headers . reduce (
282+ ( result , header ) => {
283+ const { key, value } = header as { key : string ; value : string } ;
284+ result [ key ] = value ;
285+ return result ;
286+ } ,
287+ { } as { [ key : string ] : string }
288+ )
289+ : editedMessage . value . headers ,
290+ } ;
291+ const response = await serviceControlStore . postToServiceControl ( `edit/${ id } ` , payload ) ;
292+ if ( ! response . ok ) {
293+ throw new Error ( response . statusText ) ;
294+ }
295+
296+ //older versions of SC return no payload about the edit result
297+ const bodyText = await response . text ( ) ;
298+ if ( bodyText === "" ) {
299+ editRetryResponse . value = {
300+ edit_ignored : false ,
301+ } ;
302+ } else {
303+ editRetryResponse . value = parse ( bodyText ) as EditRetryResponse ;
304+ }
305+ }
306+
270307 async function pollForNextUpdate ( status : FailedMessageStatus ) {
271308 if ( ! state . data . id ) {
272309 return ;
@@ -326,6 +363,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
326363 body,
327364 state,
328365 edit_and_retry_config,
366+ editRetryResponse,
329367 reset,
330368 loadMessage,
331369 loadFailedMessage,
@@ -338,6 +376,7 @@ export const useMessageStore = defineStore("MessageStore", () => {
338376 retryMessages,
339377 conversationData,
340378 pollForNextUpdate,
379+ retryEditedMessage,
341380 } ;
342381} ) ;
343382
0 commit comments