@all-smart/all-smart-tools 1.0.0 → 1.0.2
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/main.js +27 -17
- package/package.json +2 -2
package/main.js
CHANGED
|
@@ -10,6 +10,7 @@ class asTools {
|
|
|
10
10
|
constructor(adapter) {
|
|
11
11
|
this.adapter = adapter;
|
|
12
12
|
this.licenseInvalidMassage = false;
|
|
13
|
+
this.reCheckTimeout = null;
|
|
13
14
|
this.adapter.on("message", this.onMessage.bind(this));
|
|
14
15
|
this.main();
|
|
15
16
|
}
|
|
@@ -31,33 +32,35 @@ class asTools {
|
|
|
31
32
|
|
|
32
33
|
async checkObjectsUpdate(){
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
return this.block().then((isValid) => {
|
|
36
|
+
if(isValid){
|
|
37
|
+
this.adapter.log.info('License Key is valid');
|
|
38
|
+
return true;
|
|
39
|
+
} else {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
async block() {
|
|
45
46
|
return new Promise(async (resolve, reject) => {
|
|
46
47
|
const check = async () => {
|
|
47
|
-
// look for license file
|
|
48
48
|
if (fs.existsSync(__dirname + '/cache')) {
|
|
49
49
|
if (await this.checkLocalLicenseFile()) {
|
|
50
|
+
this.adapter.log.info('License Key file OK');
|
|
50
51
|
resolve(true);
|
|
51
52
|
}
|
|
52
|
-
}
|
|
53
|
-
if (await this.checkLicenseKey(this.adapter.config.licenseKey)) {
|
|
53
|
+
} else if (await this.checkLicenseKey()) {
|
|
54
54
|
resolve(true);
|
|
55
55
|
} else {
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
if (this.licenseInvalidMassage === false) {
|
|
57
58
|
this.adapter.log.warn('License Key is invalid');
|
|
58
59
|
this.licenseInvalidMassage = true;
|
|
60
|
+
this.adapter.stop();
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
if (this.reCheckTimeout) clearTimeout(this.reCheckTimeout);
|
|
63
|
+
this.reCheckTimeout = setTimeout(check, 60 * 1000);
|
|
61
64
|
}
|
|
62
65
|
};
|
|
63
66
|
|
|
@@ -67,6 +70,7 @@ class asTools {
|
|
|
67
70
|
|
|
68
71
|
async checkLicenseKey(){
|
|
69
72
|
try {
|
|
73
|
+
|
|
70
74
|
const responseValidate = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/${this.adapter.config.licenseKey}`, {
|
|
71
75
|
headers: {
|
|
72
76
|
authorization: `Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`,
|
|
@@ -86,27 +90,32 @@ class asTools {
|
|
|
86
90
|
|
|
87
91
|
if(productName.trim() !== this.adapter.name.trim() || productVersion !== majorVersion){
|
|
88
92
|
this.adapter.log.info('License Key is not valid for this product');
|
|
93
|
+
this.adapter.stop();
|
|
89
94
|
return false;
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
if(responseValidate.data.data.timesActivated ===
|
|
97
|
+
if(responseValidate.data.data.timesActivated === null || responseValidate.data.data.timesActivated < responseValidate.data.data.timesActivatedMax){
|
|
93
98
|
this.adapter.log.info('License Key is not activated yet');
|
|
94
99
|
return await this.activateLicenseKey();
|
|
95
100
|
} else if(responseValidate.data.data.timesActivated === responseValidate.data.data.timesActivatedMax){
|
|
96
|
-
|
|
101
|
+
this.adapter.log.info('License Key was already activated');
|
|
102
|
+
this.adapter.stop();
|
|
97
103
|
return false;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
await this.createLocalLicenseFile();
|
|
101
|
-
return true;
|
|
106
|
+
// await this.createLocalLicenseFile(); Why here? This has to be in activateLicenseKey
|
|
107
|
+
// return true;
|
|
102
108
|
|
|
103
109
|
} catch (e) {
|
|
110
|
+
this.adapter.log.debug('License key check error: ' + e)
|
|
104
111
|
return false;
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
async activateLicenseKey(){
|
|
117
|
+
this.adapter.log.info(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${this.adapter.config.licenseKey}`);
|
|
118
|
+
this.adapter.log.info(`Basic ${Buffer.from(`${key1}:${key2}`).toString('base64')}`);
|
|
110
119
|
try {
|
|
111
120
|
const response = await axios.get(`${baseUrl}/wp-json/lmfwc/v2/licenses/activate/${this.adapter.config.licenseKey}`, {
|
|
112
121
|
headers: {
|
|
@@ -123,6 +132,7 @@ class asTools {
|
|
|
123
132
|
return false;
|
|
124
133
|
}
|
|
125
134
|
} catch (e) {
|
|
135
|
+
this.adapter.log.debug('Error license key activation: ' + e);
|
|
126
136
|
return false;
|
|
127
137
|
}
|
|
128
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@all-smart/all-smart-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "main.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "Christoph Gerle",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE.MD",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"axios": "^1.
|
|
12
|
+
"axios": "^1.6.5"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {},
|
|
15
15
|
"description": ""
|