@mindmakr/gs-websdk
Version:
Web SDK for Guru SaaS System - Complete JavaScript/TypeScript SDK for building applications with dynamic schema management
362 lines (361 loc) • 8.94 kB
TypeScript
/**
* Core types and interfaces for the Guru SaaS Web SDK
*/
export interface User {
id: string;
email: string;
role: string;
tenant_id?: string;
name?: string;
created_at: string;
updated_at: string;
last_login?: string;
permissions?: string[];
roles?: (Role | string)[];
}
export interface AuthTokens {
token: string;
refreshToken: string;
expiresIn: number;
tokenType: string;
}
export interface Permission {
id: string;
name: string;
description?: string;
resource: string;
action: string;
}
export interface Role {
id: string;
name: string;
description?: string;
tenant_id?: string;
is_system_role?: boolean;
permissions?: Permission[];
}
export interface Tenant {
id: string;
name: string;
domain?: string;
subdomain?: string;
custom_domain?: string;
system_config_code?: string;
created_at: string;
updated_at: string;
settings?: Record<string, unknown>;
current?: boolean;
}
export interface SchemaTemplate {
id: number;
name: string;
code: string;
description?: string;
category: string;
schema_definition: Record<string, any>;
version: string;
is_system: boolean;
is_active: boolean;
created_by?: string;
tenant_id?: string;
created_at: string;
updated_at: string;
path?: string;
parent_path?: string;
depth?: number;
base_template_id?: number;
composition_rules?: Record<string, any>;
enhanced_properties?: Record<string, any>;
status?: 'draft' | 'published' | 'archived';
published_at?: string;
published_by?: string;
expires_at?: string;
}
export interface SchemaInstance {
id: number;
entity_type: string;
entity_id: number;
schema_template_id?: number;
instance_data: Record<string, any>;
overrides: Record<string, any>;
is_active: boolean;
tenant_id?: string;
created_at: string;
updated_at: string;
template?: {
name: string;
code: string;
schema_definition: Record<string, any>;
version: string;
category: string;
};
}
export interface SchemaTranslation {
id: number;
schema_template_id: number;
language_code: string;
field_path: string;
translated_value: string;
tenant_id?: string;
created_at: string;
updated_at: string;
}
export interface Category {
id: number;
code: string;
name: string;
description?: string;
parent_id?: number;
level: number;
sort_order: number;
is_active: boolean;
is_system: boolean;
created_at: string;
updated_at: string;
children?: Category[];
template_count?: number;
}
export interface SystemConfig {
id: number;
code: string;
name: Record<string, string>;
description?: Record<string, string>;
settings: Record<string, any>;
created_at: string;
updated_at: string;
}
export interface ValidationRule {
type: string;
value?: any;
message: Record<string, string>;
}
export interface FieldEnhancement {
icon?: string;
placeholder?: Record<string, string>;
helpText?: Record<string, string>;
styling?: {
variant?: 'default' | 'outline' | 'ghost' | 'destructive';
size?: 'sm' | 'md' | 'lg';
className?: string;
};
validation?: ValidationRule[];
conditional?: {
field: string;
operator: string;
value: any;
};
}
export interface AIFieldSuggestion {
name: string;
type: string;
title: Record<string, string>;
description: Record<string, string>;
confidence: number;
reasoning: string;
alternatives: string[];
validation: ValidationRule[];
enhancement: FieldEnhancement;
}
export interface FieldType {
id: string;
name: string;
jsonType: string;
category: 'basic' | 'advanced' | 'layout' | 'selection';
defaultProperties: Record<string, any>;
}
export interface SchemaField {
id: string;
key: string;
type: string;
properties: Record<string, any>;
required: boolean;
order: number;
layout?: {
width?: 'quarter' | 'half' | 'three-quarter' | 'full';
height?: 'small' | 'medium' | 'large';
group?: string;
className?: string;
conditional?: {
field: string;
value: any;
operator: 'equals' | 'not_equals' | 'contains';
};
};
}
export interface CompositionRules {
inherit?: string[];
override?: Record<string, any>;
extend?: Array<{
key: string;
type: string;
[key: string]: any;
}>;
exclude?: string[];
rename?: Record<string, string>;
}
export interface FieldConflict {
fieldName: string;
conflictType: 'type_mismatch' | 'validation_conflict' | 'enhancement_conflict' | 'property_conflict';
baseValue: any;
childValue: any;
resolution: 'parent' | 'child' | 'merge' | 'prompt';
resolvedValue: any;
suggestion?: string;
}
export interface CompositionPreview {
composedSchema: any;
fieldCount: number;
conflicts: FieldConflict[];
warnings: string[];
}
export interface PaginatedResponse<T> {
data: T[];
pagination: {
total: number;
page: number;
limit: number;
totalPages: number;
};
}
export interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
export interface ValidationResponse {
isValid: boolean;
errors: string[];
warnings: string[];
}
export interface SDKConfig {
baseUrl?: string;
authUrl?: string;
globalDataUrl?: string;
aiServiceUrl?: string;
notificationUrl?: string;
timeout?: number;
retryAttempts?: number;
debug?: boolean;
defaultTenant?: string;
autoRefreshToken?: boolean;
}
export interface RequestConfig {
timeout?: number;
retries?: number;
headers?: Record<string, string>;
tenantId?: string;
}
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
export type RequiredKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
export type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export interface PaginationParams {
page?: number;
limit?: number;
}
export interface UserFilters {
email?: string;
role?: string;
tenant_id?: string;
search?: string;
}
export interface SchemaFilters {
category?: string;
is_active?: boolean;
is_system?: boolean;
search?: string;
path?: string;
tenant_id?: string;
}
export interface SchemaInstanceFilters {
entity_type?: string;
template_code?: string;
is_active?: boolean;
search?: string;
tenant_id?: string;
}
export declare class SDKError extends Error {
readonly code: string;
readonly statusCode?: number;
readonly details?: any;
constructor(message: string, code?: string, statusCode?: number, details?: any);
}
export declare class AuthenticationError extends SDKError {
constructor(message?: string, details?: any);
}
export declare class PermissionError extends SDKError {
constructor(message?: string, details?: any);
}
export declare class ValidationError extends SDKError {
constructor(message?: string, details?: any);
}
export declare class NetworkError extends SDKError {
constructor(message?: string, details?: any);
}
export interface AnalyzeContextRequest {
context: string;
type?: string;
}
export interface AnalyzeContextResponse {
success: boolean;
data: any;
}
export interface SuggestFieldNameRequest {
context: string;
existing_fields?: string[];
}
export interface SuggestFieldNameResponse {
success: boolean;
data: {
suggested_name: string;
};
}
export interface SuggestValidationRequest {
field_type: string;
context: string;
}
export interface SuggestValidationResponse {
success: boolean;
data: {
validation_rules: Record<string, any>;
};
}
export interface SuggestFieldTypeRequest {
context: string;
field_name?: string;
}
export interface SuggestFieldTypeResponse {
success: boolean;
data: {
suggested_type: string;
confidence?: number;
};
}
export interface SuggestFieldsRequest {
schema_context: string;
existing_fields?: any[];
requirements?: string;
}
export interface SuggestFieldsResponse {
success: boolean;
data: {
suggested_fields: any[];
};
}
export interface ExecuteFunctionRequest {
functionName: string;
parameters: Record<string, any>;
userId: string;
tenantId: string;
conversationId?: string;
requiresConfirmation?: boolean;
}
export interface ExecuteFunctionResponse {
success: boolean;
result?: any;
error?: string;
requiresConfirmation?: boolean;
confirmationMessage?: string;
}