npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

em-gateway-sdk

v1.0.1

Published

JavaScript SDK for the EM-Gateway fuel inventory API

Readme

EM-Gateway JavaScript SDK

Client library for the EM-Gateway fuel inventory management API.

The SDK accepts the API encryption key as either 64 hexadecimal characters (the format returned by EM-Gateway) or a 32-character UTF-8 string.

Installation

npm install em-gateway-sdk

Usage

Setup

const EMGatewayClient = require('em-gateway-sdk');

const client = new EMGatewayClient({
  baseUrl: 'http://your-api-host:3000',
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
});

OAuth2 Token Flow

// Step 1: Get authorization URL
const authUrl = client.getAuthorizationUrl({
  redirectUri: 'http://localhost:3000',
  scope: 'tank_id storage_name remaining_fuel',
});
console.log('Visit:', authUrl);

// Step 2: After user authorizes, exchange code for token
const token = await client.exchangeAuthorizationCode({
  code: 'authorization-code-from-redirect',
  redirectUri: 'http://localhost:3000',
});

// Step 3: Set the token
client.setBearerToken(token.access_token);

Submit Fuel Data (Encrypted)

const testData = {
  code: 'FUEL-001',
  tank_id: 'TANK-001',
  storage_name: 'Storage A',
  storage_owner: 'Owner',
  storage_type: 'Type',
  fuel_type: 'Diesel',
  tank_capacity: 50000,
  dead_stock: 100,
  remaining_fuel: 25000,
  source: 1,
};

const result = await client.submitEncryptedFuelInventory(
  testData,
  'encryption-key-32-characters!!!',
  {
    clientId: 'your-client-id',
    count: 1,
  }
);
console.log(result);
// { success: true, message: '...', count: 1 }

Dry-Run Mode (Test Without Saving)

Test your data submission without writing to the database. The API decrypts and validates your data, then returns a preview — useful for testing before going live.

const result = await client.submitEncryptedFuelInventory(
  testData,
  'encryption-key-32-characters!!!',
  {
    clientId: 'your-client-id',
    count: 1,
    dryRun: true, // ← enables dry-run mode
  }
);

if (result.dry_run) {
  console.log('✅ Validation passed!');
  console.log('Preview:', result.preview);
  // No data was saved to database
}

Dry-Run Response (Success)

{
  "success": true,
  "dry_run": true,
  "message": "ข้อมูลผ่านการตรวจสอบทั้งหมด 1 รายการ (Dry-Run — ไม่ได้บันทึกลงฐานข้อมูล)",
  "count": 1,
  "preview": [
    {
      "code": "FUEL-001",
      "tank_id": "TANK-001",
      "storage_name": "Storage A",
      "remaining_fuel": 25000
    }
  ]
}

Dry-Run Response (Validation Error)

{
  "success": false,
  "dry_run": true,
  "message": "ข้อมูลไม่ผ่านการตรวจสอบ (Dry-Run)",
  "validation_errors": [
    { "index": 1, "missing_fields": ["tank_id", "fuel_type"] }
  ],
  "total_records": 1,
  "error_count": 1,
  "valid_count": 0
}

Master Data

const provinces = await client.request('/api/master/getProvince', {
  method: 'POST',
  body: {},
});

const regions = await client.request('/api/master/getRegion', {
  method: 'POST',
  body: {},
});

const tanks = await client.getStorageLocationTank({});

Health Check

const health = await client.health();
// { status: 'healthy', service: 'api-gateway', timestamp: '...' }

API Methods

| Method | Description | |--------|-------------| | getAuthorizationUrl(opts) | Generate OAuth2 authorization URL | | exchangeAuthorizationCode(opts) | Exchange auth code for token | | exchangeClientCredentials(opts) | Get token via client credentials | | setBearerToken(token) | Set the JWT access token | | submitFuelInventory(payload) | Submit raw fuel data (POST) | | submitEncryptedFuelInventory(data, key, opts) | Submit encrypted fuel data | | encryptFuelPayload(data, key) | Encrypt data with AES-256-CBC | | getStorageLocationTank(payload) | Get storage location tanks | | health() | Server health check | | request(path, opts) | Generic API request |

Environment Variables

EM_GATEWAY_URL=http://your-api-host:3000
EM_GATEWAY_CLIENT_ID=your-client-id
EM_GATEWAY_CLIENT_SECRET=your-client-secret