diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..99af2f1 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ +import * as helpers from './utils/helpers.js'; +import * as netsuite from './utils/netsuite.js'; +import * as sftp from './utils/sftp.js'; +export { helpers, netsuite, sftp }; diff --git a/package.json b/package.json index 49045f7..14b4ba7 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "version": "0.3.0", "description": "Utilities to be used in Pipedream as NPM dependencies", "main": "index.js", + "types": "index.d.ts", "files": [ "utils", "!utils/*.test.js" @@ -11,9 +12,10 @@ "scripts": { "test": "node --test", "lint": "npx eslint .", - "type-check": "tsc", + "type-check": "tsc --noEmit", "format": "prettier --write \"**/*.js\"", - "format-check": "prettier --check \"**/*.js\"" + "format-check": "prettier --check \"**/*.js\"", + "generate-types": "tsc --allowJs --declaration --emitDeclarationOnly --outDir ." }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 0d695a4..9db6311 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,6 @@ "baseUrl": ".", "allowJs": true, "checkJs": true, - "noEmit": true, "strict": false, "lib": ["ES2021", "DOM"], @@ -14,4 +13,3 @@ "include": ["**/*.js"], "exclude": ["node_modules"] } - diff --git a/utils/helpers.d.ts b/utils/helpers.d.ts new file mode 100644 index 0000000..6b4b602 --- /dev/null +++ b/utils/helpers.d.ts @@ -0,0 +1,19 @@ +/** + * Returns a Date object with the end_of_month.beginning_of_day from a Date Time + * @param {Date | string} date + * @return {Date} + */ +export function lastDay(date: Date | string): Date; +/** + * Normalize strings + * @param {string | undefined} v + * @returns {string} + */ +export function normalizeString(v: string | undefined): string; +/** + * Check if string starts with a prefix + * @param {string} val + * @param {string} prefix + * @returns {boolean} + */ +export function startsWith(val: string, prefix: string): boolean; diff --git a/utils/helpers.test.d.ts b/utils/helpers.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/utils/helpers.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/utils/netsuite.d.ts b/utils/netsuite.d.ts new file mode 100644 index 0000000..d9251bd --- /dev/null +++ b/utils/netsuite.d.ts @@ -0,0 +1,46 @@ +/** + * Represents the NetSuite OAuth configuration. + * @typedef {import('netsuite-api-client').NetsuiteOptions} Config + */ +/** + * Options for a NetSuite request. See https://github.com/julbrs/netsuite-api-client/blob/main/src/types.ts + * @typedef {import('netsuite-api-client').NetsuiteRequestOptions} Options - Request options + */ +/** + * Gets the portion of the URL starting with '/record'. Used to obtain a GET query path from the "location" response + * header on a NetSuite POST request. + * @param {string | string[]} url + * @returns {string} + */ +export function getRecordPath(url: string | string[]): string; +/** + * Send a request to NetSuite + * @param {Options} options - Request options + * @param {Config} config - NetSuite configuration + * @returns {Promise} + */ +export function request(options: Options, config: Config): Promise; +/** + * Run a SuiteQL query to get a specific (single) NetSuite record. + * @param {string} query - SuiteQL Query + * @param {Config} config - NetSuite configuration + * @returns {Promise} + */ +export function queryRecord(query: string, config: Config): Promise; +/** + * Run a SuiteQL query against NetSuite records. + * @param {string} query - SuiteQL Query + * @param {Config} config - NetSuite configuration + * @param {?Number} timeout - The timeout in seconds + * @param {Number} timeoutRecords - The maximum number of records to return before timing out + * @returns {Promise} + */ +export function queryRecords(query: string, config: Config, timeout?: number | null, timeoutRecords?: number): Promise; +/** + * Represents the NetSuite OAuth configuration. + */ +export type Config = import("netsuite-api-client").NetsuiteOptions; +/** + * - Request options + */ +export type Options = import("netsuite-api-client").NetsuiteRequestOptions; diff --git a/utils/netsuite.test.d.ts b/utils/netsuite.test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/utils/netsuite.test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/utils/sftp.d.ts b/utils/sftp.d.ts new file mode 100644 index 0000000..a0ff360 --- /dev/null +++ b/utils/sftp.d.ts @@ -0,0 +1,30 @@ +/** + * @typedef {Object} SftpConfig + * @property {string} host + * @property {string} username + * @property {string} privateKey + */ +/** + * @typedef {Object} SftpResponse + * @property {string} message + * @property {string} error + * @property {boolean} successful + */ +/** + * Moves a file by its path to a new destination on an SFTP host. Returns an error or success message. + * @param {string} filePath - The path to the local file to upload + * @param {string} dest - The path to the destination file on the remote server including the new name + * @param {SftpConfig} sftpConfig - SFTP authentication details + * @returns {Promise} - { message: string, error: string, successful: boolean } + */ +export function renameSftpFile(filePath: string, dest: string, sftpConfig: SftpConfig): Promise; +export type SftpConfig = { + host: string; + username: string; + privateKey: string; +}; +export type SftpResponse = { + message: string; + error: string; + successful: boolean; +};