@0xobelisk/react 1.2.0-pre.92 → 1.2.0-pre.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -106,13 +106,16 @@ function App() {
106
106
  packageId: '0x123...',
107
107
  metadata: contractMetadata,
108
108
  // Optional features
109
+ dubheSchemaId: '0xabc...', // Optional: Dubhe Schema ID
109
110
  dubheMetadata: dubheConfigMetadata, // Enables GraphQL + ECS
110
111
  credentials: {
111
112
  secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // ⚠️ LOCAL DEVELOPMENT ONLY // ⚠️ LOCAL DEVELOPMENT ONLY
112
113
  },
113
114
  endpoints: {
115
+ fullnodeUrls: ['https://fullnode.devnet.sui.io:443'], // Optional: Custom RPC endpoints
114
116
  graphql: process.env.NEXT_PUBLIC_GRAPHQL_URL,
115
- websocket: process.env.NEXT_PUBLIC_GRAPHQL_WS_URL
117
+ websocket: process.env.NEXT_PUBLIC_GRAPHQL_WS_URL,
118
+ grpc: 'http://localhost:8080' // Optional: Custom gRPC endpoint
116
119
  },
117
120
  options: {
118
121
  enableBatchOptimization: true,
@@ -468,6 +471,7 @@ function ErrorHandlingExample() {
468
471
  import type {
469
472
  NetworkType,
470
473
  DubheConfig,
474
+ ClientConfig, // Alias for DubheConfig (for consistency with @0xobelisk/client)
471
475
  DubheReturn,
472
476
  ContractReturn // Alias for DubheReturn
473
477
  } from '@0xobelisk/react/sui';
@@ -516,6 +520,7 @@ npm run format
516
520
  interface DubheReturn {
517
521
  contract: Dubhe; // Enhanced contract instance
518
522
  graphqlClient: DubheGraphqlClient | null; // GraphQL client (if enabled)
523
+ grpcClient: DubheGrpcClient; // gRPC client
519
524
  ecsWorld: DubheECSWorld | null; // ECS World (if enabled)
520
525
  metadata: SuiMoveNormalizedModules; // Contract metadata
521
526
  network: NetworkType; // Current network
@@ -527,6 +532,48 @@ interface DubheReturn {
527
532
  }
528
533
  ```
529
534
 
535
+ ### DubheConfig Interface
536
+
537
+ Configuration aligned with `@0xobelisk/client` for consistency:
538
+
539
+ ```typescript
540
+ interface DubheConfig {
541
+ // Required fields
542
+ network: NetworkType; // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
543
+ packageId: string; // Contract package ID
544
+ metadata: any; // Contract metadata (from dubhe schemagen)
545
+
546
+ // Optional fields
547
+ dubheSchemaId?: string; // Dubhe Schema ID for enhanced features
548
+ dubheMetadata?: any; // Dubhe metadata for GraphQL/ECS features
549
+
550
+ // Credentials
551
+ credentials?: {
552
+ secretKey?: string; // Private key (base64 or hex)
553
+ mnemonics?: string; // 12 or 24 word mnemonic phrase
554
+ };
555
+
556
+ // Endpoints
557
+ endpoints?: {
558
+ fullnodeUrls?: string[]; // Full node RPC URLs (multiple for redundancy)
559
+ graphql?: string; // GraphQL endpoint (default: http://localhost:4000/graphql)
560
+ websocket?: string; // WebSocket endpoint (default: ws://localhost:4000/graphql)
561
+ grpc?: string; // gRPC endpoint (default: http://localhost:8080)
562
+ };
563
+
564
+ // Options
565
+ options?: {
566
+ enableBatchOptimization?: boolean; // Default: true
567
+ cacheTimeout?: number; // Default: 5000 (ms)
568
+ debounceMs?: number; // Default: 100 (ms)
569
+ reconnectOnError?: boolean; // Default: true
570
+ };
571
+ }
572
+
573
+ // Type alias for consistency with @0xobelisk/client
574
+ type ClientConfig = DubheConfig;
575
+ ```
576
+
530
577
  ### Available Hooks
531
578
 
532
579
  - `useDubhe()` → `DubheReturn` - Complete Dubhe ecosystem
@@ -80,6 +80,22 @@ function validateConfig(config) {
80
80
  if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {
81
81
  errors.push("endpoints.websocket must be a valid URL");
82
82
  }
83
+ if (config.endpoints?.grpc && !isValidUrl(config.endpoints.grpc)) {
84
+ errors.push("endpoints.grpc must be a valid URL");
85
+ }
86
+ if (config.endpoints?.fullnodeUrls) {
87
+ if (!Array.isArray(config.endpoints.fullnodeUrls)) {
88
+ errors.push("endpoints.fullnodeUrls must be an array");
89
+ } else if (config.endpoints.fullnodeUrls.length === 0) {
90
+ errors.push("endpoints.fullnodeUrls cannot be empty if provided");
91
+ } else {
92
+ config.endpoints.fullnodeUrls.forEach((url, index) => {
93
+ if (!isValidUrl(url)) {
94
+ errors.push(`endpoints.fullnodeUrls[${index}] must be a valid URL: ${url}`);
95
+ }
96
+ });
97
+ }
98
+ }
83
99
  if (config.options?.cacheTimeout !== void 0 && (typeof config.options.cacheTimeout !== "number" || config.options.cacheTimeout < 0)) {
84
100
  errors.push("options.cacheTimeout must be a non-negative number");
85
101
  }
@@ -181,7 +197,9 @@ function DubheProvider({ config, children }) {
181
197
  networkType: finalConfig.network,
182
198
  packageId: finalConfig.packageId,
183
199
  metadata: finalConfig.metadata,
184
- secretKey: finalConfig.credentials?.secretKey
200
+ secretKey: finalConfig.credentials?.secretKey,
201
+ mnemonics: finalConfig.credentials?.mnemonics,
202
+ fullnodeUrls: finalConfig.endpoints?.fullnodeUrls
185
203
  });
186
204
  } catch (error) {
187
205
  console.error("Contract initialization failed:", error);
@@ -216,7 +234,7 @@ function DubheProvider({ config, children }) {
216
234
  try {
217
235
  console.log("Initializing gRPC client instance (one-time)");
218
236
  grpcClientRef.current = new DubheGrpcClient({
219
- baseUrl: finalConfig.endpoints?.grpc || "http://localhost:50051"
237
+ baseUrl: finalConfig.endpoints?.grpc || "http://localhost:8080"
220
238
  });
221
239
  hasInitializedGrpc.current = true;
222
240
  } catch (error) {
@@ -313,7 +331,8 @@ function DubheProvider({ config, children }) {
313
331
  packageId: finalConfig.packageId,
314
332
  metadata: finalConfig.metadata,
315
333
  secretKey: finalConfig.credentials?.secretKey,
316
- mnemonics: finalConfig.credentials?.mnemonics
334
+ mnemonics: finalConfig.credentials?.mnemonics,
335
+ fullnodeUrls: finalConfig.endpoints?.fullnodeUrls
317
336
  });
318
337
  }
319
338
  }, [
@@ -321,7 +340,8 @@ function DubheProvider({ config, children }) {
321
340
  finalConfig.packageId,
322
341
  finalConfig.metadata,
323
342
  finalConfig.credentials?.secretKey,
324
- finalConfig.credentials?.mnemonics
343
+ finalConfig.credentials?.mnemonics,
344
+ finalConfig.endpoints?.fullnodeUrls
325
345
  ]);
326
346
  useEffect(() => {
327
347
  if (graphqlClientRef.current) {
@@ -463,4 +483,4 @@ export {
463
483
  useDubheConfigUpdate2 as useDubheConfigUpdate,
464
484
  useContract
465
485
  };
466
- //# sourceMappingURL=chunk-YQUGWGOF.mjs.map
486
+ //# sourceMappingURL=chunk-Q5VWR7TU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sui/config.ts","../src/sui/utils.ts","../src/sui/provider.tsx","../src/sui/hooks.ts"],"sourcesContent":["/**\n * Configuration Management for Dubhe React Integration\n *\n * Features:\n * - Type-safe configuration interface\n * - Configuration validation and error handling\n * - Smart merging of defaults and explicit config\n * - No environment variable handling (developers should handle environment variables themselves)\n */\n\nimport { useMemo } from 'react';\nimport type { DubheConfig } from './types';\nimport { mergeConfigurations, validateConfig } from './utils';\n\n/**\n * Default configuration object with sensible defaults\n */\nexport const DEFAULT_CONFIG: Partial<DubheConfig> = {\n endpoints: {\n graphql: 'http://localhost:4000/graphql',\n websocket: 'ws://localhost:4000/graphql'\n },\n options: {\n enableBatchOptimization: true,\n cacheTimeout: 5000,\n debounceMs: 100,\n reconnectOnError: true\n }\n};\n\n/**\n * Configuration Hook: useDubheConfig\n *\n * Merges defaults with explicit configuration provided by the developer\n *\n * Note: Environment variables should be handled by the developer before passing to this hook\n *\n * @param config - Complete or partial configuration object\n * @returns Complete, validated DubheConfig\n *\n * @example\n * ```typescript\n * // Basic usage with explicit config\n * const config = useDubheConfig({\n * network: 'testnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // Handle env vars yourself\n * }\n * });\n *\n * // With helper function to handle environment variables\n * const getConfigFromEnv = () => ({\n * network: process.env.NEXT_PUBLIC_NETWORK as NetworkType,\n * packageId: process.env.NEXT_PUBLIC_PACKAGE_ID,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * });\n *\n * const config = useDubheConfig({\n * ...getConfigFromEnv(),\n * metadata: contractMetadata\n * });\n * ```\n */\nexport function useDubheConfig(config: Partial<DubheConfig>): DubheConfig {\n // Memoize the stringified config to detect actual changes\n const configKey = useMemo(() => {\n return JSON.stringify(config);\n }, [config]);\n\n return useMemo(() => {\n // Merge configurations: defaults -> user provided config\n const mergedConfig = mergeConfigurations(DEFAULT_CONFIG, config);\n\n // Validate the final configuration\n const validatedConfig = validateConfig(mergedConfig);\n\n // if (process.env.NODE_ENV === 'development') {\n // console.log('🔧 Dubhe Config:', {\n // ...validatedConfig,\n // credentials: validatedConfig.credentials?.secretKey ? '[REDACTED]' : undefined\n // });\n // }\n\n return validatedConfig;\n }, [configKey]);\n}\n","/**\n * Utility Functions for Dubhe Configuration Management\n *\n * Features:\n * - Configuration validation and error handling\n * - Smart configuration merging with proper type safety\n * - Type-safe configuration validation\n */\n\nimport type { DubheConfig } from './types';\n\n/**\n * Merge multiple configuration objects with proper deep merging\n * Later configurations override earlier ones\n *\n * @param baseConfig - Base configuration (usually defaults)\n * @param overrideConfig - Override configuration (user provided)\n * @returns Merged configuration\n */\nexport function mergeConfigurations(\n baseConfig: Partial<DubheConfig>,\n overrideConfig?: Partial<DubheConfig>\n): Partial<DubheConfig> {\n if (!overrideConfig) {\n return { ...baseConfig };\n }\n\n const result: Partial<DubheConfig> = { ...baseConfig };\n\n // Merge top-level properties\n Object.assign(result, overrideConfig);\n\n // Deep merge nested objects\n if (overrideConfig.credentials || baseConfig.credentials) {\n result.credentials = {\n ...baseConfig.credentials,\n ...overrideConfig.credentials\n };\n }\n\n if (overrideConfig.endpoints || baseConfig.endpoints) {\n result.endpoints = {\n ...baseConfig.endpoints,\n ...overrideConfig.endpoints\n };\n }\n\n if (overrideConfig.options || baseConfig.options) {\n result.options = {\n ...baseConfig.options,\n ...overrideConfig.options\n };\n }\n\n return result;\n}\n\n/**\n * Validate configuration and ensure required fields are present\n * Throws descriptive errors for missing required fields\n *\n * @param config - Configuration to validate\n * @returns Validated and typed configuration\n * @throws Error if required fields are missing or invalid\n */\nexport function validateConfig(config: Partial<DubheConfig>): DubheConfig {\n const errors: string[] = [];\n\n // Check required fields\n if (!config.network) {\n errors.push('network is required');\n }\n\n if (!config.packageId) {\n errors.push('packageId is required');\n }\n\n if (!config.metadata) {\n errors.push('metadata is required');\n } else {\n // Basic metadata validation\n if (typeof config.metadata !== 'object') {\n errors.push('metadata must be an object');\n } else if (Object.keys(config.metadata).length === 0) {\n errors.push('metadata cannot be empty');\n }\n }\n\n // Validate network type\n if (config.network && !['mainnet', 'testnet', 'devnet', 'localnet'].includes(config.network)) {\n errors.push(\n `invalid network: ${config.network}. Must be one of: mainnet, testnet, devnet, localnet`\n );\n }\n\n // Validate package ID format (enhanced check)\n if (config.packageId) {\n if (!config.packageId.startsWith('0x')) {\n errors.push('packageId must start with 0x');\n } else if (config.packageId.length < 3) {\n errors.push('packageId must be longer than 0x');\n } else if (!/^0x[a-fA-F0-9]+$/.test(config.packageId)) {\n errors.push('packageId must contain only hexadecimal characters after 0x');\n }\n }\n\n // Validate dubheMetadata if provided\n if (config.dubheMetadata !== undefined) {\n if (typeof config.dubheMetadata !== 'object' || config.dubheMetadata === null) {\n errors.push('dubheMetadata must be an object');\n } else if (!config.dubheMetadata.components && !config.dubheMetadata.resources) {\n errors.push('dubheMetadata must contain components or resources');\n }\n }\n\n // Validate credentials if provided\n if (config.credentials) {\n if (config.credentials.secretKey && typeof config.credentials.secretKey !== 'string') {\n errors.push('credentials.secretKey must be a string');\n }\n if (config.credentials.mnemonics && typeof config.credentials.mnemonics !== 'string') {\n errors.push('credentials.mnemonics must be a string');\n }\n }\n\n // Validate URLs if provided\n if (config.endpoints?.graphql && !isValidUrl(config.endpoints.graphql)) {\n errors.push('endpoints.graphql must be a valid URL');\n }\n\n if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {\n errors.push('endpoints.websocket must be a valid URL');\n }\n\n if (config.endpoints?.grpc && !isValidUrl(config.endpoints.grpc)) {\n errors.push('endpoints.grpc must be a valid URL');\n }\n\n // Validate fullnodeUrls if provided\n if (config.endpoints?.fullnodeUrls) {\n if (!Array.isArray(config.endpoints.fullnodeUrls)) {\n errors.push('endpoints.fullnodeUrls must be an array');\n } else if (config.endpoints.fullnodeUrls.length === 0) {\n errors.push('endpoints.fullnodeUrls cannot be empty if provided');\n } else {\n config.endpoints.fullnodeUrls.forEach((url, index) => {\n if (!isValidUrl(url)) {\n errors.push(`endpoints.fullnodeUrls[${index}] must be a valid URL: ${url}`);\n }\n });\n }\n }\n\n // Validate numeric options\n if (\n config.options?.cacheTimeout !== undefined &&\n (typeof config.options.cacheTimeout !== 'number' || config.options.cacheTimeout < 0)\n ) {\n errors.push('options.cacheTimeout must be a non-negative number');\n }\n\n if (\n config.options?.debounceMs !== undefined &&\n (typeof config.options.debounceMs !== 'number' || config.options.debounceMs < 0)\n ) {\n errors.push('options.debounceMs must be a non-negative number');\n }\n\n if (errors.length > 0) {\n const errorMessage = `Invalid Dubhe configuration (${errors.length} error${\n errors.length > 1 ? 's' : ''\n }):\\n${errors.map((e) => `- ${e}`).join('\\n')}`;\n console.error('Configuration validation failed:', { errors, config });\n throw new Error(errorMessage);\n }\n\n return config as DubheConfig;\n}\n\n/**\n * Simple URL validation helper\n *\n * @param url - URL string to validate\n * @returns true if URL is valid, false otherwise\n */\nfunction isValidUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Generate a configuration summary for debugging\n * Hides sensitive information like private keys\n *\n * @param config - Configuration to summarize\n * @returns Safe configuration summary\n */\nexport function getConfigSummary(config: DubheConfig): object {\n return {\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n hasMetadata: !!config.metadata,\n hasDubheMetadata: !!config.dubheMetadata,\n hasCredentials: !!config.credentials?.secretKey,\n endpoints: config.endpoints,\n options: config.options\n };\n}\n","/**\n * Dubhe Provider - useRef Pattern for Client Management\n *\n * Features:\n * - 🎯 Single client instances across application lifecycle\n * - ⚡ useRef-based storage (no re-initialization on re-renders)\n * - 🔧 Provider pattern for dependency injection\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing\n */\n\nimport {\n createContext,\n useContext,\n useRef,\n ReactNode,\n useState,\n useCallback,\n useEffect\n} from 'react';\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient, DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld, DubheECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport { useDubheConfig } from './config';\nimport type { DubheConfig, DubheReturn } from './types';\n\n/**\n * Context interface for Dubhe client instances\n * All clients are stored using useRef to ensure single initialization\n */\ninterface DubheContextValue {\n getContract: () => Dubhe;\n getGraphqlClient: () => DubheGraphqlClient;\n getGrpcClient: () => DubheGrpcClient;\n getEcsWorld: () => DubheECSWorld;\n getAddress: () => string;\n getMetrics: () => {\n initTime: number;\n requestCount: number;\n lastActivity: number;\n };\n config: DubheConfig;\n updateConfig: (newConfig: Partial<DubheConfig>) => void;\n resetClients: (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => void;\n}\n\n/**\n * Context for sharing Dubhe clients across the application\n * Uses useRef pattern to ensure clients are created only once\n */\nconst DubheContext = createContext<DubheContextValue | null>(null);\n\n/**\n * Props interface for DubheProvider component\n */\ninterface DubheProviderProps {\n /** Configuration for Dubhe initialization */\n config: Partial<DubheConfig>;\n /** Child components that will have access to Dubhe clients */\n children: ReactNode;\n}\n\n/**\n * DubheProvider Component - useRef Pattern Implementation\n *\n * This Provider uses useRef to store client instances, ensuring they are:\n * 1. Created only once during component lifecycle\n * 2. Persisted across re-renders without re-initialization\n * 3. Shared efficiently via React Context\n *\n * Key advantages over useMemo:\n * - useRef guarantees single initialization (useMemo can re-run on dependency changes)\n * - No dependency array needed (eliminates potential re-initialization bugs)\n * - Better performance for heavy client objects\n * - Clearer separation of concerns via Provider pattern\n *\n * @param props - Provider props containing config and children\n * @returns Provider component wrapping children with Dubhe context\n *\n * @example\n * ```typescript\n * // App root setup\n * function App() {\n * const dubheConfig = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={dubheConfig}>\n * <MyApplication />\n * </DubheProvider>\n * );\n * }\n * ```\n */\nexport function DubheProvider({ config, children }: DubheProviderProps) {\n // Use state to manage config for dynamic updates with persistence\n const [currentConfig, setCurrentConfig] = useState<Partial<DubheConfig>>(() => {\n // Try to restore config from localStorage\n if (typeof window !== 'undefined') {\n try {\n const saved = localStorage.getItem('dubhe-config');\n if (saved) {\n const parsedConfig = JSON.parse(saved);\n console.log('Restored Dubhe configuration from localStorage');\n // Important: Explicit config takes precedence over localStorage\n return { ...parsedConfig, ...config };\n }\n } catch (error) {\n console.warn('Failed to restore Dubhe configuration from localStorage', error);\n }\n }\n return config;\n });\n\n // Merge configuration with defaults\n const finalConfig = useDubheConfig(currentConfig);\n\n // Track initialization start time (useRef ensures single timestamp)\n const startTimeRef = useRef<number>(performance.now());\n\n // useRef for contract instance - guarantees single initialization\n // Unlike useMemo, useRef.current is never re-calculated\n const contractRef = useRef<Dubhe | undefined>(undefined);\n const getContract = (): Dubhe => {\n if (!contractRef.current) {\n try {\n console.log('Initializing Dubhe contract instance (one-time)');\n contractRef.current = new Dubhe({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics,\n fullnodeUrls: finalConfig.endpoints?.fullnodeUrls\n });\n } catch (error) {\n console.error('Contract initialization failed:', error);\n throw error;\n }\n }\n return contractRef.current;\n };\n\n // useRef for GraphQL client instance - single initialization guaranteed\n const graphqlClientRef = useRef<DubheGraphqlClient | null>(null);\n const hasInitializedGraphql = useRef(false);\n const getGraphqlClient = (): DubheGraphqlClient => {\n if (!hasInitializedGraphql.current) {\n try {\n console.log('Initializing GraphQL client instance (one-time)');\n graphqlClientRef.current = createDubheGraphqlClient({\n endpoint: finalConfig.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: finalConfig.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: finalConfig.dubheMetadata\n });\n hasInitializedGraphql.current = true;\n } catch (error) {\n console.error('GraphQL client initialization failed:', error);\n throw error;\n }\n }\n return graphqlClientRef.current!;\n };\n\n // useRef for gRPC client instance - single initialization guaranteed\n const grpcClientRef = useRef<DubheGrpcClient | null>(null);\n const hasInitializedGrpc = useRef(false);\n const getGrpcClient = (): DubheGrpcClient => {\n if (!hasInitializedGrpc.current) {\n try {\n console.log('Initializing gRPC client instance (one-time)');\n grpcClientRef.current = new DubheGrpcClient({\n baseUrl: finalConfig.endpoints?.grpc || 'http://localhost:8080'\n });\n hasInitializedGrpc.current = true;\n } catch (error) {\n console.error('gRPC client initialization failed:', error);\n throw error;\n }\n }\n return grpcClientRef.current!;\n };\n\n // useRef for ECS World instance - depends on GraphQL client\n const ecsWorldRef = useRef<DubheECSWorld | null>(null);\n const hasInitializedEcs = useRef(false);\n const getEcsWorld = (): DubheECSWorld => {\n const graphqlClient = getGraphqlClient();\n if (!hasInitializedEcs.current) {\n try {\n console.log('Initializing ECS World instance (one-time)');\n ecsWorldRef.current = createECSWorld(graphqlClient, {\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs ?? 100,\n reconnectOnError: finalConfig.options?.reconnectOnError ?? true\n }\n });\n hasInitializedEcs.current = true;\n } catch (error) {\n console.error('ECS World initialization failed:', error);\n throw error;\n }\n }\n return ecsWorldRef.current!;\n };\n\n // Address getter - calculated from contract\n const getAddress = (): string => {\n return getContract().getAddress();\n };\n\n // Metrics getter - performance tracking\n const getMetrics = () => ({\n initTime: performance.now() - (startTimeRef.current || 0),\n requestCount: 0, // Can be enhanced with actual tracking\n lastActivity: Date.now()\n });\n\n // Selective reset client instances\n const resetClients = useCallback(\n (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => {\n const opts = {\n resetContract: true,\n resetGraphql: true,\n resetGrpc: true,\n resetEcs: true,\n ...options\n };\n\n console.log('Resetting Dubhe client instances', opts);\n\n if (opts.resetContract) {\n contractRef.current = undefined;\n }\n if (opts.resetGraphql) {\n graphqlClientRef.current = null;\n hasInitializedGraphql.current = false;\n }\n if (opts.resetGrpc) {\n grpcClientRef.current = null;\n hasInitializedGrpc.current = false;\n }\n if (opts.resetEcs) {\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n\n startTimeRef.current = performance.now();\n },\n []\n );\n\n // Update config without resetting clients (reactive update)\n const updateConfig = useCallback((newConfig: Partial<DubheConfig>) => {\n console.log('Updating Dubhe configuration (reactive)');\n setCurrentConfig((prev) => {\n const updated = { ...prev, ...newConfig };\n // Persist to localStorage\n if (typeof window !== 'undefined') {\n try {\n localStorage.setItem('dubhe-config', JSON.stringify(updated));\n console.log('Persisted Dubhe configuration to localStorage');\n } catch (error) {\n console.warn('Failed to persist Dubhe configuration', error);\n }\n }\n return updated;\n });\n }, []);\n\n // Reactive configuration updates via useEffect\n\n // Monitor Contract configuration changes\n useEffect(() => {\n if (contractRef.current) {\n console.log('Contract config dependencies changed, updating...');\n contractRef.current.updateConfig({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics,\n fullnodeUrls: finalConfig.endpoints?.fullnodeUrls\n });\n }\n }, [\n finalConfig.network,\n finalConfig.packageId,\n finalConfig.metadata,\n finalConfig.credentials?.secretKey,\n finalConfig.credentials?.mnemonics,\n finalConfig.endpoints?.fullnodeUrls\n ]);\n\n // Monitor GraphQL endpoint changes\n useEffect(() => {\n if (graphqlClientRef.current) {\n console.log('GraphQL endpoint dependencies changed, updating...');\n graphqlClientRef.current.updateConfig({\n endpoint: finalConfig.endpoints?.graphql,\n subscriptionEndpoint: finalConfig.endpoints?.websocket\n });\n // Reset ECS World when GraphQL endpoints change (needs new connection)\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);\n\n // Monitor GraphQL metadata changes\n useEffect(() => {\n if (graphqlClientRef.current && finalConfig.dubheMetadata) {\n console.log('GraphQL metadata changed, updating...');\n graphqlClientRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata\n });\n // Note: ECS will handle its own metadata update via its useEffect\n }\n }, [finalConfig.dubheMetadata]);\n\n // Monitor gRPC configuration changes\n useEffect(() => {\n if (grpcClientRef.current && finalConfig.endpoints?.grpc) {\n console.log('gRPC config dependencies changed, updating...');\n grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });\n }\n }, [finalConfig.endpoints?.grpc]);\n\n // Monitor ECS configuration changes\n useEffect(() => {\n if (ecsWorldRef.current) {\n console.log('ECS config dependencies changed, updating...');\n ecsWorldRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs,\n reconnectOnError: finalConfig.options?.reconnectOnError\n }\n });\n }\n }, [\n finalConfig.dubheMetadata,\n finalConfig.options?.enableBatchOptimization,\n finalConfig.options?.cacheTimeout,\n finalConfig.options?.debounceMs,\n finalConfig.options?.reconnectOnError\n ]);\n\n // Context value - stable reference (no re-renders for consumers)\n const contextValue: DubheContextValue = {\n getContract,\n getGraphqlClient,\n getGrpcClient,\n getEcsWorld,\n getAddress,\n getMetrics,\n config: finalConfig,\n updateConfig,\n resetClients\n };\n\n return <DubheContext.Provider value={contextValue}>{children}</DubheContext.Provider>;\n}\n\n/**\n * Custom hook to access Dubhe context\n * Provides type-safe access to all Dubhe client instances\n *\n * @returns DubheContextValue with all client getters and config\n * @throws Error if used outside of DubheProvider\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const dubheContext = useDubheContext();\n *\n * const contract = dubheContext.getContract();\n * const graphqlClient = dubheContext.getGraphqlClient();\n * const ecsWorld = dubheContext.getEcsWorld();\n * const address = dubheContext.getAddress();\n *\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubheContext(): DubheContextValue {\n const context = useContext(DubheContext);\n\n if (!context) {\n throw new Error(\n 'useDubheContext must be used within a DubheProvider. ' +\n 'Make sure to wrap your app with <DubheProvider config={...}>'\n );\n }\n\n return context;\n}\n\n/**\n * Enhanced hook that mimics the original useDubhe API\n * Uses the Provider pattern internally but maintains backward compatibility\n *\n * @returns DubheReturn object with all instances and metadata\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const { contract, graphqlClient, ecsWorld, address } = useDubheFromProvider();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheFromProvider(): DubheReturn {\n const context = useDubheContext();\n\n // Get instances (lazy initialization via getters)\n const contract = context.getContract();\n const graphqlClient = context.getGraphqlClient();\n const grpcClient = context.getGrpcClient();\n const ecsWorld = context.getEcsWorld();\n const address = context.getAddress();\n const metrics = context.getMetrics();\n\n return {\n contract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: context.config.metadata,\n network: context.config.network,\n packageId: context.config.packageId,\n dubheSchemaId: context.config.dubheSchemaId,\n address,\n options: context.config.options,\n metrics\n };\n}\n\n/**\n * Individual client hooks for components that only need specific instances\n * These are more efficient than useDubheFromProvider for single-client usage\n */\n\n/**\n * Hook for accessing only the Dubhe contract instance\n */\nexport function useDubheContractFromProvider(): Dubhe {\n const { contract } = useDubheFromProvider();\n return contract;\n}\n\n/**\n * Hook for accessing only the GraphQL client instance\n */\nexport function useDubheGraphQLFromProvider(): DubheGraphqlClient {\n const { getGraphqlClient } = useDubheContext();\n return getGraphqlClient();\n}\n\n/**\n * Hook for accessing only the ECS World instance\n */\nexport function useDubheECSFromProvider(): DubheECSWorld {\n const { getEcsWorld } = useDubheContext();\n return getEcsWorld();\n}\n\n/**\n * Hook for accessing only the gRPC client instance\n */\nexport function useDubheGrpcFromProvider(): DubheGrpcClient {\n const { getGrpcClient } = useDubheContext();\n return getGrpcClient();\n}\n\n/**\n * Hook for accessing configuration update methods\n *\n * @returns Object with updateConfig and resetClients methods\n *\n * @example\n * ```typescript\n * function ConfigUpdater() {\n * const { updateConfig, resetClients, config } = useDubheConfigUpdate();\n *\n * const switchNetwork = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xnew...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Current network: {config.network}</p>\n * <button onClick={switchNetwork}>Switch to Testnet</button>\n * <button onClick={resetClients}>Reset Clients</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n const { updateConfig, resetClients, config } = useDubheContext();\n return { updateConfig, resetClients, config };\n}\n","/**\n * Modern Dubhe React Hooks - Provider Pattern\n *\n * Features:\n * - 🎯 Simple API design with Provider pattern\n * - ⚡ Single client initialization with useRef\n * - 🔧 Configuration-driven setup (developers handle environment variables themselves)\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing across components\n */\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport type { DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport type { DubheECSWorld } from '@0xobelisk/ecs';\n\nimport {\n useDubheFromProvider,\n useDubheContractFromProvider,\n useDubheGraphQLFromProvider,\n useDubheECSFromProvider,\n useDubheConfigUpdate as useDubheConfigUpdateFromProvider\n} from './provider';\nimport type { DubheReturn } from './types';\n\n/**\n * Primary Hook: useDubhe\n *\n * Uses Provider pattern to access shared Dubhe clients with guaranteed single initialization.\n * Must be used within a DubheProvider.\n *\n * @returns Complete Dubhe ecosystem with contract, GraphQL, ECS, and metadata\n *\n * @example\n * ```typescript\n * // App setup with Provider\n * function App() {\n * const config = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={config}>\n * <MyDApp />\n * </DubheProvider>\n * );\n * }\n *\n * // Component usage\n * function MyDApp() {\n * const { contract, address } = useDubhe();\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubhe(): DubheReturn {\n return useDubheFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheContract\n *\n * Returns only the Dubhe contract instance from Provider context.\n * More efficient than useDubhe() when only contract access is needed.\n *\n * @returns Dubhe contract instance\n *\n * @example\n * ```typescript\n * function TransactionComponent() {\n * const contract = useDubheContract();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheContract(): Dubhe {\n return useDubheContractFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheGraphQL\n *\n * Returns only the GraphQL client from Provider context.\n * More efficient than useDubhe() when only GraphQL access is needed.\n *\n * @returns GraphQL client instance (always available with default localhost endpoint)\n *\n * @example\n * ```typescript\n * function DataComponent() {\n * const graphqlClient = useDubheGraphQL();\n *\n * useEffect(() => {\n * graphqlClient.query({ ... }).then(setData);\n * }, [graphqlClient]);\n *\n * return <div>{data && JSON.stringify(data)}</div>;\n * }\n * ```\n */\nexport function useDubheGraphQL(): DubheGraphqlClient {\n return useDubheGraphQLFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheECS\n *\n * Returns only the ECS World instance from Provider context.\n * More efficient than useDubhe() when only ECS access is needed.\n *\n * @returns ECS World instance (always available, depends on GraphQL client)\n *\n * @example\n * ```typescript\n * function ECSComponent() {\n * const ecsWorld = useDubheECS();\n *\n * useEffect(() => {\n * ecsWorld.getComponent('MyComponent').then(setComponent);\n * }, [ecsWorld]);\n *\n * return <div>ECS Component Data</div>;\n * }\n * ```\n */\nexport function useDubheECS(): DubheECSWorld {\n return useDubheECSFromProvider();\n}\n\n/**\n * Hook for dynamic configuration updates\n *\n * Provides methods to update provider configuration at runtime\n *\n * @returns Object with updateConfig, resetClients methods and current config\n *\n * @example\n * ```typescript\n * function NetworkSwitcher() {\n * const { updateConfig, config } = useDubheConfigUpdate();\n *\n * const switchToTestnet = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xTestnetPackageId...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Network: {config.network}</p>\n * <button onClick={switchToTestnet}>Switch to Testnet</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n return useDubheConfigUpdateFromProvider();\n}\n\n/**\n * Compatibility alias for useDubhe\n */\nexport const useContract = useDubhe;\n"],"mappings":";AAUA,SAAS,eAAe;;;ACSjB,SAAS,oBACd,YACA,gBACsB;AACtB,MAAI,CAAC,gBAAgB;AACnB,WAAO,EAAE,GAAG,WAAW;AAAA,EACzB;AAEA,QAAM,SAA+B,EAAE,GAAG,WAAW;AAGrD,SAAO,OAAO,QAAQ,cAAc;AAGpC,MAAI,eAAe,eAAe,WAAW,aAAa;AACxD,WAAO,cAAc;AAAA,MACnB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MA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AAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,QAAQ,OAAO;AAAA,IACzB,SAAS,QAAQ,OAAO;AAAA,IACxB,WAAW,QAAQ,OAAO;AAAA,IAC1B,eAAe,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,SAAS,QAAQ,OAAO;AAAA,IACxB;AAAA,EACF;AACF;AAUO,SAAS,+BAAsC;AACpD,QAAM,EAAE,SAAS,IAAI,qBAAqB;AAC1C,SAAO;AACT;AAKO,SAAS,8BAAkD;AAChE,QAAM,EAAE,iBAAiB,IAAI,gBAAgB;AAC7C,SAAO,iBAAiB;AAC1B;AAKO,SAAS,0BAAyC;AACvD,QAAM,EAAE,YAAY,IAAI,gBAAgB;AACxC,SAAO,YAAY;AACrB;AAqCO,SAAS,uBAAuB;AACrC,QAAM,EAAE,cAAc,cAAc,OAAO,IAAI,gBAAgB;AAC/D,SAAO,EAAE,cAAc,cAAc,OAAO;AAC9C;;;AC9dO,SAAS,WAAwB;AACtC,SAAO,qBAAqB;AAC9B;AAwBO,SAAS,mBAA0B;AACxC,SAAO,6BAA6B;AACtC;AAuBO,SAAS,kBAAsC;AACpD,SAAO,4BAA4B;AACrC;AAuBO,SAAS,cAA6B;AAC3C,SAAO,wBAAwB;AACjC;AA8BO,SAASA,wBAAuB;AACrC,SAAO,qBAAiC;AAC1C;AAKO,IAAM,cAAc;","names":["useDubheConfigUpdate"]}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.mjs';
1
+ export { ClientConfig, ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.mjs';
2
2
  import '@0xobelisk/sui-client';
3
3
  import '@0xobelisk/graphql-client';
4
4
  import '@0xobelisk/ecs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.js';
1
+ export { ClientConfig, ContractReturn, DEFAULT_CONFIG, DubheConfig, DubheProvider, DubheReturn, NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig } from './sui/index.js';
2
2
  import '@0xobelisk/sui-client';
3
3
  import '@0xobelisk/graphql-client';
4
4
  import '@0xobelisk/ecs';
package/dist/index.js CHANGED
@@ -117,6 +117,22 @@ function validateConfig(config) {
117
117
  if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {
118
118
  errors.push("endpoints.websocket must be a valid URL");
119
119
  }
120
+ if (config.endpoints?.grpc && !isValidUrl(config.endpoints.grpc)) {
121
+ errors.push("endpoints.grpc must be a valid URL");
122
+ }
123
+ if (config.endpoints?.fullnodeUrls) {
124
+ if (!Array.isArray(config.endpoints.fullnodeUrls)) {
125
+ errors.push("endpoints.fullnodeUrls must be an array");
126
+ } else if (config.endpoints.fullnodeUrls.length === 0) {
127
+ errors.push("endpoints.fullnodeUrls cannot be empty if provided");
128
+ } else {
129
+ config.endpoints.fullnodeUrls.forEach((url, index) => {
130
+ if (!isValidUrl(url)) {
131
+ errors.push(`endpoints.fullnodeUrls[${index}] must be a valid URL: ${url}`);
132
+ }
133
+ });
134
+ }
135
+ }
120
136
  if (config.options?.cacheTimeout !== void 0 && (typeof config.options.cacheTimeout !== "number" || config.options.cacheTimeout < 0)) {
121
137
  errors.push("options.cacheTimeout must be a non-negative number");
122
138
  }
@@ -211,7 +227,9 @@ function DubheProvider({ config, children }) {
211
227
  networkType: finalConfig.network,
212
228
  packageId: finalConfig.packageId,
213
229
  metadata: finalConfig.metadata,
214
- secretKey: finalConfig.credentials?.secretKey
230
+ secretKey: finalConfig.credentials?.secretKey,
231
+ mnemonics: finalConfig.credentials?.mnemonics,
232
+ fullnodeUrls: finalConfig.endpoints?.fullnodeUrls
215
233
  });
216
234
  } catch (error) {
217
235
  console.error("Contract initialization failed:", error);
@@ -246,7 +264,7 @@ function DubheProvider({ config, children }) {
246
264
  try {
247
265
  console.log("Initializing gRPC client instance (one-time)");
248
266
  grpcClientRef.current = new import_grpc_client.DubheGrpcClient({
249
- baseUrl: finalConfig.endpoints?.grpc || "http://localhost:50051"
267
+ baseUrl: finalConfig.endpoints?.grpc || "http://localhost:8080"
250
268
  });
251
269
  hasInitializedGrpc.current = true;
252
270
  } catch (error) {
@@ -343,7 +361,8 @@ function DubheProvider({ config, children }) {
343
361
  packageId: finalConfig.packageId,
344
362
  metadata: finalConfig.metadata,
345
363
  secretKey: finalConfig.credentials?.secretKey,
346
- mnemonics: finalConfig.credentials?.mnemonics
364
+ mnemonics: finalConfig.credentials?.mnemonics,
365
+ fullnodeUrls: finalConfig.endpoints?.fullnodeUrls
347
366
  });
348
367
  }
349
368
  }, [
@@ -351,7 +370,8 @@ function DubheProvider({ config, children }) {
351
370
  finalConfig.packageId,
352
371
  finalConfig.metadata,
353
372
  finalConfig.credentials?.secretKey,
354
- finalConfig.credentials?.mnemonics
373
+ finalConfig.credentials?.mnemonics,
374
+ finalConfig.endpoints?.fullnodeUrls
355
375
  ]);
356
376
  (0, import_react2.useEffect)(() => {
357
377
  if (graphqlClientRef.current) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/sui/config.ts","../src/sui/utils.ts","../src/sui/provider.tsx","../src/sui/hooks.ts"],"sourcesContent":["/**\n * @0xobelisk/react - Modern Dubhe React Integration\n *\n * 🚀 Provides simple, powerful React experience for multi-chain blockchain development\n *\n * Currently supported:\n * - Sui blockchain ✅\n * - Aptos blockchain (coming soon)\n * - Initia blockchain (coming soon)\n */\n\n// Sui integration\nexport * from './sui/index';\n// TODO: Future extensions\n// export * from './aptos/index';\n// export * from './initia/index';\n","/**\n * Configuration Management for Dubhe React Integration\n *\n * Features:\n * - Type-safe configuration interface\n * - Configuration validation and error handling\n * - Smart merging of defaults and explicit config\n * - No environment variable handling (developers should handle environment variables themselves)\n */\n\nimport { useMemo } from 'react';\nimport type { DubheConfig } from './types';\nimport { mergeConfigurations, validateConfig } from './utils';\n\n/**\n * Default configuration object with sensible defaults\n */\nexport const DEFAULT_CONFIG: Partial<DubheConfig> = {\n endpoints: {\n graphql: 'http://localhost:4000/graphql',\n websocket: 'ws://localhost:4000/graphql'\n },\n options: {\n enableBatchOptimization: true,\n cacheTimeout: 5000,\n debounceMs: 100,\n reconnectOnError: true\n }\n};\n\n/**\n * Configuration Hook: useDubheConfig\n *\n * Merges defaults with explicit configuration provided by the developer\n *\n * Note: Environment variables should be handled by the developer before passing to this hook\n *\n * @param config - Complete or partial configuration object\n * @returns Complete, validated DubheConfig\n *\n * @example\n * ```typescript\n * // Basic usage with explicit config\n * const config = useDubheConfig({\n * network: 'testnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // Handle env vars yourself\n * }\n * });\n *\n * // With helper function to handle environment variables\n * const getConfigFromEnv = () => ({\n * network: process.env.NEXT_PUBLIC_NETWORK as NetworkType,\n * packageId: process.env.NEXT_PUBLIC_PACKAGE_ID,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * });\n *\n * const config = useDubheConfig({\n * ...getConfigFromEnv(),\n * metadata: contractMetadata\n * });\n * ```\n */\nexport function useDubheConfig(config: Partial<DubheConfig>): DubheConfig {\n // Memoize the stringified config to detect actual changes\n const configKey = useMemo(() => {\n return JSON.stringify(config);\n }, [config]);\n\n return useMemo(() => {\n // Merge configurations: defaults -> user provided config\n const mergedConfig = mergeConfigurations(DEFAULT_CONFIG, config);\n\n // Validate the final configuration\n const validatedConfig = validateConfig(mergedConfig);\n\n // if (process.env.NODE_ENV === 'development') {\n // console.log('🔧 Dubhe Config:', {\n // ...validatedConfig,\n // credentials: validatedConfig.credentials?.secretKey ? '[REDACTED]' : undefined\n // });\n // }\n\n return validatedConfig;\n }, [configKey]);\n}\n","/**\n * Utility Functions for Dubhe Configuration Management\n *\n * Features:\n * - Configuration validation and error handling\n * - Smart configuration merging with proper type safety\n * - Type-safe configuration validation\n */\n\nimport type { DubheConfig } from './types';\n\n/**\n * Merge multiple configuration objects with proper deep merging\n * Later configurations override earlier ones\n *\n * @param baseConfig - Base configuration (usually defaults)\n * @param overrideConfig - Override configuration (user provided)\n * @returns Merged configuration\n */\nexport function mergeConfigurations(\n baseConfig: Partial<DubheConfig>,\n overrideConfig?: Partial<DubheConfig>\n): Partial<DubheConfig> {\n if (!overrideConfig) {\n return { ...baseConfig };\n }\n\n const result: Partial<DubheConfig> = { ...baseConfig };\n\n // Merge top-level properties\n Object.assign(result, overrideConfig);\n\n // Deep merge nested objects\n if (overrideConfig.credentials || baseConfig.credentials) {\n result.credentials = {\n ...baseConfig.credentials,\n ...overrideConfig.credentials\n };\n }\n\n if (overrideConfig.endpoints || baseConfig.endpoints) {\n result.endpoints = {\n ...baseConfig.endpoints,\n ...overrideConfig.endpoints\n };\n }\n\n if (overrideConfig.options || baseConfig.options) {\n result.options = {\n ...baseConfig.options,\n ...overrideConfig.options\n };\n }\n\n return result;\n}\n\n/**\n * Validate configuration and ensure required fields are present\n * Throws descriptive errors for missing required fields\n *\n * @param config - Configuration to validate\n * @returns Validated and typed configuration\n * @throws Error if required fields are missing or invalid\n */\nexport function validateConfig(config: Partial<DubheConfig>): DubheConfig {\n const errors: string[] = [];\n\n // Check required fields\n if (!config.network) {\n errors.push('network is required');\n }\n\n if (!config.packageId) {\n errors.push('packageId is required');\n }\n\n if (!config.metadata) {\n errors.push('metadata is required');\n } else {\n // Basic metadata validation\n if (typeof config.metadata !== 'object') {\n errors.push('metadata must be an object');\n } else if (Object.keys(config.metadata).length === 0) {\n errors.push('metadata cannot be empty');\n }\n }\n\n // Validate network type\n if (config.network && !['mainnet', 'testnet', 'devnet', 'localnet'].includes(config.network)) {\n errors.push(\n `invalid network: ${config.network}. Must be one of: mainnet, testnet, devnet, localnet`\n );\n }\n\n // Validate package ID format (enhanced check)\n if (config.packageId) {\n if (!config.packageId.startsWith('0x')) {\n errors.push('packageId must start with 0x');\n } else if (config.packageId.length < 3) {\n errors.push('packageId must be longer than 0x');\n } else if (!/^0x[a-fA-F0-9]+$/.test(config.packageId)) {\n errors.push('packageId must contain only hexadecimal characters after 0x');\n }\n }\n\n // Validate dubheMetadata if provided\n if (config.dubheMetadata !== undefined) {\n if (typeof config.dubheMetadata !== 'object' || config.dubheMetadata === null) {\n errors.push('dubheMetadata must be an object');\n } else if (!config.dubheMetadata.components && !config.dubheMetadata.resources) {\n errors.push('dubheMetadata must contain components or resources');\n }\n }\n\n // Validate credentials if provided\n if (config.credentials) {\n if (config.credentials.secretKey && typeof config.credentials.secretKey !== 'string') {\n errors.push('credentials.secretKey must be a string');\n }\n if (config.credentials.mnemonics && typeof config.credentials.mnemonics !== 'string') {\n errors.push('credentials.mnemonics must be a string');\n }\n }\n\n // Validate URLs if provided\n if (config.endpoints?.graphql && !isValidUrl(config.endpoints.graphql)) {\n errors.push('endpoints.graphql must be a valid URL');\n }\n\n if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {\n errors.push('endpoints.websocket must be a valid URL');\n }\n\n // Validate numeric options\n if (\n config.options?.cacheTimeout !== undefined &&\n (typeof config.options.cacheTimeout !== 'number' || config.options.cacheTimeout < 0)\n ) {\n errors.push('options.cacheTimeout must be a non-negative number');\n }\n\n if (\n config.options?.debounceMs !== undefined &&\n (typeof config.options.debounceMs !== 'number' || config.options.debounceMs < 0)\n ) {\n errors.push('options.debounceMs must be a non-negative number');\n }\n\n if (errors.length > 0) {\n const errorMessage = `Invalid Dubhe configuration (${errors.length} error${\n errors.length > 1 ? 's' : ''\n }):\\n${errors.map((e) => `- ${e}`).join('\\n')}`;\n console.error('Configuration validation failed:', { errors, config });\n throw new Error(errorMessage);\n }\n\n return config as DubheConfig;\n}\n\n/**\n * Simple URL validation helper\n *\n * @param url - URL string to validate\n * @returns true if URL is valid, false otherwise\n */\nfunction isValidUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Generate a configuration summary for debugging\n * Hides sensitive information like private keys\n *\n * @param config - Configuration to summarize\n * @returns Safe configuration summary\n */\nexport function getConfigSummary(config: DubheConfig): object {\n return {\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n hasMetadata: !!config.metadata,\n hasDubheMetadata: !!config.dubheMetadata,\n hasCredentials: !!config.credentials?.secretKey,\n endpoints: config.endpoints,\n options: config.options\n };\n}\n","/**\n * Dubhe Provider - useRef Pattern for Client Management\n *\n * Features:\n * - 🎯 Single client instances across application lifecycle\n * - ⚡ useRef-based storage (no re-initialization on re-renders)\n * - 🔧 Provider pattern for dependency injection\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing\n */\n\nimport {\n createContext,\n useContext,\n useRef,\n ReactNode,\n useState,\n useCallback,\n useEffect\n} from 'react';\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient, DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld, DubheECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport { useDubheConfig } from './config';\nimport type { DubheConfig, DubheReturn } from './types';\n\n/**\n * Context interface for Dubhe client instances\n * All clients are stored using useRef to ensure single initialization\n */\ninterface DubheContextValue {\n getContract: () => Dubhe;\n getGraphqlClient: () => DubheGraphqlClient;\n getGrpcClient: () => DubheGrpcClient;\n getEcsWorld: () => DubheECSWorld;\n getAddress: () => string;\n getMetrics: () => {\n initTime: number;\n requestCount: number;\n lastActivity: number;\n };\n config: DubheConfig;\n updateConfig: (newConfig: Partial<DubheConfig>) => void;\n resetClients: (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => void;\n}\n\n/**\n * Context for sharing Dubhe clients across the application\n * Uses useRef pattern to ensure clients are created only once\n */\nconst DubheContext = createContext<DubheContextValue | null>(null);\n\n/**\n * Props interface for DubheProvider component\n */\ninterface DubheProviderProps {\n /** Configuration for Dubhe initialization */\n config: Partial<DubheConfig>;\n /** Child components that will have access to Dubhe clients */\n children: ReactNode;\n}\n\n/**\n * DubheProvider Component - useRef Pattern Implementation\n *\n * This Provider uses useRef to store client instances, ensuring they are:\n * 1. Created only once during component lifecycle\n * 2. Persisted across re-renders without re-initialization\n * 3. Shared efficiently via React Context\n *\n * Key advantages over useMemo:\n * - useRef guarantees single initialization (useMemo can re-run on dependency changes)\n * - No dependency array needed (eliminates potential re-initialization bugs)\n * - Better performance for heavy client objects\n * - Clearer separation of concerns via Provider pattern\n *\n * @param props - Provider props containing config and children\n * @returns Provider component wrapping children with Dubhe context\n *\n * @example\n * ```typescript\n * // App root setup\n * function App() {\n * const dubheConfig = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={dubheConfig}>\n * <MyApplication />\n * </DubheProvider>\n * );\n * }\n * ```\n */\nexport function DubheProvider({ config, children }: DubheProviderProps) {\n // Use state to manage config for dynamic updates with persistence\n const [currentConfig, setCurrentConfig] = useState<Partial<DubheConfig>>(() => {\n // Try to restore config from localStorage\n if (typeof window !== 'undefined') {\n try {\n const saved = localStorage.getItem('dubhe-config');\n if (saved) {\n const parsedConfig = JSON.parse(saved);\n console.log('Restored Dubhe configuration from localStorage');\n // Important: Explicit config takes precedence over localStorage\n return { ...parsedConfig, ...config };\n }\n } catch (error) {\n console.warn('Failed to restore Dubhe configuration from localStorage', error);\n }\n }\n return config;\n });\n\n // Merge configuration with defaults\n const finalConfig = useDubheConfig(currentConfig);\n\n // Track initialization start time (useRef ensures single timestamp)\n const startTimeRef = useRef<number>(performance.now());\n\n // useRef for contract instance - guarantees single initialization\n // Unlike useMemo, useRef.current is never re-calculated\n const contractRef = useRef<Dubhe | undefined>(undefined);\n const getContract = (): Dubhe => {\n if (!contractRef.current) {\n try {\n console.log('Initializing Dubhe contract instance (one-time)');\n contractRef.current = new Dubhe({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey\n });\n } catch (error) {\n console.error('Contract initialization failed:', error);\n throw error;\n }\n }\n return contractRef.current;\n };\n\n // useRef for GraphQL client instance - single initialization guaranteed\n const graphqlClientRef = useRef<DubheGraphqlClient | null>(null);\n const hasInitializedGraphql = useRef(false);\n const getGraphqlClient = (): DubheGraphqlClient => {\n if (!hasInitializedGraphql.current) {\n try {\n console.log('Initializing GraphQL client instance (one-time)');\n graphqlClientRef.current = createDubheGraphqlClient({\n endpoint: finalConfig.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: finalConfig.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: finalConfig.dubheMetadata\n });\n hasInitializedGraphql.current = true;\n } catch (error) {\n console.error('GraphQL client initialization failed:', error);\n throw error;\n }\n }\n return graphqlClientRef.current!;\n };\n\n // useRef for gRPC client instance - single initialization guaranteed\n const grpcClientRef = useRef<DubheGrpcClient | null>(null);\n const hasInitializedGrpc = useRef(false);\n const getGrpcClient = (): DubheGrpcClient => {\n if (!hasInitializedGrpc.current) {\n try {\n console.log('Initializing gRPC client instance (one-time)');\n grpcClientRef.current = new DubheGrpcClient({\n baseUrl: finalConfig.endpoints?.grpc || 'http://localhost:50051'\n });\n hasInitializedGrpc.current = true;\n } catch (error) {\n console.error('gRPC client initialization failed:', error);\n throw error;\n }\n }\n return grpcClientRef.current!;\n };\n\n // useRef for ECS World instance - depends on GraphQL client\n const ecsWorldRef = useRef<DubheECSWorld | null>(null);\n const hasInitializedEcs = useRef(false);\n const getEcsWorld = (): DubheECSWorld => {\n const graphqlClient = getGraphqlClient();\n if (!hasInitializedEcs.current) {\n try {\n console.log('Initializing ECS World instance (one-time)');\n ecsWorldRef.current = createECSWorld(graphqlClient, {\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs ?? 100,\n reconnectOnError: finalConfig.options?.reconnectOnError ?? true\n }\n });\n hasInitializedEcs.current = true;\n } catch (error) {\n console.error('ECS World initialization failed:', error);\n throw error;\n }\n }\n return ecsWorldRef.current!;\n };\n\n // Address getter - calculated from contract\n const getAddress = (): string => {\n return getContract().getAddress();\n };\n\n // Metrics getter - performance tracking\n const getMetrics = () => ({\n initTime: performance.now() - (startTimeRef.current || 0),\n requestCount: 0, // Can be enhanced with actual tracking\n lastActivity: Date.now()\n });\n\n // Selective reset client instances\n const resetClients = useCallback(\n (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => {\n const opts = {\n resetContract: true,\n resetGraphql: true,\n resetGrpc: true,\n resetEcs: true,\n ...options\n };\n\n console.log('Resetting Dubhe client instances', opts);\n\n if (opts.resetContract) {\n contractRef.current = undefined;\n }\n if (opts.resetGraphql) {\n graphqlClientRef.current = null;\n hasInitializedGraphql.current = false;\n }\n if (opts.resetGrpc) {\n grpcClientRef.current = null;\n hasInitializedGrpc.current = false;\n }\n if (opts.resetEcs) {\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n\n startTimeRef.current = performance.now();\n },\n []\n );\n\n // Update config without resetting clients (reactive update)\n const updateConfig = useCallback((newConfig: Partial<DubheConfig>) => {\n console.log('Updating Dubhe configuration (reactive)');\n setCurrentConfig((prev) => {\n const updated = { ...prev, ...newConfig };\n // Persist to localStorage\n if (typeof window !== 'undefined') {\n try {\n localStorage.setItem('dubhe-config', JSON.stringify(updated));\n console.log('Persisted Dubhe configuration to localStorage');\n } catch (error) {\n console.warn('Failed to persist Dubhe configuration', error);\n }\n }\n return updated;\n });\n }, []);\n\n // Reactive configuration updates via useEffect\n\n // Monitor Contract configuration changes\n useEffect(() => {\n if (contractRef.current) {\n console.log('Contract config dependencies changed, updating...');\n contractRef.current.updateConfig({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics\n });\n }\n }, [\n finalConfig.network,\n finalConfig.packageId,\n finalConfig.metadata,\n finalConfig.credentials?.secretKey,\n finalConfig.credentials?.mnemonics\n ]);\n\n // Monitor GraphQL endpoint changes\n useEffect(() => {\n if (graphqlClientRef.current) {\n console.log('GraphQL endpoint dependencies changed, updating...');\n graphqlClientRef.current.updateConfig({\n endpoint: finalConfig.endpoints?.graphql,\n subscriptionEndpoint: finalConfig.endpoints?.websocket\n });\n // Reset ECS World when GraphQL endpoints change (needs new connection)\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);\n\n // Monitor GraphQL metadata changes\n useEffect(() => {\n if (graphqlClientRef.current && finalConfig.dubheMetadata) {\n console.log('GraphQL metadata changed, updating...');\n graphqlClientRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata\n });\n // Note: ECS will handle its own metadata update via its useEffect\n }\n }, [finalConfig.dubheMetadata]);\n\n // Monitor gRPC configuration changes\n useEffect(() => {\n if (grpcClientRef.current && finalConfig.endpoints?.grpc) {\n console.log('gRPC config dependencies changed, updating...');\n grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });\n }\n }, [finalConfig.endpoints?.grpc]);\n\n // Monitor ECS configuration changes\n useEffect(() => {\n if (ecsWorldRef.current) {\n console.log('ECS config dependencies changed, updating...');\n ecsWorldRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs,\n reconnectOnError: finalConfig.options?.reconnectOnError\n }\n });\n }\n }, [\n finalConfig.dubheMetadata,\n finalConfig.options?.enableBatchOptimization,\n finalConfig.options?.cacheTimeout,\n finalConfig.options?.debounceMs,\n finalConfig.options?.reconnectOnError\n ]);\n\n // Context value - stable reference (no re-renders for consumers)\n const contextValue: DubheContextValue = {\n getContract,\n getGraphqlClient,\n getGrpcClient,\n getEcsWorld,\n getAddress,\n getMetrics,\n config: finalConfig,\n updateConfig,\n resetClients\n };\n\n return <DubheContext.Provider value={contextValue}>{children}</DubheContext.Provider>;\n}\n\n/**\n * Custom hook to access Dubhe context\n * Provides type-safe access to all Dubhe client instances\n *\n * @returns DubheContextValue with all client getters and config\n * @throws Error if used outside of DubheProvider\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const dubheContext = useDubheContext();\n *\n * const contract = dubheContext.getContract();\n * const graphqlClient = dubheContext.getGraphqlClient();\n * const ecsWorld = dubheContext.getEcsWorld();\n * const address = dubheContext.getAddress();\n *\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubheContext(): DubheContextValue {\n const context = useContext(DubheContext);\n\n if (!context) {\n throw new Error(\n 'useDubheContext must be used within a DubheProvider. ' +\n 'Make sure to wrap your app with <DubheProvider config={...}>'\n );\n }\n\n return context;\n}\n\n/**\n * Enhanced hook that mimics the original useDubhe API\n * Uses the Provider pattern internally but maintains backward compatibility\n *\n * @returns DubheReturn object with all instances and metadata\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const { contract, graphqlClient, ecsWorld, address } = useDubheFromProvider();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheFromProvider(): DubheReturn {\n const context = useDubheContext();\n\n // Get instances (lazy initialization via getters)\n const contract = context.getContract();\n const graphqlClient = context.getGraphqlClient();\n const grpcClient = context.getGrpcClient();\n const ecsWorld = context.getEcsWorld();\n const address = context.getAddress();\n const metrics = context.getMetrics();\n\n return {\n contract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: context.config.metadata,\n network: context.config.network,\n packageId: context.config.packageId,\n dubheSchemaId: context.config.dubheSchemaId,\n address,\n options: context.config.options,\n metrics\n };\n}\n\n/**\n * Individual client hooks for components that only need specific instances\n * These are more efficient than useDubheFromProvider for single-client usage\n */\n\n/**\n * Hook for accessing only the Dubhe contract instance\n */\nexport function useDubheContractFromProvider(): Dubhe {\n const { contract } = useDubheFromProvider();\n return contract;\n}\n\n/**\n * Hook for accessing only the GraphQL client instance\n */\nexport function useDubheGraphQLFromProvider(): DubheGraphqlClient {\n const { getGraphqlClient } = useDubheContext();\n return getGraphqlClient();\n}\n\n/**\n * Hook for accessing only the ECS World instance\n */\nexport function useDubheECSFromProvider(): DubheECSWorld {\n const { getEcsWorld } = useDubheContext();\n return getEcsWorld();\n}\n\n/**\n * Hook for accessing only the gRPC client instance\n */\nexport function useDubheGrpcFromProvider(): DubheGrpcClient {\n const { getGrpcClient } = useDubheContext();\n return getGrpcClient();\n}\n\n/**\n * Hook for accessing configuration update methods\n *\n * @returns Object with updateConfig and resetClients methods\n *\n * @example\n * ```typescript\n * function ConfigUpdater() {\n * const { updateConfig, resetClients, config } = useDubheConfigUpdate();\n *\n * const switchNetwork = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xnew...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Current network: {config.network}</p>\n * <button onClick={switchNetwork}>Switch to Testnet</button>\n * <button onClick={resetClients}>Reset Clients</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n const { updateConfig, resetClients, config } = useDubheContext();\n return { updateConfig, resetClients, config };\n}\n","/**\n * Modern Dubhe React Hooks - Provider Pattern\n *\n * Features:\n * - 🎯 Simple API design with Provider pattern\n * - ⚡ Single client initialization with useRef\n * - 🔧 Configuration-driven setup (developers handle environment variables themselves)\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing across components\n */\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport type { DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport type { DubheECSWorld } from '@0xobelisk/ecs';\n\nimport {\n useDubheFromProvider,\n useDubheContractFromProvider,\n useDubheGraphQLFromProvider,\n useDubheECSFromProvider,\n useDubheConfigUpdate as useDubheConfigUpdateFromProvider\n} from './provider';\nimport type { DubheReturn } from './types';\n\n/**\n * Primary Hook: useDubhe\n *\n * Uses Provider pattern to access shared Dubhe clients with guaranteed single initialization.\n * Must be used within a DubheProvider.\n *\n * @returns Complete Dubhe ecosystem with contract, GraphQL, ECS, and metadata\n *\n * @example\n * ```typescript\n * // App setup with Provider\n * function App() {\n * const config = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={config}>\n * <MyDApp />\n * </DubheProvider>\n * );\n * }\n *\n * // Component usage\n * function MyDApp() {\n * const { contract, address } = useDubhe();\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubhe(): DubheReturn {\n return useDubheFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheContract\n *\n * Returns only the Dubhe contract instance from Provider context.\n * More efficient than useDubhe() when only contract access is needed.\n *\n * @returns Dubhe contract instance\n *\n * @example\n * ```typescript\n * function TransactionComponent() {\n * const contract = useDubheContract();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheContract(): Dubhe {\n return useDubheContractFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheGraphQL\n *\n * Returns only the GraphQL client from Provider context.\n * More efficient than useDubhe() when only GraphQL access is needed.\n *\n * @returns GraphQL client instance (always available with default localhost endpoint)\n *\n * @example\n * ```typescript\n * function DataComponent() {\n * const graphqlClient = useDubheGraphQL();\n *\n * useEffect(() => {\n * graphqlClient.query({ ... }).then(setData);\n * }, [graphqlClient]);\n *\n * return <div>{data && JSON.stringify(data)}</div>;\n * }\n * ```\n */\nexport function useDubheGraphQL(): DubheGraphqlClient {\n return useDubheGraphQLFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheECS\n *\n * Returns only the ECS World instance from Provider context.\n * More efficient than useDubhe() when only ECS access is needed.\n *\n * @returns ECS World instance (always available, depends on GraphQL client)\n *\n * @example\n * ```typescript\n * function ECSComponent() {\n * const ecsWorld = useDubheECS();\n *\n * useEffect(() => {\n * ecsWorld.getComponent('MyComponent').then(setComponent);\n * }, [ecsWorld]);\n *\n * return <div>ECS Component Data</div>;\n * }\n * ```\n */\nexport function useDubheECS(): DubheECSWorld {\n return useDubheECSFromProvider();\n}\n\n/**\n * Hook for dynamic configuration updates\n *\n * Provides methods to update provider configuration at runtime\n *\n * @returns Object with updateConfig, resetClients methods and current config\n *\n * @example\n * ```typescript\n * function NetworkSwitcher() {\n * const { updateConfig, config } = useDubheConfigUpdate();\n *\n * const switchToTestnet = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xTestnetPackageId...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Network: {config.network}</p>\n * <button onClick={switchToTestnet}>Switch to Testnet</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n return useDubheConfigUpdateFromProvider();\n}\n\n/**\n * Compatibility alias for useDubhe\n */\nexport const useContract = useDubhe;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,mBAAwB;;;ACSjB,SAAS,oBACd,YACA,gBACsB;AACtB,MAAI,CAAC,gBAAgB;AACnB,WAAO,EAAE,GAAG,WAAW;AAAA,EACzB;AAEA,QAAM,SAA+B,EAAE,GAAG,WAAW;AAGrD,SAAO,OAAO,QAAQ,cAAc;AAGpC,MAAI,eAAe,eAAe,WAAW,aAAa;AACxD,WAAO,cAAc;AAAA,MACnB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,aAAa,WAAW,WAAW;AACpD,WAAO,YAAY;AAAA,MACjB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,WAAW,WAAW,SAAS;AAChD,WAAO,UAAU;AAAA,MACf,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;AAUO,SAAS,eAAe,QAA2C;AACxE,QAAM,SAAmB,CAAC;AAG1B,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAEA,MAAI,CAAC,OAAO,WAAW;AACrB,WAAO,KAAK,uBAAuB;AAAA,EACrC;AAEA,MAAI,CAAC,OAAO,UAAU;AACpB,WAAO,KAAK,sBAAsB;AAAA,EACpC,OAAO;AAEL,QAAI,OAAO,OAAO,aAAa,UAAU;AACvC,aAAO,KAAK,4BAA4B;AAAA,IAC1C,WAAW,OAAO,KAAK,OAAO,QAAQ,EAAE,WAAW,G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AQ,OAAO;AAAA,IACxB,WAAW,QAAQ,OAAO;AAAA,IAC1B,eAAe,QAAQ,OAAO;AAAA,IAC9B;AAAA,IACA,SAAS,QAAQ,OAAO;AAAA,IACxB;AAAA,EACF;AACF;AAUO,SAAS,+BAAsC;AACpD,QAAM,EAAE,SAAS,IAAI,qBAAqB;AAC1C,SAAO;AACT;AAKO,SAAS,8BAAkD;AAChE,QAAM,EAAE,iBAAiB,IAAI,gBAAgB;AAC7C,SAAO,iBAAiB;AAC1B;AAKO,SAAS,0BAAyC;AACvD,QAAM,EAAE,YAAY,IAAI,gBAAgB;AACxC,SAAO,YAAY;AACrB;AAqCO,SAAS,uBAAuB;AACrC,QAAM,EAAE,cAAc,cAAc,OAAO,IAAI,gBAAgB;AAC/D,SAAO,EAAE,cAAc,cAAc,OAAO;AAC9C;;;AC1dO,SAAS,WAAwB;AACtC,SAAO,qBAAqB;AAC9B;AAwBO,SAAS,mBAA0B;AACxC,SAAO,6BAA6B;AACtC;AAuBO,SAAS,kBAAsC;AACpD,SAAO,4BAA4B;AACrC;AAuBO,SAAS,cAA6B;AAC3C,SAAO,wBAAwB;AACjC;AA8BO,SAASC,wBAAuB;AACrC,SAAO,qBAAiC;AAC1C;AAKO,IAAM,cAAc;","names":["useDubheConfigUpdate","import_react","useDubheConfigUpdate"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/sui/config.ts","../src/sui/utils.ts","../src/sui/provider.tsx","../src/sui/hooks.ts"],"sourcesContent":["/**\n * @0xobelisk/react - Modern Dubhe React Integration\n *\n * 🚀 Provides simple, powerful React experience for multi-chain blockchain development\n *\n * Currently supported:\n * - Sui blockchain ✅\n * - Aptos blockchain (coming soon)\n * - Initia blockchain (coming soon)\n */\n\n// Sui integration\nexport * from './sui/index';\n// TODO: Future extensions\n// export * from './aptos/index';\n// export * from './initia/index';\n","/**\n * Configuration Management for Dubhe React Integration\n *\n * Features:\n * - Type-safe configuration interface\n * - Configuration validation and error handling\n * - Smart merging of defaults and explicit config\n * - No environment variable handling (developers should handle environment variables themselves)\n */\n\nimport { useMemo } from 'react';\nimport type { DubheConfig } from './types';\nimport { mergeConfigurations, validateConfig } from './utils';\n\n/**\n * Default configuration object with sensible defaults\n */\nexport const DEFAULT_CONFIG: Partial<DubheConfig> = {\n endpoints: {\n graphql: 'http://localhost:4000/graphql',\n websocket: 'ws://localhost:4000/graphql'\n },\n options: {\n enableBatchOptimization: true,\n cacheTimeout: 5000,\n debounceMs: 100,\n reconnectOnError: true\n }\n};\n\n/**\n * Configuration Hook: useDubheConfig\n *\n * Merges defaults with explicit configuration provided by the developer\n *\n * Note: Environment variables should be handled by the developer before passing to this hook\n *\n * @param config - Complete or partial configuration object\n * @returns Complete, validated DubheConfig\n *\n * @example\n * ```typescript\n * // Basic usage with explicit config\n * const config = useDubheConfig({\n * network: 'testnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY // Handle env vars yourself\n * }\n * });\n *\n * // With helper function to handle environment variables\n * const getConfigFromEnv = () => ({\n * network: process.env.NEXT_PUBLIC_NETWORK as NetworkType,\n * packageId: process.env.NEXT_PUBLIC_PACKAGE_ID,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * });\n *\n * const config = useDubheConfig({\n * ...getConfigFromEnv(),\n * metadata: contractMetadata\n * });\n * ```\n */\nexport function useDubheConfig(config: Partial<DubheConfig>): DubheConfig {\n // Memoize the stringified config to detect actual changes\n const configKey = useMemo(() => {\n return JSON.stringify(config);\n }, [config]);\n\n return useMemo(() => {\n // Merge configurations: defaults -> user provided config\n const mergedConfig = mergeConfigurations(DEFAULT_CONFIG, config);\n\n // Validate the final configuration\n const validatedConfig = validateConfig(mergedConfig);\n\n // if (process.env.NODE_ENV === 'development') {\n // console.log('🔧 Dubhe Config:', {\n // ...validatedConfig,\n // credentials: validatedConfig.credentials?.secretKey ? '[REDACTED]' : undefined\n // });\n // }\n\n return validatedConfig;\n }, [configKey]);\n}\n","/**\n * Utility Functions for Dubhe Configuration Management\n *\n * Features:\n * - Configuration validation and error handling\n * - Smart configuration merging with proper type safety\n * - Type-safe configuration validation\n */\n\nimport type { DubheConfig } from './types';\n\n/**\n * Merge multiple configuration objects with proper deep merging\n * Later configurations override earlier ones\n *\n * @param baseConfig - Base configuration (usually defaults)\n * @param overrideConfig - Override configuration (user provided)\n * @returns Merged configuration\n */\nexport function mergeConfigurations(\n baseConfig: Partial<DubheConfig>,\n overrideConfig?: Partial<DubheConfig>\n): Partial<DubheConfig> {\n if (!overrideConfig) {\n return { ...baseConfig };\n }\n\n const result: Partial<DubheConfig> = { ...baseConfig };\n\n // Merge top-level properties\n Object.assign(result, overrideConfig);\n\n // Deep merge nested objects\n if (overrideConfig.credentials || baseConfig.credentials) {\n result.credentials = {\n ...baseConfig.credentials,\n ...overrideConfig.credentials\n };\n }\n\n if (overrideConfig.endpoints || baseConfig.endpoints) {\n result.endpoints = {\n ...baseConfig.endpoints,\n ...overrideConfig.endpoints\n };\n }\n\n if (overrideConfig.options || baseConfig.options) {\n result.options = {\n ...baseConfig.options,\n ...overrideConfig.options\n };\n }\n\n return result;\n}\n\n/**\n * Validate configuration and ensure required fields are present\n * Throws descriptive errors for missing required fields\n *\n * @param config - Configuration to validate\n * @returns Validated and typed configuration\n * @throws Error if required fields are missing or invalid\n */\nexport function validateConfig(config: Partial<DubheConfig>): DubheConfig {\n const errors: string[] = [];\n\n // Check required fields\n if (!config.network) {\n errors.push('network is required');\n }\n\n if (!config.packageId) {\n errors.push('packageId is required');\n }\n\n if (!config.metadata) {\n errors.push('metadata is required');\n } else {\n // Basic metadata validation\n if (typeof config.metadata !== 'object') {\n errors.push('metadata must be an object');\n } else if (Object.keys(config.metadata).length === 0) {\n errors.push('metadata cannot be empty');\n }\n }\n\n // Validate network type\n if (config.network && !['mainnet', 'testnet', 'devnet', 'localnet'].includes(config.network)) {\n errors.push(\n `invalid network: ${config.network}. Must be one of: mainnet, testnet, devnet, localnet`\n );\n }\n\n // Validate package ID format (enhanced check)\n if (config.packageId) {\n if (!config.packageId.startsWith('0x')) {\n errors.push('packageId must start with 0x');\n } else if (config.packageId.length < 3) {\n errors.push('packageId must be longer than 0x');\n } else if (!/^0x[a-fA-F0-9]+$/.test(config.packageId)) {\n errors.push('packageId must contain only hexadecimal characters after 0x');\n }\n }\n\n // Validate dubheMetadata if provided\n if (config.dubheMetadata !== undefined) {\n if (typeof config.dubheMetadata !== 'object' || config.dubheMetadata === null) {\n errors.push('dubheMetadata must be an object');\n } else if (!config.dubheMetadata.components && !config.dubheMetadata.resources) {\n errors.push('dubheMetadata must contain components or resources');\n }\n }\n\n // Validate credentials if provided\n if (config.credentials) {\n if (config.credentials.secretKey && typeof config.credentials.secretKey !== 'string') {\n errors.push('credentials.secretKey must be a string');\n }\n if (config.credentials.mnemonics && typeof config.credentials.mnemonics !== 'string') {\n errors.push('credentials.mnemonics must be a string');\n }\n }\n\n // Validate URLs if provided\n if (config.endpoints?.graphql && !isValidUrl(config.endpoints.graphql)) {\n errors.push('endpoints.graphql must be a valid URL');\n }\n\n if (config.endpoints?.websocket && !isValidUrl(config.endpoints.websocket)) {\n errors.push('endpoints.websocket must be a valid URL');\n }\n\n if (config.endpoints?.grpc && !isValidUrl(config.endpoints.grpc)) {\n errors.push('endpoints.grpc must be a valid URL');\n }\n\n // Validate fullnodeUrls if provided\n if (config.endpoints?.fullnodeUrls) {\n if (!Array.isArray(config.endpoints.fullnodeUrls)) {\n errors.push('endpoints.fullnodeUrls must be an array');\n } else if (config.endpoints.fullnodeUrls.length === 0) {\n errors.push('endpoints.fullnodeUrls cannot be empty if provided');\n } else {\n config.endpoints.fullnodeUrls.forEach((url, index) => {\n if (!isValidUrl(url)) {\n errors.push(`endpoints.fullnodeUrls[${index}] must be a valid URL: ${url}`);\n }\n });\n }\n }\n\n // Validate numeric options\n if (\n config.options?.cacheTimeout !== undefined &&\n (typeof config.options.cacheTimeout !== 'number' || config.options.cacheTimeout < 0)\n ) {\n errors.push('options.cacheTimeout must be a non-negative number');\n }\n\n if (\n config.options?.debounceMs !== undefined &&\n (typeof config.options.debounceMs !== 'number' || config.options.debounceMs < 0)\n ) {\n errors.push('options.debounceMs must be a non-negative number');\n }\n\n if (errors.length > 0) {\n const errorMessage = `Invalid Dubhe configuration (${errors.length} error${\n errors.length > 1 ? 's' : ''\n }):\\n${errors.map((e) => `- ${e}`).join('\\n')}`;\n console.error('Configuration validation failed:', { errors, config });\n throw new Error(errorMessage);\n }\n\n return config as DubheConfig;\n}\n\n/**\n * Simple URL validation helper\n *\n * @param url - URL string to validate\n * @returns true if URL is valid, false otherwise\n */\nfunction isValidUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Generate a configuration summary for debugging\n * Hides sensitive information like private keys\n *\n * @param config - Configuration to summarize\n * @returns Safe configuration summary\n */\nexport function getConfigSummary(config: DubheConfig): object {\n return {\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n hasMetadata: !!config.metadata,\n hasDubheMetadata: !!config.dubheMetadata,\n hasCredentials: !!config.credentials?.secretKey,\n endpoints: config.endpoints,\n options: config.options\n };\n}\n","/**\n * Dubhe Provider - useRef Pattern for Client Management\n *\n * Features:\n * - 🎯 Single client instances across application lifecycle\n * - ⚡ useRef-based storage (no re-initialization on re-renders)\n * - 🔧 Provider pattern for dependency injection\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing\n */\n\nimport {\n createContext,\n useContext,\n useRef,\n ReactNode,\n useState,\n useCallback,\n useEffect\n} from 'react';\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient, DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld, DubheECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport { useDubheConfig } from './config';\nimport type { DubheConfig, DubheReturn } from './types';\n\n/**\n * Context interface for Dubhe client instances\n * All clients are stored using useRef to ensure single initialization\n */\ninterface DubheContextValue {\n getContract: () => Dubhe;\n getGraphqlClient: () => DubheGraphqlClient;\n getGrpcClient: () => DubheGrpcClient;\n getEcsWorld: () => DubheECSWorld;\n getAddress: () => string;\n getMetrics: () => {\n initTime: number;\n requestCount: number;\n lastActivity: number;\n };\n config: DubheConfig;\n updateConfig: (newConfig: Partial<DubheConfig>) => void;\n resetClients: (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => void;\n}\n\n/**\n * Context for sharing Dubhe clients across the application\n * Uses useRef pattern to ensure clients are created only once\n */\nconst DubheContext = createContext<DubheContextValue | null>(null);\n\n/**\n * Props interface for DubheProvider component\n */\ninterface DubheProviderProps {\n /** Configuration for Dubhe initialization */\n config: Partial<DubheConfig>;\n /** Child components that will have access to Dubhe clients */\n children: ReactNode;\n}\n\n/**\n * DubheProvider Component - useRef Pattern Implementation\n *\n * This Provider uses useRef to store client instances, ensuring they are:\n * 1. Created only once during component lifecycle\n * 2. Persisted across re-renders without re-initialization\n * 3. Shared efficiently via React Context\n *\n * Key advantages over useMemo:\n * - useRef guarantees single initialization (useMemo can re-run on dependency changes)\n * - No dependency array needed (eliminates potential re-initialization bugs)\n * - Better performance for heavy client objects\n * - Clearer separation of concerns via Provider pattern\n *\n * @param props - Provider props containing config and children\n * @returns Provider component wrapping children with Dubhe context\n *\n * @example\n * ```typescript\n * // App root setup\n * function App() {\n * const dubheConfig = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={dubheConfig}>\n * <MyApplication />\n * </DubheProvider>\n * );\n * }\n * ```\n */\nexport function DubheProvider({ config, children }: DubheProviderProps) {\n // Use state to manage config for dynamic updates with persistence\n const [currentConfig, setCurrentConfig] = useState<Partial<DubheConfig>>(() => {\n // Try to restore config from localStorage\n if (typeof window !== 'undefined') {\n try {\n const saved = localStorage.getItem('dubhe-config');\n if (saved) {\n const parsedConfig = JSON.parse(saved);\n console.log('Restored Dubhe configuration from localStorage');\n // Important: Explicit config takes precedence over localStorage\n return { ...parsedConfig, ...config };\n }\n } catch (error) {\n console.warn('Failed to restore Dubhe configuration from localStorage', error);\n }\n }\n return config;\n });\n\n // Merge configuration with defaults\n const finalConfig = useDubheConfig(currentConfig);\n\n // Track initialization start time (useRef ensures single timestamp)\n const startTimeRef = useRef<number>(performance.now());\n\n // useRef for contract instance - guarantees single initialization\n // Unlike useMemo, useRef.current is never re-calculated\n const contractRef = useRef<Dubhe | undefined>(undefined);\n const getContract = (): Dubhe => {\n if (!contractRef.current) {\n try {\n console.log('Initializing Dubhe contract instance (one-time)');\n contractRef.current = new Dubhe({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics,\n fullnodeUrls: finalConfig.endpoints?.fullnodeUrls\n });\n } catch (error) {\n console.error('Contract initialization failed:', error);\n throw error;\n }\n }\n return contractRef.current;\n };\n\n // useRef for GraphQL client instance - single initialization guaranteed\n const graphqlClientRef = useRef<DubheGraphqlClient | null>(null);\n const hasInitializedGraphql = useRef(false);\n const getGraphqlClient = (): DubheGraphqlClient => {\n if (!hasInitializedGraphql.current) {\n try {\n console.log('Initializing GraphQL client instance (one-time)');\n graphqlClientRef.current = createDubheGraphqlClient({\n endpoint: finalConfig.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: finalConfig.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: finalConfig.dubheMetadata\n });\n hasInitializedGraphql.current = true;\n } catch (error) {\n console.error('GraphQL client initialization failed:', error);\n throw error;\n }\n }\n return graphqlClientRef.current!;\n };\n\n // useRef for gRPC client instance - single initialization guaranteed\n const grpcClientRef = useRef<DubheGrpcClient | null>(null);\n const hasInitializedGrpc = useRef(false);\n const getGrpcClient = (): DubheGrpcClient => {\n if (!hasInitializedGrpc.current) {\n try {\n console.log('Initializing gRPC client instance (one-time)');\n grpcClientRef.current = new DubheGrpcClient({\n baseUrl: finalConfig.endpoints?.grpc || 'http://localhost:8080'\n });\n hasInitializedGrpc.current = true;\n } catch (error) {\n console.error('gRPC client initialization failed:', error);\n throw error;\n }\n }\n return grpcClientRef.current!;\n };\n\n // useRef for ECS World instance - depends on GraphQL client\n const ecsWorldRef = useRef<DubheECSWorld | null>(null);\n const hasInitializedEcs = useRef(false);\n const getEcsWorld = (): DubheECSWorld => {\n const graphqlClient = getGraphqlClient();\n if (!hasInitializedEcs.current) {\n try {\n console.log('Initializing ECS World instance (one-time)');\n ecsWorldRef.current = createECSWorld(graphqlClient, {\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs ?? 100,\n reconnectOnError: finalConfig.options?.reconnectOnError ?? true\n }\n });\n hasInitializedEcs.current = true;\n } catch (error) {\n console.error('ECS World initialization failed:', error);\n throw error;\n }\n }\n return ecsWorldRef.current!;\n };\n\n // Address getter - calculated from contract\n const getAddress = (): string => {\n return getContract().getAddress();\n };\n\n // Metrics getter - performance tracking\n const getMetrics = () => ({\n initTime: performance.now() - (startTimeRef.current || 0),\n requestCount: 0, // Can be enhanced with actual tracking\n lastActivity: Date.now()\n });\n\n // Selective reset client instances\n const resetClients = useCallback(\n (options?: {\n resetContract?: boolean;\n resetGraphql?: boolean;\n resetGrpc?: boolean;\n resetEcs?: boolean;\n }) => {\n const opts = {\n resetContract: true,\n resetGraphql: true,\n resetGrpc: true,\n resetEcs: true,\n ...options\n };\n\n console.log('Resetting Dubhe client instances', opts);\n\n if (opts.resetContract) {\n contractRef.current = undefined;\n }\n if (opts.resetGraphql) {\n graphqlClientRef.current = null;\n hasInitializedGraphql.current = false;\n }\n if (opts.resetGrpc) {\n grpcClientRef.current = null;\n hasInitializedGrpc.current = false;\n }\n if (opts.resetEcs) {\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n\n startTimeRef.current = performance.now();\n },\n []\n );\n\n // Update config without resetting clients (reactive update)\n const updateConfig = useCallback((newConfig: Partial<DubheConfig>) => {\n console.log('Updating Dubhe configuration (reactive)');\n setCurrentConfig((prev) => {\n const updated = { ...prev, ...newConfig };\n // Persist to localStorage\n if (typeof window !== 'undefined') {\n try {\n localStorage.setItem('dubhe-config', JSON.stringify(updated));\n console.log('Persisted Dubhe configuration to localStorage');\n } catch (error) {\n console.warn('Failed to persist Dubhe configuration', error);\n }\n }\n return updated;\n });\n }, []);\n\n // Reactive configuration updates via useEffect\n\n // Monitor Contract configuration changes\n useEffect(() => {\n if (contractRef.current) {\n console.log('Contract config dependencies changed, updating...');\n contractRef.current.updateConfig({\n networkType: finalConfig.network,\n packageId: finalConfig.packageId,\n metadata: finalConfig.metadata,\n secretKey: finalConfig.credentials?.secretKey,\n mnemonics: finalConfig.credentials?.mnemonics,\n fullnodeUrls: finalConfig.endpoints?.fullnodeUrls\n });\n }\n }, [\n finalConfig.network,\n finalConfig.packageId,\n finalConfig.metadata,\n finalConfig.credentials?.secretKey,\n finalConfig.credentials?.mnemonics,\n finalConfig.endpoints?.fullnodeUrls\n ]);\n\n // Monitor GraphQL endpoint changes\n useEffect(() => {\n if (graphqlClientRef.current) {\n console.log('GraphQL endpoint dependencies changed, updating...');\n graphqlClientRef.current.updateConfig({\n endpoint: finalConfig.endpoints?.graphql,\n subscriptionEndpoint: finalConfig.endpoints?.websocket\n });\n // Reset ECS World when GraphQL endpoints change (needs new connection)\n ecsWorldRef.current = null;\n hasInitializedEcs.current = false;\n }\n }, [finalConfig.endpoints?.graphql, finalConfig.endpoints?.websocket]);\n\n // Monitor GraphQL metadata changes\n useEffect(() => {\n if (graphqlClientRef.current && finalConfig.dubheMetadata) {\n console.log('GraphQL metadata changed, updating...');\n graphqlClientRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata\n });\n // Note: ECS will handle its own metadata update via its useEffect\n }\n }, [finalConfig.dubheMetadata]);\n\n // Monitor gRPC configuration changes\n useEffect(() => {\n if (grpcClientRef.current && finalConfig.endpoints?.grpc) {\n console.log('gRPC config dependencies changed, updating...');\n grpcClientRef.current.updateConfig({ baseUrl: finalConfig.endpoints.grpc });\n }\n }, [finalConfig.endpoints?.grpc]);\n\n // Monitor ECS configuration changes\n useEffect(() => {\n if (ecsWorldRef.current) {\n console.log('ECS config dependencies changed, updating...');\n ecsWorldRef.current.updateConfig({\n dubheMetadata: finalConfig.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: finalConfig.options?.enableBatchOptimization,\n defaultCacheTimeout: finalConfig.options?.cacheTimeout\n },\n subscriptionConfig: {\n defaultDebounceMs: finalConfig.options?.debounceMs,\n reconnectOnError: finalConfig.options?.reconnectOnError\n }\n });\n }\n }, [\n finalConfig.dubheMetadata,\n finalConfig.options?.enableBatchOptimization,\n finalConfig.options?.cacheTimeout,\n finalConfig.options?.debounceMs,\n finalConfig.options?.reconnectOnError\n ]);\n\n // Context value - stable reference (no re-renders for consumers)\n const contextValue: DubheContextValue = {\n getContract,\n getGraphqlClient,\n getGrpcClient,\n getEcsWorld,\n getAddress,\n getMetrics,\n config: finalConfig,\n updateConfig,\n resetClients\n };\n\n return <DubheContext.Provider value={contextValue}>{children}</DubheContext.Provider>;\n}\n\n/**\n * Custom hook to access Dubhe context\n * Provides type-safe access to all Dubhe client instances\n *\n * @returns DubheContextValue with all client getters and config\n * @throws Error if used outside of DubheProvider\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const dubheContext = useDubheContext();\n *\n * const contract = dubheContext.getContract();\n * const graphqlClient = dubheContext.getGraphqlClient();\n * const ecsWorld = dubheContext.getEcsWorld();\n * const address = dubheContext.getAddress();\n *\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubheContext(): DubheContextValue {\n const context = useContext(DubheContext);\n\n if (!context) {\n throw new Error(\n 'useDubheContext must be used within a DubheProvider. ' +\n 'Make sure to wrap your app with <DubheProvider config={...}>'\n );\n }\n\n return context;\n}\n\n/**\n * Enhanced hook that mimics the original useDubhe API\n * Uses the Provider pattern internally but maintains backward compatibility\n *\n * @returns DubheReturn object with all instances and metadata\n *\n * @example\n * ```typescript\n * function MyComponent() {\n * const { contract, graphqlClient, ecsWorld, address } = useDubheFromProvider();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheFromProvider(): DubheReturn {\n const context = useDubheContext();\n\n // Get instances (lazy initialization via getters)\n const contract = context.getContract();\n const graphqlClient = context.getGraphqlClient();\n const grpcClient = context.getGrpcClient();\n const ecsWorld = context.getEcsWorld();\n const address = context.getAddress();\n const metrics = context.getMetrics();\n\n return {\n contract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: context.config.metadata,\n network: context.config.network,\n packageId: context.config.packageId,\n dubheSchemaId: context.config.dubheSchemaId,\n address,\n options: context.config.options,\n metrics\n };\n}\n\n/**\n * Individual client hooks for components that only need specific instances\n * These are more efficient than useDubheFromProvider for single-client usage\n */\n\n/**\n * Hook for accessing only the Dubhe contract instance\n */\nexport function useDubheContractFromProvider(): Dubhe {\n const { contract } = useDubheFromProvider();\n return contract;\n}\n\n/**\n * Hook for accessing only the GraphQL client instance\n */\nexport function useDubheGraphQLFromProvider(): DubheGraphqlClient {\n const { getGraphqlClient } = useDubheContext();\n return getGraphqlClient();\n}\n\n/**\n * Hook for accessing only the ECS World instance\n */\nexport function useDubheECSFromProvider(): DubheECSWorld {\n const { getEcsWorld } = useDubheContext();\n return getEcsWorld();\n}\n\n/**\n * Hook for accessing only the gRPC client instance\n */\nexport function useDubheGrpcFromProvider(): DubheGrpcClient {\n const { getGrpcClient } = useDubheContext();\n return getGrpcClient();\n}\n\n/**\n * Hook for accessing configuration update methods\n *\n * @returns Object with updateConfig and resetClients methods\n *\n * @example\n * ```typescript\n * function ConfigUpdater() {\n * const { updateConfig, resetClients, config } = useDubheConfigUpdate();\n *\n * const switchNetwork = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xnew...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Current network: {config.network}</p>\n * <button onClick={switchNetwork}>Switch to Testnet</button>\n * <button onClick={resetClients}>Reset Clients</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n const { updateConfig, resetClients, config } = useDubheContext();\n return { updateConfig, resetClients, config };\n}\n","/**\n * Modern Dubhe React Hooks - Provider Pattern\n *\n * Features:\n * - 🎯 Simple API design with Provider pattern\n * - ⚡ Single client initialization with useRef\n * - 🔧 Configuration-driven setup (developers handle environment variables themselves)\n * - 🛡️ Complete type safety with strict TypeScript\n * - 📦 Context-based client sharing across components\n */\nimport { Dubhe } from '@0xobelisk/sui-client';\nimport type { DubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport type { DubheECSWorld } from '@0xobelisk/ecs';\n\nimport {\n useDubheFromProvider,\n useDubheContractFromProvider,\n useDubheGraphQLFromProvider,\n useDubheECSFromProvider,\n useDubheConfigUpdate as useDubheConfigUpdateFromProvider\n} from './provider';\nimport type { DubheReturn } from './types';\n\n/**\n * Primary Hook: useDubhe\n *\n * Uses Provider pattern to access shared Dubhe clients with guaranteed single initialization.\n * Must be used within a DubheProvider.\n *\n * @returns Complete Dubhe ecosystem with contract, GraphQL, ECS, and metadata\n *\n * @example\n * ```typescript\n * // App setup with Provider\n * function App() {\n * const config = {\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata: contractMetadata,\n * credentials: {\n * secretKey: process.env.NEXT_PUBLIC_PRIVATE_KEY\n * }\n * };\n *\n * return (\n * <DubheProvider config={config}>\n * <MyDApp />\n * </DubheProvider>\n * );\n * }\n *\n * // Component usage\n * function MyDApp() {\n * const { contract, address } = useDubhe();\n * return <div>Connected as {address}</div>;\n * }\n * ```\n */\nexport function useDubhe(): DubheReturn {\n return useDubheFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheContract\n *\n * Returns only the Dubhe contract instance from Provider context.\n * More efficient than useDubhe() when only contract access is needed.\n *\n * @returns Dubhe contract instance\n *\n * @example\n * ```typescript\n * function TransactionComponent() {\n * const contract = useDubheContract();\n *\n * const handleTransaction = async () => {\n * const tx = new Transaction();\n * await contract.tx.my_system.my_method({ tx });\n * };\n *\n * return <button onClick={handleTransaction}>Execute</button>;\n * }\n * ```\n */\nexport function useDubheContract(): Dubhe {\n return useDubheContractFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheGraphQL\n *\n * Returns only the GraphQL client from Provider context.\n * More efficient than useDubhe() when only GraphQL access is needed.\n *\n * @returns GraphQL client instance (always available with default localhost endpoint)\n *\n * @example\n * ```typescript\n * function DataComponent() {\n * const graphqlClient = useDubheGraphQL();\n *\n * useEffect(() => {\n * graphqlClient.query({ ... }).then(setData);\n * }, [graphqlClient]);\n *\n * return <div>{data && JSON.stringify(data)}</div>;\n * }\n * ```\n */\nexport function useDubheGraphQL(): DubheGraphqlClient {\n return useDubheGraphQLFromProvider();\n}\n\n/**\n * Individual Instance Hook: useDubheECS\n *\n * Returns only the ECS World instance from Provider context.\n * More efficient than useDubhe() when only ECS access is needed.\n *\n * @returns ECS World instance (always available, depends on GraphQL client)\n *\n * @example\n * ```typescript\n * function ECSComponent() {\n * const ecsWorld = useDubheECS();\n *\n * useEffect(() => {\n * ecsWorld.getComponent('MyComponent').then(setComponent);\n * }, [ecsWorld]);\n *\n * return <div>ECS Component Data</div>;\n * }\n * ```\n */\nexport function useDubheECS(): DubheECSWorld {\n return useDubheECSFromProvider();\n}\n\n/**\n * Hook for dynamic configuration updates\n *\n * Provides methods to update provider configuration at runtime\n *\n * @returns Object with updateConfig, resetClients methods and current config\n *\n * @example\n * ```typescript\n * function NetworkSwitcher() {\n * const { updateConfig, config } = useDubheConfigUpdate();\n *\n * const switchToTestnet = () => {\n * updateConfig({\n * network: 'testnet',\n * packageId: '0xTestnetPackageId...'\n * });\n * };\n *\n * return (\n * <div>\n * <p>Network: {config.network}</p>\n * <button onClick={switchToTestnet}>Switch to Testnet</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useDubheConfigUpdate() {\n return useDubheConfigUpdateFromProvider();\n}\n\n/**\n * Compatibility alias for useDubhe\n */\nexport const useContract = useDubhe;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,mBAAwB;;;ACSjB,SAAS,oBACd,YACA,gBACsB;AACtB,MAAI,CAAC,gBAAgB;AACnB,WAAO,EAAE,GAAG,WAAW;AAAA,EACzB;AAEA,QAAM,SAA+B,EAAE,GAAG,WAAW;AAGrD,SAAO,OAAO,QAAQ,cAAc;AAGpC,MAAI,eAAe,eAAe,WAAW,aAAa;AACxD,WAAO,cAAc;AAAA,MACnB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,aAAa,WAAW,WAAW;AACpD,WAAO,YAAY;AAAA,MACjB,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,eAAe,WAAW,WAAW,SAAS;AAChD,WAAO,UAAU;AAAA,MACf,GAAG,WAAW;AAAA,MACd,GAAG,eAAe;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AACT;AAUO,SAAS,eAAe,QAA2C;AACxE,QAAM,SAAmB,CAAC;AAG1B,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO,KAAK,qBAAqB;AAAA,EACnC;AAEA,MAAI,CAAC,O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xC,SAAO,YAAY;AACrB;AAqCO,SAAS,uBAAuB;AACrC,QAAM,EAAE,cAAc,cAAc,OAAO,IAAI,gBAAgB;AAC/D,SAAO,EAAE,cAAc,cAAc,OAAO;AAC9C;;;AC9dO,SAAS,WAAwB;AACtC,SAAO,qBAAqB;AAC9B;AAwBO,SAAS,mBAA0B;AACxC,SAAO,6BAA6B;AACtC;AAuBO,SAAS,kBAAsC;AACpD,SAAO,4BAA4B;AACrC;AAuBO,SAAS,cAA6B;AAC3C,SAAO,wBAAwB;AACjC;AA8BO,SAASC,wBAAuB;AACrC,SAAO,qBAAiC;AAC1C;AAKO,IAAM,cAAc;","names":["useDubheConfigUpdate","import_react","useDubheConfigUpdate"]}
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  useDubheECS,
12
12
  useDubheGraphQL,
13
13
  validateConfig
14
- } from "./chunk-YQUGWGOF.mjs";
14
+ } from "./chunk-Q5VWR7TU.mjs";
15
15
  export {
16
16
  DEFAULT_CONFIG,
17
17
  DubheProvider,
@@ -11,27 +11,35 @@ import { ReactNode } from 'react';
11
11
  type NetworkType = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
12
12
  /**
13
13
  * Modern Dubhe client configuration for auto-initialization
14
+ * Aligned with @0xobelisk/client configuration for consistency
14
15
  */
15
16
  interface DubheConfig {
16
17
  /** Network type */
17
18
  network: NetworkType;
18
19
  /** Contract package ID */
19
20
  packageId: string;
20
- /** Dubhe Schema ID (optional, for enhanced features) */
21
- dubheSchemaId: string;
22
21
  /** Contract metadata (required for contract instantiation) */
23
22
  metadata: any;
23
+ /** Dubhe Schema ID (optional, for enhanced features) */
24
+ dubheSchemaId?: string;
24
25
  /** Dubhe metadata (enables GraphQL/ECS features) */
25
- dubheMetadata: any;
26
+ dubheMetadata?: any;
26
27
  /** Authentication credentials */
27
28
  credentials?: {
29
+ /** Private key (base64 or hex string) */
28
30
  secretKey?: string;
31
+ /** Mnemonic phrase (12 or 24 words) */
29
32
  mnemonics?: string;
30
33
  };
31
34
  /** Service endpoints configuration */
32
35
  endpoints?: {
36
+ /** Full node RPC URLs (can provide multiple for redundancy) */
37
+ fullnodeUrls?: string[];
38
+ /** GraphQL endpoint URL */
33
39
  graphql?: string;
40
+ /** WebSocket endpoint URL for subscriptions */
34
41
  websocket?: string;
42
+ /** gRPC endpoint URL */
35
43
  grpc?: string;
36
44
  };
37
45
  /** Performance and behavior options */
@@ -46,6 +54,10 @@ interface DubheConfig {
46
54
  reconnectOnError?: boolean;
47
55
  };
48
56
  }
57
+ /**
58
+ * Type alias for consistency with @0xobelisk/client package
59
+ */
60
+ type ClientConfig = DubheConfig;
49
61
  /**
50
62
  * Return type for the main useDubhe hook
51
63
  */
@@ -372,4 +384,4 @@ declare function useDubheConfigUpdate(): {
372
384
  */
373
385
  declare const useContract: typeof useDubhe;
374
386
 
375
- export { type ContractReturn, DEFAULT_CONFIG, type DubheConfig, DubheProvider, type DubheReturn, type NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig };
387
+ export { type ClientConfig, type ContractReturn, DEFAULT_CONFIG, type DubheConfig, DubheProvider, type DubheReturn, type NetworkType, getConfigSummary, mergeConfigurations, useContract, useDubhe, useDubheConfig, useDubheConfigUpdate, useDubheContract, useDubheECS, useDubheGraphQL, validateConfig };