@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
package/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Varity Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Varity SDK - Web3 Operating System
|
|
26
|
+
|
|
27
|
+
Build and deploy apps on Varity L3 with 70-85% cost savings vs traditional cloud.
|
|
28
|
+
|
|
29
|
+
For more information, visit https://varity.so
|
|
30
|
+
|
|
31
|
+
"Powered by Varity" attribution is required when using this SDK.
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# @varity/sdk
|
|
2
|
+
|
|
3
|
+
**Complete Web3 SDK for Varity L3** - Build production-ready blockchain applications with multi-chain support, thirdweb integration, and enterprise-grade features.
|
|
4
|
+
|
|
5
|
+
**Status:** ✅ **ALL BLOCKERS RESOLVED** - Ready for End-to-End Testing (Jan 24, 2026)
|
|
6
|
+
|
|
7
|
+
## Deployed Contracts (Varity L3 - Chain ID 33529)
|
|
8
|
+
|
|
9
|
+
| Contract | Address | Purpose |
|
|
10
|
+
|----------|---------|---------|
|
|
11
|
+
| **TemplateMarketplace** | `0x769250dac29817081f38CfBa597Ef2485F3a94e8` | **70/30 Revenue Split** |
|
|
12
|
+
| **TemplateRegistry** | `0xEbD8C516c05BD2b76b5CDd56530b3Dd9f8b3D748` | Template metadata |
|
|
13
|
+
| **VarityAppRegistry** | `0x52d4f28ebe20fad743bbef9daa61bfe3ce91eb74` | App Store submissions |
|
|
14
|
+
| **SimplifiedPaymaster** | `0xeF467aef91d4e626C7e56967779069bEF22c4453` | Gas sponsorship |
|
|
15
|
+
| **VarityWalletFactory** | `0x85AB92708CB4d921f5c2BdCCd7f2D0813a380f71` | Smart wallets |
|
|
16
|
+
|
|
17
|
+
**Revenue Split:** 70% → Developer | 30% → Varity Platform
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @varity/sdk@alpha
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createVaritySDK, varityL3Testnet, ChainRegistry } from '@varity/sdk';
|
|
29
|
+
|
|
30
|
+
// Initialize SDK
|
|
31
|
+
const sdk = createVaritySDK({
|
|
32
|
+
network: 'testnet',
|
|
33
|
+
apiUrl: 'https://api.varity.io',
|
|
34
|
+
thirdwebClientId: 'your-client-id'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Use multi-chain configuration
|
|
38
|
+
const chain = ChainRegistry.getChain(33529); // Varity L3
|
|
39
|
+
console.log('Connected to:', chain.name);
|
|
40
|
+
|
|
41
|
+
// Deploy a contract
|
|
42
|
+
const contract = await sdk.deployContract({
|
|
43
|
+
chain: varityL3Testnet,
|
|
44
|
+
contractType: 'nft-collection',
|
|
45
|
+
name: 'My Collection'
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
### 🔗 Multi-Chain Support
|
|
52
|
+
- **Varity L3** (Chain ID 33529) - Low-cost Arbitrum Orbit rollup with USDC gas token
|
|
53
|
+
- **Arbitrum** (Sepolia & Mainnet) - Fast, low-cost L2
|
|
54
|
+
- **Base** (Sepolia & Mainnet) - Coinbase's L2 built on OP Stack
|
|
55
|
+
- **ChainRegistry** - Intelligent chain selection based on cost, speed, security
|
|
56
|
+
|
|
57
|
+
### ⚡ Complete thirdweb Integration
|
|
58
|
+
- **Engine** - Production transaction management with auto-retry and webhooks
|
|
59
|
+
- **Nebula AI** - Natural language blockchain interactions (generate contracts, query chains)
|
|
60
|
+
- **Storage** - Decentralized storage via IPFS/Arweave
|
|
61
|
+
- **Bridge** - Cross-chain asset transfers
|
|
62
|
+
- **Gateway** - Production RPC infrastructure with WebSocket support
|
|
63
|
+
- **x402** - API monetization with 70/30 revenue split
|
|
64
|
+
- **Smart Wallets** - ERC-4337 gasless transactions with account abstraction
|
|
65
|
+
- **Server Wallets** - Backend automation for transaction signing
|
|
66
|
+
|
|
67
|
+
### 🎯 Enterprise Features
|
|
68
|
+
- Template system for rapid deployment (ISO, SaaS, eCommerce, Healthcare)
|
|
69
|
+
- Multi-tenant architecture with wallet-based isolation
|
|
70
|
+
- Comprehensive analytics and forecasting
|
|
71
|
+
- ZK proofs (ZKML, privacy-preserving computations)
|
|
72
|
+
- TEE support (confidential computing)
|
|
73
|
+
- Encryption (Lit Protocol, FHE, AES-256-GCM)
|
|
74
|
+
|
|
75
|
+
### 📦 Developer Experience
|
|
76
|
+
- TypeScript-first with full type safety
|
|
77
|
+
- Function-based API (thirdweb v5)
|
|
78
|
+
- Comprehensive error handling
|
|
79
|
+
- Detailed logging and monitoring
|
|
80
|
+
- Extensive documentation
|
|
81
|
+
|
|
82
|
+
## Documentation
|
|
83
|
+
|
|
84
|
+
See [docs.varity.ai/packages/sdk](https://docs.varity.ai) for full documentation.
|
|
85
|
+
|
|
86
|
+
## Key Exports
|
|
87
|
+
|
|
88
|
+
### Multi-Chain
|
|
89
|
+
```typescript
|
|
90
|
+
import {
|
|
91
|
+
ChainRegistry, // Chain registry with intelligent selection
|
|
92
|
+
varityL3, // Varity L3 Testnet (Chain ID 33529)
|
|
93
|
+
arbitrum, // Arbitrum One mainnet
|
|
94
|
+
arbitrumSepolia, // Arbitrum Sepolia testnet
|
|
95
|
+
base, // Base mainnet
|
|
96
|
+
baseSepolia, // Base Sepolia testnet
|
|
97
|
+
formatUSDC, // Format USDC with 6 decimals
|
|
98
|
+
parseUSDC, // Parse USDC from string
|
|
99
|
+
} from '@varity/sdk';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### thirdweb Clients
|
|
103
|
+
```typescript
|
|
104
|
+
import {
|
|
105
|
+
EngineClient, // Production transaction management
|
|
106
|
+
NebulaClient, // AI-powered blockchain interactions
|
|
107
|
+
StorageClient, // IPFS/Arweave storage
|
|
108
|
+
BridgeClient, // Cross-chain bridging
|
|
109
|
+
GatewayClient, // RPC infrastructure
|
|
110
|
+
x402Client, // API monetization
|
|
111
|
+
createThirdwebWrapper, // Base thirdweb wrapper
|
|
112
|
+
} from '@varity/sdk';
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Core SDK
|
|
116
|
+
```typescript
|
|
117
|
+
import {
|
|
118
|
+
VaritySDK, // Main SDK class
|
|
119
|
+
createVaritySDK, // Factory function
|
|
120
|
+
TemplateRegistry, // Template management
|
|
121
|
+
loadISOTemplate, // Load ISO template
|
|
122
|
+
} from '@varity/sdk';
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Contract Addresses (NEW - Jan 24, 2026)
|
|
126
|
+
```typescript
|
|
127
|
+
import {
|
|
128
|
+
VARITY_L3_CHAIN_ID, // 33529
|
|
129
|
+
VARITY_CONTRACTS, // All deployed contract addresses
|
|
130
|
+
REVENUE_SPLIT, // { DEVELOPER_PERCENT: 70, PLATFORM_PERCENT: 30 }
|
|
131
|
+
getVarityContractAddress, // Helper function
|
|
132
|
+
} from '@varity/sdk';
|
|
133
|
+
|
|
134
|
+
// Access specific contracts
|
|
135
|
+
const marketplaceAddress = VARITY_CONTRACTS.TemplateMarketplace;
|
|
136
|
+
const paymasterAddress = VARITY_CONTRACTS.SimplifiedPaymaster;
|
|
137
|
+
const factoryAddress = VARITY_CONTRACTS.VarityWalletFactory;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Examples
|
|
141
|
+
|
|
142
|
+
### Deploy Contract with Multi-Chain
|
|
143
|
+
```typescript
|
|
144
|
+
import { createVaritySDK, ChainRegistry } from '@varity/sdk';
|
|
145
|
+
|
|
146
|
+
const sdk = createVaritySDK({ /* config */ });
|
|
147
|
+
|
|
148
|
+
// Auto-select cheapest chain
|
|
149
|
+
const chain = ChainRegistry.selectChain({
|
|
150
|
+
optimize: 'cost',
|
|
151
|
+
requirements: { testnet: true }
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const contract = await sdk.deployContract({
|
|
155
|
+
chain,
|
|
156
|
+
contractType: 'marketplace',
|
|
157
|
+
name: 'My Marketplace'
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### AI-Powered Contract Generation
|
|
162
|
+
```typescript
|
|
163
|
+
import { NebulaClient } from '@varity/sdk';
|
|
164
|
+
|
|
165
|
+
const nebula = new NebulaClient({ apiKey: 'your-key' });
|
|
166
|
+
|
|
167
|
+
// Generate Solidity from natural language
|
|
168
|
+
const result = await nebula.generateContract({
|
|
169
|
+
prompt: 'Create an NFT marketplace with royalty splits',
|
|
170
|
+
language: 'solidity',
|
|
171
|
+
framework: 'foundry'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
console.log(result.code); // Generated Solidity contract
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Cross-Chain Asset Bridge
|
|
178
|
+
```typescript
|
|
179
|
+
import { BridgeClient, varityL3, arbitrum } from '@varity/sdk';
|
|
180
|
+
|
|
181
|
+
const bridge = new BridgeClient({ clientId: 'your-id' });
|
|
182
|
+
|
|
183
|
+
// Get quote for bridging USDC
|
|
184
|
+
const quote = await bridge.getQuote({
|
|
185
|
+
fromChain: varityL3,
|
|
186
|
+
toChain: arbitrum,
|
|
187
|
+
amount: 1000000n, // 1 USDC (6 decimals)
|
|
188
|
+
token: 'USDC'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Execute bridge
|
|
192
|
+
const tx = await bridge.bridgeAsset({
|
|
193
|
+
quote,
|
|
194
|
+
fromAddress: '0x...',
|
|
195
|
+
toAddress: '0x...'
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Decentralized Storage
|
|
200
|
+
```typescript
|
|
201
|
+
import { StorageClient } from '@varity/sdk';
|
|
202
|
+
|
|
203
|
+
const storage = new StorageClient({ clientId: 'your-id' });
|
|
204
|
+
|
|
205
|
+
// Upload file to IPFS
|
|
206
|
+
const file = new File(['Hello World'], 'hello.txt');
|
|
207
|
+
const result = await storage.uploadFile(file);
|
|
208
|
+
console.log('IPFS URI:', result.uri); // ipfs://...
|
|
209
|
+
|
|
210
|
+
// Download from IPFS
|
|
211
|
+
const blob = await storage.downloadFile({ uri: result.uri });
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### API Monetization with x402
|
|
215
|
+
```typescript
|
|
216
|
+
import { x402Client } from '@varity/sdk';
|
|
217
|
+
|
|
218
|
+
const x402 = new x402Client({ clientId: 'your-id' });
|
|
219
|
+
|
|
220
|
+
// Create pay-per-call API endpoint
|
|
221
|
+
const endpoint = await x402.createPaymentEndpoint({
|
|
222
|
+
apiUrl: 'https://api.yourapp.com/data',
|
|
223
|
+
pricePerCall: 10000n, // 0.01 USDC per call
|
|
224
|
+
paymentToken: 'USDC',
|
|
225
|
+
chain: varityL3
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Users pay with crypto, you earn 70% (thirdweb takes 30%)
|
|
229
|
+
console.log('Payment endpoint:', endpoint.endpointId);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Version
|
|
233
|
+
|
|
234
|
+
Current version: **2.0.0-alpha.1**
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT - See [LICENSE](../../LICENSE) file
|
|
239
|
+
|
|
240
|
+
## Contributing
|
|
241
|
+
|
|
242
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
|
|
243
|
+
|
|
244
|
+
## Support
|
|
245
|
+
|
|
246
|
+
- Documentation: https://docs.varity.ai
|
|
247
|
+
- Discord: https://discord.gg/varity
|
|
248
|
+
- GitHub Issues: https://github.com/varity-labs/varity-sdk/issues
|
|
249
|
+
- Email: support@varity.ai
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
**Powered by Varity** | [Website](https://varity.ai) | [Twitter](https://twitter.com/VarityLabs) | [Discord](https://discord.gg/varity)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Tracker - Tracks app usage for billing
|
|
3
|
+
*
|
|
4
|
+
* Tracks:
|
|
5
|
+
* - Deployments (static/dynamic)
|
|
6
|
+
* - API requests
|
|
7
|
+
* - Storage operations (uploads, downloads, bandwidth)
|
|
8
|
+
* - Compute usage (function executions, duration)
|
|
9
|
+
* - Smart contract interactions
|
|
10
|
+
*/
|
|
11
|
+
export interface UsageEvent {
|
|
12
|
+
appId: string;
|
|
13
|
+
developerId: string;
|
|
14
|
+
eventType: 'deploy' | 'api_request' | 'storage' | 'compute' | 'contract';
|
|
15
|
+
timestamp: number;
|
|
16
|
+
metadata: {
|
|
17
|
+
hostingType?: 'static' | 'dynamic';
|
|
18
|
+
buildTime?: number;
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
statusCode?: number;
|
|
21
|
+
responseTime?: number;
|
|
22
|
+
operation?: 'upload' | 'download' | 'delete';
|
|
23
|
+
bytes?: number;
|
|
24
|
+
fileCount?: number;
|
|
25
|
+
functionName?: string;
|
|
26
|
+
executionTime?: number;
|
|
27
|
+
memoryUsed?: number;
|
|
28
|
+
contractAddress?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
gasUsed?: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface AnalyticsConfig {
|
|
34
|
+
apiEndpoint: string;
|
|
35
|
+
apiKey: string;
|
|
36
|
+
batchSize?: number;
|
|
37
|
+
flushInterval?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare class AnalyticsTracker {
|
|
40
|
+
private apiEndpoint;
|
|
41
|
+
private apiKey;
|
|
42
|
+
private batchSize;
|
|
43
|
+
private flushInterval;
|
|
44
|
+
private eventQueue;
|
|
45
|
+
private flushTimer;
|
|
46
|
+
constructor(config: AnalyticsConfig);
|
|
47
|
+
/**
|
|
48
|
+
* Start auto-flush timer
|
|
49
|
+
*/
|
|
50
|
+
private startAutoFlush;
|
|
51
|
+
/**
|
|
52
|
+
* Stop auto-flush timer
|
|
53
|
+
*/
|
|
54
|
+
stopAutoFlush(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Track a deployment event
|
|
57
|
+
*/
|
|
58
|
+
trackDeployment(params: {
|
|
59
|
+
appId: string;
|
|
60
|
+
developerId: string;
|
|
61
|
+
hostingType: 'static' | 'dynamic';
|
|
62
|
+
buildTime: number;
|
|
63
|
+
}): void;
|
|
64
|
+
/**
|
|
65
|
+
* Track an API request
|
|
66
|
+
*/
|
|
67
|
+
trackApiRequest(params: {
|
|
68
|
+
appId: string;
|
|
69
|
+
developerId: string;
|
|
70
|
+
endpoint: string;
|
|
71
|
+
statusCode: number;
|
|
72
|
+
responseTime: number;
|
|
73
|
+
}): void;
|
|
74
|
+
/**
|
|
75
|
+
* Track storage operation
|
|
76
|
+
*/
|
|
77
|
+
trackStorage(params: {
|
|
78
|
+
appId: string;
|
|
79
|
+
developerId: string;
|
|
80
|
+
operation: 'upload' | 'download' | 'delete';
|
|
81
|
+
bytes: number;
|
|
82
|
+
fileCount: number;
|
|
83
|
+
}): void;
|
|
84
|
+
/**
|
|
85
|
+
* Track compute usage
|
|
86
|
+
*/
|
|
87
|
+
trackCompute(params: {
|
|
88
|
+
appId: string;
|
|
89
|
+
developerId: string;
|
|
90
|
+
functionName: string;
|
|
91
|
+
executionTime: number;
|
|
92
|
+
memoryUsed: number;
|
|
93
|
+
}): void;
|
|
94
|
+
/**
|
|
95
|
+
* Track smart contract interaction
|
|
96
|
+
*/
|
|
97
|
+
trackContract(params: {
|
|
98
|
+
appId: string;
|
|
99
|
+
developerId: string;
|
|
100
|
+
contractAddress: string;
|
|
101
|
+
method: string;
|
|
102
|
+
gasUsed: number;
|
|
103
|
+
}): void;
|
|
104
|
+
/**
|
|
105
|
+
* Internal: Add event to queue
|
|
106
|
+
*/
|
|
107
|
+
private track;
|
|
108
|
+
/**
|
|
109
|
+
* Flush events to backend
|
|
110
|
+
*/
|
|
111
|
+
flush(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Get current queue size
|
|
114
|
+
*/
|
|
115
|
+
getQueueSize(): number;
|
|
116
|
+
/**
|
|
117
|
+
* Clear all queued events
|
|
118
|
+
*/
|
|
119
|
+
clearQueue(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Shutdown the tracker (flush remaining events and stop auto-flush)
|
|
122
|
+
*/
|
|
123
|
+
shutdown(): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
export declare function initializeAnalytics(config: AnalyticsConfig): AnalyticsTracker;
|
|
126
|
+
export declare function getAnalyticsTracker(): AnalyticsTracker;
|
|
127
|
+
export declare function shutdownAnalytics(): Promise<void>;
|
|
128
|
+
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/analytics/tracker.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics Tracker - Tracks app usage for billing
|
|
3
|
+
*
|
|
4
|
+
* Tracks:
|
|
5
|
+
* - Deployments (static/dynamic)
|
|
6
|
+
* - API requests
|
|
7
|
+
* - Storage operations (uploads, downloads, bandwidth)
|
|
8
|
+
* - Compute usage (function executions, duration)
|
|
9
|
+
* - Smart contract interactions
|
|
10
|
+
*/
|
|
11
|
+
export class AnalyticsTracker {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.batchSize = 50;
|
|
14
|
+
this.flushInterval = 30000; // 30 seconds
|
|
15
|
+
this.eventQueue = [];
|
|
16
|
+
this.flushTimer = null;
|
|
17
|
+
this.apiEndpoint = config.apiEndpoint;
|
|
18
|
+
this.apiKey = config.apiKey;
|
|
19
|
+
if (config.batchSize) {
|
|
20
|
+
this.batchSize = config.batchSize;
|
|
21
|
+
}
|
|
22
|
+
if (config.flushInterval) {
|
|
23
|
+
this.flushInterval = config.flushInterval;
|
|
24
|
+
}
|
|
25
|
+
// Auto-flush every interval
|
|
26
|
+
this.startAutoFlush();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Start auto-flush timer
|
|
30
|
+
*/
|
|
31
|
+
startAutoFlush() {
|
|
32
|
+
this.flushTimer = setInterval(() => {
|
|
33
|
+
this.flush().catch(err => {
|
|
34
|
+
console.error('Auto-flush failed:', err);
|
|
35
|
+
});
|
|
36
|
+
}, this.flushInterval);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Stop auto-flush timer
|
|
40
|
+
*/
|
|
41
|
+
stopAutoFlush() {
|
|
42
|
+
if (this.flushTimer) {
|
|
43
|
+
clearInterval(this.flushTimer);
|
|
44
|
+
this.flushTimer = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Track a deployment event
|
|
49
|
+
*/
|
|
50
|
+
trackDeployment(params) {
|
|
51
|
+
this.track({
|
|
52
|
+
appId: params.appId,
|
|
53
|
+
developerId: params.developerId,
|
|
54
|
+
eventType: 'deploy',
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
metadata: {
|
|
57
|
+
hostingType: params.hostingType,
|
|
58
|
+
buildTime: params.buildTime
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Track an API request
|
|
64
|
+
*/
|
|
65
|
+
trackApiRequest(params) {
|
|
66
|
+
this.track({
|
|
67
|
+
appId: params.appId,
|
|
68
|
+
developerId: params.developerId,
|
|
69
|
+
eventType: 'api_request',
|
|
70
|
+
timestamp: Date.now(),
|
|
71
|
+
metadata: {
|
|
72
|
+
endpoint: params.endpoint,
|
|
73
|
+
statusCode: params.statusCode,
|
|
74
|
+
responseTime: params.responseTime
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Track storage operation
|
|
80
|
+
*/
|
|
81
|
+
trackStorage(params) {
|
|
82
|
+
this.track({
|
|
83
|
+
appId: params.appId,
|
|
84
|
+
developerId: params.developerId,
|
|
85
|
+
eventType: 'storage',
|
|
86
|
+
timestamp: Date.now(),
|
|
87
|
+
metadata: {
|
|
88
|
+
operation: params.operation,
|
|
89
|
+
bytes: params.bytes,
|
|
90
|
+
fileCount: params.fileCount
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Track compute usage
|
|
96
|
+
*/
|
|
97
|
+
trackCompute(params) {
|
|
98
|
+
this.track({
|
|
99
|
+
appId: params.appId,
|
|
100
|
+
developerId: params.developerId,
|
|
101
|
+
eventType: 'compute',
|
|
102
|
+
timestamp: Date.now(),
|
|
103
|
+
metadata: {
|
|
104
|
+
functionName: params.functionName,
|
|
105
|
+
executionTime: params.executionTime,
|
|
106
|
+
memoryUsed: params.memoryUsed
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Track smart contract interaction
|
|
112
|
+
*/
|
|
113
|
+
trackContract(params) {
|
|
114
|
+
this.track({
|
|
115
|
+
appId: params.appId,
|
|
116
|
+
developerId: params.developerId,
|
|
117
|
+
eventType: 'contract',
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
metadata: {
|
|
120
|
+
contractAddress: params.contractAddress,
|
|
121
|
+
method: params.method,
|
|
122
|
+
gasUsed: params.gasUsed
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Internal: Add event to queue
|
|
128
|
+
*/
|
|
129
|
+
track(event) {
|
|
130
|
+
this.eventQueue.push(event);
|
|
131
|
+
// Auto-flush when batch is full
|
|
132
|
+
if (this.eventQueue.length >= this.batchSize) {
|
|
133
|
+
this.flush().catch(err => {
|
|
134
|
+
console.error('Auto-flush on batch size failed:', err);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Flush events to backend
|
|
140
|
+
*/
|
|
141
|
+
async flush() {
|
|
142
|
+
if (this.eventQueue.length === 0)
|
|
143
|
+
return;
|
|
144
|
+
const events = [...this.eventQueue];
|
|
145
|
+
this.eventQueue = [];
|
|
146
|
+
try {
|
|
147
|
+
const response = await fetch(`${this.apiEndpoint}/analytics/events`, {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: {
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
'X-API-Key': this.apiKey
|
|
152
|
+
},
|
|
153
|
+
body: JSON.stringify({ events })
|
|
154
|
+
});
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
throw new Error(`Failed to send analytics: ${response.status} ${response.statusText}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error('Failed to send analytics events:', error);
|
|
161
|
+
// Re-queue failed events at the beginning
|
|
162
|
+
this.eventQueue.unshift(...events);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get current queue size
|
|
168
|
+
*/
|
|
169
|
+
getQueueSize() {
|
|
170
|
+
return this.eventQueue.length;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Clear all queued events
|
|
174
|
+
*/
|
|
175
|
+
clearQueue() {
|
|
176
|
+
this.eventQueue = [];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Shutdown the tracker (flush remaining events and stop auto-flush)
|
|
180
|
+
*/
|
|
181
|
+
async shutdown() {
|
|
182
|
+
this.stopAutoFlush();
|
|
183
|
+
await this.flush();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Global instance
|
|
187
|
+
let globalTracker = null;
|
|
188
|
+
export function initializeAnalytics(config) {
|
|
189
|
+
globalTracker = new AnalyticsTracker(config);
|
|
190
|
+
return globalTracker;
|
|
191
|
+
}
|
|
192
|
+
export function getAnalyticsTracker() {
|
|
193
|
+
if (!globalTracker) {
|
|
194
|
+
throw new Error('Analytics not initialized. Call initializeAnalytics() first.');
|
|
195
|
+
}
|
|
196
|
+
return globalTracker;
|
|
197
|
+
}
|
|
198
|
+
export function shutdownAnalytics() {
|
|
199
|
+
if (globalTracker) {
|
|
200
|
+
return globalTracker.shutdown();
|
|
201
|
+
}
|
|
202
|
+
return Promise.resolve();
|
|
203
|
+
}
|