@iobroker/repochecker 3.0.0-alpha.1 → 3.0.0-alpha.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.
@@ -0,0 +1,658 @@
1
+ 'use strict';
2
+ /*
3
+ This module is a support module for iobroker.repochecker
4
+
5
+ Area checked: io-package.json
6
+ Numbering : 100 - 199
7
+
8
+ */
9
+
10
+ const compareVersions = require('compare-versions');
11
+ const sizeOf = require('image-size');
12
+
13
+ const common = require('./common.js');
14
+
15
+ async function getIOPackageJson(context) {
16
+ console.log('\ngetIOPackageJson');
17
+
18
+ const ioPackageJson = await common.downloadFile(context.githubUrl, '/io-package.json')
19
+ context.ioPackageJson = ioPackageJson;
20
+ if (typeof context.ioPackageJson === 'string') {
21
+ try {
22
+ context.ioPackageJson = JSON.parse(context.ioPackageJson);
23
+ } catch (e) {
24
+ context.errors.push(`[E100] Cannot parse ioPackage.json: ${e}`);
25
+ }
26
+ }
27
+ return context;
28
+ }
29
+
30
+ const recommendedJsControllerVersion = '5.0.19';
31
+ let requiredJsControllerVersion = '4.0.24';
32
+ const recommendedNodeVersion = '18'; // This is the minimum node version that should be required
33
+ const requiredNodeVersion = '16'; // This is the minimum node version that must be required
34
+
35
+ const blacklistIOPackageJson = {
36
+ installedFrom: {
37
+ msg: '"installedFrom" is invalid at io-package.json. Please remove.',
38
+ err:true
39
+ },
40
+ 'common.installedFrom': {
41
+ msg: '"common.installedFrom" is invalid. Please remove from io-package.json.',
42
+ err:true
43
+ },
44
+ 'common.title': {
45
+ msg: '"common.title" is deprecated and replaced by "common.titleLang". Please remove from io-package.json.',
46
+ err:false
47
+ },
48
+ 'common.main': {
49
+ msg: '"common.main" is deprecated and ignored. Please remove from io-package.json. Use "main" at package.json instead.',
50
+ err:false
51
+ },
52
+ 'common.materialize': {
53
+ msg: '"common.materialize" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI".',
54
+ err:false
55
+ },
56
+ 'common.materializeTab': {
57
+ msg: '"common.materializeTab" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI".',
58
+ err:false
59
+ },
60
+ 'common.noConfig': {
61
+ msg: '"common.noConfig" is deprecated for admin >= 5 at io-package.json. Please use property "adminUI.config":"none".',
62
+ err:false
63
+ },
64
+ 'common.subscribe': {
65
+ msg: '"common.subscribe" will be removed with js-controller >= 6. Please remove from io-package.json and adapt code if required.',
66
+ err:true
67
+ },
68
+ 'common.wakeup': {
69
+ msg: '"common.wakeup" is deprecated and ignored. Please remove from io-package.json.',
70
+ err:true
71
+ },
72
+ };
73
+
74
+
75
+ async function checkIOPackageJson(context) {
76
+ console.log('\ncheckIOPackage [E1xx]');
77
+
78
+ if (!context.ioPackageJson.native) {
79
+ context.errors.push('[E101] io-package.json must have at least empty "native" attribute');
80
+ } else {
81
+ context.checks.push('"native" found in io-package.json');
82
+
83
+ // Generic check for potential credentials that should have a counterpart in encryptedNative/protectedNative
84
+ const suspiciousPhrases = [
85
+ 'apikey',
86
+ 'api_key',
87
+ 'credential',
88
+ 'pass',
89
+ 'passwd',
90
+ 'password',
91
+ 'passwort',
92
+ 'pin',
93
+ 'private_pw',
94
+ 'psk',
95
+ 'pwd',
96
+ 'secret',
97
+ 'token',
98
+ ];
99
+ //const regex = new RegExp(suspiciousPhrases.join('|'), 'i');
100
+
101
+ let suspiciousKeys = Object.keys(context.ioPackageJson.native) || [];
102
+ // console.log(`native keys: ${suspiciousKeys.join()}`);
103
+ //suspiciousKeys = suspiciousKeys.filter( key => regex.test(key));
104
+ suspiciousKeys = suspiciousKeys.filter( key => suspiciousPhrases.includes(key.toLowerCase()));
105
+ // console.log(`suspicious keys: ${suspiciousKeys.join()}`);
106
+
107
+ if ( suspiciousKeys.length) {
108
+ if (context.ioPackageJson.protectedNative) {
109
+ const missingProtected = suspiciousKeys.filter( key => !context.ioPackageJson.protectedNative.includes(key));
110
+ if (missingProtected.length) context.warnings.push( `[W173] Potential sensitive data "${missingProtected.join()}" not listed at "protectedNative" in io-package.json`);
111
+ } else {
112
+ context.warnings.push( `[W173] Potential sensitive data "${suspiciousKeys.join()}" not listed at "protectedNative" in io-package.json`);
113
+ }
114
+
115
+ if (context.ioPackageJson.encryptedNative) {
116
+ const missingProtected = suspiciousKeys.filter( key => !context.ioPackageJson.encryptedNative.includes(key));
117
+ if (missingProtected.length) context.warnings.push( `[W174] Potential sensitive data "${missingProtected.join()}" not listed at "encryptedNative" in io-package.json`);
118
+ } else {
119
+ context.warnings.push( `[W174] Potential sensitive data "${suspiciousKeys.join()}" not listed at "encryptedNative" in io-package.json`);
120
+ }
121
+ }
122
+ }
123
+
124
+ if (!context.ioPackageJson.common) {
125
+ context.errors.push('[E102] io-package.json must have common object');
126
+ return resolve(context);
127
+ } else {
128
+ context.checks.push('"common" found in io-package.json');
129
+ if (!context.ioPackageJson.common.name || context.ioPackageJson.common.name !== context.adapterName.toLowerCase()) {
130
+ context.errors.push(`[E103] "common.name" in io-package.json must be equal to "${context.adapterName.toLowerCase()}'". Now is ${context.ioPackageJson.common.name}`);
131
+ } else {
132
+ context.checks.push('"common.name" is valid in io-package.json');
133
+ }
134
+
135
+ /*
136
+ if (context.ioPackageJson.common.title) {
137
+ context.warnings.push('[W171] "common.title" is deprecated in io-package.json. Please remove from io-package.json.');
138
+ }
139
+
140
+ if (context.ioPackageJson.common.main) {
141
+ context.warnings.push('[W177] "common.main" is deprecated in io-package.json. For js-controller >= 3.3 please use package.json main and remove "common.main" from io-package.json.');
142
+ }
143
+
144
+ if (context.ioPackageJson.common.materialize) {
145
+ context.warnings.push('[W178] "common.materialize" is deprecated in io-package.json. For admin version >= 5 please use the property "common.adminUI"');
146
+ }
147
+
148
+ if (context.ioPackageJson.common.materializeTab) {
149
+ context.warnings.push('[W179] "common.materializeTab" is deprecated in io-package.json. For admin version >= 5 please use the property "common.adminUI".');
150
+ }
151
+
152
+ if (context.ioPackageJson.common.noConfig) {
153
+ context.warnings.push('[W180] "common.noConfig" is deprecated in io-package.json. For admin version >= 5 please use "common.adminUI.config":"none".');
154
+ }
155
+ */
156
+ if (!context.ioPackageJson.common.titleLang) {
157
+ context.errors.push('[E104] No "common.titleLang" found in io-package.json');
158
+ } else {
159
+ context.checks.push('"common.titleLang" found in io-package.json');
160
+
161
+ if (typeof context.ioPackageJson.common.titleLang !== 'object') {
162
+ context.errors.push(`[E105] "common.titleLang" must be an object. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
163
+ } else {
164
+ let missingLang = common.checkLanguages(context.ioPackageJson.common.titleLang, context.cfg.requiredLanguages);
165
+ if (missingLang.length) {
166
+ context.warnings.push(`[W105] Missing mandatory translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
167
+ }
168
+
169
+ missingLang = common.checkLanguages(context.ioPackageJson.common.titleLang, context.cfg.allowedLanguages);
170
+ missingLang = missingLang.filter( lang => !context.cfg.requiredLanguages.includes(lang));
171
+ if (missingLang.length) {
172
+ missingLang = [... new Set(missingLang)]; // make unique
173
+ context.warnings.push(`[W105] Missing suggested translation into ${missingLang.join()} of "common.titleLang" in io-package.json.`);
174
+ }
175
+ }
176
+
177
+ Object.keys(context.ioPackageJson.common.titleLang).forEach(lang => {
178
+ const text = context.ioPackageJson.common.titleLang[lang];
179
+ if (text.match(/iobroker/i)) {
180
+ context.errors.push(`[E106] "common.titleLang" must not have ioBroker in the name. It is clear, for what this adapter was created. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
181
+ } else {
182
+ context.checks.push('"common.titleLang" has no ioBroker in it in io-package.json');
183
+ }
184
+
185
+ if (text.match(/\sadapter|adapter\s/i)) {
186
+ context.warnings.push(`[W106] "common.titleLang" should not contain word "adapter" in the name. It is clear, that this is adapter. Now: ${JSON.stringify(context.ioPackageJson.common.titleLang)}`);
187
+ } else {
188
+ context.checks.push('"common.titleLang" has no "adapter" in it in io-package.json');
189
+ }
190
+ });
191
+ }
192
+
193
+ if (!context.ioPackageJson.common.version) {
194
+ context.errors.push('[E107] No "common.version" found in io-package.json');
195
+ } else {
196
+ context.checks.push('"common.version" found in io-package.json');
197
+
198
+ if (!context.packageJson || context.ioPackageJson.common.version !== context.packageJson.version) {
199
+ context.errors.push('[E118] Versions in package.json and in io-package.json are different');
200
+ } else {
201
+ context.checks.push('"common.version" is equal in package.json adn in io-package.json');
202
+ }
203
+ }
204
+
205
+ if (!context.ioPackageJson.common.desc) {
206
+ context.errors.push('[E108] No "common.desc" found in io-package.json');
207
+ } else {
208
+ context.checks.push('"common.desc" found in io-package.json');
209
+
210
+ if (typeof context.ioPackageJson.common.desc !== 'object') {
211
+ context.errors.push(`[E109] "common.desc" in io-package.json should be an object for many languages. Found only "${context.ioPackageJson.common.desc}"`);
212
+ } else {
213
+
214
+ let missingLang = common.checkLanguages(context.ioPackageJson.common.desc, context.cfg.requiredLanguages);
215
+ if (missingLang.length) {
216
+ context.warnings.push(`[E109] Missing mandatory translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
217
+ }
218
+
219
+ missingLang = common.checkLanguages(context.ioPackageJson.common.desc, context.cfg.allowedLanguages);
220
+ missingLang = missingLang.filter( lang => !context.cfg.requiredLanguages.includes(lang));
221
+ if (missingLang.length) {
222
+ missingLang = [... new Set(missingLang)]; // make unique
223
+ context.warnings.push(`[W109] Missing suggested translation into ${missingLang.join()} of "common.desc" in io-package.json.`);
224
+ }
225
+ }
226
+ }
227
+
228
+ if (! context.ioPackageJson.common.keywords) {
229
+ context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
230
+ } else {
231
+ const forbiddenKeywords = ['iobroker', 'adapter', 'smart home'];
232
+ if (!Array.isArray(context.ioPackageJson.common.keywords)) {
233
+ context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
234
+ } else if (context.ioPackageJson.common.keywords.length === 0) {
235
+ context.errors.push('[E169] "common.keywords" must be an array within io-package.json and contain some useful keywords');
236
+ } else if (forbiddenKeywords.filter(keyword => context.ioPackageJson.common.keywords.map(k => k.toLowerCase()).includes(keyword)).length > 0) {
237
+ context.warnings.push(`[W170] "common.keywords" should not contain "${forbiddenKeywords.join(', ')}" io-package.json`);
238
+ }
239
+
240
+ context.checks.push('"common.keywords" found in io-package.json');
241
+ }
242
+
243
+ if (!context.ioPackageJson.common.icon) {
244
+ context.errors.push('[E110] Icon not found in the io-package.json');
245
+ } else {
246
+ context.checks.push('"common.icon" found in io-package.json');
247
+ }
248
+
249
+ if (!context.ioPackageJson.common.extIcon) {
250
+ context.errors.push('[E111] extIcon not found in the io-package.json');
251
+ } else {
252
+ context.checks.push('"common.extIcon" found in io-package.json');
253
+
254
+ // extract icon name
255
+ let fileName = context.ioPackageJson.common.extIcon;
256
+ let pos = fileName.indexOf('?');
257
+
258
+ if (pos !== -1) {
259
+ fileName = fileName.substring(0, pos);
260
+ }
261
+ pos = fileName.lastIndexOf('/');
262
+ fileName = fileName.substring(pos + 1, fileName.length);
263
+
264
+ if (fileName !== context.ioPackageJson.common.icon) {
265
+ context.errors.push('[E112] extIcon must be the same as an icon but with github path');
266
+ } else {
267
+ context.checks.push('"common.extIcon" has same path as repo in io-package.json');
268
+ }
269
+ }
270
+
271
+ if (!context.ioPackageJson.common.compact && !context.ioPackageJson.common.onlyWWW) {
272
+ context.warnings.push('[W113] Adapter should support compact mode');
273
+ } else if (!context.ioPackageJson.common.onlyWWW) {
274
+ context.checks.push('"common.compact" found in io-package.json');
275
+ }
276
+
277
+ if (context.ioPackageJson.common.noConfig &&
278
+ (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config !== 'none')
279
+ ) {
280
+ context.errors.push('[E114] "common.noConfig=true" requires "common.adminUI.config" to be set to "none"' );
281
+ }
282
+ if (!context.ioPackageJson.common.materialize &&
283
+ !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') &&
284
+ !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'materialize') &&
285
+ !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'html') &&
286
+ !(context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'none')
287
+ ) {
288
+ context.errors.push('[E114] Admin support not specified. Please add "common.adminUI.config = json|materialize|html|none"');
289
+ } else {
290
+ context.checks.push('"common.materialize" or valid "common.adminUI.config:xxx" found in io-package.json');
291
+ }
292
+
293
+ if (context.ioPackageJson.common.license) {
294
+ context.warnings.push('[W181] "common.license" in io-package.json is deprecated. Please define object "common.licenseInformation"');
295
+ }
296
+
297
+ if (!context.ioPackageJson.common.licenseInformation) {
298
+ if (!context.ioPackageJson.common.license) {
299
+ context.errors.push('[E115] "common.licenseInformation" not found in io-package.json');
300
+ }
301
+ } else {
302
+ context.checks.push('"common.licenseInformation" found in io-package.json');
303
+
304
+ if (context.ioPackageJson.common.license) {
305
+ context.errors.push('[E182] Please remove "common.license" from io-package.json as "common.licenseInformation" is declared.');
306
+ }
307
+
308
+ // check if license valid
309
+ if (!context.ioPackageJson.common.licenseInformation.license) {
310
+ context.errors.push('[E183] "common.licenseInformation.license" is missing');
311
+ } else if (!context.cfg.allowedLicenses.includes(context.ioPackageJson.common?.licenseInformation?.license)) {
312
+ context.errors.push('[E116] No SPDX license found at "common.licenseInformation". Please use one of listed here: https://spdx.org/licenses/');
313
+ } else {
314
+ context.checks.push('"common.licenseInformation" is valid in io-package.json');
315
+ }
316
+
317
+ // check if type is valid
318
+ if (!['free', 'paid', 'commercial', 'limited'].includes(context.ioPackageJson.common?.licenseInformation?.type)) {
319
+ context.errors.push('[E170] "common.licenseInformation.type" is invalid. Select valid type (e.g. free)');
320
+ } else {
321
+ context.checks.push('"common.licenseInformation.type" is valid in io-package.json');
322
+
323
+ if (['paid', 'commercial', 'limited'].includes(context.ioPackageJson.common?.licenseInformation?.type)) {
324
+ if (!context.ioPackageJson.common?.licenseInformation?.link) {
325
+ context.errors.push('[E171] "common.licenseInformation.link" is required for non-free adapters');
326
+ } else {
327
+ context.checks.push('"common.licenseInformation.link" is valid in io-package.json');
328
+ }
329
+ }
330
+ }
331
+
332
+ if (!context.packageJson ||
333
+ context.ioPackageJson.common?.licenseInformation?.license !== context.packageJson.license) {
334
+ context.errors.push('[E117] Licenses in package.json and in io-package.json are different');
335
+ } else {
336
+ context.checks.push('"common.licenseInformation.license" is equal in package.json and in io-package.json');
337
+ }
338
+ }
339
+
340
+ if (!context.ioPackageJson.common.mode) {
341
+ context.errors.push('[E165] "common.mode" not found in io-package.json');
342
+ } else {
343
+ context.checks.push('"common.mode" found in io-package.json');
344
+
345
+ if (!context.cfg.allowedModes[context.ioPackageJson.common.mode]) {
346
+ context.errors.push(`[E166] "common.mode: ${context.ioPackageJson.common.mode}" is unknown in io-package.json.`);
347
+ } else {
348
+ context.checks.push('"common.mode" has known mode in io-package.json');
349
+
350
+ if (context.ioPackageJson.common.onlyWWW && context.ioPackageJson.common.mode !== 'none') {
351
+ context.errors.push('[E162] onlyWWW should have common.mode "none" in io-package.json');
352
+ }
353
+
354
+ if (context.ioPackageJson.common.mode === 'schedule' && !context.ioPackageJson.common.schedule) {
355
+ context.errors.push('[E167] scheduled adapters must have "common.schedule" property in io-package.json');
356
+ }
357
+ }
358
+ }
359
+
360
+ if (!context.ioPackageJson.common.type) {
361
+ context.errors.push('[E119] No type found in io-package.json');
362
+ } else {
363
+ context.checks.push('"common.type" found in io-package.json');
364
+
365
+ if (!context.cfg.allowedTypes[context.ioPackageJson.common.type]) {
366
+ context.errors.push('[E120] Unknown type found in io-package.json');
367
+ } else {
368
+ context.checks.push('"common.type" has known type in io-package.json');
369
+ }
370
+ }
371
+
372
+ if (!context.ioPackageJson.common.authors) {
373
+ context.errors.push('[E121] No authors found in io-package.json');
374
+ } else {
375
+ context.checks.push('"common.authors" found in io-package.json');
376
+
377
+ if (!(context.ioPackageJson.common.authors instanceof Array)) {
378
+ context.errors.push('[E122] authors must be an Array in io-package.json');
379
+ } else {
380
+ context.checks.push('"common.authors" is array in io-package.json');
381
+ }
382
+
383
+ if (!context.ioPackageJson.common.authors.length) {
384
+ context.errors.push('[E123] Authors may not be empty in io-package.json');
385
+ } else {
386
+ context.checks.push('"common.authors" is not empty in io-package.json');
387
+ }
388
+ }
389
+
390
+ if (context.ioPackageJson.common.localLink) {
391
+ context.warnings.push('[W172] "common.localLink" in io-package.json is deprecated. Please define object "common.localLinks": { "_default": "..." }');
392
+ } else {
393
+ context.checks.push('No "common.localLink" found in io-package.json');
394
+ }
395
+
396
+ if (!context.ioPackageJson.common.news) {
397
+ context.errors.push('[E130] No "common.news" found in io-package.json');
398
+ } else {
399
+ context.checks.push('"common.news" found in io-package.json');
400
+
401
+ if (Object.keys(context.ioPackageJson.common.news).length > 20) {
402
+ context.errors.push('[E130] Too many "common.news" found in io-package.json. Must be less than 20. Please remove old news.');
403
+ } else if (Object.keys(context.ioPackageJson.common.news).length > 7) {
404
+ context.warnings.push('[W130] Many "common.news" found in io-package.json. Repository builder will truncate at 7 news. Please remove old news.');
405
+ }
406
+
407
+ Object.keys(context.ioPackageJson.common.news).forEach(version => {
408
+ if (!compareVersions.validateStrict(version)) {
409
+ context.errors.push(`[E175] Release "${version}" at "common.news" in io-package.json is malformed.`);
410
+ }
411
+ });
412
+
413
+ if (!context.ioPackageJson.common.news[context.ioPackageJson.common.version]) {
414
+ context.errors.push(`[E145] No "common.news" found for actual version ${context.ioPackageJson.common.version} in io-package.json`);
415
+ }
416
+
417
+ let missingLang =[];
418
+ Object.keys(context.ioPackageJson.common.news).forEach(version => {
419
+ missingLang = missingLang.concat( common.checkLanguages(context.ioPackageJson.common.news[version], context.cfg.requiredLanguages) );
420
+ });
421
+ if (missingLang.length) {
422
+ missingLang = [... new Set(missingLang)]; // make unique
423
+ context.warnings.push(`[E145] Missing mandatory translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
424
+ }
425
+
426
+ missingLang =[];
427
+ Object.keys(context.ioPackageJson.common.news).forEach(version => {
428
+ missingLang = missingLang.concat(common.checkLanguages(context.ioPackageJson.common.news[version], context.cfg.allowedLanguages));
429
+ });
430
+ missingLang = missingLang.filter( lang => !context.cfg.requiredLanguages.includes(lang));
431
+ if (missingLang.length) {
432
+ missingLang = [... new Set(missingLang)]; // make unique
433
+ context.warnings.push(`[W145] Missing suggested translation into ${missingLang.join()} of some "common.news" in io-package.json.`);
434
+ }
435
+
436
+ }
437
+
438
+ // now check the package.json again, because it is valid only for onlyWWW
439
+ if (!context.packageJson.main) {
440
+ !context.ioPackageJson.common.onlyWWW && context.errors.push('[E143] No main found in the package.json');
441
+ } else {
442
+ context.checks.push('"main" found in package.json');
443
+
444
+ if (context.ioPackageJson.common.mode !== 'none' && !context.packageJson.main.endsWith('.js')) {
445
+ !context.ioPackageJson.common.onlyWWW && context.errors.push(`[E163] common.mode "${context.ioPackageJson.common.mode}" requires JavaScript file for "main" in package.json`);
446
+ }
447
+ }
448
+
449
+ //if (context.ioPackageJson.common.installedFrom) {
450
+ // context.errors.push('[E144] common.installedFrom field found in io-package.json. Must be removed.');
451
+ //}
452
+
453
+ if (context.ioPackageJson.instanceObjects) {
454
+ const instanceObjects = context.ioPackageJson.instanceObjects;
455
+ if (!(instanceObjects instanceof Array)) {
456
+ context.errors.push('[E146] instanceObjects must be an Array in io-package.json');
457
+ } else {
458
+ const allowedObjectTypes = ['state', 'channel', 'device', 'enum', 'host', 'adapter', 'instance', 'meta', 'config', 'script', 'user', 'group', 'chart', 'folder'];
459
+ const allowedStateTypes = ['number', 'string', 'boolean', 'array', 'object', 'mixed', 'file', 'json'];
460
+
461
+ instanceObjects.forEach(instanceObject => {
462
+ if (instanceObject.type !== undefined && !allowedObjectTypes.includes(instanceObject.type)) {
463
+ context.errors.push(`[E147] instanceObject type has an invalid type: ${instanceObject.type}`);
464
+ }
465
+
466
+ if (instanceObject.common) {
467
+ if (instanceObject.common.type !== undefined) {
468
+ if (typeof instanceObject.common.type !== 'string') {
469
+ context.errors.push(`[E148] instanceObject common.type has an invalid type! Expected "string", received "${typeof instanceObject.common.type}"`);
470
+ }
471
+
472
+ if (instanceObject.type === 'state' && !allowedStateTypes.includes(instanceObject.common.type)) {
473
+ context.errors.push(`[E149] instanceObject common.type has an invalid value: ${instanceObject.common.type}`);
474
+ }
475
+ }
476
+ }
477
+ });
478
+ }
479
+ }
480
+
481
+ if (!context.ioPackageJson.common.connectionType) {
482
+ !context.ioPackageJson.common.onlyWWW && context.errors.push('[E150] No "common.connectionType" found in io-package.json');
483
+ } else if (!['local', 'cloud', 'none'].includes(context.ioPackageJson.common.connectionType)) {
484
+ context.errors.push(`[E151] "common.connectionType" type has an invalid value "${context.ioPackageJson.common.connectionType}"`);
485
+ }
486
+
487
+ if (!context.ioPackageJson.common.dataSource) {
488
+ !context.ioPackageJson.common.onlyWWW && context.errors.push('[E152] No "common.dataSource" found in io-package.json');
489
+ } else if (!['poll', 'push', 'assumption', 'none'].includes(context.ioPackageJson.common.dataSource)) {
490
+ context.errors.push(`[E153] "common.dataSource" type has an invalid value "${context.ioPackageJson.common.dataSource}"`);
491
+ }
492
+
493
+ let currentJsControllerVersion = undefined;
494
+
495
+ if (context.ioPackageJson.common.dependencies) {
496
+ if (!(context.ioPackageJson.common.dependencies instanceof Array)) {
497
+ context.errors.push(`[E185] "common.dependencies" must be an array at io-package.json`);
498
+ } else {
499
+ const dependencyArray = common.getDependencyArray(context.ioPackageJson.common.dependencies);
500
+
501
+ // Admin is not allowed in dependencies (globalDependencies only)
502
+ if (dependencyArray.includes('admin')) {
503
+ context.errors.push(`[E160] "admin" is not allowed in common.dependencies`);
504
+ }
505
+
506
+ const jsControllerDependency = context.ioPackageJson.common.dependencies.find(dep => Object.keys(dep).find(attr => attr === 'js-controller'));
507
+ if (jsControllerDependency) {
508
+ console.log(`Found current js-controller dependency "${jsControllerDependency['js-controller']}"`);
509
+
510
+ if (!jsControllerDependency['js-controller'].startsWith('>=')) {
511
+ context.errors.push(`[E159] common.dependencies "js-controller" dependency should always allow future versions (>=x.x.x) - recommended: {"js-controller": ">=${recommendedJsControllerVersion}"}`);
512
+ } else {
513
+ currentJsControllerVersion = jsControllerDependency['js-controller'].replace(/[^\d.]/g, '');
514
+ }
515
+ } else {
516
+ context.errors.push(`[E162] js-controller dependency missing. js-controller ${requiredJsControllerVersion} is required as minimum, ${recommendedJsControllerVersion} is recommended. Please add to dependencies at io-package.json.`);
517
+ }
518
+ }
519
+ }
520
+
521
+ /*
522
+ increase dependency as required by addition features
523
+ */
524
+ if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.supportedMessges) {
525
+ requiredJsControllerVersion = common.maxVersion( requiredJsControllerVersion, '5.0.18');
526
+ }
527
+ if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.nodeProcessParams) {
528
+ requiredJsControllerVersion = common.maxVersion( requiredJsControllerVersion, '5.0.18');
529
+ }
530
+
531
+
532
+ if ( currentJsControllerVersion && compareVersions.compare( requiredJsControllerVersion, currentJsControllerVersion, '>' )) {
533
+ context.errors.push(`[E162] js-controller ${currentJsControllerVersion} listed as dependency but ${requiredJsControllerVersion} is required as minimum, ${recommendedJsControllerVersion} is recommended. Please update dependency at io-package.json.`);
534
+ } else if ( currentJsControllerVersion && compareVersions.compare( recommendedJsControllerVersion, currentJsControllerVersion, '>' )) {
535
+ context.warnings.push(`[W162] js-controller ${currentJsControllerVersion} listed as dependency but ${recommendedJsControllerVersion} is recommended. Please consider updating dependency at io-package.json.`);
536
+ }
537
+
538
+ if (context.ioPackageJson.common.globalDependencies) {
539
+ const dependencyArray = common.getDependencyArray(context.ioPackageJson.common.globalDependencies);
540
+
541
+ if (!(context.ioPackageJson.common.globalDependencies instanceof Array)) {
542
+ context.errors.push(`[E186] "common.globalDependencies" must be an array at io-package.json`);
543
+ } else {
544
+ // js-controller is not allowed in global dependencies (dependencies only)
545
+ if (dependencyArray.includes('js-controller')) {
546
+ context.errors.push(`[E161] "js-controller" is not allowed in common.globalDependencies`);
547
+ }
548
+ }
549
+
550
+ }
551
+
552
+
553
+ if (!context.ioPackageJson.common.onlyWWW) {
554
+ if (!context.ioPackageJson.common.tier) {
555
+ context.warnings.push(`[W115] "common.tier" is required in io-package.json. Please check https://github.com/ioBroker/ioBroker.docs/blob/master/docs/en/dev/objectsschema.md#adapter.`);
556
+ } else if (![1, 2, 3].includes(context.ioPackageJson.common.tier)) {
557
+ context.errors.push(`[E155] Invalid "common.tier" value: ${context.ioPackageJson.common.tier} at io-package.json. Only 1, 2 or 3 are allowed!`);
558
+ } else {
559
+ context.checks.push('"common.tier" is valid in io-package.json');
560
+ }
561
+ } else {
562
+ context.checks.push('"common.tier" check skipped for wwwOnly adapter.');
563
+ }
564
+
565
+ if (context.ioPackageJson.common.automaticUpgrade) {
566
+ context.errors.push(`[E172] "common.automaticUpgrade" will be defined by the user. Please remove from io-package.json`);
567
+ } else {
568
+ context.checks.push('"common.automaticUpgrade" does not exist in io-package.json');
569
+ }
570
+
571
+ //if (context.ioPackageJson.common.wakeup) {
572
+ // context.warnings.push(`[W174] "common.wakeup" is deprecated. Please remove from io-package.json`);
573
+ //} else {
574
+ // context.checks.push('"common.wakeup" does not exist in io-package.json');
575
+ //}
576
+
577
+ if (context.ioPackageJson.common.restartAdapters) {
578
+ const restartAdaptersArray = context.ioPackageJson.common.restartAdapters;
579
+
580
+ // own adapter is not allowed in a restart array
581
+ if (restartAdaptersArray.includes(context.ioPackageJson.common.name)) {
582
+ context.errors.push(`[E176] Own adapter is not allowed to be listed at "common.restartAdapters" in io-package.json`);
583
+ } else {
584
+ context.checks.push('Own adapter not listed at "common.restartAdapters".');
585
+ }
586
+ } else {
587
+ context.checks.push('"restartAdapters" check skipped as object not present.');
588
+ }
589
+
590
+ for (const blacklist in blacklistIOPackageJson) {
591
+ //console.log(`checking blacklist ${blacklist}`);
592
+ let tmp = context.ioPackageJson;
593
+ let log = '';
594
+ for (const element of blacklist.split('.')) {
595
+ log = `${log}.${element}`;
596
+ //console.log(` check ${log}`);
597
+ tmp = tmp[element];
598
+ if ( !tmp ) {
599
+ //console.log(` ${log} does not exist`);
600
+ break;
601
+ }
602
+ }
603
+ if (tmp) {
604
+ if (blacklistIOPackageJson[blacklist].err) {
605
+ context.errors.push(`[E184] ${blacklistIOPackageJson[blacklist].msg}`);
606
+ } else {
607
+ context.warnings.push(`[W184] ${blacklistIOPackageJson[blacklist].msg}`);
608
+ }
609
+ }
610
+ //else {
611
+ // console.log(`blacklist ${blacklist} no match`);
612
+ //}
613
+ }
614
+ context.checks.push('"blacklist (io-package)" checked.');
615
+
616
+ if (context.ioPackageJson.common.extIcon) {
617
+ try {
618
+ const icon = await common.downloadFile(context.ioPackageJson.common.extIcon, null, true);
619
+ context.checks.push('"extIcon" could be downloaded');
620
+
621
+ const image = sizeOf(icon);
622
+ if (image.width !== image.height) {
623
+ context.errors.push('[E140] width and height of logo are not equal');
624
+ } else {
625
+ context.checks.push('Width and height of logo are equal');
626
+ if (image.width < 32) {
627
+ context.errors.push('[E141] logo is too small. It must be greater or equal than 32x32');
628
+ } else if (image.width > 512) {
629
+ context.errors.push('[E142] logo is too big. It must be less or equal than 512x512');
630
+ }
631
+ }
632
+ } catch (e) {
633
+ common.debug (e);
634
+ context.errors.push(`[E125] External icon not found under URL: ${context.ioPackageJson.common.extIcon}`);
635
+ }
636
+ }
637
+
638
+ if (!context.ioPackageJson.common.onlyWWW && context.packageJson.main) {
639
+ try {
640
+ await common.downloadFile(context.githubUrl, `/${context.packageJson.main}`)
641
+ context.checks.push(`${context.packageJson.main} could be downloaded`);
642
+ } catch (e) {
643
+ common.debug (e);
644
+ context.errors.push(`[E124] Main file not found under URL: ${context.githubUrl}/${context.packageJson.main}`);
645
+ }
646
+ }
647
+
648
+ // max number is E186
649
+ // free 144
650
+ // duplicates to check 145
651
+ }
652
+
653
+ return context;
654
+
655
+ }
656
+
657
+ exports.getIOPackageJson = getIOPackageJson;
658
+ exports.checkIOPackageJson = checkIOPackageJson;