התקנה
npm install @yehuda-water/sdk
העתק
yarn add @yehuda-water/sdk
העתק
✓
WebSocket telemetry stream
✓
Auto-retry + exponential backoff
✓
Tree-shakeable, ESM + CJS
דוגמת קוד — שליחת בדיקה
import { WaterEnergyClient } from '@yehuda-water/sdk' ;
const client = new WaterEnergyClient ({
apiKey: 'wek_live_xxxxxxxxxxxx'
});
// שליחת תוצאת בדיקת נצילות
const result = await client.pumpTests.create({
stationId: 'ST-MEI-001' ,
pumpId: 'P-003' ,
testDate: new Date (),
flowM3h: 285.4 ,
headM: 42.8 ,
powerKw: 45.2
});
console.log(`נצילות: ${result.efficiencyPct} %` ); // נצילות: 78.3%
console.log(`סטטוס: ${result.regulatoryStatus} ` ); // סטטוס: PASS
TypeScript — Types מובנים
import { WaterEnergyClient , PumpTestResult , Station } from '@yehuda-water/sdk' ;
const client = new WaterEnergyClient ({ apiKey: process.env.WATER_API_KEY ! });
// TypeScript knows the shape of every response
const stations: Station [] = await client.stations.list({ status: 'active' });
stations.forEach((s: Station ) => {
if (s.avgEfficiencyPct < 65 ) {
console.warn(`⚠ ${s.name} — נצילות נמוכה: ${s.avgEfficiencyPct} %` );
}
});
Telemetry Stream — WebSocket
// Subscribe to real-time telemetry stream
const stream = client.telemetry.stream({
gatewayId: 'GW-DALTON-01' ,
sensors: ['FLOW-001' , 'PWR-001' , 'PRESS-001' ]
});
stream.on('reading' , (reading) => {
console.log(`[${reading.sensorId} ] ${reading.metric} : ${reading.value} ` );
});
stream.on('anomaly' , (alert) => {
console.error(`🚨 אנומליה: ${alert.description} ` );
});
stream.connect();
// stream.disconnect(); // לסגירה
Webhook Handler — Node.js Express
import express from 'express' ;
import { verifyWebhookSignature } from '@yehuda-water/sdk' ;
const app = express();
app.use(express.raw({ type: 'application/json' }));
app.post('/hooks/water-energy' , (req, res) => {
const valid = verifyWebhookSignature (
req.body,
req.headers['x-wek-signature' ] as string,
process.env.WEBHOOK_SECRET !
);
if (!valid) return res.status(401 ).send('Unauthorized' );
const event = JSON.parse(req.body.toString());
console.log(`אירוע: ${event.event} ` );
res.status(200 ).json({ received: true });
});
app.listen(3000 );
github.com/yehuda-buju/yehuda-water-sdk-js
JavaScript/TypeScript SDK — Source code, Issues, PRs
בקרוב