Skip to content

Commit

Permalink
fix #19 target modern JS modules (#30)
Browse files Browse the repository at this point in the history
* target modern JS modules

* fix #27: fix esm import issue

* fix unit tests after cjs -> esm migration
osdevisnot authored Mar 6, 2024
1 parent a79a21f commit 40448b6
Showing 19 changed files with 66 additions and 56 deletions.
13 changes: 9 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
const config = {
preset: 'ts-jest',
setupFiles: ["dotenv/config"],
setupFiles: ['dotenv/config'],
testEnvironment: 'node',
transform: {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/']
};
moduleNameMapper: {
'(.+)\\.js': '$1',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
};

export default config;
8 changes: 4 additions & 4 deletions lib/account-streamer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import WebSocket from 'isomorphic-ws'
import _ from 'lodash'
import type { JsonMap, JsonValue } from './utils/json-util'
import { JsonBuilder } from './utils/json-util'
import TastytradeSession from './models/tastytrade-session'
import { MinTlsVersion } from './utils/constants'
import type { JsonMap, JsonValue } from './utils/json-util.js'
import { JsonBuilder } from './utils/json-util.js'
import TastytradeSession from './models/tastytrade-session.js'
import { MinTlsVersion } from './utils/constants.js'

export enum STREAMER_STATE {
Open = 0,
2 changes: 1 addition & 1 deletion lib/market-data-streamer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import WebSocket from 'isomorphic-ws'
import _ from 'lodash'
import { v4 as uuidv4 } from 'uuid'
import { MinTlsVersion } from './utils/constants'
import { MinTlsVersion } from './utils/constants.js'

export enum MarketDataSubscriptionType {
Candle = 'Candle',
4 changes: 2 additions & 2 deletions lib/services/account-status-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

// create the central class that aggregates all services
export default class AccountStatusService {
4 changes: 2 additions & 2 deletions lib/services/accounts-and-customers-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class AccountsAndCustomersService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/balances-and-positions-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class BalancesAndPositionsService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/instruments-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";
import _ from 'lodash'

export default class InstrumentsService {
4 changes: 2 additions & 2 deletions lib/services/margin-requirements-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class MarginRequirementsService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/market-metrics-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class MarketMetricsService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/net-liquidating-value-history-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class NetLiquidatingValueHistoryService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/orders-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class OrderService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/risk-parameters-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class RiskParametersService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/session-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class SessionService {
constructor(public httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/symbol-search-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class SymbolSearchService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/tastytrade-http-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TastytradeSession from "../models/tastytrade-session"
import TastytradeSession from "../models/tastytrade-session.js"
import axios from "axios"
import qs from 'qs'
import { recursiveDasherizeKeys } from "../utils/json-util"
import { recursiveDasherizeKeys } from "../utils/json-util.js"
import _ from 'lodash'

const ParamsSerializer = {
4 changes: 2 additions & 2 deletions lib/services/transactions-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class TransactionsService {
constructor(private httpClient: TastytradeHttpClient) {
4 changes: 2 additions & 2 deletions lib/services/watchlists-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import extractResponseData from "../utils/response-util";
import TastytradeHttpClient from "./tastytrade-http-client";
import extractResponseData from "../utils/response-util.js";
import TastytradeHttpClient from "./tastytrade-http-client.js";

export default class WatchlistsService {
constructor(private httpClient: TastytradeHttpClient) {
34 changes: 17 additions & 17 deletions lib/tastytrade-api.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import TastytradeHttpClient from "./services/tastytrade-http-client"
import { AccountStreamer, STREAMER_STATE, Disposer, StreamerStateObserver } from './account-streamer'
import MarketDataStreamer, { CandleSubscriptionOptions, CandleType, MarketDataSubscriptionType, MarketDataListener } from "./market-data-streamer"
import TastytradeHttpClient from "./services/tastytrade-http-client.js"
import { AccountStreamer, STREAMER_STATE, Disposer, StreamerStateObserver } from './account-streamer.js'
import MarketDataStreamer, { CandleSubscriptionOptions, CandleType, MarketDataSubscriptionType, MarketDataListener } from "./market-data-streamer.js"

//Services:
import SessionService from "./services/session-service"
import AccountStatusService from "./services/account-status-service"
import AccountsAndCustomersService from "./services/accounts-and-customers-service"
import BalancesAndPositionsService from "./services/balances-and-positions-service"
import InstrumentsService from "./services/instruments-service"
import MarginRequirementsService from "./services/margin-requirements-service"
import MarketMetricsService from "./services/market-metrics-service"
import NetLiquidatingValueHistoryService from "./services/net-liquidating-value-history-service"
import OrderService from "./services/orders-service"
import RiskParametersService from "./services/risk-parameters-service"
import SymbolSearchService from "./services/symbol-search-service"
import TransactionsService from "./services/transactions-service"
import WatchlistsService from "./services/watchlists-service"
import TastytradeSession from "./models/tastytrade-session"
import SessionService from "./services/session-service.js"
import AccountStatusService from "./services/account-status-service.js"
import AccountsAndCustomersService from "./services/accounts-and-customers-service.js"
import BalancesAndPositionsService from "./services/balances-and-positions-service.js"
import InstrumentsService from "./services/instruments-service.js"
import MarginRequirementsService from "./services/margin-requirements-service.js"
import MarketMetricsService from "./services/market-metrics-service.js"
import NetLiquidatingValueHistoryService from "./services/net-liquidating-value-history-service.js"
import OrderService from "./services/orders-service.js"
import RiskParametersService from "./services/risk-parameters-service.js"
import SymbolSearchService from "./services/symbol-search-service.js"
import TransactionsService from "./services/transactions-service.js"
import WatchlistsService from "./services/watchlists-service.js"
import TastytradeSession from "./models/tastytrade-session.js"

export default class TastytradeClient {
public readonly httpClient: TastytradeHttpClient
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "@tastytrade/api",
"version": "3.1.0",
"main": "dist/tastytrade-api.js",
"typings": "dist/tastytrade-api.d.ts",
"type": "module",
"module": "dist/tastytrade-api.js",
"types": "dist/tastytrade-api.d.ts",
"exports": {
"types": "./dist/tastytrade-api.d.ts",
"default": "./dist/tastytrade-api.js"
},
"repository": "https://github.com/tastytrade/tastytrade-api-js",
"license": "MIT",
"description": "Typescript impelementation of tastytrade api",

0 comments on commit 40448b6

Please sign in to comment.