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