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

Add basic typescript definitions #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
97 changes: 97 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
declare module 'nsrestlet' {

interface BasicSettings {
/**
* You NetSuite Account ID. Also known as realm
*/
accountId: number | string
}

/**
* OAuth requires `accountId`, a `Consumer Key-Secret Pair` (Found on the Integrations page in Netsuite), and a `Token Key-Secret Pair` (Found on the Tokens page in Netsuite).
*/
interface OAuthSettings extends BasicSettings {
tokenKey: string,
tokenSecret: string,
consumerKey: string,
consumerSecret: string,
}

/**
* NLAuth requires an `email` and `password`. It also allows us to
* specifiy a `role`, which isn't required but is highly reccomended.
*/
interface NLAuthSettings extends BasicSettings {
email: string,
password: string,

/**
* Recommended.
*/
role?: number | string,
}

/**
* If a retryable error occurs and `backoff` and `retries` properties
* are provided, it will keep requesting until a successful resolution
* or the provided limits are reached. Otherwise, an error is returned
* instead.
*
* Retryable errors:
* - `ECONNRESET`
* - `ESOCKETTIMEDOUT`
* - `ETIMEDOUT`
* - `SSS_REQUEST_LIMIT_EXCEEDED`
*/
interface ErrorRetryURLSettings {
/**
* The amount of time, in milliseconds, to exponentially backoff on
* each retry.
*/
backoff?: number,

/**
* The number of times to retry the request if an error is returned.
*/
retries?: number,
}

interface DeriveURLSettings extends ErrorRetryURLSettings {
/**
* Script Id
*/
script: number | string,

/**
* Deployment Id
*/
deployment: number | string
}

interface URLSettings extends ErrorRetryURLSettings {
/**
* Valid URL Like:
* > https://**accountId**.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=**scriptId**&deploy=**deploymentId**
*/
url: string
}

interface HTTPFacade {
get(payload: any, callback: (error: any, response: any) => void): void,
get(payload: any): Promise<any>,

post(payload: any, callback: (error: any, response: any) => void): void,
post(payload: any): Promise<any>,

put(payload: any, callback: (error: any, response: any) => void): void,
put(payload: any): Promise<any>,

delete(payload: any, callback: (error: any, response: any) => void): void,
delete(payload: any): Promise<any>,
}

function createLink(
accountSettings: OAuthSettings | NLAuthSettings,
urlSettings: URLSettings | DeriveURLSettings
): HTTPFacade;
}