JSPM

  • Created
  • Published
  • Downloads 62
  • Score
    100M100P100Q66244F
  • License MIT

Mock NetSuite API for testing SuiteQL queries without a NetSuite account

Package Exports

  • @scottybee84/mock-netsuite
  • @scottybee84/mock-netsuite/dist/server.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@scottybee84/mock-netsuite) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@scottybee84/mock-netsuite

Tiny local API to practice AI β†’ SuiteQL without a NetSuite account.

Built with TypeScript and compiled to JavaScript for production use. Features auto-seeding and a CLI for easy setup.

Prerequisites

⚠️ Important: Node.js Version

This package requires Node.js 18-22 (tested on 18/20/22). It will NOT work with Node.js 23+ due to better-sqlite3 ABI compatibility.

# Check your version
node --version

# If you need to switch (using nvm):
nvm install 20
nvm use 20

# Or install Volta for automatic switching:
# https://volta.sh
curl https://get.volta.sh | bash
volta pin node@20

πŸ’‘ For consuming projects: Install Volta to automatically use the correct Node version when working with this package.

Quick Start (Global Install)

npm install -g @scottybee84/mock-netsuite
mock-netsuite

The CLI will automatically:

  • βœ… Check Node.js version compatibility
  • πŸš€ Start the Mock NetSuite API
  • πŸ“Š Seed database with 500 customers + 2000 invoices (first run only)
  • 🌐 Launch server on port 3000 (or PORT env var)

Development Workflow

πŸš€ Quick Setup:

./dev.sh setup          # One-time setup
./dev.sh watch          # Auto-rebuild + restart on file changes

πŸ“ Manual Commands:

npm install
npm run build           # Compile TypeScript β†’ dist/
npm run dev:watch       # Watch TypeScript files for changes
npm run dev:cli         # Build and test CLI
npm run reset           # Reset database with fresh data
npm run dev             # Build and start server once

🎯 VS Code Integration:

  • Ctrl+Shift+P β†’ "Tasks: Run Task" β†’ "Watch TypeScript"
  • Ctrl+Shift+P β†’ "Tasks: Run Task" β†’ "Start CLI"

πŸ“¦ Publishing:

./dev.sh publish        # Automated: test β†’ build β†’ version β†’ publish β†’ git push
# OR manually:
npm run build && npm version patch && npm publish

API Usage

Query Endpoint

POST http://localhost:3000/query/v1/suiteql
Content-Type: application/json

{
  "query": "SELECT tranid,total,duedate,status FROM invoice WHERE status='Overdue' AND total > 10000 ORDER BY duedate ASC LIMIT 5;"
}

Record Lookups

  • Customer: GET /record/v1/customer/{id}
  • Invoice: GET /record/v1/invoice/{id}

Testing

# Health check
curl -s http://localhost:3000/health

# SuiteQL query example
curl -s -X POST http://localhost:3000/query/v1/suiteql \
  -H "Content-Type: application/json" \
  -d '{"query":"SELECT c.companyname, i.tranid, i.total FROM customer c JOIN invoice i ON c.id = i.customerid LIMIT 3;"}' | jq

Project Structure

  • src/ - TypeScript source files
    • cli.ts - Command-line interface with auto-seeding
    • server.ts - Express API server
    • seed.ts - Database seeding script
  • dist/ - Compiled JavaScript files (auto-generated)
  • schema.sql - SQLite database schema with NetSuite-style field names
  • tsconfig.json - TypeScript configuration

NetSuite-Style Fields

The database uses NetSuite internal ID conventions:

  • entityid (not entity_id)
  • companyname (not company_name)
  • tranid (not tran_id)
  • customerid (not customer_id)
  • duedate (not due_date)
  • datecreated (not created_at)

License

MIT - See LICENSE file for details. AI β†’ SuiteQL without a NetSuite account.

Built with TypeScript and compiled to JavaScript for production use.

Development

npm install
npm run build      # Compile TypeScript to dist/
npm run reset      # Reset database with fresh data
npm run dev        # Start server
npm run dev:watch  # Watch TypeScript files for changes

Query

POST http://localhost:3000/query/v1/suiteql

{ "query": "SELECT tranid,total,duedate,status FROM invoice WHERE status='Overdue' AND total > 10000 ORDER BY duedate ASC LIMIT 20;" }


STEP 2 β€” Install, run, verify

In VS Code terminal:

npm i
npm run seed
npm run dev


Test (Terminal or Postman):

curl -s -X POST http://localhost:3000/query/v1/suiteql \
  -H "Content-Type: application/json" \
  -d '{"query":"SELECT tranid,total,duedate,status FROM invoice WHERE status=''Overdue'' AND total > 10000 ORDER BY duedate ASC LIMIT 5;"}' | jq

## Version Compatibility

**Node.js Support:** This package supports Node.js 18-22 (tested on 18/20/22) with fail-fast version checking.

**ABI Compatibility:** Uses `better-sqlite3` which requires native compilation. Version constraints ensure compatibility across the tested Node.js matrix.

**Auto-Version Management:**
- **Volta users:** Run `volta pin node@20` in your consuming project for automatic version switching
- **nvm users:** Use the included `.nvmrc` file with `nvm use`
- **CI/CD:** The `engines` field in package.json enforces version constraints

**Installation Flow:**
1. `preinstall` hook runs `scripts/check-node.js` for immediate version verification
2. `postinstall` hook rebuilds native modules for your specific Node version
3. Helpful error messages guide users to version management solutions


You should see an items array of invoices.

Back in GitHub Desktop: commit β†’ β€œinit mock-netsuite” β†’ Publish repository (public).