@all-smart/all-smart-tools 1.0.5 → 1.0.10

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 CHANGED
@@ -66,10 +66,14 @@ class asTools {
66
66
  async block() {
67
67
  return new Promise(async (resolve, reject) => {
68
68
  const check = async () => {
69
- if (fs.existsSync(__dirname + '/cache')) {
69
+ const adapterObject = await this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
70
+ if (adapterObject.native.licenseCertificate) {
70
71
  if (await this.checkLocalLicenseCertificate()) {
71
- this.adapter.log.info('License Key file OK');
72
+ this.adapter.log.info('License Certificate OK');
72
73
  resolve(true);
74
+ } else {
75
+ this.adapter.log.warn('There was an error validating the license')
76
+ reject(false);
73
77
  }
74
78
  } else if (await this.checkLicenseKey()) {
75
79
  resolve(true);
@@ -171,22 +175,25 @@ class asTools {
171
175
  "majorVersion": majorVersion
172
176
  }
173
177
  // encode license certificate
174
- const licenseFileEncoded = JSON.stringify(licenseCertificate).toString('base64');
178
+ const licenseCertificateEncoded = Buffer.from(JSON.stringify(licenseCertificate)).toString('base64');
179
+ this.adapter.log.debug(licenseCertificateEncoded);
175
180
  // write license certificate
176
181
  await this.adapter.extendForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`, {
177
182
  native: {
178
- licenseCertificate: licenseFileEncoded
183
+ licenseCertificate: licenseCertificateEncoded
179
184
  }
180
185
  })
181
186
  }
182
187
 
183
188
  async checkLocalLicenseCertificate(){
184
189
  // read license certificate
185
- const licenseFileEncoded = fs.readFileSync(__dirname + '/cache');
186
- const adapterObj = this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`)
190
+ const adapterObj = await this.adapter.getForeignObjectAsync(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
191
+ this.adapter.log.debug(`system.adapter.${this.adapter.namespace.replace(/\.\d/g, '')}`);
192
+ this.adapter.log.debug(JSON.stringify(adapterObj));
187
193
  const licenseCertificateEncoded = adapterObj.native.licenseCertificate;
188
194
  // decode license file
189
- const licenseCertificate = JSON.parse(licenseCertificateEncoded.toString().toString('ascii'));
195
+ const licenseCertificate = JSON.parse(Buffer.from(licenseCertificateEncoded, 'base64').toString('ascii'));
196
+ this.adapter.log.info(JSON.stringify(licenseCertificate));
190
197
  // get system uuid
191
198
  const systemMeta = await this.adapter.getForeignObjectAsync('system.meta.uuid');
192
199
  const systemUuid = systemMeta.native.uuid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@all-smart/all-smart-tools",
3
- "version": "1.0.5",
3
+ "version": "1.0.10",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"