@squiz/dx-json-schema-lib 1.2.13-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/jest.config.ts +20 -0
  3. package/jsonCompiler.ts +22 -0
  4. package/lib/JsonValidationService.d.ts +9 -0
  5. package/lib/JsonValidationService.js +54 -0
  6. package/lib/JsonValidationService.js.map +1 -0
  7. package/lib/JsonValidationService.spec.d.ts +1 -0
  8. package/lib/JsonValidationService.spec.js +143 -0
  9. package/lib/JsonValidationService.spec.js.map +1 -0
  10. package/lib/errors/SchemaValidationError.d.ts +4 -0
  11. package/lib/errors/SchemaValidationError.js +12 -0
  12. package/lib/errors/SchemaValidationError.js.map +1 -0
  13. package/lib/formatted-text/v1/formattedText.d.ts +51 -0
  14. package/lib/formatted-text/v1/formattedText.js +9 -0
  15. package/lib/formatted-text/v1/formattedText.js.map +1 -0
  16. package/lib/formatted-text/v1/formattedText.json +134 -0
  17. package/lib/formatted-text/v1/formattedTextModels.d.ts +1 -0
  18. package/lib/formatted-text/v1/formattedTextModels.js +28 -0
  19. package/lib/formatted-text/v1/formattedTextModels.js.map +1 -0
  20. package/lib/formatted-text/v1/formattedTextSchemas.d.ts +2 -0
  21. package/lib/formatted-text/v1/formattedTextSchemas.js +9 -0
  22. package/lib/formatted-text/v1/formattedTextSchemas.js.map +1 -0
  23. package/lib/index.d.ts +7 -0
  24. package/lib/index.js +37 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/manifest/v1/DxComponentIcons.json +2279 -0
  27. package/lib/manifest/v1/DxComponentInputSchema.json +20 -0
  28. package/lib/manifest/v1/DxComponentInputSchema.spec.d.ts +1 -0
  29. package/lib/manifest/v1/DxComponentInputSchema.spec.js +113 -0
  30. package/lib/manifest/v1/DxComponentInputSchema.spec.js.map +1 -0
  31. package/lib/manifest/v1/DxContentMetaSchema.json +165 -0
  32. package/lib/manifest/v1/__test__/schemas/badFunctionInputComponent.json +39 -0
  33. package/lib/manifest/v1/__test__/schemas/badNestedFunctionInput.json +39 -0
  34. package/lib/manifest/v1/__test__/schemas/nonObjectFunctionInputComponent.json +39 -0
  35. package/lib/manifest/v1/__test__/schemas/validComponent.json +40 -0
  36. package/lib/manifest/v1/manifestModels.d.ts +1 -0
  37. package/lib/manifest/v1/manifestModels.js +28 -0
  38. package/lib/manifest/v1/manifestModels.js.map +1 -0
  39. package/lib/manifest/v1/manifestSchemas.d.ts +2 -0
  40. package/lib/manifest/v1/manifestSchemas.js +9 -0
  41. package/lib/manifest/v1/manifestSchemas.js.map +1 -0
  42. package/lib/manifest/v1/subSchemas.d.ts +4 -0
  43. package/lib/manifest/v1/subSchemas.js +13 -0
  44. package/lib/manifest/v1/subSchemas.js.map +1 -0
  45. package/lib/manifest/v1/v1.d.ts +460 -0
  46. package/lib/manifest/v1/v1.js +9 -0
  47. package/lib/manifest/v1/v1.js.map +1 -0
  48. package/lib/manifest/v1/v1.json +362 -0
  49. package/lib/manifest/v1/v1.spec.d.ts +1 -0
  50. package/lib/manifest/v1/v1.spec.js +35 -0
  51. package/lib/manifest/v1/v1.spec.js.map +1 -0
  52. package/package.json +36 -0
  53. package/src/JsonValidationService.spec.ts +162 -0
  54. package/src/JsonValidationService.ts +54 -0
  55. package/src/errors/SchemaValidationError.ts +9 -0
  56. package/src/formatted-text/v1/formattedText.json +145 -0
  57. package/src/formatted-text/v1/formattedText.ts +54 -0
  58. package/src/formatted-text/v1/formattedTextModels.ts +1 -0
  59. package/src/formatted-text/v1/formattedTextSchemas.ts +3 -0
  60. package/src/index.ts +10 -0
  61. package/src/manifest/v1/DxComponentIcons.json +2279 -0
  62. package/src/manifest/v1/DxComponentInputSchema.json +20 -0
  63. package/src/manifest/v1/DxComponentInputSchema.spec.ts +136 -0
  64. package/src/manifest/v1/DxContentMetaSchema.json +165 -0
  65. package/src/manifest/v1/__test__/schemas/badFunctionInputComponent.json +39 -0
  66. package/src/manifest/v1/__test__/schemas/badNestedFunctionInput.json +39 -0
  67. package/src/manifest/v1/__test__/schemas/nonObjectFunctionInputComponent.json +39 -0
  68. package/src/manifest/v1/__test__/schemas/validComponent.json +40 -0
  69. package/src/manifest/v1/manifestModels.ts +1 -0
  70. package/src/manifest/v1/manifestSchemas.ts +3 -0
  71. package/src/manifest/v1/subSchemas.ts +5 -0
  72. package/src/manifest/v1/v1.json +369 -0
  73. package/src/manifest/v1/v1.spec.ts +39 -0
  74. package/src/manifest/v1/v1.ts +2731 -0
  75. package/tsconfig.json +16 -0
  76. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,369 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "ComponentManifest",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "$schema": { "type": "string", "description": "the manifest schema version" },
8
+ "namespace": {
9
+ "type": "string",
10
+ "description": "Namesapce of the component",
11
+ "$ref": "#/definitions/name-pattern"
12
+ },
13
+ "name": { "type": "string", "description": "Name of the component", "$ref": "#/definitions/name-pattern" },
14
+ "displayName": { "type": "string", "description": "Display name of the component" },
15
+ "description": { "type": "string", "description": "Description of the component" },
16
+ "mainFunction": {
17
+ "type": "string",
18
+ "description": "Name of the main function to be executed at the root of the access url"
19
+ },
20
+ "icon": {
21
+ "$ref": "DxComponentIcons.json"
22
+ },
23
+ "version": {
24
+ "type": "string",
25
+ "description": "Semver version number",
26
+ "minLength": 5,
27
+ "maxLength": 14,
28
+ "pattern": "^(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)$"
29
+ },
30
+ "environment": {
31
+ "type": "array",
32
+ "description": "an array of environmental variables needed to execute correctly. These variables are set through your local environment variables during testing or through the component set during production run time",
33
+ "items": {
34
+ "type": "object",
35
+ "properties": {
36
+ "name": {
37
+ "type": "string",
38
+ "$ref": "#/definitions/name-pattern",
39
+ "description": "Environmental variable name"
40
+ },
41
+ "required": {
42
+ "type": "boolean",
43
+ "default": true
44
+ }
45
+ },
46
+ "required": ["name"]
47
+ }
48
+ },
49
+
50
+ "staticFiles": {
51
+ "type": "object",
52
+ "properties": {
53
+ "locationRoot": {
54
+ "type": "string",
55
+ "description": "The location the system begins looking static files. All static files will be referenced from here."
56
+ }
57
+ },
58
+
59
+ "required": ["locationRoot"]
60
+ },
61
+ "functions": {
62
+ "type": "array",
63
+ "minItems": 0,
64
+ "items": {
65
+ "title": "ComponentFunction",
66
+ "description": "Component function definition, this object provides the runtime with input validation and what to execute",
67
+ "type": "object",
68
+ "properties": {
69
+ "name": {
70
+ "type": "string",
71
+ "$ref": "#/definitions/name-pattern",
72
+ "description": "Function name, this will be used as part of the url to access this function"
73
+ },
74
+ "entry": {
75
+ "type": "string",
76
+ "description": "File path to the javascript file to execute. The file path must be relative to the manifest file and cannot be in a folder above the manifest file."
77
+ },
78
+ "input": {
79
+ "$ref": "DxComponentInputSchema.json"
80
+ },
81
+ "output": {
82
+ "oneOf": [
83
+ {
84
+ "title": "HtmlResponse",
85
+ "type": "object",
86
+ "additionalProperties": false,
87
+ "description": "The HtmlResponse type is for returning html content. The response out of the function must be a string. This response object also includes references to resources (staticFiles) the component needs to execute correctly. It is up to the integrating system to respect this.",
88
+ "properties": {
89
+ "responseType": { "const": "html" },
90
+
91
+ "staticFiles": {
92
+ "type": "array",
93
+ "description": "A list of static resources that are required for the component to execute correctly",
94
+ "items": {
95
+ "type": "object",
96
+ "title": "HtmlStaticFile",
97
+ "additionalProperties": false,
98
+ "properties": {
99
+ "location": {
100
+ "description": "The location property is used to inform integrating system if the static resource should be included in the header of footer of the document",
101
+ "oneOf": [
102
+ {
103
+ "const": "header"
104
+ },
105
+ {
106
+ "const": "footer"
107
+ }
108
+ ]
109
+ },
110
+ "file": {
111
+ "oneOf": [
112
+ {
113
+ "type": "object",
114
+ "title": "JsFile",
115
+ "additionalProperties": false,
116
+ "properties": {
117
+ "type": {
118
+ "const": "js"
119
+ },
120
+ "filepath": {
121
+ "type": "string"
122
+ },
123
+ "defer": {
124
+ "type": "boolean"
125
+ },
126
+ "async": {
127
+ "type": "boolean"
128
+ },
129
+ "integrity": {
130
+ "type": "string"
131
+ },
132
+ "crossorigin": {
133
+ "oneOf": [
134
+ {
135
+ "const": "anonymous"
136
+ },
137
+ {
138
+ "const": "use-credentials"
139
+ }
140
+ ]
141
+ },
142
+ "referrerpolicy": {
143
+ "oneOf": [
144
+ {
145
+ "const": "no-referrer"
146
+ },
147
+ {
148
+ "const": "no-referrer-when-downgrade"
149
+ },
150
+ {
151
+ "const": "origin"
152
+ },
153
+ {
154
+ "const": "origin-when-cross-origin"
155
+ },
156
+ {
157
+ "const": "same-origin"
158
+ },
159
+ {
160
+ "const": "strict-origin"
161
+ },
162
+ {
163
+ "const": "strict-origin-when-cross-origin"
164
+ },
165
+ {
166
+ "const": "unsafe-url"
167
+ }
168
+ ]
169
+ }
170
+ },
171
+ "required": ["filepath", "type"]
172
+ },
173
+ {
174
+ "type": "object",
175
+ "title": "CssFile",
176
+ "additionalProperties": false,
177
+ "properties": {
178
+ "type": {
179
+ "const": "css"
180
+ },
181
+ "filepath": {
182
+ "type": "string"
183
+ },
184
+ "crossorigin": {
185
+ "oneOf": [
186
+ {
187
+ "const": "anonymous"
188
+ },
189
+ {
190
+ "const": "use-credentials"
191
+ }
192
+ ]
193
+ },
194
+ "referrerpolicy": {
195
+ "oneOf": [
196
+ {
197
+ "const": "no-referrer"
198
+ },
199
+ {
200
+ "const": "no-referrer-when-downgrade"
201
+ },
202
+ {
203
+ "const": "origin"
204
+ },
205
+ {
206
+ "const": "origin-when-cross-origin"
207
+ },
208
+ {
209
+ "const": "same-origin"
210
+ },
211
+ {
212
+ "const": "strict-origin"
213
+ },
214
+ {
215
+ "const": "strict-origin-when-cross-origin"
216
+ },
217
+ {
218
+ "const": "unsafe-url"
219
+ }
220
+ ]
221
+ }
222
+ },
223
+ "required": ["filepath"]
224
+ }
225
+ ]
226
+ }
227
+ },
228
+ "required": ["location", "file"]
229
+ }
230
+ },
231
+ "headers": {
232
+ "title": "ResponseHeaders",
233
+ "type": "object",
234
+ "description": "Response headers to set",
235
+ "additionalProperties": {
236
+ "type": "string"
237
+ }
238
+ }
239
+ },
240
+
241
+ "required": ["responseType"]
242
+ },
243
+ {
244
+ "title": "JsonResponse",
245
+ "type": "object",
246
+ "additionalProperties": false,
247
+ "properties": {
248
+ "responseType": { "const": "json" },
249
+ "definition": { "$ref": "http://json-schema.org/draft-07/schema#" },
250
+ "headers": {
251
+ "title": "ResponseHeaders",
252
+ "type": "object",
253
+ "description": "Response headers to set",
254
+ "additionalProperties": {
255
+ "type": "string"
256
+ }
257
+ }
258
+ },
259
+
260
+ "required": ["responseType", "definition"]
261
+ }
262
+ ]
263
+ }
264
+ },
265
+ "required": ["name", "entry", "input", "output"]
266
+ }
267
+ },
268
+ "previews": {
269
+ "type": "object",
270
+ "description": "A map of previews which provide configuration to preview the component in isolation",
271
+ "propertyNames": {
272
+ "$ref": "#/definitions/name-pattern"
273
+ },
274
+ "minProperties": 1,
275
+ "additionalProperties": {
276
+ "title": "Preview Definition",
277
+ "type": "object",
278
+ "description": "Name for the preview and how it will be accessed",
279
+ "required": ["functionData"],
280
+ "properties": {
281
+ "functionData": {
282
+ "description": "A map of the functions to their respective preview information. Properties must match name of a function defined in functions list",
283
+ "type": "object",
284
+ "propertyNames": {
285
+ "$ref": "#/definitions/name-pattern"
286
+ },
287
+ "minProperties": 1,
288
+ "additionalProperties": {
289
+ "type": "object",
290
+ "title": "Function preview configuration",
291
+ "description": "Data inputs for the preview of functions in the component",
292
+ "properties": {
293
+ "inputData": {
294
+ "type": "object",
295
+ "description": "Property for defining the input data for this preview component function",
296
+ "properties": {
297
+ "type": {
298
+ "description": "An enum of 'file' or 'inline' for how the input data is defined",
299
+ "enum": ["file", "inline"]
300
+ }
301
+ },
302
+ "required": ["type"],
303
+ "oneOf": [
304
+ {
305
+ "type": "object",
306
+ "properties": {
307
+ "type": {
308
+ "enum": ["file"]
309
+ },
310
+ "path": {
311
+ "type": "string",
312
+ "format": "uri-reference",
313
+ "description": "Path to input data file"
314
+ }
315
+ },
316
+ "required": ["type", "path"]
317
+ },
318
+ {
319
+ "type": "object",
320
+ "properties": {
321
+ "type": {
322
+ "enum": ["inline"]
323
+ },
324
+ "value": {
325
+ "type": "object",
326
+ "description": "Input data value"
327
+ }
328
+ },
329
+ "required": ["type", "value"]
330
+ }
331
+ ]
332
+ },
333
+ "headers": {
334
+ "title": "ResponseHeaders",
335
+ "type": "object",
336
+ "description": "Response headers to set",
337
+ "additionalProperties": {
338
+ "type": "string"
339
+ }
340
+ },
341
+ "wrapper": {
342
+ "type": "object",
343
+ "description": "Define the extra static files which provide a container for the component function",
344
+ "properties": {
345
+ "path": {
346
+ "type": "string",
347
+ "format": "uri-reference",
348
+ "description": "File path to the wrapper container"
349
+ }
350
+ },
351
+ "required": ["path"]
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
+ },
360
+
361
+ "required": ["name", "namespace", "displayName", "description", "version", "functions", "$schema", "mainFunction"],
362
+
363
+ "definitions": {
364
+ "name-pattern": {
365
+ "type": "string",
366
+ "pattern": "^[a-zA-Z0-9_\\-]+$"
367
+ }
368
+ }
369
+ }
@@ -0,0 +1,39 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { resolve } from 'path';
3
+ import { SchemaValidationError } from '../../errors/SchemaValidationError';
4
+ import { JsonValidationService } from '../../JsonValidationService';
5
+
6
+ async function fetchTestManifest(filename: string) {
7
+ const contents = await readFile(resolve(__dirname, '__test__', 'schemas', filename), {
8
+ encoding: 'utf-8',
9
+ });
10
+ return JSON.parse(contents);
11
+ }
12
+
13
+ describe('manifest/v1', () => {
14
+ let validationService: JsonValidationService;
15
+
16
+ beforeAll(() => {
17
+ validationService = new JsonValidationService();
18
+ });
19
+
20
+ it('succeeds on a valid manifest', async () => {
21
+ const manifest = await fetchTestManifest('validComponent.json');
22
+ expect(validationService.validateManifest(manifest, 'v1')).toBeTruthy();
23
+ });
24
+
25
+ it('errors on invalid property types in function input', async () => {
26
+ const manifest = await fetchTestManifest('badFunctionInputComponent.json');
27
+ expect(() => validationService.validateManifest(manifest, 'v1')).toThrowError(SchemaValidationError);
28
+ });
29
+
30
+ it('errors on invalid property types in nested function input', async () => {
31
+ const manifest = await fetchTestManifest('badNestedFunctionInput.json');
32
+ expect(() => validationService.validateManifest(manifest, 'v1')).toThrowError(SchemaValidationError);
33
+ });
34
+
35
+ it('errors on non-object top level input', async () => {
36
+ const manifest = await fetchTestManifest('nonObjectFunctionInputComponent.json');
37
+ expect(() => validationService.validateManifest(manifest, 'v1')).toThrowError(SchemaValidationError);
38
+ });
39
+ });