diff --git a/src/service.ts b/src/service.ts index d97b232..38dd0b6 100644 --- a/src/service.ts +++ b/src/service.ts @@ -264,8 +264,6 @@ export class Service { })); } - - /** * Get relay statistics from RelayManager. * @returns Statistics about connected relays @@ -703,6 +701,48 @@ export class Service { } } + public async getProcessesData(filteredProcesses: Record): Promise> { + const data: Record = {}; + // Now we decrypt all we can in the processes + for (const [processId, process] of Object.entries(filteredProcesses)) { + console.log('process roles:', this.getRoles(process)); + // We also take the public data + const lastState = this.getLastCommitedState(process); + if (!lastState) { + console.error(`❌ Process ${processId} doesn't have a commited state`); + continue; + } + const processData: Record = {}; + for (const attribute of Object.keys(lastState.public_data)) { + try { + const value = this.decodeValue(lastState.public_data[attribute]); + if (value) { + processData[attribute] = value; + } + } catch (e) { + console.error(`❌ Error decoding public data ${attribute} for process ${processId}:`, e); + } + } + for (let i = process.states.length - 2; i >= 0; i--) { + const state = process.states[i]; + for (const attribute of Object.keys(state.keys)) { + if (processData[attribute] !== undefined && processData[attribute] !== null) continue; + try { + const value = await this.decryptAttribute(processId, state, attribute); + if (value) { + processData[attribute] = value; + } + } catch (e) { + console.error(`❌ Error decrypting attribute ${attribute} for process ${processId}:`, e); + } + } + } + data[processId] = processData; + } + + return data; + } + // Utility method: Get Process async getProcess(processId: string): Promise { // First check in-memory cache diff --git a/src/simple-server.ts b/src/simple-server.ts index 8614e5a..beca766 100644 --- a/src/simple-server.ts +++ b/src/simple-server.ts @@ -279,42 +279,7 @@ class SimpleProcessHandlers { } } - const data: Record = {}; - // Now we decrypt all we can in the processes - for (const [processId, process] of Object.entries(filteredProcesses)) { - // We also take the public data - const lastState = this.service.getLastCommitedState(process); - if (!lastState) { - console.error(`❌ Process ${processId} doesn't have a commited state`); - continue; - } - const processData: Record = {}; - for (const attribute of Object.keys(lastState.public_data)) { - try { - const value = this.service.decodeValue(lastState.public_data[attribute]); - if (value) { - processData[attribute] = value; - } - } catch (e) { - console.error(`❌ Error decoding public data ${attribute} for process ${processId}:`, e); - } - } - for (let i = process.states.length - 2; i >= 0; i--) { - const state = process.states[i]; - for (const attribute of Object.keys(state.keys)) { - if (processData[attribute] !== undefined && processData[attribute] !== null) continue; - try { - const value = await this.service.decryptAttribute(processId, state, attribute); - if (value) { - processData[attribute] = value; - } - } catch (e) { - console.error(`❌ Error decrypting attribute ${attribute} for process ${processId}:`, e); - } - } - } - data[processId] = processData; - } + const data = await this.service.getProcessesData(filteredProcesses); return { type: MessageType.PROCESSES_RETRIEVED,