@synova-cloud/sdk 1.5.0 → 1.7.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/README.md +154 -99
- package/dist/index.cjs +560 -226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +468 -225
- package/dist/index.d.ts +468 -225
- package/dist/index.js +539 -227
- package/dist/index.js.map +1 -1
- package/package.json +16 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
|
|
3
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
+
}) : x)(function(x) {
|
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
7
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
|
|
1
10
|
// src/errors/index.ts
|
|
2
11
|
var SynovaError = class extends Error {
|
|
3
12
|
constructor(message) {
|
|
@@ -69,9 +78,34 @@ var NetworkSynovaError = class extends SynovaError {
|
|
|
69
78
|
this.cause = cause;
|
|
70
79
|
}
|
|
71
80
|
};
|
|
81
|
+
var ExecutionSynovaError = class extends SynovaError {
|
|
82
|
+
code;
|
|
83
|
+
provider;
|
|
84
|
+
retryable;
|
|
85
|
+
retryAfterMs;
|
|
86
|
+
details;
|
|
87
|
+
constructor(error) {
|
|
88
|
+
super(error.message);
|
|
89
|
+
this.name = "ExecutionSynovaError";
|
|
90
|
+
this.code = error.code;
|
|
91
|
+
this.provider = error.provider;
|
|
92
|
+
this.retryable = error.retryable;
|
|
93
|
+
this.retryAfterMs = error.retryAfterMs;
|
|
94
|
+
this.details = error.details;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var ValidationSynovaError = class extends SynovaError {
|
|
98
|
+
violations;
|
|
99
|
+
constructor(violations) {
|
|
100
|
+
const message = `Validation failed: ${violations.map((v) => v.property).join(", ")}`;
|
|
101
|
+
super(message);
|
|
102
|
+
this.name = "ValidationSynovaError";
|
|
103
|
+
this.violations = violations;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
72
106
|
|
|
73
107
|
// src/version.ts
|
|
74
|
-
var SDK_VERSION = "1.
|
|
108
|
+
var SDK_VERSION = "1.7.0" ;
|
|
75
109
|
|
|
76
110
|
// src/utils/http.ts
|
|
77
111
|
var HttpClient = class {
|
|
@@ -282,6 +316,451 @@ var HttpClient = class {
|
|
|
282
316
|
}
|
|
283
317
|
};
|
|
284
318
|
|
|
319
|
+
// src/schema/types.ts
|
|
320
|
+
var SCHEMA_METADATA_KEYS = {
|
|
321
|
+
// Metadata
|
|
322
|
+
DESCRIPTION: "synova:schema:description",
|
|
323
|
+
EXAMPLES: "synova:schema:examples",
|
|
324
|
+
DEFAULT: "synova:schema:default",
|
|
325
|
+
// Type helpers
|
|
326
|
+
FORMAT: "synova:schema:format",
|
|
327
|
+
ARRAY_ITEM_TYPE: "synova:schema:arrayItemType",
|
|
328
|
+
NULLABLE: "synova:schema:nullable",
|
|
329
|
+
ENUM: "synova:schema:enum",
|
|
330
|
+
// String constraints
|
|
331
|
+
MIN_LENGTH: "synova:schema:minLength",
|
|
332
|
+
MAX_LENGTH: "synova:schema:maxLength",
|
|
333
|
+
PATTERN: "synova:schema:pattern",
|
|
334
|
+
// Number constraints
|
|
335
|
+
MINIMUM: "synova:schema:minimum",
|
|
336
|
+
MAXIMUM: "synova:schema:maximum",
|
|
337
|
+
EXCLUSIVE_MINIMUM: "synova:schema:exclusiveMinimum",
|
|
338
|
+
EXCLUSIVE_MAXIMUM: "synova:schema:exclusiveMaximum",
|
|
339
|
+
MULTIPLE_OF: "synova:schema:multipleOf",
|
|
340
|
+
// Array constraints
|
|
341
|
+
MIN_ITEMS: "synova:schema:minItems",
|
|
342
|
+
MAX_ITEMS: "synova:schema:maxItems",
|
|
343
|
+
UNIQUE_ITEMS: "synova:schema:uniqueItems"
|
|
344
|
+
};
|
|
345
|
+
function createMetadataDecorator(key, value) {
|
|
346
|
+
return function(target, propertyKey) {
|
|
347
|
+
Reflect.defineMetadata(key, value, target, propertyKey);
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function Description(description) {
|
|
351
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.DESCRIPTION, description);
|
|
352
|
+
}
|
|
353
|
+
function Example(...examples) {
|
|
354
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXAMPLES, examples);
|
|
355
|
+
}
|
|
356
|
+
function Default(value) {
|
|
357
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.DEFAULT, value);
|
|
358
|
+
}
|
|
359
|
+
function ArrayItems(itemType) {
|
|
360
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE, itemType);
|
|
361
|
+
}
|
|
362
|
+
function Format(format) {
|
|
363
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.FORMAT, format);
|
|
364
|
+
}
|
|
365
|
+
function Nullable() {
|
|
366
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.NULLABLE, true);
|
|
367
|
+
}
|
|
368
|
+
function SchemaMinLength(length) {
|
|
369
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_LENGTH, length);
|
|
370
|
+
}
|
|
371
|
+
function SchemaMaxLength(length) {
|
|
372
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_LENGTH, length);
|
|
373
|
+
}
|
|
374
|
+
function SchemaPattern(pattern) {
|
|
375
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.PATTERN, pattern);
|
|
376
|
+
}
|
|
377
|
+
function SchemaMin(value) {
|
|
378
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MINIMUM, value);
|
|
379
|
+
}
|
|
380
|
+
function SchemaMax(value) {
|
|
381
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAXIMUM, value);
|
|
382
|
+
}
|
|
383
|
+
function ExclusiveMin(value) {
|
|
384
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM, value);
|
|
385
|
+
}
|
|
386
|
+
function ExclusiveMax(value) {
|
|
387
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM, value);
|
|
388
|
+
}
|
|
389
|
+
function MultipleOf(value) {
|
|
390
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MULTIPLE_OF, value);
|
|
391
|
+
}
|
|
392
|
+
function SchemaMinItems(count) {
|
|
393
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MIN_ITEMS, count);
|
|
394
|
+
}
|
|
395
|
+
function SchemaMaxItems(count) {
|
|
396
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.MAX_ITEMS, count);
|
|
397
|
+
}
|
|
398
|
+
function SchemaUniqueItems() {
|
|
399
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.UNIQUE_ITEMS, true);
|
|
400
|
+
}
|
|
401
|
+
function SchemaEnum(values) {
|
|
402
|
+
return createMetadataDecorator(SCHEMA_METADATA_KEYS.ENUM, values);
|
|
403
|
+
}
|
|
404
|
+
function getSchemaMetadata(key, target, propertyKey) {
|
|
405
|
+
return Reflect.getMetadata(key, target, propertyKey);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/schema/class-schema.ts
|
|
409
|
+
var ClassSchema = class {
|
|
410
|
+
/**
|
|
411
|
+
* Generate JSON Schema from a class
|
|
412
|
+
*/
|
|
413
|
+
static generate(targetClass, options = {}) {
|
|
414
|
+
const { additionalProperties = false } = options;
|
|
415
|
+
const properties = this.getProperties(targetClass);
|
|
416
|
+
const required = this.getRequiredProperties(targetClass, properties);
|
|
417
|
+
return {
|
|
418
|
+
type: "object",
|
|
419
|
+
properties,
|
|
420
|
+
required: required.length > 0 ? required : void 0,
|
|
421
|
+
additionalProperties
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Get all properties with their schemas
|
|
426
|
+
*/
|
|
427
|
+
static getProperties(targetClass) {
|
|
428
|
+
const properties = {};
|
|
429
|
+
const prototype = targetClass.prototype;
|
|
430
|
+
const classValidatorProperties = this.getClassValidatorProperties(targetClass);
|
|
431
|
+
const decoratorProperties = this.getDecoratorProperties(prototype);
|
|
432
|
+
const allProperties = /* @__PURE__ */ new Set([...classValidatorProperties, ...decoratorProperties]);
|
|
433
|
+
for (const propertyName of allProperties) {
|
|
434
|
+
properties[propertyName] = this.getPropertySchema(targetClass, propertyName);
|
|
435
|
+
}
|
|
436
|
+
return properties;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Get property names from class-validator metadata
|
|
440
|
+
*/
|
|
441
|
+
static getClassValidatorProperties(targetClass) {
|
|
442
|
+
try {
|
|
443
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
444
|
+
const metadataStorage = getMetadataStorage();
|
|
445
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
446
|
+
targetClass,
|
|
447
|
+
"",
|
|
448
|
+
true,
|
|
449
|
+
false
|
|
450
|
+
);
|
|
451
|
+
const propertyNames = targetMetadatas.map((m) => m.propertyName);
|
|
452
|
+
return [...new Set(propertyNames)];
|
|
453
|
+
} catch {
|
|
454
|
+
return [];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Get property names from our decorator metadata
|
|
459
|
+
*/
|
|
460
|
+
static getDecoratorProperties(prototype) {
|
|
461
|
+
const properties = [];
|
|
462
|
+
const ownKeys = Reflect.ownKeys(prototype);
|
|
463
|
+
for (const key of ownKeys) {
|
|
464
|
+
if (typeof key === "string" && key !== "constructor") {
|
|
465
|
+
for (const metaKey of Object.values(SCHEMA_METADATA_KEYS)) {
|
|
466
|
+
if (Reflect.hasMetadata(metaKey, prototype, key)) {
|
|
467
|
+
properties.push(key);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return properties;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Get JSON Schema for a single property
|
|
477
|
+
*/
|
|
478
|
+
static getPropertySchema(targetClass, propertyName) {
|
|
479
|
+
const prototype = targetClass.prototype;
|
|
480
|
+
const schema = {};
|
|
481
|
+
const designType = Reflect.getMetadata("design:type", prototype, propertyName);
|
|
482
|
+
const baseSchema = this.getBaseTypeSchema(designType, targetClass, propertyName);
|
|
483
|
+
Object.assign(schema, baseSchema);
|
|
484
|
+
this.applyClassValidatorConstraints(schema, targetClass, propertyName);
|
|
485
|
+
this.applyDecoratorMetadata(schema, prototype, propertyName);
|
|
486
|
+
const isNullable = getSchemaMetadata(
|
|
487
|
+
SCHEMA_METADATA_KEYS.NULLABLE,
|
|
488
|
+
prototype,
|
|
489
|
+
propertyName
|
|
490
|
+
);
|
|
491
|
+
if (isNullable && schema.type && typeof schema.type === "string") {
|
|
492
|
+
schema.type = [schema.type, "null"];
|
|
493
|
+
}
|
|
494
|
+
return schema;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Get base schema from TypeScript type
|
|
498
|
+
*/
|
|
499
|
+
static getBaseTypeSchema(designType, targetClass, propertyName) {
|
|
500
|
+
if (designType === String) {
|
|
501
|
+
return { type: "string" };
|
|
502
|
+
}
|
|
503
|
+
if (designType === Number) {
|
|
504
|
+
return { type: "number" };
|
|
505
|
+
}
|
|
506
|
+
if (designType === Boolean) {
|
|
507
|
+
return { type: "boolean" };
|
|
508
|
+
}
|
|
509
|
+
if (designType === Array) {
|
|
510
|
+
const itemType = getSchemaMetadata(
|
|
511
|
+
SCHEMA_METADATA_KEYS.ARRAY_ITEM_TYPE,
|
|
512
|
+
targetClass.prototype,
|
|
513
|
+
propertyName
|
|
514
|
+
);
|
|
515
|
+
return {
|
|
516
|
+
type: "array",
|
|
517
|
+
items: this.getArrayItemSchema(itemType)
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
if (designType === Object) {
|
|
521
|
+
return { type: "object" };
|
|
522
|
+
}
|
|
523
|
+
if (typeof designType === "function" && designType.prototype) {
|
|
524
|
+
return this.generate(designType);
|
|
525
|
+
}
|
|
526
|
+
return { type: "string" };
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Get schema for array items
|
|
530
|
+
*/
|
|
531
|
+
static getArrayItemSchema(itemType) {
|
|
532
|
+
if (!itemType) {
|
|
533
|
+
return { type: "string" };
|
|
534
|
+
}
|
|
535
|
+
if (itemType === String) {
|
|
536
|
+
return { type: "string" };
|
|
537
|
+
}
|
|
538
|
+
if (itemType === Number) {
|
|
539
|
+
return { type: "number" };
|
|
540
|
+
}
|
|
541
|
+
if (itemType === Boolean) {
|
|
542
|
+
return { type: "boolean" };
|
|
543
|
+
}
|
|
544
|
+
return this.generate(itemType);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Apply class-validator constraints to schema
|
|
548
|
+
*/
|
|
549
|
+
static applyClassValidatorConstraints(schema, targetClass, propertyName) {
|
|
550
|
+
try {
|
|
551
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
552
|
+
const metadataStorage = getMetadataStorage();
|
|
553
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
554
|
+
targetClass,
|
|
555
|
+
"",
|
|
556
|
+
true,
|
|
557
|
+
false
|
|
558
|
+
);
|
|
559
|
+
const propertyMetadatas = targetMetadatas.filter(
|
|
560
|
+
(m) => m.propertyName === propertyName
|
|
561
|
+
);
|
|
562
|
+
for (const metadata of propertyMetadatas) {
|
|
563
|
+
this.applyValidationConstraint(schema, metadata);
|
|
564
|
+
}
|
|
565
|
+
} catch {
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Apply a single class-validator constraint
|
|
570
|
+
*/
|
|
571
|
+
static applyValidationConstraint(schema, metadata) {
|
|
572
|
+
const constraintType = metadata.name || metadata.type || "";
|
|
573
|
+
const constraints = metadata.constraints || [];
|
|
574
|
+
switch (constraintType) {
|
|
575
|
+
case "isString":
|
|
576
|
+
schema.type = "string";
|
|
577
|
+
break;
|
|
578
|
+
case "isNumber":
|
|
579
|
+
case "isInt":
|
|
580
|
+
schema.type = constraintType === "isInt" ? "integer" : "number";
|
|
581
|
+
break;
|
|
582
|
+
case "isBoolean":
|
|
583
|
+
schema.type = "boolean";
|
|
584
|
+
break;
|
|
585
|
+
case "isArray":
|
|
586
|
+
schema.type = "array";
|
|
587
|
+
break;
|
|
588
|
+
case "isEnum":
|
|
589
|
+
if (constraints[0]) {
|
|
590
|
+
schema.enum = Object.values(constraints[0]);
|
|
591
|
+
}
|
|
592
|
+
break;
|
|
593
|
+
case "minLength":
|
|
594
|
+
schema.minLength = constraints[0];
|
|
595
|
+
break;
|
|
596
|
+
case "maxLength":
|
|
597
|
+
schema.maxLength = constraints[0];
|
|
598
|
+
break;
|
|
599
|
+
case "min":
|
|
600
|
+
schema.minimum = constraints[0];
|
|
601
|
+
break;
|
|
602
|
+
case "max":
|
|
603
|
+
schema.maximum = constraints[0];
|
|
604
|
+
break;
|
|
605
|
+
case "isEmail":
|
|
606
|
+
schema.format = "email";
|
|
607
|
+
break;
|
|
608
|
+
case "isUrl":
|
|
609
|
+
case "isURL":
|
|
610
|
+
schema.format = "uri";
|
|
611
|
+
break;
|
|
612
|
+
case "isUUID":
|
|
613
|
+
schema.format = "uuid";
|
|
614
|
+
break;
|
|
615
|
+
case "isDateString":
|
|
616
|
+
case "isISO8601":
|
|
617
|
+
schema.format = "date-time";
|
|
618
|
+
break;
|
|
619
|
+
case "matches":
|
|
620
|
+
if (constraints[0] instanceof RegExp) {
|
|
621
|
+
schema.pattern = constraints[0].source;
|
|
622
|
+
} else if (typeof constraints[0] === "string") {
|
|
623
|
+
schema.pattern = constraints[0];
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
626
|
+
case "arrayMinSize":
|
|
627
|
+
schema.minItems = constraints[0];
|
|
628
|
+
break;
|
|
629
|
+
case "arrayMaxSize":
|
|
630
|
+
schema.maxItems = constraints[0];
|
|
631
|
+
break;
|
|
632
|
+
case "arrayUnique":
|
|
633
|
+
schema.uniqueItems = true;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Apply our decorator metadata to schema.
|
|
639
|
+
* Our decorators take precedence over class-validator if both are used.
|
|
640
|
+
*/
|
|
641
|
+
static applyDecoratorMetadata(schema, prototype, propertyName) {
|
|
642
|
+
const description = getSchemaMetadata(
|
|
643
|
+
SCHEMA_METADATA_KEYS.DESCRIPTION,
|
|
644
|
+
prototype,
|
|
645
|
+
propertyName
|
|
646
|
+
);
|
|
647
|
+
if (description) schema.description = description;
|
|
648
|
+
const examples = getSchemaMetadata(
|
|
649
|
+
SCHEMA_METADATA_KEYS.EXAMPLES,
|
|
650
|
+
prototype,
|
|
651
|
+
propertyName
|
|
652
|
+
);
|
|
653
|
+
if (examples) schema.examples = examples;
|
|
654
|
+
const defaultValue = getSchemaMetadata(
|
|
655
|
+
SCHEMA_METADATA_KEYS.DEFAULT,
|
|
656
|
+
prototype,
|
|
657
|
+
propertyName
|
|
658
|
+
);
|
|
659
|
+
if (defaultValue !== void 0) schema.default = defaultValue;
|
|
660
|
+
const format = getSchemaMetadata(SCHEMA_METADATA_KEYS.FORMAT, prototype, propertyName);
|
|
661
|
+
if (format) schema.format = format;
|
|
662
|
+
const enumValues = getSchemaMetadata(
|
|
663
|
+
SCHEMA_METADATA_KEYS.ENUM,
|
|
664
|
+
prototype,
|
|
665
|
+
propertyName
|
|
666
|
+
);
|
|
667
|
+
if (enumValues) schema.enum = enumValues;
|
|
668
|
+
const minLength = getSchemaMetadata(
|
|
669
|
+
SCHEMA_METADATA_KEYS.MIN_LENGTH,
|
|
670
|
+
prototype,
|
|
671
|
+
propertyName
|
|
672
|
+
);
|
|
673
|
+
if (minLength !== void 0) schema.minLength = minLength;
|
|
674
|
+
const maxLength = getSchemaMetadata(
|
|
675
|
+
SCHEMA_METADATA_KEYS.MAX_LENGTH,
|
|
676
|
+
prototype,
|
|
677
|
+
propertyName
|
|
678
|
+
);
|
|
679
|
+
if (maxLength !== void 0) schema.maxLength = maxLength;
|
|
680
|
+
const pattern = getSchemaMetadata(
|
|
681
|
+
SCHEMA_METADATA_KEYS.PATTERN,
|
|
682
|
+
prototype,
|
|
683
|
+
propertyName
|
|
684
|
+
);
|
|
685
|
+
if (pattern) schema.pattern = pattern;
|
|
686
|
+
const minimum = getSchemaMetadata(
|
|
687
|
+
SCHEMA_METADATA_KEYS.MINIMUM,
|
|
688
|
+
prototype,
|
|
689
|
+
propertyName
|
|
690
|
+
);
|
|
691
|
+
if (minimum !== void 0) schema.minimum = minimum;
|
|
692
|
+
const maximum = getSchemaMetadata(
|
|
693
|
+
SCHEMA_METADATA_KEYS.MAXIMUM,
|
|
694
|
+
prototype,
|
|
695
|
+
propertyName
|
|
696
|
+
);
|
|
697
|
+
if (maximum !== void 0) schema.maximum = maximum;
|
|
698
|
+
const exclusiveMinimum = getSchemaMetadata(
|
|
699
|
+
SCHEMA_METADATA_KEYS.EXCLUSIVE_MINIMUM,
|
|
700
|
+
prototype,
|
|
701
|
+
propertyName
|
|
702
|
+
);
|
|
703
|
+
if (exclusiveMinimum !== void 0) schema.exclusiveMinimum = exclusiveMinimum;
|
|
704
|
+
const exclusiveMaximum = getSchemaMetadata(
|
|
705
|
+
SCHEMA_METADATA_KEYS.EXCLUSIVE_MAXIMUM,
|
|
706
|
+
prototype,
|
|
707
|
+
propertyName
|
|
708
|
+
);
|
|
709
|
+
if (exclusiveMaximum !== void 0) schema.exclusiveMaximum = exclusiveMaximum;
|
|
710
|
+
const multipleOf = getSchemaMetadata(
|
|
711
|
+
SCHEMA_METADATA_KEYS.MULTIPLE_OF,
|
|
712
|
+
prototype,
|
|
713
|
+
propertyName
|
|
714
|
+
);
|
|
715
|
+
if (multipleOf !== void 0) schema.multipleOf = multipleOf;
|
|
716
|
+
const minItems = getSchemaMetadata(
|
|
717
|
+
SCHEMA_METADATA_KEYS.MIN_ITEMS,
|
|
718
|
+
prototype,
|
|
719
|
+
propertyName
|
|
720
|
+
);
|
|
721
|
+
if (minItems !== void 0) schema.minItems = minItems;
|
|
722
|
+
const maxItems = getSchemaMetadata(
|
|
723
|
+
SCHEMA_METADATA_KEYS.MAX_ITEMS,
|
|
724
|
+
prototype,
|
|
725
|
+
propertyName
|
|
726
|
+
);
|
|
727
|
+
if (maxItems !== void 0) schema.maxItems = maxItems;
|
|
728
|
+
const uniqueItems = getSchemaMetadata(
|
|
729
|
+
SCHEMA_METADATA_KEYS.UNIQUE_ITEMS,
|
|
730
|
+
prototype,
|
|
731
|
+
propertyName
|
|
732
|
+
);
|
|
733
|
+
if (uniqueItems) schema.uniqueItems = uniqueItems;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Get required properties (properties without @IsOptional)
|
|
737
|
+
*/
|
|
738
|
+
static getRequiredProperties(targetClass, properties) {
|
|
739
|
+
const required = [];
|
|
740
|
+
try {
|
|
741
|
+
const { getMetadataStorage } = __require("class-validator");
|
|
742
|
+
const metadataStorage = getMetadataStorage();
|
|
743
|
+
const targetMetadatas = metadataStorage.getTargetValidationMetadatas(
|
|
744
|
+
targetClass,
|
|
745
|
+
"",
|
|
746
|
+
true,
|
|
747
|
+
false
|
|
748
|
+
);
|
|
749
|
+
for (const propertyName of Object.keys(properties)) {
|
|
750
|
+
const isOptional = targetMetadatas.some(
|
|
751
|
+
(m) => m.propertyName === propertyName && (m.type === "isOptional" || m.type === "conditionalValidation")
|
|
752
|
+
);
|
|
753
|
+
if (!isOptional) {
|
|
754
|
+
required.push(propertyName);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
} catch {
|
|
758
|
+
required.push(...Object.keys(properties));
|
|
759
|
+
}
|
|
760
|
+
return required;
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
|
|
285
764
|
// src/resources/prompts.ts
|
|
286
765
|
var PromptsResource = class {
|
|
287
766
|
constructor(http) {
|
|
@@ -289,22 +768,6 @@ var PromptsResource = class {
|
|
|
289
768
|
}
|
|
290
769
|
/**
|
|
291
770
|
* Get a prompt by ID (returns version with 'latest' tag)
|
|
292
|
-
*
|
|
293
|
-
* @param promptId - The prompt ID (e.g., 'prm_abc123')
|
|
294
|
-
* @param options - Optional settings
|
|
295
|
-
* @returns The prompt data
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```ts
|
|
299
|
-
* // Get default (latest) version
|
|
300
|
-
* const prompt = await client.prompts.get('prm_abc123');
|
|
301
|
-
*
|
|
302
|
-
* // Get by specific tag
|
|
303
|
-
* const production = await client.prompts.get('prm_abc123', { tag: 'production' });
|
|
304
|
-
*
|
|
305
|
-
* // Get specific version
|
|
306
|
-
* const v2 = await client.prompts.get('prm_abc123', { version: '2.0.0' });
|
|
307
|
-
* ```
|
|
308
771
|
*/
|
|
309
772
|
async get(promptId, options) {
|
|
310
773
|
if (options?.version) {
|
|
@@ -325,43 +788,29 @@ var PromptsResource = class {
|
|
|
325
788
|
path: `/api/v1/prompts/${promptId}/tags/${tag}`
|
|
326
789
|
});
|
|
327
790
|
}
|
|
791
|
+
async execute(promptId, options) {
|
|
792
|
+
if ("responseClass" in options && options.responseClass) {
|
|
793
|
+
return this.executeTyped(promptId, options);
|
|
794
|
+
}
|
|
795
|
+
return this.executeRaw(promptId, options);
|
|
796
|
+
}
|
|
797
|
+
async executeByTag(promptId, tag, options) {
|
|
798
|
+
return this.execute(promptId, { ...options, tag });
|
|
799
|
+
}
|
|
800
|
+
async executeByVersion(promptId, version, options) {
|
|
801
|
+
return this.execute(promptId, { ...options, version });
|
|
802
|
+
}
|
|
328
803
|
/**
|
|
329
|
-
* Execute
|
|
330
|
-
*
|
|
331
|
-
* @param promptId - The prompt ID
|
|
332
|
-
* @param options - Execution options including provider, model and variables
|
|
333
|
-
* @returns The execution response
|
|
334
|
-
*
|
|
335
|
-
* @example
|
|
336
|
-
* ```ts
|
|
337
|
-
* const result = await client.prompts.execute('prm_abc123', {
|
|
338
|
-
* provider: 'openai',
|
|
339
|
-
* model: 'gpt-4o',
|
|
340
|
-
* variables: { topic: 'TypeScript' },
|
|
341
|
-
* });
|
|
342
|
-
*
|
|
343
|
-
* if (result.type === 'message') {
|
|
344
|
-
* console.log(result.content);
|
|
345
|
-
* }
|
|
346
|
-
*
|
|
347
|
-
* // Image generation
|
|
348
|
-
* const imageResult = await client.prompts.execute('prm_image123', {
|
|
349
|
-
* provider: 'google',
|
|
350
|
-
* model: 'gemini-2.0-flash-exp',
|
|
351
|
-
* variables: { style: 'modern' },
|
|
352
|
-
* });
|
|
353
|
-
*
|
|
354
|
-
* if (imageResult.type === 'image') {
|
|
355
|
-
* console.log('Generated images:', imageResult.files);
|
|
356
|
-
* }
|
|
357
|
-
* ```
|
|
804
|
+
* Execute raw request without typed response
|
|
805
|
+
* @throws {ExecutionSynovaError} If LLM returns an error
|
|
358
806
|
*/
|
|
359
|
-
async
|
|
807
|
+
async executeRaw(promptId, options) {
|
|
360
808
|
const body = {
|
|
361
809
|
provider: options.provider,
|
|
362
810
|
model: options.model
|
|
363
811
|
};
|
|
364
|
-
if (options.
|
|
812
|
+
if (options.apiKey !== void 0) body.apiKey = options.apiKey;
|
|
813
|
+
if (options.azureEndpoint !== void 0) body.azureEndpoint = options.azureEndpoint;
|
|
365
814
|
if (options.variables !== void 0) body.variables = options.variables;
|
|
366
815
|
if (options.messages !== void 0) body.messages = options.messages;
|
|
367
816
|
if (options.tag !== void 0) body.tag = options.tag;
|
|
@@ -369,77 +818,59 @@ var PromptsResource = class {
|
|
|
369
818
|
if (options.metadata !== void 0) body.metadata = options.metadata;
|
|
370
819
|
if (options.parameters !== void 0) body.parameters = options.parameters;
|
|
371
820
|
if (options.responseSchema !== void 0) body.responseSchema = options.responseSchema;
|
|
372
|
-
|
|
821
|
+
const response = await this.http.request({
|
|
373
822
|
method: "POST",
|
|
374
823
|
path: `/api/v1/prompts/${promptId}/run`,
|
|
375
824
|
body
|
|
376
825
|
});
|
|
826
|
+
if (response.type === "error" && response.error) {
|
|
827
|
+
throw new ExecutionSynovaError(response.error);
|
|
828
|
+
}
|
|
829
|
+
return response;
|
|
377
830
|
}
|
|
378
831
|
/**
|
|
379
|
-
* Execute
|
|
380
|
-
*
|
|
381
|
-
* @param promptId - The prompt ID
|
|
382
|
-
* @param tag - The tag (e.g., 'latest', 'production', 'staging')
|
|
383
|
-
* @param options - Execution options
|
|
384
|
-
* @returns The execution response
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```ts
|
|
388
|
-
* const result = await client.prompts.executeByTag('prm_abc123', 'production', {
|
|
389
|
-
* provider: 'openai',
|
|
390
|
-
* model: 'gpt-4o',
|
|
391
|
-
* variables: { topic: 'TypeScript' },
|
|
392
|
-
* });
|
|
393
|
-
* ```
|
|
832
|
+
* Execute with typed response class
|
|
394
833
|
*/
|
|
395
|
-
async
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
provider: options.provider,
|
|
402
|
-
model: options.model,
|
|
403
|
-
apiKeyId: options.apiKeyId,
|
|
404
|
-
variables: options.variables,
|
|
405
|
-
messages: options.messages,
|
|
406
|
-
metadata: options.metadata,
|
|
407
|
-
parameters: options.parameters
|
|
408
|
-
}
|
|
834
|
+
async executeTyped(promptId, options) {
|
|
835
|
+
const { responseClass, validate = true, ...executeOptions } = options;
|
|
836
|
+
const responseSchema = ClassSchema.generate(responseClass);
|
|
837
|
+
const response = await this.executeRaw(promptId, {
|
|
838
|
+
...executeOptions,
|
|
839
|
+
responseSchema
|
|
409
840
|
});
|
|
841
|
+
const object = response.object;
|
|
842
|
+
if (validate) {
|
|
843
|
+
await this.validateObject(object, responseClass);
|
|
844
|
+
}
|
|
845
|
+
return object;
|
|
410
846
|
}
|
|
411
847
|
/**
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* @param promptId - The prompt ID
|
|
415
|
-
* @param version - The semantic version (e.g., '1.0.0', '2.1.0')
|
|
416
|
-
* @param options - Execution options
|
|
417
|
-
* @returns The execution response
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* const result = await client.prompts.executeByVersion('prm_abc123', '1.2.0', {
|
|
422
|
-
* provider: 'openai',
|
|
423
|
-
* model: 'gpt-4o',
|
|
424
|
-
* variables: { topic: 'TypeScript' },
|
|
425
|
-
* });
|
|
426
|
-
* ```
|
|
848
|
+
* Validate object using class-validator
|
|
427
849
|
*/
|
|
428
|
-
async
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
850
|
+
async validateObject(object, responseClass) {
|
|
851
|
+
try {
|
|
852
|
+
const { plainToInstance } = __require("class-transformer");
|
|
853
|
+
const { validate } = __require("class-validator");
|
|
854
|
+
const instance = plainToInstance(responseClass, object);
|
|
855
|
+
const errors = await validate(instance);
|
|
856
|
+
if (errors.length > 0) {
|
|
857
|
+
const violations = errors.map(
|
|
858
|
+
(error) => ({
|
|
859
|
+
property: error.property,
|
|
860
|
+
constraints: error.constraints || {},
|
|
861
|
+
value: error.value
|
|
862
|
+
})
|
|
863
|
+
);
|
|
864
|
+
throw new ValidationSynovaError(violations);
|
|
441
865
|
}
|
|
442
|
-
})
|
|
866
|
+
} catch (error) {
|
|
867
|
+
if (error instanceof ValidationSynovaError) {
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
870
|
+
console.warn(
|
|
871
|
+
"[Synova SDK] Validation skipped: class-validator or class-transformer not installed. Install them with: npm install class-validator class-transformer"
|
|
872
|
+
);
|
|
873
|
+
}
|
|
443
874
|
}
|
|
444
875
|
};
|
|
445
876
|
|
|
@@ -571,123 +1002,6 @@ var FilesResource = class {
|
|
|
571
1002
|
}
|
|
572
1003
|
};
|
|
573
1004
|
|
|
574
|
-
// src/resources/llm-provider-keys.ts
|
|
575
|
-
var LlmProviderKeysResource = class {
|
|
576
|
-
constructor(http) {
|
|
577
|
-
this.http = http;
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* List all LLM provider keys
|
|
581
|
-
*
|
|
582
|
-
* @returns List of LLM provider keys
|
|
583
|
-
*
|
|
584
|
-
* @example
|
|
585
|
-
* ```ts
|
|
586
|
-
* const { items, total } = await client.llmProviderKeys.list();
|
|
587
|
-
* console.log(`Found ${total} keys`);
|
|
588
|
-
* for (const key of items) {
|
|
589
|
-
* console.log(`${key.provider}: ${key.maskedKey} (default: ${key.isDefault})`);
|
|
590
|
-
* }
|
|
591
|
-
* ```
|
|
592
|
-
*/
|
|
593
|
-
async list() {
|
|
594
|
-
return this.http.request({
|
|
595
|
-
method: "GET",
|
|
596
|
-
path: "/api/v1/llm-provider-keys"
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Get an LLM provider key by ID
|
|
601
|
-
*
|
|
602
|
-
* @param id - Key ID (e.g., 'lpk_abc123')
|
|
603
|
-
* @returns LLM provider key details
|
|
604
|
-
*
|
|
605
|
-
* @example
|
|
606
|
-
* ```ts
|
|
607
|
-
* const key = await client.llmProviderKeys.get('lpk_abc123');
|
|
608
|
-
* console.log(`Provider: ${key.provider}, Default: ${key.isDefault}`);
|
|
609
|
-
* ```
|
|
610
|
-
*/
|
|
611
|
-
async get(id) {
|
|
612
|
-
return this.http.request({
|
|
613
|
-
method: "GET",
|
|
614
|
-
path: `/api/v1/llm-provider-keys/${id}`
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Create a new LLM provider key
|
|
619
|
-
*
|
|
620
|
-
* The first key created for a provider will automatically be set as the default.
|
|
621
|
-
*
|
|
622
|
-
* @param options - Key creation options
|
|
623
|
-
* @returns Created LLM provider key
|
|
624
|
-
*
|
|
625
|
-
* @example
|
|
626
|
-
* ```ts
|
|
627
|
-
* // Create OpenAI key
|
|
628
|
-
* const key = await client.llmProviderKeys.create({
|
|
629
|
-
* provider: 'openai',
|
|
630
|
-
* apiKey: 'sk-...',
|
|
631
|
-
* label: 'Production Key',
|
|
632
|
-
* defaultModel: 'gpt-4o',
|
|
633
|
-
* });
|
|
634
|
-
*
|
|
635
|
-
* // Create Azure OpenAI key
|
|
636
|
-
* const azureKey = await client.llmProviderKeys.create({
|
|
637
|
-
* provider: 'azure_openai',
|
|
638
|
-
* apiKey: 'your-azure-key',
|
|
639
|
-
* azure: {
|
|
640
|
-
* endpoint: 'https://my-resource.openai.azure.com',
|
|
641
|
-
* },
|
|
642
|
-
* label: 'Azure Production',
|
|
643
|
-
* });
|
|
644
|
-
* ```
|
|
645
|
-
*/
|
|
646
|
-
async create(options) {
|
|
647
|
-
return this.http.request({
|
|
648
|
-
method: "POST",
|
|
649
|
-
path: "/api/v1/llm-provider-keys",
|
|
650
|
-
body: options
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Set an LLM provider key as the default for its provider
|
|
655
|
-
*
|
|
656
|
-
* The previous default key for this provider will be unset.
|
|
657
|
-
*
|
|
658
|
-
* @param id - Key ID to set as default
|
|
659
|
-
* @returns Updated LLM provider key
|
|
660
|
-
*
|
|
661
|
-
* @example
|
|
662
|
-
* ```ts
|
|
663
|
-
* const key = await client.llmProviderKeys.setDefault('lpk_abc123');
|
|
664
|
-
* console.log(`${key.id} is now the default for ${key.provider}`);
|
|
665
|
-
* ```
|
|
666
|
-
*/
|
|
667
|
-
async setDefault(id) {
|
|
668
|
-
return this.http.request({
|
|
669
|
-
method: "POST",
|
|
670
|
-
path: `/api/v1/llm-provider-keys/${id}/set-default`
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Delete an LLM provider key
|
|
675
|
-
*
|
|
676
|
-
* @param id - Key ID to delete
|
|
677
|
-
*
|
|
678
|
-
* @example
|
|
679
|
-
* ```ts
|
|
680
|
-
* await client.llmProviderKeys.delete('lpk_abc123');
|
|
681
|
-
* ```
|
|
682
|
-
*/
|
|
683
|
-
async delete(id) {
|
|
684
|
-
await this.http.request({
|
|
685
|
-
method: "DELETE",
|
|
686
|
-
path: `/api/v1/llm-provider-keys/${id}`
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
|
|
691
1005
|
// src/client.ts
|
|
692
1006
|
var DEFAULT_BASE_URL = "https://api.synova.cloud";
|
|
693
1007
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -708,7 +1022,6 @@ var SynovaCloudSdk = class {
|
|
|
708
1022
|
prompts;
|
|
709
1023
|
models;
|
|
710
1024
|
files;
|
|
711
|
-
llmProviderKeys;
|
|
712
1025
|
http;
|
|
713
1026
|
/**
|
|
714
1027
|
* Create a new Synova Cloud SDK client
|
|
@@ -737,10 +1050,9 @@ var SynovaCloudSdk = class {
|
|
|
737
1050
|
this.prompts = new PromptsResource(this.http);
|
|
738
1051
|
this.models = new ModelsResource(this.http);
|
|
739
1052
|
this.files = new FilesResource(this.http);
|
|
740
|
-
this.llmProviderKeys = new LlmProviderKeysResource(this.http);
|
|
741
1053
|
}
|
|
742
1054
|
};
|
|
743
1055
|
|
|
744
|
-
export { ApiSynovaError, AuthSynovaError, NetworkSynovaError, NotFoundSynovaError, RateLimitSynovaError, ServerSynovaError, SynovaCloudSdk, SynovaError, TimeoutSynovaError };
|
|
1056
|
+
export { ApiSynovaError, ArrayItems, AuthSynovaError, ClassSchema, Default, Description, Example, ExclusiveMax, ExclusiveMin, ExecutionSynovaError, Format, MultipleOf, NetworkSynovaError, NotFoundSynovaError, Nullable, RateLimitSynovaError, SCHEMA_METADATA_KEYS, SchemaEnum, SchemaMax, SchemaMaxItems, SchemaMaxLength, SchemaMin, SchemaMinItems, SchemaMinLength, SchemaPattern, SchemaUniqueItems, ServerSynovaError, SynovaCloudSdk, SynovaError, TimeoutSynovaError, ValidationSynovaError };
|
|
745
1057
|
//# sourceMappingURL=index.js.map
|
|
746
1058
|
//# sourceMappingURL=index.js.map
|