diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index de50b852..c51a72e6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,8 +9,8 @@ on: - '**' env: - BEE_VERSION: '1.4.1-238867f1-stateful' - BLOCKCHAIN_VERSION: '1.2.0-for-1.4.1-238867f1-stateful' + BEE_VERSION: '1.4.3-1213e063-stateful' + BLOCKCHAIN_VERSION: '1.2.0-for-1.4.3-1213e063-stateful' BEE_ENV_PREFIX: 'swarm-test' BEE_IMAGE_PREFIX: 'docker.pkg.github.com/ethersphere/bee-factory' COMMIT_VERSION_TAG: 'false' diff --git a/.github/workflows/update_bee.yaml b/.github/workflows/update_bee.yaml index 2d2613aa..ff062117 100644 --- a/.github/workflows/update_bee.yaml +++ b/.github/workflows/update_bee.yaml @@ -6,6 +6,12 @@ on: beeFactoryImageVersion: description: 'Bee Factory image version (eq. 1.3.0-fd09d1c4-stateful)' required: true + beeApiVersion: + description: 'Bee API version (eq. 1.3.0)' + required: true + beeDebugApiVersion: + description: 'Bee Debug API version (eq. 1.3.0)' + required: true repository_dispatch: types: [update-bee] @@ -23,14 +29,20 @@ jobs: run: | if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then image_version="${{ github.event.client_payload.imageVersion }}" + bee_api_version="${{ github.event.client_payload.apiVersion }}" + bee_debug_api_version="${{ github.event.client_payload.debugApiVersion }}" else image_version="${{ github.event.inputs.beeFactoryImageVersion }}" + bee_api_version="${{ github.event.inputs.beeApiVersion }}" + bee_debug_api_version="${{ github.event.inputs.beeDebugApiVersion }}" fi bee_version=${image_version/-stateful} echo "IMAGE_VERSION=$image_version" >> $GITHUB_ENV echo "BEE_VERSION=$bee_version" >> $GITHUB_ENV echo "TARGET_BRANCH=${bee_version/-rc*}" >> $GITHUB_ENV + echo "API_VERSION=$bee_api_version" >> $GITHUB_ENV + echo "DEBUG_API_VERSION=$bee_debug_api_version" >> $GITHUB_ENV - name: Replace Engine in package.json uses: jossef/action-set-json-field@v1 @@ -39,22 +51,52 @@ jobs: field: engines.bee value: ${{ env.BEE_VERSION }} - - name: Replace BEE_VERSION for CI - uses: jacobtomlinson/gha-find-replace@v2 + - name: Replace API version in package.json + uses: jossef/action-set-json-field@v1 with: - find: "BEE_VERSION: '.*?'" - replace: "BEE_VERSION: '${{ env.IMAGE_VERSION }}'" - include: ".github/workflows/tests.yaml" - regex: true + file: package.json + field: engines.beeApiVersion + value: ${{ env.API_VERSION }} + + - name: Replace Debug API version in package.json + uses: jossef/action-set-json-field@v1 + with: + file: package.json + field: engines.beeDebugApiVersion + value: ${{ env.DEBUG_API_VERSION }} - name: Replace SUPPORTED_BEE_VERSION_EXACT for Status module uses: jacobtomlinson/gha-find-replace@v2 with: find: "export const SUPPORTED_BEE_VERSION_EXACT = '.*?'" - replace: "export const SUPPORTED_BEE_VERSION_EXACT = '${{ env.IMAGE_VERSION }}'" + replace: "export const SUPPORTED_BEE_VERSION_EXACT = '${{ env.BEE_VERSION }}'" + include: "src/modules/debug/status.ts" + regex: true + + - name: Replace SUPPORTED_API_VERSION for Status module + uses: jacobtomlinson/gha-find-replace@v2 + with: + find: "export const SUPPORTED_API_VERSION = '.*?'" + replace: "export const SUPPORTED_API_VERSION = '${{ env.API_VERSION }}'" + include: "src/modules/debug/status.ts" + regex: true + + - name: Replace SUPPORTED_DEBUG_API_VERSION for Status module + uses: jacobtomlinson/gha-find-replace@v2 + with: + find: "export const SUPPORTED_DEBUG_API_VERSION = '.*?'" + replace: "export const SUPPORTED_DEBUG_API_VERSION = '${{ env.DEBUG_API_VERSION }}'" include: "src/modules/debug/status.ts" regex: true + - name: Replace BEE_VERSION for CI + uses: jacobtomlinson/gha-find-replace@v2 + with: + find: "BEE_VERSION: '.*?'" + replace: "BEE_VERSION: '${{ env.IMAGE_VERSION }}'" + include: ".github/workflows/tests.yaml" + regex: true + - name: Replace BLOCKCHAIN_VERSION for CI uses: jacobtomlinson/gha-find-replace@v2 with: diff --git a/package-lock.json b/package-lock.json index e0213732..5c5a7707 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "ky": "^0.25.1", "ky-universal": "^0.8.2", "readable-stream": "^3.6.0", + "semver": "^7.3.5", "tar-js": "^0.3.0", "utf-8-validate": "^5.0.8", "web-streams-polyfill": "^3.1.0", @@ -43,6 +44,7 @@ "@types/jest-environment-puppeteer": "^4.4.1", "@types/node": "^15.12.4", "@types/puppeteer": "^5.4.3", + "@types/semver": "^7.3.9", "@types/ws": "^7.4.5", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", @@ -129,6 +131,15 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/core/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/generator": { "version": "7.16.8", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.16.8.tgz", @@ -186,6 +197,15 @@ "@babel/core": "^7.0.0" } }, + "node_modules/@babel/helper-compilation-targets/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/helper-create-class-features-plugin": { "version": "7.16.10", "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.16.10.tgz", @@ -242,6 +262,15 @@ "@babel/core": "^7.4.0-0" } }, + "node_modules/@babel/helper-define-polyfill-provider/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/helper-environment-visitor": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.16.7.tgz", @@ -1422,6 +1451,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-runtime/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/plugin-transform-shorthand-properties": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.16.7.tgz", @@ -1692,6 +1730,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/preset-env/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/preset-modules": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/@babel/preset-modules/-/preset-modules-0.1.5.tgz", @@ -1945,39 +1992,6 @@ "node": ">=v10" } }, - "node_modules/@commitlint/is-ignored/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@commitlint/is-ignored/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@commitlint/is-ignored/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/@commitlint/lint": { "version": "12.1.1", "resolved": "https://registry.npmjs.org/@commitlint/lint/-/lint-12.1.1.tgz", @@ -4112,6 +4126,12 @@ "safe-buffer": "*" } }, + "node_modules/@types/semver": { + "version": "7.3.9", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.9.tgz", + "integrity": "sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ==", + "dev": true + }, "node_modules/@types/stack-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz", @@ -4185,39 +4205,6 @@ } } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/@typescript-eslint/experimental-utils": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.10.0.tgz", @@ -4347,39 +4334,6 @@ } } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/@typescript-eslint/utils": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.10.0.tgz", @@ -5133,6 +5087,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/babel-plugin-polyfill-corejs3": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.2.3.tgz", @@ -6007,39 +5970,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/depcheck/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/depcheck/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/depcheck/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/deps-regex": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deps-regex/-/deps-regex-0.1.4.tgz", @@ -8237,6 +8167,15 @@ "node": ">=8" } }, + "node_modules/istanbul-lib-instrument/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/istanbul-lib-report": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", @@ -11422,18 +11361,6 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" } }, - "node_modules/jest-snapshot/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/jest-snapshot/node_modules/pretty-format": { "version": "27.5.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.0.tgz", @@ -11460,21 +11387,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/jest-snapshot/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/jest-snapshot/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -11487,12 +11399,6 @@ "node": ">=8" } }, - "node_modules/jest-snapshot/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/jest-util": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-26.6.2.tgz", @@ -12332,6 +12238,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -12750,39 +12665,6 @@ "node": ">=10" } }, - "node_modules/normalize-package-data/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/normalize-package-data/node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/normalize-package-data/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -14037,12 +13919,17 @@ } }, "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true, + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, "bin": { "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/semver-compare": { @@ -14051,6 +13938,22 @@ "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", "dev": true }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", @@ -15818,6 +15721,14 @@ "json5": "^2.1.2", "semver": "^6.3.0", "source-map": "^0.5.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/generator": { @@ -15860,6 +15771,14 @@ "@babel/helper-validator-option": "^7.16.7", "browserslist": "^4.17.5", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/helper-create-class-features-plugin": { @@ -15901,6 +15820,14 @@ "lodash.debounce": "^4.0.8", "resolve": "^1.14.2", "semver": "^6.1.2" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/helper-environment-visitor": { @@ -16694,6 +16621,14 @@ "babel-plugin-polyfill-corejs3": "^0.2.2", "babel-plugin-polyfill-regenerator": "^0.2.2", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "@babel/plugin-transform-shorthand-properties": { @@ -16899,6 +16834,12 @@ "requires": { "@babel/helper-define-polyfill-provider": "^0.3.1" } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true } } }, @@ -17092,32 +17033,6 @@ "requires": { "@commitlint/types": "^12.1.1", "semver": "7.3.5" - }, - "dependencies": { - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } } }, "@commitlint/lint": { @@ -18827,6 +18742,12 @@ "safe-buffer": "*" } }, + "@types/semver": { + "version": "7.3.9", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.9.tgz", + "integrity": "sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ==", + "dev": true + }, "@types/stack-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.0.tgz", @@ -18882,32 +18803,6 @@ "regexpp": "^3.2.0", "semver": "^7.3.5", "tsutils": "^3.21.0" - }, - "dependencies": { - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } } }, "@typescript-eslint/experimental-utils": { @@ -18971,32 +18866,6 @@ "is-glob": "^4.0.3", "semver": "^7.3.5", "tsutils": "^3.21.0" - }, - "dependencies": { - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } } }, "@typescript-eslint/utils": { @@ -19617,6 +19486,14 @@ "@babel/compat-data": "^7.13.11", "@babel/helper-define-polyfill-provider": "^0.2.2", "semver": "^6.1.1" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "babel-plugin-polyfill-corejs3": { @@ -20289,30 +20166,6 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==", "dev": true - }, - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true } } }, @@ -21921,6 +21774,14 @@ "@istanbuljs/schema": "^0.1.2", "istanbul-lib-coverage": "^3.2.0", "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "istanbul-lib-report": { @@ -24395,15 +24256,6 @@ "picomatch": "^2.2.3" } }, - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, "pretty-format": { "version": "27.5.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.0.tgz", @@ -24423,15 +24275,6 @@ } } }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -24440,12 +24283,6 @@ "requires": { "has-flag": "^4.0.0" } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true } } }, @@ -25076,6 +24913,14 @@ "dev": true, "requires": { "semver": "^6.0.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } } }, "make-error": { @@ -25400,32 +25245,6 @@ "resolve": "^1.20.0", "semver": "^7.3.4", "validate-npm-package-license": "^3.0.1" - }, - "dependencies": { - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "requires": { - "yallist": "^4.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - } } }, "normalize-path": { @@ -26347,10 +26166,27 @@ } }, "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } }, "semver-compare": { "version": "1.0.0", diff --git a/package.json b/package.json index 8790e2bf..910f8e6e 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "ky": "^0.25.1", "ky-universal": "^0.8.2", "readable-stream": "^3.6.0", + "semver": "^7.3.5", "tar-js": "^0.3.0", "utf-8-validate": "^5.0.8", "web-streams-polyfill": "^3.1.0", @@ -97,6 +98,7 @@ "@types/jest-environment-puppeteer": "^4.4.1", "@types/node": "^15.12.4", "@types/puppeteer": "^5.4.3", + "@types/semver": "^7.3.9", "@types/ws": "^7.4.5", "@typescript-eslint/eslint-plugin": "^5.10.0", "@typescript-eslint/parser": "^5.10.0", @@ -129,6 +131,8 @@ "engines": { "node": ">=12.0.0", "npm": ">=6.0.0", - "bee": "1.4.1-238867f1" + "beeApiVersion": "2.0.0", + "beeDebugApiVersion": "1.2.1", + "bee": "1.4.3-1213e063" } } diff --git a/src/bee-debug.ts b/src/bee-debug.ts index 78a1b8b0..08f22759 100644 --- a/src/bee-debug.ts +++ b/src/bee-debug.ts @@ -32,6 +32,7 @@ import type { TransactionInfo, TransactionHash, NodeInfo, + BeeVersions, } from './types' import { BeeArgumentError } from './utils/error' import { assertBeeUrl, stripLastSlash } from './utils/url' @@ -384,6 +385,7 @@ export class BeeDebug { * Connnects to a node and checks if it is a supported Bee version by the bee-js * * @returns true if the Bee node version is supported + * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead */ async isSupportedVersion(options?: RequestOptions): Promise | never { assertRequestOptions(options) @@ -391,6 +393,76 @@ export class BeeDebug { return status.isSupportedVersion(this.getKy(options)) } + /** + * 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 + * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()` + * based on your use-case. + * + * @param options + */ + async isSupportedExactVersion(options?: RequestOptions): Promise | never { + assertRequestOptions(options) + + return status.isSupportedExactVersion(this.getKy(options)) + } + + /** + * 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 options + */ + async isSupportedMainApiVersion(options?: RequestOptions): Promise | never { + assertRequestOptions(options) + + return status.isSupportedMainApiVersion(this.getKy(options)) + } + + /** + * 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 options + */ + async isSupportedDebugApiVersion(options?: RequestOptions): Promise | never { + assertRequestOptions(options) + + return status.isSupportedDebugApiVersion(this.getKy(options)) + } + + /** + * + * 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 options + */ + async isSupportedApiVersion(options?: RequestOptions): Promise | never { + assertRequestOptions(options) + + return status.isSupportedDebugApiVersion(this.getKy(options)) + } + + /** + * 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 options + */ + async getVersions(options?: RequestOptions): Promise | never { + assertRequestOptions(options) + + return status.getVersions(this.getKy(options)) + } + /** * Get reserve state */ diff --git a/src/modules/debug/status.ts b/src/modules/debug/status.ts index 0f6931a8..700f16dd 100644 --- a/src/modules/debug/status.ts +++ b/src/modules/debug/status.ts @@ -1,10 +1,15 @@ import { http } from '../../utils/http' import type { Health, NodeInfo } from '../../types/debug' import { Ky } from '../../types' +import { BeeVersions } from '../../types/debug' +import getMajorSemver from 'semver/functions/major' + +// 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.4.3-1213e063' +export const SUPPORTED_API_VERSION = '2.0.0' +export const SUPPORTED_DEBUG_API_VERSION = '1.2.1' -// This line bellow is automatically updated with GitHub Action when Bee version is updated -// so if you are changing anything about it change the `update_bee` action accordingly! -export const SUPPORTED_BEE_VERSION_EXACT = '1.4.1-238867f1' export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-')) const NODE_INFO_URL = 'node' @@ -46,9 +51,87 @@ export async function getNodeInfo(ky: Ky): Promise { * @param ky Ky debug instance * * @returns true if the Bee node version is supported + * @deprecated Use `isSupportedExactVersion` instead */ export async function isSupportedVersion(ky: Ky): Promise { + 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 async function isSupportedExactVersion(ky: Ky): Promise { const { version } = await 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 async function isSupportedMainApiVersion(ky: Ky): Promise { + const { apiVersion } = await 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 async function isSupportedDebugApiVersion(ky: Ky): Promise { + const { debugApiVersion } = await 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 async function isSupportedApiVersion(ky: Ky): Promise { + const { apiVersion, debugApiVersion } = await 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 async function getVersions(ky: Ky): Promise { + const { version, apiVersion, debugApiVersion } = await getHealth(ky) + + return { + supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT, + supportedBeeApiVersion: SUPPORTED_API_VERSION, + supportedBeeDebugApiVersion: SUPPORTED_DEBUG_API_VERSION, + beeVersion: version, + beeApiVersion: apiVersion, + beeDebugApiVersion: debugApiVersion, + } +} diff --git a/src/types/debug.ts b/src/types/debug.ts index 7f1e1513..eba1a6dd 100644 --- a/src/types/debug.ts +++ b/src/types/debug.ts @@ -148,6 +148,15 @@ export interface Health { debugApiVersion: string } +export interface BeeVersions { + supportedBeeVersion: string + supportedBeeApiVersion: string + supportedBeeDebugApiVersion: string + beeVersion: string + beeApiVersion: string + beeDebugApiVersion: string +} + export enum BeeModes { FULL = 'full', LIGHT = 'light', diff --git a/test/integration/modules/debug/status.spec.ts b/test/integration/modules/debug/status.spec.ts index a5d87313..2d38145d 100644 --- a/test/integration/modules/debug/status.spec.ts +++ b/test/integration/modules/debug/status.spec.ts @@ -1,40 +1,20 @@ import { getHealth, + getVersions, + isSupportedApiVersion, + isSupportedDebugApiVersion, + isSupportedExactVersion, + isSupportedMainApiVersion, isSupportedVersion, - SUPPORTED_BEE_VERSION, + SUPPORTED_API_VERSION, SUPPORTED_BEE_VERSION_EXACT, + SUPPORTED_DEBUG_API_VERSION, } from '../../../../src/modules/debug/status' import { beeDebugKy } from '../../../utils' import fs from 'fs' import path from 'path' import * as util from 'util' - -/** - * Matches these: - * 0.5.3-c423a39c, 0.5.3-c423a39c-dirty, 0.5.3, 1.0.0-rc4, 1.0.0-rc4-02dd4346 - */ -const expectValidVersion = (string: string): void => { - const parts = string.split('-') - expect(parts.length).toBeGreaterThanOrEqual(1) - expect(parts.length).toBeLessThanOrEqual(3) - expect(parts[0]).toMatch(/^\d+\.\d+\.\d+$/) - - if (parts[1]) { - if (parts[1].startsWith('rc')) { - expect(parts[1]).toMatch(/^rc\d+$/) - - if (parts[2]) { - expect(parts[2]).toMatch(/^[0-9a-f]{7,8}$/) - } - } else { - expect(parts[1]).toMatch(/^[0-9a-f]{7,8}$/) - - if (parts[2]) { - expect(parts[2]).toBe('dirty') - } - } - } -} +import semver from 'semver' const BEE_DEBUG_URL = beeDebugKy() @@ -44,7 +24,7 @@ describe('modules/status', () => { expect(health.status).toBe('ok') // Matches both versions like 0.5.3-c423a39c, 0.5.3-c423a39c-dirty and 0.5.3 - expectValidVersion(health.version) + expect(semver.valid(health.version)).not.toBeNull() }) test('isSupportedVersion', async () => { @@ -53,18 +33,58 @@ describe('modules/status', () => { expect(isSupported).toBe(true) }) - test('format of supported bee version', () => { - // Matches semantic version e.g. 0.5.3 - expect(SUPPORTED_BEE_VERSION).toMatch(/^\d+\.\d+\.\d+$/i) + test('isSupportedExactVersion', async () => { + const isSupported = await isSupportedExactVersion(BEE_DEBUG_URL) + + expect(isSupported).toBe(true) + }) + + test('isSupportedMainApiVersion', async () => { + const isSupported = await isSupportedMainApiVersion(BEE_DEBUG_URL) + + expect(isSupported).toBe(true) + }) + + test('isSupportedDebugApiVersion', async () => { + const isSupported = await isSupportedDebugApiVersion(BEE_DEBUG_URL) + + expect(isSupported).toBe(true) + }) + + test('isSupportedApiVersion', async () => { + const isSupported = await isSupportedApiVersion(BEE_DEBUG_URL) + + expect(isSupported).toBe(true) + }) + + test('getVersions', async () => { + const versions = await getVersions(BEE_DEBUG_URL) + + expect(versions).toEqual( + expect.objectContaining({ + supportedBeeVersion: expect.any(String), + supportedBeeApiVersion: expect.any(String), + supportedBeeDebugApiVersion: expect.any(String), + beeVersion: expect.any(String), + beeApiVersion: expect.any(String), + beeDebugApiVersion: expect.any(String), + }), + ) - // Matches semantic version with commit message e.g. 0.5.3-acbd0e2 - expectValidVersion(SUPPORTED_BEE_VERSION_EXACT) + expect(semver.valid(versions.beeVersion)).not.toBeNull() + expect(semver.valid(versions.beeApiVersion)).not.toBeNull() + expect(semver.valid(versions.beeDebugApiVersion)).not.toBeNull() + expect(semver.valid(versions.supportedBeeApiVersion)).not.toBeNull() + expect(semver.valid(versions.supportedBeeVersion)).not.toBeNull() + expect(semver.valid(versions.supportedBeeDebugApiVersion)).not.toBeNull() }) - test('SUPPORTED_BEE_VERSION_EXACT should be same as in package.json', async () => { + test('SUPPORTED_BEE_* should be same as in package.json', async () => { const file = await util.promisify(fs.readFile)(path.join(__dirname, '../../../../package.json')) const packageJson = JSON.parse(file.toString()) expect(SUPPORTED_BEE_VERSION_EXACT).toBe(packageJson.engines.bee) + expect(SUPPORTED_API_VERSION).toBe(packageJson.engines.beeApiVersion) + expect(SUPPORTED_DEBUG_API_VERSION).toBe(packageJson.engines.beeDebugApiVersion) }) })