From afb85120e913993c193f36cf17b6abad99022258 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Tue, 24 Feb 2026 15:22:18 +0930 Subject: [PATCH 1/2] use typescript to generate .d.ts files --- index.d.ts | 4 ++++ package.json | 4 +++- tsconfig.json | 2 -- utils/helpers.d.ts | 19 +++++++++++++++++ utils/helpers.test.d.ts | 1 + utils/netsuite.d.ts | 46 ++++++++++++++++++++++++++++++++++++++++ utils/netsuite.test.d.ts | 1 + utils/sftp.d.ts | 30 ++++++++++++++++++++++++++ 8 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 index.d.ts create mode 100644 utils/helpers.d.ts create mode 100644 utils/helpers.test.d.ts create mode 100644 utils/netsuite.d.ts create mode 100644 utils/netsuite.test.d.ts create mode 100644 utils/sftp.d.ts 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..7a06ecd 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" @@ -13,7 +14,8 @@ "lint": "npx eslint .", "type-check": "tsc", "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; +}; From af6d25fee975c7ff5b2b35601d2f103cef17175b Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Tue, 24 Feb 2026 16:42:57 +0930 Subject: [PATCH 2/2] don't emit files in type check --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a06ecd..14b4ba7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "scripts": { "test": "node --test", "lint": "npx eslint .", - "type-check": "tsc", + "type-check": "tsc --noEmit", "format": "prettier --write \"**/*.js\"", "format-check": "prettier --check \"**/*.js\"", "generate-types": "tsc --allowJs --declaration --emitDeclarationOnly --outDir ."