Socket
Socket
Sign inDemoInstall

arweave

Package Overview
Dependencies
Maintainers
5
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arweave - npm Package Compare versions

Comparing version 1.11.8 to 1.12.0

15

node/lib/api.d.ts

@@ -1,3 +0,1 @@

/// <reference types="node" />
import { AxiosResponse, AxiosRequestConfig, AxiosInstance } from "axios";
export interface ApiConfig {

@@ -12,2 +10,5 @@ host?: string;

}
export interface ResponseWithData<T = any> extends Response {
data: T;
}
export default class Api {

@@ -21,9 +22,5 @@ readonly METHOD_GET = "GET";

private mergeDefaults;
get<T = any>(endpoint: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
post<T = any>(endpoint: string, body: Buffer | string | object, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
/**
* Get an AxiosInstance with the base configuration setup to fire off
* a request to the network.
*/
request(): AxiosInstance;
get<T = any>(endpoint: string, config?: RequestInit): Promise<ResponseWithData<T>>;
post<T = any>(endpoint: string, body: any, config?: RequestInit): Promise<ResponseWithData<T>>;
request<T = unknown>(endpoint: string, init?: RequestInit): Promise<ResponseWithData<T>>;
}

79

node/lib/api.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
class Api {

@@ -33,49 +29,48 @@ constructor(config) {

async get(endpoint, config) {
try {
return await this.request().get(endpoint, config);
}
catch (error) {
if (error.response && error.response.status) {
return error.response;
}
throw error;
}
return await this.request(endpoint, { ...config, method: this.METHOD_GET });
}
async post(endpoint, body, config) {
try {
return await this.request().post(endpoint, body, config);
const headers = new Headers(config?.headers || {});
headers.append("content-type", "application/json");
headers.append("accept", "application/json, text/plain, */*");
return await this.request(endpoint, {
...config,
method: this.METHOD_POST,
body: JSON.stringify(body),
headers,
});
}
async request(endpoint, init) {
const headers = new Headers(init?.headers || {});
const baseURL = `${this.config.protocol}://${this.config.host}:${this.config.port}`;
if (endpoint.startsWith("/")) {
endpoint = endpoint.replace("/", "");
}
catch (error) {
if (error.response && error.response.status) {
return error.response;
}
throw error;
}
}
/**
* Get an AxiosInstance with the base configuration setup to fire off
* a request to the network.
*/
request() {
const headers = {};
if (this.config.network) {
headers["x-network"] = this.config.network;
headers.append("x-network", this.config.network);
}
let instance = axios_1.default.create({
baseURL: `${this.config.protocol}://${this.config.host}:${this.config.port}`,
timeout: this.config.timeout,
maxContentLength: 1024 * 1024 * 512,
if (this.config.logging) {
this.config.logger(`Requesting: ${baseURL}/${endpoint}`);
}
let res = await fetch(`${baseURL}/${endpoint}`, {
...(init || {}),
headers,
});
if (this.config.logging) {
instance.interceptors.request.use((request) => {
this.config.logger(`Requesting: ${request.baseURL}/${request.url}`);
return request;
});
instance.interceptors.response.use((response) => {
this.config.logger(`Response: ${response.config.url} - ${response.status}`);
return response;
});
this.config.logger(`Response: ${res.url} - ${res.status}`);
}
return instance;
const contentType = res.headers.get("content-type");
const response = res;
if (contentType?.startsWith("application/json")) {
response.data = (await res.clone().json());
}
else {
try {
response.data = (await res.clone().text());
}
catch {
response.data = (await res.clone().arrayBuffer());
}
}
return response;
}

@@ -82,0 +77,0 @@ }

@@ -116,3 +116,3 @@ "use strict";

}
const subtle = crypto === null || crypto === void 0 ? void 0 : crypto.subtle;
const subtle = crypto?.subtle;
if (subtle === undefined) {

@@ -119,0 +119,0 @@ return false;

@@ -1,2 +0,2 @@

import { AxiosResponse } from "axios";
import { ResponseWithData } from "./api";
export declare const enum ArweaveErrorType {

@@ -10,10 +10,10 @@ TX_NOT_FOUND = "TX_NOT_FOUND",

readonly type: ArweaveErrorType;
readonly response?: AxiosResponse;
readonly response?: ResponseWithData;
constructor(type: ArweaveErrorType, optional?: {
message?: string;
response?: AxiosResponse;
response?: ResponseWithData;
});
getType(): ArweaveErrorType;
}
type AxiosResponseLite = {
type ResponseLite = {
status: number;

@@ -25,3 +25,3 @@ statusText?: string;

};
export declare function getError(resp: AxiosResponseLite): any;
export declare function getError(resp: ResponseLite): any;
export {};

@@ -21,3 +21,3 @@ "use strict";

// Safely get error string
// from an axios response, falling back to
// from a response, falling back to
// resp.data, statusText or 'unknown'.

@@ -24,0 +24,0 @@ // Note: a wrongly set content-type can

@@ -26,14 +26,2 @@ "use strict";

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -62,5 +50,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

*/
return this.api
.get(`tx_anchor`, { transformResponse: [] })
.then((response) => {
return this.api.get(`tx_anchor`).then((response) => {
return response.data;

@@ -73,18 +59,3 @@ });

: `price/${byteSize}`;
return this.api
.get(endpoint, {
transformResponse: [
/**
* We need to specify a response transformer to override
* the default JSON.parse behavior, as this causes
* winston to be converted to a number and we want to
* return it as a winston string.
* @param data
*/
function (data) {
return data;
},
],
})
.then((response) => {
return this.api.get(endpoint).then((response) => {
return response.data;

@@ -101,5 +72,11 @@ });

const data = await this.getData(id);
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { data }));
return new transaction_1.default({
...response.data,
data,
});
}
return new transaction_1.default(Object.assign(Object.assign({}, response.data), { format: response.data.format || 1 }));
return new transaction_1.default({
...response.data,
format: response.data.format || 1,
});
}

@@ -186,3 +163,3 @@ if (response.status == 404) {

}
catch (_a) {
catch {
// Permission is already granted

@@ -335,11 +312,9 @@ }

*/
upload(upload, data) {
return __asyncGenerator(this, arguments, function* upload_1() {
const uploader = yield __await(this.getUploader(upload, data));
while (!uploader.isComplete) {
yield __await(uploader.uploadChunk());
yield yield __await(uploader);
}
return yield __await(uploader);
});
async *upload(upload, data) {
const uploader = await this.getUploader(upload, data);
while (!uploader.isComplete) {
await uploader.uploadChunk();
yield uploader;
}
return uploader;
}

@@ -346,0 +321,0 @@ }

@@ -41,18 +41,3 @@ "use strict";

getBalance(address) {
return this.api
.get(`wallet/${address}/balance`, {
transformResponse: [
/**
* We need to specify a response transformer to override
* the default JSON.parse behaviour, as this causes
* balances to be converted to a number and we want to
* return it as a winston string.
* @param data
*/
function (data) {
return data;
},
],
})
.then((response) => {
return this.api.get(`wallet/${address}/balance`).then((response) => {
return response.data;

@@ -90,3 +75,3 @@ });

}
catch (_a) {
catch {
// Permission is already granted

@@ -93,0 +78,0 @@ }

{
"name": "arweave",
"version": "1.11.8",
"version": "1.12.0",
"description": "Arweave JS client library",

@@ -14,3 +14,3 @@ "main": "./node/index.js",

"scripts": {
"compile:node": "tsc --declaration -project tsconfig.node.json && resolve-tspaths -p tsconfig.node.json",
"compile:node": "cross-env NODE_OPTIONS='--experimental-fetch' tsc --declaration -project tsconfig.node.json && resolve-tspaths -p tsconfig.node.json",
"compile:web": "tsc --declaration -project tsconfig.web.json && resolve-tspaths -p tsconfig.web.json",

@@ -27,3 +27,3 @@ "bundle:web": "npx webpack --config-name web",

"prepublishOnly": "npm run clean && npm run build",
"test": "mocha -r ts-node/register -r tsconfig-paths/register test/*.ts && echo \"NOW RUN => 'npm run test:web' <= \" ",
"test": "cross-env NODE_OPTIONS='--experimental-fetch' mocha -r ts-node/register -r tsconfig-paths/register test/*.ts && echo \"NOW RUN => 'npm run test:web' <= \" ",
"test:web": "npm run bundle:web && npx webpack --config-name web-tests && opener test/web/web.html",

@@ -68,2 +68,3 @@ "prettier:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",

"chai": "^4.3.6",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",

@@ -93,3 +94,3 @@ "mkdirp": "^1.0.4",

"engines": {
"node": ">=12"
"node": ">=16"
},

@@ -96,0 +97,0 @@ "dependencies": {

@@ -1,3 +0,1 @@

/// <reference types="node" />
import { AxiosResponse, AxiosRequestConfig, AxiosInstance } from "axios";
export interface ApiConfig {

@@ -12,2 +10,5 @@ host?: string;

}
export interface ResponseWithData<T = any> extends Response {
data: T;
}
export default class Api {

@@ -21,9 +22,5 @@ readonly METHOD_GET = "GET";

private mergeDefaults;
get<T = any>(endpoint: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
post<T = any>(endpoint: string, body: Buffer | string | object, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
/**
* Get an AxiosInstance with the base configuration setup to fire off
* a request to the network.
*/
request(): AxiosInstance;
get<T = any>(endpoint: string, config?: RequestInit): Promise<ResponseWithData<T>>;
post<T = any>(endpoint: string, body: any, config?: RequestInit): Promise<ResponseWithData<T>>;
request<T = unknown>(endpoint: string, init?: RequestInit): Promise<ResponseWithData<T>>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("axios");
class Api {

@@ -30,49 +29,40 @@ constructor(config) {

async get(endpoint, config) {
try {
return await this.request().get(endpoint, config);
}
catch (error) {
if (error.response && error.response.status) {
return error.response;
}
throw error;
}
return await this.request(endpoint, Object.assign(Object.assign({}, config), { method: this.METHOD_GET }));
}
async post(endpoint, body, config) {
try {
return await this.request().post(endpoint, body, config);
const headers = new Headers((config === null || config === void 0 ? void 0 : config.headers) || {});
headers.append("content-type", "application/json");
headers.append("accept", "application/json, text/plain, */*");
return await this.request(endpoint, Object.assign(Object.assign({}, config), { method: this.METHOD_POST, body: JSON.stringify(body), headers }));
}
async request(endpoint, init) {
const headers = new Headers((init === null || init === void 0 ? void 0 : init.headers) || {});
const baseURL = `${this.config.protocol}://${this.config.host}:${this.config.port}`;
if (endpoint.startsWith("/")) {
endpoint = endpoint.replace("/", "");
}
catch (error) {
if (error.response && error.response.status) {
return error.response;
}
throw error;
}
}
/**
* Get an AxiosInstance with the base configuration setup to fire off
* a request to the network.
*/
request() {
const headers = {};
if (this.config.network) {
headers["x-network"] = this.config.network;
headers.append("x-network", this.config.network);
}
let instance = axios_1.default.create({
baseURL: `${this.config.protocol}://${this.config.host}:${this.config.port}`,
timeout: this.config.timeout,
maxContentLength: 1024 * 1024 * 512,
headers,
});
if (this.config.logging) {
instance.interceptors.request.use((request) => {
this.config.logger(`Requesting: ${request.baseURL}/${request.url}`);
return request;
});
instance.interceptors.response.use((response) => {
this.config.logger(`Response: ${response.config.url} - ${response.status}`);
return response;
});
this.config.logger(`Requesting: ${baseURL}/${endpoint}`);
}
return instance;
let res = await fetch(`${baseURL}/${endpoint}`, Object.assign(Object.assign({}, (init || {})), { headers }));
if (this.config.logging) {
this.config.logger(`Response: ${res.url} - ${res.status}`);
}
const contentType = res.headers.get("content-type");
const response = res;
if (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("application/json")) {
response.data = (await res.clone().json());
}
else {
try {
response.data = (await res.clone().text());
}
catch (_a) {
response.data = (await res.clone().arrayBuffer());
}
}
return response;
}

@@ -79,0 +69,0 @@ }

@@ -1,2 +0,2 @@

import { AxiosResponse } from "axios";
import { ResponseWithData } from "./api";
export declare const enum ArweaveErrorType {

@@ -10,10 +10,10 @@ TX_NOT_FOUND = "TX_NOT_FOUND",

readonly type: ArweaveErrorType;
readonly response?: AxiosResponse;
readonly response?: ResponseWithData;
constructor(type: ArweaveErrorType, optional?: {
message?: string;
response?: AxiosResponse;
response?: ResponseWithData;
});
getType(): ArweaveErrorType;
}
type AxiosResponseLite = {
type ResponseLite = {
status: number;

@@ -25,3 +25,3 @@ statusText?: string;

};
export declare function getError(resp: AxiosResponseLite): any;
export declare function getError(resp: ResponseLite): any;
export {};

@@ -21,3 +21,3 @@ "use strict";

// Safely get error string
// from an axios response, falling back to
// from a response, falling back to
// resp.data, statusText or 'unknown'.

@@ -24,0 +24,0 @@ // Note: a wrongly set content-type can

@@ -35,5 +35,3 @@ "use strict";

*/
return this.api
.get(`tx_anchor`, { transformResponse: [] })
.then((response) => {
return this.api.get(`tx_anchor`).then((response) => {
return response.data;

@@ -46,18 +44,3 @@ });

: `price/${byteSize}`;
return this.api
.get(endpoint, {
transformResponse: [
/**
* We need to specify a response transformer to override
* the default JSON.parse behavior, as this causes
* winston to be converted to a number and we want to
* return it as a winston string.
* @param data
*/
function (data) {
return data;
},
],
})
.then((response) => {
return this.api.get(endpoint).then((response) => {
return response.data;

@@ -64,0 +47,0 @@ });

@@ -18,18 +18,3 @@ "use strict";

getBalance(address) {
return this.api
.get(`wallet/${address}/balance`, {
transformResponse: [
/**
* We need to specify a response transformer to override
* the default JSON.parse behaviour, as this causes
* balances to be converted to a number and we want to
* return it as a winston string.
* @param data
*/
function (data) {
return data;
},
],
})
.then((response) => {
return this.api.get(`wallet/${address}/balance`).then((response) => {
return response.data;

@@ -36,0 +21,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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc