@xube/kit-device 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import { XubeResponse } from "@xube/kit-request";
2
+ export declare const sendCommandsToDevice: (device: string, commands: Record<string, string>) => Promise<XubeResponse<boolean>>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendCommandsToDevice = void 0;
4
+ const kit_request_1 = require("@xube/kit-request");
5
+ const kit_constants_1 = require("@xube/kit-constants");
6
+ const constants_1 = require("../constants");
7
+ const sendCommandsToDevice = async (device, commands) => {
8
+ console.log(`Sending commands to device ${device}:`, commands);
9
+ try {
10
+ return (0, kit_request_1.xubePostRequest)({
11
+ device,
12
+ commands,
13
+ }, kit_request_1.XUBE_BASE_API_URL + constants_1.DEVICES_BASE_PATH + constants_1.COMMANDS_PATH, kit_request_1.contentTypeJSONHeader);
14
+ }
15
+ catch (e) {
16
+ console.log("Failed to send commands to device", e);
17
+ return new kit_request_1.XubeResponse({
18
+ statusCode: kit_constants_1.StatusCode.BadRequest,
19
+ error: "Failed to send commands to device",
20
+ });
21
+ }
22
+ };
23
+ exports.sendCommandsToDevice = sendCommandsToDevice;
@@ -0,0 +1,4 @@
1
+ export declare const DEVICES_BASE_PATH = "/devices";
2
+ export declare const COMMANDS_PATH = "/commands";
3
+ export declare const ENGINE_PATH = "/engine";
4
+ export declare const RESTART_PATH = "/restart";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESTART_PATH = exports.ENGINE_PATH = exports.COMMANDS_PATH = exports.DEVICES_BASE_PATH = void 0;
4
+ exports.DEVICES_BASE_PATH = "/devices";
5
+ exports.COMMANDS_PATH = "/commands";
6
+ exports.ENGINE_PATH = "/engine";
7
+ exports.RESTART_PATH = "/restart";
@@ -0,0 +1,2 @@
1
+ import { XubeResponse } from "@xube/kit-request";
2
+ export declare const restartDeviceEngine: (device: string) => Promise<XubeResponse<boolean>>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restartDeviceEngine = void 0;
4
+ const kit_request_1 = require("@xube/kit-request");
5
+ const kit_constants_1 = require("@xube/kit-constants");
6
+ const constants_1 = require("../constants");
7
+ const restartDeviceEngine = async (device) => {
8
+ console.log(`Attempting to restart device engine: ${device}`);
9
+ try {
10
+ return (0, kit_request_1.xubePostRequest)({
11
+ device,
12
+ }, kit_request_1.XUBE_BASE_API_URL + constants_1.DEVICES_BASE_PATH + constants_1.ENGINE_PATH, kit_request_1.contentTypeJSONHeader);
13
+ }
14
+ catch (e) {
15
+ console.log("Failed to restart device engine", e);
16
+ return new kit_request_1.XubeResponse({
17
+ statusCode: kit_constants_1.StatusCode.BadRequest,
18
+ error: `Error occurred when restarting the device engine of device: ${device}.`,
19
+ });
20
+ }
21
+ };
22
+ exports.restartDeviceEngine = restartDeviceEngine;
@@ -0,0 +1,4 @@
1
+ export * from "./command/send";
2
+ export * from "./engine/restart";
3
+ export * from "./constants";
4
+ export * from "./reset";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./command/send"), exports);
18
+ __exportStar(require("./engine/restart"), exports);
19
+ __exportStar(require("./constants"), exports);
20
+ __exportStar(require("./reset"), exports);
@@ -0,0 +1 @@
1
+ export declare const restartDevice: () => void;
package/dist/reset.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restartDevice = void 0;
4
+ const restartDevice = () => {
5
+ };
6
+ exports.restartDevice = restartDevice;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@xube/kit-device",
3
+ "version": "0.0.22",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "generate": "npx ts-node src/generator.ts"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+ssh://git@github.com/XubeLtd/dev-kit.git"
13
+ },
14
+ "author": "Xube Pty Ltd",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/XubeLtd/dev-kit/issues"
18
+ },
19
+ "homepage": "https://github.com/XubeLtd/dev-kit#readme",
20
+ "devDependencies": {
21
+ "@types/node": "^20.4.7",
22
+ "@xube/kit-build": "^0.0.22",
23
+ "ts-node": "^10.9.1",
24
+ "typescript": "^5.1.6"
25
+ },
26
+ "dependencies": {
27
+ "@xube/kit-generator": "^0.0.22",
28
+ "@xube/kit-log": "^0.0.22",
29
+ "@xube/kit-request": "^0.0.22"
30
+ }
31
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ XUBE_BASE_API_URL,
3
+ XubeResponse,
4
+ contentTypeJSONHeader,
5
+ xubePostRequest,
6
+ } from "@xube/kit-request";
7
+ import { StatusCode } from "@xube/kit-constants";
8
+ import { COMMANDS_PATH, DEVICES_BASE_PATH } from "../constants";
9
+
10
+ export const sendCommandsToDevice = async (
11
+ device: string,
12
+ commands: Record<string, string>
13
+ ): Promise<XubeResponse<boolean>> => {
14
+ console.log(`Sending commands to device ${device}:`, commands);
15
+
16
+ try {
17
+ return xubePostRequest(
18
+ {
19
+ device,
20
+ commands,
21
+ },
22
+ XUBE_BASE_API_URL + DEVICES_BASE_PATH + COMMANDS_PATH,
23
+ contentTypeJSONHeader
24
+ );
25
+ } catch (e) {
26
+ console.log("Failed to send commands to device", e);
27
+
28
+ return new XubeResponse({
29
+ statusCode: StatusCode.BadRequest,
30
+ error: "Failed to send commands to device",
31
+ });
32
+ }
33
+ };
@@ -0,0 +1,5 @@
1
+ export const DEVICES_BASE_PATH = "/devices";
2
+
3
+ export const COMMANDS_PATH = "/commands";
4
+ export const ENGINE_PATH = "/engine";
5
+ export const RESTART_PATH = "/restart";
@@ -0,0 +1,31 @@
1
+ import {
2
+ XUBE_BASE_API_URL,
3
+ XubeResponse,
4
+ contentTypeJSONHeader,
5
+ xubePostRequest,
6
+ } from "@xube/kit-request";
7
+ import { StatusCode } from "@xube/kit-constants";
8
+ import { DEVICES_BASE_PATH, ENGINE_PATH } from "../constants";
9
+
10
+ export const restartDeviceEngine = async (
11
+ device: string
12
+ ): Promise<XubeResponse<boolean>> => {
13
+ console.log(`Attempting to restart device engine: ${device}`);
14
+
15
+ try {
16
+ return xubePostRequest(
17
+ {
18
+ device,
19
+ },
20
+ XUBE_BASE_API_URL + DEVICES_BASE_PATH + ENGINE_PATH,
21
+ contentTypeJSONHeader
22
+ );
23
+ } catch (e) {
24
+ console.log("Failed to restart device engine", e);
25
+
26
+ return new XubeResponse({
27
+ statusCode: StatusCode.BadRequest,
28
+ error: `Error occurred when restarting the device engine of device: ${device}.`,
29
+ });
30
+ }
31
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./command/send";
2
+ export * from "./engine/restart";
3
+ export * from "./constants";
4
+ export * from "./reset";
package/src/reset.ts ADDED
@@ -0,0 +1,3 @@
1
+ export const restartDevice = () => {
2
+
3
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "../kit-build/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "exclude": ["**/*.test.ts", "**/*.mock.ts", "dist"],
8
+ "references": [
9
+ {
10
+ "path": "../kit-generator"
11
+ },
12
+ {
13
+ "path": "../kit-constants"
14
+ },
15
+ {
16
+ "path": "../kit-log"
17
+ },
18
+ {
19
+ "path": "../kit-request"
20
+ }
21
+ ]
22
+ }
23
+