edilkamin 1.1.0 → 1.3.0
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.
- package/README.md +16 -1
- package/dist/package.json +50 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +85 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/{index.js → src/index.js} +2 -2
- package/dist/{library.d.ts → src/library.d.ts} +4 -4
- package/dist/{library.js → src/library.js} +50 -18
- package/dist/src/library.test.d.ts +1 -0
- package/dist/src/library.test.js +81 -0
- package/package.json +19 -5
- package/dist/index.d.ts +0 -4
- /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/dist/{constants.js → src/constants.js} +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Edilkamin.js
|
|
2
2
|
|
|
3
3
|
[](https://github.com/AndreMiras/edilkamin.js/actions/workflows/tests.yml)
|
|
4
|
+
[](https://github.com/AndreMiras/edilkamin.js/actions/workflows/cli-tests.yml)
|
|
4
5
|
[](https://github.com/AndreMiras/edilkamin.js/actions/workflows/documentation.yml)
|
|
5
6
|
[](https://badge.fury.io/js/edilkamin)
|
|
6
7
|
|
|
@@ -39,12 +40,26 @@ It's also possible to change the default backend URL:
|
|
|
39
40
|
```js
|
|
40
41
|
import { signIn, configure } from "edilkamin";
|
|
41
42
|
|
|
42
|
-
const baseUrl = "https://my-proxy.com/"
|
|
43
|
+
const baseUrl = "https://my-proxy.com/";
|
|
43
44
|
const { deviceInfo, setPower } = configure(baseUrl);
|
|
44
45
|
deviceInfo(token, macAddress).then(console.log);
|
|
45
46
|
setPower(token, macAddress, 0).then(console.log);
|
|
46
47
|
```
|
|
47
48
|
|
|
49
|
+
## CLI
|
|
50
|
+
|
|
51
|
+
The library includes a CLI tool that is useful for debugging.
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
yarn cli deviceInfo --mac $MAC --username $USERNAME --password $PASSWORD
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Or with `npx` once the library is installed:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npx edilkamin deviceInfo --mac $MAC --username $USERNAME --password $PASSWORD
|
|
61
|
+
```
|
|
62
|
+
|
|
48
63
|
## Motivations
|
|
49
64
|
|
|
50
65
|
- providing an open source web alternative
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "edilkamin",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"cli": "ts-node src/cli.ts",
|
|
9
|
+
"cli:debug": "node --inspect --require ts-node/register/transpile-only src/cli.ts",
|
|
10
|
+
"test": "mocha --require ts-node/register src/*.test.ts",
|
|
11
|
+
"test:debug": "mocha --require ts-node/register/transpile-only --inspect src/*.test.ts",
|
|
12
|
+
"lint": "prettier --check src docs .github *.md",
|
|
13
|
+
"format": "prettier --write src docs .github *.md",
|
|
14
|
+
"build": "tsc"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"/dist"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/AndreMiras/edilkamin.js.git"
|
|
22
|
+
},
|
|
23
|
+
"author": "Andre Miras",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/AndreMiras/edilkamin.js/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/AndreMiras/edilkamin.js#readme",
|
|
29
|
+
"bin": {
|
|
30
|
+
"edilkamin": "dist/cli.js"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"aws-amplify": "^6.10.0",
|
|
34
|
+
"axios": "^0.26.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@aws-amplify/cli": "^7.6.21",
|
|
38
|
+
"@types/mocha": "^10.0.10",
|
|
39
|
+
"@types/sinon": "^17.0.3",
|
|
40
|
+
"mocha": "^10.8.2",
|
|
41
|
+
"prettier": "^2.5.1",
|
|
42
|
+
"sinon": "^19.0.2",
|
|
43
|
+
"ts-node": "^10.9.1",
|
|
44
|
+
"typedoc": "^0.27.2",
|
|
45
|
+
"typescript": "^5.7.2"
|
|
46
|
+
},
|
|
47
|
+
"optionalDependencies": {
|
|
48
|
+
"commander": "^12.1.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.main = void 0;
|
|
17
|
+
const library_1 = require("./library");
|
|
18
|
+
const commander_1 = require("commander");
|
|
19
|
+
const readline_1 = __importDefault(require("readline"));
|
|
20
|
+
const package_json_1 = require("../package.json");
|
|
21
|
+
const promptPassword = () => {
|
|
22
|
+
const rl = readline_1.default.createInterface({
|
|
23
|
+
input: process.stdin,
|
|
24
|
+
output: process.stdout,
|
|
25
|
+
terminal: true,
|
|
26
|
+
});
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
rl.question("Enter password: ", (password) => {
|
|
29
|
+
// Hide the password input
|
|
30
|
+
readline_1.default.moveCursor(process.stdout, 0, -1);
|
|
31
|
+
readline_1.default.clearLine(process.stdout, 0);
|
|
32
|
+
rl.close();
|
|
33
|
+
resolve(password);
|
|
34
|
+
});
|
|
35
|
+
// Disable input echoing for password
|
|
36
|
+
process.stdin.on("data", (char) => {
|
|
37
|
+
if (char.toString("hex") === "0d0a")
|
|
38
|
+
return; // Enter key
|
|
39
|
+
process.stdout.write("*");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Adds common options (username and password) to a command.
|
|
45
|
+
* @param command The command to which options should be added.
|
|
46
|
+
* @returns The command with options added.
|
|
47
|
+
*/
|
|
48
|
+
const addCommonOptions = (command) => command
|
|
49
|
+
.requiredOption("-u, --username <username>", "Username")
|
|
50
|
+
.option("-p, --password <password>", "Password");
|
|
51
|
+
const createProgram = () => {
|
|
52
|
+
const program = new commander_1.Command();
|
|
53
|
+
program
|
|
54
|
+
.name("edilkamin-cli")
|
|
55
|
+
.description("CLI tool for interacting with the Edilkamin API")
|
|
56
|
+
.version(package_json_1.version);
|
|
57
|
+
// Command: signIn
|
|
58
|
+
addCommonOptions(program.command("signIn").description("Sign in and retrieve a JWT token")).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const { username, password } = options;
|
|
60
|
+
const pwd = password || (yield promptPassword());
|
|
61
|
+
const jwtToken = yield (0, library_1.signIn)(username, pwd);
|
|
62
|
+
console.log("JWT Token:", jwtToken);
|
|
63
|
+
}));
|
|
64
|
+
// Command: deviceInfo
|
|
65
|
+
addCommonOptions(program
|
|
66
|
+
.command("deviceInfo")
|
|
67
|
+
.description("Retrieve device info for a specific MAC address")
|
|
68
|
+
.requiredOption("-m, --mac <macAddress>", "MAC address of the device")).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const { username, password, mac } = options;
|
|
70
|
+
const pwd = password || (yield promptPassword());
|
|
71
|
+
const jwtToken = yield (0, library_1.signIn)(username, pwd);
|
|
72
|
+
const api = (0, library_1.configure)(); // Use the default API configuration
|
|
73
|
+
const deviceInfo = yield api.deviceInfo(jwtToken, mac);
|
|
74
|
+
console.log("Device Info:", deviceInfo.data);
|
|
75
|
+
}));
|
|
76
|
+
return program;
|
|
77
|
+
};
|
|
78
|
+
const main = () => {
|
|
79
|
+
const program = createProgram();
|
|
80
|
+
program.parse(process.argv);
|
|
81
|
+
};
|
|
82
|
+
exports.main = main;
|
|
83
|
+
if (require.main === module) {
|
|
84
|
+
main();
|
|
85
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { API_URL } from "./constants";
|
|
2
|
+
export { CommandsType, DeviceInfoType, StatusType, TemperaturesType, UserParametersType, } from "./types";
|
|
3
|
+
export { signIn, configure } from "./library";
|
|
4
|
+
export declare const deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<import("./types").DeviceInfoType, any>>, setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any, any>>, setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any, any>>, setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.deviceInfo = void 0;
|
|
4
|
+
exports.setPowerOn = exports.setPowerOff = exports.setPower = exports.deviceInfo = exports.configure = exports.signIn = exports.API_URL = void 0;
|
|
5
5
|
const library_1 = require("./library");
|
|
6
6
|
var constants_1 = require("./constants");
|
|
7
7
|
Object.defineProperty(exports, "API_URL", { enumerable: true, get: function () { return constants_1.API_URL; } });
|
|
8
8
|
var library_2 = require("./library");
|
|
9
9
|
Object.defineProperty(exports, "signIn", { enumerable: true, get: function () { return library_2.signIn; } });
|
|
10
10
|
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return library_2.configure; } });
|
|
11
|
-
_a = library_1.configure(), exports.deviceInfo = _a.deviceInfo, exports.setPower = _a.setPower, exports.setPowerOff = _a.setPowerOff, exports.setPowerOn = _a.setPowerOn;
|
|
11
|
+
_a = (0, library_1.configure)(), exports.deviceInfo = _a.deviceInfo, exports.setPower = _a.setPower, exports.setPowerOff = _a.setPowerOff, exports.setPowerOn = _a.setPowerOn;
|
|
@@ -4,9 +4,9 @@ import { DeviceInfoType } from "./types";
|
|
|
4
4
|
*/
|
|
5
5
|
declare const signIn: (username: string, password: string) => Promise<string>;
|
|
6
6
|
declare const configure: (baseURL?: string) => {
|
|
7
|
-
deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<DeviceInfoType>>;
|
|
8
|
-
setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>;
|
|
9
|
-
setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
|
|
10
|
-
setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
|
|
7
|
+
deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<DeviceInfoType, any>>;
|
|
8
|
+
setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
+
setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
10
|
+
setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
11
11
|
};
|
|
12
12
|
export { signIn, configure };
|
|
@@ -1,4 +1,37 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,18 +41,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
42
|
});
|
|
10
43
|
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
11
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
48
|
exports.configure = exports.signIn = void 0;
|
|
13
49
|
const assert_1 = require("assert");
|
|
14
50
|
const aws_amplify_1 = require("aws-amplify");
|
|
15
|
-
const
|
|
51
|
+
const amplifyAuth = __importStar(require("aws-amplify/auth"));
|
|
52
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
53
|
const constants_1 = require("./constants");
|
|
17
54
|
const amplifyconfiguration = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
userPoolWebClientId: "7sc1qltkqobo3ddqsk4542dg2h",
|
|
22
|
-
},
|
|
55
|
+
aws_project_region: "eu-central-1",
|
|
56
|
+
aws_user_pools_id: "eu-central-1_BYmQ2VBlo",
|
|
57
|
+
aws_user_pools_web_client_id: "7sc1qltkqobo3ddqsk4542dg2h",
|
|
23
58
|
};
|
|
24
59
|
aws_amplify_1.Amplify.configure(amplifyconfiguration);
|
|
25
60
|
const headers = (jwtToken) => ({ Authorization: `Bearer ${jwtToken}` });
|
|
@@ -27,14 +62,20 @@ const headers = (jwtToken) => ({ Authorization: `Bearer ${jwtToken}` });
|
|
|
27
62
|
* Sign in to return the JWT token.
|
|
28
63
|
*/
|
|
29
64
|
const signIn = (username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const
|
|
31
|
-
|
|
65
|
+
const { isSignedIn, nextStep } = yield amplifyAuth.signIn({
|
|
66
|
+
username,
|
|
67
|
+
password,
|
|
68
|
+
});
|
|
69
|
+
assert_1.strict.ok(isSignedIn);
|
|
70
|
+
const { tokens } = yield amplifyAuth.fetchAuthSession();
|
|
71
|
+
assert_1.strict.ok(tokens);
|
|
72
|
+
return tokens.accessToken.toString();
|
|
32
73
|
});
|
|
33
74
|
exports.signIn = signIn;
|
|
34
75
|
const deviceInfo = (axiosInstance) => (jwtToken, macAddress) => axiosInstance.get(`device/${macAddress}/info`, {
|
|
35
76
|
headers: headers(jwtToken),
|
|
36
77
|
});
|
|
37
|
-
const mqttCommand = (axiosInstance) => (jwtToken, macAddress, payload) => axiosInstance.put(
|
|
78
|
+
const mqttCommand = (axiosInstance) => (jwtToken, macAddress, payload) => axiosInstance.put("mqtt/command", Object.assign({ mac_address: macAddress }, payload), { headers: headers(jwtToken) });
|
|
38
79
|
const setPower = (axiosInstance) => (jwtToken, macAddress, value) => mqttCommand(axiosInstance)(jwtToken, macAddress, { name: "power", value });
|
|
39
80
|
const setPowerOn = (axiosInstance) => (jwtToken, macAddress) => setPower(axiosInstance)(jwtToken, macAddress, 1);
|
|
40
81
|
const setPowerOff = (axiosInstance) => (jwtToken, macAddress) => setPower(axiosInstance)(jwtToken, macAddress, 0);
|
|
@@ -53,12 +94,3 @@ const configure = (baseURL = constants_1.API_URL) => {
|
|
|
53
94
|
};
|
|
54
95
|
exports.configure = configure;
|
|
55
96
|
const defaultApi = configure();
|
|
56
|
-
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
const { USERNAME, PASSWORD, MAC_ADDRESS } = process.env;
|
|
58
|
-
assert_1.ok(USERNAME);
|
|
59
|
-
assert_1.ok(PASSWORD);
|
|
60
|
-
assert_1.ok(MAC_ADDRESS);
|
|
61
|
-
const jwtToken = yield signIn(USERNAME, PASSWORD);
|
|
62
|
-
const info = yield defaultApi.deviceInfo(jwtToken, MAC_ADDRESS);
|
|
63
|
-
console.log({ info });
|
|
64
|
-
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const assert_1 = require("assert");
|
|
16
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const library_1 = require("../src/library");
|
|
19
|
+
describe("library", () => {
|
|
20
|
+
let axiosStub;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
axiosStub = sinon_1.default.stub(axios_1.default, "create").returns({
|
|
23
|
+
get: sinon_1.default.stub(),
|
|
24
|
+
put: sinon_1.default.stub(),
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
sinon_1.default.restore();
|
|
29
|
+
});
|
|
30
|
+
describe("configure", () => {
|
|
31
|
+
it("should create API methods with the correct baseURL", () => {
|
|
32
|
+
const baseURL = "https://example.com/api";
|
|
33
|
+
const api = (0, library_1.configure)(baseURL);
|
|
34
|
+
assert_1.strict.ok(axiosStub.calledOnce);
|
|
35
|
+
assert_1.strict.deepEqual(axiosStub.firstCall.args[0], { baseURL });
|
|
36
|
+
assert_1.strict.deepEqual(Object.keys(api), [
|
|
37
|
+
"deviceInfo",
|
|
38
|
+
"setPower",
|
|
39
|
+
"setPowerOff",
|
|
40
|
+
"setPowerOn",
|
|
41
|
+
]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("API Methods", () => {
|
|
45
|
+
it("should call axios for deviceInfo", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const mockAxios = {
|
|
47
|
+
get: sinon_1.default
|
|
48
|
+
.stub()
|
|
49
|
+
.resolves({ data: { id: "123", name: "Mock Device" } }),
|
|
50
|
+
};
|
|
51
|
+
axiosStub.returns(mockAxios);
|
|
52
|
+
const api = (0, library_1.configure)("https://example.com/api");
|
|
53
|
+
const result = yield api.deviceInfo("mockToken", "mockMacAddress");
|
|
54
|
+
assert_1.strict.ok(mockAxios.get.calledOnce);
|
|
55
|
+
assert_1.strict.equal(mockAxios.get.firstCall.args[0], "device/mockMacAddress/info");
|
|
56
|
+
assert_1.strict.deepEqual(mockAxios.get.firstCall.args[1], {
|
|
57
|
+
headers: { Authorization: "Bearer mockToken" },
|
|
58
|
+
});
|
|
59
|
+
assert_1.strict.deepEqual(result.data, { id: "123", name: "Mock Device" });
|
|
60
|
+
}));
|
|
61
|
+
it("should call axios for setPowerOn", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const mockAxios = {
|
|
63
|
+
put: sinon_1.default.stub().resolves({ status: 200 }),
|
|
64
|
+
};
|
|
65
|
+
axiosStub.returns(mockAxios);
|
|
66
|
+
const api = (0, library_1.configure)("https://example.com/api");
|
|
67
|
+
const result = yield api.setPowerOn("mockToken", "mockMacAddress");
|
|
68
|
+
assert_1.strict.ok(mockAxios.put.calledOnce);
|
|
69
|
+
assert_1.strict.equal(mockAxios.put.firstCall.args[0], "mqtt/command");
|
|
70
|
+
assert_1.strict.deepEqual(mockAxios.put.firstCall.args[1], {
|
|
71
|
+
mac_address: "mockMacAddress",
|
|
72
|
+
name: "power",
|
|
73
|
+
value: 1,
|
|
74
|
+
});
|
|
75
|
+
assert_1.strict.deepEqual(mockAxios.put.firstCall.args[2], {
|
|
76
|
+
headers: { Authorization: "Bearer mockToken" },
|
|
77
|
+
});
|
|
78
|
+
assert_1.strict.equal(result.status, 200);
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edilkamin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"cli": "ts-node src/cli.ts",
|
|
9
|
+
"cli:debug": "node --inspect --require ts-node/register/transpile-only src/cli.ts",
|
|
10
|
+
"test": "mocha --require ts-node/register src/*.test.ts",
|
|
11
|
+
"test:debug": "mocha --require ts-node/register/transpile-only --inspect src/*.test.ts",
|
|
9
12
|
"lint": "prettier --check src docs .github *.md",
|
|
10
13
|
"format": "prettier --write src docs .github *.md",
|
|
11
14
|
"build": "tsc"
|
|
@@ -23,14 +26,25 @@
|
|
|
23
26
|
"url": "https://github.com/AndreMiras/edilkamin.js/issues"
|
|
24
27
|
},
|
|
25
28
|
"homepage": "https://github.com/AndreMiras/edilkamin.js#readme",
|
|
29
|
+
"bin": {
|
|
30
|
+
"edilkamin": "dist/cli.js"
|
|
31
|
+
},
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
33
|
+
"aws-amplify": "^6.10.0",
|
|
34
|
+
"axios": "^0.26.0"
|
|
29
35
|
},
|
|
30
36
|
"devDependencies": {
|
|
31
37
|
"@aws-amplify/cli": "^7.6.21",
|
|
38
|
+
"@types/mocha": "^10.0.10",
|
|
39
|
+
"@types/sinon": "^17.0.3",
|
|
40
|
+
"mocha": "^10.8.2",
|
|
32
41
|
"prettier": "^2.5.1",
|
|
42
|
+
"sinon": "^19.0.2",
|
|
33
43
|
"ts-node": "^10.9.1",
|
|
34
|
-
"typedoc": "^0.
|
|
44
|
+
"typedoc": "^0.27.2",
|
|
45
|
+
"typescript": "^5.7.2"
|
|
46
|
+
},
|
|
47
|
+
"optionalDependencies": {
|
|
48
|
+
"commander": "^12.1.0"
|
|
35
49
|
}
|
|
36
50
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { API_URL } from "./constants";
|
|
2
|
-
export { CommandsType, DeviceInfoType, StatusType, TemperaturesType, UserParametersType, } from "./types";
|
|
3
|
-
export { signIn, configure } from "./library";
|
|
4
|
-
export declare const deviceInfo: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<import("./types").DeviceInfoType>>, setPower: (jwtToken: string, macAddress: string, value: number) => Promise<import("axios").AxiosResponse<any>>, setPowerOff: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>, setPowerOn: (jwtToken: string, macAddress: string) => Promise<import("axios").AxiosResponse<any>>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|