@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.
Files changed (295) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +253 -0
  3. package/dist/analytics/index.d.ts +7 -0
  4. package/dist/analytics/index.d.ts.map +1 -0
  5. package/dist/analytics/index.js +6 -0
  6. package/dist/analytics/tracker.d.ts +128 -0
  7. package/dist/analytics/tracker.d.ts.map +1 -0
  8. package/dist/analytics/tracker.js +203 -0
  9. package/dist/blockchain/BlockchainService.d.ts +100 -0
  10. package/dist/blockchain/BlockchainService.d.ts.map +1 -0
  11. package/dist/blockchain/BlockchainService.js +188 -0
  12. package/dist/blockchain/NFTLicensingService.d.ts +69 -0
  13. package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
  14. package/dist/blockchain/NFTLicensingService.js +136 -0
  15. package/dist/blockchain/RevenueSplitService.d.ts +71 -0
  16. package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
  17. package/dist/blockchain/RevenueSplitService.js +111 -0
  18. package/dist/blockchain/index.d.ts +48 -0
  19. package/dist/blockchain/index.d.ts.map +1 -0
  20. package/dist/blockchain/index.js +46 -0
  21. package/dist/blockchain/types.d.ts +63 -0
  22. package/dist/blockchain/types.d.ts.map +1 -0
  23. package/dist/blockchain/types.js +6 -0
  24. package/dist/chains/arbitrum.d.ts +89 -0
  25. package/dist/chains/arbitrum.d.ts.map +1 -0
  26. package/dist/chains/arbitrum.js +134 -0
  27. package/dist/chains/base.d.ts +84 -0
  28. package/dist/chains/base.d.ts.map +1 -0
  29. package/dist/chains/base.js +131 -0
  30. package/dist/chains/index.d.ts +36 -0
  31. package/dist/chains/index.d.ts.map +1 -0
  32. package/dist/chains/index.js +32 -0
  33. package/dist/chains/registry.d.ts +113 -0
  34. package/dist/chains/registry.d.ts.map +1 -0
  35. package/dist/chains/registry.js +201 -0
  36. package/dist/chains/varityL3.d.ts +81 -0
  37. package/dist/chains/varityL3.d.ts.map +1 -0
  38. package/dist/chains/varityL3.js +125 -0
  39. package/dist/cli/commands/clone.d.ts +8 -0
  40. package/dist/cli/commands/clone.d.ts.map +1 -0
  41. package/dist/cli/commands/clone.js +391 -0
  42. package/dist/cli/commands/dev.d.ts +8 -0
  43. package/dist/cli/commands/dev.d.ts.map +1 -0
  44. package/dist/cli/commands/dev.js +40 -0
  45. package/dist/cli/commands/generate.d.ts +8 -0
  46. package/dist/cli/commands/generate.d.ts.map +1 -0
  47. package/dist/cli/commands/generate.js +303 -0
  48. package/dist/cli/commands/init.d.ts +8 -0
  49. package/dist/cli/commands/init.d.ts.map +1 -0
  50. package/dist/cli/commands/init.js +317 -0
  51. package/dist/cli/commands/validate.d.ts +8 -0
  52. package/dist/cli/commands/validate.d.ts.map +1 -0
  53. package/dist/cli/commands/validate.js +69 -0
  54. package/dist/cli/index.d.ts +8 -0
  55. package/dist/cli/index.d.ts.map +1 -0
  56. package/dist/cli/index.js +33 -0
  57. package/dist/cli/utils/logger.d.ts +17 -0
  58. package/dist/cli/utils/logger.d.ts.map +1 -0
  59. package/dist/cli/utils/logger.js +35 -0
  60. package/dist/cli/utils/prompts.d.ts +21 -0
  61. package/dist/cli/utils/prompts.d.ts.map +1 -0
  62. package/dist/cli/utils/prompts.js +103 -0
  63. package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
  64. package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
  65. package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
  66. package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
  67. package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
  68. package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
  69. package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
  70. package/dist/contracts/addresses.d.ts +88 -0
  71. package/dist/contracts/addresses.d.ts.map +1 -0
  72. package/dist/contracts/addresses.js +94 -0
  73. package/dist/contracts/index.d.ts +7 -0
  74. package/dist/contracts/index.d.ts.map +1 -0
  75. package/dist/contracts/index.js +6 -0
  76. package/dist/core/VaritySDK.d.ts +177 -0
  77. package/dist/core/VaritySDK.d.ts.map +1 -0
  78. package/dist/core/VaritySDK.js +325 -0
  79. package/dist/core/config.d.ts +120 -0
  80. package/dist/core/config.d.ts.map +1 -0
  81. package/dist/core/config.js +187 -0
  82. package/dist/core/credentials-proxy.d.ts +157 -0
  83. package/dist/core/credentials-proxy.d.ts.map +1 -0
  84. package/dist/core/credentials-proxy.js +345 -0
  85. package/dist/core/credentials.d.ts +219 -0
  86. package/dist/core/credentials.d.ts.map +1 -0
  87. package/dist/core/credentials.js +345 -0
  88. package/dist/core/template-loader.d.ts +15 -0
  89. package/dist/core/template-loader.d.ts.map +1 -0
  90. package/dist/core/template-loader.js +380 -0
  91. package/dist/core/template.d.ts +321 -0
  92. package/dist/core/template.d.ts.map +1 -0
  93. package/dist/core/template.js +189 -0
  94. package/dist/core/types.d.ts +572 -0
  95. package/dist/core/types.d.ts.map +1 -0
  96. package/dist/core/types.js +52 -0
  97. package/dist/dev/dev-server.d.ts +16 -0
  98. package/dist/dev/dev-server.d.ts.map +1 -0
  99. package/dist/dev/dev-server.js +119 -0
  100. package/dist/generators/contracts/generator.d.ts +21 -0
  101. package/dist/generators/contracts/generator.d.ts.map +1 -0
  102. package/dist/generators/contracts/generator.js +252 -0
  103. package/dist/generators/tests/generator.d.ts +20 -0
  104. package/dist/generators/tests/generator.d.ts.map +1 -0
  105. package/dist/generators/tests/generator.js +375 -0
  106. package/dist/generators/types/generator.d.ts +19 -0
  107. package/dist/generators/types/generator.d.ts.map +1 -0
  108. package/dist/generators/types/generator.js +165 -0
  109. package/dist/generators/ui/component-generator.d.ts +20 -0
  110. package/dist/generators/ui/component-generator.d.ts.map +1 -0
  111. package/dist/generators/ui/component-generator.js +749 -0
  112. package/dist/generators/ui/dashboard-generator.d.ts +20 -0
  113. package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
  114. package/dist/generators/ui/dashboard-generator.js +349 -0
  115. package/dist/index.d.ts +61 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +74 -0
  118. package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
  119. package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
  120. package/dist/modules/analytics/AnalyticsModule.js +274 -0
  121. package/dist/modules/analytics/index.d.ts +3 -0
  122. package/dist/modules/analytics/index.d.ts.map +1 -0
  123. package/dist/modules/analytics/index.js +1 -0
  124. package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
  125. package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
  126. package/dist/modules/auth/AccessKeyModule.js +322 -0
  127. package/dist/modules/auth/AuthModule.d.ts +133 -0
  128. package/dist/modules/auth/AuthModule.d.ts.map +1 -0
  129. package/dist/modules/auth/AuthModule.js +214 -0
  130. package/dist/modules/auth/index.d.ts +8 -0
  131. package/dist/modules/auth/index.d.ts.map +1 -0
  132. package/dist/modules/auth/index.js +6 -0
  133. package/dist/modules/cache/CacheModule.d.ts +279 -0
  134. package/dist/modules/cache/CacheModule.d.ts.map +1 -0
  135. package/dist/modules/cache/CacheModule.js +493 -0
  136. package/dist/modules/cache/index.d.ts +3 -0
  137. package/dist/modules/cache/index.d.ts.map +1 -0
  138. package/dist/modules/cache/index.js +1 -0
  139. package/dist/modules/compute/ComputeModule.d.ts +226 -0
  140. package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
  141. package/dist/modules/compute/ComputeModule.js +379 -0
  142. package/dist/modules/compute/index.d.ts +6 -0
  143. package/dist/modules/compute/index.d.ts.map +1 -0
  144. package/dist/modules/compute/index.js +4 -0
  145. package/dist/modules/contracts/ContractsModule.d.ts +164 -0
  146. package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
  147. package/dist/modules/contracts/ContractsModule.js +242 -0
  148. package/dist/modules/contracts/index.d.ts +6 -0
  149. package/dist/modules/contracts/index.d.ts.map +1 -0
  150. package/dist/modules/contracts/index.js +4 -0
  151. package/dist/modules/export/ExportModule.d.ts +346 -0
  152. package/dist/modules/export/ExportModule.d.ts.map +1 -0
  153. package/dist/modules/export/ExportModule.js +432 -0
  154. package/dist/modules/export/index.d.ts +3 -0
  155. package/dist/modules/export/index.d.ts.map +1 -0
  156. package/dist/modules/export/index.js +1 -0
  157. package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
  158. package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
  159. package/dist/modules/forecasting/ForecastingModule.js +310 -0
  160. package/dist/modules/forecasting/index.d.ts +3 -0
  161. package/dist/modules/forecasting/index.d.ts.map +1 -0
  162. package/dist/modules/forecasting/index.js +1 -0
  163. package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
  164. package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
  165. package/dist/modules/monitoring/MonitoringModule.js +483 -0
  166. package/dist/modules/monitoring/index.d.ts +3 -0
  167. package/dist/modules/monitoring/index.d.ts.map +1 -0
  168. package/dist/modules/monitoring/index.js +1 -0
  169. package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
  170. package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
  171. package/dist/modules/notifications/NotificationsModule.js +418 -0
  172. package/dist/modules/notifications/index.d.ts +3 -0
  173. package/dist/modules/notifications/index.d.ts.map +1 -0
  174. package/dist/modules/notifications/index.js +1 -0
  175. package/dist/modules/oracle/OracleModule.d.ts +110 -0
  176. package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
  177. package/dist/modules/oracle/OracleModule.js +151 -0
  178. package/dist/modules/oracle/index.d.ts +6 -0
  179. package/dist/modules/oracle/index.d.ts.map +1 -0
  180. package/dist/modules/oracle/index.js +4 -0
  181. package/dist/modules/storage/S3Module.d.ts +377 -0
  182. package/dist/modules/storage/S3Module.d.ts.map +1 -0
  183. package/dist/modules/storage/S3Module.js +680 -0
  184. package/dist/modules/storage/StorageModule.d.ts +157 -0
  185. package/dist/modules/storage/StorageModule.d.ts.map +1 -0
  186. package/dist/modules/storage/StorageModule.js +302 -0
  187. package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
  188. package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
  189. package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
  190. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
  191. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
  192. package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
  193. package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
  194. package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
  195. package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
  196. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
  197. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
  198. package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
  199. package/dist/modules/storage/adapters/index.d.ts +12 -0
  200. package/dist/modules/storage/adapters/index.d.ts.map +1 -0
  201. package/dist/modules/storage/adapters/index.js +12 -0
  202. package/dist/modules/storage/index.d.ts +16 -0
  203. package/dist/modules/storage/index.d.ts.map +1 -0
  204. package/dist/modules/storage/index.js +15 -0
  205. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
  206. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
  207. package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
  208. package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
  209. package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
  210. package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
  211. package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
  212. package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
  213. package/dist/modules/storage/tiering/MetadataStore.js +535 -0
  214. package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
  215. package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
  216. package/dist/modules/storage/tiering/TieringEngine.js +419 -0
  217. package/dist/modules/storage/tiering/example.d.ts +8 -0
  218. package/dist/modules/storage/tiering/example.d.ts.map +1 -0
  219. package/dist/modules/storage/tiering/example.js +250 -0
  220. package/dist/modules/storage/tiering/index.d.ts +17 -0
  221. package/dist/modules/storage/tiering/index.d.ts.map +1 -0
  222. package/dist/modules/storage/tiering/index.js +13 -0
  223. package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
  224. package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
  225. package/dist/modules/webhooks/WebhooksModule.js +359 -0
  226. package/dist/modules/webhooks/index.d.ts +3 -0
  227. package/dist/modules/webhooks/index.d.ts.map +1 -0
  228. package/dist/modules/webhooks/index.js +1 -0
  229. package/dist/modules/zk/ZKModule.d.ts +153 -0
  230. package/dist/modules/zk/ZKModule.d.ts.map +1 -0
  231. package/dist/modules/zk/ZKModule.js +262 -0
  232. package/dist/modules/zk/index.d.ts +7 -0
  233. package/dist/modules/zk/index.d.ts.map +1 -0
  234. package/dist/modules/zk/index.js +4 -0
  235. package/dist/thirdweb/BridgeClient.d.ts +228 -0
  236. package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
  237. package/dist/thirdweb/BridgeClient.js +160 -0
  238. package/dist/thirdweb/EngineClient.d.ts +396 -0
  239. package/dist/thirdweb/EngineClient.d.ts.map +1 -0
  240. package/dist/thirdweb/EngineClient.js +386 -0
  241. package/dist/thirdweb/GatewayClient.d.ts +190 -0
  242. package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
  243. package/dist/thirdweb/GatewayClient.js +257 -0
  244. package/dist/thirdweb/NebulaClient.d.ts +292 -0
  245. package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
  246. package/dist/thirdweb/NebulaClient.js +180 -0
  247. package/dist/thirdweb/StorageClient.d.ts +445 -0
  248. package/dist/thirdweb/StorageClient.d.ts.map +1 -0
  249. package/dist/thirdweb/StorageClient.js +405 -0
  250. package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
  251. package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
  252. package/dist/thirdweb/ThirdwebWrapper.js +332 -0
  253. package/dist/thirdweb/index.d.ts +21 -0
  254. package/dist/thirdweb/index.d.ts.map +1 -0
  255. package/dist/thirdweb/index.js +28 -0
  256. package/dist/thirdweb/varity-chain.d.ts +48 -0
  257. package/dist/thirdweb/varity-chain.d.ts.map +1 -0
  258. package/dist/thirdweb/varity-chain.js +64 -0
  259. package/dist/thirdweb/x402Client.d.ts +319 -0
  260. package/dist/thirdweb/x402Client.d.ts.map +1 -0
  261. package/dist/thirdweb/x402Client.js +223 -0
  262. package/dist/tracking/gasTracker.d.ts +158 -0
  263. package/dist/tracking/gasTracker.d.ts.map +1 -0
  264. package/dist/tracking/gasTracker.js +227 -0
  265. package/dist/tracking/index.d.ts +10 -0
  266. package/dist/tracking/index.d.ts.map +1 -0
  267. package/dist/tracking/index.js +8 -0
  268. package/dist/tracking/types.d.ts +327 -0
  269. package/dist/tracking/types.d.ts.map +1 -0
  270. package/dist/tracking/types.js +8 -0
  271. package/dist/ui/components/ChartWidget.d.ts +36 -0
  272. package/dist/ui/components/ChartWidget.d.ts.map +1 -0
  273. package/dist/ui/components/ChartWidget.js +82 -0
  274. package/dist/ui/components/DashboardLayout.d.ts +41 -0
  275. package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
  276. package/dist/ui/components/DashboardLayout.js +102 -0
  277. package/dist/ui/components/DataTable.d.ts +49 -0
  278. package/dist/ui/components/DataTable.d.ts.map +1 -0
  279. package/dist/ui/components/DataTable.js +96 -0
  280. package/dist/ui/components/EntityForm.d.ts +60 -0
  281. package/dist/ui/components/EntityForm.d.ts.map +1 -0
  282. package/dist/ui/components/EntityForm.js +182 -0
  283. package/dist/ui/components/KPICard.d.ts +29 -0
  284. package/dist/ui/components/KPICard.d.ts.map +1 -0
  285. package/dist/ui/components/KPICard.js +61 -0
  286. package/dist/ui/components/Modal.d.ts +34 -0
  287. package/dist/ui/components/Modal.d.ts.map +1 -0
  288. package/dist/ui/components/Modal.js +30 -0
  289. package/dist/ui/components/index.d.ts +18 -0
  290. package/dist/ui/components/index.d.ts.map +1 -0
  291. package/dist/ui/components/index.js +11 -0
  292. package/dist/validation/template-validator.d.ts +25 -0
  293. package/dist/validation/template-validator.d.ts.map +1 -0
  294. package/dist/validation/template-validator.js +305 -0
  295. 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
+ }