@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,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NotificationsModule - Universal notifications and alerting
|
|
3
|
+
*
|
|
4
|
+
* Provides multi-channel notification delivery with templates, scheduling,
|
|
5
|
+
* preferences, and alert rules. Works across all templates by using
|
|
6
|
+
* template-specific notification templates.
|
|
7
|
+
*/
|
|
8
|
+
export class NotificationsModule {
|
|
9
|
+
constructor(sdk) {
|
|
10
|
+
this.sdk = sdk;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Send notification immediately
|
|
14
|
+
*
|
|
15
|
+
* Universal method - sends notifications via any channel for any template.
|
|
16
|
+
* Template configuration provides template-specific message content.
|
|
17
|
+
*
|
|
18
|
+
* @example ISO Dashboard
|
|
19
|
+
* ```typescript
|
|
20
|
+
* await sdk.notifications.send({
|
|
21
|
+
* type: 'email',
|
|
22
|
+
* to: 'merchant@example.com',
|
|
23
|
+
* template: 'merchant_registered',
|
|
24
|
+
* data: { merchantName: 'Acme Corp' }
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example Healthcare Dashboard
|
|
29
|
+
* ```typescript
|
|
30
|
+
* await sdk.notifications.send({
|
|
31
|
+
* type: 'sms',
|
|
32
|
+
* to: '+1234567890',
|
|
33
|
+
* template: 'appointment_reminder',
|
|
34
|
+
* data: { patientName: 'John Doe', appointmentTime: '2025-01-15 10:00' }
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
async send(options) {
|
|
39
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
40
|
+
const apiKey = this.sdk.getAPIKey();
|
|
41
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/send`, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(options)
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(`Failed to send notification: ${response.statusText}`);
|
|
51
|
+
}
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Send batch notifications
|
|
56
|
+
*
|
|
57
|
+
* Universal method - sends multiple notifications efficiently.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const results = await sdk.notifications.sendBatch([
|
|
62
|
+
* { type: 'email', to: 'user1@example.com', template: 'alert' },
|
|
63
|
+
* { type: 'email', to: 'user2@example.com', template: 'alert' },
|
|
64
|
+
* { type: 'sms', to: '+1234567890', template: 'urgent_alert' }
|
|
65
|
+
* ])
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
async sendBatch(notifications) {
|
|
69
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
70
|
+
const apiKey = this.sdk.getAPIKey();
|
|
71
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/send-batch`, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'application/json',
|
|
75
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
76
|
+
},
|
|
77
|
+
body: JSON.stringify({ notifications })
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`Failed to send batch notifications: ${response.statusText}`);
|
|
81
|
+
}
|
|
82
|
+
return await response.json();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get notification preferences for a user
|
|
86
|
+
*
|
|
87
|
+
* Universal method - retrieves user notification preferences.
|
|
88
|
+
*/
|
|
89
|
+
async getPreferences(userId) {
|
|
90
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
91
|
+
const apiKey = this.sdk.getAPIKey();
|
|
92
|
+
const url = userId
|
|
93
|
+
? `${apiEndpoint}/api/v1/notifications/preferences?userId=${userId}`
|
|
94
|
+
: `${apiEndpoint}/api/v1/notifications/preferences`;
|
|
95
|
+
const response = await fetch(url, {
|
|
96
|
+
method: 'GET',
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`Failed to get notification preferences: ${response.statusText}`);
|
|
104
|
+
}
|
|
105
|
+
return await response.json();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Set notification preferences for a user
|
|
109
|
+
*
|
|
110
|
+
* Universal method - updates user notification preferences.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* await sdk.notifications.setPreferences({
|
|
115
|
+
* email: true,
|
|
116
|
+
* slack: true,
|
|
117
|
+
* push: false,
|
|
118
|
+
* alerts: ['compliance', 'anomaly', 'milestone'],
|
|
119
|
+
* quietHours: {
|
|
120
|
+
* enabled: true,
|
|
121
|
+
* start: '22:00',
|
|
122
|
+
* end: '08:00',
|
|
123
|
+
* timezone: 'America/New_York'
|
|
124
|
+
* }
|
|
125
|
+
* })
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
async setPreferences(preferences, userId) {
|
|
129
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
130
|
+
const apiKey = this.sdk.getAPIKey();
|
|
131
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/preferences`, {
|
|
132
|
+
method: 'PUT',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
136
|
+
},
|
|
137
|
+
body: JSON.stringify({ preferences, userId })
|
|
138
|
+
});
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
throw new Error(`Failed to set notification preferences: ${response.statusText}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get notification history
|
|
145
|
+
*
|
|
146
|
+
* Universal method - retrieves past notifications with filtering.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const history = await sdk.notifications.getHistory({
|
|
151
|
+
* type: 'email',
|
|
152
|
+
* status: 'delivered',
|
|
153
|
+
* startDate: '2025-01-01',
|
|
154
|
+
* limit: 50
|
|
155
|
+
* })
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async getHistory(options = {}) {
|
|
159
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
160
|
+
const apiKey = this.sdk.getAPIKey();
|
|
161
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/history`, {
|
|
162
|
+
method: 'POST',
|
|
163
|
+
headers: {
|
|
164
|
+
'Content-Type': 'application/json',
|
|
165
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
166
|
+
},
|
|
167
|
+
body: JSON.stringify(options)
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new Error(`Failed to get notification history: ${response.statusText}`);
|
|
171
|
+
}
|
|
172
|
+
return await response.json();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Schedule notification for later delivery
|
|
176
|
+
*
|
|
177
|
+
* Universal method - schedules notifications for future delivery.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const scheduled = await sdk.notifications.schedule({
|
|
182
|
+
* type: 'email',
|
|
183
|
+
* to: 'user@example.com',
|
|
184
|
+
* template: 'monthly_report',
|
|
185
|
+
* scheduledFor: '2025-02-01T09:00:00Z',
|
|
186
|
+
* repeat: {
|
|
187
|
+
* interval: 'monthly',
|
|
188
|
+
* count: 12
|
|
189
|
+
* }
|
|
190
|
+
* })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
async schedule(options) {
|
|
194
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
195
|
+
const apiKey = this.sdk.getAPIKey();
|
|
196
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/schedule`, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: {
|
|
199
|
+
'Content-Type': 'application/json',
|
|
200
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
201
|
+
},
|
|
202
|
+
body: JSON.stringify(options)
|
|
203
|
+
});
|
|
204
|
+
if (!response.ok) {
|
|
205
|
+
throw new Error(`Failed to schedule notification: ${response.statusText}`);
|
|
206
|
+
}
|
|
207
|
+
return await response.json();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Cancel scheduled notification
|
|
211
|
+
*
|
|
212
|
+
* Universal method - cancels a scheduled notification.
|
|
213
|
+
*/
|
|
214
|
+
async cancelScheduled(notificationId) {
|
|
215
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
216
|
+
const apiKey = this.sdk.getAPIKey();
|
|
217
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/schedule/${notificationId}`, {
|
|
218
|
+
method: 'DELETE',
|
|
219
|
+
headers: {
|
|
220
|
+
'Content-Type': 'application/json',
|
|
221
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
throw new Error(`Failed to cancel scheduled notification: ${response.statusText}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* List scheduled notifications
|
|
230
|
+
*
|
|
231
|
+
* Universal method - lists all scheduled notifications.
|
|
232
|
+
*/
|
|
233
|
+
async listScheduled(options = {}) {
|
|
234
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
235
|
+
const apiKey = this.sdk.getAPIKey();
|
|
236
|
+
const queryParams = new URLSearchParams();
|
|
237
|
+
if (options.status)
|
|
238
|
+
queryParams.append('status', options.status);
|
|
239
|
+
if (options.limit)
|
|
240
|
+
queryParams.append('limit', options.limit.toString());
|
|
241
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/scheduled?${queryParams}`, {
|
|
242
|
+
method: 'GET',
|
|
243
|
+
headers: {
|
|
244
|
+
'Content-Type': 'application/json',
|
|
245
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
if (!response.ok) {
|
|
249
|
+
throw new Error(`Failed to list scheduled notifications: ${response.statusText}`);
|
|
250
|
+
}
|
|
251
|
+
return await response.json();
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Create alert rule
|
|
255
|
+
*
|
|
256
|
+
* Universal method - creates an automatic alert based on conditions.
|
|
257
|
+
*
|
|
258
|
+
* @example ISO Dashboard
|
|
259
|
+
* ```typescript
|
|
260
|
+
* await sdk.notifications.createAlertRule({
|
|
261
|
+
* name: 'High Residual Alert',
|
|
262
|
+
* condition: {
|
|
263
|
+
* metric: 'residual_amount',
|
|
264
|
+
* operator: '>',
|
|
265
|
+
* threshold: 10000,
|
|
266
|
+
* duration: 300 // 5 minutes
|
|
267
|
+
* },
|
|
268
|
+
* notification: {
|
|
269
|
+
* type: 'email',
|
|
270
|
+
* to: 'admin@example.com',
|
|
271
|
+
* template: 'high_residual_alert'
|
|
272
|
+
* },
|
|
273
|
+
* enabled: true
|
|
274
|
+
* })
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
async createAlertRule(rule) {
|
|
278
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
279
|
+
const apiKey = this.sdk.getAPIKey();
|
|
280
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/alert-rules`, {
|
|
281
|
+
method: 'POST',
|
|
282
|
+
headers: {
|
|
283
|
+
'Content-Type': 'application/json',
|
|
284
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
285
|
+
},
|
|
286
|
+
body: JSON.stringify(rule)
|
|
287
|
+
});
|
|
288
|
+
if (!response.ok) {
|
|
289
|
+
throw new Error(`Failed to create alert rule: ${response.statusText}`);
|
|
290
|
+
}
|
|
291
|
+
return await response.json();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Update alert rule
|
|
295
|
+
*
|
|
296
|
+
* Universal method - updates an existing alert rule.
|
|
297
|
+
*/
|
|
298
|
+
async updateAlertRule(ruleId, updates) {
|
|
299
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
300
|
+
const apiKey = this.sdk.getAPIKey();
|
|
301
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/alert-rules/${ruleId}`, {
|
|
302
|
+
method: 'PUT',
|
|
303
|
+
headers: {
|
|
304
|
+
'Content-Type': 'application/json',
|
|
305
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
306
|
+
},
|
|
307
|
+
body: JSON.stringify(updates)
|
|
308
|
+
});
|
|
309
|
+
if (!response.ok) {
|
|
310
|
+
throw new Error(`Failed to update alert rule: ${response.statusText}`);
|
|
311
|
+
}
|
|
312
|
+
return await response.json();
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Delete alert rule
|
|
316
|
+
*
|
|
317
|
+
* Universal method - deletes an alert rule.
|
|
318
|
+
*/
|
|
319
|
+
async deleteAlertRule(ruleId) {
|
|
320
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
321
|
+
const apiKey = this.sdk.getAPIKey();
|
|
322
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/alert-rules/${ruleId}`, {
|
|
323
|
+
method: 'DELETE',
|
|
324
|
+
headers: {
|
|
325
|
+
'Content-Type': 'application/json',
|
|
326
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
if (!response.ok) {
|
|
330
|
+
throw new Error(`Failed to delete alert rule: ${response.statusText}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* List alert rules
|
|
335
|
+
*
|
|
336
|
+
* Universal method - lists all alert rules.
|
|
337
|
+
*/
|
|
338
|
+
async listAlertRules(options = {}) {
|
|
339
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
340
|
+
const apiKey = this.sdk.getAPIKey();
|
|
341
|
+
const queryParams = new URLSearchParams();
|
|
342
|
+
if (options.enabled !== undefined)
|
|
343
|
+
queryParams.append('enabled', options.enabled.toString());
|
|
344
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/alert-rules?${queryParams}`, {
|
|
345
|
+
method: 'GET',
|
|
346
|
+
headers: {
|
|
347
|
+
'Content-Type': 'application/json',
|
|
348
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
if (!response.ok) {
|
|
352
|
+
throw new Error(`Failed to list alert rules: ${response.statusText}`);
|
|
353
|
+
}
|
|
354
|
+
return await response.json();
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Create notification template
|
|
358
|
+
*
|
|
359
|
+
* Universal method - creates a reusable notification template.
|
|
360
|
+
*/
|
|
361
|
+
async createTemplate(template) {
|
|
362
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
363
|
+
const apiKey = this.sdk.getAPIKey();
|
|
364
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/templates`, {
|
|
365
|
+
method: 'POST',
|
|
366
|
+
headers: {
|
|
367
|
+
'Content-Type': 'application/json',
|
|
368
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
369
|
+
},
|
|
370
|
+
body: JSON.stringify(template)
|
|
371
|
+
});
|
|
372
|
+
if (!response.ok) {
|
|
373
|
+
throw new Error(`Failed to create notification template: ${response.statusText}`);
|
|
374
|
+
}
|
|
375
|
+
return await response.json();
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Get notification template
|
|
379
|
+
*
|
|
380
|
+
* Universal method - retrieves a notification template by name.
|
|
381
|
+
*/
|
|
382
|
+
async getTemplate(templateName) {
|
|
383
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
384
|
+
const apiKey = this.sdk.getAPIKey();
|
|
385
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/templates/${templateName}`, {
|
|
386
|
+
method: 'GET',
|
|
387
|
+
headers: {
|
|
388
|
+
'Content-Type': 'application/json',
|
|
389
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
if (!response.ok) {
|
|
393
|
+
throw new Error(`Failed to get notification template: ${response.statusText}`);
|
|
394
|
+
}
|
|
395
|
+
return await response.json();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* List notification templates
|
|
399
|
+
*
|
|
400
|
+
* Universal method - lists all available notification templates.
|
|
401
|
+
*/
|
|
402
|
+
async listTemplates(type) {
|
|
403
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
404
|
+
const apiKey = this.sdk.getAPIKey();
|
|
405
|
+
const queryParams = type ? `?type=${type}` : '';
|
|
406
|
+
const response = await fetch(`${apiEndpoint}/api/v1/notifications/templates${queryParams}`, {
|
|
407
|
+
method: 'GET',
|
|
408
|
+
headers: {
|
|
409
|
+
'Content-Type': 'application/json',
|
|
410
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
throw new Error(`Failed to list notification templates: ${response.statusText}`);
|
|
415
|
+
}
|
|
416
|
+
return await response.json();
|
|
417
|
+
}
|
|
418
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { NotificationsModule } from './NotificationsModule';
|
|
2
|
+
export type { NotificationType, NotificationPriority, NotificationStatus, SendNotificationOptions, NotificationAttachment, NotificationResult, NotificationPreferences, NotificationHistoryOptions, NotificationHistoryEntry, NotificationHistoryResult, ScheduleNotificationOptions, ScheduledNotification, AlertRule, AlertCondition, AlertRuleResult, NotificationTemplate } from './NotificationsModule';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,eAAe,EACf,oBAAoB,EACrB,MAAM,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NotificationsModule } from './NotificationsModule';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Oracle Module
|
|
3
|
+
*
|
|
4
|
+
* Universal oracle data fetching.
|
|
5
|
+
* Works across all templates (ISO, Healthcare, Retail, etc.)
|
|
6
|
+
*/
|
|
7
|
+
import type { VaritySDK } from '../../core/VaritySDK';
|
|
8
|
+
export interface OracleQuery {
|
|
9
|
+
source: string;
|
|
10
|
+
parameters: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface OracleData {
|
|
13
|
+
value: any;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
source: string;
|
|
16
|
+
confidence?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface DataCallback {
|
|
19
|
+
(data: OracleData): void;
|
|
20
|
+
}
|
|
21
|
+
export interface Subscription {
|
|
22
|
+
id: string;
|
|
23
|
+
unsubscribe: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface PriceData {
|
|
26
|
+
asset: string;
|
|
27
|
+
price: number;
|
|
28
|
+
currency: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
source: string;
|
|
31
|
+
}
|
|
32
|
+
export interface TimeRange {
|
|
33
|
+
start: Date;
|
|
34
|
+
end: Date;
|
|
35
|
+
}
|
|
36
|
+
export interface PriceHistory {
|
|
37
|
+
asset: string;
|
|
38
|
+
prices: Array<{
|
|
39
|
+
price: number;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
}>;
|
|
42
|
+
range: TimeRange;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* OracleModule - Universal oracle data fetching
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Get oracle data
|
|
50
|
+
* const data = await sdk.oracle.getData({
|
|
51
|
+
* source: 'chainlink',
|
|
52
|
+
* parameters: { asset: 'ETH/USD' }
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* // Get price feed
|
|
56
|
+
* const price = await sdk.oracle.getPrice('ETH')
|
|
57
|
+
*
|
|
58
|
+
* // Subscribe to updates
|
|
59
|
+
* const sub = await sdk.oracle.subscribe(
|
|
60
|
+
* { source: 'chainlink', parameters: { asset: 'ETH/USD' } },
|
|
61
|
+
* (data) => console.log('New price:', data.value)
|
|
62
|
+
* )
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare class OracleModule {
|
|
66
|
+
private sdk;
|
|
67
|
+
private subscriptions;
|
|
68
|
+
constructor(sdk: VaritySDK);
|
|
69
|
+
/**
|
|
70
|
+
* Get data from oracle
|
|
71
|
+
*
|
|
72
|
+
* @param query - Oracle query
|
|
73
|
+
* @returns Oracle data
|
|
74
|
+
*/
|
|
75
|
+
getData(query: OracleQuery): Promise<OracleData>;
|
|
76
|
+
/**
|
|
77
|
+
* Subscribe to oracle data updates
|
|
78
|
+
*
|
|
79
|
+
* @param query - Oracle query
|
|
80
|
+
* @param callback - Data callback
|
|
81
|
+
* @returns Subscription
|
|
82
|
+
*/
|
|
83
|
+
subscribe(query: OracleQuery, callback: DataCallback): Promise<Subscription>;
|
|
84
|
+
/**
|
|
85
|
+
* Unsubscribe from oracle data
|
|
86
|
+
*
|
|
87
|
+
* @param subscriptionId - Subscription identifier
|
|
88
|
+
*/
|
|
89
|
+
unsubscribe(subscriptionId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get current price for an asset
|
|
92
|
+
*
|
|
93
|
+
* @param asset - Asset symbol (e.g., 'ETH', 'BTC')
|
|
94
|
+
* @returns Price data
|
|
95
|
+
*/
|
|
96
|
+
getPrice(asset: string): Promise<PriceData>;
|
|
97
|
+
/**
|
|
98
|
+
* Get price history for an asset
|
|
99
|
+
*
|
|
100
|
+
* @param asset - Asset symbol
|
|
101
|
+
* @param range - Time range
|
|
102
|
+
* @returns Price history
|
|
103
|
+
*/
|
|
104
|
+
getPriceHistory(asset: string, range: TimeRange): Promise<PriceHistory>;
|
|
105
|
+
/**
|
|
106
|
+
* Remove all subscriptions
|
|
107
|
+
*/
|
|
108
|
+
removeAllSubscriptions(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=OracleModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OracleModule.d.ts","sourceRoot":"","sources":["../../../src/modules/oracle/OracleModule.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAErD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,EAAE,IAAI,CAAA;CACV;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,MAAM,CAAA;QACb,SAAS,EAAE,MAAM,CAAA;KAClB,CAAC,CAAA;IACF,KAAK,EAAE,SAAS,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,aAAa,CAA8B;gBAEvC,GAAG,EAAE,SAAS;IAI1B;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBtD;;;;;;OAMG;IACG,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAuBlF;;;;OAIG;IACG,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAejD;;;;;;OAMG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IA2B7E;;OAEG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9C"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Oracle Module
|
|
3
|
+
*
|
|
4
|
+
* Universal oracle data fetching.
|
|
5
|
+
* Works across all templates (ISO, Healthcare, Retail, etc.)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* OracleModule - Universal oracle data fetching
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Get oracle data
|
|
13
|
+
* const data = await sdk.oracle.getData({
|
|
14
|
+
* source: 'chainlink',
|
|
15
|
+
* parameters: { asset: 'ETH/USD' }
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Get price feed
|
|
19
|
+
* const price = await sdk.oracle.getPrice('ETH')
|
|
20
|
+
*
|
|
21
|
+
* // Subscribe to updates
|
|
22
|
+
* const sub = await sdk.oracle.subscribe(
|
|
23
|
+
* { source: 'chainlink', parameters: { asset: 'ETH/USD' } },
|
|
24
|
+
* (data) => console.log('New price:', data.value)
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class OracleModule {
|
|
29
|
+
constructor(sdk) {
|
|
30
|
+
this.subscriptions = new Map();
|
|
31
|
+
this.sdk = sdk;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get data from oracle
|
|
35
|
+
*
|
|
36
|
+
* @param query - Oracle query
|
|
37
|
+
* @returns Oracle data
|
|
38
|
+
*/
|
|
39
|
+
async getData(query) {
|
|
40
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
41
|
+
const apiKey = this.sdk.getAPIKey();
|
|
42
|
+
const response = await fetch(`${apiEndpoint}/api/v1/oracle/query`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(query)
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new Error(`Oracle query failed: ${response.statusText}`);
|
|
52
|
+
}
|
|
53
|
+
return await response.json();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Subscribe to oracle data updates
|
|
57
|
+
*
|
|
58
|
+
* @param query - Oracle query
|
|
59
|
+
* @param callback - Data callback
|
|
60
|
+
* @returns Subscription
|
|
61
|
+
*/
|
|
62
|
+
async subscribe(query, callback) {
|
|
63
|
+
const subscriptionId = `${query.source}:${JSON.stringify(query.parameters)}`;
|
|
64
|
+
// For v1, we use polling. Future versions could use WebSocket
|
|
65
|
+
const pollInterval = setInterval(async () => {
|
|
66
|
+
try {
|
|
67
|
+
const data = await this.getData(query);
|
|
68
|
+
callback(data);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error('Oracle subscription error:', error);
|
|
72
|
+
}
|
|
73
|
+
}, 5000); // Poll every 5 seconds
|
|
74
|
+
this.subscriptions.set(subscriptionId, pollInterval);
|
|
75
|
+
return {
|
|
76
|
+
id: subscriptionId,
|
|
77
|
+
unsubscribe: async () => {
|
|
78
|
+
await this.unsubscribe(subscriptionId);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Unsubscribe from oracle data
|
|
84
|
+
*
|
|
85
|
+
* @param subscriptionId - Subscription identifier
|
|
86
|
+
*/
|
|
87
|
+
async unsubscribe(subscriptionId) {
|
|
88
|
+
const interval = this.subscriptions.get(subscriptionId);
|
|
89
|
+
if (interval) {
|
|
90
|
+
clearInterval(interval);
|
|
91
|
+
this.subscriptions.delete(subscriptionId);
|
|
92
|
+
console.log(`✅ Unsubscribed from ${subscriptionId}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get current price for an asset
|
|
97
|
+
*
|
|
98
|
+
* @param asset - Asset symbol (e.g., 'ETH', 'BTC')
|
|
99
|
+
* @returns Price data
|
|
100
|
+
*/
|
|
101
|
+
async getPrice(asset) {
|
|
102
|
+
const data = await this.getData({
|
|
103
|
+
source: 'chainlink',
|
|
104
|
+
parameters: { asset: `${asset}/USD` }
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
asset,
|
|
108
|
+
price: data.value,
|
|
109
|
+
currency: 'USD',
|
|
110
|
+
timestamp: data.timestamp,
|
|
111
|
+
source: data.source
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get price history for an asset
|
|
116
|
+
*
|
|
117
|
+
* @param asset - Asset symbol
|
|
118
|
+
* @param range - Time range
|
|
119
|
+
* @returns Price history
|
|
120
|
+
*/
|
|
121
|
+
async getPriceHistory(asset, range) {
|
|
122
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
123
|
+
const apiKey = this.sdk.getAPIKey();
|
|
124
|
+
const response = await fetch(`${apiEndpoint}/api/v1/oracle/price-history`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: {
|
|
127
|
+
'Content-Type': 'application/json',
|
|
128
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` })
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
asset,
|
|
132
|
+
start: range.start.toISOString(),
|
|
133
|
+
end: range.end.toISOString()
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new Error(`Price history failed: ${response.statusText}`);
|
|
138
|
+
}
|
|
139
|
+
return await response.json();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Remove all subscriptions
|
|
143
|
+
*/
|
|
144
|
+
async removeAllSubscriptions() {
|
|
145
|
+
for (const [id, interval] of this.subscriptions.entries()) {
|
|
146
|
+
clearInterval(interval);
|
|
147
|
+
}
|
|
148
|
+
this.subscriptions.clear();
|
|
149
|
+
console.log('✅ All oracle subscriptions removed');
|
|
150
|
+
}
|
|
151
|
+
}
|