Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds typings (#37)
* fix: add typings

* fix: response type
  • Loading branch information
efredin authored and abisalehalliprasan committed Oct 18, 2019
commit fb84163fa654a4ee0240d9e47592517b7b06742e
143 changes: 143 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import csrf from 'csrf';

declare class AuthResponse {
constructor(params: AuthResponse.AuthResponseParams);
getToken(): Token;
text(): string;
status(): number;
headers(): Object;
valid(): boolean;
getJson(): Object;
get_intuit_tid(): string;
}

declare namespace AuthResponse {
export interface AuthResponseParams {
token?: Token;
response?: Response;
body?: string;
json?: Object;
intuit_tid?: string;
}
}

declare class Token implements Token.TokenData {
latency: number;
accessToken(): string;
refreshToken(): string;
tokenType(): string;
getToken(): Token.TokenData;
setToken(tokenData: Token.TokenData): Token;
clearToken(): Token;
isAccessTokenValid(): boolean;
isRefreshTokenValid(): boolean;
}

declare namespace Token {
export interface TokenData {
realmId: string;
token_type: string;
access_token: string;
refresh_token: string;
expires_in: number;
x_refresh_token_expires_in: number;
id_token: string;
createdAt: string;
}
}

declare class OAuthClient {
constructor(config: OAuthClient.OAuthClientConfig);
authHeader(): string;
authorizeUri(params: OAuthClient.AuthorizeParams): string;
createError(e: Error, authResponse?: AuthResponse): OAuthClient.OAuthClientError;
createToken(uri: string): Promise<AuthResponse>;
generateOauth1Sign(params: OAuthClient.GenerateOAuth1SignParams): string;
getKeyFromJWKsURI(id_token: string, kid: string, request: Request): Promise<object | string>;
getPublicKey(modulus: string, exponent: string): string;
getToken(): Token;
getTokenRequest(request: Request): Promise<AuthResponse>;
getUserInfo(params?: OAuthClient.GetUserInfoParams): Promise<AuthResponse>;
isAccessTokenValid(): boolean;
loadResponse(request: Request): Promise<Response>;
loadResponseFromJWKsURI(request: Request): Promise<Response>;
log(level: string, message: string, messageData: any): void;
makeApiCall(params?: OAuthClient.MakeApiCallParams): Promise<AuthResponse>;
migrate(params: OAuthClient.MigrateParams): Promise<AuthResponse>;
refresh(): Promise<AuthResponse>;
refreshUsingToken(refresh_token: string): Promise<AuthResponse>;
revoke(params?: OAuthClient.RevokeParams): Promise<AuthResponse>;
setToken(params: Token.TokenData): Token;
validateIdToken(params: OAuthClient.ValidateIdTokenParams): Promise<Response>;
validateToken(): void;
}

declare namespace OAuthClient {
export interface OAuthClientConfig {
environment: string;
appSecret: string;
appKey: string;
cachePrefix?: string;
}

export enum Environment {
sandbox = 'https://sandbox-quickbooks.api.intuit.com/',
production = 'https://quickbooks.api.intuit.com/'
}

export enum AuthorizeScope {
Accounting = 'com.intuit.quickbooks.accounting',
Payment = 'com.intuit.quickbooks.payment',
Payroll = 'com.intuit.quickbooks.payroll',
TimeTracking = 'com.intuit.quickbooks.payroll.timetracking',
Benefits = 'com.intuit.quickbooks.payroll.benefits',
Profile = 'profile',
Email = 'email',
Phone = 'phone',
Address = 'address',
OpenId = 'openid',
Intuit_name = 'intuit_name'
}

export interface AuthorizeParams {
scope: AuthorizeScope | AuthorizeScope[] | string;
state?: csrf;
}

export interface RevokeParams {
access_token?: string;
refresh_token?: string;
}

export interface GetUserInfoParams { }

export interface MakeApiCallParams {
url: string;
}

export interface MigrateParams extends GenerateOAuth1SignParams {
scope?: AuthorizeScope | AuthorizeScope[] | string;
}

export interface GenerateOAuth1SignParams {
oauth_consumer_key: string;
oauth_consumer_secret: string;
access_token: string;
access_secret: string;
method: 'GET' | 'POST';
uri: string;
}

export interface ValidateIdTokenParams {
id_token?: string;
}

export interface OAuthClientError extends Error {
intuit_tid: string;
authResponse: AuthResponse;
originalMessage: string;
error_description: string;
}
}

export = OAuthClient;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.5.0",
"description": "Intuit Node.js client for OAuth2.0 and OpenID",
"main": "./src/OAuthClient.js",
"types": "./index.d.ts",
"scripts": {
"start": "node index.js",
"karma": "karma start karma.conf.js",
Expand Down