@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,493 @@
1
+ /**
2
+ * CacheModule - Universal caching and performance optimization
3
+ *
4
+ * Provides high-performance caching with TTL, namespacing, and invalidation
5
+ * patterns. Works across all templates to optimize query performance.
6
+ */
7
+ export class CacheModule {
8
+ constructor(sdk) {
9
+ this.sdk = sdk;
10
+ }
11
+ /**
12
+ * Get value from cache
13
+ *
14
+ * Universal method - retrieves cached value by key.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const kpis = await sdk.cache.get('dashboard:kpis:current_month')
19
+ * if (!kpis) {
20
+ * // Cache miss - fetch from source
21
+ * kpis = await sdk.analytics.getKPIs({ period: 'current_month' })
22
+ * await sdk.cache.set('dashboard:kpis:current_month', kpis, { ttl: 300 })
23
+ * }
24
+ * ```
25
+ */
26
+ async get(key, namespace) {
27
+ const apiEndpoint = this.sdk.getAPIEndpoint();
28
+ const apiKey = this.sdk.getAPIKey();
29
+ const fullKey = namespace ? `${namespace}:${key}` : key;
30
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}`, {
31
+ method: 'GET',
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
35
+ }
36
+ });
37
+ if (response.status === 404) {
38
+ return null; // Cache miss
39
+ }
40
+ if (!response.ok) {
41
+ throw new Error(`Failed to get cache value: ${response.statusText}`);
42
+ }
43
+ const result = await response.json();
44
+ return result.value;
45
+ }
46
+ /**
47
+ * Set value in cache with optional TTL
48
+ *
49
+ * Universal method - stores value in cache with expiration.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * await sdk.cache.set('user:123:profile', userProfile, { ttl: 3600, tags: ['user'] })
54
+ * ```
55
+ */
56
+ async set(key, value, options = {}) {
57
+ const apiEndpoint = this.sdk.getAPIEndpoint();
58
+ const apiKey = this.sdk.getAPIKey();
59
+ const fullKey = options.namespace ? `${options.namespace}:${key}` : key;
60
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}`, {
61
+ method: 'PUT',
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
65
+ },
66
+ body: JSON.stringify({
67
+ value,
68
+ ttl: options.ttl,
69
+ tags: options.tags,
70
+ compress: options.compress
71
+ })
72
+ });
73
+ if (!response.ok) {
74
+ throw new Error(`Failed to set cache value: ${response.statusText}`);
75
+ }
76
+ }
77
+ /**
78
+ * Delete value from cache
79
+ *
80
+ * Universal method - removes cached value by key.
81
+ */
82
+ async delete(key, namespace) {
83
+ const apiEndpoint = this.sdk.getAPIEndpoint();
84
+ const apiKey = this.sdk.getAPIKey();
85
+ const fullKey = namespace ? `${namespace}:${key}` : key;
86
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}`, {
87
+ method: 'DELETE',
88
+ headers: {
89
+ 'Content-Type': 'application/json',
90
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
91
+ }
92
+ });
93
+ if (response.status === 404) {
94
+ return false; // Key didn't exist
95
+ }
96
+ if (!response.ok) {
97
+ throw new Error(`Failed to delete cache value: ${response.statusText}`);
98
+ }
99
+ return true;
100
+ }
101
+ /**
102
+ * Check if key exists in cache
103
+ *
104
+ * Universal method - checks cache key existence without retrieving value.
105
+ */
106
+ async has(key, namespace) {
107
+ const apiEndpoint = this.sdk.getAPIEndpoint();
108
+ const apiKey = this.sdk.getAPIKey();
109
+ const fullKey = namespace ? `${namespace}:${key}` : key;
110
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}/exists`, {
111
+ method: 'GET',
112
+ headers: {
113
+ 'Content-Type': 'application/json',
114
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
115
+ }
116
+ });
117
+ if (!response.ok) {
118
+ throw new Error(`Failed to check cache key: ${response.statusText}`);
119
+ }
120
+ const result = await response.json();
121
+ return result.exists;
122
+ }
123
+ /**
124
+ * Remember pattern - get from cache or execute function and cache result
125
+ *
126
+ * Universal method - simplifies cache-aside pattern.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const kpis = await sdk.cache.remember(
131
+ * 'dashboard:kpis',
132
+ * async () => await sdk.analytics.getKPIs(),
133
+ * { ttl: 300 }
134
+ * )
135
+ * ```
136
+ */
137
+ async remember(key, fn, options = {}) {
138
+ // Try to get from cache first
139
+ const cached = await this.get(key, options.namespace);
140
+ if (cached !== null) {
141
+ return cached;
142
+ }
143
+ // Cache miss - execute function
144
+ const result = await fn();
145
+ // Store in cache
146
+ await this.set(key, result, options);
147
+ return result;
148
+ }
149
+ /**
150
+ * Invalidate cache by pattern
151
+ *
152
+ * Universal method - removes all keys matching pattern.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * // Invalidate all user-related cache
157
+ * await sdk.cache.invalidate('user:*')
158
+ *
159
+ * // Invalidate specific namespace
160
+ * await sdk.cache.invalidate('*', 'analytics')
161
+ * ```
162
+ */
163
+ async invalidate(pattern, namespace) {
164
+ const apiEndpoint = this.sdk.getAPIEndpoint();
165
+ const apiKey = this.sdk.getAPIKey();
166
+ const fullPattern = namespace ? `${namespace}:${pattern}` : pattern;
167
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/invalidate`, {
168
+ method: 'POST',
169
+ headers: {
170
+ 'Content-Type': 'application/json',
171
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
172
+ },
173
+ body: JSON.stringify({ pattern: fullPattern })
174
+ });
175
+ if (!response.ok) {
176
+ throw new Error(`Failed to invalidate cache: ${response.statusText}`);
177
+ }
178
+ const result = await response.json();
179
+ return result.deletedCount;
180
+ }
181
+ /**
182
+ * Invalidate cache by tags
183
+ *
184
+ * Universal method - removes all keys with specific tags.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Set cache with tags
189
+ * await sdk.cache.set('merchant:123', data, { tags: ['merchant', 'iso'] })
190
+ *
191
+ * // Invalidate all entries with 'merchant' tag
192
+ * await sdk.cache.invalidateByTags(['merchant'])
193
+ * ```
194
+ */
195
+ async invalidateByTags(tags) {
196
+ const apiEndpoint = this.sdk.getAPIEndpoint();
197
+ const apiKey = this.sdk.getAPIKey();
198
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/invalidate-by-tags`, {
199
+ method: 'POST',
200
+ headers: {
201
+ 'Content-Type': 'application/json',
202
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
203
+ },
204
+ body: JSON.stringify({ tags })
205
+ });
206
+ if (!response.ok) {
207
+ throw new Error(`Failed to invalidate by tags: ${response.statusText}`);
208
+ }
209
+ const result = await response.json();
210
+ return result.deletedCount;
211
+ }
212
+ /**
213
+ * Clear entire cache or namespace
214
+ *
215
+ * Universal method - removes all cached entries.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * // Clear entire cache
220
+ * await sdk.cache.clear()
221
+ *
222
+ * // Clear specific namespace
223
+ * await sdk.cache.clear('analytics')
224
+ * ```
225
+ */
226
+ async clear(namespace) {
227
+ const apiEndpoint = this.sdk.getAPIEndpoint();
228
+ const apiKey = this.sdk.getAPIKey();
229
+ const queryParams = namespace ? `?namespace=${namespace}` : '';
230
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/clear${queryParams}`, {
231
+ method: 'POST',
232
+ headers: {
233
+ 'Content-Type': 'application/json',
234
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
235
+ }
236
+ });
237
+ if (!response.ok) {
238
+ throw new Error(`Failed to clear cache: ${response.statusText}`);
239
+ }
240
+ const result = await response.json();
241
+ return result.deletedCount;
242
+ }
243
+ /**
244
+ * Get cache statistics
245
+ *
246
+ * Universal method - retrieves cache performance metrics.
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const stats = await sdk.cache.getStats()
251
+ * console.log(`Cache hit rate: ${stats.hitRate}%`)
252
+ * ```
253
+ */
254
+ async getStats(namespace) {
255
+ const apiEndpoint = this.sdk.getAPIEndpoint();
256
+ const apiKey = this.sdk.getAPIKey();
257
+ const queryParams = namespace ? `?namespace=${namespace}` : '';
258
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/stats${queryParams}`, {
259
+ method: 'GET',
260
+ headers: {
261
+ 'Content-Type': 'application/json',
262
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
263
+ }
264
+ });
265
+ if (!response.ok) {
266
+ throw new Error(`Failed to get cache stats: ${response.statusText}`);
267
+ }
268
+ return await response.json();
269
+ }
270
+ /**
271
+ * Batch operations on cache
272
+ *
273
+ * Universal method - performs multiple cache operations efficiently.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const results = await sdk.cache.batch([
278
+ * { key: 'user:123', operation: 'get' },
279
+ * { key: 'user:456', operation: 'get' },
280
+ * { key: 'session:abc', operation: 'delete' }
281
+ * ])
282
+ * ```
283
+ */
284
+ async batch(operations) {
285
+ const apiEndpoint = this.sdk.getAPIEndpoint();
286
+ const apiKey = this.sdk.getAPIKey();
287
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/batch`, {
288
+ method: 'POST',
289
+ headers: {
290
+ 'Content-Type': 'application/json',
291
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
292
+ },
293
+ body: JSON.stringify({ operations })
294
+ });
295
+ if (!response.ok) {
296
+ throw new Error(`Failed to perform batch operations: ${response.statusText}`);
297
+ }
298
+ return await response.json();
299
+ }
300
+ /**
301
+ * Get multiple values from cache
302
+ *
303
+ * Universal method - retrieves multiple cached values efficiently.
304
+ *
305
+ * @example
306
+ * ```typescript
307
+ * const values = await sdk.cache.getMany(['user:123', 'user:456', 'user:789'])
308
+ * ```
309
+ */
310
+ async getMany(keys, namespace) {
311
+ const operations = keys.map(key => ({
312
+ key: namespace ? `${namespace}:${key}` : key,
313
+ operation: 'get'
314
+ }));
315
+ const results = await this.batch(operations);
316
+ const map = new Map();
317
+ results.forEach((result, index) => {
318
+ if (result.success && result.value !== null) {
319
+ map.set(keys[index], result.value);
320
+ }
321
+ });
322
+ return map;
323
+ }
324
+ /**
325
+ * Set multiple values in cache
326
+ *
327
+ * Universal method - stores multiple values efficiently.
328
+ */
329
+ async setMany(entries) {
330
+ const operations = entries.map(entry => ({
331
+ key: entry.options?.namespace ? `${entry.options.namespace}:${entry.key}` : entry.key,
332
+ value: entry.value,
333
+ operation: 'set',
334
+ options: entry.options
335
+ }));
336
+ await this.batch(operations);
337
+ }
338
+ /**
339
+ * Delete multiple keys from cache
340
+ *
341
+ * Universal method - removes multiple cached values efficiently.
342
+ */
343
+ async deleteMany(keys, namespace) {
344
+ const operations = keys.map(key => ({
345
+ key: namespace ? `${namespace}:${key}` : key,
346
+ operation: 'delete'
347
+ }));
348
+ const results = await this.batch(operations);
349
+ return results.filter(r => r.success).length;
350
+ }
351
+ /**
352
+ * List keys matching pattern
353
+ *
354
+ * Universal method - finds all keys matching a pattern.
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * const keys = await sdk.cache.keys('user:*')
359
+ * ```
360
+ */
361
+ async keys(pattern, namespace) {
362
+ const apiEndpoint = this.sdk.getAPIEndpoint();
363
+ const apiKey = this.sdk.getAPIKey();
364
+ const fullPattern = namespace ? `${namespace}:${pattern}` : pattern;
365
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/keys?pattern=${encodeURIComponent(fullPattern)}`, {
366
+ method: 'GET',
367
+ headers: {
368
+ 'Content-Type': 'application/json',
369
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
370
+ }
371
+ });
372
+ if (!response.ok) {
373
+ throw new Error(`Failed to list cache keys: ${response.statusText}`);
374
+ }
375
+ const result = await response.json();
376
+ return result.keys;
377
+ }
378
+ /**
379
+ * Get TTL (time to live) for a key
380
+ *
381
+ * Universal method - returns remaining TTL in seconds.
382
+ */
383
+ async ttl(key, namespace) {
384
+ const apiEndpoint = this.sdk.getAPIEndpoint();
385
+ const apiKey = this.sdk.getAPIKey();
386
+ const fullKey = namespace ? `${namespace}:${key}` : key;
387
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}/ttl`, {
388
+ method: 'GET',
389
+ headers: {
390
+ 'Content-Type': 'application/json',
391
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
392
+ }
393
+ });
394
+ if (response.status === 404) {
395
+ return null; // Key doesn't exist
396
+ }
397
+ if (!response.ok) {
398
+ throw new Error(`Failed to get TTL: ${response.statusText}`);
399
+ }
400
+ const result = await response.json();
401
+ return result.ttl;
402
+ }
403
+ /**
404
+ * Extend TTL for a key
405
+ *
406
+ * Universal method - extends expiration time for cached value.
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * // Extend TTL by 1 hour
411
+ * await sdk.cache.extend('session:abc', 3600)
412
+ * ```
413
+ */
414
+ async extend(key, additionalTTL, namespace) {
415
+ const apiEndpoint = this.sdk.getAPIEndpoint();
416
+ const apiKey = this.sdk.getAPIKey();
417
+ const fullKey = namespace ? `${namespace}:${key}` : key;
418
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}/extend`, {
419
+ method: 'POST',
420
+ headers: {
421
+ 'Content-Type': 'application/json',
422
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
423
+ },
424
+ body: JSON.stringify({ ttl: additionalTTL })
425
+ });
426
+ if (response.status === 404) {
427
+ return false; // Key doesn't exist
428
+ }
429
+ if (!response.ok) {
430
+ throw new Error(`Failed to extend TTL: ${response.statusText}`);
431
+ }
432
+ return true;
433
+ }
434
+ /**
435
+ * Increment numeric value in cache
436
+ *
437
+ * Universal method - atomically increments cached number.
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * // Increment page view counter
442
+ * const views = await sdk.cache.increment('page:views:home', 1)
443
+ * ```
444
+ */
445
+ async increment(key, amount = 1, namespace) {
446
+ const apiEndpoint = this.sdk.getAPIEndpoint();
447
+ const apiKey = this.sdk.getAPIKey();
448
+ const fullKey = namespace ? `${namespace}:${key}` : key;
449
+ const response = await fetch(`${apiEndpoint}/api/v1/cache/${encodeURIComponent(fullKey)}/increment`, {
450
+ method: 'POST',
451
+ headers: {
452
+ 'Content-Type': 'application/json',
453
+ ...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
454
+ },
455
+ body: JSON.stringify({ amount })
456
+ });
457
+ if (!response.ok) {
458
+ throw new Error(`Failed to increment: ${response.statusText}`);
459
+ }
460
+ const result = await response.json();
461
+ return result.value;
462
+ }
463
+ /**
464
+ * Decrement numeric value in cache
465
+ *
466
+ * Universal method - atomically decrements cached number.
467
+ */
468
+ async decrement(key, amount = 1, namespace) {
469
+ return await this.increment(key, -amount, namespace);
470
+ }
471
+ /**
472
+ * Warm cache with data
473
+ *
474
+ * Universal method - preloads cache with frequently accessed data.
475
+ *
476
+ * @example
477
+ * ```typescript
478
+ * await sdk.cache.warm([
479
+ * { key: 'dashboard:kpis', fn: () => sdk.analytics.getKPIs(), ttl: 300 },
480
+ * { key: 'dashboard:trends', fn: () => sdk.analytics.getTrends(...), ttl: 300 }
481
+ * ])
482
+ * ```
483
+ */
484
+ async warm(entries) {
485
+ await Promise.all(entries.map(async (entry) => {
486
+ const exists = await this.has(entry.key, entry.options?.namespace);
487
+ if (!exists) {
488
+ const value = await entry.fn();
489
+ await this.set(entry.key, value, entry.options);
490
+ }
491
+ }));
492
+ }
493
+ }
@@ -0,0 +1,3 @@
1
+ export { CacheModule } from './CacheModule';
2
+ export type { CacheOptions, CacheEntry, CacheStats, CacheBatchOperation, CacheBatchResult, CachePattern } from './CacheModule';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EACV,YAAY,EACZ,UAAU,EACV,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAA"}
@@ -0,0 +1 @@
1
+ export { CacheModule } from './CacheModule';