Socket
Socket
Sign inDemoInstall

@onekeyfe/hd-transport-http

Package Overview
Dependencies
Maintainers
2
Versions
249
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onekeyfe/hd-transport-http - npm Package Compare versions

Comparing version 0.1.44 to 0.1.45

53

dist/index.js

@@ -1,5 +0,12 @@

import transport from '@onekeyfe/hd-transport';
import { HardwareError, HardwareErrorCode, ERRORS } from '@onekeyfe/hd-shared';
import axios from 'axios';
'use strict';
var transport = require('@onekeyfe/hd-transport');
var hdShared = require('@onekeyfe/hd-shared');
var axios = require('axios');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var transport__default = /*#__PURE__*/_interopDefaultLegacy(transport);
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
/******************************************************************************

@@ -63,3 +70,3 @@ Copyright (c) Microsoft Corporation.

};
const res = yield axios.request(fetchOptions);
const res = yield axios__default["default"].request(fetchOptions);
if (+res.status === 200) {

@@ -70,13 +77,29 @@ return parseResult(res.data);

if (typeof resJson === 'object' && resJson != null && resJson.error != null) {
throw new HardwareError({ errorCode: HardwareErrorCode.NetworkError, message: resJson.error });
throw new hdShared.HardwareError({
errorCode: hdShared.HardwareErrorCode.NetworkError,
message: resJson.error,
});
}
else {
throw new HardwareError({ errorCode: HardwareErrorCode.NetworkError, message: res.data });
throw new hdShared.HardwareError({ errorCode: hdShared.HardwareErrorCode.NetworkError, message: res.data });
}
});
}
axios__default["default"].interceptors.request.use(config => {
var _a, _b;
if (typeof window !== 'undefined') {
return config;
}
if ((_a = config.url) === null || _a === void 0 ? void 0 : _a.startsWith('http://localhost:21320')) {
if (!((_b = config === null || config === void 0 ? void 0 : config.headers) === null || _b === void 0 ? void 0 : _b.Origin)) {
console.log('set node request origin');
config.headers = Object.assign(Object.assign({}, config.headers), { Origin: 'https://jssdk.onekey.so' });
}
}
return config;
});
const DEFAULT_URL = 'http://localhost:21320';
const { check, buildOne, receiveOne, parseConfigure } = transport;
const { check, buildOne, receiveOne, parseConfigure } = transport__default["default"];
class HttpTransport {

@@ -90,3 +113,3 @@ constructor(url) {

if (this.stopped) {
return Promise.reject(ERRORS.TypedError('Transport stopped.'));
return Promise.reject(hdShared.ERRORS.TypedError('Transport stopped.'));
}

@@ -121,3 +144,3 @@ return request(Object.assign(Object.assign({}, options), { method: 'POST', url: this.url + options.url }));

if (old === null) {
throw ERRORS.TypedError('Http-Transport does not support listen without previous.');
throw hdShared.ERRORS.TypedError('Http-Transport does not support listen without previous.');
}

@@ -164,3 +187,3 @@ const devicesS = yield this._post({

if (this._messages == null) {
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
}

@@ -177,3 +200,3 @@ const messages = this._messages;

if (typeof resData !== 'string') {
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
}

@@ -187,3 +210,3 @@ const jsonData = receiveOne(messages, resData);

if (this._messages == null) {
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
}

@@ -201,3 +224,3 @@ const messages = this._messages;

if (this._messages == null) {
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
}

@@ -209,3 +232,3 @@ const messages = this._messages;

if (typeof resData !== 'string') {
throw ERRORS.TypedError(HardwareErrorCode.NetworkError, 'Returning data is not string.');
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Returning data is not string.');
}

@@ -227,2 +250,2 @@ const jsonData = receiveOne(messages, resData);

export { HttpTransport as default };
module.exports = HttpTransport;
{
"name": "@onekeyfe/hd-transport-http",
"version": "0.1.44",
"version": "0.1.45",
"description": "hardware http transport",

@@ -28,7 +28,7 @@ "author": "OneKey",

"dependencies": {
"@onekeyfe/hd-shared": "^0.1.44",
"@onekeyfe/hd-transport": "^0.1.44",
"@onekeyfe/hd-shared": "^0.1.45",
"@onekeyfe/hd-transport": "^0.1.45",
"axios": "^0.27.2"
},
"gitHead": "fb673918587877267cbbeca6e0c6abbc56a0d0fa"
"gitHead": "0436f8ff26494933124c1c6f4586d4aeb5526c30"
}

@@ -52,3 +52,6 @@ import axios, { AxiosRequestConfig } from 'axios';

if (typeof resJson === 'object' && resJson != null && resJson.error != null) {
throw new HardwareError({ errorCode: HardwareErrorCode.NetworkError, message: resJson.error });
throw new HardwareError({
errorCode: HardwareErrorCode.NetworkError,
message: resJson.error,
});
} else {

@@ -58,1 +61,19 @@ throw new HardwareError({ errorCode: HardwareErrorCode.NetworkError, message: res.data });

}
axios.interceptors.request.use(config => {
if (typeof window !== 'undefined') {
return config;
}
// node environment
if (config.url?.startsWith('http://localhost:21320')) {
if (!config?.headers?.Origin) {
console.log('set node request origin');
// add Origin field for request headers
config.headers = {
...config.headers,
Origin: 'https://jssdk.onekey.so',
};
}
}
return config;
});

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