Compare commits

...

4 Commits

Author SHA1 Message Date
Sosthene
7d8c63f52d Add getOfficeProcessByIdnot 2025-09-09 11:14:55 +02:00
Sosthene
31e04da8ab Add getPairingId 2025-09-09 11:14:40 +02:00
Sosthene
7d5861b831 Add getUserProcessByIdNot() 2025-09-07 18:34:25 +02:00
Sosthene
f5bddd992a Add createProcess() 2025-09-07 18:34:07 +02:00

View File

@ -228,7 +228,16 @@ export class SDKSignerClient {
this.on('message', handler);
});
}
async get_owned_processes(): Promise<ServerResponse> {
async getPairingId(): Promise<ServerResponse> {
const message: ClientMessage = {
type: MessageType.GET_PAIRING_ID,
messageId: this.generateMessageId()
};
return this.sendAndWait(message, MessageType.GET_PAIRING_ID);
}
async getOwnedProcesses(): Promise<ServerResponse> {
const message: ClientMessage = {
type: MessageType.GET_MY_PROCESSES,
messageId: this.generateMessageId()
@ -238,6 +247,78 @@ export class SDKSignerClient {
return response;
}
async createProcess(processData: { [label: string]: any }, privateFields: string[], roles: any): Promise<ServerResponse> {
const message: ClientMessage = {
type: MessageType.CREATE_PROCESS,
processData,
privateFields,
roles,
messageId: this.generateMessageId()
};
return this.sendAndWait(message, MessageType.PROCESS_CREATED);
}
// Are we part of user process as a validator?
// User on first connection do have his idnot
// we must check if there's already a process for this user
// if yes, user can add a new device he made the idnot login on
// if not, we create a new process and add it's pairing id
async getUserProcessByIdnot(idNot: string): Promise<{ processId: string, processData: any } | null> {
console.log('Getting user process by idnot:', idNot);
try {
const signerResponse: ServerResponse = await this.getOwnedProcesses();
// We are interested in the data
const processesData: any = signerResponse.data;
for (const [processId, processData] of Object.entries(processesData)) {
if (processData
&& typeof processData === 'object'
&& 'utype' in processData
&& 'idNot' in processData
&& 'office' in processData
&& 'contact' in processData
&& 'office_role' in processData
&& 'role' in processData
&& (processData as any).utype === 'collaborator'
&& (processData as any).office
&& (processData as any).office.idNot
&& (processData as any).idNot === idNot
) {
console.log('Found matching process:', processId);
return { processId, processData };
}
}
return null;
} catch (error) {
console.error('Error getting user process by idnot:', error);
throw error;
}
}
async getOfficeProcessByIdnot(idNot: string): Promise<{ processId: string, processData: any } | null> {
console.log('Getting office process by idnot:', idNot);
try {
const signerResponse: ServerResponse = await this.getOwnedProcesses();
// We are interested in the data
const processesData: any = signerResponse.data;
for (const [processId, processData] of Object.entries(processesData)) {
if (processData
&& typeof processData === 'object'
&& 'utype' in processData
&& 'idNot' in processData
&& (processData as any).utype === 'office'
&& (processData as any).idNot === idNot
) {
console.log('Found matching process:', processId);
return { processId, processData };
}
}
return null;
} catch (error) {
console.error('Error getting user process by idnot:', error);
throw error;
}
}
/**
* Notify an update for a process