@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,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access Key Management Module
|
|
3
|
+
*
|
|
4
|
+
* Handles creation, listing, and revocation of API access keys for
|
|
5
|
+
* S3-compatible and GCS-compatible storage gateway authentication.
|
|
6
|
+
*
|
|
7
|
+
* @module AccessKeyModule
|
|
8
|
+
*/
|
|
9
|
+
import type { AccessKey, AccessKeyStatus, Permission, RateLimit } from '@varity-labs/types';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for the Varity SDK
|
|
12
|
+
* (Will be defined in SDK core, imported here for type safety)
|
|
13
|
+
*/
|
|
14
|
+
export interface VaritySDKConfig {
|
|
15
|
+
apiEndpoint?: string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
network?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Minimal SDK interface for dependency injection
|
|
21
|
+
*/
|
|
22
|
+
export interface VaritySDK {
|
|
23
|
+
getAPIEndpoint(): string;
|
|
24
|
+
getAPIKey(): string | null;
|
|
25
|
+
getNetwork(): string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for creating a new access key
|
|
29
|
+
*/
|
|
30
|
+
export interface CreateAccessKeyOptions {
|
|
31
|
+
/** Human-readable name for the key */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Optional description */
|
|
34
|
+
description?: string;
|
|
35
|
+
/** Permissions to grant (defaults to full storage access) */
|
|
36
|
+
permissions?: Permission[];
|
|
37
|
+
/** Number of days until key expires (optional) */
|
|
38
|
+
expiresInDays?: number;
|
|
39
|
+
/** Rate limiting configuration (optional, uses defaults) */
|
|
40
|
+
rateLimit?: RateLimit;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for updating an access key
|
|
44
|
+
*/
|
|
45
|
+
export interface UpdateAccessKeyOptions {
|
|
46
|
+
/** Update the name */
|
|
47
|
+
name?: string;
|
|
48
|
+
/** Update the description */
|
|
49
|
+
description?: string;
|
|
50
|
+
/** Update permissions */
|
|
51
|
+
permissions?: Permission[];
|
|
52
|
+
/** Update status */
|
|
53
|
+
status?: AccessKeyStatus;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Access Key Management Module
|
|
57
|
+
*
|
|
58
|
+
* Provides methods for managing API access keys used for authentication
|
|
59
|
+
* with S3-compatible and GCS-compatible storage gateways.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Create a new access key
|
|
64
|
+
* const accessKey = await sdk.accessKeys.createAccessKey({
|
|
65
|
+
* name: 'Production S3 Access',
|
|
66
|
+
* description: 'Used by production app for S3 uploads',
|
|
67
|
+
* expiresInDays: 90
|
|
68
|
+
* })
|
|
69
|
+
*
|
|
70
|
+
* console.log('Access Key ID:', accessKey.accessKeyId)
|
|
71
|
+
* console.log('Secret Key:', accessKey.secretAccessKey) // Only shown once!
|
|
72
|
+
*
|
|
73
|
+
* // List all access keys
|
|
74
|
+
* const keys = await sdk.accessKeys.listAccessKeys()
|
|
75
|
+
*
|
|
76
|
+
* // Revoke a key
|
|
77
|
+
* await sdk.accessKeys.revokeAccessKey(accessKey.accessKeyId)
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare class AccessKeyModule {
|
|
81
|
+
private sdk;
|
|
82
|
+
constructor(sdk: VaritySDK);
|
|
83
|
+
/**
|
|
84
|
+
* Create a new access key for the authenticated customer
|
|
85
|
+
*
|
|
86
|
+
* @param options - Configuration for the new access key
|
|
87
|
+
* @returns The created access key (including secret, only shown once!)
|
|
88
|
+
* @throws Error if authentication is missing or API request fails
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const key = await sdk.accessKeys.createAccessKey({
|
|
93
|
+
* name: 'Backup System Key',
|
|
94
|
+
* description: 'Used by nightly backup job',
|
|
95
|
+
* permissions: [{
|
|
96
|
+
* resource: 'bucket:backups/*',
|
|
97
|
+
* actions: [Action.PUT_OBJECT, Action.GET_OBJECT],
|
|
98
|
+
* effect: PermissionEffect.ALLOW
|
|
99
|
+
* }],
|
|
100
|
+
* expiresInDays: 365
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
createAccessKey(options: CreateAccessKeyOptions): Promise<AccessKey>;
|
|
105
|
+
/**
|
|
106
|
+
* List all access keys for the authenticated customer
|
|
107
|
+
*
|
|
108
|
+
* Note: Secret access keys are redacted in the list response for security.
|
|
109
|
+
* Secrets are only returned once during creation.
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of access keys (without secrets)
|
|
112
|
+
* @throws Error if authentication is missing or API request fails
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const keys = await sdk.accessKeys.listAccessKeys()
|
|
117
|
+
* for (const key of keys) {
|
|
118
|
+
* console.log(`${key.name}: ${key.accessKeyId} (${key.status})`)
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
listAccessKeys(): Promise<AccessKey[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Get details of a specific access key
|
|
125
|
+
*
|
|
126
|
+
* @param accessKeyId - Access key ID to retrieve
|
|
127
|
+
* @returns Access key details (without secret)
|
|
128
|
+
* @throws Error if authentication is missing or API request fails
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const key = await sdk.accessKeys.getAccessKey('VARIETYABC123')
|
|
133
|
+
* console.log('Last used:', key.lastUsedAt)
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
getAccessKey(accessKeyId: string): Promise<AccessKey>;
|
|
137
|
+
/**
|
|
138
|
+
* Revoke an access key (permanent, cannot be undone)
|
|
139
|
+
*
|
|
140
|
+
* @param accessKeyId - Access key ID to revoke
|
|
141
|
+
* @throws Error if authentication is missing or API request fails
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* await sdk.accessKeys.revokeAccessKey('VARIETYABC123')
|
|
146
|
+
* console.log('Key revoked successfully')
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
revokeAccessKey(accessKeyId: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Update access key properties
|
|
152
|
+
*
|
|
153
|
+
* @param accessKeyId - Access key ID to update
|
|
154
|
+
* @param updates - Properties to update
|
|
155
|
+
* @returns Updated access key
|
|
156
|
+
* @throws Error if authentication is missing or API request fails
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const updated = await sdk.accessKeys.updateAccessKey('VARIETYABC123', {
|
|
161
|
+
* name: 'New Key Name',
|
|
162
|
+
* status: AccessKeyStatus.INACTIVE
|
|
163
|
+
* })
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
updateAccessKey(accessKeyId: string, updates: UpdateAccessKeyOptions): Promise<AccessKey>;
|
|
167
|
+
/**
|
|
168
|
+
* Generate a random access key ID
|
|
169
|
+
* Format: VARITY + 16 random uppercase alphanumeric characters
|
|
170
|
+
* Example: VARIETYAB12CD34EF56GH78
|
|
171
|
+
*/
|
|
172
|
+
private generateAccessKeyId;
|
|
173
|
+
/**
|
|
174
|
+
* Generate a random secret access key
|
|
175
|
+
* Format: 40 random base64 characters
|
|
176
|
+
*/
|
|
177
|
+
private generateSecretAccessKey;
|
|
178
|
+
/**
|
|
179
|
+
* Get default permissions for new access keys
|
|
180
|
+
* Grants full storage access to all buckets
|
|
181
|
+
*/
|
|
182
|
+
private getDefaultPermissions;
|
|
183
|
+
/**
|
|
184
|
+
* Get default rate limit
|
|
185
|
+
* Generous limits suitable for most applications
|
|
186
|
+
*/
|
|
187
|
+
private getDefaultRateLimit;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=AccessKeyModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessKeyModule.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/AccessKeyModule.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,UAAU,EAGV,SAAS,EACV,MAAM,oBAAoB,CAAA;AAE3B;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,cAAc,IAAI,MAAM,CAAA;IACxB,SAAS,IAAI,MAAM,GAAG,IAAI,CAAA;IAC1B,UAAU,IAAI,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IAEZ,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAE1B,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,yBAAyB;IACzB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAE1B,oBAAoB;IACpB,MAAM,CAAC,EAAE,eAAe,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAW;gBAEV,GAAG,EAAE,SAAS;IAI1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC;IAuD1E;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAuC5C;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA0C3D;;;;;;;;;;;OAWG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BzD;;;;;;;;;;;;;;;OAeG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,SAAS,CAAC;IAiDrB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAI/B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAe7B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAO5B"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access Key Management Module
|
|
3
|
+
*
|
|
4
|
+
* Handles creation, listing, and revocation of API access keys for
|
|
5
|
+
* S3-compatible and GCS-compatible storage gateway authentication.
|
|
6
|
+
*
|
|
7
|
+
* @module AccessKeyModule
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes } from 'crypto';
|
|
10
|
+
/**
|
|
11
|
+
* Access Key Management Module
|
|
12
|
+
*
|
|
13
|
+
* Provides methods for managing API access keys used for authentication
|
|
14
|
+
* with S3-compatible and GCS-compatible storage gateways.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Create a new access key
|
|
19
|
+
* const accessKey = await sdk.accessKeys.createAccessKey({
|
|
20
|
+
* name: 'Production S3 Access',
|
|
21
|
+
* description: 'Used by production app for S3 uploads',
|
|
22
|
+
* expiresInDays: 90
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* console.log('Access Key ID:', accessKey.accessKeyId)
|
|
26
|
+
* console.log('Secret Key:', accessKey.secretAccessKey) // Only shown once!
|
|
27
|
+
*
|
|
28
|
+
* // List all access keys
|
|
29
|
+
* const keys = await sdk.accessKeys.listAccessKeys()
|
|
30
|
+
*
|
|
31
|
+
* // Revoke a key
|
|
32
|
+
* await sdk.accessKeys.revokeAccessKey(accessKey.accessKeyId)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class AccessKeyModule {
|
|
36
|
+
constructor(sdk) {
|
|
37
|
+
this.sdk = sdk;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a new access key for the authenticated customer
|
|
41
|
+
*
|
|
42
|
+
* @param options - Configuration for the new access key
|
|
43
|
+
* @returns The created access key (including secret, only shown once!)
|
|
44
|
+
* @throws Error if authentication is missing or API request fails
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const key = await sdk.accessKeys.createAccessKey({
|
|
49
|
+
* name: 'Backup System Key',
|
|
50
|
+
* description: 'Used by nightly backup job',
|
|
51
|
+
* permissions: [{
|
|
52
|
+
* resource: 'bucket:backups/*',
|
|
53
|
+
* actions: [Action.PUT_OBJECT, Action.GET_OBJECT],
|
|
54
|
+
* effect: PermissionEffect.ALLOW
|
|
55
|
+
* }],
|
|
56
|
+
* expiresInDays: 365
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async createAccessKey(options) {
|
|
61
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
62
|
+
const apiKey = this.sdk.getAPIKey();
|
|
63
|
+
if (!apiKey) {
|
|
64
|
+
throw new Error('Authentication required to create access keys');
|
|
65
|
+
}
|
|
66
|
+
// Generate access key ID and secret
|
|
67
|
+
const accessKeyId = this.generateAccessKeyId();
|
|
68
|
+
const secretAccessKey = this.generateSecretAccessKey();
|
|
69
|
+
const response = await fetch(`${apiEndpoint}/api/v1/auth/access-keys`, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: {
|
|
72
|
+
'Content-Type': 'application/json',
|
|
73
|
+
'Authorization': `Bearer ${apiKey}`
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
accessKeyId,
|
|
77
|
+
secretAccessKey,
|
|
78
|
+
name: options.name,
|
|
79
|
+
description: options.description,
|
|
80
|
+
permissions: options.permissions || this.getDefaultPermissions(),
|
|
81
|
+
expiresAt: options.expiresInDays
|
|
82
|
+
? new Date(Date.now() + options.expiresInDays * 24 * 60 * 60 * 1000)
|
|
83
|
+
: undefined,
|
|
84
|
+
rateLimit: options.rateLimit || this.getDefaultRateLimit()
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
const errorData = await response.json().catch(() => ({}));
|
|
89
|
+
throw new Error(`Failed to create access key: ${response.statusText}. ${errorData.message || ''}`);
|
|
90
|
+
}
|
|
91
|
+
const data = await response.json();
|
|
92
|
+
return {
|
|
93
|
+
accessKeyId: data.accessKeyId,
|
|
94
|
+
secretAccessKey: data.secretAccessKey,
|
|
95
|
+
customerId: data.customerId,
|
|
96
|
+
name: data.name,
|
|
97
|
+
description: data.description,
|
|
98
|
+
permissions: data.permissions,
|
|
99
|
+
status: data.status,
|
|
100
|
+
createdAt: new Date(data.createdAt),
|
|
101
|
+
expiresAt: data.expiresAt ? new Date(data.expiresAt) : undefined
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* List all access keys for the authenticated customer
|
|
106
|
+
*
|
|
107
|
+
* Note: Secret access keys are redacted in the list response for security.
|
|
108
|
+
* Secrets are only returned once during creation.
|
|
109
|
+
*
|
|
110
|
+
* @returns Array of access keys (without secrets)
|
|
111
|
+
* @throws Error if authentication is missing or API request fails
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const keys = await sdk.accessKeys.listAccessKeys()
|
|
116
|
+
* for (const key of keys) {
|
|
117
|
+
* console.log(`${key.name}: ${key.accessKeyId} (${key.status})`)
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async listAccessKeys() {
|
|
122
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
123
|
+
const apiKey = this.sdk.getAPIKey();
|
|
124
|
+
if (!apiKey) {
|
|
125
|
+
throw new Error('Authentication required to list access keys');
|
|
126
|
+
}
|
|
127
|
+
const response = await fetch(`${apiEndpoint}/api/v1/auth/access-keys`, {
|
|
128
|
+
headers: {
|
|
129
|
+
'Authorization': `Bearer ${apiKey}`
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
const errorData = await response.json().catch(() => ({}));
|
|
134
|
+
throw new Error(`Failed to list access keys: ${response.statusText}. ${errorData.message || ''}`);
|
|
135
|
+
}
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
return data.accessKeys.map((key) => ({
|
|
138
|
+
accessKeyId: key.accessKeyId,
|
|
139
|
+
secretAccessKey: '***REDACTED***', // Never return secret in list
|
|
140
|
+
customerId: key.customerId,
|
|
141
|
+
name: key.name,
|
|
142
|
+
description: key.description,
|
|
143
|
+
permissions: key.permissions,
|
|
144
|
+
status: key.status,
|
|
145
|
+
createdAt: new Date(key.createdAt),
|
|
146
|
+
lastUsedAt: key.lastUsedAt ? new Date(key.lastUsedAt) : undefined,
|
|
147
|
+
expiresAt: key.expiresAt ? new Date(key.expiresAt) : undefined
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get details of a specific access key
|
|
152
|
+
*
|
|
153
|
+
* @param accessKeyId - Access key ID to retrieve
|
|
154
|
+
* @returns Access key details (without secret)
|
|
155
|
+
* @throws Error if authentication is missing or API request fails
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const key = await sdk.accessKeys.getAccessKey('VARIETYABC123')
|
|
160
|
+
* console.log('Last used:', key.lastUsedAt)
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async getAccessKey(accessKeyId) {
|
|
164
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
165
|
+
const apiKey = this.sdk.getAPIKey();
|
|
166
|
+
if (!apiKey) {
|
|
167
|
+
throw new Error('Authentication required to get access key');
|
|
168
|
+
}
|
|
169
|
+
const response = await fetch(`${apiEndpoint}/api/v1/auth/access-keys/${accessKeyId}`, {
|
|
170
|
+
headers: {
|
|
171
|
+
'Authorization': `Bearer ${apiKey}`
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
const errorData = await response.json().catch(() => ({}));
|
|
176
|
+
throw new Error(`Failed to get access key: ${response.statusText}. ${errorData.message || ''}`);
|
|
177
|
+
}
|
|
178
|
+
const data = await response.json();
|
|
179
|
+
return {
|
|
180
|
+
accessKeyId: data.accessKeyId,
|
|
181
|
+
secretAccessKey: '***REDACTED***',
|
|
182
|
+
customerId: data.customerId,
|
|
183
|
+
name: data.name,
|
|
184
|
+
description: data.description,
|
|
185
|
+
permissions: data.permissions,
|
|
186
|
+
status: data.status,
|
|
187
|
+
createdAt: new Date(data.createdAt),
|
|
188
|
+
lastUsedAt: data.lastUsedAt ? new Date(data.lastUsedAt) : undefined,
|
|
189
|
+
expiresAt: data.expiresAt ? new Date(data.expiresAt) : undefined
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Revoke an access key (permanent, cannot be undone)
|
|
194
|
+
*
|
|
195
|
+
* @param accessKeyId - Access key ID to revoke
|
|
196
|
+
* @throws Error if authentication is missing or API request fails
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* await sdk.accessKeys.revokeAccessKey('VARIETYABC123')
|
|
201
|
+
* console.log('Key revoked successfully')
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
async revokeAccessKey(accessKeyId) {
|
|
205
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
206
|
+
const apiKey = this.sdk.getAPIKey();
|
|
207
|
+
if (!apiKey) {
|
|
208
|
+
throw new Error('Authentication required to revoke access keys');
|
|
209
|
+
}
|
|
210
|
+
const response = await fetch(`${apiEndpoint}/api/v1/auth/access-keys/${accessKeyId}`, {
|
|
211
|
+
method: 'DELETE',
|
|
212
|
+
headers: {
|
|
213
|
+
'Authorization': `Bearer ${apiKey}`
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
if (!response.ok) {
|
|
217
|
+
const errorData = await response.json().catch(() => ({}));
|
|
218
|
+
throw new Error(`Failed to revoke access key: ${response.statusText}. ${errorData.message || ''}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Update access key properties
|
|
223
|
+
*
|
|
224
|
+
* @param accessKeyId - Access key ID to update
|
|
225
|
+
* @param updates - Properties to update
|
|
226
|
+
* @returns Updated access key
|
|
227
|
+
* @throws Error if authentication is missing or API request fails
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const updated = await sdk.accessKeys.updateAccessKey('VARIETYABC123', {
|
|
232
|
+
* name: 'New Key Name',
|
|
233
|
+
* status: AccessKeyStatus.INACTIVE
|
|
234
|
+
* })
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
async updateAccessKey(accessKeyId, updates) {
|
|
238
|
+
const apiEndpoint = this.sdk.getAPIEndpoint();
|
|
239
|
+
const apiKey = this.sdk.getAPIKey();
|
|
240
|
+
if (!apiKey) {
|
|
241
|
+
throw new Error('Authentication required to update access keys');
|
|
242
|
+
}
|
|
243
|
+
const response = await fetch(`${apiEndpoint}/api/v1/auth/access-keys/${accessKeyId}`, {
|
|
244
|
+
method: 'PATCH',
|
|
245
|
+
headers: {
|
|
246
|
+
'Content-Type': 'application/json',
|
|
247
|
+
'Authorization': `Bearer ${apiKey}`
|
|
248
|
+
},
|
|
249
|
+
body: JSON.stringify(updates)
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
const errorData = await response.json().catch(() => ({}));
|
|
253
|
+
throw new Error(`Failed to update access key: ${response.statusText}. ${errorData.message || ''}`);
|
|
254
|
+
}
|
|
255
|
+
const data = await response.json();
|
|
256
|
+
return {
|
|
257
|
+
accessKeyId: data.accessKeyId,
|
|
258
|
+
secretAccessKey: '***REDACTED***',
|
|
259
|
+
customerId: data.customerId,
|
|
260
|
+
name: data.name,
|
|
261
|
+
description: data.description,
|
|
262
|
+
permissions: data.permissions,
|
|
263
|
+
status: data.status,
|
|
264
|
+
createdAt: new Date(data.createdAt),
|
|
265
|
+
lastUsedAt: data.lastUsedAt ? new Date(data.lastUsedAt) : undefined,
|
|
266
|
+
expiresAt: data.expiresAt ? new Date(data.expiresAt) : undefined
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// Private Helper Methods
|
|
271
|
+
// ============================================================================
|
|
272
|
+
/**
|
|
273
|
+
* Generate a random access key ID
|
|
274
|
+
* Format: VARITY + 16 random uppercase alphanumeric characters
|
|
275
|
+
* Example: VARIETYAB12CD34EF56GH78
|
|
276
|
+
*/
|
|
277
|
+
generateAccessKeyId() {
|
|
278
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
279
|
+
const bytes = randomBytes(16);
|
|
280
|
+
let result = 'VARITY';
|
|
281
|
+
for (let i = 0; i < 16; i++) {
|
|
282
|
+
result += chars[bytes[i] % chars.length];
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Generate a random secret access key
|
|
288
|
+
* Format: 40 random base64 characters
|
|
289
|
+
*/
|
|
290
|
+
generateSecretAccessKey() {
|
|
291
|
+
return randomBytes(30).toString('base64');
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get default permissions for new access keys
|
|
295
|
+
* Grants full storage access to all buckets
|
|
296
|
+
*/
|
|
297
|
+
getDefaultPermissions() {
|
|
298
|
+
return [
|
|
299
|
+
{
|
|
300
|
+
resource: 'bucket:*',
|
|
301
|
+
actions: [
|
|
302
|
+
'storage:GetObject',
|
|
303
|
+
'storage:PutObject',
|
|
304
|
+
'storage:DeleteObject',
|
|
305
|
+
'storage:ListObjects'
|
|
306
|
+
],
|
|
307
|
+
effect: 'allow'
|
|
308
|
+
}
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get default rate limit
|
|
313
|
+
* Generous limits suitable for most applications
|
|
314
|
+
*/
|
|
315
|
+
getDefaultRateLimit() {
|
|
316
|
+
return {
|
|
317
|
+
requestsPerSecond: 100,
|
|
318
|
+
requestsPerDay: 1000000,
|
|
319
|
+
bandwidthPerDay: 100 * 1024 * 1024 * 1024 // 100 GB
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity SDK - Auth Module
|
|
3
|
+
*
|
|
4
|
+
* Universal authentication, permissions, and access control.
|
|
5
|
+
* Works across all templates (ISO, Healthcare, Retail, etc.)
|
|
6
|
+
*/
|
|
7
|
+
import type { VaritySDK } from '../../core/VaritySDK';
|
|
8
|
+
import type { Role, UserProfile, AccessCondition } from '../../core/types';
|
|
9
|
+
export interface LoginCredentials {
|
|
10
|
+
address?: string;
|
|
11
|
+
signature?: string;
|
|
12
|
+
message?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AuthToken {
|
|
15
|
+
token: string;
|
|
16
|
+
expiresAt: number;
|
|
17
|
+
user: string;
|
|
18
|
+
}
|
|
19
|
+
export interface User {
|
|
20
|
+
address: string;
|
|
21
|
+
roles: Role[];
|
|
22
|
+
profile?: UserProfile;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* AuthModule - Universal authentication and access control
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Login with wallet
|
|
30
|
+
* const token = await sdk.auth.login({ address: '0x...' })
|
|
31
|
+
*
|
|
32
|
+
* // Check permissions
|
|
33
|
+
* const canAccess = await sdk.auth.checkPermission('0x...', 'merchants')
|
|
34
|
+
*
|
|
35
|
+
* // Assign role
|
|
36
|
+
* await sdk.auth.assignRole('0x...', Role.MANAGER)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class AuthModule {
|
|
40
|
+
private sdk;
|
|
41
|
+
private accessControlContract;
|
|
42
|
+
constructor(sdk: VaritySDK);
|
|
43
|
+
/**
|
|
44
|
+
* Initialize Access Control contract
|
|
45
|
+
*/
|
|
46
|
+
private getAccessControlContract;
|
|
47
|
+
/**
|
|
48
|
+
* Login with wallet signature
|
|
49
|
+
*
|
|
50
|
+
* @param credentials - Login credentials
|
|
51
|
+
* @returns Authentication token
|
|
52
|
+
*/
|
|
53
|
+
login(credentials: LoginCredentials): Promise<AuthToken>;
|
|
54
|
+
/**
|
|
55
|
+
* Logout current user
|
|
56
|
+
*/
|
|
57
|
+
logout(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get current authenticated user
|
|
60
|
+
*
|
|
61
|
+
* @returns Current user info
|
|
62
|
+
*/
|
|
63
|
+
getCurrentUser(): Promise<User>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if user has permission to access a resource
|
|
66
|
+
*
|
|
67
|
+
* @param user - User address
|
|
68
|
+
* @param resource - Resource identifier
|
|
69
|
+
* @returns True if user has access
|
|
70
|
+
*/
|
|
71
|
+
checkPermission(user: string, resource: string): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Assign role to user
|
|
74
|
+
*
|
|
75
|
+
* @param user - User address
|
|
76
|
+
* @param role - Role to assign
|
|
77
|
+
* @param metadata - Optional metadata
|
|
78
|
+
*/
|
|
79
|
+
assignRole(user: string, role: Role, metadata?: string): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Revoke role from user
|
|
82
|
+
*
|
|
83
|
+
* @param user - User address
|
|
84
|
+
* @param role - Role to revoke
|
|
85
|
+
*/
|
|
86
|
+
revokeRole(user: string, role: Role): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Get all roles for a user
|
|
89
|
+
*
|
|
90
|
+
* @param user - User address
|
|
91
|
+
* @returns Array of roles
|
|
92
|
+
*/
|
|
93
|
+
getUserRoles(user: string): Promise<Role[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Get user profile
|
|
96
|
+
*
|
|
97
|
+
* @param user - User address
|
|
98
|
+
* @returns User profile
|
|
99
|
+
*/
|
|
100
|
+
getUserProfile(user: string): Promise<UserProfile>;
|
|
101
|
+
/**
|
|
102
|
+
* Set Lit Protocol access condition for a role
|
|
103
|
+
*
|
|
104
|
+
* @param role - Role
|
|
105
|
+
* @param condition - Lit Protocol condition JSON
|
|
106
|
+
* @param encryptedKey - Encrypted symmetric key
|
|
107
|
+
*/
|
|
108
|
+
setAccessCondition(role: Role, condition: string, encryptedKey: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Get Lit Protocol access condition for a role
|
|
111
|
+
*
|
|
112
|
+
* @param role - Role
|
|
113
|
+
* @returns Access condition
|
|
114
|
+
*/
|
|
115
|
+
getAccessCondition(role: Role): Promise<AccessCondition>;
|
|
116
|
+
/**
|
|
117
|
+
* Check if user has a specific role
|
|
118
|
+
*
|
|
119
|
+
* @param user - User address
|
|
120
|
+
* @param role - Role to check
|
|
121
|
+
* @returns True if user has the role
|
|
122
|
+
*/
|
|
123
|
+
hasRole(user: string, role: Role): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Check if user has any of the specified roles
|
|
126
|
+
*
|
|
127
|
+
* @param user - User address
|
|
128
|
+
* @param roles - Roles to check
|
|
129
|
+
* @returns True if user has any of the roles
|
|
130
|
+
*/
|
|
131
|
+
hasAnyRole(user: string, roles: Role[]): Promise<boolean>;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=AuthModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModule.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/AuthModule.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAG1E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,IAAI;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,qBAAqB,CAA+B;gBAEhD,GAAG,EAAE,SAAS;IAI1B;;OAEG;YACW,wBAAwB;IAatC;;;;;OAKG;IACG,KAAK,CAAC,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAuB9D;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAM7B;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrC;;;;;;OAMG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYvE;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB5E;;;;;OAKG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzD;;;;;OAKG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAQjD;;;;;OAKG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAcxD;;;;;;OAMG;IACG,kBAAkB,CACtB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;IAgBhB;;;;;OAKG;IACG,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC;IAY9D;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzD;;;;;;OAMG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAIhE"}
|