UNPKG

dt-common-device

Version:

A secure and robust device management library for IoT applications

41 lines (40 loc) 1.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceHubService = void 0; const axios_1 = __importDefault(require("axios")); const config_1 = require("../../../config/config"); class DeviceHubService { constructor() { const { DEVICE_SERVICE } = (0, config_1.getConfig)(); if (!DEVICE_SERVICE) { throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE."); } this.baseUrl = DEVICE_SERVICE; } async addHub(body) { return await axios_1.default.post(`${this.baseUrl}/devices/hubs`, body); } //get hubs takes an array of hub ids as query params async getHubs(hubIds) { const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : ""; return await axios_1.default.get(`${this.baseUrl}/devices/hubs${query}`); } //get hub takes a hub id in params async getHub(hubId) { return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}`); } async updateHub(hubId, body) { return await axios_1.default.put(`${this.baseUrl}/devices/hubs/${hubId}`, body); } async deleteHub(hubId) { return await axios_1.default.delete(`${this.baseUrl}/devices/hubs/${hubId}`); } async deleteAllHubs(hubIds) { const query = hubIds.length ? `?ids=${hubIds.join(",")}` : ""; return await axios_1.default.delete(`${this.baseUrl}/devices/hubs${query}`); } } exports.DeviceHubService = DeviceHubService;