@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,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 @@
|
|
|
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';
|