feat: préparer l'intégration dans 4NK_node - nouvelle branche 4nk-node-integration depuis dev - modifications router.ts pour l'intégration conteneur
This commit is contained in:
parent
19da967605
commit
484b5ea250
@ -1,5 +1,5 @@
|
||||
import '../public/style/4nk.css';
|
||||
import { initHeader } from '../src/components/header/header';
|
||||
import { initHeader } from './components/header/header';
|
||||
/*import { initChat } from '../src/pages/chat/chat';*/
|
||||
import Database from './services/database.service';
|
||||
import Services from './services/service';
|
||||
@ -148,7 +148,7 @@ export async function init(): Promise<void> {
|
||||
} else {
|
||||
services.restoreDevice(device);
|
||||
}
|
||||
|
||||
|
||||
// If we create a new device, we most probably don't have anything in db, but just in case
|
||||
await services.restoreProcessesFromDB();
|
||||
await services.restoreSecretsFromDB();
|
||||
@ -178,10 +178,10 @@ export async function registerAllListeners() {
|
||||
const services = await Services.getInstance();
|
||||
const tokenService = await TokenService.getInstance();
|
||||
|
||||
const errorResponse = (errorMsg: string, origin: string, messageId?: string) => {
|
||||
const errorResponse = (errorMsg: string, origin: string, messageId?: string) => {
|
||||
window.parent.postMessage(
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
{
|
||||
type: MessageType.ERROR,
|
||||
error: errorMsg,
|
||||
messageId
|
||||
},
|
||||
@ -215,9 +215,9 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
try {
|
||||
const tokens = await tokenService.generateSessionToken(event.origin);
|
||||
const tokens = await tokenService.generateSessionToken(event.origin);
|
||||
const acceptedMsg = {
|
||||
type: MessageType.LINK_ACCEPTED,
|
||||
type: MessageType.LINK_ACCEPTED,
|
||||
accessToken: tokens.accessToken,
|
||||
refreshToken: tokens.refreshToken,
|
||||
messageId: event.data.messageId
|
||||
@ -259,7 +259,7 @@ export async function registerAllListeners() {
|
||||
if (!pairingId) {
|
||||
throw new Error('Failed to get pairing process id');
|
||||
}
|
||||
|
||||
|
||||
// Send success response
|
||||
const successMsg = {
|
||||
type: MessageType.PAIRING_CREATED,
|
||||
@ -292,9 +292,9 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
const myProcesses = await services.getMyProcesses();
|
||||
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.GET_MY_PROCESSES,
|
||||
myProcesses,
|
||||
messageId: event.data.messageId
|
||||
@ -305,8 +305,8 @@ export async function registerAllListeners() {
|
||||
const errorMsg = `Failed to get processes: ${e}`;
|
||||
errorResponse(errorMsg, event.origin, event.data.messageId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const handleGetProcesses = async (event: MessageEvent) => {
|
||||
if (event.data.type !== MessageType.GET_PROCESSES) {
|
||||
return;
|
||||
@ -329,9 +329,9 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
const processes = await services.getProcesses();
|
||||
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.PROCESSES_RETRIEVED,
|
||||
processes,
|
||||
messageId: event.data.messageId
|
||||
@ -342,7 +342,7 @@ export async function registerAllListeners() {
|
||||
const errorMsg = `Failed to get processes: ${e}`;
|
||||
errorResponse(errorMsg, event.origin, event.data.messageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// We got a state for some process and return as many clear attributes as we can
|
||||
const handleDecryptState = async (event: MessageEvent) => {
|
||||
@ -388,7 +388,7 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.DATA_RETRIEVED,
|
||||
data: res,
|
||||
messageId: event.data.messageId
|
||||
@ -430,23 +430,23 @@ export async function registerAllListeners() {
|
||||
if (event.data.type !== MessageType.RENEW_TOKEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const refreshToken = event.data.refreshToken;
|
||||
|
||||
|
||||
if (!refreshToken) {
|
||||
throw new Error('No refresh token provided');
|
||||
}
|
||||
|
||||
|
||||
const newAccessToken = await tokenService.refreshAccessToken(refreshToken, event.origin);
|
||||
|
||||
|
||||
if (!newAccessToken) {
|
||||
throw new Error('Failed to refresh token');
|
||||
}
|
||||
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
type: MessageType.RENEW_TOKEN,
|
||||
{
|
||||
type: MessageType.RENEW_TOKEN,
|
||||
accessToken: newAccessToken,
|
||||
refreshToken: refreshToken,
|
||||
messageId: event.data.messageId
|
||||
@ -476,9 +476,9 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
const userPairingId = services.getPairingProcessId();
|
||||
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.GET_PAIRING_ID,
|
||||
userPairingId,
|
||||
messageId: event.data.messageId
|
||||
@ -525,7 +525,7 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.PROCESS_CREATED,
|
||||
processCreated: res,
|
||||
messageId: event.data.messageId
|
||||
@ -562,7 +562,7 @@ export async function registerAllListeners() {
|
||||
await services.handleApiReturn(res);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.UPDATE_NOTIFIED,
|
||||
messageId: event.data.messageId
|
||||
},
|
||||
@ -594,7 +594,7 @@ export async function registerAllListeners() {
|
||||
await services.handleApiReturn(res);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.STATE_VALIDATED,
|
||||
validatedProcess: res.updated_process,
|
||||
messageId: event.data.messageId
|
||||
@ -606,7 +606,7 @@ export async function registerAllListeners() {
|
||||
errorResponse(errorMsg, event.origin, event.data.messageId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const handleUpdateProcess = async (event: MessageEvent) => {
|
||||
if (event.data.type !== MessageType.UPDATE_PROCESS) return;
|
||||
|
||||
@ -698,12 +698,12 @@ export async function registerAllListeners() {
|
||||
}
|
||||
|
||||
// We'll let the wasm check if roles are consistent
|
||||
|
||||
|
||||
const res = await services.updateProcess(process, privateData, publicData, roles);
|
||||
await services.handleApiReturn(res);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.PROCESS_UPDATED,
|
||||
updatedProcess: res.updated_process,
|
||||
messageId: event.data.messageId
|
||||
@ -731,11 +731,11 @@ export async function registerAllListeners() {
|
||||
if (!accessToken || !(await tokenService.validateToken(accessToken, event.origin))) {
|
||||
throw new Error('Invalid or expired session token');
|
||||
}
|
||||
|
||||
|
||||
const decodedData = services.decodeValue(encodedData);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.PUBLIC_DATA_DECODED,
|
||||
decodedData,
|
||||
messageId: event.data.messageId
|
||||
@ -759,11 +759,11 @@ export async function registerAllListeners() {
|
||||
if (!accessToken || !(await tokenService.validateToken(accessToken, event.origin))) {
|
||||
throw new Error('Invalid or expired session token');
|
||||
}
|
||||
|
||||
|
||||
const hash = services.getHashForFile(commitedIn, label, fileBlob);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.VALUE_HASHED,
|
||||
hash,
|
||||
messageId: event.data.messageId
|
||||
@ -789,7 +789,7 @@ export async function registerAllListeners() {
|
||||
const proof = services.getMerkleProofForFile(processState, attributeName);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.MERKLE_PROOF_RETRIEVED,
|
||||
proof,
|
||||
messageId: event.data.messageId
|
||||
@ -824,7 +824,7 @@ export async function registerAllListeners() {
|
||||
const res = services.validateMerkleProof(parsedMerkleProof, documentHash);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
{
|
||||
type: MessageType.MERKLE_PROOF_VALIDATED,
|
||||
isValid: res,
|
||||
messageId: event.data.messageId
|
||||
@ -934,9 +934,9 @@ document.addEventListener('navigate', ((e: Event) => {
|
||||
if (event.detail.page === 'chat') {
|
||||
const container = document.querySelector('.container');
|
||||
if (container) container.innerHTML = '';
|
||||
|
||||
|
||||
//initChat();
|
||||
|
||||
|
||||
const chatElement = document.querySelector('chat-element');
|
||||
if (chatElement) {
|
||||
chatElement.setAttribute('process-id', event.detail.processId || '');
|
||||
|
Loading…
x
Reference in New Issue
Block a user