-
-
Save Yumshot/33e0d155ff9dc84bd838e7ec8836778f to your computer and use it in GitHub Desktop.
???
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AxiosInstance } from 'axios'; | |
import { SubmitTokenResponse } from './types'; | |
declare class TDAmeritrade { | |
CONSUMER_KEY: string; | |
client: AxiosInstance; | |
refreshToken: string | undefined; | |
constructor(consumerKey: string); | |
submitAuthToken(token: string, offline: boolean, redirectUri: string): Promise<SubmitTokenResponse>; | |
getNewAccessToken(): Promise<SubmitTokenResponse>; | |
getOauthLink(redirectUri: string): string; | |
} | |
export = TDAmeritrade; |
Author
Yumshot
commented
Apr 29, 2022
•
Hello, Shock here
This should fix it:
declare module "package-name" {
declare class TDAmeritrade {
CONSUMER_KEY: string;
client: AxiosInstance;
refreshToken: string | undefined;
constructor(consumerKey: string);
submitAuthToken(token: string, offline: boolean, redirectUri: string): Promise<SubmitTokenResponse>;
getNewAccessToken(): Promise<SubmitTokenResponse>;
getOauthLink(redirectUri: string): string;
}
export = TDAmeritrade;
}
Hello, Shock here
This should fix it:
declare module "package-name" { declare class TDAmeritrade { CONSUMER_KEY: string; client: AxiosInstance; refreshToken: string | undefined; constructor(consumerKey: string); submitAuthToken(token: string, offline: boolean, redirectUri: string): Promise<SubmitTokenResponse>; getNewAccessToken(): Promise<SubmitTokenResponse>; getOauthLink(redirectUri: string): string; } export = TDAmeritrade; }
after looking through the package , ive realized i can just yoink it all out myself and just recreate the classes. No dependencies or secrets
Thank you for your help tho.
interface TDAProps {}
interface TDAState {}
import { Logger } from '@nestjs/common';
import axios from 'axios';
class TDA {
CONSUMER_KEY: string;
client: any;
refreshToken: any;
constructor(consumerKey: string) {
this.CONSUMER_KEY = consumerKey;
this.client = axios.create({ baseURL: 'https://api.tdameritrade.com/v1' });
}
async submitAuthToken(token: string, offline: boolean, redirectURI: string) {
try {
const response = (
await this.client.post(
'/oauth2/token',
JSON.stringify({
grant_type: 'authorization_code',
redirect_uri: redirectURI,
code: decodeURIComponent(token),
offline: offline ? 'offline' : '',
client_id: `${this.CONSUMER_KEY}@AMER.OAUTHAP`,
}),
)
).data;
this.client.defaults.headers.common[
'Authorization'
] = `Bearer ${response.access_token}`;
this.refreshToken = response.refresh_token;
Logger.log('Token: ', response);
return response;
} catch (error) {
return Logger.error(error);
}
}
}
export default TDA;
Cool!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment