@trayio/tray-schema 4.25.0 → 4.26.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/tray-schema",
3
- "version": "4.25.0",
3
+ "version": "4.26.0",
4
4
  "description": "Schema for Tray connectors and authentications",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -11,7 +11,7 @@
11
11
  "access": "public"
12
12
  },
13
13
  "dependencies": {
14
- "@trayio/commons": "4.25.0",
14
+ "@trayio/commons": "4.26.0",
15
15
  "@types/node": "18.11.9",
16
16
  "lodash": "4.17.21",
17
17
  "typescript-json-schema": "0.62.0"
@@ -1,12 +0,0 @@
1
- import { DynamicObject } from '@trayio/commons/dynamictype/DynamicType';
2
- export interface LegacyTraySchemaConverterInterface {
3
- convertToLegacySchema(schema: DynamicObject): DynamicObject;
4
- }
5
- export declare class LegacyTraySchemaConverter implements LegacyTraySchemaConverterInterface {
6
- convertToLegacySchema(schema: DynamicObject): DynamicObject;
7
- private transformTag;
8
- private transformLookup;
9
- private transformLookupInput;
10
- private transformEnums;
11
- }
12
- //# sourceMappingURL=LegacyTraySchemaConverter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LegacyTraySchemaConverter.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAExE,MAAM,WAAW,kCAAkC;IAClD,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAAC;CAC5D;AAED,qBAAa,yBACZ,YAAW,kCAAkC;IAE7C,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa;IAa3D,OAAO,CAAC,YAAY,CAwBlB;IAEF,OAAO,CAAC,eAAe,CAsBrB;IAEF,OAAO,CAAC,oBAAoB,CAc1B;IAEF,OAAO,CAAC,cAAc,CAoBpB;CACF"}
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LegacyTraySchemaConverter = void 0;
4
- class LegacyTraySchemaConverter {
5
- convertToLegacySchema(schema) {
6
- for (const [key, value] of Object.entries(schema)) {
7
- if (typeof value === 'object' && value !== null) {
8
- this.transformLookup(value);
9
- this.transformEnums(value);
10
- this.transformTag(value);
11
- this.convertToLegacySchema(value);
12
- }
13
- }
14
- return schema;
15
- }
16
- transformTag = (object) => {
17
- if (typeof object !== 'object' || object === null)
18
- return object;
19
- if (object.tag && typeof object.tag === 'string') {
20
- switch (object.tag) {
21
- case 'code':
22
- object.format = 'code';
23
- delete object.tag;
24
- break;
25
- case 'text':
26
- object.format = 'text';
27
- delete object.tag;
28
- break;
29
- case 'datetime':
30
- object.format = 'datetime';
31
- delete object.tag;
32
- break;
33
- case 'password':
34
- object.format = 'password';
35
- delete object.tag;
36
- break;
37
- default:
38
- break;
39
- }
40
- }
41
- };
42
- transformLookup = (object) => {
43
- if (typeof object !== 'object' || object === null)
44
- return object;
45
- if (object.lookup &&
46
- object.lookup.operation &&
47
- object.lookup.input) {
48
- const lookup = object.lookup;
49
- object.lookup = {
50
- url: '{{{step.ephemeral_url}}}',
51
- body: {
52
- step_settings: this.transformLookupInput(lookup.input),
53
- message: lookup.operation,
54
- ...(lookup.authRequired && { auth_id: '{{{step.auth_id}}}' }),
55
- },
56
- };
57
- }
58
- return object;
59
- };
60
- transformLookupInput = (input) => {
61
- if (typeof input !== 'object' || input === null)
62
- return input;
63
- const result = {};
64
- Object.keys(input).forEach((key) => {
65
- result[key] = {
66
- value: typeof input[key] === 'object'
67
- ? this.transformLookupInput(input[key])
68
- : input[key],
69
- type: typeof input[key],
70
- };
71
- });
72
- return result;
73
- };
74
- transformEnums = (object) => {
75
- if (typeof object !== 'object' || object === null)
76
- return object;
77
- if (object.enum &&
78
- object.enumLabels &&
79
- Array.isArray(object.enum) &&
80
- Array.isArray(object.enumLabels)) {
81
- object.enum = object.enum.map((enumItem, index) => ({
82
- value: enumItem,
83
- text: object.enumLabels[index],
84
- }));
85
- delete object.enumLabels;
86
- }
87
- return object;
88
- };
89
- }
90
- exports.LegacyTraySchemaConverter = LegacyTraySchemaConverter;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=LegacyTraySchemaConverter.unit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LegacyTraySchemaConverter.unit.test.d.ts","sourceRoot":"","sources":["../../src/schema/LegacyTraySchemaConverter.unit.test.ts"],"names":[],"mappings":""}
@@ -1,529 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const LegacyTraySchemaConverter_1 = require("./LegacyTraySchemaConverter");
4
- describe('LegacyTraySchemaConverter', () => {
5
- const converter = new LegacyTraySchemaConverter_1.LegacyTraySchemaConverter();
6
- describe('convertToLegacySchema', () => {
7
- it('should convert a connector schema with a lookup to legacy schema', () => {
8
- const schema = {
9
- type: 'object',
10
- properties: {
11
- id: {
12
- type: 'number',
13
- lookup: {
14
- operation: 'list_tables_ddl',
15
- input: {
16
- workspace_id: '{{{workspace_id}}}',
17
- project_id: '{{{project_id}}}',
18
- service: {
19
- name: '{{{service_name}}}',
20
- version: 1,
21
- },
22
- },
23
- },
24
- },
25
- },
26
- additionalProperties: false,
27
- required: ['id'],
28
- $schema: 'http://json-schema.org/draft-07/schema#',
29
- advanced: [],
30
- };
31
- const expected = {
32
- type: 'object',
33
- properties: {
34
- id: {
35
- type: 'number',
36
- lookup: {
37
- url: '{{{step.ephemeral_url}}}',
38
- body: {
39
- step_settings: {
40
- workspace_id: {
41
- value: '{{{workspace_id}}}',
42
- type: 'string',
43
- },
44
- project_id: {
45
- value: '{{{project_id}}}',
46
- type: 'string',
47
- },
48
- service: {
49
- type: 'object',
50
- value: {
51
- name: {
52
- value: '{{{service_name}}}',
53
- type: 'string',
54
- },
55
- version: {
56
- value: 1,
57
- type: 'number',
58
- },
59
- },
60
- },
61
- },
62
- message: 'list_tables_ddl',
63
- },
64
- },
65
- },
66
- },
67
- additionalProperties: false,
68
- required: ['id'],
69
- $schema: 'http://json-schema.org/draft-07/schema#',
70
- advanced: [],
71
- };
72
- const result = converter.convertToLegacySchema(schema);
73
- expect(result).toEqual(expected);
74
- });
75
- it('should convert a connector schema with a lookup and include authId on DDL when authRequired is true', () => {
76
- const schema = {
77
- type: 'object',
78
- properties: {
79
- id: {
80
- type: 'number',
81
- lookup: {
82
- operation: 'list_tables_ddl',
83
- input: {
84
- workspace_id: '{{{workspace_id}}}',
85
- project_id: '{{{project_id}}}',
86
- service: {
87
- name: '{{{service_name}}}',
88
- version: 1,
89
- },
90
- },
91
- authRequired: true,
92
- },
93
- },
94
- },
95
- additionalProperties: false,
96
- required: ['id'],
97
- $schema: 'http://json-schema.org/draft-07/schema#',
98
- advanced: [],
99
- };
100
- const expected = {
101
- type: 'object',
102
- properties: {
103
- id: {
104
- type: 'number',
105
- lookup: {
106
- url: '{{{step.ephemeral_url}}}',
107
- body: {
108
- step_settings: {
109
- workspace_id: {
110
- value: '{{{workspace_id}}}',
111
- type: 'string',
112
- },
113
- project_id: {
114
- value: '{{{project_id}}}',
115
- type: 'string',
116
- },
117
- service: {
118
- type: 'object',
119
- value: {
120
- name: {
121
- value: '{{{service_name}}}',
122
- type: 'string',
123
- },
124
- version: {
125
- value: 1,
126
- type: 'number',
127
- },
128
- },
129
- },
130
- },
131
- message: 'list_tables_ddl',
132
- auth_id: '{{{step.auth_id}}}',
133
- },
134
- },
135
- },
136
- },
137
- additionalProperties: false,
138
- required: ['id'],
139
- $schema: 'http://json-schema.org/draft-07/schema#',
140
- advanced: [],
141
- };
142
- const result = converter.convertToLegacySchema(schema);
143
- expect(result).toEqual(expected);
144
- });
145
- it('should convert a connector schema with a lookup to legacy schema and also has a lookup field', () => {
146
- const schema = {
147
- type: 'object',
148
- properties: {
149
- id: {
150
- type: 'number',
151
- lookup: {
152
- operation: 'list_tables_ddl',
153
- input: {
154
- workspace_id: '{{{workspace_id}}}',
155
- project_id: '{{{project_id}}}',
156
- },
157
- },
158
- },
159
- lookup: {
160
- type: 'string',
161
- lookup: {
162
- operation: 'list_tables_ddl',
163
- input: {
164
- workspace_id: '{{{workspace_id}}}',
165
- project_id: '{{{project_id}}}',
166
- },
167
- },
168
- },
169
- },
170
- additionalProperties: false,
171
- required: ['id'],
172
- $schema: 'http://json-schema.org/draft-07/schema#',
173
- advanced: [],
174
- };
175
- const expected = {
176
- type: 'object',
177
- properties: {
178
- id: {
179
- type: 'number',
180
- lookup: {
181
- url: '{{{step.ephemeral_url}}}',
182
- body: {
183
- step_settings: {
184
- workspace_id: {
185
- value: '{{{workspace_id}}}',
186
- type: 'string',
187
- },
188
- project_id: {
189
- value: '{{{project_id}}}',
190
- type: 'string',
191
- },
192
- },
193
- message: 'list_tables_ddl',
194
- },
195
- },
196
- },
197
- lookup: {
198
- type: 'string',
199
- lookup: {
200
- url: '{{{step.ephemeral_url}}}',
201
- body: {
202
- step_settings: {
203
- workspace_id: {
204
- value: '{{{workspace_id}}}',
205
- type: 'string',
206
- },
207
- project_id: {
208
- value: '{{{project_id}}}',
209
- type: 'string',
210
- },
211
- },
212
- message: 'list_tables_ddl',
213
- },
214
- },
215
- },
216
- },
217
- additionalProperties: false,
218
- required: ['id'],
219
- $schema: 'http://json-schema.org/draft-07/schema#',
220
- advanced: [],
221
- };
222
- const result = converter.convertToLegacySchema(schema);
223
- expect(result).toEqual(expected);
224
- });
225
- it('should convert a schema with an enum', () => {
226
- const schema = {
227
- type: 'object',
228
- properties: {
229
- actions: {
230
- description: 'example dropdown',
231
- type: 'array',
232
- items: {
233
- type: 'object',
234
- properties: {
235
- text: { type: 'string' },
236
- type: {
237
- type: 'string',
238
- enum: ['default always', 'primary-one', 'the_danger'],
239
- enumLabels: ['Default Always', 'Primary One', 'The Danger'],
240
- },
241
- },
242
- additionalProperties: false,
243
- required: ['text', 'type'],
244
- advanced: [],
245
- },
246
- },
247
- name: { type: 'string' },
248
- },
249
- additionalProperties: false,
250
- required: ['actions', 'name'],
251
- $schema: 'http://json-schema.org/draft-07/schema#',
252
- advanced: [],
253
- };
254
- const expected = {
255
- type: 'object',
256
- properties: {
257
- actions: {
258
- description: 'example dropdown',
259
- type: 'array',
260
- items: {
261
- type: 'object',
262
- properties: {
263
- text: { type: 'string' },
264
- type: {
265
- type: 'string',
266
- enum: [
267
- {
268
- value: 'default always',
269
- text: 'Default Always',
270
- },
271
- {
272
- value: 'primary-one',
273
- text: 'Primary One',
274
- },
275
- {
276
- value: 'the_danger',
277
- text: 'The Danger',
278
- },
279
- ],
280
- },
281
- },
282
- additionalProperties: false,
283
- required: ['text', 'type'],
284
- advanced: [],
285
- },
286
- },
287
- name: { type: 'string' },
288
- },
289
- required: ['actions', 'name'],
290
- additionalProperties: false,
291
- $schema: 'http://json-schema.org/draft-07/schema#',
292
- advanced: [],
293
- };
294
- const result = converter.convertToLegacySchema(schema);
295
- expect(result).toEqual(expected);
296
- });
297
- it('should convert a schema with an enum and a field name as enum', () => {
298
- const schema = {
299
- type: 'object',
300
- properties: {
301
- actions: {
302
- description: 'example dropdown',
303
- type: 'array',
304
- items: {
305
- type: 'object',
306
- properties: {
307
- text: { type: 'string' },
308
- type: {
309
- type: 'string',
310
- enum: ['default always', 'primary-one', 'the_danger'],
311
- enumLabels: ['Default Always', 'Primary One', 'The Danger'],
312
- },
313
- },
314
- additionalProperties: false,
315
- required: ['text', 'type'],
316
- advanced: [],
317
- },
318
- },
319
- enum: { type: 'string' },
320
- },
321
- additionalProperties: false,
322
- required: ['actions', 'enum'],
323
- $schema: 'http://json-schema.org/draft-07/schema#',
324
- advanced: [],
325
- };
326
- const expected = {
327
- type: 'object',
328
- properties: {
329
- actions: {
330
- description: 'example dropdown',
331
- type: 'array',
332
- items: {
333
- type: 'object',
334
- properties: {
335
- text: { type: 'string' },
336
- type: {
337
- type: 'string',
338
- enum: [
339
- {
340
- value: 'default always',
341
- text: 'Default Always',
342
- },
343
- {
344
- value: 'primary-one',
345
- text: 'Primary One',
346
- },
347
- {
348
- value: 'the_danger',
349
- text: 'The Danger',
350
- },
351
- ],
352
- },
353
- },
354
- additionalProperties: false,
355
- required: ['text', 'type'],
356
- advanced: [],
357
- },
358
- },
359
- enum: { type: 'string' },
360
- },
361
- additionalProperties: false,
362
- required: ['actions', 'enum'],
363
- $schema: 'http://json-schema.org/draft-07/schema#',
364
- advanced: [],
365
- };
366
- const result = converter.convertToLegacySchema(schema);
367
- expect(result).toEqual(expected);
368
- });
369
- it('should convert lookups and enums in nested objects', () => {
370
- const schema = {
371
- properties: {
372
- id: {
373
- type: 'object',
374
- properties: {
375
- lookup: {
376
- input: {
377
- input1: 'value1',
378
- input2: 'value2',
379
- },
380
- operation: 'operation',
381
- },
382
- },
383
- },
384
- nested: {
385
- properties: {
386
- sort_by: {
387
- type: {
388
- type: 'string',
389
- enum: ['value1', 'value2'],
390
- enumLabels: ['Value 1', 'Value 2'],
391
- },
392
- },
393
- },
394
- },
395
- },
396
- };
397
- const expected = {
398
- properties: {
399
- id: {
400
- type: 'object',
401
- properties: {
402
- lookup: {
403
- url: '{{{step.ephemeral_url}}}',
404
- body: {
405
- step_settings: {
406
- input1: {
407
- value: 'value1',
408
- type: 'string',
409
- },
410
- input2: {
411
- value: 'value2',
412
- type: 'string',
413
- },
414
- },
415
- message: 'operation',
416
- },
417
- },
418
- },
419
- },
420
- nested: {
421
- properties: {
422
- sort_by: {
423
- type: {
424
- type: 'string',
425
- enum: [
426
- {
427
- value: 'value1',
428
- text: 'Value 1',
429
- },
430
- {
431
- value: 'value2',
432
- text: 'Value 2',
433
- },
434
- ],
435
- },
436
- },
437
- },
438
- },
439
- },
440
- };
441
- const result = converter.convertToLegacySchema(schema);
442
- expect(result).toEqual(expected);
443
- });
444
- it('should preserve the schema without a lookup and an enum', () => {
445
- const schema = {
446
- type: 'object',
447
- properties: {
448
- name: { type: 'string' },
449
- },
450
- additionalProperties: false,
451
- required: ['actions'],
452
- $schema: 'http://json-schema.org/draft-07/schema#',
453
- advanced: [],
454
- };
455
- const expected = {
456
- type: 'object',
457
- properties: {
458
- name: { type: 'string' },
459
- },
460
- additionalProperties: false,
461
- required: ['actions'],
462
- $schema: 'http://json-schema.org/draft-07/schema#',
463
- advanced: [],
464
- };
465
- const result = converter.convertToLegacySchema(schema);
466
- expect(result).toEqual(expected);
467
- });
468
- it('should convert legacy tags to format', () => {
469
- const schema = {
470
- type: 'object',
471
- properties: {
472
- details: { type: 'string', tag: 'text' },
473
- password: { type: 'string', tag: 'password' },
474
- source: { type: 'string', tag: 'code' },
475
- created: { type: 'string', tag: 'datetime' },
476
- tag: { type: 'string', tag: 'text' },
477
- nested: {
478
- type: 'object',
479
- properties: {
480
- details: { type: 'string', tag: 'text' },
481
- password: { type: 'string', tag: 'password' },
482
- source: { type: 'string', tag: 'code' },
483
- created: { type: 'string', tag: 'datetime' },
484
- tag: { type: 'string', tag: 'text' },
485
- },
486
- additionalProperties: false,
487
- required: [],
488
- $schema: 'http://json-schema.org/draft-07/schema#',
489
- advanced: [],
490
- },
491
- },
492
- additionalProperties: false,
493
- required: [],
494
- $schema: 'http://json-schema.org/draft-07/schema#',
495
- advanced: [],
496
- };
497
- const expected = {
498
- type: 'object',
499
- properties: {
500
- details: { type: 'string', format: 'text' },
501
- password: { type: 'string', format: 'password' },
502
- source: { type: 'string', format: 'code' },
503
- created: { type: 'string', format: 'datetime' },
504
- tag: { type: 'string', format: 'text' },
505
- nested: {
506
- type: 'object',
507
- properties: {
508
- details: { type: 'string', format: 'text' },
509
- password: { type: 'string', format: 'password' },
510
- source: { type: 'string', format: 'code' },
511
- created: { type: 'string', format: 'datetime' },
512
- tag: { type: 'string', format: 'text' },
513
- },
514
- additionalProperties: false,
515
- required: [],
516
- $schema: 'http://json-schema.org/draft-07/schema#',
517
- advanced: [],
518
- },
519
- },
520
- additionalProperties: false,
521
- required: [],
522
- $schema: 'http://json-schema.org/draft-07/schema#',
523
- advanced: [],
524
- };
525
- const result = converter.convertToLegacySchema(schema);
526
- expect(result).toEqual(expected);
527
- });
528
- });
529
- });