@ethersphere/bee-js
Advanced tools
Comparing version 8.0.2 to 8.1.0
@@ -26,4 +26,4 @@ "use strict"; | ||
const { reference } = await bee.uploadData(postageBatchId, serializedData, options, requestOptions); | ||
return writer.upload(postageBatchId, reference); | ||
return writer.upload(postageBatchId, reference, { pin: options?.pin }); | ||
} | ||
exports.setJsonData = setJsonData; |
@@ -33,3 +33,3 @@ "use strict"; | ||
catch (e) { | ||
if (e?.response?.status === 404) { | ||
if (e?.status === 404 || e?.status === 500) { | ||
return false; | ||
@@ -36,0 +36,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.getDebugStatus = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_DEBUG_API_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0; | ||
exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.getDebugStatus = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0; | ||
const major_js_1 = __importDefault(require("semver/functions/major.js")); | ||
@@ -12,5 +12,4 @@ const http_1 = require("../../utils/http"); | ||
// so if you are changing anything about them change the `update_bee` action accordingly! | ||
exports.SUPPORTED_BEE_VERSION_EXACT = '1.18.2-759f56f'; | ||
exports.SUPPORTED_API_VERSION = '4.0.0'; | ||
exports.SUPPORTED_DEBUG_API_VERSION = '4.0.0'; | ||
exports.SUPPORTED_BEE_VERSION_EXACT = '2.2.0-06a0aca7'; | ||
exports.SUPPORTED_API_VERSION = '7.1.0'; | ||
exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.split('-')[0]; | ||
@@ -17,0 +16,0 @@ const NODE_INFO_URL = 'node'; |
@@ -61,4 +61,4 @@ "use strict"; | ||
}); | ||
return response.data.references; | ||
return response.data.references || []; | ||
} | ||
exports.getAllPins = getAllPins; |
@@ -18,4 +18,7 @@ "use strict"; | ||
class BeeResponseError extends BeeError { | ||
constructor(message, status, statusText) { | ||
constructor(method, url, message, responseBody, status, statusText) { | ||
super(message); | ||
this.method = method; | ||
this.url = url; | ||
this.responseBody = responseBody; | ||
this.status = status; | ||
@@ -22,0 +25,0 @@ this.statusText = statusText; |
@@ -11,4 +11,4 @@ "use strict"; | ||
// browser | ||
if (typeof File === 'function') { | ||
return file instanceof File; | ||
if (typeof File === 'function' && file instanceof File) { | ||
return true; | ||
} | ||
@@ -15,0 +15,0 @@ // node.js |
@@ -38,3 +38,3 @@ "use strict"; | ||
if (e instanceof AxiosError) { | ||
throw new index_1.BeeResponseError(e.message, e.status, e.code); | ||
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code); | ||
} | ||
@@ -41,0 +41,0 @@ throw e; |
@@ -185,5 +185,2 @@ "use strict"; | ||
const options = value; | ||
if (options.retry) { | ||
assertNonNegativeInteger(options.retry, `${name}.retry`); | ||
} | ||
if (options.timeout) { | ||
@@ -190,0 +187,0 @@ assertNonNegativeInteger(options.timeout, `${name}.timeout`); |
@@ -81,3 +81,6 @@ import { ReferenceType } from '@ethersphere/swarm-cid'; | ||
assertData(data); | ||
if (options) assertUploadOptions(options); | ||
assertRequestOptions(requestOptions); | ||
if (options) { | ||
assertUploadOptions(options); | ||
} | ||
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options); | ||
@@ -128,2 +131,3 @@ } | ||
assertBatchId(postageBatchId); | ||
assertRequestOptions(requestOptions); | ||
if (!(data instanceof Uint8Array)) { | ||
@@ -138,3 +142,5 @@ throw new TypeError('Data has to be Uint8Array instance!'); | ||
} | ||
if (options) assertUploadOptions(options); | ||
if (options) { | ||
assertUploadOptions(options); | ||
} | ||
return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options); | ||
@@ -168,2 +174,3 @@ } | ||
async createGrantees(postageBatchId, grantees, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertBatchId(postageBatchId); | ||
@@ -180,2 +187,3 @@ return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees); | ||
async getGrantees(reference, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions)); | ||
@@ -194,2 +202,3 @@ } | ||
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertBatchId(postageBatchId); | ||
@@ -218,5 +227,8 @@ return grantee.patchGrantees(postageBatchId, reference, history, { | ||
async uploadFile(postageBatchId, data, name, options, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertBatchId(postageBatchId); | ||
assertFileData(data); | ||
if (options) assertFileUploadOptions(options); | ||
if (options) { | ||
assertFileUploadOptions(options); | ||
} | ||
if (name && typeof name !== 'string') { | ||
@@ -294,4 +306,7 @@ throw new TypeError('name has to be string or undefined!'); | ||
async uploadFiles(postageBatchId, fileList, options, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertBatchId(postageBatchId); | ||
if (options) assertCollectionUploadOptions(options); | ||
if (options) { | ||
assertCollectionUploadOptions(options); | ||
} | ||
const data = await makeCollectionFromFileList(fileList); | ||
@@ -310,7 +325,8 @@ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST); | ||
*/ | ||
async uploadCollection(postageBatchId, collection, options) { | ||
async uploadCollection(postageBatchId, collection, options, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertBatchId(postageBatchId); | ||
assertCollection(collection); | ||
if (options) assertCollectionUploadOptions(options); | ||
return addCidConversionFunction(await bzz.uploadCollection(this.requestOptions, collection, postageBatchId, options), ReferenceType.MANIFEST); | ||
return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), ReferenceType.MANIFEST); | ||
} | ||
@@ -335,2 +351,3 @@ /** | ||
assertBatchId(postageBatchId); | ||
assertRequestOptions(requestOptions); | ||
if (options) assertCollectionUploadOptions(options); | ||
@@ -363,6 +380,6 @@ const data = await makeCollectionFromFS(dir); | ||
*/ | ||
async getAllTags(options) { | ||
assertRequestOptions(options); | ||
async getAllTags(options, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
assertAllTagsOptions(options); | ||
return tag.getAllTags(this.getRequestOptionsForCall(options), options?.offset, options?.limit); | ||
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit); | ||
} | ||
@@ -529,3 +546,3 @@ /** | ||
} catch (e) { | ||
if (e?.response?.status === 404) { | ||
if (e?.status === 404 || e?.status === 500) { | ||
return false; | ||
@@ -760,3 +777,3 @@ } | ||
async setJsonFeed(postageBatchId, topic, data, options, requestOptions) { | ||
assertRequestOptions(options, 'JsonFeedOptions'); | ||
assertRequestOptions(requestOptions, 'JsonFeedOptions'); | ||
assertBatchId(postageBatchId); | ||
@@ -787,4 +804,4 @@ const hashedTopic = this.makeFeedTopic(topic); | ||
*/ | ||
async getJsonFeed(topic, options) { | ||
assertRequestOptions(options, 'JsonFeedOptions'); | ||
async getJsonFeed(topic, options, requestOptions) { | ||
assertRequestOptions(requestOptions); | ||
const hashedTopic = this.makeFeedTopic(topic); | ||
@@ -809,3 +826,3 @@ const feedType = options?.type ?? DEFAULT_FEED_TYPE; | ||
} | ||
const reader = this.makeFeedReader(feedType, hashedTopic, address, options); | ||
const reader = this.makeFeedReader(feedType, hashedTopic, address, requestOptions); | ||
return getJsonData(this, reader); | ||
@@ -1025,2 +1042,3 @@ } | ||
assertAddress(address); | ||
assertRequestOptions(requestOptions); | ||
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options); | ||
@@ -1208,2 +1226,3 @@ } | ||
assertNonNegativeInteger(depth); | ||
assertRequestOptions(requestOptions); | ||
if (depth < STAMPS_DEPTH_MIN) { | ||
@@ -1368,4 +1387,4 @@ throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth); | ||
async depositStake(amount, options, requestOptions) { | ||
assertRequestOptions(options); | ||
assertTransactionOptions(options); | ||
assertRequestOptions(requestOptions); | ||
await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options); | ||
@@ -1407,3 +1426,3 @@ } | ||
} | ||
throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.'); | ||
throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.'); | ||
} | ||
@@ -1410,0 +1429,0 @@ getRequestOptionsForCall(options) { |
@@ -23,3 +23,5 @@ import { isError } from "../utils/type.js"; | ||
} = await bee.uploadData(postageBatchId, serializedData, options, requestOptions); | ||
return writer.upload(postageBatchId, reference); | ||
return writer.upload(postageBatchId, reference, { | ||
pin: options?.pin | ||
}); | ||
} |
@@ -29,3 +29,3 @@ import { Binary } from 'cafe-utility'; | ||
} catch (e) { | ||
if (e?.response?.status === 404) { | ||
if (e?.status === 404 || e?.status === 500) { | ||
return false; | ||
@@ -32,0 +32,0 @@ } |
import getMajorSemver from 'semver/functions/major.js'; | ||
import { http } from "../../utils/http.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.18.2-759f56f'; | ||
export const SUPPORTED_API_VERSION = '4.0.0'; | ||
export const SUPPORTED_DEBUG_API_VERSION = '4.0.0'; | ||
export const SUPPORTED_BEE_VERSION_EXACT = '2.2.0-06a0aca7'; | ||
export const SUPPORTED_API_VERSION = '7.1.0'; | ||
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0]; | ||
@@ -8,0 +7,0 @@ const NODE_INFO_URL = 'node'; |
@@ -55,3 +55,3 @@ import { http } from "../utils/http.js"; | ||
}); | ||
return response.data.references; | ||
return response.data.references || []; | ||
} |
@@ -13,4 +13,7 @@ export class BeeError extends Error { | ||
export class BeeResponseError extends BeeError { | ||
constructor(message, status, statusText) { | ||
constructor(method, url, message, responseBody, status, statusText) { | ||
super(message); | ||
this.method = method; | ||
this.url = url; | ||
this.responseBody = responseBody; | ||
this.status = status; | ||
@@ -17,0 +20,0 @@ this.statusText = statusText; |
@@ -8,4 +8,4 @@ /** | ||
// browser | ||
if (typeof File === 'function') { | ||
return file instanceof File; | ||
if (typeof File === 'function' && file instanceof File) { | ||
return true; | ||
} | ||
@@ -12,0 +12,0 @@ // node.js |
@@ -35,3 +35,3 @@ import axios from 'axios'; | ||
if (e instanceof AxiosError) { | ||
throw new BeeResponseError(e.message, e.status, e.code); | ||
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code); | ||
} | ||
@@ -38,0 +38,0 @@ throw e; |
@@ -154,5 +154,2 @@ import { decodeCid, encodeReference } from '@ethersphere/swarm-cid'; | ||
const options = value; | ||
if (options.retry) { | ||
assertNonNegativeInteger(options.retry, `${name}.retry`); | ||
} | ||
if (options.timeout) { | ||
@@ -159,0 +156,0 @@ assertNonNegativeInteger(options.timeout, `${name}.timeout`); |
@@ -193,3 +193,3 @@ /// <reference types="node" /> | ||
*/ | ||
uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions): Promise<UploadResultWithCid>; | ||
uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions, requestOptions?: BeeRequestOptions): Promise<UploadResultWithCid>; | ||
/** | ||
@@ -232,3 +232,3 @@ * Upload collection of files. | ||
*/ | ||
getAllTags(options?: AllTagsOptions): Promise<Tag[]>; | ||
getAllTags(options?: AllTagsOptions, requestOptions?: BeeRequestOptions): Promise<Tag[]>; | ||
/** | ||
@@ -469,3 +469,3 @@ * Retrieve tag information from Bee node | ||
*/ | ||
setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>; | ||
setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions & UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>; | ||
/** | ||
@@ -490,3 +490,3 @@ * High-level function that allows you to easily get data from feed. | ||
*/ | ||
getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions): Promise<T>; | ||
getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<T>; | ||
/** | ||
@@ -493,0 +493,0 @@ * Make a new feed topic from a string |
import { BeeRequestOptions } from '../../index'; | ||
import type { DebugStatus, Health, NodeInfo } from '../../types/debug'; | ||
import { BeeVersions } from '../../types/debug'; | ||
export declare const SUPPORTED_BEE_VERSION_EXACT = "1.18.2-759f56f"; | ||
export declare const SUPPORTED_API_VERSION = "4.0.0"; | ||
export declare const SUPPORTED_DEBUG_API_VERSION = "4.0.0"; | ||
export declare const SUPPORTED_BEE_VERSION_EXACT = "2.2.0-06a0aca7"; | ||
export declare const SUPPORTED_API_VERSION = "7.1.0"; | ||
export declare const SUPPORTED_BEE_VERSION: string; | ||
@@ -8,0 +7,0 @@ export declare function getDebugStatus(requestOptions: BeeRequestOptions): Promise<DebugStatus>; |
@@ -74,3 +74,2 @@ import type { Identifier, SingleOwnerChunk } from '../chunk/soc'; | ||
timeout?: number | false; | ||
retry?: number | false; | ||
headers?: Record<string, string>; | ||
@@ -77,0 +76,0 @@ onRequest?: (request: BeeRequest) => void; |
@@ -9,5 +9,8 @@ export declare class BeeError extends Error { | ||
export declare class BeeResponseError extends BeeError { | ||
method: string; | ||
url: string; | ||
responseBody?: any; | ||
status?: number | undefined; | ||
statusText?: string | undefined; | ||
constructor(message: string, status?: number | undefined, statusText?: string | undefined); | ||
constructor(method: string, url: string, message: string, responseBody?: any, status?: number | undefined, statusText?: string | undefined); | ||
} |
{ | ||
"name": "@ethersphere/bee-js", | ||
"version": "8.0.2", | ||
"version": "8.1.0", | ||
"description": "Javascript client for Bee", | ||
@@ -55,3 +55,4 @@ "keywords": [ | ||
"mock-ci": "npm run lint:check && npm run check:types && npm run test", | ||
"test": "mocha", | ||
"test": "jest --config=jest.config.ts --runInBand --verbose", | ||
"test:coverage": "jest --config=jest.config.ts --coverage", | ||
"check:types": "tsc --project tsconfig.test.json", | ||
@@ -61,3 +62,3 @@ "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"depcheck": "depcheck .", | ||
"bee": "npx fdp-play start --detach --fresh" | ||
"bee": "npx @fairdatasociety/fdp-play@3.2.0 start --detach --fresh" | ||
}, | ||
@@ -84,11 +85,8 @@ "dependencies": { | ||
"@fluffy-spoon/substitute": "^1.208.0", | ||
"@jest/types": "^29.6.3", | ||
"@naholyr/cross-env": "^1.0.0", | ||
"@types/chai": "^4.3.4", | ||
"@types/chai-as-promised": "^7.1.5", | ||
"@types/elliptic": "^6.4.14", | ||
"@types/mocha": "^10.0.1", | ||
"@types/jest": "^29.5.13", | ||
"@types/node": "^18.11.11", | ||
"@types/semver": "^7.3.9", | ||
"@types/sinon": "^10.0.13", | ||
"@types/sinon-chai": "^3.2.9", | ||
"@types/ws": "^8.5.3", | ||
@@ -99,5 +97,2 @@ "@typescript-eslint/eslint-plugin": "^5.46.0", | ||
"babel-plugin-add-import-extension": "^1.6.0", | ||
"chai": "^4.3.7", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-parentheses": "^0.0.2", | ||
"cross-env": "^7.0.3", | ||
@@ -109,5 +104,4 @@ "depcheck": "^1.4.7", | ||
"eslint-plugin-unused-imports": "^2.0.0", | ||
"expect": "^29.4.0", | ||
"husky": "^8.0.1", | ||
"mocha": "^10.2.0", | ||
"jest": "^29.7.0", | ||
"nock": "^13.3.0", | ||
@@ -117,5 +111,4 @@ "playwright-test": "^8.1.2", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^15.0.1", | ||
"sinon-chai": "^3.7.0", | ||
"terser-webpack-plugin": "^5.3.1", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "^10.9.1", | ||
@@ -125,3 +118,7 @@ "typescript": "^4.9.5", | ||
"webpack-cli": "^5.0.1" | ||
}, | ||
"engines": { | ||
"bee": "2.2.0-06a0aca7", | ||
"beeApiVersion": "7.1.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1918442
38
14550