diff --git a/schemas/package-schemas/examples/advanced-features/api/rest.json b/schemas/package-schemas/examples/advanced-features/api/rest.json new file mode 100644 index 000000000..f227eb665 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/api/rest.json @@ -0,0 +1,232 @@ +{ + "$schema": "https://metabuilder.dev/schemas/api.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced REST API with authentication and rate limiting", + "basePath": "/api", + "version": "v1", + "auth": { + "type": "jwt", + "tokenLocation": "header", + "headerName": "Authorization", + "scheme": "Bearer", + "secret": "${JWT_SECRET}", + "expiresIn": 3600, + "issuer": "advanced-features-api" + }, + "rateLimit": { + "enabled": true, + "windowMs": 900000, + "maxRequests": 100, + "message": "Too many requests, please try again later", + "keyGenerator": "ip" + }, + "cors": { + "enabled": true, + "origin": ["http://localhost:3000", "https://example.com"], + "credentials": true, + "methods": ["GET", "POST", "PUT", "PATCH", "DELETE"], + "allowedHeaders": ["Content-Type", "Authorization"], + "exposedHeaders": ["X-Total-Count", "X-Page-Count"] + }, + "routes": [ + { + "id": "list_orders", + "path": "/orders", + "method": "GET", + "handler": "handlers.orders.list", + "description": "List orders with pagination and filtering", + "auth": { + "required": true, + "permissions": ["orders.read"] + }, + "rateLimit": { + "maxRequests": 60 + }, + "queryParams": { + "page": { + "type": "integer", + "default": 1, + "min": 1 + }, + "limit": { + "type": "integer", + "default": 20, + "min": 1, + "max": 100 + }, + "status": { + "type": "string", + "enum": ["pending", "processing", "shipped", "delivered", "cancelled", "refunded"] + }, + "customerId": { + "type": "uuid" + }, + "sort": { + "type": "string", + "default": "-createdAt" + } + }, + "response": { + "200": { + "description": "List of orders", + "type": "OrderListResponse" + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + } + } + }, + { + "id": "create_order", + "path": "/orders", + "method": "POST", + "handler": "handlers.orders.create", + "description": "Create a new order", + "auth": { + "required": true, + "permissions": ["orders.create"] + }, + "validation": { + "body": "CreateOrderRequest" + }, + "middleware": ["validateCart", "checkInventory"], + "response": { + "201": { + "description": "Order created", + "type": "Order" + }, + "400": { + "description": "Invalid request" + }, + "422": { + "description": "Validation failed" + } + } + }, + { + "id": "get_order", + "path": "/orders/:id", + "method": "GET", + "handler": "handlers.orders.get", + "description": "Get order by ID", + "auth": { + "required": true, + "permissions": ["orders.read"] + }, + "params": { + "id": { + "type": "uuid", + "required": true + } + }, + "queryParams": { + "include": { + "type": "array", + "items": { + "type": "string", + "enum": ["items", "customer", "shipping"] + } + } + }, + "response": { + "200": { + "description": "Order details", + "type": "Order" + }, + "404": { + "description": "Order not found" + } + } + }, + { + "id": "update_order", + "path": "/orders/:id", + "method": "PATCH", + "handler": "handlers.orders.update", + "description": "Update order", + "auth": { + "required": true, + "permissions": ["orders.update"] + }, + "params": { + "id": { + "type": "uuid", + "required": true + } + }, + "validation": { + "body": "UpdateOrderRequest" + }, + "response": { + "200": { + "description": "Order updated", + "type": "Order" + }, + "404": { + "description": "Order not found" + } + } + }, + { + "id": "cancel_order", + "path": "/orders/:id/cancel", + "method": "POST", + "handler": "handlers.orders.cancel", + "description": "Cancel an order", + "auth": { + "required": true, + "permissions": ["orders.cancel"] + }, + "params": { + "id": { + "type": "uuid", + "required": true + } + }, + "validation": { + "body": { + "reason": { + "type": "string", + "required": true, + "minLength": 10 + } + } + }, + "response": { + "200": { + "description": "Order cancelled", + "type": "Order" + }, + "400": { + "description": "Cannot cancel order in current status" + } + } + }, + { + "id": "webhook_shipment", + "path": "/webhooks/shipment", + "method": "POST", + "handler": "handlers.webhooks.shipment", + "description": "Webhook for shipment tracking updates", + "auth": { + "required": true, + "type": "apiKey", + "location": "header", + "name": "X-Webhook-Secret" + }, + "validation": { + "body": "ShipmentWebhook" + } + } + ], + "middleware": [ + "logger", + "cors", + "bodyParser", + "rateLimit" + ] +} diff --git a/schemas/package-schemas/examples/advanced-features/components/dashboard.json b/schemas/package-schemas/examples/advanced-features/components/dashboard.json new file mode 100644 index 000000000..0fca210ca --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/components/dashboard.json @@ -0,0 +1,207 @@ +{ + "$schema": "https://metabuilder.dev/schemas/components.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced UI components with state management", + "components": [ + { + "id": "order_dashboard", + "name": "OrderDashboard", + "type": "container", + "description": "Order management dashboard with real-time updates", + "props": { + "userId": { + "type": "string", + "required": false, + "description": "Filter by user ID" + }, + "status": { + "type": "OrderStatus", + "required": false, + "description": "Filter by order status" + }, + "onOrderSelect": { + "type": "function", + "signature": "(orderId: string) => void", + "required": false + } + }, + "state": { + "orders": { + "type": "AsyncOperation>", + "default": { "status": "idle", "data": null } + }, + "selectedOrder": { + "type": "string | null", + "default": null + }, + "filters": { + "type": "OrderFilters", + "default": {} + } + }, + "hooks": { + "onMount": "loadOrders", + "onUnmount": "cleanup" + }, + "children": [ + { + "component": "FilterBar", + "props": { + "filters": "state.filters", + "onChange": "handleFilterChange" + } + }, + { + "component": "OrderTable", + "props": { + "orders": "state.orders.data?.data", + "loading": "state.orders.status === 'loading'", + "onRowClick": "handleOrderSelect" + } + }, + { + "component": "Pagination", + "props": { + "pagination": "state.orders.data?.pagination", + "onChange": "handlePageChange" + } + } + ] + }, + { + "id": "order_table", + "name": "OrderTable", + "type": "presentation", + "description": "Sortable, filterable order table", + "props": { + "orders": { + "type": "Order[]", + "required": true + }, + "loading": { + "type": "boolean", + "required": false, + "default": false + }, + "sortBy": { + "type": "OrderKeys", + "required": false + }, + "sortDirection": { + "type": "'asc' | 'desc'", + "required": false, + "default": "desc" + }, + "onRowClick": { + "type": "function", + "signature": "(order: Order) => void", + "required": false + }, + "onSort": { + "type": "function", + "signature": "(field: OrderKeys, direction: 'asc' | 'desc') => void", + "required": false + } + }, + "columns": [ + { + "field": "orderNumber", + "header": "Order #", + "sortable": true, + "width": "150px" + }, + { + "field": "customer.name", + "header": "Customer", + "sortable": true + }, + { + "field": "status", + "header": "Status", + "sortable": true, + "render": "components.StatusBadge" + }, + { + "field": "totalAmount", + "header": "Total", + "sortable": true, + "render": "components.CurrencyFormatter" + }, + { + "field": "createdAt", + "header": "Date", + "sortable": true, + "render": "components.DateFormatter" + } + ] + }, + { + "id": "order_form", + "name": "OrderForm", + "type": "form", + "description": "Multi-step order creation form", + "props": { + "initialValues": { + "type": "Partial", + "required": false + }, + "onSubmit": { + "type": "function", + "signature": "(order: CreateOrderRequest) => Promise", + "required": true + }, + "onCancel": { + "type": "function", + "signature": "() => void", + "required": false + } + }, + "state": { + "currentStep": { + "type": "number", + "default": 1 + }, + "formData": { + "type": "Partial", + "default": {} + }, + "validationErrors": { + "type": "Record", + "default": {} + } + }, + "steps": [ + { + "id": "customer_info", + "title": "Customer Information", + "fields": ["customerId", "email", "phone"], + "validation": "validateCustomerInfo" + }, + { + "id": "items", + "title": "Order Items", + "fields": ["items"], + "validation": "validateOrderItems" + }, + { + "id": "shipping", + "title": "Shipping Details", + "fields": ["shippingAddress", "shippingMethod"], + "validation": "validateShippingInfo" + }, + { + "id": "payment", + "title": "Payment", + "fields": ["paymentMethod", "billingAddress"], + "validation": "validatePaymentInfo" + }, + { + "id": "review", + "title": "Review & Submit", + "readOnly": true + } + ] + } + ] +} diff --git a/schemas/package-schemas/examples/advanced-features/config/feature-flags.json b/schemas/package-schemas/examples/advanced-features/config/feature-flags.json new file mode 100644 index 000000000..00f29b967 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/config/feature-flags.json @@ -0,0 +1,218 @@ +{ + "$schema": "https://metabuilder.dev/schemas/config.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced configuration with feature flags and environment management", + "environments": ["development", "test", "staging", "production"], + "variables": [ + { + "name": "DATABASE_URL", + "type": "url", + "description": "PostgreSQL connection URL", + "required": true, + "sensitive": true, + "environment": ["development", "test", "staging", "production"] + }, + { + "name": "REDIS_URL", + "type": "url", + "description": "Redis connection URL for caching", + "required": true, + "sensitive": true, + "default": "redis://localhost:6379" + }, + { + "name": "KAFKA_HOST", + "type": "string", + "description": "Kafka broker hostname", + "required": true, + "default": "localhost" + }, + { + "name": "KAFKA_PORT", + "type": "number", + "description": "Kafka broker port", + "required": false, + "default": 9092, + "min": 1, + "max": 65535 + }, + { + "name": "MAX_CONCURRENT_ORDERS", + "type": "number", + "description": "Maximum concurrent order processing", + "required": false, + "default": 100, + "min": 1, + "max": 1000 + }, + { + "name": "ORDER_TIMEOUT_MS", + "type": "number", + "description": "Order processing timeout in milliseconds", + "required": false, + "default": 30000, + "min": 1000 + } + ], + "featureFlags": [ + { + "name": "event-sourcing", + "description": "Enable event sourcing for orders", + "enabled": false, + "environments": { + "development": { + "enabled": true + }, + "staging": { + "enabled": true, + "rollout": { + "percentage": 50 + } + }, + "production": { + "enabled": false + } + }, + "owner": "platform-team", + "tags": ["experimental", "orders"] + }, + { + "name": "real-time-inventory", + "description": "Real-time inventory updates via websockets", + "enabled": false, + "environments": { + "development": { + "enabled": true + }, + "production": { + "enabled": true, + "rollout": { + "percentage": 25, + "groups": ["premium-sellers"] + } + } + }, + "dependencies": ["websocket-support"], + "owner": "inventory-team" + }, + { + "name": "ai-fraud-detection", + "description": "ML-based fraud detection for payments", + "enabled": false, + "rules": [ + { + "condition": "order.totalAmount > 1000", + "enabled": true, + "description": "Enable for high-value orders" + } + ], + "variants": [ + { + "name": "model-v1", + "weight": 50, + "config": { + "model": "fraud-detection-v1", + "threshold": 0.7 + } + }, + { + "name": "model-v2", + "weight": 50, + "config": { + "model": "fraud-detection-v2", + "threshold": 0.8 + } + } + ], + "owner": "security-team", + "tags": ["ml", "security"] + }, + { + "name": "advanced-analytics", + "description": "Advanced analytics dashboard", + "enabled": false, + "environments": { + "production": { + "enabled": true, + "rollout": { + "users": ["admin-user-1", "admin-user-2"] + } + } + } + } + ], + "secrets": [ + { + "name": "JWT_SECRET", + "description": "JWT signing secret", + "provider": "aws-secrets-manager", + "path": "prod/api/jwt-secret", + "required": true, + "rotation": { + "enabled": true, + "interval": 7776000 + } + }, + { + "name": "STRIPE_SECRET_KEY", + "description": "Stripe API secret key", + "provider": "aws-secrets-manager", + "path": "prod/payments/stripe-secret", + "required": true, + "accessControl": { + "roles": ["admin", "payment-processor"], + "environments": ["production"] + } + }, + { + "name": "ENCRYPTION_KEY", + "description": "Data encryption key", + "provider": "aws-secrets-manager", + "path": "prod/security/encryption-key", + "required": true, + "encryption": { + "algorithm": "aes-256-gcm", + "keyId": "aws-kms-key-id" + } + } + ], + "providers": [ + { + "name": "environment", + "type": "env", + "priority": 100, + "enabled": true + }, + { + "name": "config-file", + "type": "file", + "priority": 50, + "enabled": true, + "options": { + "path": "./config/config.json", + "format": "json", + "watch": true + } + }, + { + "name": "remote-config", + "type": "remote", + "priority": 25, + "enabled": true, + "options": { + "url": "${CONFIG_SERVICE_URL}/config", + "pollInterval": 300, + "cache": true, + "cacheTTL": 600 + } + } + ], + "validation": { + "strict": true, + "onError": "throw", + "validateOnLoad": true, + "coerceTypes": true, + "removeUnknown": false + } +} diff --git a/schemas/package-schemas/examples/advanced-features/entities/advanced.json b/schemas/package-schemas/examples/advanced-features/entities/advanced.json new file mode 100644 index 000000000..220bbbbdc --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/entities/advanced.json @@ -0,0 +1,181 @@ +{ + "$schema": "https://metabuilder.dev/schemas/entities.schema.json", + "schemaVersion": "2.0.0", + "entities": [ + { + "name": "Order", + "version": "1.0", + "description": "E-commerce order entity with advanced features", + "tableName": "orders", + "softDelete": true, + "timestamps": true, + "fields": { + "id": { + "type": "uuid", + "required": true, + "primaryKey": true, + "description": "Unique order identifier" + }, + "orderNumber": { + "type": "string", + "required": true, + "unique": true, + "length": 20, + "description": "Human-readable order number" + }, + "customerId": { + "type": "uuid", + "required": true, + "index": true, + "description": "Reference to customer" + }, + "status": { + "type": "enum", + "required": true, + "enum": ["pending", "processing", "shipped", "delivered", "cancelled", "refunded"], + "default": "pending", + "description": "Order status" + }, + "totalAmount": { + "type": "decimal", + "required": true, + "precision": 10, + "scale": 2, + "description": "Total order amount in currency" + }, + "currency": { + "type": "string", + "required": true, + "length": 3, + "default": "USD", + "description": "ISO 4217 currency code" + }, + "shippingAddress": { + "type": "json", + "required": true, + "description": "Shipping address as JSON" + }, + "billingAddress": { + "type": "json", + "required": false, + "description": "Billing address (defaults to shipping)" + }, + "metadata": { + "type": "json", + "required": false, + "description": "Additional order metadata" + }, + "trackingNumber": { + "type": "string", + "required": false, + "length": 100, + "description": "Shipment tracking number" + }, + "notes": { + "type": "text", + "required": false, + "description": "Internal notes" + } + }, + "indexes": [ + { + "name": "idx_orders_customer_status", + "fields": ["customerId", "status"], + "unique": false + }, + { + "name": "idx_orders_order_number", + "fields": ["orderNumber"], + "unique": true + }, + { + "name": "idx_orders_created_at", + "fields": ["createdAt"], + "unique": false + } + ], + "relations": [ + { + "name": "customer", + "type": "belongsTo", + "entity": "Customer", + "foreignKey": "customerId" + }, + { + "name": "items", + "type": "hasMany", + "entity": "OrderItem", + "foreignKey": "orderId" + } + ] + }, + { + "name": "OrderItem", + "version": "1.0", + "description": "Individual items in an order", + "tableName": "order_items", + "timestamps": true, + "fields": { + "id": { + "type": "uuid", + "required": true, + "primaryKey": true + }, + "orderId": { + "type": "uuid", + "required": true, + "index": true + }, + "productId": { + "type": "uuid", + "required": true, + "index": true + }, + "quantity": { + "type": "integer", + "required": true, + "default": 1, + "validation": { + "min": 1 + } + }, + "unitPrice": { + "type": "decimal", + "required": true, + "precision": 10, + "scale": 2 + }, + "discount": { + "type": "decimal", + "required": false, + "precision": 5, + "scale": 2, + "default": 0 + }, + "subtotal": { + "type": "decimal", + "required": true, + "precision": 10, + "scale": 2, + "computed": { + "expression": "quantity * unitPrice * (1 - discount / 100)" + } + } + }, + "relations": [ + { + "name": "order", + "type": "belongsTo", + "entity": "Order", + "foreignKey": "orderId" + }, + { + "name": "product", + "type": "belongsTo", + "entity": "Product", + "foreignKey": "productId" + } + ] + } + ] +} diff --git a/schemas/package-schemas/examples/advanced-features/events/event-sourcing.json b/schemas/package-schemas/examples/advanced-features/events/event-sourcing.json new file mode 100644 index 000000000..c6d5b1b62 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/events/event-sourcing.json @@ -0,0 +1,230 @@ +{ + "$schema": "https://metabuilder.dev/schemas/events.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Event-sourcing pattern for orders with complete audit trail", + "events": [ + { + "id": "order_created", + "name": "order.created", + "version": "1.0.0", + "description": "Order was created", + "channel": "orders", + "payload": "OrderCreatedPayload", + "metadata": { + "timestamp": true, + "correlationId": true, + "userId": true + }, + "priority": "high", + "retention": { + "enabled": true, + "ttl": 31536000 + } + }, + { + "id": "order_status_changed", + "name": "order.statusChanged", + "version": "1.0.0", + "description": "Order status was updated", + "channel": "orders", + "payload": { + "type": "object", + "properties": { + "orderId": { "type": "string" }, + "previousStatus": { "type": "string" }, + "newStatus": { "type": "string" }, + "reason": { "type": "string" }, + "changedBy": { "type": "string" } + }, + "required": ["orderId", "previousStatus", "newStatus"] + }, + "priority": "high", + "retention": { + "enabled": true, + "ttl": 31536000 + } + }, + { + "id": "order_item_added", + "name": "order.itemAdded", + "version": "1.0.0", + "description": "Item was added to order", + "channel": "orders", + "payload": { + "type": "object", + "properties": { + "orderId": { "type": "string" }, + "item": { "type": "OrderItem" }, + "addedBy": { "type": "string" } + }, + "required": ["orderId", "item"] + }, + "retention": { + "enabled": true, + "ttl": 31536000 + } + }, + { + "id": "order_shipped", + "name": "order.shipped", + "version": "1.0.0", + "description": "Order was shipped", + "channel": "orders", + "payload": { + "type": "object", + "properties": { + "orderId": { "type": "string" }, + "trackingNumber": { "type": "string" }, + "carrier": { "type": "string" }, + "estimatedDelivery": { "type": "string" }, + "shippedAt": { "type": "string" } + }, + "required": ["orderId", "trackingNumber", "carrier"] + }, + "priority": "high", + "retention": { + "enabled": true, + "ttl": 31536000 + } + }, + { + "id": "payment_processed", + "name": "payment.processed", + "version": "1.0.0", + "description": "Payment was processed for order", + "channel": "payments", + "payload": { + "type": "object", + "properties": { + "orderId": { "type": "string" }, + "paymentId": { "type": "string" }, + "amount": { "type": "number" }, + "currency": { "type": "string" }, + "method": { "type": "string" }, + "status": { "type": "string" } + }, + "required": ["orderId", "paymentId", "amount", "currency"] + }, + "priority": "critical", + "retention": { + "enabled": true, + "ttl": 94608000 + } + } + ], + "subscribers": [ + { + "id": "order_event_store", + "name": "Order Event Store", + "description": "Persist all order events for event sourcing", + "events": ["order.*"], + "handler": "eventStore.persist", + "async": true, + "priority": 100, + "retry": { + "enabled": true, + "maxAttempts": 5, + "backoff": "exponential" + } + }, + { + "id": "update_order_projection", + "name": "Update Order Projection", + "description": "Update read model from events", + "events": ["order.*"], + "handler": "projections.updateOrder", + "async": true, + "retry": { + "enabled": true, + "maxAttempts": 3 + } + }, + { + "id": "send_shipping_notification", + "name": "Send Shipping Notification", + "description": "Notify customer when order ships", + "events": ["order.shipped"], + "handler": "notifications.sendShippingEmail", + "async": true, + "retry": { + "enabled": true, + "maxAttempts": 3 + } + }, + { + "id": "update_inventory", + "name": "Update Inventory", + "description": "Update inventory when order is created or cancelled", + "events": ["order.created", "order.cancelled"], + "handler": "inventory.updateStock", + "async": true, + "retry": { + "enabled": true, + "maxAttempts": 5 + }, + "deadLetterQueue": { + "enabled": true, + "channel": "inventory-dlq", + "maxRetries": 5 + } + }, + { + "id": "analytics_tracker", + "name": "Analytics Tracker", + "description": "Track all events for analytics", + "events": ["*"], + "handler": "analytics.track", + "async": true, + "priority": -10, + "retry": { + "enabled": false + } + } + ], + "channels": [ + { + "name": "orders", + "description": "Order lifecycle events", + "type": "stream", + "persistent": true, + "partitions": 3, + "retention": { + "ttl": 31536000 + } + }, + { + "name": "payments", + "description": "Payment events", + "type": "stream", + "persistent": true, + "retention": { + "ttl": 94608000 + } + }, + { + "name": "inventory-dlq", + "description": "Failed inventory updates", + "type": "queue", + "persistent": true + } + ], + "config": { + "enabled": true, + "engine": "kafka", + "connection": { + "host": "${KAFKA_HOST}", + "port": 9092 + }, + "serialization": "json", + "compression": "snappy", + "monitoring": { + "enabled": true, + "metrics": ["throughput", "latency", "errors", "retries", "dlq"] + }, + "replay": { + "enabled": true, + "storage": "kafka" + } + } +} diff --git a/schemas/package-schemas/examples/advanced-features/forms/multi-step.json b/schemas/package-schemas/examples/advanced-features/forms/multi-step.json new file mode 100644 index 000000000..c81af9548 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/forms/multi-step.json @@ -0,0 +1,273 @@ +{ + "$schema": "https://metabuilder.dev/schemas/forms.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced multi-step forms with conditional logic and async validation", + "forms": [ + { + "id": "vendor_onboarding", + "name": "VendorOnboarding", + "title": "Vendor Registration", + "description": "Multi-step vendor onboarding with document uploads", + "layout": "vertical", + "fields": [ + { + "name": "companyName", + "type": "text", + "label": "Company Name", + "required": true, + "validation": { + "required": "Company name is required", + "minLength": 2, + "maxLength": 100, + "async": "validators.checkCompanyNameAvailability", + "messages": { + "minLength": "Company name must be at least 2 characters" + } + }, + "aria": { + "label": "Enter your company name", + "required": true + } + }, + { + "name": "businessType", + "type": "select", + "label": "Business Type", + "required": true, + "options": [ + { "value": "sole-proprietor", "label": "Sole Proprietor" }, + { "value": "llc", "label": "LLC" }, + { "value": "corporation", "label": "Corporation" }, + { "value": "partnership", "label": "Partnership" }, + { "value": "nonprofit", "label": "Non-Profit" } + ] + }, + { + "name": "taxId", + "type": "text", + "label": "Tax ID / EIN", + "required": true, + "placeholder": "XX-XXXXXXX", + "validation": { + "required": true, + "pattern": "^\\d{2}-\\d{7}$", + "messages": { + "pattern": "Tax ID must be in format XX-XXXXXXX" + } + }, + "conditional": { + "when": "businessType", + "operator": "notEquals", + "value": "sole-proprietor", + "then": { + "require": ["taxId"] + } + } + }, + { + "name": "revenue", + "type": "select", + "label": "Annual Revenue", + "required": true, + "options": [ + { "value": "0-100k", "label": "Under $100,000" }, + { "value": "100k-500k", "label": "$100,000 - $500,000" }, + { "value": "500k-1m", "label": "$500,000 - $1 Million" }, + { "value": "1m-5m", "label": "$1 Million - $5 Million" }, + { "value": "5m+", "label": "Over $5 Million" } + ] + }, + { + "name": "productsOffered", + "type": "multiselect", + "label": "Product Categories", + "required": true, + "helpText": "Select all categories that apply", + "options": [ + { "value": "electronics", "label": "Electronics" }, + { "value": "clothing", "label": "Clothing & Apparel" }, + { "value": "home-garden", "label": "Home & Garden" }, + { "value": "sports", "label": "Sports & Outdoors" }, + { "value": "books", "label": "Books & Media" }, + { "value": "food-beverage", "label": "Food & Beverage" }, + { "value": "other", "label": "Other" } + ], + "validation": { + "custom": "validators.validateProductCategories" + } + }, + { + "name": "otherCategory", + "type": "text", + "label": "Please Specify Other Category", + "required": false, + "hidden": true, + "conditional": { + "when": "productsOffered", + "operator": "contains", + "value": "other", + "then": { + "show": ["otherCategory"], + "require": ["otherCategory"] + }, + "else": { + "hide": ["otherCategory"] + } + } + }, + { + "name": "contactName", + "type": "text", + "label": "Primary Contact Name", + "required": true + }, + { + "name": "contactEmail", + "type": "email", + "label": "Contact Email", + "required": true, + "validation": { + "email": true, + "async": "validators.checkEmailDomain" + } + }, + { + "name": "contactPhone", + "type": "tel", + "label": "Contact Phone", + "required": true, + "placeholder": "+1 (555) 000-0000", + "validation": { + "pattern": "^\\+?1?[-\\s.]?\\(?([0-9]{3})\\)?[-\\s.]?([0-9]{3})[-\\s.]?([0-9]{4})$" + } + }, + { + "name": "warehouseAddress", + "type": "text", + "label": "Warehouse Address", + "required": true + }, + { + "name": "shippingCapabilities", + "type": "checkbox", + "label": "Can handle own shipping", + "defaultValue": false + }, + { + "name": "shippingMethods", + "type": "multiselect", + "label": "Shipping Methods Available", + "required": false, + "options": [ + { "value": "ground", "label": "Ground Shipping" }, + { "value": "express", "label": "Express Shipping" }, + { "value": "overnight", "label": "Overnight" }, + { "value": "international", "label": "International" } + ], + "conditional": { + "when": "shippingCapabilities", + "operator": "equals", + "value": true, + "then": { + "show": ["shippingMethods"], + "require": ["shippingMethods"] + }, + "else": { + "hide": ["shippingMethods"] + } + } + }, + { + "name": "businessLicense", + "type": "file", + "label": "Business License", + "required": true, + "helpText": "Upload PDF or image (max 5MB)", + "validation": { + "custom": "validators.validateBusinessLicense" + }, + "attributes": { + "accept": ".pdf,.jpg,.jpeg,.png", + "maxSize": 5242880 + } + }, + { + "name": "insuranceCert", + "type": "file", + "label": "Liability Insurance Certificate", + "required": true, + "helpText": "Required for all vendors", + "attributes": { + "accept": ".pdf", + "maxSize": 5242880 + } + }, + { + "name": "agreeToTerms", + "type": "checkbox", + "label": "I agree to the Terms and Conditions", + "required": true, + "validation": { + "required": "You must agree to the terms and conditions" + } + }, + { + "name": "signature", + "type": "text", + "label": "Electronic Signature", + "required": true, + "helpText": "Type your full name as signature", + "validation": { + "required": true, + "custom": "validators.matchesContactName" + } + } + ], + "sections": [ + { + "title": "Business Information", + "description": "Tell us about your business", + "fields": ["companyName", "businessType", "taxId", "revenue", "productsOffered", "otherCategory"] + }, + { + "title": "Contact Information", + "description": "Primary contact details", + "fields": ["contactName", "contactEmail", "contactPhone"] + }, + { + "title": "Operations", + "description": "Warehouse and shipping information", + "fields": ["warehouseAddress", "shippingCapabilities", "shippingMethods"], + "collapsible": true + }, + { + "title": "Documentation", + "description": "Required legal documents", + "fields": ["businessLicense", "insuranceCert"] + }, + { + "title": "Agreement", + "description": "Terms and signature", + "fields": ["agreeToTerms", "signature"] + } + ], + "validation": { + "validateOnChange": false, + "validateOnBlur": true, + "validateOnSubmit": true, + "stopOnFirstError": false, + "crossFieldValidation": [ + { + "fields": ["contactEmail", "companyName"], + "validator": "validators.validateBusinessEmail", + "message": "Email domain should match company name" + } + ] + }, + "onSubmit": "handlers.submitVendorOnboarding", + "onValidate": "handlers.validateVendorForm", + "onChange": "handlers.trackFormProgress" + } + ] +} diff --git a/schemas/package-schemas/examples/advanced-features/jobs/scheduled-tasks.json b/schemas/package-schemas/examples/advanced-features/jobs/scheduled-tasks.json new file mode 100644 index 000000000..6c74fa090 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/jobs/scheduled-tasks.json @@ -0,0 +1,238 @@ +{ + "$schema": "https://metabuilder.dev/schemas/jobs.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced job scheduling with dependencies and error handling", + "jobs": [ + { + "id": "sync_inventory", + "name": "Sync Inventory", + "description": "Sync inventory levels from external suppliers", + "handler": "jobs.syncInventory", + "queue": "integration", + "schedule": { + "cron": "*/15 * * * *", + "timezone": "UTC" + }, + "enabled": true, + "priority": 5, + "timeout": 600000, + "retry": { + "enabled": true, + "maxAttempts": 3, + "backoff": "exponential", + "initialDelay": 5000, + "maxDelay": 60000, + "retryOn": ["NETWORK_ERROR", "TIMEOUT"] + }, + "concurrency": 1, + "hooks": { + "onStart": "hooks.notifyJobStart", + "onComplete": "hooks.logJobSuccess", + "onError": "hooks.handleJobError", + "onFailed": "hooks.alertJobFailure" + }, + "notifications": { + "onFailure": ["ops@example.com"], + "channels": ["email", "slack"] + }, + "tags": ["inventory", "integration", "critical"] + }, + { + "id": "generate_daily_report", + "name": "Generate Daily Sales Report", + "description": "Generate and email daily sales report", + "handler": "jobs.generateDailySalesReport", + "queue": "reports", + "schedule": { + "cron": "0 8 * * *", + "timezone": "America/New_York", + "immediate": false + }, + "enabled": true, + "timeout": 300000, + "dependencies": ["sync_inventory"], + "params": { + "includeCharts": true, + "format": "pdf", + "recipients": ["sales@example.com", "management@example.com"] + }, + "validation": { + "schema": "DailyReportParams" + } + }, + { + "id": "cleanup_expired_sessions", + "name": "Cleanup Expired Sessions", + "description": "Remove expired user sessions from Redis", + "handler": "jobs.cleanupExpiredSessions", + "queue": "maintenance", + "schedule": { + "interval": 3600000 + }, + "enabled": true, + "priority": -5, + "timeout": 120000, + "cleanup": { + "removeOnComplete": true, + "removeOnFail": false, + "keepLogs": 10 + } + }, + { + "id": "process_abandoned_carts", + "name": "Process Abandoned Carts", + "description": "Send reminders for abandoned shopping carts", + "handler": "jobs.processAbandonedCarts", + "queue": "marketing", + "schedule": { + "cron": "0 10,16 * * *", + "timezone": "America/New_York" + }, + "enabled": true, + "rateLimit": { + "max": 1000, + "window": 3600000 + }, + "params": { + "minCartValue": 50, + "abandonedHours": 24 + } + }, + { + "id": "reindex_search", + "name": "Reindex Search Database", + "description": "Full reindex of product search database", + "handler": "jobs.reindexSearch", + "queue": "maintenance", + "schedule": { + "cron": "0 3 * * 0", + "timezone": "UTC" + }, + "enabled": true, + "priority": 10, + "timeout": 7200000, + "concurrency": 1, + "notifications": { + "onSuccess": ["platform-team@example.com"], + "onFailure": ["platform-team@example.com", "oncall@example.com"], + "channels": ["email", "slack"] + } + }, + { + "id": "archive_old_orders", + "name": "Archive Old Orders", + "description": "Archive orders older than 2 years to cold storage", + "handler": "jobs.archiveOldOrders", + "queue": "maintenance", + "schedule": { + "cron": "0 2 1 * *", + "timezone": "UTC" + }, + "enabled": true, + "timeout": 3600000, + "params": { + "ageInDays": 730, + "batchSize": 1000 + } + } + ], + "queues": [ + { + "name": "default", + "description": "Default job queue", + "concurrency": 10, + "priority": false, + "persistence": { + "enabled": true, + "backend": "redis", + "connection": { + "url": "${REDIS_URL}" + } + } + }, + { + "name": "integration", + "description": "External integration jobs", + "concurrency": 3, + "priority": true, + "rateLimit": { + "max": 100, + "window": 60000 + }, + "persistence": { + "enabled": true, + "backend": "redis" + }, + "deadLetter": { + "enabled": true, + "queue": "integration-dlq", + "maxRetries": 5 + }, + "monitoring": { + "enabled": true, + "metrics": ["throughput", "latency", "waiting", "failed"] + } + }, + { + "name": "reports", + "description": "Report generation queue", + "concurrency": 2, + "priority": false, + "persistence": { + "enabled": true, + "backend": "redis" + } + }, + { + "name": "maintenance", + "description": "Maintenance and cleanup tasks", + "concurrency": 1, + "priority": true, + "persistence": { + "enabled": true, + "backend": "redis" + } + }, + { + "name": "marketing", + "description": "Marketing and email jobs", + "concurrency": 5, + "rateLimit": { + "max": 500, + "window": 3600000 + }, + "persistence": { + "enabled": true, + "backend": "redis" + } + } + ], + "config": { + "enabled": true, + "defaultQueue": "default", + "defaultTimeout": 30000, + "defaultRetry": { + "enabled": true, + "maxAttempts": 3, + "backoff": "exponential", + "delay": 1000, + "maxDelay": 60000 + }, + "maxConcurrentJobs": 20, + "processInterval": 1000, + "lockDuration": 30000, + "lockRenewInterval": 5000, + "stalledInterval": 30000, + "cleanupInterval": 3600000, + "retention": { + "completed": 86400, + "failed": 604800 + }, + "logging": { + "enabled": true, + "level": "info", + "logJobData": false + } + } +} diff --git a/schemas/package-schemas/examples/advanced-features/migrations/complex-schema.json b/schemas/package-schemas/examples/advanced-features/migrations/complex-schema.json new file mode 100644 index 000000000..fc65a5b52 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/migrations/complex-schema.json @@ -0,0 +1,427 @@ +{ + "$schema": "https://metabuilder.dev/schemas/migrations.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Complex database migrations with data transformations", + "migrations": [ + { + "version": "001", + "timestamp": "2024-01-01T00:00:00Z", + "description": "Create orders and order_items tables with full schema", + "author": "platform-team", + "up": [ + { + "type": "createTable", + "table": "orders", + "columns": [ + { + "name": "id", + "type": "uuid", + "primary": true, + "nullable": false + }, + { + "name": "order_number", + "type": "string", + "length": 20, + "nullable": false, + "unique": true + }, + { + "name": "customer_id", + "type": "uuid", + "nullable": false + }, + { + "name": "status", + "type": "enum", + "enum": ["pending", "processing", "shipped", "delivered", "cancelled", "refunded"], + "nullable": false, + "default": "pending" + }, + { + "name": "total_amount", + "type": "decimal", + "precision": 10, + "scale": 2, + "nullable": false + }, + { + "name": "currency", + "type": "string", + "length": 3, + "nullable": false, + "default": "USD" + }, + { + "name": "shipping_address", + "type": "jsonb", + "nullable": false + }, + { + "name": "billing_address", + "type": "jsonb", + "nullable": true + }, + { + "name": "metadata", + "type": "jsonb", + "nullable": true + }, + { + "name": "tracking_number", + "type": "string", + "length": 100, + "nullable": true + }, + { + "name": "notes", + "type": "text", + "nullable": true + }, + { + "name": "created_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "updated_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "deleted_at", + "type": "timestamp", + "nullable": true + } + ], + "indexes": [ + { + "name": "idx_orders_customer", + "columns": ["customer_id"] + }, + { + "name": "idx_orders_status", + "columns": ["status"] + }, + { + "name": "idx_orders_created", + "columns": ["created_at"] + }, + { + "name": "idx_orders_tracking", + "columns": ["tracking_number"] + } + ], + "options": { + "comment": "Customer orders table with soft delete support" + } + }, + { + "type": "createTable", + "table": "order_items", + "columns": [ + { + "name": "id", + "type": "uuid", + "primary": true, + "nullable": false + }, + { + "name": "order_id", + "type": "uuid", + "nullable": false + }, + { + "name": "product_id", + "type": "uuid", + "nullable": false + }, + { + "name": "quantity", + "type": "integer", + "nullable": false, + "default": 1 + }, + { + "name": "unit_price", + "type": "decimal", + "precision": 10, + "scale": 2, + "nullable": false + }, + { + "name": "discount", + "type": "decimal", + "precision": 5, + "scale": 2, + "nullable": false, + "default": 0 + }, + { + "name": "subtotal", + "type": "decimal", + "precision": 10, + "scale": 2, + "nullable": false + }, + { + "name": "created_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "updated_at", + "type": "timestamp", + "nullable": false + } + ], + "foreignKeys": [ + { + "name": "fk_order_items_order", + "columns": ["order_id"], + "references": { + "table": "orders", + "columns": ["id"] + }, + "onDelete": "CASCADE", + "onUpdate": "CASCADE" + } + ], + "indexes": [ + { + "name": "idx_order_items_order", + "columns": ["order_id"] + }, + { + "name": "idx_order_items_product", + "columns": ["product_id"] + } + ] + } + ], + "down": [ + { + "type": "dropTable", + "table": "order_items", + "cascade": true + }, + { + "type": "dropTable", + "table": "orders", + "cascade": true + } + ], + "transactional": true + }, + { + "version": "002", + "timestamp": "2024-01-15T00:00:00Z", + "description": "Add payment tracking columns", + "author": "payments-team", + "dependencies": ["001"], + "up": [ + { + "type": "addColumn", + "table": "orders", + "column": { + "name": "payment_status", + "type": "enum", + "enum": ["pending", "authorized", "captured", "failed", "refunded"], + "nullable": false, + "default": "pending" + } + }, + { + "type": "addColumn", + "table": "orders", + "column": { + "name": "payment_method", + "type": "string", + "length": 50, + "nullable": true + } + }, + { + "type": "addColumn", + "table": "orders", + "column": { + "name": "payment_id", + "type": "string", + "length": 100, + "nullable": true, + "comment": "External payment processor ID" + } + }, + { + "type": "addIndex", + "table": "orders", + "index": { + "name": "idx_orders_payment_status", + "columns": ["payment_status"] + } + } + ], + "down": [ + { + "type": "dropIndex", + "table": "orders", + "name": "idx_orders_payment_status" + }, + { + "type": "dropColumn", + "table": "orders", + "column": "payment_id" + }, + { + "type": "dropColumn", + "table": "orders", + "column": "payment_method" + }, + { + "type": "dropColumn", + "table": "orders", + "column": "payment_status" + } + ], + "transactional": true + }, + { + "version": "003", + "timestamp": "2024-02-01T00:00:00Z", + "description": "Migrate order numbers to new format", + "author": "platform-team", + "dependencies": ["002"], + "up": [ + { + "type": "sql", + "sql": [ + "-- Temporarily remove unique constraint", + "ALTER TABLE orders DROP CONSTRAINT IF EXISTS orders_order_number_key;", + "-- Update order numbers to new format", + "UPDATE orders SET order_number = 'ORD-' || TO_CHAR(created_at, 'YYYY') || '-' || LPAD(CAST(id AS TEXT), 6, '0') WHERE order_number NOT LIKE 'ORD-%';", + "-- Re-add unique constraint", + "ALTER TABLE orders ADD CONSTRAINT orders_order_number_key UNIQUE (order_number);" + ] + } + ], + "down": [ + { + "type": "sql", + "sql": "-- Cannot reliably reverse order number migration" + } + ], + "transactional": true + }, + { + "version": "004", + "timestamp": "2024-02-15T00:00:00Z", + "description": "Add order fulfillment tracking", + "author": "operations-team", + "dependencies": ["003"], + "up": [ + { + "type": "createTable", + "table": "order_fulfillments", + "columns": [ + { + "name": "id", + "type": "uuid", + "primary": true, + "nullable": false + }, + { + "name": "order_id", + "type": "uuid", + "nullable": false + }, + { + "name": "warehouse_id", + "type": "uuid", + "nullable": false + }, + { + "name": "status", + "type": "enum", + "enum": ["pending", "picking", "packing", "shipped", "cancelled"], + "nullable": false, + "default": "pending" + }, + { + "name": "picked_at", + "type": "timestamp", + "nullable": true + }, + { + "name": "packed_at", + "type": "timestamp", + "nullable": true + }, + { + "name": "shipped_at", + "type": "timestamp", + "nullable": true + }, + { + "name": "tracking_url", + "type": "string", + "length": 500, + "nullable": true + }, + { + "name": "notes", + "type": "text", + "nullable": true + }, + { + "name": "created_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "updated_at", + "type": "timestamp", + "nullable": false + } + ], + "foreignKeys": [ + { + "name": "fk_fulfillments_order", + "columns": ["order_id"], + "references": { + "table": "orders", + "columns": ["id"] + }, + "onDelete": "CASCADE" + } + ], + "indexes": [ + { + "name": "idx_fulfillments_order", + "columns": ["order_id"] + }, + { + "name": "idx_fulfillments_status", + "columns": ["status"] + } + ] + } + ], + "down": [ + { + "type": "dropTable", + "table": "order_fulfillments", + "cascade": true + } + ], + "transactional": true + } + ], + "config": { + "tableName": "schema_migrations", + "autoRun": false, + "validateChecksums": true, + "allowOutOfOrder": false, + "lockTimeout": 300 + } +} diff --git a/schemas/package-schemas/examples/advanced-features/package.json b/schemas/package-schemas/examples/advanced-features/package.json new file mode 100644 index 000000000..145d26bd7 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/package.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://metabuilder.dev/schemas/package-metadata.schema.json", + "packageId": "advanced-features", + "name": "Advanced Features Package", + "version": "1.0.0", + "description": "Demonstrates advanced MetaBuilder features and patterns", + "author": "MetaBuilder Team", + "license": "MIT", + "tags": ["advanced", "examples", "features"], + "repository": { + "type": "git", + "url": "https://github.com/metabuilder/advanced-features" + } +} diff --git a/schemas/package-schemas/examples/advanced-features/permissions/abac.json b/schemas/package-schemas/examples/advanced-features/permissions/abac.json new file mode 100644 index 000000000..42890165e --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/permissions/abac.json @@ -0,0 +1,355 @@ +{ + "$schema": "https://metabuilder.dev/schemas/permissions.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced ABAC (Attribute-Based Access Control) with dynamic policies", + "roles": [ + { + "id": "super-admin", + "name": "Super Administrator", + "description": "Full system access with no restrictions", + "level": 100, + "permissions": ["*"], + "system": true, + "metadata": { + "color": "#dc2626", + "icon": "shield-check" + } + }, + { + "id": "admin", + "name": "Administrator", + "description": "Administrative access", + "level": 90, + "permissions": [ + "orders.*", + "users.read", + "users.update", + "products.*", + "reports.read", + "settings.update" + ], + "system": true + }, + { + "id": "order-manager", + "name": "Order Manager", + "description": "Manage all orders and customer service", + "level": 50, + "permissions": [ + "orders.*", + "customers.read", + "products.read", + "shipping.manage" + ], + "inherits": ["customer-service"] + }, + { + "id": "customer-service", + "name": "Customer Service", + "description": "Handle customer inquiries and basic order management", + "level": 30, + "permissions": [ + "orders.read", + "orders.update", + "customers.read", + "tickets.manage" + ] + }, + { + "id": "warehouse-staff", + "name": "Warehouse Staff", + "description": "Manage inventory and fulfillment", + "level": 25, + "permissions": [ + "orders.read", + "inventory.*", + "shipping.create", + "shipping.update" + ] + }, + { + "id": "analyst", + "name": "Data Analyst", + "description": "Read-only access to data and reports", + "level": 20, + "permissions": [ + "orders.read", + "products.read", + "customers.read", + "reports.*", + "analytics.*" + ] + }, + { + "id": "customer", + "name": "Customer", + "description": "Standard customer account", + "level": 10, + "permissions": [ + "orders.read.own", + "orders.create", + "profile.manage.own" + ], + "default": true + } + ], + "permissions": [ + { + "id": "orders.manage.high-value", + "name": "Manage High-Value Orders", + "description": "Manage orders over $10,000", + "resource": "orders", + "action": "manage", + "scope": "custom", + "conditions": [ + { + "type": "attribute", + "attribute": "order.totalAmount", + "operator": "greaterThan", + "value": 10000 + }, + { + "type": "role", + "operator": "in", + "value": ["admin", "order-manager"] + } + ], + "priority": 10 + }, + { + "id": "orders.cancel.recent", + "name": "Cancel Recent Orders", + "description": "Cancel orders within 24 hours of creation", + "resource": "orders", + "action": "delete", + "conditions": [ + { + "type": "custom", + "expression": "helpers.isWithinHours(order.createdAt, 24)" + } + ] + }, + { + "id": "data.export.restricted", + "name": "Export Restricted Data", + "description": "Export sensitive customer data", + "resource": "data", + "action": "execute", + "conditions": [ + { + "type": "role", + "operator": "in", + "value": ["admin", "analyst"] + }, + { + "type": "time", + "timeRange": { + "start": "09:00", + "end": "17:00", + "timezone": "America/New_York", + "days": ["monday", "tuesday", "wednesday", "thursday", "friday"] + } + }, + { + "type": "ip", + "ipRanges": ["10.0.0.0/8", "192.168.0.0/16"] + } + ], + "priority": 20 + } + ], + "resources": [ + { + "id": "orders", + "name": "Orders", + "type": "entity", + "description": "Customer orders", + "actions": ["create", "read", "update", "delete", "manage"], + "ownership": { + "enabled": true, + "field": "customerId", + "allowedActions": ["read", "update"] + }, + "attributes": [ + { + "name": "totalAmount", + "type": "number", + "description": "Order total amount" + }, + { + "name": "status", + "type": "string", + "description": "Order status" + }, + { + "name": "createdAt", + "type": "date", + "description": "Order creation date" + } + ], + "hierarchical": false + }, + { + "id": "inventory", + "name": "Inventory", + "type": "entity", + "description": "Product inventory", + "actions": ["read", "update", "manage"], + "attributes": [ + { + "name": "warehouseId", + "type": "string", + "description": "Warehouse location" + }, + { + "name": "quantity", + "type": "number", + "description": "Stock quantity" + } + ] + }, + { + "id": "reports", + "name": "Reports", + "type": "custom", + "description": "Business reports and analytics", + "actions": ["read", "execute"], + "attributes": [ + { + "name": "sensitivity", + "type": "string", + "description": "Data sensitivity level" + }, + { + "name": "department", + "type": "string", + "description": "Owning department" + } + ] + } + ], + "policies": [ + { + "id": "regional_data_access", + "name": "Regional Data Access Policy", + "description": "Restrict data access by user region", + "effect": "allow", + "priority": 50, + "rules": [ + { + "resources": ["orders/*", "customers/*"], + "actions": ["read", "update"], + "conditions": [ + { + "type": "attribute", + "attribute": "user.region", + "operator": "equals", + "value": "resource.region" + } + ] + } + ], + "subjects": { + "roles": ["order-manager", "customer-service"] + }, + "enabled": true + }, + { + "id": "high_value_approval", + "name": "High-Value Order Approval", + "description": "Require approval for orders over $5000", + "effect": "deny", + "priority": 75, + "rules": [ + { + "resources": ["orders"], + "actions": ["create", "update"], + "conditions": [ + { + "type": "attribute", + "attribute": "order.totalAmount", + "operator": "greaterThan", + "value": 5000 + }, + { + "type": "attribute", + "attribute": "order.approved", + "operator": "notEquals", + "value": true + } + ] + } + ], + "enabled": true + }, + { + "id": "pci_compliance", + "name": "PCI Compliance Policy", + "description": "Restrict payment data access", + "effect": "deny", + "priority": 100, + "rules": [ + { + "resources": ["payments/*/full-card-number"], + "actions": ["read"], + "conditions": [ + { + "type": "role", + "operator": "notIn", + "value": ["super-admin", "payment-processor"] + } + ] + } + ], + "enabled": true + }, + { + "id": "gdpr_data_export", + "name": "GDPR Data Export Policy", + "description": "Control customer data exports", + "effect": "allow", + "priority": 60, + "rules": [ + { + "resources": ["customers/*/data-export"], + "actions": ["execute"], + "conditions": [ + { + "type": "ownership", + "attribute": "customerId", + "operator": "equals", + "value": "currentUser.id" + } + ] + } + ], + "enabled": true + } + ], + "config": { + "enabled": true, + "model": "hybrid", + "defaultDeny": true, + "caching": { + "enabled": true, + "ttl": 300 + }, + "audit": { + "enabled": true, + "logDenials": true, + "logGrants": true, + "handler": "audit.logPermissionCheck" + }, + "superAdmin": { + "enabled": true, + "roleId": "super-admin", + "bypassAll": true + }, + "delegation": { + "enabled": true, + "maxDepth": 2, + "requireApproval": true + } + } +} diff --git a/schemas/package-schemas/examples/advanced-features/scripts/automation.json b/schemas/package-schemas/examples/advanced-features/scripts/automation.json new file mode 100644 index 000000000..7bf2b2c83 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/scripts/automation.json @@ -0,0 +1,336 @@ +{ + "$schema": "https://metabuilder.dev/schemas/script.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced automation scripts with error handling and retry logic", + "scripts": [ + { + "id": "process_pending_orders", + "name": "processPendingOrders", + "description": "Process all pending orders and update their status", + "async": true, + "returnType": "Promise", + "params": [], + "body": [ + { + "type": "try", + "try": [ + { + "type": "variable", + "name": "pendingOrders", + "value": { + "type": "await", + "expression": "db.orders.findMany({ where: { status: 'pending' } })" + } + }, + { + "type": "variable", + "name": "results", + "value": { + "processed": 0, + "failed": 0, + "errors": [] + } + }, + { + "type": "for", + "iterator": "order", + "iterable": "pendingOrders", + "body": [ + { + "type": "try", + "try": [ + { + "type": "await", + "expression": "processOrder(order)" + }, + { + "type": "expression", + "expression": "results.processed++" + } + ], + "catch": { + "errorVar": "error", + "body": [ + { + "type": "expression", + "expression": "results.failed++" + }, + { + "type": "expression", + "expression": "results.errors.push({ orderId: order.id, error: error.message })" + }, + { + "type": "await", + "expression": "logger.error('Failed to process order', { orderId: order.id, error })" + } + ] + } + } + ] + }, + { + "type": "return", + "value": { + "type": "expression", + "expression": "results" + } + } + ], + "catch": { + "errorVar": "error", + "body": [ + { + "type": "await", + "expression": "logger.error('Critical error in processPendingOrders', { error })" + }, + { + "type": "throw", + "value": "error" + } + ] + } + } + ] + }, + { + "id": "send_order_confirmation", + "name": "sendOrderConfirmation", + "description": "Send order confirmation email with retry logic", + "async": true, + "params": [ + { + "name": "orderId", + "type": "string", + "required": true + } + ], + "returnType": "Promise", + "body": [ + { + "type": "variable", + "name": "order", + "value": { + "type": "await", + "expression": "db.orders.findUnique({ where: { id: orderId }, include: { customer: true, items: true } })" + } + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "!order" + }, + "then": [ + { + "type": "throw", + "value": { + "type": "new", + "class": "Error", + "args": ["Order not found"] + } + } + ] + }, + { + "type": "variable", + "name": "maxRetries", + "value": 3 + }, + { + "type": "variable", + "name": "retryDelay", + "value": 1000 + }, + { + "type": "for", + "iterator": "attempt", + "start": 1, + "condition": { + "type": "comparison", + "operator": "<=", + "left": "attempt", + "right": "maxRetries" + }, + "increment": 1, + "body": [ + { + "type": "try", + "try": [ + { + "type": "await", + "expression": "emailService.send({ to: order.customer.email, template: 'order-confirmation', data: order })" + }, + { + "type": "await", + "expression": "db.orders.update({ where: { id: orderId }, data: { confirmationSent: true } })" + }, + { + "type": "return" + } + ], + "catch": { + "errorVar": "error", + "body": [ + { + "type": "await", + "expression": "logger.warn(`Failed to send confirmation (attempt ${attempt}/${maxRetries})`, { orderId, error })" + }, + { + "type": "conditional", + "condition": { + "type": "comparison", + "operator": "===", + "left": "attempt", + "right": "maxRetries" + }, + "then": [ + { + "type": "throw", + "value": "error" + } + ], + "else": [ + { + "type": "await", + "expression": "sleep(retryDelay * attempt)" + } + ] + } + ] + } + } + ] + } + ] + }, + { + "id": "calculate_shipping_cost", + "name": "calculateShippingCost", + "description": "Calculate shipping cost based on weight, distance, and method", + "params": [ + { + "name": "order", + "type": "Order", + "required": true + }, + { + "name": "method", + "type": "ShippingMethod", + "required": true + } + ], + "returnType": "number", + "body": [ + { + "type": "comment", + "text": "Calculate total weight" + }, + { + "type": "variable", + "name": "totalWeight", + "value": { + "type": "expression", + "expression": "order.items.reduce((sum, item) => sum + (item.product.weight * item.quantity), 0)" + } + }, + { + "type": "comment", + "text": "Get distance from warehouse to destination" + }, + { + "type": "variable", + "name": "distance", + "value": { + "type": "expression", + "expression": "calculateDistance(warehouse.address, order.shippingAddress)" + } + }, + { + "type": "comment", + "text": "Base rate calculation" + }, + { + "type": "variable", + "name": "baseRate", + "value": { + "type": "switch", + "expression": "method", + "cases": [ + { + "value": "'standard'", + "result": 5.99 + }, + { + "value": "'express'", + "result": 12.99 + }, + { + "value": "'overnight'", + "result": 24.99 + } + ], + "default": 5.99 + } + }, + { + "type": "comment", + "text": "Weight surcharge" + }, + { + "type": "variable", + "name": "weightSurcharge", + "value": { + "type": "ternary", + "condition": "totalWeight > 10", + "ifTrue": { + "type": "expression", + "expression": "(totalWeight - 10) * 0.5" + }, + "ifFalse": 0 + } + }, + { + "type": "comment", + "text": "Distance surcharge" + }, + { + "type": "variable", + "name": "distanceSurcharge", + "value": { + "type": "ternary", + "condition": "distance > 100", + "ifTrue": { + "type": "expression", + "expression": "(distance - 100) * 0.1" + }, + "ifFalse": 0 + } + }, + { + "type": "comment", + "text": "Calculate total" + }, + { + "type": "variable", + "name": "total", + "value": { + "type": "expression", + "expression": "baseRate + weightSurcharge + distanceSurcharge" + } + }, + { + "type": "comment", + "text": "Round to 2 decimal places" + }, + { + "type": "return", + "value": { + "type": "expression", + "expression": "Math.round(total * 100) / 100" + } + } + ] + } + ] +} diff --git a/schemas/package-schemas/examples/advanced-features/styles/design-system.json b/schemas/package-schemas/examples/advanced-features/styles/design-system.json new file mode 100644 index 000000000..7c8cdd5c7 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/styles/design-system.json @@ -0,0 +1,240 @@ +{ + "$schema": "https://metabuilder.dev/schemas/styles.schema.json", + "schemaVersion": "1.0.0", + "package": "advanced-features", + "description": "Advanced design system with theming and responsive breakpoints", + "tokens": { + "colors": { + "primary": { + "50": "#f0f9ff", + "100": "#e0f2fe", + "200": "#bae6fd", + "300": "#7dd3fc", + "400": "#38bdf8", + "500": "#0ea5e9", + "600": "#0284c7", + "700": "#0369a1", + "800": "#075985", + "900": "#0c4a6e" + }, + "success": { + "light": "#d1fae5", + "base": "#10b981", + "dark": "#065f46" + }, + "warning": { + "light": "#fef3c7", + "base": "#f59e0b", + "dark": "#92400e" + }, + "error": { + "light": "#fee2e2", + "base": "#ef4444", + "dark": "#991b1b" + }, + "neutral": { + "0": "#ffffff", + "50": "#fafafa", + "100": "#f5f5f5", + "200": "#e5e5e5", + "300": "#d4d4d4", + "400": "#a3a3a3", + "500": "#737373", + "600": "#525252", + "700": "#404040", + "800": "#262626", + "900": "#171717", + "950": "#0a0a0a" + } + }, + "spacing": { + "0": "0px", + "1": "0.25rem", + "2": "0.5rem", + "3": "0.75rem", + "4": "1rem", + "5": "1.25rem", + "6": "1.5rem", + "8": "2rem", + "10": "2.5rem", + "12": "3rem", + "16": "4rem", + "20": "5rem", + "24": "6rem", + "32": "8rem" + }, + "typography": { + "fontFamily": { + "sans": "Inter, system-ui, -apple-system, sans-serif", + "serif": "Georgia, serif", + "mono": "'JetBrains Mono', 'Fira Code', monospace" + }, + "fontSize": { + "xs": "0.75rem", + "sm": "0.875rem", + "base": "1rem", + "lg": "1.125rem", + "xl": "1.25rem", + "2xl": "1.5rem", + "3xl": "1.875rem", + "4xl": "2.25rem", + "5xl": "3rem" + }, + "fontWeight": { + "light": 300, + "normal": 400, + "medium": 500, + "semibold": 600, + "bold": 700, + "extrabold": 800 + }, + "lineHeight": { + "tight": 1.25, + "normal": 1.5, + "relaxed": 1.75, + "loose": 2 + } + }, + "borderRadius": { + "none": "0", + "sm": "0.125rem", + "base": "0.25rem", + "md": "0.375rem", + "lg": "0.5rem", + "xl": "0.75rem", + "2xl": "1rem", + "full": "9999px" + }, + "shadows": { + "sm": "0 1px 2px 0 rgba(0, 0, 0, 0.05)", + "base": "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)", + "md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)", + "lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)", + "xl": "0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)", + "2xl": "0 25px 50px -12px rgba(0, 0, 0, 0.25)" + }, + "breakpoints": { + "xs": "320px", + "sm": "640px", + "md": "768px", + "lg": "1024px", + "xl": "1280px", + "2xl": "1536px" + }, + "transitions": { + "fast": "150ms", + "base": "300ms", + "slow": "500ms", + "verySlow": "1000ms" + }, + "zIndex": { + "hide": -1, + "base": 0, + "dropdown": 1000, + "sticky": 1100, + "overlay": 1200, + "modal": 1300, + "popover": 1400, + "toast": 1500, + "tooltip": 1600 + } + }, + "themes": { + "light": { + "background": { + "primary": "colors.neutral.0", + "secondary": "colors.neutral.50", + "tertiary": "colors.neutral.100" + }, + "text": { + "primary": "colors.neutral.900", + "secondary": "colors.neutral.600", + "tertiary": "colors.neutral.400" + }, + "border": "colors.neutral.200" + }, + "dark": { + "background": { + "primary": "colors.neutral.900", + "secondary": "colors.neutral.800", + "tertiary": "colors.neutral.700" + }, + "text": { + "primary": "colors.neutral.50", + "secondary": "colors.neutral.300", + "tertiary": "colors.neutral.500" + }, + "border": "colors.neutral.700" + } + }, + "components": { + "button": { + "base": { + "padding": "spacing.3 spacing.6", + "borderRadius": "borderRadius.md", + "fontSize": "typography.fontSize.base", + "fontWeight": "typography.fontWeight.medium", + "transition": "transitions.base" + }, + "variants": { + "primary": { + "background": "colors.primary.500", + "color": "colors.neutral.0", + "hover": { + "background": "colors.primary.600" + } + }, + "secondary": { + "background": "colors.neutral.200", + "color": "colors.neutral.900", + "hover": { + "background": "colors.neutral.300" + } + }, + "ghost": { + "background": "transparent", + "color": "colors.primary.500", + "hover": { + "background": "colors.primary.50" + } + } + }, + "sizes": { + "sm": { + "padding": "spacing.2 spacing.4", + "fontSize": "typography.fontSize.sm" + }, + "md": { + "padding": "spacing.3 spacing.6", + "fontSize": "typography.fontSize.base" + }, + "lg": { + "padding": "spacing.4 spacing.8", + "fontSize": "typography.fontSize.lg" + } + } + }, + "card": { + "base": { + "background": "theme.background.primary", + "borderRadius": "borderRadius.lg", + "padding": "spacing.6", + "boxShadow": "shadows.md" + } + }, + "input": { + "base": { + "padding": "spacing.3 spacing.4", + "borderRadius": "borderRadius.md", + "border": "1px solid", + "borderColor": "theme.border", + "fontSize": "typography.fontSize.base", + "focus": { + "borderColor": "colors.primary.500", + "outline": "none", + "boxShadow": "0 0 0 3px rgba(14, 165, 233, 0.1)" + } + } + } + } +} diff --git a/schemas/package-schemas/examples/advanced-features/types/advanced.json b/schemas/package-schemas/examples/advanced-features/types/advanced.json new file mode 100644 index 000000000..1cf151a24 --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/types/advanced.json @@ -0,0 +1,228 @@ +{ + "$schema": "https://metabuilder.dev/schemas/json-script-types.schema.json", + "schemaVersion": "2.0.0", + "package": "advanced-features", + "description": "Advanced TypeScript type definitions with generics and utilities", + "types": [ + { + "id": "paginated_response", + "name": "PaginatedResponse", + "kind": "generic", + "exported": true, + "description": "Generic paginated response wrapper", + "typeParameters": ["T"], + "properties": { + "data": { + "type": "T[]", + "required": true, + "description": "Array of items" + }, + "pagination": { + "type": "PaginationInfo", + "required": true, + "description": "Pagination metadata" + } + } + }, + { + "id": "pagination_info", + "name": "PaginationInfo", + "kind": "object", + "exported": true, + "properties": { + "page": { + "type": "number", + "required": true + }, + "limit": { + "type": "number", + "required": true + }, + "total": { + "type": "number", + "required": true + }, + "totalPages": { + "type": "number", + "required": true + }, + "hasNext": { + "type": "boolean", + "required": true + }, + "hasPrev": { + "type": "boolean", + "required": true + } + } + }, + { + "id": "order_list_response", + "name": "OrderListResponse", + "kind": "alias", + "exported": true, + "description": "Paginated order list response", + "aliasOf": "PaginatedResponse" + }, + { + "id": "api_response", + "name": "ApiResponse", + "kind": "generic", + "exported": true, + "description": "Generic API response wrapper", + "typeParameters": ["T"], + "properties": { + "success": { + "type": "boolean", + "required": true + }, + "data": { + "type": "T", + "required": false + }, + "error": { + "type": "ApiError", + "required": false + }, + "meta": { + "type": "Record", + "required": false + } + } + }, + { + "id": "api_error", + "name": "ApiError", + "kind": "object", + "exported": true, + "properties": { + "code": { + "type": "string", + "required": true + }, + "message": { + "type": "string", + "required": true + }, + "details": { + "type": "Record", + "required": false + }, + "timestamp": { + "type": "string", + "required": true + } + } + }, + { + "id": "partial_order", + "name": "PartialOrder", + "kind": "utility", + "exported": true, + "description": "Partial Order type for updates", + "utility": { + "type": "Partial", + "targetType": "Order" + } + }, + { + "id": "readonly_order", + "name": "ReadonlyOrder", + "kind": "utility", + "exported": true, + "description": "Readonly Order type", + "utility": { + "type": "Readonly", + "targetType": "Order" + } + }, + { + "id": "order_keys", + "name": "OrderKeys", + "kind": "utility", + "exported": true, + "description": "Union of Order property keys", + "utility": { + "type": "keyof", + "targetType": "Order" + } + }, + { + "id": "result_type", + "name": "Result", + "kind": "generic", + "exported": true, + "description": "Result type for operations that can fail", + "typeParameters": ["T", "E = Error"], + "union": [ + { + "kind": "object", + "properties": { + "ok": { "type": "true", "required": true }, + "value": { "type": "T", "required": true } + } + }, + { + "kind": "object", + "properties": { + "ok": { "type": "false", "required": true }, + "error": { "type": "E", "required": true } + } + } + ] + }, + { + "id": "async_operation", + "name": "AsyncOperation", + "kind": "generic", + "exported": true, + "description": "Async operation with loading and error states", + "typeParameters": ["T"], + "union": [ + { + "kind": "object", + "properties": { + "status": { "type": "'idle'", "required": true }, + "data": { "type": "null", "required": true } + } + }, + { + "kind": "object", + "properties": { + "status": { "type": "'loading'", "required": true }, + "data": { "type": "null", "required": true } + } + }, + { + "kind": "object", + "properties": { + "status": { "type": "'success'", "required": true }, + "data": { "type": "T", "required": true } + } + }, + { + "kind": "object", + "properties": { + "status": { "type": "'error'", "required": true }, + "data": { "type": "null", "required": true }, + "error": { "type": "Error", "required": true } + } + } + ] + } + ], + "exports": { + "types": [ + "PaginatedResponse", + "PaginationInfo", + "OrderListResponse", + "ApiResponse", + "ApiError", + "PartialOrder", + "ReadonlyOrder", + "OrderKeys", + "Result", + "AsyncOperation" + ] + } +} diff --git a/schemas/package-schemas/examples/advanced-features/validation/complex.json b/schemas/package-schemas/examples/advanced-features/validation/complex.json new file mode 100644 index 000000000..1608f2daa --- /dev/null +++ b/schemas/package-schemas/examples/advanced-features/validation/complex.json @@ -0,0 +1,345 @@ +{ + "$schema": "https://metabuilder.dev/schemas/json-script-validation.schema.json", + "schemaVersion": "2.0.0", + "package": "advanced-features", + "description": "Advanced validation functions with custom logic", + "patterns": { + "orderNumber": "^ORD-[0-9]{4}-[0-9]{6}$", + "trackingNumber": "^[A-Z0-9]{10,20}$", + "currencyCode": "^[A-Z]{3}$", + "postalCode": "^[0-9]{5}(-[0-9]{4})?$" + }, + "validators": [ + { + "id": "validate_order_total", + "name": "validateOrderTotal", + "exported": true, + "description": "Validate that order total matches sum of items", + "params": [ + { + "name": "order", + "type": "Order", + "required": true + } + ], + "returnType": "ValidationResult", + "body": [ + { + "type": "variable", + "name": "itemsTotal", + "value": { + "type": "expression", + "expression": "order.items.reduce((sum, item) => sum + item.subtotal, 0)" + } + }, + { + "type": "conditional", + "condition": { + "type": "comparison", + "operator": "!==", + "left": "order.totalAmount", + "right": "itemsTotal" + }, + "then": [ + { + "type": "return", + "value": { + "valid": false, + "errors": [ + { + "field": "totalAmount", + "message": "Total amount does not match sum of items", + "code": "INVALID_TOTAL" + } + ] + } + } + ] + }, + { + "type": "return", + "value": { + "valid": true + } + } + ] + }, + { + "id": "validate_shipping_address", + "name": "validateShippingAddress", + "exported": true, + "description": "Validate shipping address completeness", + "params": [ + { + "name": "address", + "type": "Address", + "required": true + } + ], + "returnType": "ValidationResult", + "body": [ + { + "type": "variable", + "name": "errors", + "value": [] + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "!address.street || address.street.trim().length === 0" + }, + "then": [ + { + "type": "expression", + "expression": "errors.push({ field: 'street', message: 'Street is required', code: 'REQUIRED' })" + } + ] + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "!address.city || address.city.trim().length === 0" + }, + "then": [ + { + "type": "expression", + "expression": "errors.push({ field: 'city', message: 'City is required', code: 'REQUIRED' })" + } + ] + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "!address.postalCode || !/^[0-9]{5}(-[0-9]{4})?$/.test(address.postalCode)" + }, + "then": [ + { + "type": "expression", + "expression": "errors.push({ field: 'postalCode', message: 'Invalid postal code', code: 'INVALID_FORMAT' })" + } + ] + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "!address.country || address.country.length !== 2" + }, + "then": [ + { + "type": "expression", + "expression": "errors.push({ field: 'country', message: 'Invalid country code', code: 'INVALID_FORMAT' })" + } + ] + }, + { + "type": "return", + "value": { + "type": "ternary", + "condition": "errors.length === 0", + "ifTrue": { "valid": true }, + "ifFalse": { "valid": false, "errors": "errors" } + } + } + ] + }, + { + "id": "validate_inventory", + "name": "validateInventory", + "exported": true, + "description": "Validate product inventory availability", + "async": true, + "params": [ + { + "name": "items", + "type": "OrderItem[]", + "required": true + } + ], + "returnType": "Promise", + "body": [ + { + "type": "variable", + "name": "errors", + "value": [] + }, + { + "type": "for", + "iterator": "item", + "iterable": "items", + "body": [ + { + "type": "variable", + "name": "stock", + "value": { + "type": "await", + "expression": "inventory.getStock(item.productId)" + } + }, + { + "type": "conditional", + "condition": { + "type": "comparison", + "operator": "<", + "left": "stock.available", + "right": "item.quantity" + }, + "then": [ + { + "type": "expression", + "expression": "errors.push({ field: `items.${item.productId}`, message: `Insufficient stock. Available: ${stock.available}, Requested: ${item.quantity}`, code: 'INSUFFICIENT_STOCK' })" + } + ] + } + ] + }, + { + "type": "return", + "value": { + "type": "ternary", + "condition": "errors.length === 0", + "ifTrue": { "valid": true }, + "ifFalse": { "valid": false, "errors": "errors" } + } + } + ] + }, + { + "id": "validate_credit_card", + "name": "validateCreditCard", + "exported": true, + "description": "Validate credit card using Luhn algorithm", + "params": [ + { + "name": "cardNumber", + "type": "string", + "required": true + } + ], + "returnType": "boolean", + "body": [ + { + "type": "comment", + "text": "Remove all non-digit characters" + }, + { + "type": "variable", + "name": "digits", + "value": { + "type": "expression", + "expression": "cardNumber.replace(/\\D/g, '')" + } + }, + { + "type": "conditional", + "condition": { + "type": "expression", + "expression": "digits.length < 13 || digits.length > 19" + }, + "then": [ + { + "type": "return", + "value": false + } + ] + }, + { + "type": "comment", + "text": "Luhn algorithm implementation" + }, + { + "type": "variable", + "name": "sum", + "value": 0 + }, + { + "type": "variable", + "name": "isEven", + "value": false + }, + { + "type": "for", + "iterator": "i", + "start": { + "type": "expression", + "expression": "digits.length - 1" + }, + "condition": { + "type": "comparison", + "operator": ">=", + "left": "i", + "right": 0 + }, + "increment": -1, + "body": [ + { + "type": "variable", + "name": "digit", + "value": { + "type": "expression", + "expression": "parseInt(digits[i], 10)" + } + }, + { + "type": "conditional", + "condition": "isEven", + "then": [ + { + "type": "expression", + "expression": "digit *= 2" + }, + { + "type": "conditional", + "condition": { + "type": "comparison", + "operator": ">", + "left": "digit", + "right": 9 + }, + "then": [ + { + "type": "expression", + "expression": "digit -= 9" + } + ] + } + ] + }, + { + "type": "expression", + "expression": "sum += digit" + }, + { + "type": "expression", + "expression": "isEven = !isEven" + } + ] + }, + { + "type": "return", + "value": { + "type": "expression", + "expression": "sum % 10 === 0" + } + } + ] + } + ], + "exports": { + "functions": [ + "validateOrderTotal", + "validateShippingAddress", + "validateInventory", + "validateCreditCard" + ], + "patterns": [ + "orderNumber", + "trackingNumber", + "currencyCode", + "postalCode" + ] + } +} diff --git a/schemas/package-schemas/examples/complete-package/config/settings.json b/schemas/package-schemas/examples/complete-package/config/settings.json new file mode 100644 index 000000000..3c81cdfe5 --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/config/settings.json @@ -0,0 +1,96 @@ +{ + "$schema": "https://metabuilder.dev/schemas/config.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Configuration for complete example package", + "environments": ["development", "test", "production"], + "variables": [ + { + "name": "APP_NAME", + "type": "string", + "description": "Application name", + "required": true, + "default": "Complete Example App", + "example": "My Application" + }, + { + "name": "PORT", + "type": "number", + "description": "Server port", + "required": false, + "default": 3000, + "min": 1, + "max": 65535 + }, + { + "name": "LOG_LEVEL", + "type": "enum", + "description": "Logging level", + "required": false, + "default": "info", + "enum": ["error", "warn", "info", "debug"] + }, + { + "name": "DATABASE_URL", + "type": "url", + "description": "Database connection URL", + "required": true, + "sensitive": true, + "example": "postgresql://user:pass@localhost:5432/db" + }, + { + "name": "ENABLE_ANALYTICS", + "type": "boolean", + "description": "Enable analytics tracking", + "required": false, + "default": false + } + ], + "featureFlags": [ + { + "name": "new-dashboard", + "description": "New dashboard UI", + "enabled": false, + "environments": { + "development": { + "enabled": true + }, + "production": { + "enabled": false, + "rollout": { + "percentage": 10 + } + } + } + }, + { + "name": "beta-features", + "description": "Beta features access", + "enabled": false, + "rules": [ + { + "condition": "user.role === 'beta-tester'", + "enabled": true, + "description": "Enable for beta testers" + } + ] + } + ], + "secrets": [ + { + "name": "API_KEY", + "description": "External API key", + "provider": "env", + "required": true + }, + { + "name": "JWT_SECRET", + "description": "JWT signing secret", + "provider": "env", + "required": true, + "rotation": { + "enabled": false + } + } + ] +} diff --git a/schemas/package-schemas/examples/complete-package/events/handlers.json b/schemas/package-schemas/examples/complete-package/events/handlers.json new file mode 100644 index 000000000..ed244a20b --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/events/handlers.json @@ -0,0 +1,82 @@ +{ + "$schema": "https://metabuilder.dev/schemas/events.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Event handlers for complete example package", + "events": [ + { + "id": "user_created", + "name": "user.created", + "version": "1.0.0", + "description": "Fired when a new user is created", + "channel": "users", + "payload": "User", + "metadata": { + "timestamp": true, + "correlationId": true, + "userId": true + }, + "priority": "normal", + "retention": { + "enabled": true, + "ttl": 2592000 + } + }, + { + "id": "user_updated", + "name": "user.updated", + "version": "1.0.0", + "description": "Fired when a user is updated", + "channel": "users", + "payload": "User", + "priority": "normal" + }, + { + "id": "user_deleted", + "name": "user.deleted", + "version": "1.0.0", + "description": "Fired when a user is deleted", + "channel": "users", + "payload": { + "type": "object", + "properties": { + "id": { "type": "string" }, + "email": { "type": "string" } + }, + "required": ["id", "email"] + }, + "priority": "high" + } + ], + "subscribers": [ + { + "id": "send_welcome_email", + "name": "Send Welcome Email", + "description": "Send welcome email when user is created", + "events": ["user.created"], + "handler": "handlers.sendWelcomeEmail", + "async": true, + "retry": { + "enabled": true, + "maxAttempts": 3, + "backoff": "exponential" + } + }, + { + "id": "log_user_changes", + "name": "Log User Changes", + "description": "Log all user-related events", + "events": ["user.*"], + "handler": "handlers.logUserEvent", + "async": true + } + ], + "channels": [ + { + "name": "users", + "description": "User-related events channel", + "type": "topic", + "persistent": true + } + ] +} diff --git a/schemas/package-schemas/examples/complete-package/forms/user-form.json b/schemas/package-schemas/examples/complete-package/forms/user-form.json new file mode 100644 index 000000000..a5ba52c82 --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/forms/user-form.json @@ -0,0 +1,149 @@ +{ + "$schema": "https://metabuilder.dev/schemas/forms.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Dynamic forms for complete example package", + "forms": [ + { + "id": "user_registration", + "name": "UserRegistration", + "title": "Create Account", + "description": "User registration form", + "layout": "vertical", + "fields": [ + { + "name": "email", + "type": "email", + "label": "Email Address", + "placeholder": "you@example.com", + "required": true, + "validation": { + "email": true, + "required": "Email is required", + "messages": { + "email": "Please enter a valid email address" + } + } + }, + { + "name": "password", + "type": "password", + "label": "Password", + "placeholder": "Enter password", + "required": true, + "helpText": "Password must be at least 8 characters", + "validation": { + "required": true, + "minLength": 8, + "pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).+$", + "messages": { + "minLength": "Password must be at least 8 characters", + "pattern": "Password must contain uppercase, lowercase, and numbers" + } + } + }, + { + "name": "confirmPassword", + "type": "password", + "label": "Confirm Password", + "placeholder": "Re-enter password", + "required": true, + "validation": { + "required": true, + "custom": "validators.matchesPassword" + } + }, + { + "name": "name", + "type": "text", + "label": "Full Name", + "placeholder": "John Doe", + "required": true, + "validation": { + "required": true, + "minLength": 2, + "maxLength": 100 + } + }, + { + "name": "role", + "type": "select", + "label": "Role", + "required": true, + "defaultValue": "user", + "options": [ + { "value": "user", "label": "User" }, + { "value": "moderator", "label": "Moderator" } + ] + }, + { + "name": "newsletter", + "type": "checkbox", + "label": "Subscribe to newsletter", + "defaultValue": false + } + ], + "validation": { + "validateOnBlur": true, + "validateOnChange": false, + "validateOnSubmit": true + }, + "onSubmit": "handlers.registerUser" + }, + { + "id": "user_profile", + "name": "UserProfile", + "title": "Edit Profile", + "description": "User profile editing form", + "layout": "grid", + "columns": 2, + "fields": [ + { + "name": "name", + "type": "text", + "label": "Full Name", + "required": true, + "grid": { "column": 2 } + }, + { + "name": "email", + "type": "email", + "label": "Email", + "required": true, + "readonly": true, + "grid": { "column": 2 } + }, + { + "name": "phone", + "type": "tel", + "label": "Phone Number", + "placeholder": "+1 (555) 000-0000", + "grid": { "column": 1 } + }, + { + "name": "timezone", + "type": "select", + "label": "Timezone", + "options": [ + { "value": "America/New_York", "label": "Eastern Time" }, + { "value": "America/Chicago", "label": "Central Time" }, + { "value": "America/Denver", "label": "Mountain Time" }, + { "value": "America/Los_Angeles", "label": "Pacific Time" } + ], + "grid": { "column": 1 } + }, + { + "name": "bio", + "type": "textarea", + "label": "Bio", + "placeholder": "Tell us about yourself", + "validation": { + "maxLength": 500 + }, + "grid": { "column": 2 } + } + ], + "onSubmit": "handlers.updateProfile" + } + ] +} diff --git a/schemas/package-schemas/examples/complete-package/jobs/tasks.json b/schemas/package-schemas/examples/complete-package/jobs/tasks.json new file mode 100644 index 000000000..e98a971f5 --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/jobs/tasks.json @@ -0,0 +1,86 @@ +{ + "$schema": "https://metabuilder.dev/schemas/jobs.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Background jobs for complete example package", + "jobs": [ + { + "id": "cleanup_old_users", + "name": "Cleanup Old Users", + "description": "Remove inactive users older than 1 year", + "handler": "jobs.cleanupOldUsers", + "queue": "maintenance", + "schedule": "0 2 * * *", + "enabled": true, + "priority": 0, + "timeout": 300000, + "retry": { + "enabled": true, + "maxAttempts": 3, + "backoff": "exponential" + } + }, + { + "id": "send_daily_digest", + "name": "Send Daily Digest", + "description": "Send daily digest emails to users", + "handler": "jobs.sendDailyDigest", + "queue": "emails", + "schedule": { + "cron": "0 9 * * *", + "timezone": "America/New_York" + }, + "enabled": true, + "notifications": { + "onFailure": ["admin@example.com"], + "channels": ["email"] + } + }, + { + "id": "process_analytics", + "name": "Process Analytics", + "description": "Process and aggregate analytics data", + "handler": "jobs.processAnalytics", + "queue": "default", + "schedule": { + "interval": 3600000 + }, + "enabled": true, + "concurrency": 1 + }, + { + "id": "backup_database", + "name": "Backup Database", + "description": "Create database backup", + "handler": "jobs.backupDatabase", + "queue": "maintenance", + "schedule": "0 0 * * *", + "enabled": true, + "priority": 10, + "timeout": 600000 + } + ], + "queues": [ + { + "name": "default", + "description": "Default job queue", + "concurrency": 5, + "priority": false + }, + { + "name": "emails", + "description": "Email sending queue", + "concurrency": 3, + "rateLimit": { + "max": 100, + "window": 60000 + } + }, + { + "name": "maintenance", + "description": "Maintenance tasks queue", + "concurrency": 1, + "priority": true + } + ] +} diff --git a/schemas/package-schemas/examples/complete-package/migrations/001_initial.json b/schemas/package-schemas/examples/complete-package/migrations/001_initial.json new file mode 100644 index 000000000..5b477e265 --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/migrations/001_initial.json @@ -0,0 +1,176 @@ +{ + "$schema": "https://metabuilder.dev/schemas/migrations.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Database migrations for complete example package", + "migrations": [ + { + "version": "001", + "timestamp": "2024-01-01T00:00:00Z", + "description": "Create users table", + "author": "admin", + "up": [ + { + "type": "createTable", + "table": "users", + "columns": [ + { + "name": "id", + "type": "uuid", + "primary": true, + "nullable": false + }, + { + "name": "email", + "type": "string", + "length": 255, + "nullable": false, + "unique": true + }, + { + "name": "name", + "type": "string", + "length": 255, + "nullable": false + }, + { + "name": "password_hash", + "type": "string", + "length": 255, + "nullable": false + }, + { + "name": "role", + "type": "enum", + "enum": ["user", "admin", "moderator"], + "nullable": false, + "default": "user" + }, + { + "name": "is_active", + "type": "boolean", + "nullable": false, + "default": true + }, + { + "name": "created_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "updated_at", + "type": "timestamp", + "nullable": false + } + ], + "indexes": [ + { + "name": "idx_users_email", + "columns": ["email"], + "unique": true + }, + { + "name": "idx_users_role", + "columns": ["role"] + } + ] + } + ], + "down": [ + { + "type": "dropTable", + "table": "users" + } + ], + "transactional": true + }, + { + "version": "002", + "timestamp": "2024-01-02T00:00:00Z", + "description": "Create content table", + "author": "admin", + "dependencies": ["001"], + "up": [ + { + "type": "createTable", + "table": "content", + "columns": [ + { + "name": "id", + "type": "uuid", + "primary": true, + "nullable": false + }, + { + "name": "title", + "type": "string", + "length": 255, + "nullable": false + }, + { + "name": "body", + "type": "text", + "nullable": true + }, + { + "name": "author_id", + "type": "uuid", + "nullable": false + }, + { + "name": "status", + "type": "enum", + "enum": ["draft", "published", "archived"], + "nullable": false, + "default": "draft" + }, + { + "name": "created_at", + "type": "timestamp", + "nullable": false + }, + { + "name": "updated_at", + "type": "timestamp", + "nullable": false + } + ], + "foreignKeys": [ + { + "name": "fk_content_author", + "columns": ["author_id"], + "references": { + "table": "users", + "columns": ["id"] + }, + "onDelete": "CASCADE" + } + ], + "indexes": [ + { + "name": "idx_content_author", + "columns": ["author_id"] + }, + { + "name": "idx_content_status", + "columns": ["status"] + } + ] + } + ], + "down": [ + { + "type": "dropTable", + "table": "content" + } + ], + "transactional": true + } + ], + "config": { + "tableName": "migrations", + "autoRun": false, + "validateChecksums": true, + "allowOutOfOrder": false + } +} diff --git a/schemas/package-schemas/examples/complete-package/permissions/rbac.json b/schemas/package-schemas/examples/complete-package/permissions/rbac.json new file mode 100644 index 000000000..d95de00df --- /dev/null +++ b/schemas/package-schemas/examples/complete-package/permissions/rbac.json @@ -0,0 +1,157 @@ +{ + "$schema": "https://metabuilder.dev/schemas/permissions.schema.json", + "schemaVersion": "1.0.0", + "package": "complete-example", + "description": "Role-based access control for complete example package", + "roles": [ + { + "id": "admin", + "name": "Administrator", + "description": "Full system access", + "level": 100, + "permissions": ["*"], + "system": true + }, + { + "id": "user", + "name": "User", + "description": "Standard user access", + "level": 10, + "permissions": ["users.read", "users.update.own", "content.create", "content.read"], + "default": true + }, + { + "id": "moderator", + "name": "Moderator", + "description": "Content moderation access", + "level": 50, + "permissions": ["users.read", "content.*", "reports.manage"], + "inherits": ["user"] + } + ], + "permissions": [ + { + "id": "users.read", + "name": "Read Users", + "description": "View user information", + "resource": "users", + "action": "read", + "scope": "global" + }, + { + "id": "users.update.own", + "name": "Update Own Profile", + "description": "Update own user profile", + "resource": "users", + "action": "update", + "scope": "user", + "conditions": [ + { + "type": "ownership", + "attribute": "userId", + "operator": "equals", + "value": "currentUser.id" + } + ] + }, + { + "id": "content.create", + "name": "Create Content", + "description": "Create new content", + "resource": "content", + "action": "create", + "scope": "global" + }, + { + "id": "content.read", + "name": "Read Content", + "description": "View content", + "resource": "content", + "action": "read", + "scope": "global" + }, + { + "id": "content.update", + "name": "Update Content", + "description": "Edit content", + "resource": "content", + "action": "update", + "scope": "global" + }, + { + "id": "content.delete", + "name": "Delete Content", + "description": "Delete content", + "resource": "content", + "action": "delete", + "scope": "global" + } + ], + "resources": [ + { + "id": "users", + "name": "Users", + "type": "entity", + "description": "User resources", + "actions": ["create", "read", "update", "delete"], + "ownership": { + "enabled": true, + "field": "userId", + "allowedActions": ["read", "update"] + } + }, + { + "id": "content", + "name": "Content", + "type": "entity", + "description": "Content resources", + "actions": ["create", "read", "update", "delete", "manage"], + "ownership": { + "enabled": true, + "field": "authorId", + "allowedActions": ["read", "update", "delete"] + } + } + ], + "policies": [ + { + "id": "business_hours_policy", + "name": "Business Hours Access", + "description": "Restrict sensitive operations to business hours", + "effect": "deny", + "priority": 10, + "rules": [ + { + "resources": ["users.*"], + "actions": ["delete"], + "conditions": [ + { + "type": "time", + "timeRange": { + "start": "09:00", + "end": "17:00", + "timezone": "America/New_York", + "days": ["monday", "tuesday", "wednesday", "thursday", "friday"] + } + } + ] + } + ], + "enabled": false + } + ], + "config": { + "enabled": true, + "model": "RBAC", + "defaultDeny": true, + "caching": { + "enabled": true, + "ttl": 300 + }, + "audit": { + "enabled": true, + "logDenials": true, + "logGrants": false + } + } +} diff --git a/schemas/package-schemas/examples/minimal-package/api/index.json b/schemas/package-schemas/examples/minimal-package/api/index.json new file mode 100644 index 000000000..5b71d78f8 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/api/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/api.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "endpoints": [] +} diff --git a/schemas/package-schemas/examples/minimal-package/components/index.json b/schemas/package-schemas/examples/minimal-package/components/index.json new file mode 100644 index 000000000..2d8a0be1a --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/components/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/components.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "components": [] +} diff --git a/schemas/package-schemas/examples/minimal-package/config/index.json b/schemas/package-schemas/examples/minimal-package/config/index.json new file mode 100644 index 000000000..780e2f711 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/config/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/config.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/entities/index.json b/schemas/package-schemas/examples/minimal-package/entities/index.json new file mode 100644 index 000000000..c430894e5 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/entities/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/entities.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "entities": [] +} diff --git a/schemas/package-schemas/examples/minimal-package/events/index.json b/schemas/package-schemas/examples/minimal-package/events/index.json new file mode 100644 index 000000000..a8c4335d2 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/events/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/events.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/forms/index.json b/schemas/package-schemas/examples/minimal-package/forms/index.json new file mode 100644 index 000000000..7fb0eb1a1 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/forms/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/forms.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/jobs/index.json b/schemas/package-schemas/examples/minimal-package/jobs/index.json new file mode 100644 index 000000000..02f15b004 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/jobs/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/jobs.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/migrations/index.json b/schemas/package-schemas/examples/minimal-package/migrations/index.json new file mode 100644 index 000000000..1b44d960d --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/migrations/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/migrations.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/permissions/index.json b/schemas/package-schemas/examples/minimal-package/permissions/index.json new file mode 100644 index 000000000..83c455cf3 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/permissions/index.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://metabuilder.dev/schemas/permissions.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example" +} diff --git a/schemas/package-schemas/examples/minimal-package/scripts/index.json b/schemas/package-schemas/examples/minimal-package/scripts/index.json new file mode 100644 index 000000000..fc8d17875 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/scripts/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/script.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "scripts": [] +} diff --git a/schemas/package-schemas/examples/minimal-package/styles/index.json b/schemas/package-schemas/examples/minimal-package/styles/index.json new file mode 100644 index 000000000..c001754ad --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/styles/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/styles.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "tokens": {} +} diff --git a/schemas/package-schemas/examples/minimal-package/types/index.json b/schemas/package-schemas/examples/minimal-package/types/index.json new file mode 100644 index 000000000..880bcce97 --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/types/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/json-script-types.schema.json", + "schemaVersion": "2.0.0", + "package": "minimal-example", + "types": [] +} diff --git a/schemas/package-schemas/examples/minimal-package/validation/index.json b/schemas/package-schemas/examples/minimal-package/validation/index.json new file mode 100644 index 000000000..7c04ea7de --- /dev/null +++ b/schemas/package-schemas/examples/minimal-package/validation/index.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://metabuilder.dev/schemas/validation.schema.json", + "schemaVersion": "1.0.0", + "package": "minimal-example", + "validators": [] +}