@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba
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/CHANGELOG.md +1 -11
- package/dist/PerpsController.cjs +66 -2224
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +79 -933
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +79 -933
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +64 -2221
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/index.cjs +1 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -6
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -19
- package/dist/__mocks__/hyperliquidMock.cjs +0 -68
- package/dist/__mocks__/hyperliquidMock.cjs.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.cts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.cts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.d.mts +0 -15
- package/dist/__mocks__/hyperliquidMock.d.mts.map +0 -1
- package/dist/__mocks__/hyperliquidMock.mjs +0 -65
- package/dist/__mocks__/hyperliquidMock.mjs.map +0 -1
- package/dist/__mocks__/providerMocks.cjs +0 -144
- package/dist/__mocks__/providerMocks.cjs.map +0 -1
- package/dist/__mocks__/providerMocks.d.cts +0 -44
- package/dist/__mocks__/providerMocks.d.cts.map +0 -1
- package/dist/__mocks__/providerMocks.d.mts +0 -44
- package/dist/__mocks__/providerMocks.d.mts.map +0 -1
- package/dist/__mocks__/providerMocks.mjs +0 -136
- package/dist/__mocks__/providerMocks.mjs.map +0 -1
- package/dist/__mocks__/serviceMocks.cjs +0 -187
- package/dist/__mocks__/serviceMocks.cjs.map +0 -1
- package/dist/__mocks__/serviceMocks.d.cts +0 -58
- package/dist/__mocks__/serviceMocks.d.cts.map +0 -1
- package/dist/__mocks__/serviceMocks.d.mts +0 -58
- package/dist/__mocks__/serviceMocks.d.mts.map +0 -1
- package/dist/__mocks__/serviceMocks.mjs +0 -180
- package/dist/__mocks__/serviceMocks.mjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -459
- package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -222
- package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
- package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -455
- package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
- package/dist/aggregation/index.cjs +0 -9
- package/dist/aggregation/index.cjs.map +0 -1
- package/dist/aggregation/index.d.cts +0 -6
- package/dist/aggregation/index.d.cts.map +0 -1
- package/dist/aggregation/index.d.mts +0 -6
- package/dist/aggregation/index.d.mts.map +0 -1
- package/dist/aggregation/index.mjs +0 -5
- package/dist/aggregation/index.mjs.map +0 -1
- package/dist/constants/eventNames.cjs +0 -117
- package/dist/constants/eventNames.cjs.map +0 -1
- package/dist/constants/eventNames.d.cts +0 -106
- package/dist/constants/eventNames.d.cts.map +0 -1
- package/dist/constants/eventNames.d.mts +0 -106
- package/dist/constants/eventNames.d.mts.map +0 -1
- package/dist/constants/eventNames.mjs +0 -114
- package/dist/constants/eventNames.mjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.cjs +0 -366
- package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.cts +0 -276
- package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
- package/dist/constants/hyperLiquidConfig.d.mts +0 -276
- package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
- package/dist/constants/hyperLiquidConfig.mjs +0 -357
- package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
- package/dist/constants/index.cjs +0 -23
- package/dist/constants/index.cjs.map +0 -1
- package/dist/constants/index.d.cts +0 -7
- package/dist/constants/index.d.cts.map +0 -1
- package/dist/constants/index.d.mts +0 -7
- package/dist/constants/index.d.mts.map +0 -1
- package/dist/constants/index.mjs +0 -7
- package/dist/constants/index.mjs.map +0 -1
- package/dist/constants/orderTypes.cjs +0 -31
- package/dist/constants/orderTypes.cjs.map +0 -1
- package/dist/constants/orderTypes.d.cts +0 -19
- package/dist/constants/orderTypes.d.cts.map +0 -1
- package/dist/constants/orderTypes.d.mts +0 -19
- package/dist/constants/orderTypes.d.mts.map +0 -1
- package/dist/constants/orderTypes.mjs +0 -27
- package/dist/constants/orderTypes.mjs.map +0 -1
- package/dist/constants/performanceMetrics.cjs +0 -61
- package/dist/constants/performanceMetrics.cjs.map +0 -1
- package/dist/constants/performanceMetrics.d.cts +0 -44
- package/dist/constants/performanceMetrics.d.cts.map +0 -1
- package/dist/constants/performanceMetrics.d.mts +0 -44
- package/dist/constants/performanceMetrics.d.mts.map +0 -1
- package/dist/constants/performanceMetrics.mjs +0 -58
- package/dist/constants/performanceMetrics.mjs.map +0 -1
- package/dist/constants/perpsConfig.cjs +0 -461
- package/dist/constants/perpsConfig.cjs.map +0 -1
- package/dist/constants/perpsConfig.d.cts +0 -343
- package/dist/constants/perpsConfig.d.cts.map +0 -1
- package/dist/constants/perpsConfig.d.mts +0 -343
- package/dist/constants/perpsConfig.d.mts.map +0 -1
- package/dist/constants/perpsConfig.mjs +0 -458
- package/dist/constants/perpsConfig.mjs.map +0 -1
- package/dist/constants/perpsErrorCodes.cjs +0 -79
- package/dist/constants/perpsErrorCodes.cjs.map +0 -1
- package/dist/constants/perpsErrorCodes.d.cts +0 -64
- package/dist/constants/perpsErrorCodes.d.cts.map +0 -1
- package/dist/constants/perpsErrorCodes.d.mts +0 -64
- package/dist/constants/perpsErrorCodes.d.mts.map +0 -1
- package/dist/constants/perpsErrorCodes.mjs +0 -76
- package/dist/constants/perpsErrorCodes.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.cjs +0 -857
- package/dist/platform-services/HyperLiquidClientService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.cts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.d.mts +0 -263
- package/dist/platform-services/HyperLiquidClientService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidClientService.mjs +0 -853
- package/dist/platform-services/HyperLiquidClientService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs +0 -2170
- package/dist/platform-services/HyperLiquidSubscriptionService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts +0 -424
- package/dist/platform-services/HyperLiquidSubscriptionService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs +0 -2166
- package/dist/platform-services/HyperLiquidSubscriptionService.mjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.cjs +0 -140
- package/dist/platform-services/HyperLiquidWalletService.cjs.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.cts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.cts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.d.mts +0 -78
- package/dist/platform-services/HyperLiquidWalletService.d.mts.map +0 -1
- package/dist/platform-services/HyperLiquidWalletService.mjs +0 -136
- package/dist/platform-services/HyperLiquidWalletService.mjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +0 -777
- package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +0 -466
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +0 -773
- package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.cjs +0 -5172
- package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.cts +0 -881
- package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
- package/dist/providers/HyperLiquidProvider.d.mts +0 -881
- package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
- package/dist/providers/HyperLiquidProvider.mjs +0 -5168
- package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
- package/dist/providers/index.cjs +0 -11
- package/dist/providers/index.cjs.map +0 -1
- package/dist/providers/index.d.cts +0 -6
- package/dist/providers/index.d.cts.map +0 -1
- package/dist/providers/index.d.mts +0 -6
- package/dist/providers/index.d.mts.map +0 -1
- package/dist/providers/index.mjs +0 -6
- package/dist/providers/index.mjs.map +0 -1
- package/dist/routing/ProviderRouter.cjs +0 -148
- package/dist/routing/ProviderRouter.cjs.map +0 -1
- package/dist/routing/ProviderRouter.d.cts +0 -124
- package/dist/routing/ProviderRouter.d.cts.map +0 -1
- package/dist/routing/ProviderRouter.d.mts +0 -124
- package/dist/routing/ProviderRouter.d.mts.map +0 -1
- package/dist/routing/ProviderRouter.mjs +0 -144
- package/dist/routing/ProviderRouter.mjs.map +0 -1
- package/dist/routing/index.cjs +0 -9
- package/dist/routing/index.cjs.map +0 -1
- package/dist/routing/index.d.cts +0 -6
- package/dist/routing/index.d.cts.map +0 -1
- package/dist/routing/index.d.mts +0 -6
- package/dist/routing/index.d.mts.map +0 -1
- package/dist/routing/index.mjs +0 -5
- package/dist/routing/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -161
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -345
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts +0 -345
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs +0 -153
- package/dist/selectors.mjs.map +0 -1
- package/dist/services/AccountService.cjs +0 -313
- package/dist/services/AccountService.cjs.map +0 -1
- package/dist/services/AccountService.d.cts +0 -53
- package/dist/services/AccountService.d.cts.map +0 -1
- package/dist/services/AccountService.d.mts +0 -53
- package/dist/services/AccountService.d.mts.map +0 -1
- package/dist/services/AccountService.mjs +0 -309
- package/dist/services/AccountService.mjs.map +0 -1
- package/dist/services/DataLakeService.cjs +0 -219
- package/dist/services/DataLakeService.cjs.map +0 -1
- package/dist/services/DataLakeService.d.cts +0 -49
- package/dist/services/DataLakeService.d.cts.map +0 -1
- package/dist/services/DataLakeService.d.mts +0 -49
- package/dist/services/DataLakeService.d.mts.map +0 -1
- package/dist/services/DataLakeService.mjs +0 -215
- package/dist/services/DataLakeService.mjs.map +0 -1
- package/dist/services/DepositService.cjs +0 -96
- package/dist/services/DepositService.cjs.map +0 -1
- package/dist/services/DepositService.d.cts +0 -37
- package/dist/services/DepositService.d.cts.map +0 -1
- package/dist/services/DepositService.d.mts +0 -37
- package/dist/services/DepositService.d.mts.map +0 -1
- package/dist/services/DepositService.mjs +0 -92
- package/dist/services/DepositService.mjs.map +0 -1
- package/dist/services/EligibilityService.cjs +0 -156
- package/dist/services/EligibilityService.cjs.map +0 -1
- package/dist/services/EligibilityService.d.cts +0 -48
- package/dist/services/EligibilityService.d.cts.map +0 -1
- package/dist/services/EligibilityService.d.mts +0 -48
- package/dist/services/EligibilityService.d.mts.map +0 -1
- package/dist/services/EligibilityService.mjs +0 -152
- package/dist/services/EligibilityService.mjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.cjs +0 -258
- package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.cts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.d.mts +0 -100
- package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
- package/dist/services/FeatureFlagConfigurationService.mjs +0 -254
- package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
- package/dist/services/MarketDataService.cjs +0 -875
- package/dist/services/MarketDataService.cjs.map +0 -1
- package/dist/services/MarketDataService.d.cts +0 -289
- package/dist/services/MarketDataService.d.cts.map +0 -1
- package/dist/services/MarketDataService.d.mts +0 -289
- package/dist/services/MarketDataService.d.mts.map +0 -1
- package/dist/services/MarketDataService.mjs +0 -871
- package/dist/services/MarketDataService.mjs.map +0 -1
- package/dist/services/RewardsIntegrationService.cjs +0 -94
- package/dist/services/RewardsIntegrationService.cjs.map +0 -1
- package/dist/services/RewardsIntegrationService.d.cts +0 -30
- package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
- package/dist/services/RewardsIntegrationService.d.mts +0 -30
- package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
- package/dist/services/RewardsIntegrationService.mjs +0 -90
- package/dist/services/RewardsIntegrationService.mjs.map +0 -1
- package/dist/services/ServiceContext.cjs +0 -3
- package/dist/services/ServiceContext.cjs.map +0 -1
- package/dist/services/ServiceContext.d.cts +0 -110
- package/dist/services/ServiceContext.d.cts.map +0 -1
- package/dist/services/ServiceContext.d.mts +0 -110
- package/dist/services/ServiceContext.d.mts.map +0 -1
- package/dist/services/ServiceContext.mjs +0 -2
- package/dist/services/ServiceContext.mjs.map +0 -1
- package/dist/services/TradingService.cjs +0 -1481
- package/dist/services/TradingService.cjs.map +0 -1
- package/dist/services/TradingService.d.cts +0 -308
- package/dist/services/TradingService.d.cts.map +0 -1
- package/dist/services/TradingService.d.mts +0 -308
- package/dist/services/TradingService.d.mts.map +0 -1
- package/dist/services/TradingService.mjs +0 -1477
- package/dist/services/TradingService.mjs.map +0 -1
- package/dist/services/index.cjs +0 -26
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.d.cts +0 -11
- package/dist/services/index.d.cts.map +0 -1
- package/dist/services/index.d.mts +0 -11
- package/dist/services/index.d.mts.map +0 -1
- package/dist/services/index.mjs +0 -10
- package/dist/services/index.mjs.map +0 -1
- package/dist/services/utils.cjs +0 -16
- package/dist/services/utils.cjs.map +0 -1
- package/dist/services/utils.d.cts +0 -8
- package/dist/services/utils.d.cts.map +0 -1
- package/dist/services/utils.d.mts +0 -8
- package/dist/services/utils.d.mts.map +0 -1
- package/dist/services/utils.mjs +0 -12
- package/dist/services/utils.mjs.map +0 -1
- package/dist/types/chart.cjs +0 -42
- package/dist/types/chart.cjs.map +0 -1
- package/dist/types/chart.d.cts +0 -62
- package/dist/types/chart.d.cts.map +0 -1
- package/dist/types/chart.d.mts +0 -62
- package/dist/types/chart.d.mts.map +0 -1
- package/dist/types/chart.mjs +0 -39
- package/dist/types/chart.mjs.map +0 -1
- package/dist/types/hyperliquid-types.cjs +0 -3
- package/dist/types/hyperliquid-types.cjs.map +0 -1
- package/dist/types/hyperliquid-types.d.cts +0 -52
- package/dist/types/hyperliquid-types.d.cts.map +0 -1
- package/dist/types/hyperliquid-types.d.mts +0 -52
- package/dist/types/hyperliquid-types.d.mts.map +0 -1
- package/dist/types/hyperliquid-types.mjs +0 -2
- package/dist/types/hyperliquid-types.mjs.map +0 -1
- package/dist/types/index.cjs +0 -96
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -1153
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -1153
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -79
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/transactionTypes.cjs +0 -28
- package/dist/types/transactionTypes.cjs.map +0 -1
- package/dist/types/transactionTypes.d.cts +0 -64
- package/dist/types/transactionTypes.d.cts.map +0 -1
- package/dist/types/transactionTypes.d.mts +0 -64
- package/dist/types/transactionTypes.d.mts.map +0 -1
- package/dist/types/transactionTypes.mjs +0 -23
- package/dist/types/transactionTypes.mjs.map +0 -1
- package/dist/utils/accountUtils.cjs +0 -65
- package/dist/utils/accountUtils.cjs.map +0 -1
- package/dist/utils/accountUtils.d.cts +0 -26
- package/dist/utils/accountUtils.d.cts.map +0 -1
- package/dist/utils/accountUtils.d.mts +0 -26
- package/dist/utils/accountUtils.d.mts.map +0 -1
- package/dist/utils/accountUtils.mjs +0 -61
- package/dist/utils/accountUtils.mjs.map +0 -1
- package/dist/utils/amountConversion.cjs +0 -61
- package/dist/utils/amountConversion.cjs.map +0 -1
- package/dist/utils/amountConversion.d.cts +0 -16
- package/dist/utils/amountConversion.d.cts.map +0 -1
- package/dist/utils/amountConversion.d.mts +0 -16
- package/dist/utils/amountConversion.d.mts.map +0 -1
- package/dist/utils/amountConversion.mjs +0 -54
- package/dist/utils/amountConversion.mjs.map +0 -1
- package/dist/utils/chartUtils.cjs +0 -98
- package/dist/utils/chartUtils.cjs.map +0 -1
- package/dist/utils/chartUtils.d.cts +0 -14
- package/dist/utils/chartUtils.d.cts.map +0 -1
- package/dist/utils/chartUtils.d.mts +0 -14
- package/dist/utils/chartUtils.d.mts.map +0 -1
- package/dist/utils/chartUtils.mjs +0 -94
- package/dist/utils/chartUtils.mjs.map +0 -1
- package/dist/utils/errorUtils.cjs +0 -22
- package/dist/utils/errorUtils.cjs.map +0 -1
- package/dist/utils/errorUtils.d.cts +0 -13
- package/dist/utils/errorUtils.d.cts.map +0 -1
- package/dist/utils/errorUtils.d.mts +0 -13
- package/dist/utils/errorUtils.d.mts.map +0 -1
- package/dist/utils/errorUtils.mjs +0 -18
- package/dist/utils/errorUtils.mjs.map +0 -1
- package/dist/utils/formatUtils.cjs +0 -987
- package/dist/utils/formatUtils.cjs.map +0 -1
- package/dist/utils/formatUtils.d.cts +0 -387
- package/dist/utils/formatUtils.d.cts.map +0 -1
- package/dist/utils/formatUtils.d.mts +0 -387
- package/dist/utils/formatUtils.d.mts.map +0 -1
- package/dist/utils/formatUtils.mjs +0 -966
- package/dist/utils/formatUtils.mjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.cjs +0 -454
- package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.cts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.d.mts +0 -158
- package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
- package/dist/utils/hyperLiquidAdapter.mjs +0 -439
- package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -89
- package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -58
- package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -84
- package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.cjs +0 -426
- package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.cts +0 -143
- package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
- package/dist/utils/hyperLiquidValidation.d.mts +0 -143
- package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
- package/dist/utils/hyperLiquidValidation.mjs +0 -413
- package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
- package/dist/utils/idUtils.cjs +0 -50
- package/dist/utils/idUtils.cjs.map +0 -1
- package/dist/utils/idUtils.d.cts +0 -38
- package/dist/utils/idUtils.d.cts.map +0 -1
- package/dist/utils/idUtils.d.mts +0 -38
- package/dist/utils/idUtils.d.mts.map +0 -1
- package/dist/utils/idUtils.mjs +0 -42
- package/dist/utils/idUtils.mjs.map +0 -1
- package/dist/utils/marginUtils.cjs +0 -137
- package/dist/utils/marginUtils.cjs.map +0 -1
- package/dist/utils/marginUtils.d.cts +0 -64
- package/dist/utils/marginUtils.d.cts.map +0 -1
- package/dist/utils/marginUtils.d.mts +0 -64
- package/dist/utils/marginUtils.d.mts.map +0 -1
- package/dist/utils/marginUtils.mjs +0 -131
- package/dist/utils/marginUtils.mjs.map +0 -1
- package/dist/utils/marketDataTransform.cjs +0 -227
- package/dist/utils/marketDataTransform.cjs.map +0 -1
- package/dist/utils/marketDataTransform.d.cts +0 -45
- package/dist/utils/marketDataTransform.d.cts.map +0 -1
- package/dist/utils/marketDataTransform.d.mts +0 -45
- package/dist/utils/marketDataTransform.d.mts.map +0 -1
- package/dist/utils/marketDataTransform.mjs +0 -220
- package/dist/utils/marketDataTransform.mjs.map +0 -1
- package/dist/utils/marketUtils.cjs +0 -420
- package/dist/utils/marketUtils.cjs.map +0 -1
- package/dist/utils/marketUtils.d.cts +0 -227
- package/dist/utils/marketUtils.d.cts.map +0 -1
- package/dist/utils/marketUtils.d.mts +0 -227
- package/dist/utils/marketUtils.d.mts.map +0 -1
- package/dist/utils/marketUtils.mjs +0 -404
- package/dist/utils/marketUtils.mjs.map +0 -1
- package/dist/utils/orderBookGrouping.cjs +0 -151
- package/dist/utils/orderBookGrouping.cjs.map +0 -1
- package/dist/utils/orderBookGrouping.d.cts +0 -76
- package/dist/utils/orderBookGrouping.d.cts.map +0 -1
- package/dist/utils/orderBookGrouping.d.mts +0 -76
- package/dist/utils/orderBookGrouping.d.mts.map +0 -1
- package/dist/utils/orderBookGrouping.mjs +0 -143
- package/dist/utils/orderBookGrouping.mjs.map +0 -1
- package/dist/utils/orderCalculations.cjs +0 -283
- package/dist/utils/orderCalculations.cjs.map +0 -1
- package/dist/utils/orderCalculations.d.cts +0 -107
- package/dist/utils/orderCalculations.d.cts.map +0 -1
- package/dist/utils/orderCalculations.d.mts +0 -107
- package/dist/utils/orderCalculations.d.mts.map +0 -1
- package/dist/utils/orderCalculations.mjs +0 -274
- package/dist/utils/orderCalculations.mjs.map +0 -1
- package/dist/utils/orderUtils.cjs +0 -159
- package/dist/utils/orderUtils.cjs.map +0 -1
- package/dist/utils/orderUtils.d.cts +0 -66
- package/dist/utils/orderUtils.d.cts.map +0 -1
- package/dist/utils/orderUtils.d.mts +0 -66
- package/dist/utils/orderUtils.d.mts.map +0 -1
- package/dist/utils/orderUtils.mjs +0 -151
- package/dist/utils/orderUtils.mjs.map +0 -1
- package/dist/utils/pnlCalculations.cjs +0 -107
- package/dist/utils/pnlCalculations.cjs.map +0 -1
- package/dist/utils/pnlCalculations.d.cts +0 -79
- package/dist/utils/pnlCalculations.d.cts.map +0 -1
- package/dist/utils/pnlCalculations.d.mts +0 -79
- package/dist/utils/pnlCalculations.d.mts.map +0 -1
- package/dist/utils/pnlCalculations.mjs +0 -97
- package/dist/utils/pnlCalculations.mjs.map +0 -1
- package/dist/utils/positionCalculations.cjs +0 -176
- package/dist/utils/positionCalculations.cjs.map +0 -1
- package/dist/utils/positionCalculations.d.cts +0 -85
- package/dist/utils/positionCalculations.d.cts.map +0 -1
- package/dist/utils/positionCalculations.d.mts +0 -85
- package/dist/utils/positionCalculations.d.mts.map +0 -1
- package/dist/utils/positionCalculations.mjs +0 -165
- package/dist/utils/positionCalculations.mjs.map +0 -1
- package/dist/utils/sortMarkets.cjs +0 -88
- package/dist/utils/sortMarkets.cjs.map +0 -1
- package/dist/utils/sortMarkets.d.cts +0 -21
- package/dist/utils/sortMarkets.d.cts.map +0 -1
- package/dist/utils/sortMarkets.d.mts +0 -21
- package/dist/utils/sortMarkets.d.mts.map +0 -1
- package/dist/utils/sortMarkets.mjs +0 -84
- package/dist/utils/sortMarkets.mjs.map +0 -1
- package/dist/utils/standaloneInfoClient.cjs +0 -34
- package/dist/utils/standaloneInfoClient.cjs.map +0 -1
- package/dist/utils/standaloneInfoClient.d.cts +0 -31
- package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
- package/dist/utils/standaloneInfoClient.d.mts +0 -31
- package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
- package/dist/utils/standaloneInfoClient.mjs +0 -30
- package/dist/utils/standaloneInfoClient.mjs.map +0 -1
- package/dist/utils/stringParseUtils.cjs +0 -49
- package/dist/utils/stringParseUtils.cjs.map +0 -1
- package/dist/utils/stringParseUtils.d.cts +0 -35
- package/dist/utils/stringParseUtils.d.cts.map +0 -1
- package/dist/utils/stringParseUtils.d.mts +0 -35
- package/dist/utils/stringParseUtils.d.mts.map +0 -1
- package/dist/utils/stringParseUtils.mjs +0 -44
- package/dist/utils/stringParseUtils.mjs.map +0 -1
- package/dist/utils/time.cjs +0 -37
- package/dist/utils/time.cjs.map +0 -1
- package/dist/utils/time.d.cts +0 -17
- package/dist/utils/time.d.cts.map +0 -1
- package/dist/utils/time.d.mts +0 -17
- package/dist/utils/time.d.mts.map +0 -1
- package/dist/utils/time.mjs +0 -33
- package/dist/utils/time.mjs.map +0 -1
- package/dist/utils/tpslValidation.cjs +0 -505
- package/dist/utils/tpslValidation.cjs.map +0 -1
- package/dist/utils/tpslValidation.d.cts +0 -182
- package/dist/utils/tpslValidation.d.cts.map +0 -1
- package/dist/utils/tpslValidation.d.mts +0 -182
- package/dist/utils/tpslValidation.d.mts.map +0 -1
- package/dist/utils/tpslValidation.mjs +0 -482
- package/dist/utils/tpslValidation.mjs.map +0 -1
- package/dist/utils/transactionUtils.cjs +0 -36
- package/dist/utils/transactionUtils.cjs.map +0 -1
- package/dist/utils/transactionUtils.d.cts +0 -17
- package/dist/utils/transactionUtils.d.cts.map +0 -1
- package/dist/utils/transactionUtils.d.mts +0 -17
- package/dist/utils/transactionUtils.d.mts.map +0 -1
- package/dist/utils/transactionUtils.mjs +0 -32
- package/dist/utils/transactionUtils.mjs.map +0 -1
- package/dist/utils/wait.cjs +0 -12
- package/dist/utils/wait.cjs.map +0 -1
- package/dist/utils/wait.d.cts +0 -8
- package/dist/utils/wait.d.cts.map +0 -1
- package/dist/utils/wait.d.mts +0 -8
- package/dist/utils/wait.d.mts.map +0 -1
- package/dist/utils/wait.mjs +0 -8
- package/dist/utils/wait.mjs.map +0 -1
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EligibilityService = void 0;
|
|
4
|
-
/* eslint-disable id-denylist, no-restricted-syntax, @typescript-eslint/naming-convention */
|
|
5
|
-
// TODO: Fix ESLint errors in this file - tracked for Phase 5 cleanup
|
|
6
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
7
|
-
const utils_1 = require("./utils.cjs");
|
|
8
|
-
// Geo-blocking API URLs
|
|
9
|
-
const ON_RAMP_GEO_BLOCKING_URLS = {
|
|
10
|
-
DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',
|
|
11
|
-
PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* EligibilityService
|
|
15
|
-
*
|
|
16
|
-
* Handles geo-location fetching and eligibility checking.
|
|
17
|
-
* Manages caching to minimize API calls.
|
|
18
|
-
*
|
|
19
|
-
* Instance-based service with constructor injection of platform dependencies.
|
|
20
|
-
* Cache is instance-scoped to support multiple service instances (e.g., testing).
|
|
21
|
-
*/
|
|
22
|
-
class EligibilityService {
|
|
23
|
-
/**
|
|
24
|
-
* Create a new EligibilityService instance.
|
|
25
|
-
*
|
|
26
|
-
* @param deps - Platform dependencies for logging, metrics, etc.
|
|
27
|
-
*/
|
|
28
|
-
constructor(deps) {
|
|
29
|
-
this.GEO_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
30
|
-
this.geoLocationCache = null;
|
|
31
|
-
this.geoLocationFetchPromise = null;
|
|
32
|
-
this.deps = deps;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Fetch geo location with caching and deduplication.
|
|
36
|
-
*
|
|
37
|
-
* @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails
|
|
38
|
-
*/
|
|
39
|
-
async fetchGeoLocation() {
|
|
40
|
-
// Check cache first
|
|
41
|
-
if (this.geoLocationCache) {
|
|
42
|
-
const cacheAge = Date.now() - this.geoLocationCache.timestamp;
|
|
43
|
-
if (cacheAge < this.GEO_CACHE_TTL_MS) {
|
|
44
|
-
this.deps.debugLogger.log('EligibilityService: Using cached geo location', {
|
|
45
|
-
location: this.geoLocationCache.location,
|
|
46
|
-
cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,
|
|
47
|
-
});
|
|
48
|
-
return this.geoLocationCache.location;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// If already fetching, return the existing promise
|
|
52
|
-
if (this.geoLocationFetchPromise) {
|
|
53
|
-
this.deps.debugLogger.log('EligibilityService: Geo location fetch already in progress, waiting...');
|
|
54
|
-
return this.geoLocationFetchPromise;
|
|
55
|
-
}
|
|
56
|
-
// Start new fetch
|
|
57
|
-
this.geoLocationFetchPromise = this.performGeoLocationFetch();
|
|
58
|
-
try {
|
|
59
|
-
const location = await this.geoLocationFetchPromise;
|
|
60
|
-
return location;
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
// Clear the promise after completion (success or failure)
|
|
64
|
-
this.geoLocationFetchPromise = null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Perform the actual geo location fetch.
|
|
69
|
-
* Separated to allow proper promise management.
|
|
70
|
-
*
|
|
71
|
-
* @returns The geo location string or 'UNKNOWN' on failure
|
|
72
|
-
*/
|
|
73
|
-
async performGeoLocationFetch() {
|
|
74
|
-
let location = 'UNKNOWN';
|
|
75
|
-
try {
|
|
76
|
-
const environment = (0, utils_1.getEnvironment)();
|
|
77
|
-
this.deps.debugLogger.log('EligibilityService: Fetching geo location from API', {
|
|
78
|
-
environment,
|
|
79
|
-
});
|
|
80
|
-
const response = await (0, controller_utils_1.successfulFetch)(ON_RAMP_GEO_BLOCKING_URLS[environment]);
|
|
81
|
-
const textResult = await response?.text();
|
|
82
|
-
location = textResult || 'UNKNOWN';
|
|
83
|
-
// Cache the successful result
|
|
84
|
-
this.geoLocationCache = {
|
|
85
|
-
location,
|
|
86
|
-
timestamp: Date.now(),
|
|
87
|
-
};
|
|
88
|
-
this.deps.debugLogger.log('EligibilityService: Geo location fetched successfully', {
|
|
89
|
-
location,
|
|
90
|
-
});
|
|
91
|
-
return location;
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
95
|
-
this.deps.logger.error(error, {
|
|
96
|
-
context: {
|
|
97
|
-
name: 'EligibilityService.performGeoLocationFetch',
|
|
98
|
-
data: {},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
// Don't cache failures
|
|
102
|
-
return location;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Check if user is eligible based on geo-blocked regions.
|
|
107
|
-
*
|
|
108
|
-
* @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])
|
|
109
|
-
* @returns true if eligible (not in blocked region), false otherwise
|
|
110
|
-
*/
|
|
111
|
-
async checkEligibility(blockedRegions) {
|
|
112
|
-
try {
|
|
113
|
-
this.deps.debugLogger.log('EligibilityService: Checking eligibility', {
|
|
114
|
-
blockedRegionsCount: blockedRegions.length,
|
|
115
|
-
});
|
|
116
|
-
// Returns UNKNOWN if we can't fetch the geo location
|
|
117
|
-
const geoLocation = await this.fetchGeoLocation();
|
|
118
|
-
// Only set to eligible if we have valid geolocation and it's not blocked
|
|
119
|
-
if (geoLocation !== 'UNKNOWN') {
|
|
120
|
-
const isEligible = blockedRegions.every((geoBlockedRegion) => !geoLocation
|
|
121
|
-
.toUpperCase()
|
|
122
|
-
.startsWith(geoBlockedRegion.toUpperCase()));
|
|
123
|
-
this.deps.debugLogger.log('EligibilityService: Eligibility check completed', {
|
|
124
|
-
geoLocation,
|
|
125
|
-
isEligible,
|
|
126
|
-
blockedRegions,
|
|
127
|
-
});
|
|
128
|
-
return isEligible;
|
|
129
|
-
}
|
|
130
|
-
// Default to eligible if location is unknown
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
135
|
-
this.deps.logger.error(error, {
|
|
136
|
-
context: {
|
|
137
|
-
name: 'EligibilityService.checkEligibility',
|
|
138
|
-
data: {},
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
// Default to eligible on error
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Clear the geo-location cache.
|
|
147
|
-
* Useful for testing or forcing a fresh fetch.
|
|
148
|
-
*/
|
|
149
|
-
clearCache() {
|
|
150
|
-
this.geoLocationCache = null;
|
|
151
|
-
this.geoLocationFetchPromise = null;
|
|
152
|
-
this.deps.debugLogger.log('EligibilityService: Cache cleared');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.EligibilityService = EligibilityService;
|
|
156
|
-
//# sourceMappingURL=EligibilityService.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EligibilityService.cjs","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":";;;AAAA,4FAA4F;AAC5F,qEAAqE;AACrE,iEAA6D;AAE7D,uCAAyC;AAGzC,wBAAwB;AACxB,MAAM,yBAAyB,GAAG;IAChC,GAAG,EAAE,oDAAoD;IACzD,IAAI,EAAE,gDAAgD;CAC9C,CAAC;AAUX;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IAS7B;;;;OAIG;IACH,YAAY,IAA+B;QAb1B,qBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;QAIvD,qBAAgB,GAA4B,IAAI,CAAC;QAEjD,4BAAuB,GAA2B,IAAI,CAAC;QAQ7D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gB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AAC,gBAAgB,EAAE,EAAE,CACnB,CAAC,WAAW;qBACT,WAAW,EAAE;qBACb,UAAU,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAChD,CAAC;gBAEF,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CACvB,iDAAiD,EACjD;oBACE,WAAW;oBACX,UAAU;oBACV,cAAc;iBACf,CACF,CAAC;gBAEF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,6CAA6C;YAC7C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAClE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;gBAC5B,OAAO,EAAE;oBACP,IAAI,EAAE,qCAAqC;oBAC3C,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;YACH,+BAA+B;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjE,CAAC;CACF;AA5KD,gDA4KC","sourcesContent":["/* eslint-disable id-denylist, no-restricted-syntax, @typescript-eslint/naming-convention */\n// TODO: Fix ESLint errors in this file - tracked for Phase 5 cleanup\nimport { successfulFetch } from '@metamask/controller-utils';\n\nimport { getEnvironment } from './utils';\nimport type { PerpsPlatformDependencies } from '../types';\n\n// Geo-blocking API URLs\nconst ON_RAMP_GEO_BLOCKING_URLS = {\n DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',\n PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',\n} as const;\n\n/**\n * Geo-location cache entry\n */\ntype GeoLocationCache = {\n location: string;\n timestamp: number;\n};\n\n/**\n * EligibilityService\n *\n * Handles geo-location fetching and eligibility checking.\n * Manages caching to minimize API calls.\n *\n * Instance-based service with constructor injection of platform dependencies.\n * Cache is instance-scoped to support multiple service instances (e.g., testing).\n */\nexport class EligibilityService {\n private readonly GEO_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes\n\n private readonly deps: PerpsPlatformDependencies;\n\n private geoLocationCache: GeoLocationCache | null = null;\n\n private geoLocationFetchPromise: Promise<string> | null = null;\n\n /**\n * Create a new EligibilityService instance.\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n */\n constructor(deps: PerpsPlatformDependencies) {\n this.deps = deps;\n }\n\n /**\n * Fetch geo location with caching and deduplication.\n *\n * @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails\n */\n async fetchGeoLocation(): Promise<string> {\n // Check cache first\n if (this.geoLocationCache) {\n const cacheAge = Date.now() - this.geoLocationCache.timestamp;\n if (cacheAge < this.GEO_CACHE_TTL_MS) {\n this.deps.debugLogger.log(\n 'EligibilityService: Using cached geo location',\n {\n location: this.geoLocationCache.location,\n cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,\n },\n );\n return this.geoLocationCache.location;\n }\n }\n\n // If already fetching, return the existing promise\n if (this.geoLocationFetchPromise) {\n this.deps.debugLogger.log(\n 'EligibilityService: Geo location fetch already in progress, waiting...',\n );\n return this.geoLocationFetchPromise;\n }\n\n // Start new fetch\n this.geoLocationFetchPromise = this.performGeoLocationFetch();\n\n try {\n const location = await this.geoLocationFetchPromise;\n return location;\n } finally {\n // Clear the promise after completion (success or failure)\n this.geoLocationFetchPromise = null;\n }\n }\n\n /**\n * Perform the actual geo location fetch.\n * Separated to allow proper promise management.\n *\n * @returns The geo location string or 'UNKNOWN' on failure\n */\n private async performGeoLocationFetch(): Promise<string> {\n let location = 'UNKNOWN';\n\n try {\n const environment = getEnvironment();\n\n this.deps.debugLogger.log(\n 'EligibilityService: Fetching geo location from API',\n {\n environment,\n },\n );\n\n const response = await successfulFetch(\n ON_RAMP_GEO_BLOCKING_URLS[environment],\n );\n\n const textResult = await response?.text();\n location = textResult || 'UNKNOWN';\n\n // Cache the successful result\n this.geoLocationCache = {\n location,\n timestamp: Date.now(),\n };\n\n this.deps.debugLogger.log(\n 'EligibilityService: Geo location fetched successfully',\n {\n location,\n },\n );\n\n return location;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n this.deps.logger.error(error, {\n context: {\n name: 'EligibilityService.performGeoLocationFetch',\n data: {},\n },\n });\n // Don't cache failures\n return location;\n }\n }\n\n /**\n * Check if user is eligible based on geo-blocked regions.\n *\n * @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])\n * @returns true if eligible (not in blocked region), false otherwise\n */\n async checkEligibility(blockedRegions: string[]): Promise<boolean> {\n try {\n this.deps.debugLogger.log('EligibilityService: Checking eligibility', {\n blockedRegionsCount: blockedRegions.length,\n });\n\n // Returns UNKNOWN if we can't fetch the geo location\n const geoLocation = await this.fetchGeoLocation();\n\n // Only set to eligible if we have valid geolocation and it's not blocked\n if (geoLocation !== 'UNKNOWN') {\n const isEligible = blockedRegions.every(\n (geoBlockedRegion) =>\n !geoLocation\n .toUpperCase()\n .startsWith(geoBlockedRegion.toUpperCase()),\n );\n\n this.deps.debugLogger.log(\n 'EligibilityService: Eligibility check completed',\n {\n geoLocation,\n isEligible,\n blockedRegions,\n },\n );\n\n return isEligible;\n }\n\n // Default to eligible if location is unknown\n return true;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n this.deps.logger.error(error, {\n context: {\n name: 'EligibilityService.checkEligibility',\n data: {},\n },\n });\n // Default to eligible on error\n return true;\n }\n }\n\n /**\n * Clear the geo-location cache.\n * Useful for testing or forcing a fresh fetch.\n */\n clearCache(): void {\n this.geoLocationCache = null;\n this.geoLocationFetchPromise = null;\n this.deps.debugLogger.log('EligibilityService: Cache cleared');\n }\n}\n"]}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { PerpsPlatformDependencies } from "../types/index.cjs";
|
|
2
|
-
/**
|
|
3
|
-
* EligibilityService
|
|
4
|
-
*
|
|
5
|
-
* Handles geo-location fetching and eligibility checking.
|
|
6
|
-
* Manages caching to minimize API calls.
|
|
7
|
-
*
|
|
8
|
-
* Instance-based service with constructor injection of platform dependencies.
|
|
9
|
-
* Cache is instance-scoped to support multiple service instances (e.g., testing).
|
|
10
|
-
*/
|
|
11
|
-
export declare class EligibilityService {
|
|
12
|
-
private readonly GEO_CACHE_TTL_MS;
|
|
13
|
-
private readonly deps;
|
|
14
|
-
private geoLocationCache;
|
|
15
|
-
private geoLocationFetchPromise;
|
|
16
|
-
/**
|
|
17
|
-
* Create a new EligibilityService instance.
|
|
18
|
-
*
|
|
19
|
-
* @param deps - Platform dependencies for logging, metrics, etc.
|
|
20
|
-
*/
|
|
21
|
-
constructor(deps: PerpsPlatformDependencies);
|
|
22
|
-
/**
|
|
23
|
-
* Fetch geo location with caching and deduplication.
|
|
24
|
-
*
|
|
25
|
-
* @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails
|
|
26
|
-
*/
|
|
27
|
-
fetchGeoLocation(): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Perform the actual geo location fetch.
|
|
30
|
-
* Separated to allow proper promise management.
|
|
31
|
-
*
|
|
32
|
-
* @returns The geo location string or 'UNKNOWN' on failure
|
|
33
|
-
*/
|
|
34
|
-
private performGeoLocationFetch;
|
|
35
|
-
/**
|
|
36
|
-
* Check if user is eligible based on geo-blocked regions.
|
|
37
|
-
*
|
|
38
|
-
* @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])
|
|
39
|
-
* @returns true if eligible (not in blocked region), false otherwise
|
|
40
|
-
*/
|
|
41
|
-
checkEligibility(blockedRegions: string[]): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Clear the geo-location cache.
|
|
44
|
-
* Useful for testing or forcing a fresh fetch.
|
|
45
|
-
*/
|
|
46
|
-
clearCache(): void;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=EligibilityService.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EligibilityService.d.cts","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAgB1D;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;IAElD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4B;IAEjD,OAAO,CAAC,gBAAgB,CAAiC;IAEzD,OAAO,CAAC,uBAAuB,CAAgC;IAE/D;;;;OAIG;gBACS,IAAI,EAAE,yBAAyB;IAI3C;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAoCzC;;;;;OAKG;YACW,uBAAuB;IA+CrC;;;;;OAKG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA6ClE;;;OAGG;IACH,UAAU,IAAI,IAAI;CAKnB"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { PerpsPlatformDependencies } from "../types/index.mjs";
|
|
2
|
-
/**
|
|
3
|
-
* EligibilityService
|
|
4
|
-
*
|
|
5
|
-
* Handles geo-location fetching and eligibility checking.
|
|
6
|
-
* Manages caching to minimize API calls.
|
|
7
|
-
*
|
|
8
|
-
* Instance-based service with constructor injection of platform dependencies.
|
|
9
|
-
* Cache is instance-scoped to support multiple service instances (e.g., testing).
|
|
10
|
-
*/
|
|
11
|
-
export declare class EligibilityService {
|
|
12
|
-
private readonly GEO_CACHE_TTL_MS;
|
|
13
|
-
private readonly deps;
|
|
14
|
-
private geoLocationCache;
|
|
15
|
-
private geoLocationFetchPromise;
|
|
16
|
-
/**
|
|
17
|
-
* Create a new EligibilityService instance.
|
|
18
|
-
*
|
|
19
|
-
* @param deps - Platform dependencies for logging, metrics, etc.
|
|
20
|
-
*/
|
|
21
|
-
constructor(deps: PerpsPlatformDependencies);
|
|
22
|
-
/**
|
|
23
|
-
* Fetch geo location with caching and deduplication.
|
|
24
|
-
*
|
|
25
|
-
* @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails
|
|
26
|
-
*/
|
|
27
|
-
fetchGeoLocation(): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Perform the actual geo location fetch.
|
|
30
|
-
* Separated to allow proper promise management.
|
|
31
|
-
*
|
|
32
|
-
* @returns The geo location string or 'UNKNOWN' on failure
|
|
33
|
-
*/
|
|
34
|
-
private performGeoLocationFetch;
|
|
35
|
-
/**
|
|
36
|
-
* Check if user is eligible based on geo-blocked regions.
|
|
37
|
-
*
|
|
38
|
-
* @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])
|
|
39
|
-
* @returns true if eligible (not in blocked region), false otherwise
|
|
40
|
-
*/
|
|
41
|
-
checkEligibility(blockedRegions: string[]): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Clear the geo-location cache.
|
|
44
|
-
* Useful for testing or forcing a fresh fetch.
|
|
45
|
-
*/
|
|
46
|
-
clearCache(): void;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=EligibilityService.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EligibilityService.d.mts","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAgB1D;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;IAElD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4B;IAEjD,OAAO,CAAC,gBAAgB,CAAiC;IAEzD,OAAO,CAAC,uBAAuB,CAAgC;IAE/D;;;;OAIG;gBACS,IAAI,EAAE,yBAAyB;IAI3C;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAoCzC;;;;;OAKG;YACW,uBAAuB;IA+CrC;;;;;OAKG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA6ClE;;;OAGG;IACH,UAAU,IAAI,IAAI;CAKnB"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/* eslint-disable id-denylist, no-restricted-syntax, @typescript-eslint/naming-convention */
|
|
2
|
-
// TODO: Fix ESLint errors in this file - tracked for Phase 5 cleanup
|
|
3
|
-
import { successfulFetch } from "@metamask/controller-utils";
|
|
4
|
-
import { getEnvironment } from "./utils.mjs";
|
|
5
|
-
// Geo-blocking API URLs
|
|
6
|
-
const ON_RAMP_GEO_BLOCKING_URLS = {
|
|
7
|
-
DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',
|
|
8
|
-
PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* EligibilityService
|
|
12
|
-
*
|
|
13
|
-
* Handles geo-location fetching and eligibility checking.
|
|
14
|
-
* Manages caching to minimize API calls.
|
|
15
|
-
*
|
|
16
|
-
* Instance-based service with constructor injection of platform dependencies.
|
|
17
|
-
* Cache is instance-scoped to support multiple service instances (e.g., testing).
|
|
18
|
-
*/
|
|
19
|
-
export class EligibilityService {
|
|
20
|
-
/**
|
|
21
|
-
* Create a new EligibilityService instance.
|
|
22
|
-
*
|
|
23
|
-
* @param deps - Platform dependencies for logging, metrics, etc.
|
|
24
|
-
*/
|
|
25
|
-
constructor(deps) {
|
|
26
|
-
this.GEO_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
27
|
-
this.geoLocationCache = null;
|
|
28
|
-
this.geoLocationFetchPromise = null;
|
|
29
|
-
this.deps = deps;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Fetch geo location with caching and deduplication.
|
|
33
|
-
*
|
|
34
|
-
* @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails
|
|
35
|
-
*/
|
|
36
|
-
async fetchGeoLocation() {
|
|
37
|
-
// Check cache first
|
|
38
|
-
if (this.geoLocationCache) {
|
|
39
|
-
const cacheAge = Date.now() - this.geoLocationCache.timestamp;
|
|
40
|
-
if (cacheAge < this.GEO_CACHE_TTL_MS) {
|
|
41
|
-
this.deps.debugLogger.log('EligibilityService: Using cached geo location', {
|
|
42
|
-
location: this.geoLocationCache.location,
|
|
43
|
-
cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,
|
|
44
|
-
});
|
|
45
|
-
return this.geoLocationCache.location;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// If already fetching, return the existing promise
|
|
49
|
-
if (this.geoLocationFetchPromise) {
|
|
50
|
-
this.deps.debugLogger.log('EligibilityService: Geo location fetch already in progress, waiting...');
|
|
51
|
-
return this.geoLocationFetchPromise;
|
|
52
|
-
}
|
|
53
|
-
// Start new fetch
|
|
54
|
-
this.geoLocationFetchPromise = this.performGeoLocationFetch();
|
|
55
|
-
try {
|
|
56
|
-
const location = await this.geoLocationFetchPromise;
|
|
57
|
-
return location;
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
// Clear the promise after completion (success or failure)
|
|
61
|
-
this.geoLocationFetchPromise = null;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Perform the actual geo location fetch.
|
|
66
|
-
* Separated to allow proper promise management.
|
|
67
|
-
*
|
|
68
|
-
* @returns The geo location string or 'UNKNOWN' on failure
|
|
69
|
-
*/
|
|
70
|
-
async performGeoLocationFetch() {
|
|
71
|
-
let location = 'UNKNOWN';
|
|
72
|
-
try {
|
|
73
|
-
const environment = getEnvironment();
|
|
74
|
-
this.deps.debugLogger.log('EligibilityService: Fetching geo location from API', {
|
|
75
|
-
environment,
|
|
76
|
-
});
|
|
77
|
-
const response = await successfulFetch(ON_RAMP_GEO_BLOCKING_URLS[environment]);
|
|
78
|
-
const textResult = await response?.text();
|
|
79
|
-
location = textResult || 'UNKNOWN';
|
|
80
|
-
// Cache the successful result
|
|
81
|
-
this.geoLocationCache = {
|
|
82
|
-
location,
|
|
83
|
-
timestamp: Date.now(),
|
|
84
|
-
};
|
|
85
|
-
this.deps.debugLogger.log('EligibilityService: Geo location fetched successfully', {
|
|
86
|
-
location,
|
|
87
|
-
});
|
|
88
|
-
return location;
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
92
|
-
this.deps.logger.error(error, {
|
|
93
|
-
context: {
|
|
94
|
-
name: 'EligibilityService.performGeoLocationFetch',
|
|
95
|
-
data: {},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
// Don't cache failures
|
|
99
|
-
return location;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Check if user is eligible based on geo-blocked regions.
|
|
104
|
-
*
|
|
105
|
-
* @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])
|
|
106
|
-
* @returns true if eligible (not in blocked region), false otherwise
|
|
107
|
-
*/
|
|
108
|
-
async checkEligibility(blockedRegions) {
|
|
109
|
-
try {
|
|
110
|
-
this.deps.debugLogger.log('EligibilityService: Checking eligibility', {
|
|
111
|
-
blockedRegionsCount: blockedRegions.length,
|
|
112
|
-
});
|
|
113
|
-
// Returns UNKNOWN if we can't fetch the geo location
|
|
114
|
-
const geoLocation = await this.fetchGeoLocation();
|
|
115
|
-
// Only set to eligible if we have valid geolocation and it's not blocked
|
|
116
|
-
if (geoLocation !== 'UNKNOWN') {
|
|
117
|
-
const isEligible = blockedRegions.every((geoBlockedRegion) => !geoLocation
|
|
118
|
-
.toUpperCase()
|
|
119
|
-
.startsWith(geoBlockedRegion.toUpperCase()));
|
|
120
|
-
this.deps.debugLogger.log('EligibilityService: Eligibility check completed', {
|
|
121
|
-
geoLocation,
|
|
122
|
-
isEligible,
|
|
123
|
-
blockedRegions,
|
|
124
|
-
});
|
|
125
|
-
return isEligible;
|
|
126
|
-
}
|
|
127
|
-
// Default to eligible if location is unknown
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
132
|
-
this.deps.logger.error(error, {
|
|
133
|
-
context: {
|
|
134
|
-
name: 'EligibilityService.checkEligibility',
|
|
135
|
-
data: {},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
// Default to eligible on error
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Clear the geo-location cache.
|
|
144
|
-
* Useful for testing or forcing a fresh fetch.
|
|
145
|
-
*/
|
|
146
|
-
clearCache() {
|
|
147
|
-
this.geoLocationCache = null;
|
|
148
|
-
this.geoLocationFetchPromise = null;
|
|
149
|
-
this.deps.debugLogger.log('EligibilityService: Cache cleared');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=EligibilityService.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EligibilityService.mjs","sourceRoot":"","sources":["../../src/services/EligibilityService.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,mCAAmC;AAE7D,OAAO,EAAE,cAAc,EAAE,oBAAgB;AAGzC,wBAAwB;AACxB,MAAM,yBAAyB,GAAG;IAChC,GAAG,EAAE,oDAAoD;IACzD,IAAI,EAAE,gDAAgD;CAC9C,CAAC;AAUX;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IAS7B;;;;OAIG;IACH,YAAY,IAA+B;QAb1B,qBAAgB,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C,CAAC,CAAC;YAEH,qDAAqD;YACrD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAElD,yEAAyE;YACzE,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,MAAM,UAAU,GAAG,cAAc,CAAC,KAAK,CACrC,CAAC,gBAAgB,EAAE,EAAE,CACnB,CAAC,WAAW;qBACT,WAAW,EAAE;qBACb,UAAU,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAChD,CAAC;gBAEF,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CACvB,iDAAiD,EACjD;oBACE,WAAW;oBACX,UAAU;oBACV,cAAc;iBACf,CACF,CAAC;gBAEF,OAAO,UAAU,CAAC;YACpB,CAAC;YAED,6CAA6C;YAC7C,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAClE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;gBAC5B,OAAO,EAAE;oBACP,IAAI,EAAE,qCAAqC;oBAC3C,IAAI,EAAE,EAAE;iBACT;aACF,CAAC,CAAC;YACH,+BAA+B;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IACjE,CAAC;CACF","sourcesContent":["/* eslint-disable id-denylist, no-restricted-syntax, @typescript-eslint/naming-convention */\n// TODO: Fix ESLint errors in this file - tracked for Phase 5 cleanup\nimport { successfulFetch } from '@metamask/controller-utils';\n\nimport { getEnvironment } from './utils';\nimport type { PerpsPlatformDependencies } from '../types';\n\n// Geo-blocking API URLs\nconst ON_RAMP_GEO_BLOCKING_URLS = {\n DEV: 'https://on-ramp.uat-api.cx.metamask.io/geolocation',\n PROD: 'https://on-ramp.api.cx.metamask.io/geolocation',\n} as const;\n\n/**\n * Geo-location cache entry\n */\ntype GeoLocationCache = {\n location: string;\n timestamp: number;\n};\n\n/**\n * EligibilityService\n *\n * Handles geo-location fetching and eligibility checking.\n * Manages caching to minimize API calls.\n *\n * Instance-based service with constructor injection of platform dependencies.\n * Cache is instance-scoped to support multiple service instances (e.g., testing).\n */\nexport class EligibilityService {\n private readonly GEO_CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes\n\n private readonly deps: PerpsPlatformDependencies;\n\n private geoLocationCache: GeoLocationCache | null = null;\n\n private geoLocationFetchPromise: Promise<string> | null = null;\n\n /**\n * Create a new EligibilityService instance.\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n */\n constructor(deps: PerpsPlatformDependencies) {\n this.deps = deps;\n }\n\n /**\n * Fetch geo location with caching and deduplication.\n *\n * @returns The geo location string (e.g., 'US', 'GB') or 'UNKNOWN' if fetch fails\n */\n async fetchGeoLocation(): Promise<string> {\n // Check cache first\n if (this.geoLocationCache) {\n const cacheAge = Date.now() - this.geoLocationCache.timestamp;\n if (cacheAge < this.GEO_CACHE_TTL_MS) {\n this.deps.debugLogger.log(\n 'EligibilityService: Using cached geo location',\n {\n location: this.geoLocationCache.location,\n cacheAge: `${(cacheAge / 1000).toFixed(1)}s`,\n },\n );\n return this.geoLocationCache.location;\n }\n }\n\n // If already fetching, return the existing promise\n if (this.geoLocationFetchPromise) {\n this.deps.debugLogger.log(\n 'EligibilityService: Geo location fetch already in progress, waiting...',\n );\n return this.geoLocationFetchPromise;\n }\n\n // Start new fetch\n this.geoLocationFetchPromise = this.performGeoLocationFetch();\n\n try {\n const location = await this.geoLocationFetchPromise;\n return location;\n } finally {\n // Clear the promise after completion (success or failure)\n this.geoLocationFetchPromise = null;\n }\n }\n\n /**\n * Perform the actual geo location fetch.\n * Separated to allow proper promise management.\n *\n * @returns The geo location string or 'UNKNOWN' on failure\n */\n private async performGeoLocationFetch(): Promise<string> {\n let location = 'UNKNOWN';\n\n try {\n const environment = getEnvironment();\n\n this.deps.debugLogger.log(\n 'EligibilityService: Fetching geo location from API',\n {\n environment,\n },\n );\n\n const response = await successfulFetch(\n ON_RAMP_GEO_BLOCKING_URLS[environment],\n );\n\n const textResult = await response?.text();\n location = textResult || 'UNKNOWN';\n\n // Cache the successful result\n this.geoLocationCache = {\n location,\n timestamp: Date.now(),\n };\n\n this.deps.debugLogger.log(\n 'EligibilityService: Geo location fetched successfully',\n {\n location,\n },\n );\n\n return location;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n this.deps.logger.error(error, {\n context: {\n name: 'EligibilityService.performGeoLocationFetch',\n data: {},\n },\n });\n // Don't cache failures\n return location;\n }\n }\n\n /**\n * Check if user is eligible based on geo-blocked regions.\n *\n * @param blockedRegions - List of blocked region codes (e.g., ['US', 'CN'])\n * @returns true if eligible (not in blocked region), false otherwise\n */\n async checkEligibility(blockedRegions: string[]): Promise<boolean> {\n try {\n this.deps.debugLogger.log('EligibilityService: Checking eligibility', {\n blockedRegionsCount: blockedRegions.length,\n });\n\n // Returns UNKNOWN if we can't fetch the geo location\n const geoLocation = await this.fetchGeoLocation();\n\n // Only set to eligible if we have valid geolocation and it's not blocked\n if (geoLocation !== 'UNKNOWN') {\n const isEligible = blockedRegions.every(\n (geoBlockedRegion) =>\n !geoLocation\n .toUpperCase()\n .startsWith(geoBlockedRegion.toUpperCase()),\n );\n\n this.deps.debugLogger.log(\n 'EligibilityService: Eligibility check completed',\n {\n geoLocation,\n isEligible,\n blockedRegions,\n },\n );\n\n return isEligible;\n }\n\n // Default to eligible if location is unknown\n return true;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n this.deps.logger.error(error, {\n context: {\n name: 'EligibilityService.checkEligibility',\n data: {},\n },\n });\n // Default to eligible on error\n return true;\n }\n }\n\n /**\n * Clear the geo-location cache.\n * Useful for testing or forcing a fresh fetch.\n */\n clearCache(): void {\n this.geoLocationCache = null;\n this.geoLocationFetchPromise = null;\n this.deps.debugLogger.log('EligibilityService: Cache cleared');\n }\n}\n"]}
|