edilkamin 1.2.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/dist/package.json +7 -5
- package/dist/src/cli.js +3 -3
- package/dist/src/index.js +2 -2
- package/dist/src/library.js +46 -7
- package/dist/src/library.test.js +3 -19
- package/package.json +7 -5
package/dist/package.json
CHANGED
|
@@ -1,12 +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",
|
|
9
10
|
"test": "mocha --require ts-node/register src/*.test.ts",
|
|
11
|
+
"test:debug": "mocha --require ts-node/register/transpile-only --inspect src/*.test.ts",
|
|
10
12
|
"lint": "prettier --check src docs .github *.md",
|
|
11
13
|
"format": "prettier --write src docs .github *.md",
|
|
12
14
|
"build": "tsc"
|
|
@@ -28,9 +30,8 @@
|
|
|
28
30
|
"edilkamin": "dist/cli.js"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"aws-crt": "^1.14.5"
|
|
33
|
+
"aws-amplify": "^6.10.0",
|
|
34
|
+
"axios": "^0.26.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@aws-amplify/cli": "^7.6.21",
|
|
@@ -40,7 +41,8 @@
|
|
|
40
41
|
"prettier": "^2.5.1",
|
|
41
42
|
"sinon": "^19.0.2",
|
|
42
43
|
"ts-node": "^10.9.1",
|
|
43
|
-
"typedoc": "^0.
|
|
44
|
+
"typedoc": "^0.27.2",
|
|
45
|
+
"typescript": "^5.7.2"
|
|
44
46
|
},
|
|
45
47
|
"optionalDependencies": {
|
|
46
48
|
"commander": "^12.1.0"
|
package/dist/src/cli.js
CHANGED
|
@@ -58,7 +58,7 @@ const createProgram = () => {
|
|
|
58
58
|
addCommonOptions(program.command("signIn").description("Sign in and retrieve a JWT token")).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
59
|
const { username, password } = options;
|
|
60
60
|
const pwd = password || (yield promptPassword());
|
|
61
|
-
const jwtToken = yield library_1.signIn(username, pwd);
|
|
61
|
+
const jwtToken = yield (0, library_1.signIn)(username, pwd);
|
|
62
62
|
console.log("JWT Token:", jwtToken);
|
|
63
63
|
}));
|
|
64
64
|
// Command: deviceInfo
|
|
@@ -68,8 +68,8 @@ const createProgram = () => {
|
|
|
68
68
|
.requiredOption("-m, --mac <macAddress>", "MAC address of the device")).action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
69
|
const { username, password, mac } = options;
|
|
70
70
|
const pwd = password || (yield promptPassword());
|
|
71
|
-
const jwtToken = yield library_1.signIn(username, pwd);
|
|
72
|
-
const api = library_1.configure(); // Use the default API configuration
|
|
71
|
+
const jwtToken = yield (0, library_1.signIn)(username, pwd);
|
|
72
|
+
const api = (0, library_1.configure)(); // Use the default API configuration
|
|
73
73
|
const deviceInfo = yield api.deviceInfo(jwtToken, mac);
|
|
74
74
|
console.log("Device Info:", deviceInfo.data);
|
|
75
75
|
}));
|
package/dist/src/index.js
CHANGED
|
@@ -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;
|
package/dist/src/library.js
CHANGED
|
@@ -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) {
|
|
@@ -13,15 +46,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
46
|
};
|
|
14
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
48
|
exports.configure = exports.signIn = void 0;
|
|
49
|
+
const assert_1 = require("assert");
|
|
16
50
|
const aws_amplify_1 = require("aws-amplify");
|
|
51
|
+
const amplifyAuth = __importStar(require("aws-amplify/auth"));
|
|
17
52
|
const axios_1 = __importDefault(require("axios"));
|
|
18
53
|
const constants_1 = require("./constants");
|
|
19
54
|
const amplifyconfiguration = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
userPoolWebClientId: "7sc1qltkqobo3ddqsk4542dg2h",
|
|
24
|
-
},
|
|
55
|
+
aws_project_region: "eu-central-1",
|
|
56
|
+
aws_user_pools_id: "eu-central-1_BYmQ2VBlo",
|
|
57
|
+
aws_user_pools_web_client_id: "7sc1qltkqobo3ddqsk4542dg2h",
|
|
25
58
|
};
|
|
26
59
|
aws_amplify_1.Amplify.configure(amplifyconfiguration);
|
|
27
60
|
const headers = (jwtToken) => ({ Authorization: `Bearer ${jwtToken}` });
|
|
@@ -29,8 +62,14 @@ const headers = (jwtToken) => ({ Authorization: `Bearer ${jwtToken}` });
|
|
|
29
62
|
* Sign in to return the JWT token.
|
|
30
63
|
*/
|
|
31
64
|
const signIn = (username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
const
|
|
33
|
-
|
|
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();
|
|
34
73
|
});
|
|
35
74
|
exports.signIn = signIn;
|
|
36
75
|
const deviceInfo = (axiosInstance) => (jwtToken, macAddress) => axiosInstance.get(`device/${macAddress}/info`, {
|
package/dist/src/library.test.js
CHANGED
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const assert_1 = require("assert");
|
|
16
16
|
const sinon_1 = __importDefault(require("sinon"));
|
|
17
|
-
const aws_amplify_1 = require("aws-amplify");
|
|
18
17
|
const axios_1 = __importDefault(require("axios"));
|
|
19
18
|
const library_1 = require("../src/library");
|
|
20
19
|
describe("library", () => {
|
|
@@ -28,25 +27,10 @@ describe("library", () => {
|
|
|
28
27
|
afterEach(() => {
|
|
29
28
|
sinon_1.default.restore();
|
|
30
29
|
});
|
|
31
|
-
describe("signIn", () => {
|
|
32
|
-
it("should return a JWT token on successful login", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
const expectedJwtToken = "mockToken123";
|
|
34
|
-
const mockUserSession = {
|
|
35
|
-
getAccessToken: () => ({ jwtToken: expectedJwtToken }),
|
|
36
|
-
};
|
|
37
|
-
const mockUser = {
|
|
38
|
-
getSignInUserSession: () => mockUserSession,
|
|
39
|
-
};
|
|
40
|
-
const signInStub = sinon_1.default.stub(aws_amplify_1.Auth, "signIn").resolves(mockUser);
|
|
41
|
-
const jwtToken = yield library_1.signIn("mockUser", "mockPassword");
|
|
42
|
-
assert_1.strict.ok(signInStub.calledOnce);
|
|
43
|
-
assert_1.strict.equal(jwtToken, expectedJwtToken);
|
|
44
|
-
}));
|
|
45
|
-
});
|
|
46
30
|
describe("configure", () => {
|
|
47
31
|
it("should create API methods with the correct baseURL", () => {
|
|
48
32
|
const baseURL = "https://example.com/api";
|
|
49
|
-
const api = library_1.configure(baseURL);
|
|
33
|
+
const api = (0, library_1.configure)(baseURL);
|
|
50
34
|
assert_1.strict.ok(axiosStub.calledOnce);
|
|
51
35
|
assert_1.strict.deepEqual(axiosStub.firstCall.args[0], { baseURL });
|
|
52
36
|
assert_1.strict.deepEqual(Object.keys(api), [
|
|
@@ -65,7 +49,7 @@ describe("library", () => {
|
|
|
65
49
|
.resolves({ data: { id: "123", name: "Mock Device" } }),
|
|
66
50
|
};
|
|
67
51
|
axiosStub.returns(mockAxios);
|
|
68
|
-
const api = library_1.configure("https://example.com/api");
|
|
52
|
+
const api = (0, library_1.configure)("https://example.com/api");
|
|
69
53
|
const result = yield api.deviceInfo("mockToken", "mockMacAddress");
|
|
70
54
|
assert_1.strict.ok(mockAxios.get.calledOnce);
|
|
71
55
|
assert_1.strict.equal(mockAxios.get.firstCall.args[0], "device/mockMacAddress/info");
|
|
@@ -79,7 +63,7 @@ describe("library", () => {
|
|
|
79
63
|
put: sinon_1.default.stub().resolves({ status: 200 }),
|
|
80
64
|
};
|
|
81
65
|
axiosStub.returns(mockAxios);
|
|
82
|
-
const api = library_1.configure("https://example.com/api");
|
|
66
|
+
const api = (0, library_1.configure)("https://example.com/api");
|
|
83
67
|
const result = yield api.setPowerOn("mockToken", "mockMacAddress");
|
|
84
68
|
assert_1.strict.ok(mockAxios.put.calledOnce);
|
|
85
69
|
assert_1.strict.equal(mockAxios.put.firstCall.args[0], "mqtt/command");
|
package/package.json
CHANGED
|
@@ -1,12 +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",
|
|
9
10
|
"test": "mocha --require ts-node/register src/*.test.ts",
|
|
11
|
+
"test:debug": "mocha --require ts-node/register/transpile-only --inspect src/*.test.ts",
|
|
10
12
|
"lint": "prettier --check src docs .github *.md",
|
|
11
13
|
"format": "prettier --write src docs .github *.md",
|
|
12
14
|
"build": "tsc"
|
|
@@ -28,9 +30,8 @@
|
|
|
28
30
|
"edilkamin": "dist/cli.js"
|
|
29
31
|
},
|
|
30
32
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"aws-crt": "^1.14.5"
|
|
33
|
+
"aws-amplify": "^6.10.0",
|
|
34
|
+
"axios": "^0.26.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@aws-amplify/cli": "^7.6.21",
|
|
@@ -40,7 +41,8 @@
|
|
|
40
41
|
"prettier": "^2.5.1",
|
|
41
42
|
"sinon": "^19.0.2",
|
|
42
43
|
"ts-node": "^10.9.1",
|
|
43
|
-
"typedoc": "^0.
|
|
44
|
+
"typedoc": "^0.27.2",
|
|
45
|
+
"typescript": "^5.7.2"
|
|
44
46
|
},
|
|
45
47
|
"optionalDependencies": {
|
|
46
48
|
"commander": "^12.1.0"
|