masumi-schema-validator-component 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Masumi Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # schema-validator-component
2
+
3
+ React component that allows you to dynamically validate input schema and see how it would render in Sokosumi.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @masumi/schema-validator
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ This library is built with **Tailwind CSS** and relies on specific CSS variables (compatible with [shadcn/ui](https://ui.shadcn.com/)).
14
+
15
+ ### 1. Tailwind Configuration
16
+
17
+ You must add this package to your `tailwind.config.js` content array so Tailwind can scan for class names:
18
+
19
+ ```javascript
20
+ // tailwind.config.js
21
+ module.exports = {
22
+ content: [
23
+ // ... your other paths
24
+ "./node_modules/@masumi/schema-validator/dist/**/*.{js,mjs}"
25
+ ],
26
+ // ...
27
+ }
28
+ ```
29
+
30
+ ### 2. CSS Variables
31
+
32
+ Your application must define the standard `shadcn/ui` CSS variables (e.g., `--primary`, `--background`, `--foreground`) in your global CSS file for the component to be styled correctly.
33
+
34
+ ## Usage
35
+
36
+ ### Component
37
+
38
+ Import `JobInputsFormRenderer` to render a form based on your schema definition.
39
+
40
+ ```tsx
41
+ import { useState } from 'react';
42
+ import { JobInputsFormRenderer } from '@masumi/schema-validator';
43
+
44
+ const MyComponent = () => {
45
+ const [formData, setFormData] = useState({});
46
+
47
+ const schemas = [
48
+ {
49
+ id: "name",
50
+ type: "string",
51
+ name: "Full Name",
52
+ data: {
53
+ placeholder: "Enter your full name",
54
+ description: "Your complete name as it appears on official documents"
55
+ },
56
+ validations: [
57
+ { validation: "min", value: "2" }
58
+ ]
59
+ }
60
+ // ... more schema items
61
+ ];
62
+
63
+ return (
64
+ <JobInputsFormRenderer
65
+ jobInputSchemas={schemas}
66
+ onFormDataChange={setFormData}
67
+ className="my-custom-class"
68
+ />
69
+ );
70
+ };
71
+ ```
72
+
73
+ ### Schema Validation
74
+
75
+ You can also use the exported validation utilities to check if your schema JSON is valid before rendering.
76
+
77
+ ```tsx
78
+ import { validateSchemaWithZod } from '@masumi/schema-validator';
79
+
80
+ const schemaJson = `[...]`; // Your JSON string
81
+
82
+ const result = validateSchemaWithZod(schemaJson);
83
+
84
+ if (result.valid) {
85
+ console.log("Valid schemas:", result.parsedSchemas);
86
+ } else {
87
+ console.error("Validation errors:", result.errors);
88
+ }
89
+ ```