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