@tangle-network/agent-interface 0.42.0 → 0.42.1
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/dist/interaction.d.ts +6 -0
- package/dist/interaction.js +22 -2
- package/package.json +1 -1
package/dist/interaction.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const InteractionFieldSchema: z.ZodDiscriminatedUnion<[z.ZodObjec
|
|
|
23
23
|
type: z.ZodLiteral<"text">;
|
|
24
24
|
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
25
25
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
26
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
26
27
|
default: z.ZodOptional<z.ZodString>;
|
|
27
28
|
name: z.ZodString;
|
|
28
29
|
label: z.ZodString;
|
|
@@ -57,6 +58,7 @@ export declare const InteractionFieldSchema: z.ZodDiscriminatedUnion<[z.ZodObjec
|
|
|
57
58
|
}, z.core.$strict>, z.ZodObject<{
|
|
58
59
|
type: z.ZodLiteral<"secret">;
|
|
59
60
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
61
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
60
62
|
name: z.ZodString;
|
|
61
63
|
label: z.ZodString;
|
|
62
64
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -67,6 +69,7 @@ export declare const InteractionAnswerSpecSchema: z.ZodObject<{
|
|
|
67
69
|
type: z.ZodLiteral<"text">;
|
|
68
70
|
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
69
71
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
72
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
70
73
|
default: z.ZodOptional<z.ZodString>;
|
|
71
74
|
name: z.ZodString;
|
|
72
75
|
label: z.ZodString;
|
|
@@ -101,6 +104,7 @@ export declare const InteractionAnswerSpecSchema: z.ZodObject<{
|
|
|
101
104
|
}, z.core.$strict>, z.ZodObject<{
|
|
102
105
|
type: z.ZodLiteral<"secret">;
|
|
103
106
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
107
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
104
108
|
name: z.ZodString;
|
|
105
109
|
label: z.ZodString;
|
|
106
110
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -204,6 +208,7 @@ export declare const InteractionRequestSchema: z.ZodObject<{
|
|
|
204
208
|
type: z.ZodLiteral<"text">;
|
|
205
209
|
multiline: z.ZodOptional<z.ZodBoolean>;
|
|
206
210
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
211
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
207
212
|
default: z.ZodOptional<z.ZodString>;
|
|
208
213
|
name: z.ZodString;
|
|
209
214
|
label: z.ZodString;
|
|
@@ -238,6 +243,7 @@ export declare const InteractionRequestSchema: z.ZodObject<{
|
|
|
238
243
|
}, z.core.$strict>, z.ZodObject<{
|
|
239
244
|
type: z.ZodLiteral<"secret">;
|
|
240
245
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
246
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
241
247
|
name: z.ZodString;
|
|
242
248
|
label: z.ZodString;
|
|
243
249
|
required: z.ZodOptional<z.ZodBoolean>;
|
package/dist/interaction.js
CHANGED
|
@@ -37,6 +37,8 @@ export const InteractionFieldSchema = z
|
|
|
37
37
|
type: z.literal("text"),
|
|
38
38
|
multiline: z.boolean().optional(),
|
|
39
39
|
placeholder: z.string().optional(),
|
|
40
|
+
/** Maximum answer length chosen by the request author. Omission means no contract limit. */
|
|
41
|
+
maxLength: z.number().int().positive().optional(),
|
|
40
42
|
default: z.string().optional(),
|
|
41
43
|
}),
|
|
42
44
|
z.strictObject({
|
|
@@ -76,9 +78,22 @@ export const InteractionFieldSchema = z
|
|
|
76
78
|
...FieldBase,
|
|
77
79
|
type: z.literal("secret"),
|
|
78
80
|
placeholder: z.string().optional(),
|
|
81
|
+
/** Maximum answer length chosen by the request author. Omission means no contract limit. */
|
|
82
|
+
maxLength: z.number().int().positive().optional(),
|
|
79
83
|
}),
|
|
80
84
|
])
|
|
81
85
|
.superRefine((field, context) => {
|
|
86
|
+
if (field.type === "text" &&
|
|
87
|
+
field.default !== undefined &&
|
|
88
|
+
field.maxLength !== undefined &&
|
|
89
|
+
field.default.length > field.maxLength) {
|
|
90
|
+
context.addIssue({
|
|
91
|
+
code: "custom",
|
|
92
|
+
path: ["default"],
|
|
93
|
+
message: "text field default exceeds maxLength",
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
82
97
|
if (field.type === "number") {
|
|
83
98
|
if (field.min !== undefined &&
|
|
84
99
|
field.max !== undefined &&
|
|
@@ -489,10 +504,15 @@ export function validateInteractionAnswer(spec, data) {
|
|
|
489
504
|
}
|
|
490
505
|
switch (field.type) {
|
|
491
506
|
case "text":
|
|
492
|
-
case "secret":
|
|
493
|
-
if (typeof v !== "string")
|
|
507
|
+
case "secret": {
|
|
508
|
+
if (typeof v !== "string") {
|
|
494
509
|
errors.push(`field "${field.name}" must be a string`);
|
|
510
|
+
}
|
|
511
|
+
else if (field.maxLength !== undefined && v.length > field.maxLength) {
|
|
512
|
+
errors.push(`field "${field.name}" exceeds maxLength ${field.maxLength}`);
|
|
513
|
+
}
|
|
495
514
|
break;
|
|
515
|
+
}
|
|
496
516
|
case "number":
|
|
497
517
|
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
498
518
|
errors.push(`field "${field.name}" must be a finite number`);
|