@jonusnattapong/fuel-sdk
v1.0.1
Published
DOEB Fuel Inventory API client SDK for Node.js
Readme
@doeb/fuel-sdk
DOEB Fuel Inventory API v2 Client SDK for JavaScript/Node.js.
Installation
npm install @doeb/fuel-sdkUsage
1. Initialization
const { FuelSDK } = require('@doeb/fuel-sdk');
const api = new FuelSDK({
apiKey: 'YOUR_API_KEY_HERE',
environment: 'staging', // 'prod' | 'staging'
autoRetry: true, // Enable auto-retry on transient errors (default: true)
timeout: 30000 // Request timeout in ms (default: 30000)
});2. Submit Daily Remaining Fuel
async function submitData() {
try {
const result = await api.fuel.submit([
{ tank_id: '1', remaining_fuel: 5500.25 },
{ tank_id: '2', remaining_fuel: 3200.00 }
]);
console.log('Submission Success:', result);
// Output: { success: true, count: 2, ref_id: 'uuid' }
} catch (err) {
console.error('Submission Failed:', err.message, 'Code:', err.code);
}
}3. Get Fuel Submission History
async function getHistory() {
try {
const history = await api.fuel.history({
page: 1,
limit: 10,
from: '2026-06-01T00:00:00Z',
to: '2026-06-05T23:59:59Z'
});
console.log('History:', history);
} catch (err) {
console.error('Fetch History Failed:', err.message);
}
}4. Fetch Master Data
async function fetchMasters() {
try {
const provinces = await api.masters.getProvinces();
const regions = await api.masters.getRegions();
const tanks = await api.masters.getTanks({ depot_id: 'DEPOT123' });
console.log('Provinces:', provinces.data);
console.log('Regions:', regions.data);
console.log('Tanks:', tanks.data);
} catch (err) {
console.error('Fetch Masters Failed:', err.message);
}
}React / TSX Integration
The SDK comes with built-in React components and hooks to easily integrate with React (v16.8+) applications:
import React from 'react';
import { FuelProvider, useFuelSDK } from '@doeb/fuel-sdk/react';
const sdkOptions = {
apiKey: 'YOUR_API_KEY_HERE',
environment: 'staging' as const
};
export function App() {
return (
<FuelProvider options={sdkOptions}>
<MyComponent />
</FuelProvider>
);
}
function MyComponent() {
const api = useFuelSDK();
const handleFetch = async () => {
const provinces = await api.masters.getProvinces();
console.log(provinces);
};
return <button onClick={handleFetch}>Load Provinces</button>;
}