var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { http } from "../../utils/http.js"; import getMajorSemver from 'semver/functions/major.js'; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated // so if you are changing anything about them change the `update_bee` action accordingly! export const SUPPORTED_BEE_VERSION_EXACT = '1.6.0-6ceadd35'; export const SUPPORTED_API_VERSION = '3.0.1'; export const SUPPORTED_DEBUG_API_VERSION = '2.0.1'; export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-')); const NODE_INFO_URL = 'node'; const HEALTH_URL = 'health'; /** * Get health of node * * @param ky Ky debug instance */ export function getHealth(ky) { return __awaiter(this, void 0, void 0, function* () { const response = yield http(ky, { method: 'get', path: HEALTH_URL, responseType: 'json' }); return response.data; }); } /** * Get information about Bee node * * @param ky Ky debug instance */ export function getNodeInfo(ky) { return __awaiter(this, void 0, void 0, function* () { const response = yield http(ky, { method: 'get', path: NODE_INFO_URL, responseType: 'json' }); return response.data; }); } /** * Connects to a node and checks if it is a supported Bee version by the bee-js * * @param ky Ky debug instance * * @returns true if the Bee node version is supported * @deprecated Use `isSupportedExactVersion` instead */ export function isSupportedVersion(ky) { return __awaiter(this, void 0, void 0, function* () { return isSupportedExactVersion(ky); }); } /** * Connects to a node and checks if its version matches with the one that bee-js supports. * * Be aware that this is the most strict version check and most probably * you will want to use more relaxed API-versions based checks like * `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion` * based on your use-case. * * @param ky */ export function isSupportedExactVersion(ky) { return __awaiter(this, void 0, void 0, function* () { const { version } = yield getHealth(ky); return version === SUPPORTED_BEE_VERSION_EXACT; }); } /** * Connects to a node and checks if its main's API version matches with the one that bee-js supports. * * This is useful if you are not using `BeeDebug` class (for anything else then this check) * and want to make sure about compatibility. * * @param ky */ export function isSupportedMainApiVersion(ky) { return __awaiter(this, void 0, void 0, function* () { const { apiVersion } = yield getHealth(ky); return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION); }); } /** * Connects to a node and checks if its Debug API version matches with the one that bee-js supports. * * This is useful if you are not using `Bee` class in your application and want to make sure * about compatibility. * * @param ky */ export function isSupportedDebugApiVersion(ky) { return __awaiter(this, void 0, void 0, function* () { const { debugApiVersion } = yield getHealth(ky); return getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION); }); } /** * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports. * * This should be the main way how to check compatibility for your app and Bee node. * * @param ky */ export function isSupportedApiVersion(ky) { return __awaiter(this, void 0, void 0, function* () { const { apiVersion, debugApiVersion } = yield getHealth(ky); return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) && getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION); }); } /** * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`) * and versions that bee-js supports (properties prefixed with `supported*`). * * @param ky */ export function getVersions(ky) { return __awaiter(this, void 0, void 0, function* () { const { version, apiVersion, debugApiVersion } = yield getHealth(ky); return { supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT, supportedBeeApiVersion: SUPPORTED_API_VERSION, supportedBeeDebugApiVersion: SUPPORTED_DEBUG_API_VERSION, beeVersion: version, beeApiVersion: apiVersion, beeDebugApiVersion: debugApiVersion }; }); }