diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 961cb471..182afa41 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -59,50 +59,3 @@ jobs: - name: Tests non-Node 18 if: matrix.node-version != '18.x' run: npm run test - - - name: Debug workflow if failed - if: failure() - run: | - KEYS=$(curl -sSf -X POST https://relay.tunshell.com/api/sessions) - curl -sSf -X POST -H "Content-Type: application/json" -d "{\"text\": \"**Bee JS**\nDebug -> \`sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com\`\"}" https://beehive.ethswarm.org/hooks/${{ secrets.WEBHOOK_KEY }} - echo "Connect to github actions node using" - echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com" - curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com - -# browser: -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# node-version: [16.x] -# -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# fetch-depth: 1 -# -# - name: Use Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v3 -# with: -# node-version: ${{ matrix.node-version }} -# cache: 'npm' -# -# - name: Install npm deps -# run: npm ci -# -# # Start Bee Factory environment -# - name: Start Bee Factory environment -# run: npm run bee -- --detach -# -# - name: Run browser tests -# run: npm run test:browser -# -# - name: Debug workflow if failed -# if: failure() -# run: | -# KEYS=$(curl -sSf -X POST https://relay.tunshell.com/api/sessions) -# curl -sSf -X POST -H "Content-Type: application/json" -d "{\"text\": \"**Bee JS**\nDebug -> \`sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com\`\"}" https://beehive.ethswarm.org/hooks/${{ secrets.WEBHOOK_KEY }} -# echo "Connect to github actions node using" -# echo "sh <(curl -sSf https://lets.tunshell.com/init.sh) L $(echo $KEYS | jq -r .peer2_key) \${TUNSHELL_SECRET} relay.tunshell.com" -# curl -sSf https://lets.tunshell.com/init.sh | sh /dev/stdin T $(echo $KEYS | jq -r .peer1_key) ${{ secrets.TUNSHELL_SECRET }} relay.tunshell.com diff --git a/package-lock.json b/package-lock.json index 297776f9..ae5a8ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,13 +6,13 @@ "packages": { "": { "name": "@ethersphere/bee-js", - "version": "5.2.0", + "version": "6.0.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", "axios": "^1.3.4", - "cafe-utility": "^9.0.1", + "cafe-utility": "^10.8.1", "elliptic": "^6.5.4", "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", @@ -3727,9 +3727,9 @@ "license": "MIT" }, "node_modules/cafe-utility": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-9.0.1.tgz", - "integrity": "sha512-QiTaoRPkK8UyBBsGwv4zJRM88JibhcQ2GRHsLYTq+JaKIK6UyW1xSOlerJWAFHS/r/SpXffCQxlNIeiOA7MgCQ==" + "version": "10.8.1", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-10.8.1.tgz", + "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==" }, "node_modules/call-bind": { "version": "1.0.2", diff --git a/package.json b/package.json index 5c8761dd..cd9142b9 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", "axios": "^1.3.4", - "cafe-utility": "^9.0.1", + "cafe-utility": "^10.8.1", "elliptic": "^6.5.4", "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", diff --git a/src/bee-debug.ts b/src/bee-debug.ts index ddd724d9..c5c5284f 100644 --- a/src/bee-debug.ts +++ b/src/bee-debug.ts @@ -86,20 +86,13 @@ export class BeeDebug { // unnecessary redirects. this.url = stripLastSlash(url) - const requestOptions: BeeRequestOptions = { + this.requestOptions = { baseURL: this.url, timeout: options?.timeout ?? false, + headers: options?.headers, + onRequest: options?.onRequest, + adapter: options?.adapter, } - - if (options?.headers) { - requestOptions.headers = options.headers - } - - if (options?.onRequest) { - requestOptions.onRequest = options.onRequest - } - - this.requestOptions = requestOptions } async getNodeAddresses(options?: BeeRequestOptions): Promise { diff --git a/src/bee.ts b/src/bee.ts index a0f8be2a..9e847d6d 100644 --- a/src/bee.ts +++ b/src/bee.ts @@ -6,7 +6,7 @@ import { Index, IndexBytes, makeFeedReader, makeFeedWriter } from './feed' import { getJsonData, setJsonData } from './feed/json' import { areAllSequentialFeedsUpdateRetrievable } from './feed/retrievable' import { makeTopic, makeTopicFromString } from './feed/topic' -import { assertFeedType, DEFAULT_FEED_TYPE, FeedType } from './feed/type' +import { DEFAULT_FEED_TYPE, FeedType, assertFeedType } from './feed/type' import * as bytes from './modules/bytes' import * as bzz from './modules/bzz' import * as chunk from './modules/chunk' @@ -34,9 +34,9 @@ import type { PssSubscription, PublicKey, Reference, - Signer, SOCReader, SOCWriter, + Signer, Tag, Topic, UploadOptions, @@ -120,20 +120,13 @@ export class Bee { this.signer = makeSigner(options.signer) } - const requestOptions: BeeRequestOptions = { + this.requestOptions = { baseURL: this.url, timeout: options?.timeout ?? false, + headers: options?.headers, + onRequest: options?.onRequest, + adapter: options?.adapter, } - - if (options?.headers) { - requestOptions.headers = options.headers - } - - if (options?.onRequest) { - requestOptions.onRequest = options.onRequest - } - - this.requestOptions = requestOptions } /** diff --git a/src/modules/bytes.ts b/src/modules/bytes.ts index 078dd6c2..3c210788 100644 --- a/src/modules/bytes.ts +++ b/src/modules/bytes.ts @@ -34,7 +34,7 @@ export async function upload( return { reference: response.data.reference, - tagUid: makeTagUid(response.headers['swarm-tag']), + tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined, } } diff --git a/src/modules/bzz.ts b/src/modules/bzz.ts index 3098b396..87102cac 100644 --- a/src/modules/bzz.ts +++ b/src/modules/bzz.ts @@ -71,7 +71,7 @@ export async function uploadFile( return { reference: response.data.reference, - tagUid: makeTagUid(response.headers['swarm-tag']), + tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined, } } @@ -177,6 +177,6 @@ export async function uploadCollection( return { reference: response.data.reference, - tagUid: makeTagUid(response.headers['swarm-tag']), + tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined, } } diff --git a/src/types/index.ts b/src/types/index.ts index 51d513d3..c54e49ef 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,3 +1,4 @@ +import { AxiosAdapter } from 'axios' import type { Identifier, SingleOwnerChunk } from '../chunk/soc' import type { FeedUploadOptions } from '../feed' import type { FeedType } from '../feed/type' @@ -96,6 +97,7 @@ export type BeeRequestOptions = { timeout?: number | false retry?: number | false headers?: Record + adapter?: AxiosAdapter onRequest?: (request: BeeRequest) => void } @@ -104,7 +106,6 @@ export interface BeeOptions extends BeeRequestOptions { * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance. */ signer?: Signer | Uint8Array | string - onRequest?: (request: BeeRequest) => void } export interface UploadResultWithCid extends UploadResult { @@ -129,7 +130,7 @@ export interface UploadResult { /** * Automatically created tag's UID. */ - tagUid: number + tagUid?: number } export interface UploadOptions { diff --git a/test/integration/bee-class.spec.ts b/test/integration/bee-class.spec.ts index e53751d9..f474cae7 100644 --- a/test/integration/bee-class.spec.ts +++ b/test/integration/bee-class.spec.ts @@ -9,8 +9,11 @@ import * as bzz from '../../src/modules/bzz' import { REFERENCE_HEX_LENGTH } from '../../src/types' import { makeBytes } from '../../src/utils/bytes' import { makeEthAddress } from '../../src/utils/eth' -import { bytesToHex, HexString } from '../../src/utils/hex' +import { HexString, bytesToHex } from '../../src/utils/hex' import { + ERR_TIMEOUT, + FEED_TIMEOUT, + PSS_TIMEOUT, beeDebugUrl, beeKyOptions, beePeerDebugUrl, @@ -19,11 +22,8 @@ import { commonMatchers, createRandomNodeReadable, createReadableStream, - ERR_TIMEOUT, - FEED_TIMEOUT, getPostageBatch, makeTestTarget, - PSS_TIMEOUT, randomByteArray, testChunkPayload, testIdentity, @@ -319,7 +319,7 @@ describe('Bee class', () => { }) const statusBeforePinning = bee.getPin(result.reference) - await expect(statusBeforePinning).be.rejectedWith('Not Found') + await expect(statusBeforePinning).be.rejectedWith('Request failed with status code 404') await bee.pin(result.reference) // Nothing is asserted as nothing is returned, will throw error if something is wrong diff --git a/test/integration/modules/bytes.spec.ts b/test/integration/modules/bytes.spec.ts index 4c3ee9f3..3d5948a1 100644 --- a/test/integration/modules/bytes.spec.ts +++ b/test/integration/modules/bytes.spec.ts @@ -16,6 +16,6 @@ describe('modules/bytes', () => { it('should catch error', async function () { this.timeout(ERR_TIMEOUT) - await expect(bytes.download(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(bytes.download(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) }) diff --git a/test/integration/modules/bzz.spec.ts b/test/integration/modules/bzz.spec.ts index 51da926f..4b2fd8e4 100644 --- a/test/integration/modules/bzz.spec.ts +++ b/test/integration/modules/bzz.spec.ts @@ -5,7 +5,7 @@ import * as bzz from '../../../src/modules/bzz' import * as tag from '../../../src/modules/tag' import { Collection, ENCRYPTED_REFERENCE_HEX_LENGTH } from '../../../src/types' import { makeCollectionFromFS } from '../../../src/utils/collection.node' -import { beeKyOptions, BIG_FILE_TIMEOUT, getPostageBatch, invalidReference, randomByteArray } from '../../utils' +import { BIG_FILE_TIMEOUT, beeKyOptions, getPostageBatch, invalidReference, randomByteArray } from '../../utils' const BEE_KY_OPTIONS = beeKyOptions() @@ -243,7 +243,9 @@ describe('modules/bzz', () => { it('should catch error', async function () { this.timeout(BIG_FILE_TIMEOUT) - await expect(bzz.downloadFile(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(bzz.downloadFile(BEE_KY_OPTIONS, invalidReference)).rejectedWith( + 'Request failed with status code 404', + ) }) it('should upload bigger file', async function () { diff --git a/test/integration/modules/chunk.spec.ts b/test/integration/modules/chunk.spec.ts index 2c5beeda..53422987 100644 --- a/test/integration/modules/chunk.spec.ts +++ b/test/integration/modules/chunk.spec.ts @@ -23,6 +23,6 @@ describe('modules/chunk', () => { it('should catch error', async function () { this.timeout(ERR_TIMEOUT) - await expect(chunk.download(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(chunk.download(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) }) diff --git a/test/integration/modules/feed.spec.ts b/test/integration/modules/feed.spec.ts index e3ba28fa..ae2ccc63 100644 --- a/test/integration/modules/feed.spec.ts +++ b/test/integration/modules/feed.spec.ts @@ -4,9 +4,9 @@ import { upload as uploadSOC } from '../../../src/modules/soc' import type { Topic } from '../../../src/types' import { HexString, hexToBytes, makeHexString } from '../../../src/utils/hex' import { + ERR_TIMEOUT, beeKyOptions, commonMatchers, - ERR_TIMEOUT, getPostageBatch, testIdentity, tryDeleteChunkFromLocalStorage, @@ -32,7 +32,7 @@ describe('modules/feed', () => { const emptyTopic = '1000000000000000000000000000000000000000000000000000000000000000' as Topic const feedUpdate = fetchLatestFeedUpdate(BEE_KY_OPTIONS, owner, emptyTopic) - await expect(feedUpdate).rejectedWith('Not Found') + await expect(feedUpdate).rejectedWith('Request failed with status code 404') }) it('one feed update', async function () { diff --git a/test/integration/modules/pinning.spec.ts b/test/integration/modules/pinning.spec.ts index 723055c9..6c4c7094 100644 --- a/test/integration/modules/pinning.spec.ts +++ b/test/integration/modules/pinning.spec.ts @@ -35,11 +35,11 @@ describe('modules/pin', () => { it('should not pin a non-existing file', async function () { this.timeout(ERR_TIMEOUT) - await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should not unpin a non-existing file', async function () { - await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) }) @@ -68,11 +68,11 @@ describe('modules/pin', () => { it('should not pin a non-existing collections', async function () { this.timeout(ERR_TIMEOUT) - await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should not unpin a non-existing collections', async function () { - await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) }) @@ -92,11 +92,11 @@ describe('modules/pin', () => { it('should not pin a non-existing data', async function () { this.timeout(ERR_TIMEOUT) - await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should not unpin a non-existing data', async function () { - await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) }) @@ -118,11 +118,11 @@ describe('modules/pin', () => { it('should not pin a non-existing chunk', async function () { this.timeout(ERR_TIMEOUT) - await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.pin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should not unpin a non-existing chunk', async function () { - await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.unpin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should return pinning status of existing chunk', async function () { @@ -135,7 +135,7 @@ describe('modules/pin', () => { }) it('should not return pinning status of non-existing chunk', async function () { - await expect(pinning.getPin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Not Found') + await expect(pinning.getPin(BEE_KY_OPTIONS, invalidReference)).rejectedWith('Request failed with status code 404') }) it('should return list of pinned chunks', async function () {