@varity-labs/sdk 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +31 -0
- package/README.md +253 -0
- package/dist/analytics/index.d.ts +7 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/tracker.d.ts +128 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +203 -0
- package/dist/blockchain/BlockchainService.d.ts +100 -0
- package/dist/blockchain/BlockchainService.d.ts.map +1 -0
- package/dist/blockchain/BlockchainService.js +188 -0
- package/dist/blockchain/NFTLicensingService.d.ts +69 -0
- package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
- package/dist/blockchain/NFTLicensingService.js +136 -0
- package/dist/blockchain/RevenueSplitService.d.ts +71 -0
- package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
- package/dist/blockchain/RevenueSplitService.js +111 -0
- package/dist/blockchain/index.d.ts +48 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +46 -0
- package/dist/blockchain/types.d.ts +63 -0
- package/dist/blockchain/types.d.ts.map +1 -0
- package/dist/blockchain/types.js +6 -0
- package/dist/chains/arbitrum.d.ts +89 -0
- package/dist/chains/arbitrum.d.ts.map +1 -0
- package/dist/chains/arbitrum.js +134 -0
- package/dist/chains/base.d.ts +84 -0
- package/dist/chains/base.d.ts.map +1 -0
- package/dist/chains/base.js +131 -0
- package/dist/chains/index.d.ts +36 -0
- package/dist/chains/index.d.ts.map +1 -0
- package/dist/chains/index.js +32 -0
- package/dist/chains/registry.d.ts +113 -0
- package/dist/chains/registry.d.ts.map +1 -0
- package/dist/chains/registry.js +201 -0
- package/dist/chains/varityL3.d.ts +81 -0
- package/dist/chains/varityL3.d.ts.map +1 -0
- package/dist/chains/varityL3.js +125 -0
- package/dist/cli/commands/clone.d.ts +8 -0
- package/dist/cli/commands/clone.d.ts.map +1 -0
- package/dist/cli/commands/clone.js +391 -0
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +40 -0
- package/dist/cli/commands/generate.d.ts +8 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +303 -0
- package/dist/cli/commands/init.d.ts +8 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +317 -0
- package/dist/cli/commands/validate.d.ts +8 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +69 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +33 -0
- package/dist/cli/utils/logger.d.ts +17 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +35 -0
- package/dist/cli/utils/prompts.d.ts +21 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +103 -0
- package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
- package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
- package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
- package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
- package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
- package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
- package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
- package/dist/contracts/addresses.d.ts +88 -0
- package/dist/contracts/addresses.d.ts.map +1 -0
- package/dist/contracts/addresses.js +94 -0
- package/dist/contracts/index.d.ts +7 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +6 -0
- package/dist/core/VaritySDK.d.ts +177 -0
- package/dist/core/VaritySDK.d.ts.map +1 -0
- package/dist/core/VaritySDK.js +325 -0
- package/dist/core/config.d.ts +120 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +187 -0
- package/dist/core/credentials-proxy.d.ts +157 -0
- package/dist/core/credentials-proxy.d.ts.map +1 -0
- package/dist/core/credentials-proxy.js +345 -0
- package/dist/core/credentials.d.ts +219 -0
- package/dist/core/credentials.d.ts.map +1 -0
- package/dist/core/credentials.js +345 -0
- package/dist/core/template-loader.d.ts +15 -0
- package/dist/core/template-loader.d.ts.map +1 -0
- package/dist/core/template-loader.js +380 -0
- package/dist/core/template.d.ts +321 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +189 -0
- package/dist/core/types.d.ts +572 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +52 -0
- package/dist/dev/dev-server.d.ts +16 -0
- package/dist/dev/dev-server.d.ts.map +1 -0
- package/dist/dev/dev-server.js +119 -0
- package/dist/generators/contracts/generator.d.ts +21 -0
- package/dist/generators/contracts/generator.d.ts.map +1 -0
- package/dist/generators/contracts/generator.js +252 -0
- package/dist/generators/tests/generator.d.ts +20 -0
- package/dist/generators/tests/generator.d.ts.map +1 -0
- package/dist/generators/tests/generator.js +375 -0
- package/dist/generators/types/generator.d.ts +19 -0
- package/dist/generators/types/generator.d.ts.map +1 -0
- package/dist/generators/types/generator.js +165 -0
- package/dist/generators/ui/component-generator.d.ts +20 -0
- package/dist/generators/ui/component-generator.d.ts.map +1 -0
- package/dist/generators/ui/component-generator.js +749 -0
- package/dist/generators/ui/dashboard-generator.d.ts +20 -0
- package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
- package/dist/generators/ui/dashboard-generator.js +349 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
- package/dist/modules/analytics/AnalyticsModule.js +274 -0
- package/dist/modules/analytics/index.d.ts +3 -0
- package/dist/modules/analytics/index.d.ts.map +1 -0
- package/dist/modules/analytics/index.js +1 -0
- package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
- package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
- package/dist/modules/auth/AccessKeyModule.js +322 -0
- package/dist/modules/auth/AuthModule.d.ts +133 -0
- package/dist/modules/auth/AuthModule.d.ts.map +1 -0
- package/dist/modules/auth/AuthModule.js +214 -0
- package/dist/modules/auth/index.d.ts +8 -0
- package/dist/modules/auth/index.d.ts.map +1 -0
- package/dist/modules/auth/index.js +6 -0
- package/dist/modules/cache/CacheModule.d.ts +279 -0
- package/dist/modules/cache/CacheModule.d.ts.map +1 -0
- package/dist/modules/cache/CacheModule.js +493 -0
- package/dist/modules/cache/index.d.ts +3 -0
- package/dist/modules/cache/index.d.ts.map +1 -0
- package/dist/modules/cache/index.js +1 -0
- package/dist/modules/compute/ComputeModule.d.ts +226 -0
- package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
- package/dist/modules/compute/ComputeModule.js +379 -0
- package/dist/modules/compute/index.d.ts +6 -0
- package/dist/modules/compute/index.d.ts.map +1 -0
- package/dist/modules/compute/index.js +4 -0
- package/dist/modules/contracts/ContractsModule.d.ts +164 -0
- package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
- package/dist/modules/contracts/ContractsModule.js +242 -0
- package/dist/modules/contracts/index.d.ts +6 -0
- package/dist/modules/contracts/index.d.ts.map +1 -0
- package/dist/modules/contracts/index.js +4 -0
- package/dist/modules/export/ExportModule.d.ts +346 -0
- package/dist/modules/export/ExportModule.d.ts.map +1 -0
- package/dist/modules/export/ExportModule.js +432 -0
- package/dist/modules/export/index.d.ts +3 -0
- package/dist/modules/export/index.d.ts.map +1 -0
- package/dist/modules/export/index.js +1 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
- package/dist/modules/forecasting/ForecastingModule.js +310 -0
- package/dist/modules/forecasting/index.d.ts +3 -0
- package/dist/modules/forecasting/index.d.ts.map +1 -0
- package/dist/modules/forecasting/index.js +1 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
- package/dist/modules/monitoring/MonitoringModule.js +483 -0
- package/dist/modules/monitoring/index.d.ts +3 -0
- package/dist/modules/monitoring/index.d.ts.map +1 -0
- package/dist/modules/monitoring/index.js +1 -0
- package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
- package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
- package/dist/modules/notifications/NotificationsModule.js +418 -0
- package/dist/modules/notifications/index.d.ts +3 -0
- package/dist/modules/notifications/index.d.ts.map +1 -0
- package/dist/modules/notifications/index.js +1 -0
- package/dist/modules/oracle/OracleModule.d.ts +110 -0
- package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
- package/dist/modules/oracle/OracleModule.js +151 -0
- package/dist/modules/oracle/index.d.ts +6 -0
- package/dist/modules/oracle/index.d.ts.map +1 -0
- package/dist/modules/oracle/index.js +4 -0
- package/dist/modules/storage/S3Module.d.ts +377 -0
- package/dist/modules/storage/S3Module.d.ts.map +1 -0
- package/dist/modules/storage/S3Module.js +680 -0
- package/dist/modules/storage/StorageModule.d.ts +157 -0
- package/dist/modules/storage/StorageModule.d.ts.map +1 -0
- package/dist/modules/storage/StorageModule.js +302 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
- package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
- package/dist/modules/storage/adapters/index.d.ts +12 -0
- package/dist/modules/storage/adapters/index.d.ts.map +1 -0
- package/dist/modules/storage/adapters/index.js +12 -0
- package/dist/modules/storage/index.d.ts +16 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +15 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
- package/dist/modules/storage/tiering/MetadataStore.js +535 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
- package/dist/modules/storage/tiering/TieringEngine.js +419 -0
- package/dist/modules/storage/tiering/example.d.ts +8 -0
- package/dist/modules/storage/tiering/example.d.ts.map +1 -0
- package/dist/modules/storage/tiering/example.js +250 -0
- package/dist/modules/storage/tiering/index.d.ts +17 -0
- package/dist/modules/storage/tiering/index.d.ts.map +1 -0
- package/dist/modules/storage/tiering/index.js +13 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
- package/dist/modules/webhooks/WebhooksModule.js +359 -0
- package/dist/modules/webhooks/index.d.ts +3 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -0
- package/dist/modules/webhooks/index.js +1 -0
- package/dist/modules/zk/ZKModule.d.ts +153 -0
- package/dist/modules/zk/ZKModule.d.ts.map +1 -0
- package/dist/modules/zk/ZKModule.js +262 -0
- package/dist/modules/zk/index.d.ts +7 -0
- package/dist/modules/zk/index.d.ts.map +1 -0
- package/dist/modules/zk/index.js +4 -0
- package/dist/thirdweb/BridgeClient.d.ts +228 -0
- package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
- package/dist/thirdweb/BridgeClient.js +160 -0
- package/dist/thirdweb/EngineClient.d.ts +396 -0
- package/dist/thirdweb/EngineClient.d.ts.map +1 -0
- package/dist/thirdweb/EngineClient.js +386 -0
- package/dist/thirdweb/GatewayClient.d.ts +190 -0
- package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
- package/dist/thirdweb/GatewayClient.js +257 -0
- package/dist/thirdweb/NebulaClient.d.ts +292 -0
- package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
- package/dist/thirdweb/NebulaClient.js +180 -0
- package/dist/thirdweb/StorageClient.d.ts +445 -0
- package/dist/thirdweb/StorageClient.d.ts.map +1 -0
- package/dist/thirdweb/StorageClient.js +405 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
- package/dist/thirdweb/ThirdwebWrapper.js +332 -0
- package/dist/thirdweb/index.d.ts +21 -0
- package/dist/thirdweb/index.d.ts.map +1 -0
- package/dist/thirdweb/index.js +28 -0
- package/dist/thirdweb/varity-chain.d.ts +48 -0
- package/dist/thirdweb/varity-chain.d.ts.map +1 -0
- package/dist/thirdweb/varity-chain.js +64 -0
- package/dist/thirdweb/x402Client.d.ts +319 -0
- package/dist/thirdweb/x402Client.d.ts.map +1 -0
- package/dist/thirdweb/x402Client.js +223 -0
- package/dist/tracking/gasTracker.d.ts +158 -0
- package/dist/tracking/gasTracker.d.ts.map +1 -0
- package/dist/tracking/gasTracker.js +227 -0
- package/dist/tracking/index.d.ts +10 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/index.js +8 -0
- package/dist/tracking/types.d.ts +327 -0
- package/dist/tracking/types.d.ts.map +1 -0
- package/dist/tracking/types.js +8 -0
- package/dist/ui/components/ChartWidget.d.ts +36 -0
- package/dist/ui/components/ChartWidget.d.ts.map +1 -0
- package/dist/ui/components/ChartWidget.js +82 -0
- package/dist/ui/components/DashboardLayout.d.ts +41 -0
- package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
- package/dist/ui/components/DashboardLayout.js +102 -0
- package/dist/ui/components/DataTable.d.ts +49 -0
- package/dist/ui/components/DataTable.d.ts.map +1 -0
- package/dist/ui/components/DataTable.js +96 -0
- package/dist/ui/components/EntityForm.d.ts +60 -0
- package/dist/ui/components/EntityForm.d.ts.map +1 -0
- package/dist/ui/components/EntityForm.js +182 -0
- package/dist/ui/components/KPICard.d.ts +29 -0
- package/dist/ui/components/KPICard.d.ts.map +1 -0
- package/dist/ui/components/KPICard.js +61 -0
- package/dist/ui/components/Modal.d.ts +34 -0
- package/dist/ui/components/Modal.d.ts.map +1 -0
- package/dist/ui/components/Modal.js +30 -0
- package/dist/ui/components/index.d.ts +18 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +11 -0
- package/dist/validation/template-validator.d.ts +25 -0
- package/dist/validation/template-validator.d.ts.map +1 -0
- package/dist/validation/template-validator.js +305 -0
- package/package.json +102 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity L3 Contract Addresses
|
|
3
|
+
*
|
|
4
|
+
* All deployed contract addresses on Varity L3 Testnet (Chain ID 33529)
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { VARITY_CONTRACTS } from '@varity-labs/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const marketplaceAddress = VARITY_CONTRACTS.TemplateMarketplace;
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Varity L3 Chain ID
|
|
15
|
+
*/
|
|
16
|
+
export const VARITY_L3_CHAIN_ID = 33529;
|
|
17
|
+
/**
|
|
18
|
+
* All deployed contract addresses on Varity L3
|
|
19
|
+
*/
|
|
20
|
+
export const VARITY_CONTRACTS = {
|
|
21
|
+
// ============================================================
|
|
22
|
+
// Revenue & Marketplace Contracts
|
|
23
|
+
// ============================================================
|
|
24
|
+
/**
|
|
25
|
+
* TemplateMarketplace - 90/10 revenue split
|
|
26
|
+
* - 90% goes to Developer (template/app creator)
|
|
27
|
+
* - 10% goes to Varity (platform fee)
|
|
28
|
+
*
|
|
29
|
+
* @deployed January 30, 2026 (Updated revenue split)
|
|
30
|
+
* @network Varity L3 (Chain ID 33529)
|
|
31
|
+
*/
|
|
32
|
+
TemplateMarketplace: '0x769250dac29817081f38CfBa597Ef2485F3a94e8',
|
|
33
|
+
/**
|
|
34
|
+
* TemplateRegistry - Template metadata storage
|
|
35
|
+
*
|
|
36
|
+
* @deployed January 24, 2026
|
|
37
|
+
* @network Varity L3 (Chain ID 33529)
|
|
38
|
+
*/
|
|
39
|
+
TemplateRegistry: '0xEbD8C516c05BD2b76b5CDd56530b3Dd9f8b3D748',
|
|
40
|
+
// ============================================================
|
|
41
|
+
// App Store Contracts
|
|
42
|
+
// ============================================================
|
|
43
|
+
/**
|
|
44
|
+
* VarityAppRegistry - App Store submissions
|
|
45
|
+
* - Developers submit apps here
|
|
46
|
+
* - Admin approval workflow
|
|
47
|
+
*
|
|
48
|
+
* @deployed January 24, 2026
|
|
49
|
+
* @network Varity L3 (Chain ID 33529)
|
|
50
|
+
* @technology Arbitrum Stylus (Rust)
|
|
51
|
+
*/
|
|
52
|
+
VarityAppRegistry: '0x52d4f28ebe20fad743bbef9daa61bfe3ce91eb74',
|
|
53
|
+
// ============================================================
|
|
54
|
+
// Smart Wallet Contracts (ERC-4337 Account Abstraction)
|
|
55
|
+
// ============================================================
|
|
56
|
+
/**
|
|
57
|
+
* SimplifiedPaymaster - Sponsors gas for users
|
|
58
|
+
* - Users NEVER pay gas fees
|
|
59
|
+
* - Funded with USDC via Conduit
|
|
60
|
+
*
|
|
61
|
+
* @deployed January 13, 2026
|
|
62
|
+
* @network Varity L3 (Chain ID 33529)
|
|
63
|
+
*/
|
|
64
|
+
SimplifiedPaymaster: '0xeF467aef91d4e626C7e56967779069bEF22c4453',
|
|
65
|
+
/**
|
|
66
|
+
* VarityWalletFactory - Creates smart wallets for users
|
|
67
|
+
* - Users login with email/social (never see wallet)
|
|
68
|
+
* - Creates smart wallet behind the scenes
|
|
69
|
+
*
|
|
70
|
+
* @deployed January 13, 2026
|
|
71
|
+
* @network Varity L3 (Chain ID 33529)
|
|
72
|
+
*/
|
|
73
|
+
VarityWalletFactory: '0x85AB92708CB4d921f5c2BdCCd7f2D0813a380f71',
|
|
74
|
+
/**
|
|
75
|
+
* ERC-4337 EntryPoint (standard address)
|
|
76
|
+
* - v0.6: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
|
|
77
|
+
*/
|
|
78
|
+
EntryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Revenue split percentages (TemplateMarketplace)
|
|
82
|
+
*/
|
|
83
|
+
export const REVENUE_SPLIT = {
|
|
84
|
+
/** Developer (creator) receives 90% */
|
|
85
|
+
DEVELOPER_PERCENT: 90,
|
|
86
|
+
/** Varity (platform) receives 10% */
|
|
87
|
+
PLATFORM_PERCENT: 10,
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Get contract address by name
|
|
91
|
+
*/
|
|
92
|
+
export function getContractAddress(name) {
|
|
93
|
+
return VARITY_CONTRACTS[name];
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK v1 - Main SDK Class
|
|
3
|
+
*
|
|
4
|
+
* Entry point for all Varity SDK functionality.
|
|
5
|
+
* Provides access to ISO Dashboard modules and shared utilities.
|
|
6
|
+
*/
|
|
7
|
+
import { ethers } from 'ethers';
|
|
8
|
+
import { VaritySDKConfig, NetworkConfig } from './types';
|
|
9
|
+
import { TemplateConfig } from './template';
|
|
10
|
+
import './template-loader';
|
|
11
|
+
import { AuthModule } from '../modules/auth';
|
|
12
|
+
import { StorageModule } from '../modules/storage';
|
|
13
|
+
import { S3Module } from '../modules/storage/S3Module';
|
|
14
|
+
import { ComputeModule } from '../modules/compute';
|
|
15
|
+
import { ZKModule } from '../modules/zk';
|
|
16
|
+
import { ContractsModule } from '../modules/contracts';
|
|
17
|
+
import { OracleModule } from '../modules/oracle';
|
|
18
|
+
import { AnalyticsModule } from '../modules/analytics';
|
|
19
|
+
import { NotificationsModule } from '../modules/notifications';
|
|
20
|
+
import { ExportModule } from '../modules/export';
|
|
21
|
+
import { CacheModule } from '../modules/cache';
|
|
22
|
+
import { MonitoringModule } from '../modules/monitoring';
|
|
23
|
+
import { ForecastingModule } from '../modules/forecasting';
|
|
24
|
+
import { WebhooksModule } from '../modules/webhooks';
|
|
25
|
+
/**
|
|
26
|
+
* Main Varity SDK class
|
|
27
|
+
*
|
|
28
|
+
* **Capability-based architecture** - Universal methods that work across all templates
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { VaritySDK } from '@varity-labs/sdk'
|
|
33
|
+
*
|
|
34
|
+
* const sdk = new VaritySDK({
|
|
35
|
+
* network: 'arbitrum-sepolia',
|
|
36
|
+
* apiKey: 'your-api-key'
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* await sdk.connect()
|
|
40
|
+
*
|
|
41
|
+
* // Universal capability modules (work for ALL templates)
|
|
42
|
+
* await sdk.auth.login({ address: '0x...' })
|
|
43
|
+
* const encrypted = await sdk.storage.uploadEncrypted(data)
|
|
44
|
+
* const insights = await sdk.compute.query("Analyze performance")
|
|
45
|
+
* await sdk.contracts.send('MerchantRegistry', 'registerMerchant', [...])
|
|
46
|
+
* const proof = await sdk.zk.generateProof('login', { public: [...], private: [...] })
|
|
47
|
+
* const price = await sdk.oracle.getPrice('ETH')
|
|
48
|
+
* const kpis = await sdk.analytics.getKPIs({ period: 'current_month' })
|
|
49
|
+
* const forecast = await sdk.forecasting.predict({ metric: 'revenue', periods: 12, interval: 'month' })
|
|
50
|
+
* await sdk.webhooks.register({ url: 'https://api.example.com/webhook', events: ['transaction.created'] })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class VaritySDK {
|
|
54
|
+
private config;
|
|
55
|
+
private networkConfig;
|
|
56
|
+
private provider;
|
|
57
|
+
private signer;
|
|
58
|
+
private connected;
|
|
59
|
+
private templateConfig;
|
|
60
|
+
auth: AuthModule;
|
|
61
|
+
storage: StorageModule;
|
|
62
|
+
s3: S3Module | undefined;
|
|
63
|
+
compute: ComputeModule;
|
|
64
|
+
zk: ZKModule;
|
|
65
|
+
contracts: ContractsModule;
|
|
66
|
+
oracle: OracleModule;
|
|
67
|
+
analytics: AnalyticsModule;
|
|
68
|
+
notifications: NotificationsModule;
|
|
69
|
+
export: ExportModule;
|
|
70
|
+
cache: CacheModule;
|
|
71
|
+
monitoring: MonitoringModule;
|
|
72
|
+
forecasting: ForecastingModule;
|
|
73
|
+
webhooks: WebhooksModule;
|
|
74
|
+
/**
|
|
75
|
+
* Create a new Varity SDK instance
|
|
76
|
+
*
|
|
77
|
+
* @param config - SDK configuration
|
|
78
|
+
*/
|
|
79
|
+
constructor(config?: Partial<VaritySDKConfig>);
|
|
80
|
+
/**
|
|
81
|
+
* Connect to the blockchain network
|
|
82
|
+
*
|
|
83
|
+
* @param walletProvider - Optional wallet provider (e.g., window.ethereum)
|
|
84
|
+
* @returns Promise that resolves when connected
|
|
85
|
+
*/
|
|
86
|
+
connect(walletProvider?: any): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Disconnect from the network
|
|
89
|
+
*/
|
|
90
|
+
disconnect(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if SDK is connected
|
|
93
|
+
*/
|
|
94
|
+
isConnected(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Get the current provider
|
|
97
|
+
*/
|
|
98
|
+
getProvider(): ethers.Provider;
|
|
99
|
+
/**
|
|
100
|
+
* Get the current signer (throws if read-only)
|
|
101
|
+
*/
|
|
102
|
+
getSigner(): ethers.Signer;
|
|
103
|
+
/**
|
|
104
|
+
* Get SDK configuration
|
|
105
|
+
*/
|
|
106
|
+
getConfig(): VaritySDKConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Get network configuration
|
|
109
|
+
*/
|
|
110
|
+
getNetworkConfig(): NetworkConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Get contract address by name
|
|
113
|
+
*/
|
|
114
|
+
getContractAddress(contractName: keyof NetworkConfig['contracts']): string;
|
|
115
|
+
/**
|
|
116
|
+
* Get block number
|
|
117
|
+
*/
|
|
118
|
+
getBlockNumber(): Promise<number>;
|
|
119
|
+
/**
|
|
120
|
+
* Get wallet address (if signer available)
|
|
121
|
+
*/
|
|
122
|
+
getAddress(): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Get wallet balance (if signer available)
|
|
125
|
+
*/
|
|
126
|
+
getBalance(): Promise<bigint>;
|
|
127
|
+
/**
|
|
128
|
+
* Format balance to ETH
|
|
129
|
+
*/
|
|
130
|
+
formatBalance(balance: bigint): string;
|
|
131
|
+
/**
|
|
132
|
+
* Parse ETH to Wei
|
|
133
|
+
*/
|
|
134
|
+
parseEther(value: string): bigint;
|
|
135
|
+
/**
|
|
136
|
+
* Get backend API base URL
|
|
137
|
+
*/
|
|
138
|
+
getAPIEndpoint(): string;
|
|
139
|
+
/**
|
|
140
|
+
* Get API key for backend services
|
|
141
|
+
*/
|
|
142
|
+
getAPIKey(): string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Get current template configuration
|
|
145
|
+
*
|
|
146
|
+
* @returns Template configuration or null if no template loaded
|
|
147
|
+
*/
|
|
148
|
+
getTemplate(): TemplateConfig | null;
|
|
149
|
+
/**
|
|
150
|
+
* Load template configuration
|
|
151
|
+
*
|
|
152
|
+
* @param template - Template type or custom configuration
|
|
153
|
+
* @returns Loaded template configuration
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Load built-in template
|
|
158
|
+
* await sdk.loadTemplate('iso')
|
|
159
|
+
*
|
|
160
|
+
* // Load custom template
|
|
161
|
+
* await sdk.loadTemplate(customTemplateConfig)
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
loadTemplate(template: string | TemplateConfig): TemplateConfig;
|
|
165
|
+
/**
|
|
166
|
+
* Check if template is loaded
|
|
167
|
+
*/
|
|
168
|
+
hasTemplate(): boolean;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a new Varity SDK instance (convenience function)
|
|
172
|
+
*
|
|
173
|
+
* @param config - SDK configuration
|
|
174
|
+
* @returns Configured SDK instance
|
|
175
|
+
*/
|
|
176
|
+
export declare function createVaritySDK(config?: Partial<VaritySDKConfig>): VaritySDK;
|
|
177
|
+
//# sourceMappingURL=VaritySDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VaritySDK.d.ts","sourceRoot":"","sources":["../../src/core/VaritySDK.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK v1 - Main SDK Class
|
|
3
|
+
*
|
|
4
|
+
* Entry point for all Varity SDK functionality.
|
|
5
|
+
* Provides access to ISO Dashboard modules and shared utilities.
|
|
6
|
+
*/
|
|
7
|
+
import { ethers } from 'ethers';
|
|
8
|
+
import { getNetworkConfig, validateContractAddresses, DEFAULT_CONFIG } from './config';
|
|
9
|
+
import { templateRegistry, validateTemplate } from './template';
|
|
10
|
+
import './template-loader'; // Auto-load built-in templates
|
|
11
|
+
import { AuthModule } from '../modules/auth';
|
|
12
|
+
import { StorageModule } from '../modules/storage';
|
|
13
|
+
import { S3Module } from '../modules/storage/S3Module';
|
|
14
|
+
import { ComputeModule } from '../modules/compute';
|
|
15
|
+
import { ZKModule } from '../modules/zk';
|
|
16
|
+
import { ContractsModule } from '../modules/contracts';
|
|
17
|
+
import { OracleModule } from '../modules/oracle';
|
|
18
|
+
import { AnalyticsModule } from '../modules/analytics';
|
|
19
|
+
import { NotificationsModule } from '../modules/notifications';
|
|
20
|
+
import { ExportModule } from '../modules/export';
|
|
21
|
+
import { CacheModule } from '../modules/cache';
|
|
22
|
+
import { MonitoringModule } from '../modules/monitoring';
|
|
23
|
+
import { ForecastingModule } from '../modules/forecasting';
|
|
24
|
+
import { WebhooksModule } from '../modules/webhooks';
|
|
25
|
+
/**
|
|
26
|
+
* Main Varity SDK class
|
|
27
|
+
*
|
|
28
|
+
* **Capability-based architecture** - Universal methods that work across all templates
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { VaritySDK } from '@varity-labs/sdk'
|
|
33
|
+
*
|
|
34
|
+
* const sdk = new VaritySDK({
|
|
35
|
+
* network: 'arbitrum-sepolia',
|
|
36
|
+
* apiKey: 'your-api-key'
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* await sdk.connect()
|
|
40
|
+
*
|
|
41
|
+
* // Universal capability modules (work for ALL templates)
|
|
42
|
+
* await sdk.auth.login({ address: '0x...' })
|
|
43
|
+
* const encrypted = await sdk.storage.uploadEncrypted(data)
|
|
44
|
+
* const insights = await sdk.compute.query("Analyze performance")
|
|
45
|
+
* await sdk.contracts.send('MerchantRegistry', 'registerMerchant', [...])
|
|
46
|
+
* const proof = await sdk.zk.generateProof('login', { public: [...], private: [...] })
|
|
47
|
+
* const price = await sdk.oracle.getPrice('ETH')
|
|
48
|
+
* const kpis = await sdk.analytics.getKPIs({ period: 'current_month' })
|
|
49
|
+
* const forecast = await sdk.forecasting.predict({ metric: 'revenue', periods: 12, interval: 'month' })
|
|
50
|
+
* await sdk.webhooks.register({ url: 'https://api.example.com/webhook', events: ['transaction.created'] })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export class VaritySDK {
|
|
54
|
+
/**
|
|
55
|
+
* Create a new Varity SDK instance
|
|
56
|
+
*
|
|
57
|
+
* @param config - SDK configuration
|
|
58
|
+
*/
|
|
59
|
+
constructor(config = {}) {
|
|
60
|
+
this.provider = null;
|
|
61
|
+
this.signer = null;
|
|
62
|
+
this.connected = false;
|
|
63
|
+
this.templateConfig = null;
|
|
64
|
+
// Merge with defaults
|
|
65
|
+
this.config = {
|
|
66
|
+
...DEFAULT_CONFIG,
|
|
67
|
+
...config
|
|
68
|
+
};
|
|
69
|
+
// Get network configuration
|
|
70
|
+
this.networkConfig = getNetworkConfig(this.config.network);
|
|
71
|
+
// Load template configuration if specified
|
|
72
|
+
if (this.config.template) {
|
|
73
|
+
this.templateConfig = templateRegistry.get(this.config.template) || null;
|
|
74
|
+
if (!this.templateConfig) {
|
|
75
|
+
console.warn(`Warning: Template '${this.config.template}' not found in registry. ` +
|
|
76
|
+
`SDK will operate with default configuration.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Apply custom template config overrides
|
|
80
|
+
if (this.config.templateConfig && this.templateConfig) {
|
|
81
|
+
this.templateConfig = { ...this.templateConfig, ...this.config.templateConfig };
|
|
82
|
+
}
|
|
83
|
+
else if (this.config.templateConfig) {
|
|
84
|
+
this.templateConfig = this.config.templateConfig;
|
|
85
|
+
}
|
|
86
|
+
// Validate template if loaded
|
|
87
|
+
if (this.templateConfig) {
|
|
88
|
+
const validation = validateTemplate(this.templateConfig);
|
|
89
|
+
if (!validation.valid) {
|
|
90
|
+
console.warn(`Warning: Template validation failed:\n` +
|
|
91
|
+
validation.errors.join('\n'));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Validate contract addresses are configured (warning only, not blocking)
|
|
95
|
+
try {
|
|
96
|
+
validateContractAddresses(this.config.network);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.warn(`Warning: ${error instanceof Error ? error.message : 'Contract validation failed'}\n` +
|
|
100
|
+
`SDK will operate in read-only mode until contracts are deployed.`);
|
|
101
|
+
}
|
|
102
|
+
// Initialize capability modules (universal - work across ALL templates)
|
|
103
|
+
this.auth = new AuthModule(this);
|
|
104
|
+
this.storage = new StorageModule(this);
|
|
105
|
+
this.compute = new ComputeModule(this);
|
|
106
|
+
this.zk = new ZKModule(this);
|
|
107
|
+
this.contracts = new ContractsModule(this);
|
|
108
|
+
this.oracle = new OracleModule(this);
|
|
109
|
+
this.analytics = new AnalyticsModule(this);
|
|
110
|
+
this.notifications = new NotificationsModule(this);
|
|
111
|
+
this.export = new ExportModule(this);
|
|
112
|
+
this.cache = new CacheModule(this);
|
|
113
|
+
this.monitoring = new MonitoringModule(this);
|
|
114
|
+
this.forecasting = new ForecastingModule(this);
|
|
115
|
+
this.webhooks = new WebhooksModule(this);
|
|
116
|
+
// Initialize S3 module if S3 config provided
|
|
117
|
+
if (this.config.s3Config) {
|
|
118
|
+
this.s3 = new S3Module(this, this.config.s3Config);
|
|
119
|
+
console.log('✅ S3-compatible storage module initialized');
|
|
120
|
+
}
|
|
121
|
+
const moduleCount = 13 + (this.s3 ? 1 : 0);
|
|
122
|
+
console.log(`✅ Varity SDK initialized with comprehensive capability-based architecture (${moduleCount} universal modules)`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Connect to the blockchain network
|
|
126
|
+
*
|
|
127
|
+
* @param walletProvider - Optional wallet provider (e.g., window.ethereum)
|
|
128
|
+
* @returns Promise that resolves when connected
|
|
129
|
+
*/
|
|
130
|
+
async connect(walletProvider) {
|
|
131
|
+
try {
|
|
132
|
+
// Priority 1: Use provided wallet provider
|
|
133
|
+
if (walletProvider) {
|
|
134
|
+
const browserProvider = new ethers.BrowserProvider(walletProvider);
|
|
135
|
+
this.provider = browserProvider;
|
|
136
|
+
this.signer = await browserProvider.getSigner();
|
|
137
|
+
}
|
|
138
|
+
// Priority 2: Use configured wallet provider
|
|
139
|
+
else if (this.config.walletProvider) {
|
|
140
|
+
const browserProvider = new ethers.BrowserProvider(this.config.walletProvider);
|
|
141
|
+
this.provider = browserProvider;
|
|
142
|
+
this.signer = await browserProvider.getSigner();
|
|
143
|
+
}
|
|
144
|
+
// Priority 3: Use private key (server-side)
|
|
145
|
+
else if (this.config.privateKey) {
|
|
146
|
+
this.provider = new ethers.JsonRpcProvider(this.config.rpcUrl || this.networkConfig.rpcUrl);
|
|
147
|
+
this.signer = new ethers.Wallet(this.config.privateKey, this.provider);
|
|
148
|
+
}
|
|
149
|
+
// Priority 4: Read-only mode
|
|
150
|
+
else {
|
|
151
|
+
this.provider = new ethers.JsonRpcProvider(this.config.rpcUrl || this.networkConfig.rpcUrl);
|
|
152
|
+
console.warn('Connected in read-only mode. Provide a wallet or private key for write operations.');
|
|
153
|
+
}
|
|
154
|
+
// Verify network
|
|
155
|
+
const network = await this.provider.getNetwork();
|
|
156
|
+
if (Number(network.chainId) !== this.networkConfig.chainId) {
|
|
157
|
+
throw new Error(`Network mismatch: Expected chain ID ${this.networkConfig.chainId}, ` +
|
|
158
|
+
`but connected to ${network.chainId}`);
|
|
159
|
+
}
|
|
160
|
+
this.connected = true;
|
|
161
|
+
console.log(`✅ Connected to ${this.config.network} (Chain ID: ${network.chainId})`);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throw new Error(`Failed to connect to network: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Disconnect from the network
|
|
169
|
+
*/
|
|
170
|
+
async disconnect() {
|
|
171
|
+
this.provider = null;
|
|
172
|
+
this.signer = null;
|
|
173
|
+
this.connected = false;
|
|
174
|
+
console.log('Disconnected from network');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if SDK is connected
|
|
178
|
+
*/
|
|
179
|
+
isConnected() {
|
|
180
|
+
return this.connected;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get the current provider
|
|
184
|
+
*/
|
|
185
|
+
getProvider() {
|
|
186
|
+
if (!this.provider) {
|
|
187
|
+
throw new Error('SDK not connected. Call connect() first.');
|
|
188
|
+
}
|
|
189
|
+
return this.provider;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get the current signer (throws if read-only)
|
|
193
|
+
*/
|
|
194
|
+
getSigner() {
|
|
195
|
+
if (!this.signer) {
|
|
196
|
+
throw new Error('No signer available. SDK is in read-only mode.');
|
|
197
|
+
}
|
|
198
|
+
return this.signer;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get SDK configuration
|
|
202
|
+
*/
|
|
203
|
+
getConfig() {
|
|
204
|
+
return { ...this.config };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get network configuration
|
|
208
|
+
*/
|
|
209
|
+
getNetworkConfig() {
|
|
210
|
+
return { ...this.networkConfig };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get contract address by name
|
|
214
|
+
*/
|
|
215
|
+
getContractAddress(contractName) {
|
|
216
|
+
const address = this.networkConfig.contracts[contractName];
|
|
217
|
+
if (!address || address === '') {
|
|
218
|
+
throw new Error(`Contract ${contractName} not deployed on ${this.config.network}. ` +
|
|
219
|
+
`Please deploy contracts or check configuration.`);
|
|
220
|
+
}
|
|
221
|
+
return address;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get block number
|
|
225
|
+
*/
|
|
226
|
+
async getBlockNumber() {
|
|
227
|
+
const provider = this.getProvider();
|
|
228
|
+
return await provider.getBlockNumber();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get wallet address (if signer available)
|
|
232
|
+
*/
|
|
233
|
+
async getAddress() {
|
|
234
|
+
const signer = this.getSigner();
|
|
235
|
+
return await signer.getAddress();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get wallet balance (if signer available)
|
|
239
|
+
*/
|
|
240
|
+
async getBalance() {
|
|
241
|
+
const signer = this.getSigner();
|
|
242
|
+
const address = await signer.getAddress();
|
|
243
|
+
const provider = this.getProvider();
|
|
244
|
+
return await provider.getBalance(address);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Format balance to ETH
|
|
248
|
+
*/
|
|
249
|
+
formatBalance(balance) {
|
|
250
|
+
return ethers.formatEther(balance);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Parse ETH to Wei
|
|
254
|
+
*/
|
|
255
|
+
parseEther(value) {
|
|
256
|
+
return ethers.parseEther(value);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get backend API base URL
|
|
260
|
+
*/
|
|
261
|
+
getAPIEndpoint() {
|
|
262
|
+
return this.config.apiEndpoint || DEFAULT_CONFIG.apiEndpoint;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get API key for backend services
|
|
266
|
+
*/
|
|
267
|
+
getAPIKey() {
|
|
268
|
+
return this.config.apiKey;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get current template configuration
|
|
272
|
+
*
|
|
273
|
+
* @returns Template configuration or null if no template loaded
|
|
274
|
+
*/
|
|
275
|
+
getTemplate() {
|
|
276
|
+
return this.templateConfig;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Load template configuration
|
|
280
|
+
*
|
|
281
|
+
* @param template - Template type or custom configuration
|
|
282
|
+
* @returns Loaded template configuration
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* // Load built-in template
|
|
287
|
+
* await sdk.loadTemplate('iso')
|
|
288
|
+
*
|
|
289
|
+
* // Load custom template
|
|
290
|
+
* await sdk.loadTemplate(customTemplateConfig)
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
loadTemplate(template) {
|
|
294
|
+
if (typeof template === 'string') {
|
|
295
|
+
const config = templateRegistry.get(template);
|
|
296
|
+
if (!config) {
|
|
297
|
+
throw new Error(`Template '${template}' not found in registry`);
|
|
298
|
+
}
|
|
299
|
+
this.templateConfig = config;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
const validation = validateTemplate(template);
|
|
303
|
+
if (!validation.valid) {
|
|
304
|
+
throw new Error(`Invalid template configuration:\n${validation.errors.join('\n')}`);
|
|
305
|
+
}
|
|
306
|
+
this.templateConfig = template;
|
|
307
|
+
}
|
|
308
|
+
return this.templateConfig;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Check if template is loaded
|
|
312
|
+
*/
|
|
313
|
+
hasTemplate() {
|
|
314
|
+
return this.templateConfig !== null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Create a new Varity SDK instance (convenience function)
|
|
319
|
+
*
|
|
320
|
+
* @param config - SDK configuration
|
|
321
|
+
* @returns Configured SDK instance
|
|
322
|
+
*/
|
|
323
|
+
export function createVaritySDK(config = {}) {
|
|
324
|
+
return new VaritySDK(config);
|
|
325
|
+
}
|