Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Merge the Soroban client into this package #857

Closed
wants to merge 14 commits into from
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = {
env: {
es6: true,
es6: true
},
extends: ["airbnb-base", "prettier"],
plugins: ["@babel", "prettier", "prefer-import"],
parser: "@babel/eslint-parser",
extends: ['airbnb-base', 'prettier'],
plugins: ['@babel', 'prettier', 'prefer-import'],
parser: '@babel/eslint-parser',
rules: {
"node/no-unpublished-require": 0,
},
'node/no-unpublished-require': 0
}
};
5 changes: 3 additions & 2 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"@babel/typescript"
],
"targets": {
"browsers": [ "> 2%" ] // target modern browsers and ES6
"node": 16,
"browsers": [ "> 2%" ] // target modern browsers and ES6
},
"env": {
"development": {
Expand All @@ -14,7 +15,7 @@
"production": {
"comments": false,
"targets": {
"node": 16,
// larger feature set for prod bundle
"browsers": [
"> 2%",
"ie 11",
Expand Down
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "stellar-sdk",
"version": "11.0.0-beta.1",
"description": "A library for working with the Stellar Horizon server.",
"keywords": [
"stellar"
],
"keywords": [ "stellar", "soroban", "horizon" ],
"homepage": "https://github.com/stellar/js-stellar-sdk",
"bugs": {
"url": "https://github.com/stellar/js-stellar-sdk/issues"
Expand All @@ -17,7 +15,7 @@
"author": "Stellar Development Foundation <[email protected]>",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"browser": "./dist/stellar-sdk.js",
"browser": "./dist/stellar-sdk.min.js",
"files": [
"/types",
"/lib",
Expand All @@ -32,8 +30,9 @@
"build:docs": "cross-env NODE_ENV=docs yarn _babel",
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json --verbose",
"test": "yarn test:node && yarn test:integration && yarn test:browser",
"test": "yarn build && yarn test:node && yarn test:integration && yarn test:browser",
"test:node": "yarn _nyc mocha --recursive 'test/unit/**/*.js'",
"test:node:soroban": "yarn _nyc mocha --recursive 'test/unit/soroban/**/*.js'",
"test:integration": "yarn _nyc mocha --recursive 'test/integration/**/*.js'",
"test:browser": "karma start config/karma.conf.js",
"fmt": "yarn eslint -c .eslintrc.js src/ --fix && yarn _prettier",
Expand All @@ -42,7 +41,7 @@
"_build": "yarn build:node && yarn build:browser",
"_babel": "babel --extensions '.ts' --out-dir lib/ src/",
"_nyc": "nyc --nycrc-path config/.nycrc",
"_prettier": "prettier --ignore-path config/.prettierignore --write './**/*.js'"
"_prettier": "prettier --config config/prettier.config.js --ignore-path config/.prettierignore --write './**/*.js'"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -76,43 +75,42 @@
]
},
"devDependencies": {
"@babel/cli": "^7.22.6",
"@babel/core": "^7.22.8",
"@babel/eslint-parser": "^7.22.7",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.22.7",
"@babel/preset-typescript": "^7.21.4",
"@babel/register": "^7.21.0",
"@definitelytyped/dtslint": "^0.0.163",
"@babel/cli": "^7.22.9",
"@babel/core": "^7.22.9",
"@babel/eslint-parser": "^7.22.9",
"@babel/eslint-plugin": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-typescript": "^7.22.5",
"@babel/register": "^7.22.5",
"@definitelytyped/dtslint": "^0.0.165",
"@istanbuljs/nyc-config-babel": "3.0.0",
"@stellar/tsconfig": "^1.0.2",
"@types/detect-node": "^2.0.0",
"@types/eventsource": "^1.1.2",
"@types/lodash": "^4.14.192",
"@types/node": "^20.4.1",
"@types/lodash": "^4.14.196",
"@types/node": "^20.4.2",
"@types/randombytes": "^2.0.0",
"@types/urijs": "^1.19.6",
"@typescript-eslint/parser": "^5.59.7",
"@typescript-eslint/parser": "^6.2.1",
"axios-mock-adapter": "^1.21.5",
"babel-loader": "^9.1.3",
"babel-loader": "^9.1.2",
"babel-plugin-istanbul": "^6.1.1",
"buffer": "^6.0.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai-http": "^4.3.0",
"chai-http": "^4.4.0",
"cross-env": "^7.0.3",
"eslint": "^8.44.0",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.25.2",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-import": "^0.0.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-webpack-plugin": "^4.0.1",
"ghooks": "^2.0.4",
"husky": "^8.0.3",
"jsdoc": "^4.0.2",
"karma": "^6.4.1",
"karma": "^6.4.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.2.1",
Expand All @@ -126,24 +124,26 @@
"mocha": "^10.2.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"nyc": "^15.1.0",
"prettier": "^2.8.7",
"prettier": "^3.0.1",
"randombytes": "^2.1.0",
"sinon": "^15.2.0",
"sinon-chai": "^3.7.0",
"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.9",
"terser-webpack-plugin": "^5.3.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"utility-types": "^3.7.0",
"webpack": "^5.88.1",
"webpack-cli": "^5.0.1"
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"axios": "^1.4.0",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
"detect-node": "^2.0.4",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "^9.0.0",
"stellar-base": "10.0.0-soroban.5",
"toml": "^3.0.0",
"urijs": "^1.19.1"
}
Expand Down
50 changes: 25 additions & 25 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
module.exports = {
env: {
es6: true,
es6: true
},
rules: {
// OFF
"import/prefer-default-export": 0,
"node/no-unsupported-features/es-syntax": 0,
"node/no-unsupported-features/es-builtins": 0,
'import/prefer-default-export': 0,
'node/no-unsupported-features/es-syntax': 0,
'node/no-unsupported-features/es-builtins': 0,
camelcase: 0,
"class-methods-use-this": 0,
"linebreak-style": 0,
"new-cap": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"prefer-destructuring": 0,
"lines-between-class-members": 0,
'class-methods-use-this': 0,
'linebreak-style': 0,
'new-cap': 0,
'no-param-reassign': 0,
'no-underscore-dangle': 0,
'no-use-before-define': 0,
'prefer-destructuring': 0,
'lines-between-class-members': 0,

// WARN
"prefer-import/prefer-import-over-require": [1],
"no-console": ["warn", { allow: ["assert"] }],
"no-debugger": 1,
"no-unused-vars": 1,
"arrow-body-style": 1,
"valid-jsdoc": [
'prefer-import/prefer-import-over-require': [1],
'no-console': ['warn', { allow: ['assert'] }],
'no-debugger': 1,
'no-unused-vars': 1,
'arrow-body-style': 1,
'valid-jsdoc': [
1,
{
requireReturnDescription: false,
},
requireReturnDescription: false
}
],
"prefer-const": 1,
"object-shorthand": 1,
"require-await": 1,
'prefer-const': 1,
'object-shorthand': 1,
'require-await': 1,

// ERROR
"no-unused-expressions": [2, { allowTaggedTemplates: true }],
},
'no-unused-expressions': [2, { allowTaggedTemplates: true }]
}
};
12 changes: 6 additions & 6 deletions src/horizon_axios_client.ts → src/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosResponse } from "axios";
import URI from "urijs";

/* tslint:disable-next-line:no-var-requires */
const version = require("../package.json").version;
export const version = require("../package.json").version;

export interface ServerTime {
serverTime: number;
Expand All @@ -23,7 +23,7 @@ export interface ServerTime {
*/
export const SERVER_TIME_MAP: Record<string, ServerTime> = {};

const HorizonAxiosClient = axios.create({
const AxiosClient = axios.create({
headers: {
"X-Client-Name": "js-stellar-sdk",
"X-Client-Version": version,
Expand All @@ -34,8 +34,8 @@ function _toSeconds(ms: number): number {
return Math.floor(ms / 1000);
}

HorizonAxiosClient.interceptors.response.use(
function interceptorHorizonResponse(response: AxiosResponse) {
AxiosClient.interceptors.response.use(
(response: AxiosResponse) => {
const hostname = URI(response.config.url!).hostname();
const serverTime = _toSeconds(Date.parse(response.headers.date));
const localTimeRecorded = _toSeconds(new Date().getTime());
Expand All @@ -48,10 +48,10 @@ HorizonAxiosClient.interceptors.response.use(
}

return response;
},
}
);

export default HorizonAxiosClient;
export default AxiosClient;

/**
* Given a hostname, get the current time of that server (i.e., use the last-
Expand Down
6 changes: 3 additions & 3 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* tslint:disable:no-var-requires */

export * from "./index";
export * as StellarBase from "stellar-base";
export * from './index';
export * as StellarBase from 'stellar-base';

import axios from "axios"; // idk why axios is weird
import axios from 'axios'; // idk why axios is weird
export { axios };

export default module.exports;
4 changes: 2 additions & 2 deletions src/call_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import URITemplate from "urijs/src/URITemplate";

import { BadRequestError, NetworkError, NotFoundError } from "./errors";
import { Horizon } from "./horizon_api";
import HorizonAxiosClient from "./horizon_axios_client";
import AxiosClient from "./axios";
import { ServerApi } from "./server_api";

/* tslint:disable-next-line:no-var-requires */
Expand Down Expand Up @@ -344,7 +344,7 @@ export class CallBuilder<
url = url.protocol(this.url.protocol());
}

return HorizonAxiosClient.get(url.toString())
return AxiosClient.get(url.toString())
.then((response) => response.data)
.catch(this._handleNetworkError);
}
Expand Down
37 changes: 18 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
// tslint:disable-next-line: no-reference
/// <reference path="../types/dom-monkeypatch.d.ts" />

/* tslint:disable:no-var-requires */
const version = require("../package.json").version;

// Expose all types
export * from "./horizon_api";
export * from "./server_api";
export * from './horizon_api';
export * from './server_api';

// stellar-sdk classes to expose
export * from "./account_response";
export * from "./errors";
export { Config } from "./config";
export { Server } from "./server";
export * from './account_response';
export * from './errors';
export { Config } from './config';
export { Server } from './server';
export {
FederationServer,
FEDERATION_RESPONSE_MAX_SIZE
} from "./federation_server";
FEDERATION_RESPONSE_MAX_SIZE,
} from './federation_server';
export {
StellarTomlResolver,
STELLAR_TOML_MAX_SIZE
} from "./stellar_toml_resolver";
STELLAR_TOML_MAX_SIZE,
} from './stellar_toml_resolver';
export {
default as HorizonAxiosClient,
default as AxiosClient,
SERVER_TIME_MAP,
getCurrentServerTime
} from "./horizon_axios_client";
export * from "./utils";
getCurrentServerTime,
version,
} from './axios';
export * from './utils';

// expose classes and functions from stellar-base
export * from "stellar-base";
export * from 'stellar-base';

export { version };
// expose all Soroban stuff
export * as SorobanClient from './soroban';

export default module.exports;
Loading
Loading