@movable/rollup-plugin-manifest-validator 3.2.0-app-validation

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.
Files changed (55) hide show
  1. package/.mocharc.yml +3 -0
  2. package/babel.config.json +11 -0
  3. package/dist/apps/index.js +15 -0
  4. package/dist/apps/plugins/app-manifest-validator.js +44 -0
  5. package/dist/apps/utils/app-manifest-validator.js +44 -0
  6. package/dist/apps/validators/ajvCompiler.js +43 -0
  7. package/dist/apps/validators/erroringValidator.js +16 -0
  8. package/dist/apps/validators/index.js +23 -0
  9. package/dist/apps/validators/warningValidator.js +16 -0
  10. package/dist/index.js +21 -0
  11. package/dist/packages/index.js +15 -0
  12. package/dist/packages/plugins/package-manifest-validator.js +44 -0
  13. package/dist/packages/utils/package-manifest-validator.js +44 -0
  14. package/dist/packages/validators/ajvCompiler.js +43 -0
  15. package/dist/packages/validators/erroringValidator.js +16 -0
  16. package/dist/packages/validators/index.js +23 -0
  17. package/dist/packages/validators/warningValidator.js +16 -0
  18. package/dist/schemas/enums.js +14 -0
  19. package/dist/schemas/erroringSchemaApps.js +809 -0
  20. package/dist/schemas/erroringSchemaPackages.js +17 -0
  21. package/dist/schemas/index.js +39 -0
  22. package/dist/schemas/warningSchemaApps.js +8 -0
  23. package/dist/schemas/warningSchemaPackages.js +504 -0
  24. package/package.json +42 -0
  25. package/src/apps/index.js +3 -0
  26. package/src/apps/plugins/app-manifest-validator.js +22 -0
  27. package/src/apps/utils/app-manifest-validator.js +31 -0
  28. package/src/apps/validators/ajvCompiler.js +28 -0
  29. package/src/apps/validators/erroringValidator.js +4 -0
  30. package/src/apps/validators/index.js +4 -0
  31. package/src/apps/validators/warningValidator.js +4 -0
  32. package/src/index.js +4 -0
  33. package/src/packages/index.js +3 -0
  34. package/src/packages/plugins/package-manifest-validator.js +19 -0
  35. package/src/packages/utils/package-manifest-validator.js +31 -0
  36. package/src/packages/validators/ajvCompiler.js +28 -0
  37. package/src/packages/validators/erroringValidator.js +4 -0
  38. package/src/packages/validators/index.js +4 -0
  39. package/src/packages/validators/warningValidator.js +4 -0
  40. package/src/schemas/enums.js +130 -0
  41. package/src/schemas/erroringSchemaApps.js +468 -0
  42. package/src/schemas/erroringSchemaPackages.js +8 -0
  43. package/src/schemas/index.js +6 -0
  44. package/src/schemas/warningSchemaApps.js +1 -0
  45. package/src/schemas/warningSchemaPackages.js +304 -0
  46. package/test/fixtures/blankFile.js +0 -0
  47. package/test/fixtures/invalidField.yml +3 -0
  48. package/test/fixtures/master-app-manifest.yml +72 -0
  49. package/test/fixtures/master-package-manifest.yml +100 -0
  50. package/test/fixtures/noName.yml +1 -0
  51. package/test/helpers/lib.js +10 -0
  52. package/test/plugins/app-manifest-validation.js +34 -0
  53. package/test/plugins/package-manifest-validation.js +62 -0
  54. package/test/utils/app-manifest-validation.js +785 -0
  55. package/test/utils/package-manifest-validation.js +1515 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ type: 'object',
9
+ properties: {
10
+ name: {
11
+ type: 'string'
12
+ }
13
+ },
14
+ required: ['name'],
15
+ prohibited: ['clickthrough_dynamic_property']
16
+ };
17
+ exports.default = _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "erroringSchemaApps", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _erroringSchemaApps.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "erroringSchemaPackages", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _erroringSchemaPackages.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "warningSchemaApps", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _warningSchemaApps.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "warningSchemaPackages", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _warningSchemaPackages.default;
28
+ }
29
+ });
30
+
31
+ var _warningSchemaApps = _interopRequireDefault(require("./warningSchemaApps"));
32
+
33
+ var _erroringSchemaApps = _interopRequireDefault(require("./erroringSchemaApps"));
34
+
35
+ var _warningSchemaPackages = _interopRequireDefault(require("./warningSchemaPackages"));
36
+
37
+ var _erroringSchemaPackages = _interopRequireDefault(require("./erroringSchemaPackages"));
38
+
39
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {};
8
+ exports.default = _default;
@@ -0,0 +1,504 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _enums = require("./enums");
9
+
10
+ const strNumBool = ['string', 'number', 'boolean'];
11
+ const fieldSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ allows_dynamic: {
15
+ type: 'boolean'
16
+ },
17
+ default: {
18
+ type: strNumBool
19
+ },
20
+ description: {
21
+ type: 'string'
22
+ },
23
+ label: {
24
+ type: 'string'
25
+ },
26
+ max: {
27
+ type: 'number'
28
+ },
29
+ name: {
30
+ type: 'string'
31
+ },
32
+ options: {
33
+ type: 'array',
34
+ items: {
35
+ type: 'object',
36
+ properties: {
37
+ value: {
38
+ type: strNumBool
39
+ },
40
+ label: {
41
+ type: ['string', 'number']
42
+ }
43
+ },
44
+ required: ['value', 'label'],
45
+ additionalProperties: false
46
+ }
47
+ },
48
+ placeholder: {
49
+ type: ['string', 'number']
50
+ },
51
+ preview_text: {
52
+ type: 'array',
53
+ items: {
54
+ type: strNumBool
55
+ }
56
+ },
57
+ provider: {
58
+ type: 'string'
59
+ },
60
+ template: {
61
+ type: 'string'
62
+ },
63
+ type: {
64
+ type: 'string',
65
+ enum: _enums.fieldTypes
66
+ },
67
+ value: {
68
+ type: strNumBool
69
+ },
70
+ heading: {
71
+ type: 'string'
72
+ }
73
+ },
74
+ required: ['name', 'label', 'type'],
75
+ additionalProperties: false,
76
+ allOf: [{
77
+ if: {
78
+ properties: {
79
+ type: {
80
+ enum: ['number', 'token']
81
+ }
82
+ }
83
+ },
84
+ else: {
85
+ not: {
86
+ required: ['max']
87
+ }
88
+ }
89
+ }, {
90
+ if: {
91
+ properties: {
92
+ type: {
93
+ const: 'oAuthAccount'
94
+ }
95
+ }
96
+ },
97
+ then: {
98
+ required: ['provider']
99
+ },
100
+ else: {
101
+ not: {
102
+ required: ['provider']
103
+ }
104
+ }
105
+ }, {
106
+ if: {
107
+ properties: {
108
+ type: {
109
+ const: 'data-source'
110
+ }
111
+ }
112
+ },
113
+ else: {
114
+ not: {
115
+ required: ['template']
116
+ }
117
+ }
118
+ }, {
119
+ if: {
120
+ properties: {
121
+ type: {
122
+ enum: ['select', 'radio', 'checkbox']
123
+ }
124
+ }
125
+ },
126
+ else: {
127
+ not: {
128
+ required: ['options']
129
+ }
130
+ }
131
+ }]
132
+ };
133
+ const dynamicPropertySchema = {
134
+ propertyGroupKey: {
135
+ type: 'string'
136
+ },
137
+ propertyPath: {
138
+ type: 'string'
139
+ },
140
+ propertyPreview: {
141
+ type: strNumBool
142
+ },
143
+ propertyFallback: {
144
+ type: strNumBool
145
+ },
146
+ propertyValue: {
147
+ type: 'string'
148
+ },
149
+ context: {
150
+ type: 'object'
151
+ }
152
+ };
153
+ const toolSchema = {
154
+ type: 'object',
155
+ properties: {
156
+ class_names: {
157
+ type: 'string'
158
+ },
159
+ fields: {
160
+ type: 'array',
161
+ items: fieldSchema
162
+ },
163
+ icon: {
164
+ type: 'string',
165
+ enum: _enums.studioIcons
166
+ },
167
+ label: {
168
+ type: 'string'
169
+ },
170
+ name: {
171
+ type: 'string'
172
+ },
173
+ type: {
174
+ type: 'string'
175
+ },
176
+ locked: {
177
+ type: 'boolean'
178
+ },
179
+ dynamic_fields: {
180
+ type: 'array',
181
+ items: {
182
+ type: 'object',
183
+ properties: {
184
+ type: {
185
+ type: 'string',
186
+ enum: _enums.propertyTypes
187
+ },
188
+ name: {
189
+ type: 'string'
190
+ },
191
+ label: {
192
+ type: 'string'
193
+ },
194
+ allow_static_option: {
195
+ type: 'boolean'
196
+ }
197
+ },
198
+ required: ['name', 'label'],
199
+ additionalProperties: false
200
+ }
201
+ },
202
+ defaults: {
203
+ type: 'object',
204
+ properties: {
205
+ dynamicProperty: {
206
+ type: 'object',
207
+ properties: dynamicPropertySchema,
208
+ required: ['propertyPath'],
209
+ additionalProperties: false
210
+ },
211
+ height: {
212
+ type: 'number'
213
+ },
214
+ width: {
215
+ type: 'number'
216
+ }
217
+ },
218
+ additionalProperties: false
219
+ }
220
+ },
221
+ required: ['name', 'icon', 'label', 'type'],
222
+ additionalProperties: false
223
+ };
224
+ const propertySchema = {
225
+ type: 'object',
226
+ properties: {
227
+ name: {
228
+ type: 'string'
229
+ },
230
+ label: {
231
+ type: 'string'
232
+ },
233
+ description: {
234
+ type: 'string'
235
+ },
236
+ type: {
237
+ type: 'string',
238
+ enum: _enums.propertyTypes
239
+ },
240
+ preview_text: {
241
+ type: 'array',
242
+ items: {
243
+ type: strNumBool
244
+ }
245
+ },
246
+ preview_values: {
247
+ type: 'array',
248
+ items: {
249
+ type: strNumBool
250
+ }
251
+ },
252
+ context_options: {
253
+ type: 'array',
254
+ items: {
255
+ type: 'object',
256
+ properties: {
257
+ name: {
258
+ type: 'string'
259
+ },
260
+ type: {
261
+ type: 'string',
262
+ enum: _enums.contextOptionTypes
263
+ },
264
+ description: {
265
+ type: 'string'
266
+ },
267
+ defaultValue: {
268
+ type: 'number'
269
+ },
270
+ options: {
271
+ type: 'array',
272
+ minItems: 1,
273
+ items: {
274
+ type: 'object',
275
+ properties: {
276
+ label: {
277
+ type: 'string'
278
+ },
279
+ value: {
280
+ type: strNumBool
281
+ }
282
+ },
283
+ required: ['value', 'label'],
284
+ additionalProperties: false
285
+ }
286
+ }
287
+ },
288
+ required: ['name', 'type'],
289
+ additionalProperties: false,
290
+ allOf: [{
291
+ if: {
292
+ properties: {
293
+ type: {
294
+ enum: ['select']
295
+ }
296
+ }
297
+ },
298
+ then: {
299
+ required: ['options']
300
+ }
301
+ }]
302
+ }
303
+ }
304
+ },
305
+ required: ['name', 'label'],
306
+ additionalProperties: false
307
+ };
308
+ var _default = {
309
+ type: 'object',
310
+ properties: {
311
+ name: {
312
+ type: 'string'
313
+ },
314
+ label: {
315
+ type: 'string'
316
+ },
317
+ query_params: {
318
+ type: 'object',
319
+ patternProperties: {
320
+ '.*': {
321
+ type: 'string'
322
+ }
323
+ }
324
+ },
325
+ cold_states: {
326
+ type: 'array',
327
+ items: {
328
+ type: 'object',
329
+ properties: {
330
+ name: {
331
+ type: 'string'
332
+ },
333
+ width: {
334
+ type: 'number'
335
+ },
336
+ height: {
337
+ type: 'number'
338
+ }
339
+ },
340
+ required: ['name'],
341
+ additionalProperties: false
342
+ }
343
+ },
344
+ integration_ids: {
345
+ type: 'array',
346
+ items: {
347
+ type: 'string',
348
+ pattern: '^[a-zA-Z0-9]+$',
349
+ minLength: 15,
350
+ maxLength: 15
351
+ }
352
+ },
353
+ fields: {
354
+ type: 'array',
355
+ items: fieldSchema
356
+ },
357
+ field_headings: {
358
+ type: 'array',
359
+ items: {
360
+ type: 'object',
361
+ required: ['name', 'label'],
362
+ properties: {
363
+ name: {
364
+ type: 'string'
365
+ },
366
+ label: {
367
+ type: 'string'
368
+ },
369
+ toggleable: {
370
+ type: 'boolean'
371
+ },
372
+ default_toggle_collapsed: {
373
+ type: 'boolean'
374
+ }
375
+ }
376
+ }
377
+ },
378
+ studio_options: {
379
+ type: 'object',
380
+ properties: {
381
+ prohibit_custom_params: {
382
+ type: 'boolean'
383
+ },
384
+ framework_version: {
385
+ type: 'string',
386
+ pattern: '^(\\d+\\.){2}\\d+$'
387
+ },
388
+ tools: {
389
+ type: 'array',
390
+ items: toolSchema
391
+ },
392
+ preview_fields: {
393
+ type: 'array',
394
+ items: {
395
+ type: 'string'
396
+ }
397
+ },
398
+ property_groups: {
399
+ type: 'array',
400
+ items: {
401
+ type: 'object',
402
+ properties: {
403
+ name: {
404
+ type: 'string'
405
+ },
406
+ label: {
407
+ type: 'string'
408
+ },
409
+ description: {
410
+ type: 'string'
411
+ },
412
+ properties: {
413
+ type: 'array',
414
+ items: propertySchema
415
+ }
416
+ },
417
+ required: ['name', 'label', 'properties'],
418
+ additionalProperties: false
419
+ },
420
+ minItems: 1,
421
+ maxItems: 1
422
+ },
423
+ element_modifiers: {
424
+ type: 'array',
425
+ items: {
426
+ type: 'object',
427
+ properties: {
428
+ name: {
429
+ type: 'string'
430
+ },
431
+ label: {
432
+ type: 'string'
433
+ },
434
+ description: {
435
+ type: 'string'
436
+ }
437
+ },
438
+ required: ['name', 'label'],
439
+ additionalProperties: false
440
+ }
441
+ },
442
+ property_modifiers: {
443
+ type: 'array',
444
+ items: {
445
+ type: 'object',
446
+ properties: {
447
+ name: {
448
+ type: 'string'
449
+ },
450
+ label: {
451
+ type: 'string'
452
+ },
453
+ type: {
454
+ type: 'string',
455
+ enum: _enums.propertyTypes
456
+ },
457
+ preview_text: {
458
+ type: 'array',
459
+ items: {
460
+ type: strNumBool
461
+ }
462
+ },
463
+ description: {
464
+ type: 'string'
465
+ },
466
+ propertyInputs: {
467
+ type: 'array',
468
+ items: {
469
+ type: 'object',
470
+ properties: {
471
+ name: {
472
+ type: 'string'
473
+ },
474
+ variableName: {
475
+ type: 'string'
476
+ },
477
+ label: {
478
+ type: 'string'
479
+ },
480
+ allow_static_option: {
481
+ type: 'boolean'
482
+ },
483
+ type: {
484
+ type: 'string'
485
+ }
486
+ },
487
+ required: ['name', 'label', 'variableName'],
488
+ additionalProperties: false
489
+ }
490
+ }
491
+ },
492
+ required: ['name', 'label'],
493
+ additionalProperties: false
494
+ }
495
+ }
496
+ },
497
+ additionalProperties: false
498
+ }
499
+ },
500
+ name: true,
501
+ required: ['name'],
502
+ additionalProperties: false
503
+ };
504
+ exports.default = _default;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@movable/rollup-plugin-manifest-validator",
3
+ "version": "3.2.0-app-validation",
4
+ "description": "Validates app-manifest and package-manifest.yml",
5
+ "main": "dist",
6
+ "keywords": [],
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/movableink/studio-framework/tree/master/packages/rollup-plugin-manifest-validator.git"
10
+ },
11
+ "license": "MIT",
12
+ "author": {
13
+ "name": "Movable Ink"
14
+ },
15
+ "scripts": {
16
+ "test": "mocha --recursive",
17
+ "dev": "yarn test -w",
18
+ "build": "./node_modules/.bin/babel src --out-dir dist",
19
+ "prepublish": "yarn run build"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "devDependencies": {
25
+ "@babel/cli": "^7.13.16",
26
+ "@babel/core": "^7.14.0",
27
+ "@babel/preset-env": "^7.20.2",
28
+ "@babel/register": "^7.13.16",
29
+ "chai": "^4.3.4",
30
+ "mocha": "^8.3.2",
31
+ "rollup": "^2.52.2"
32
+ },
33
+ "dependencies": {
34
+ "ajv": "6.12.6",
35
+ "ajv-keywords": "^3.0.0",
36
+ "yamljs": "^0.3.0"
37
+ },
38
+ "volta": {
39
+ "extends": "../../package.json"
40
+ },
41
+ "gitHead": "4480978dc5c4fdc28f0dd55f569fe6d8344f6469"
42
+ }
@@ -0,0 +1,3 @@
1
+ import manifestValidatorPluginApps from './plugins/app-manifest-validator';
2
+
3
+ export { manifestValidatorPluginApps };
@@ -0,0 +1,22 @@
1
+ import YAML from 'yamljs';
2
+ import { readFileSync } from 'fs';
3
+ import appManifestValidator from '../utils/app-manifest-validator';
4
+
5
+ const formatJSON = (j) => JSON.stringify(j, null, 1);
6
+
7
+ export default ({ manifestPath }) => ({
8
+ buildStart() {
9
+ this.addWatchFile(manifestPath);
10
+
11
+ const manifest = YAML.parse(readFileSync(manifestPath).toString('utf-8'));
12
+ const { warnings, errors } = appManifestValidator(manifest);
13
+
14
+ if (errors.length) {
15
+ this.error({ message: `INVALID APP MANIFEST: ${formatJSON(errors)}` });
16
+ }
17
+
18
+ warnings.forEach((w) =>
19
+ this.warn({ message: `'APP MANIFEST VALIDATION WARNING': ${formatJSON(w)}` })
20
+ );
21
+ }
22
+ });
@@ -0,0 +1,31 @@
1
+ import { warningValidator, erroringValidator } from '../validators';
2
+
3
+ export const TOP_LEVEL_PROHIBITED_PROPERTY_MESSAGE =
4
+ 'Manifest has a prohibited keyword at the top level.';
5
+ const TOP_LEVEL_PATH = 'app-manifest.yml';
6
+
7
+ const parseValidationItem = ({ message, dataPath, params, keyword }) => {
8
+ const validation = {
9
+ message,
10
+ dataPath,
11
+ params
12
+ };
13
+
14
+ if (!dataPath) {
15
+ validation.dataPath = TOP_LEVEL_PATH;
16
+ if (keyword === 'prohibited') validation.message = TOP_LEVEL_PROHIBITED_PROPERTY_MESSAGE;
17
+ }
18
+
19
+ return validation;
20
+ };
21
+
22
+ export default function validateManifest(manifest) {
23
+ warningValidator(manifest);
24
+ erroringValidator(manifest);
25
+ const warnings = warningValidator.errors ?? [];
26
+ const errors = erroringValidator.errors ?? [];
27
+ return {
28
+ warnings: warnings.map(parseValidationItem),
29
+ errors: errors.map(parseValidationItem)
30
+ };
31
+ }
@@ -0,0 +1,28 @@
1
+ import Ajv from 'ajv';
2
+ import ajvKeywords from 'ajv-keywords';
3
+
4
+ const compiler = new Ajv({ allErrors: true });
5
+ ajvKeywords(compiler);
6
+
7
+ compiler.addKeyword('name', {
8
+ schema: false,
9
+ validate: function validation(data) {
10
+ const { name: appName } = data;
11
+ const propertyGroup = data.studio_options?.property_groups?.[0];
12
+ if (propertyGroup?.name) {
13
+ validation.errors = [
14
+ {
15
+ message: 'property_group name must match app name',
16
+ keyword: 'invalidPropertyGroupName',
17
+ params: { name: propertyGroup.name },
18
+ dataPath: '.studio_options.propertyGroups[0]'
19
+ }
20
+ ];
21
+ return propertyGroup.name === appName;
22
+ }
23
+ return true;
24
+ },
25
+ errors: true
26
+ });
27
+
28
+ export default compiler;
@@ -0,0 +1,4 @@
1
+ import ajvCompiler from './ajvCompiler';
2
+ import { erroringSchemaApps } from '../../schemas';
3
+
4
+ export default ajvCompiler.compile(erroringSchemaApps);
@@ -0,0 +1,4 @@
1
+ import warningValidator from './warningValidator';
2
+ import erroringValidator from './erroringValidator';
3
+
4
+ export { warningValidator, erroringValidator };