@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,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Storage Adapter Factory
|
|
3
|
+
*
|
|
4
|
+
* Factory pattern for creating storage adapters based on backend configuration.
|
|
5
|
+
* Supports Filecoin/IPFS, multi-tier, and future S3/GCS backends.
|
|
6
|
+
*/
|
|
7
|
+
import { FilecoinAdapter } from './FilecoinAdapter';
|
|
8
|
+
import { MultiTierAdapter } from './MultiTierAdapter';
|
|
9
|
+
/**
|
|
10
|
+
* Factory for creating storage adapters
|
|
11
|
+
*
|
|
12
|
+
* Provides a unified interface for creating different storage backend adapters
|
|
13
|
+
* based on configuration. Handles validation and adapter initialization.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Create Filecoin adapter
|
|
18
|
+
* const adapter = AdapterFactory.createAdapter(sdk, {
|
|
19
|
+
* backend: StorageBackend.FILECOIN_IPFS
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* // Create multi-tier adapter
|
|
23
|
+
* const multiTierAdapter = AdapterFactory.createAdapter(sdk, {
|
|
24
|
+
* backend: StorageBackend.MULTI_TIER,
|
|
25
|
+
* multiTierConfig: {
|
|
26
|
+
* hotTier: { backend: StorageBackend.FILECOIN_IPFS, replication: 3 },
|
|
27
|
+
* coldTier: { backend: StorageBackend.FILECOIN_IPFS, replication: 2 },
|
|
28
|
+
* autoTiering: { enabled: true, policy: TieringPolicy.ACCESS_BASED, checkInterval: 24 }
|
|
29
|
+
* }
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class AdapterFactory {
|
|
34
|
+
/**
|
|
35
|
+
* Create a storage adapter based on backend type and configuration
|
|
36
|
+
*
|
|
37
|
+
* @param sdk - Varity SDK instance
|
|
38
|
+
* @param config - Adapter configuration
|
|
39
|
+
* @returns Storage adapter instance
|
|
40
|
+
* @throws {Error} If backend is unsupported or configuration is invalid
|
|
41
|
+
*/
|
|
42
|
+
static createAdapter(sdk, config) {
|
|
43
|
+
switch (config.backend) {
|
|
44
|
+
case 'filecoin-ipfs':
|
|
45
|
+
return new FilecoinAdapter(sdk);
|
|
46
|
+
case 'multi-tier':
|
|
47
|
+
if (!config.multiTierConfig) {
|
|
48
|
+
throw new Error('MultiTierStorageConfig required for MULTI_TIER backend');
|
|
49
|
+
}
|
|
50
|
+
return new MultiTierAdapter(sdk, config.multiTierConfig);
|
|
51
|
+
case 's3-compatible':
|
|
52
|
+
throw new Error('S3-compatible storage backend not yet implemented. Coming soon!');
|
|
53
|
+
case 'gcs-compatible':
|
|
54
|
+
throw new Error('GCS-compatible storage backend not yet implemented. Coming soon!');
|
|
55
|
+
case 'celestia':
|
|
56
|
+
throw new Error('Celestia storage backend not yet implemented. Coming soon!');
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unsupported storage backend: ${config.backend}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create adapter from SDK configuration
|
|
63
|
+
*
|
|
64
|
+
* Convenience method that extracts storage configuration from SDK config
|
|
65
|
+
* and creates the appropriate adapter.
|
|
66
|
+
*
|
|
67
|
+
* @param sdk - Varity SDK instance
|
|
68
|
+
* @returns Storage adapter instance
|
|
69
|
+
*/
|
|
70
|
+
static createFromSDKConfig(sdk) {
|
|
71
|
+
const sdkConfig = sdk.getConfig();
|
|
72
|
+
// Determine backend from config
|
|
73
|
+
const backend = sdkConfig.storageBackend || 'filecoin-ipfs';
|
|
74
|
+
const config = {
|
|
75
|
+
backend,
|
|
76
|
+
multiTierConfig: sdkConfig.multiTierConfig,
|
|
77
|
+
s3Config: sdkConfig.s3Config,
|
|
78
|
+
gcsConfig: sdkConfig.gcsConfig
|
|
79
|
+
};
|
|
80
|
+
return this.createAdapter(sdk, config);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validate adapter configuration
|
|
84
|
+
*
|
|
85
|
+
* @param config - Adapter configuration
|
|
86
|
+
* @returns True if valid
|
|
87
|
+
* @throws {Error} If configuration is invalid
|
|
88
|
+
*/
|
|
89
|
+
static validateConfig(config) {
|
|
90
|
+
if (!config.backend) {
|
|
91
|
+
throw new Error('Storage backend must be specified');
|
|
92
|
+
}
|
|
93
|
+
// Validate multi-tier config
|
|
94
|
+
if (config.backend === 'multi-tier') {
|
|
95
|
+
if (!config.multiTierConfig) {
|
|
96
|
+
throw new Error('MultiTierStorageConfig required for MULTI_TIER backend');
|
|
97
|
+
}
|
|
98
|
+
const mtConfig = config.multiTierConfig;
|
|
99
|
+
if (!mtConfig.hotTier || !mtConfig.coldTier) {
|
|
100
|
+
throw new Error('Both hotTier and coldTier must be configured for multi-tier storage');
|
|
101
|
+
}
|
|
102
|
+
if (!mtConfig.autoTiering) {
|
|
103
|
+
throw new Error('AutoTiering configuration required for multi-tier storage');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Validate S3 config
|
|
107
|
+
if (config.backend === 's3-compatible') {
|
|
108
|
+
if (!config.s3Config) {
|
|
109
|
+
throw new Error('S3CompatibleConfig required for S3_COMPATIBLE backend');
|
|
110
|
+
}
|
|
111
|
+
const s3Config = config.s3Config;
|
|
112
|
+
if (!s3Config.endpoint || !s3Config.accessKeyId || !s3Config.secretAccessKey) {
|
|
113
|
+
throw new Error('S3 endpoint, accessKeyId, and secretAccessKey are required');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Validate GCS config
|
|
117
|
+
if (config.backend === 'gcs-compatible') {
|
|
118
|
+
if (!config.gcsConfig) {
|
|
119
|
+
throw new Error('GCSCompatibleConfig required for GCS_COMPATIBLE backend');
|
|
120
|
+
}
|
|
121
|
+
const gcsConfig = config.gcsConfig;
|
|
122
|
+
if (!gcsConfig.projectId || !gcsConfig.bucket) {
|
|
123
|
+
throw new Error('GCS projectId and bucket are required');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get supported backends
|
|
130
|
+
*
|
|
131
|
+
* @returns Array of supported storage backends
|
|
132
|
+
*/
|
|
133
|
+
static getSupportedBackends() {
|
|
134
|
+
return [
|
|
135
|
+
'filecoin-ipfs',
|
|
136
|
+
'multi-tier'
|
|
137
|
+
// S3 and GCS coming soon
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if a backend is supported
|
|
142
|
+
*
|
|
143
|
+
* @param backend - Backend to check
|
|
144
|
+
* @returns True if supported
|
|
145
|
+
*/
|
|
146
|
+
static isBackendSupported(backend) {
|
|
147
|
+
return this.getSupportedBackends().includes(backend);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get backend capabilities
|
|
151
|
+
*
|
|
152
|
+
* @param backend - Storage backend
|
|
153
|
+
* @returns Capabilities object
|
|
154
|
+
*/
|
|
155
|
+
static getBackendCapabilities(backend) {
|
|
156
|
+
switch (backend) {
|
|
157
|
+
case 'filecoin-ipfs':
|
|
158
|
+
return {
|
|
159
|
+
supportsEncryption: true,
|
|
160
|
+
supportsVersioning: true,
|
|
161
|
+
supportsMetadata: true,
|
|
162
|
+
supportsCopy: false,
|
|
163
|
+
supportsMove: false,
|
|
164
|
+
supportsPresignedUrls: false,
|
|
165
|
+
costTier: 'low'
|
|
166
|
+
};
|
|
167
|
+
case 'multi-tier':
|
|
168
|
+
return {
|
|
169
|
+
supportsEncryption: true,
|
|
170
|
+
supportsVersioning: true,
|
|
171
|
+
supportsMetadata: true,
|
|
172
|
+
supportsCopy: true,
|
|
173
|
+
supportsMove: true,
|
|
174
|
+
supportsPresignedUrls: false,
|
|
175
|
+
costTier: 'low'
|
|
176
|
+
};
|
|
177
|
+
case 's3-compatible':
|
|
178
|
+
return {
|
|
179
|
+
supportsEncryption: true,
|
|
180
|
+
supportsVersioning: true,
|
|
181
|
+
supportsMetadata: true,
|
|
182
|
+
supportsCopy: true,
|
|
183
|
+
supportsMove: true,
|
|
184
|
+
supportsPresignedUrls: true,
|
|
185
|
+
costTier: 'medium'
|
|
186
|
+
};
|
|
187
|
+
case 'gcs-compatible':
|
|
188
|
+
return {
|
|
189
|
+
supportsEncryption: true,
|
|
190
|
+
supportsVersioning: true,
|
|
191
|
+
supportsMetadata: true,
|
|
192
|
+
supportsCopy: true,
|
|
193
|
+
supportsMove: true,
|
|
194
|
+
supportsPresignedUrls: true,
|
|
195
|
+
costTier: 'medium'
|
|
196
|
+
};
|
|
197
|
+
default:
|
|
198
|
+
return {
|
|
199
|
+
supportsEncryption: false,
|
|
200
|
+
supportsVersioning: false,
|
|
201
|
+
supportsMetadata: false,
|
|
202
|
+
supportsCopy: false,
|
|
203
|
+
supportsMove: false,
|
|
204
|
+
supportsPresignedUrls: false,
|
|
205
|
+
costTier: 'high'
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Filecoin/IPFS Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements IStorageAdapter for Filecoin/IPFS storage via Pinata API.
|
|
5
|
+
* Extracted from StorageModule to enable multi-backend support.
|
|
6
|
+
*/
|
|
7
|
+
import type { VaritySDK } from '../../../core/VaritySDK';
|
|
8
|
+
import { type UploadOptions, type StorageResult, type StorageItem, type ListOptions, type StorageMetadata } from '@varity-labs/types';
|
|
9
|
+
import { BaseStorageAdapter } from './IStorageAdapter';
|
|
10
|
+
/**
|
|
11
|
+
* Filecoin/IPFS adapter implementation using Pinata API
|
|
12
|
+
*
|
|
13
|
+
* This adapter handles all Filecoin/IPFS operations including:
|
|
14
|
+
* - Pinning content to IPFS
|
|
15
|
+
* - Retrieving content via IPFS gateways
|
|
16
|
+
* - Managing pins (list, delete)
|
|
17
|
+
* - Gateway URL generation
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const adapter = new FilecoinAdapter(sdk)
|
|
22
|
+
* const result = await adapter.upload(Buffer.from('Hello World'), {
|
|
23
|
+
* layer: StorageLayer.CUSTOMER_DATA,
|
|
24
|
+
* tier: StorageTier.HOT,
|
|
25
|
+
* pin: true
|
|
26
|
+
* })
|
|
27
|
+
* console.log('CID:', result.identifier)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class FilecoinAdapter extends BaseStorageAdapter {
|
|
31
|
+
private sdk;
|
|
32
|
+
constructor(sdk: VaritySDK);
|
|
33
|
+
/**
|
|
34
|
+
* Upload data to Filecoin/IPFS via backend API
|
|
35
|
+
*
|
|
36
|
+
* @param data - Data to upload (Buffer, string, Blob)
|
|
37
|
+
* @param options - Upload options including layer, tier, metadata
|
|
38
|
+
* @returns Storage result with CID and gateway URL
|
|
39
|
+
*/
|
|
40
|
+
upload(data: Buffer | string | Blob, options: UploadOptions): Promise<StorageResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Download data from Filecoin/IPFS
|
|
43
|
+
*
|
|
44
|
+
* @param identifier - CID (Content Identifier)
|
|
45
|
+
* @returns Downloaded data as Buffer
|
|
46
|
+
*/
|
|
47
|
+
download(identifier: string): Promise<Buffer>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete (unpin) data from Filecoin/IPFS
|
|
50
|
+
*
|
|
51
|
+
* @param identifier - CID to unpin
|
|
52
|
+
*/
|
|
53
|
+
delete(identifier: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Check if data exists on Filecoin/IPFS
|
|
56
|
+
*
|
|
57
|
+
* @param identifier - CID to check
|
|
58
|
+
* @returns True if exists, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
exists(identifier: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* List pinned objects
|
|
63
|
+
*
|
|
64
|
+
* @param options - List filtering options
|
|
65
|
+
* @returns Array of storage items
|
|
66
|
+
*/
|
|
67
|
+
list(options?: ListOptions): Promise<StorageItem[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Get metadata for a pinned object
|
|
70
|
+
*
|
|
71
|
+
* @param identifier - CID to get metadata for
|
|
72
|
+
* @returns Storage metadata
|
|
73
|
+
*/
|
|
74
|
+
getMetadata(identifier: string): Promise<StorageMetadata>;
|
|
75
|
+
/**
|
|
76
|
+
* Get access URL for a CID
|
|
77
|
+
*
|
|
78
|
+
* @param identifier - CID
|
|
79
|
+
* @param expiresIn - Not used for IPFS (always public)
|
|
80
|
+
* @returns Gateway URL
|
|
81
|
+
*/
|
|
82
|
+
getAccessUrl(identifier: string, expiresIn?: number): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Health check for Filecoin/IPFS backend
|
|
85
|
+
*
|
|
86
|
+
* @returns Health status with latency
|
|
87
|
+
*/
|
|
88
|
+
healthCheck(): Promise<{
|
|
89
|
+
healthy: boolean;
|
|
90
|
+
latencyMs: number;
|
|
91
|
+
error?: string;
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=FilecoinAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilecoinAdapter.d.ts","sourceRoot":"","sources":["../../../../src/modules/storage/adapters/FilecoinAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,eAAgB,SAAQ,kBAAkB;IACrD,OAAO,CAAC,GAAG,CAAW;gBAEV,GAAG,EAAE,SAAS;IAK1B;;;;;;OAMG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAqD1F;;;;;OAKG;IACG,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BnD;;;;OAIG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB/C;;;;;OAKG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASlD;;;;;OAKG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAsCzD;;;;;OAKG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAiC/D;;;;;;OAMG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM3E;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAsBtF"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Filecoin/IPFS Storage Adapter
|
|
3
|
+
*
|
|
4
|
+
* Implements IStorageAdapter for Filecoin/IPFS storage via Pinata API.
|
|
5
|
+
* Extracted from StorageModule to enable multi-backend support.
|
|
6
|
+
*/
|
|
7
|
+
import { StorageBackend, StorageTier } from '@varity-labs/types';
|
|
8
|
+
import { BaseStorageAdapter } from './IStorageAdapter';
|
|
9
|
+
/**
|
|
10
|
+
* Filecoin/IPFS adapter implementation using Pinata API
|
|
11
|
+
*
|
|
12
|
+
* This adapter handles all Filecoin/IPFS operations including:
|
|
13
|
+
* - Pinning content to IPFS
|
|
14
|
+
* - Retrieving content via IPFS gateways
|
|
15
|
+
* - Managing pins (list, delete)
|
|
16
|
+
* - Gateway URL generation
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const adapter = new FilecoinAdapter(sdk)
|
|
21
|
+
* const result = await adapter.upload(Buffer.from('Hello World'), {
|
|
22
|
+
* layer: StorageLayer.CUSTOMER_DATA,
|
|
23
|
+
* tier: StorageTier.HOT,
|
|
24
|
+
* pin: true
|
|
25
|
+
* })
|
|
26
|
+
* console.log('CID:', result.identifier)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class FilecoinAdapter extends BaseStorageAdapter {
|
|
30
|
+
constructor(sdk) {
|
|
31
|
+
super(StorageBackend.FILECOIN_IPFS);
|
|
32
|
+
this.sdk = sdk;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Upload data to Filecoin/IPFS via backend API
|
|
36
|
+
*
|
|
37
|
+
* @param data - Data to upload (Buffer, string, Blob)
|
|
38
|
+
* @param options - Upload options including layer, tier, metadata
|
|
39
|
+
* @returns Storage result with CID and gateway URL
|
|
40
|
+
*/
|
|
41
|
+
async upload(data, options) {
|
|
42
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
43
|
+
const apiKey = this.sdk.getAPIKey();
|
|
44
|
+
// Convert data to appropriate format
|
|
45
|
+
let uploadData;
|
|
46
|
+
if (data instanceof Buffer) {
|
|
47
|
+
uploadData = data.toString('base64');
|
|
48
|
+
}
|
|
49
|
+
else if (data instanceof Blob) {
|
|
50
|
+
const buffer = await data.arrayBuffer();
|
|
51
|
+
uploadData = Buffer.from(buffer).toString('base64');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
uploadData = data;
|
|
55
|
+
}
|
|
56
|
+
// Call backend API to pin to IPFS
|
|
57
|
+
const response = await fetch(`${apiEndpoint}/api/v1/storage/pin`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: {
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
data: uploadData,
|
|
65
|
+
metadata: {
|
|
66
|
+
layer: options.layer,
|
|
67
|
+
tier: options.tier || StorageTier.HOT,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
contentType: options.contentType || 'application/octet-stream',
|
|
70
|
+
...options.metadata
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const errorText = await response.text();
|
|
76
|
+
throw new Error(`Upload failed: ${response.statusText} - ${errorText}`);
|
|
77
|
+
}
|
|
78
|
+
const result = await response.json();
|
|
79
|
+
return {
|
|
80
|
+
identifier: result.cid,
|
|
81
|
+
gatewayUrl: result.gatewayUrl || `https://gateway.pinata.cloud/ipfs/${result.cid}`,
|
|
82
|
+
size: result.size || 0,
|
|
83
|
+
hash: result.hash || result.cid,
|
|
84
|
+
timestamp: Date.now(),
|
|
85
|
+
backend: StorageBackend.FILECOIN_IPFS,
|
|
86
|
+
tier: options.tier || StorageTier.HOT,
|
|
87
|
+
layer: options.layer
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Download data from Filecoin/IPFS
|
|
92
|
+
*
|
|
93
|
+
* @param identifier - CID (Content Identifier)
|
|
94
|
+
* @returns Downloaded data as Buffer
|
|
95
|
+
*/
|
|
96
|
+
async download(identifier) {
|
|
97
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
98
|
+
const apiKey = this.sdk.getAPIKey();
|
|
99
|
+
const response = await fetch(`${apiEndpoint}/api/v1/storage/retrieve/${identifier}`, {
|
|
100
|
+
method: 'GET',
|
|
101
|
+
headers: {
|
|
102
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
const errorText = await response.text();
|
|
107
|
+
throw new Error(`Download failed: ${response.statusText} - ${errorText}`);
|
|
108
|
+
}
|
|
109
|
+
// Check content type to determine if it's binary or text
|
|
110
|
+
const contentType = response.headers.get('content-type') || '';
|
|
111
|
+
if (contentType.includes('application/json') || contentType.includes('text/')) {
|
|
112
|
+
const text = await response.text();
|
|
113
|
+
return Buffer.from(text);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
117
|
+
return Buffer.from(arrayBuffer);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Delete (unpin) data from Filecoin/IPFS
|
|
122
|
+
*
|
|
123
|
+
* @param identifier - CID to unpin
|
|
124
|
+
*/
|
|
125
|
+
async delete(identifier) {
|
|
126
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
127
|
+
const apiKey = this.sdk.getAPIKey();
|
|
128
|
+
const response = await fetch(`${apiEndpoint}/api/v1/storage/unpin/${identifier}`, {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
headers: {
|
|
131
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
const errorText = await response.text();
|
|
136
|
+
throw new Error(`Delete failed: ${response.statusText} - ${errorText}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if data exists on Filecoin/IPFS
|
|
141
|
+
*
|
|
142
|
+
* @param identifier - CID to check
|
|
143
|
+
* @returns True if exists, false otherwise
|
|
144
|
+
*/
|
|
145
|
+
async exists(identifier) {
|
|
146
|
+
try {
|
|
147
|
+
await this.getMetadata(identifier);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* List pinned objects
|
|
156
|
+
*
|
|
157
|
+
* @param options - List filtering options
|
|
158
|
+
* @returns Array of storage items
|
|
159
|
+
*/
|
|
160
|
+
async list(options) {
|
|
161
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
162
|
+
const apiKey = this.sdk.getAPIKey();
|
|
163
|
+
const queryParams = new URLSearchParams();
|
|
164
|
+
if (options?.prefix)
|
|
165
|
+
queryParams.append('prefix', options.prefix);
|
|
166
|
+
if (options?.maxResults)
|
|
167
|
+
queryParams.append('limit', options.maxResults.toString());
|
|
168
|
+
if (options?.continuationToken)
|
|
169
|
+
queryParams.append('pageToken', options.continuationToken);
|
|
170
|
+
if (options?.startAfter)
|
|
171
|
+
queryParams.append('startAfter', options.startAfter);
|
|
172
|
+
const response = await fetch(`${apiEndpoint}/api/v1/storage/list?${queryParams}`, {
|
|
173
|
+
headers: {
|
|
174
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (!response.ok) {
|
|
178
|
+
const errorText = await response.text();
|
|
179
|
+
throw new Error(`List failed: ${response.statusText} - ${errorText}`);
|
|
180
|
+
}
|
|
181
|
+
const data = await response.json();
|
|
182
|
+
return (data.items || []).map((item) => ({
|
|
183
|
+
identifier: item.cid,
|
|
184
|
+
key: item.cid,
|
|
185
|
+
size: item.size || 0,
|
|
186
|
+
lastModified: new Date(item.timestamp || Date.now()),
|
|
187
|
+
etag: item.hash || item.cid,
|
|
188
|
+
metadata: item.metadata,
|
|
189
|
+
tier: item.metadata?.tier,
|
|
190
|
+
encrypted: item.metadata?.encrypted || false
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get metadata for a pinned object
|
|
195
|
+
*
|
|
196
|
+
* @param identifier - CID to get metadata for
|
|
197
|
+
* @returns Storage metadata
|
|
198
|
+
*/
|
|
199
|
+
async getMetadata(identifier) {
|
|
200
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
201
|
+
const apiKey = this.sdk.getAPIKey();
|
|
202
|
+
const response = await fetch(`${apiEndpoint}/api/v1/storage/metadata/${identifier}`, {
|
|
203
|
+
headers: {
|
|
204
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (!response.ok) {
|
|
208
|
+
const errorText = await response.text();
|
|
209
|
+
throw new Error(`Get metadata failed: ${response.statusText} - ${errorText}`);
|
|
210
|
+
}
|
|
211
|
+
const data = await response.json();
|
|
212
|
+
return {
|
|
213
|
+
identifier: identifier,
|
|
214
|
+
size: data.size || 0,
|
|
215
|
+
contentType: data.contentType || 'application/octet-stream',
|
|
216
|
+
lastModified: new Date(data.timestamp || Date.now()),
|
|
217
|
+
etag: data.hash || identifier,
|
|
218
|
+
customMetadata: data.metadata || {},
|
|
219
|
+
tier: data.metadata?.tier,
|
|
220
|
+
layer: data.metadata?.layer,
|
|
221
|
+
encrypted: data.metadata?.encrypted || false
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get access URL for a CID
|
|
226
|
+
*
|
|
227
|
+
* @param identifier - CID
|
|
228
|
+
* @param expiresIn - Not used for IPFS (always public)
|
|
229
|
+
* @returns Gateway URL
|
|
230
|
+
*/
|
|
231
|
+
async getAccessUrl(identifier, expiresIn) {
|
|
232
|
+
// For IPFS, always return public gateway URL
|
|
233
|
+
// Note: expiresIn is ignored since IPFS gateways are public
|
|
234
|
+
return `https://gateway.pinata.cloud/ipfs/${identifier}`;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Health check for Filecoin/IPFS backend
|
|
238
|
+
*
|
|
239
|
+
* @returns Health status with latency
|
|
240
|
+
*/
|
|
241
|
+
async healthCheck() {
|
|
242
|
+
const startTime = Date.now();
|
|
243
|
+
try {
|
|
244
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
245
|
+
const response = await fetch(`${apiEndpoint}/health`, {
|
|
246
|
+
method: 'GET'
|
|
247
|
+
});
|
|
248
|
+
const latencyMs = Date.now() - startTime;
|
|
249
|
+
return {
|
|
250
|
+
healthy: response.ok,
|
|
251
|
+
latencyMs,
|
|
252
|
+
error: response.ok ? undefined : `HTTP ${response.status}: ${response.statusText}`
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
return {
|
|
257
|
+
healthy: false,
|
|
258
|
+
latencyMs: Date.now() - startTime,
|
|
259
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|