import { showError, showInfo } from '../../utils/logger.util' import fetch from 'node-fetch' import { NodeTypeValue } from '../../models/choice' type CreateCertificationResponse = { code: string data: { id: string publicKey: string createdAt: string } } type CertificationRequestProps = { clusterManagerURL: string publicKey: string nodeAddress: string email: string nodeType: NodeTypeValue countryISOCode: string clusterId: number } export async function notifyAboutNewNode({ clusterManagerURL, publicKey, nodeAddress, email, nodeType, countryISOCode, clusterId, }: CertificationRequestProps): Promise { showInfo(`Notify clusterManager about new node. Address: ${nodeAddress}. Use public key: ${publicKey}`) try { const response = await fetch(`${clusterManagerURL}/certification`, { method: 'POST', body: JSON.stringify({ publicKey: publicKey, url: nodeAddress, email: email, nodeType: nodeType, nodeCountryISOCode: countryISOCode, clusterId, }), headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, }) const result = (await response.json()) as CreateCertificationResponse if (result.code !== 'SUCCESS') { showError(`Error! code: ${result.code}`) } else { showInfo(`Certification created. Id: ${result.data.id}`) } } catch (error) { showError(`Error while create certification: ${error}`) } }