@metamask/snap-networks-utils 1.0.0 → 2.0.0
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 +63 -1
- package/README.md +4 -10
- package/dist/index.cjs +102 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +51 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.cjs +36 -18
- package/dist/providers/assets/AssetsProvider.cjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.cts +30 -2
- package/dist/providers/assets/AssetsProvider.d.cts.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.mts +30 -2
- package/dist/providers/assets/AssetsProvider.d.mts.map +1 -1
- package/dist/providers/assets/AssetsProvider.mjs +36 -18
- package/dist/providers/assets/AssetsProvider.mjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs.map +1 -1
- package/dist/services/analytics/AnalyticsService.cjs +225 -0
- package/dist/services/analytics/AnalyticsService.cjs.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.cts +175 -0
- package/dist/services/analytics/AnalyticsService.d.cts.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.mts +175 -0
- package/dist/services/analytics/AnalyticsService.d.mts.map +1 -0
- package/dist/services/analytics/AnalyticsService.mjs +221 -0
- package/dist/services/analytics/AnalyticsService.mjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs +23 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs +19 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs.map +1 -0
- package/dist/ui/Asset/Asset.cjs +68 -0
- package/dist/ui/Asset/Asset.cjs.map +1 -0
- package/dist/ui/Asset/Asset.d.cts +83 -0
- package/dist/ui/Asset/Asset.d.cts.map +1 -0
- package/dist/ui/Asset/Asset.d.mts +83 -0
- package/dist/ui/Asset/Asset.d.mts.map +1 -0
- package/dist/ui/Asset/Asset.mjs +60 -0
- package/dist/ui/Asset/Asset.mjs.map +1 -0
- package/dist/ui/Asset/question-mark.svg +3 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs +57 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs +53 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs +72 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs +68 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs.map +1 -0
- package/dist/utils/async/async.cjs +95 -0
- package/dist/utils/async/async.cjs.map +1 -0
- package/dist/utils/async/async.d.cts +51 -0
- package/dist/utils/async/async.d.cts.map +1 -0
- package/dist/utils/async/async.d.mts +51 -0
- package/dist/utils/async/async.d.mts.map +1 -0
- package/dist/utils/async/async.mjs +88 -0
- package/dist/utils/async/async.mjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.cjs +54 -0
- package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.cts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.mts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.mjs +51 -0
- package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.cjs +134 -0
- package/dist/utils/cache/InMemoryCache.cjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.cts +29 -0
- package/dist/utils/cache/InMemoryCache.d.cts.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.mts +29 -0
- package/dist/utils/cache/InMemoryCache.d.mts.map +1 -0
- package/dist/utils/cache/InMemoryCache.mjs +130 -0
- package/dist/utils/cache/InMemoryCache.mjs.map +1 -0
- package/dist/utils/cache/StateCache.cjs +193 -0
- package/dist/utils/cache/StateCache.cjs.map +1 -0
- package/dist/utils/cache/StateCache.d.cts +96 -0
- package/dist/utils/cache/StateCache.d.cts.map +1 -0
- package/dist/utils/cache/StateCache.d.mts +96 -0
- package/dist/utils/cache/StateCache.d.mts.map +1 -0
- package/dist/utils/cache/StateCache.mjs +189 -0
- package/dist/utils/cache/StateCache.mjs.map +1 -0
- package/dist/utils/cache/types.cjs +3 -0
- package/dist/utils/cache/types.cjs.map +1 -0
- package/dist/utils/cache/types.d.cts +99 -0
- package/dist/utils/cache/types.d.cts.map +1 -0
- package/dist/utils/cache/types.d.mts +99 -0
- package/dist/utils/cache/types.d.mts.map +1 -0
- package/dist/utils/cache/types.mjs +2 -0
- package/dist/utils/cache/types.mjs.map +1 -0
- package/dist/utils/cache/useCache.cjs +82 -0
- package/dist/utils/cache/useCache.cjs.map +1 -0
- package/dist/utils/cache/useCache.d.cts +57 -0
- package/dist/utils/cache/useCache.d.cts.map +1 -0
- package/dist/utils/cache/useCache.d.mts +57 -0
- package/dist/utils/cache/useCache.d.mts.map +1 -0
- package/dist/utils/cache/useCache.mjs +78 -0
- package/dist/utils/cache/useCache.mjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.cjs +80 -0
- package/dist/utils/cache/useCacheUntil.cjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.cts +54 -0
- package/dist/utils/cache/useCacheUntil.d.cts.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.mts +54 -0
- package/dist/utils/cache/useCacheUntil.d.mts.map +1 -0
- package/dist/utils/cache/useCacheUntil.mjs +76 -0
- package/dist/utils/cache/useCacheUntil.mjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.cjs +62 -0
- package/dist/utils/config/BaseConfigProvider.cjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.cts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.cts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.mts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.mts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.mjs +58 -0
- package/dist/utils/config/BaseConfigProvider.mjs.map +1 -0
- package/dist/utils/config/envStructs.cjs +69 -0
- package/dist/utils/config/envStructs.cjs.map +1 -0
- package/dist/utils/config/envStructs.d.cts +57 -0
- package/dist/utils/config/envStructs.d.cts.map +1 -0
- package/dist/utils/config/envStructs.d.mts +57 -0
- package/dist/utils/config/envStructs.d.mts.map +1 -0
- package/dist/utils/config/envStructs.mjs +61 -0
- package/dist/utils/config/envStructs.mjs.map +1 -0
- package/dist/utils/config/environmentStruct.cjs +19 -0
- package/dist/utils/config/environmentStruct.cjs.map +1 -0
- package/dist/utils/config/environmentStruct.d.cts +20 -0
- package/dist/utils/config/environmentStruct.d.cts.map +1 -0
- package/dist/utils/config/environmentStruct.d.mts +20 -0
- package/dist/utils/config/environmentStruct.d.mts.map +1 -0
- package/dist/utils/config/environmentStruct.mjs +16 -0
- package/dist/utils/config/environmentStruct.mjs.map +1 -0
- package/dist/utils/config/logLevelStruct.cjs +14 -0
- package/dist/utils/config/logLevelStruct.cjs.map +1 -0
- package/dist/utils/config/logLevelStruct.d.cts +17 -0
- package/dist/utils/config/logLevelStruct.d.cts.map +1 -0
- package/dist/utils/config/logLevelStruct.d.mts +17 -0
- package/dist/utils/config/logLevelStruct.d.mts.map +1 -0
- package/dist/utils/config/logLevelStruct.mjs +11 -0
- package/dist/utils/config/logLevelStruct.mjs.map +1 -0
- package/dist/utils/config/parseEnv.cjs +30 -0
- package/dist/utils/config/parseEnv.cjs.map +1 -0
- package/dist/utils/config/parseEnv.d.cts +19 -0
- package/dist/utils/config/parseEnv.d.cts.map +1 -0
- package/dist/utils/config/parseEnv.d.mts +19 -0
- package/dist/utils/config/parseEnv.d.mts.map +1 -0
- package/dist/utils/config/parseEnv.mjs +26 -0
- package/dist/utils/config/parseEnv.mjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs +28 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs +24 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
- package/dist/utils/errors/errors.cjs +44 -0
- package/dist/utils/errors/errors.cjs.map +1 -0
- package/dist/utils/errors/errors.d.cts +37 -0
- package/dist/utils/errors/errors.d.cts.map +1 -0
- package/dist/utils/errors/errors.d.mts +37 -0
- package/dist/utils/errors/errors.d.mts.map +1 -0
- package/dist/utils/errors/errors.mjs +40 -0
- package/dist/utils/errors/errors.mjs.map +1 -0
- package/dist/utils/errors/index.cjs +18 -0
- package/dist/utils/errors/index.cjs.map +1 -0
- package/dist/utils/errors/index.d.cts +10 -0
- package/dist/utils/errors/index.d.cts.map +1 -0
- package/dist/utils/errors/index.d.mts +10 -0
- package/dist/utils/errors/index.d.mts.map +1 -0
- package/dist/utils/errors/index.mjs +6 -0
- package/dist/utils/errors/index.mjs.map +1 -0
- package/dist/utils/errors/snapRpcError.cjs +33 -0
- package/dist/utils/errors/snapRpcError.cjs.map +1 -0
- package/dist/utils/errors/snapRpcError.d.cts +11 -0
- package/dist/utils/errors/snapRpcError.d.cts.map +1 -0
- package/dist/utils/errors/snapRpcError.d.mts +11 -0
- package/dist/utils/errors/snapRpcError.d.mts.map +1 -0
- package/dist/utils/errors/snapRpcError.mjs +30 -0
- package/dist/utils/errors/snapRpcError.mjs.map +1 -0
- package/dist/utils/errors/stringifyReason.cjs +36 -0
- package/dist/utils/errors/stringifyReason.cjs.map +1 -0
- package/dist/utils/errors/stringifyReason.d.cts +15 -0
- package/dist/utils/errors/stringifyReason.d.cts.map +1 -0
- package/dist/utils/errors/stringifyReason.d.mts +15 -0
- package/dist/utils/errors/stringifyReason.d.mts.map +1 -0
- package/dist/utils/errors/stringifyReason.mjs +33 -0
- package/dist/utils/errors/stringifyReason.mjs.map +1 -0
- package/dist/utils/errors/syncError.cjs +98 -0
- package/dist/utils/errors/syncError.cjs.map +1 -0
- package/dist/utils/errors/syncError.d.cts +60 -0
- package/dist/utils/errors/syncError.d.cts.map +1 -0
- package/dist/utils/errors/syncError.d.mts +60 -0
- package/dist/utils/errors/syncError.d.mts.map +1 -0
- package/dist/utils/errors/syncError.mjs +92 -0
- package/dist/utils/errors/syncError.mjs.map +1 -0
- package/dist/utils/errors/trackError.cjs +76 -0
- package/dist/utils/errors/trackError.cjs.map +1 -0
- package/dist/utils/errors/trackError.d.cts +64 -0
- package/dist/utils/errors/trackError.d.cts.map +1 -0
- package/dist/utils/errors/trackError.d.mts +64 -0
- package/dist/utils/errors/trackError.d.mts.map +1 -0
- package/dist/utils/errors/trackError.mjs +72 -0
- package/dist/utils/errors/trackError.mjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs +57 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs +53 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs +25 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs +22 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs.map +1 -0
- package/dist/utils/logger/Logger.cjs +140 -0
- package/dist/utils/logger/Logger.cjs.map +1 -0
- package/dist/utils/logger/Logger.d.cts +118 -0
- package/dist/utils/logger/Logger.d.cts.map +1 -0
- package/dist/utils/logger/Logger.d.mts +118 -0
- package/dist/utils/logger/Logger.d.mts.map +1 -0
- package/dist/utils/logger/Logger.mjs +136 -0
- package/dist/utils/logger/Logger.mjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.cjs +26 -0
- package/dist/utils/logger/__mocks__/Logger.cjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.mjs +23 -0
- package/dist/utils/logger/__mocks__/Logger.mjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs +30 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs +26 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.cjs +23 -0
- package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.mjs +19 -0
- package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs +89 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs +85 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.cjs +26 -0
- package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.cts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.mts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.mjs +22 -0
- package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
- package/dist/utils/sanitize/sanitize.cjs +42 -0
- package/dist/utils/sanitize/sanitize.cjs.map +1 -0
- package/dist/utils/sanitize/sanitize.d.cts +15 -0
- package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
- package/dist/utils/sanitize/sanitize.d.mts +15 -0
- package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
- package/dist/utils/sanitize/sanitize.mjs +38 -0
- package/dist/utils/sanitize/sanitize.mjs.map +1 -0
- package/dist/utils/serialization/serialization.cjs +73 -0
- package/dist/utils/serialization/serialization.cjs.map +1 -0
- package/dist/utils/serialization/serialization.d.cts +19 -0
- package/dist/utils/serialization/serialization.d.cts.map +1 -0
- package/dist/utils/serialization/serialization.d.mts +19 -0
- package/dist/utils/serialization/serialization.d.mts.map +1 -0
- package/dist/utils/serialization/serialization.mjs +69 -0
- package/dist/utils/serialization/serialization.mjs.map +1 -0
- package/dist/utils/serialization/types.cjs +3 -0
- package/dist/utils/serialization/types.cjs.map +1 -0
- package/dist/utils/serialization/types.d.cts +8 -0
- package/dist/utils/serialization/types.d.cts.map +1 -0
- package/dist/utils/serialization/types.d.mts +8 -0
- package/dist/utils/serialization/types.d.mts.map +1 -0
- package/dist/utils/serialization/types.mjs +2 -0
- package/dist/utils/serialization/types.mjs.map +1 -0
- package/dist/utils/state/IStateManager.cjs +3 -0
- package/dist/utils/state/IStateManager.cjs.map +1 -0
- package/dist/utils/state/IStateManager.d.cts +69 -0
- package/dist/utils/state/IStateManager.d.cts.map +1 -0
- package/dist/utils/state/IStateManager.d.mts +69 -0
- package/dist/utils/state/IStateManager.d.mts.map +1 -0
- package/dist/utils/state/IStateManager.mjs +2 -0
- package/dist/utils/state/IStateManager.mjs.map +1 -0
- package/dist/utils/state/InMemoryState.cjs +41 -0
- package/dist/utils/state/InMemoryState.cjs.map +1 -0
- package/dist/utils/state/InMemoryState.d.cts +18 -0
- package/dist/utils/state/InMemoryState.d.cts.map +1 -0
- package/dist/utils/state/InMemoryState.d.mts +18 -0
- package/dist/utils/state/InMemoryState.d.mts.map +1 -0
- package/dist/utils/state/InMemoryState.mjs +38 -0
- package/dist/utils/state/InMemoryState.mjs.map +1 -0
- package/dist/utils/state/State.cjs +159 -0
- package/dist/utils/state/State.cjs.map +1 -0
- package/dist/utils/state/State.d.cts +25 -0
- package/dist/utils/state/State.d.cts.map +1 -0
- package/dist/utils/state/State.d.mts +25 -0
- package/dist/utils/state/State.d.mts.map +1 -0
- package/dist/utils/state/State.mjs +156 -0
- package/dist/utils/state/State.mjs.map +1 -0
- package/dist/utils/transactionType/transactionType.cjs +32 -0
- package/dist/utils/transactionType/transactionType.cjs.map +1 -0
- package/dist/utils/transactionType/transactionType.d.cts +17 -0
- package/dist/utils/transactionType/transactionType.d.cts.map +1 -0
- package/dist/utils/transactionType/transactionType.d.mts +17 -0
- package/dist/utils/transactionType/transactionType.d.mts.map +1 -0
- package/dist/utils/transactionType/transactionType.mjs +28 -0
- package/dist/utils/transactionType/transactionType.mjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.cjs +96 -0
- package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.cts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.mts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.mjs +93 -0
- package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs +12 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs +9 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs.map +1 -0
- package/package.json +33 -13
- package/dist/logger.cjs +0 -57
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -30
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -30
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -53
- package/dist/logger.mjs.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* Create a struct for environment variables validated against the given
|
|
4
|
+
* struct, where unset and empty strings (the build-time injection default)
|
|
5
|
+
* mean the variable is not set.
|
|
6
|
+
*
|
|
7
|
+
* @param item - The struct to validate the value against when it is set,
|
|
8
|
+
* e.g. `UrlStruct`.
|
|
9
|
+
* @returns A struct that parses to the value or `undefined`.
|
|
10
|
+
* @example
|
|
11
|
+
* const PriceApiBaseUrlStruct = emptyToUndefined(UrlStruct);
|
|
12
|
+
*/
|
|
13
|
+
export declare const emptyToUndefined: <Type>(item: Struct<Type>) => Struct<Type | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Create a struct for comma-separated list environment variables.
|
|
16
|
+
*
|
|
17
|
+
* The raw string is split on commas and each item is validated against the
|
|
18
|
+
* given item struct.
|
|
19
|
+
*
|
|
20
|
+
* @param item - The struct to validate each list item against.
|
|
21
|
+
* @returns A struct that parses a comma-separated string into an array.
|
|
22
|
+
* @example
|
|
23
|
+
* const RpcUrlListStruct = commaSeparatedListOf(UrlStruct);
|
|
24
|
+
*/
|
|
25
|
+
export declare const commaSeparatedListOf: <Type>(item: Struct<Type>) => Struct<Type[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a struct for a URL environment variable with a fallback: unset,
|
|
28
|
+
* empty, and whitespace-only values (the build-time injection default)
|
|
29
|
+
* resolve to the fallback, surrounding whitespace is trimmed, and invalid
|
|
30
|
+
* values are rejected.
|
|
31
|
+
*
|
|
32
|
+
* @param fallback - The URL to use when the variable is unset, empty, or
|
|
33
|
+
* whitespace-only.
|
|
34
|
+
* @returns A struct that parses to the URL.
|
|
35
|
+
* @example
|
|
36
|
+
* const EsploraUrlStruct = defaultedUrlStruct('https://blockstream.info/api');
|
|
37
|
+
*/
|
|
38
|
+
export declare const defaultedUrlStruct: (fallback: string) => Struct<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Create a struct that parses an integer from a string, with a minimum value
|
|
41
|
+
* and a default for unset variables.
|
|
42
|
+
*
|
|
43
|
+
* @param minValue - The minimum value for the integer.
|
|
44
|
+
* @param defaultValue - The default value for the integer.
|
|
45
|
+
* @returns A struct that parses an integer from a string.
|
|
46
|
+
*/
|
|
47
|
+
export declare const parseIntegerStruct: (minValue: number, defaultValue: number) => Struct<number>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a struct that parses a float from a string, with a minimum value and
|
|
50
|
+
* a default for unset variables.
|
|
51
|
+
*
|
|
52
|
+
* @param minValue - The minimum value for the float.
|
|
53
|
+
* @param defaultValue - The default value for the float.
|
|
54
|
+
* @returns A struct that parses a float from a string.
|
|
55
|
+
*/
|
|
56
|
+
export declare const parseFloatStruct: (minValue: number, defaultValue: number) => Struct<number>;
|
|
57
|
+
//# sourceMappingURL=envStructs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envStructs.d.mts","sourceRoot":"","sources":["../../../src/utils/config/envStructs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAapD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,GAAI,IAAI,EACnC,MAAM,MAAM,CAAC,IAAI,CAAC,KACjB,MAAM,CAAC,IAAI,GAAG,SAAS,CAGvB,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,IAAI,EACvC,MAAM,MAAM,CAAC,IAAI,CAAC,KACjB,MAAM,CAAC,IAAI,EAAE,CACoD,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,MAAM,CAAC,MAAM,CAI/D,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,cAAc,MAAM,KACnB,MAAM,CAAC,MAAM,CAKb,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,EAChB,cAAc,MAAM,KACnB,MAAM,CAAC,MAAM,CAKb,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { array, coerce, defaulted, min, number, optional, string } from "@metamask/superstruct";
|
|
2
|
+
import { UrlStruct } from "../urlStruct/urlStruct.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Create a struct for environment variables validated against the given
|
|
5
|
+
* struct, where unset and empty strings (the build-time injection default)
|
|
6
|
+
* mean the variable is not set.
|
|
7
|
+
*
|
|
8
|
+
* @param item - The struct to validate the value against when it is set,
|
|
9
|
+
* e.g. `UrlStruct`.
|
|
10
|
+
* @returns A struct that parses to the value or `undefined`.
|
|
11
|
+
* @example
|
|
12
|
+
* const PriceApiBaseUrlStruct = emptyToUndefined(UrlStruct);
|
|
13
|
+
*/
|
|
14
|
+
export const emptyToUndefined = (item) => coerce(optional(item), string(), (value) => value === '' ? undefined : value);
|
|
15
|
+
/**
|
|
16
|
+
* Create a struct for comma-separated list environment variables.
|
|
17
|
+
*
|
|
18
|
+
* The raw string is split on commas and each item is validated against the
|
|
19
|
+
* given item struct.
|
|
20
|
+
*
|
|
21
|
+
* @param item - The struct to validate each list item against.
|
|
22
|
+
* @returns A struct that parses a comma-separated string into an array.
|
|
23
|
+
* @example
|
|
24
|
+
* const RpcUrlListStruct = commaSeparatedListOf(UrlStruct);
|
|
25
|
+
*/
|
|
26
|
+
export const commaSeparatedListOf = (item) => coerce(array(item), string(), (value) => value.split(','));
|
|
27
|
+
/**
|
|
28
|
+
* Create a struct for a URL environment variable with a fallback: unset,
|
|
29
|
+
* empty, and whitespace-only values (the build-time injection default)
|
|
30
|
+
* resolve to the fallback, surrounding whitespace is trimmed, and invalid
|
|
31
|
+
* values are rejected.
|
|
32
|
+
*
|
|
33
|
+
* @param fallback - The URL to use when the variable is unset, empty, or
|
|
34
|
+
* whitespace-only.
|
|
35
|
+
* @returns A struct that parses to the URL.
|
|
36
|
+
* @example
|
|
37
|
+
* const EsploraUrlStruct = defaultedUrlStruct('https://blockstream.info/api');
|
|
38
|
+
*/
|
|
39
|
+
export const defaultedUrlStruct = (fallback) => coerce(defaulted(UrlStruct, fallback), string(), (value) => {
|
|
40
|
+
const trimmed = value.trim();
|
|
41
|
+
return trimmed === '' ? undefined : trimmed;
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Create a struct that parses an integer from a string, with a minimum value
|
|
45
|
+
* and a default for unset variables.
|
|
46
|
+
*
|
|
47
|
+
* @param minValue - The minimum value for the integer.
|
|
48
|
+
* @param defaultValue - The default value for the integer.
|
|
49
|
+
* @returns A struct that parses an integer from a string.
|
|
50
|
+
*/
|
|
51
|
+
export const parseIntegerStruct = (minValue, defaultValue) => coerce(defaulted(min(number(), minValue), defaultValue), string(), (value) => (value === '' ? undefined : parseInt(value, 10)));
|
|
52
|
+
/**
|
|
53
|
+
* Create a struct that parses a float from a string, with a minimum value and
|
|
54
|
+
* a default for unset variables.
|
|
55
|
+
*
|
|
56
|
+
* @param minValue - The minimum value for the float.
|
|
57
|
+
* @param defaultValue - The default value for the float.
|
|
58
|
+
* @returns A struct that parses a float from a string.
|
|
59
|
+
*/
|
|
60
|
+
export const parseFloatStruct = (minValue, defaultValue) => coerce(defaulted(min(number(), minValue), defaultValue), string(), (value) => (value === '' ? undefined : parseFloat(value)));
|
|
61
|
+
//# sourceMappingURL=envStructs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envStructs.mjs","sourceRoot":"","sources":["../../../src/utils/config/envStructs.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,MAAM,EACN,SAAS,EACT,GAAG,EACH,MAAM,EACN,QAAQ,EACR,MAAM,EACP,8BAA8B;AAE/B,OAAO,EAAE,SAAS,EAAE,mCAA+B;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAkB,EACQ,EAAE,CAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAa,EAAE,EAAE,CACjD,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CACjC,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,IAAkB,EACF,EAAE,CAClB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAkB,EAAE,CACrE,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,KAAa,EAAE,EAAE;IACjE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEL;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,QAAgB,EAChB,YAAoB,EACJ,EAAE,CAClB,MAAM,CACJ,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,EAChD,MAAM,EAAE,EACR,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CACpE,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,QAAgB,EAChB,YAAoB,EACJ,EAAE,CAClB,MAAM,CACJ,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,EAChD,MAAM,EAAE,EACR,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAClE,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport {\n array,\n coerce,\n defaulted,\n min,\n number,\n optional,\n string,\n} from '@metamask/superstruct';\n\nimport { UrlStruct } from '../urlStruct/urlStruct';\n\n/**\n * Create a struct for environment variables validated against the given\n * struct, where unset and empty strings (the build-time injection default)\n * mean the variable is not set.\n *\n * @param item - The struct to validate the value against when it is set,\n * e.g. `UrlStruct`.\n * @returns A struct that parses to the value or `undefined`.\n * @example\n * const PriceApiBaseUrlStruct = emptyToUndefined(UrlStruct);\n */\nexport const emptyToUndefined = <Type>(\n item: Struct<Type>,\n): Struct<Type | undefined> =>\n coerce(optional(item), string(), (value: string) =>\n value === '' ? undefined : value,\n );\n\n/**\n * Create a struct for comma-separated list environment variables.\n *\n * The raw string is split on commas and each item is validated against the\n * given item struct.\n *\n * @param item - The struct to validate each list item against.\n * @returns A struct that parses a comma-separated string into an array.\n * @example\n * const RpcUrlListStruct = commaSeparatedListOf(UrlStruct);\n */\nexport const commaSeparatedListOf = <Type>(\n item: Struct<Type>,\n): Struct<Type[]> =>\n coerce(array(item), string(), (value: string) => value.split(','));\n\n/**\n * Create a struct for a URL environment variable with a fallback: unset,\n * empty, and whitespace-only values (the build-time injection default)\n * resolve to the fallback, surrounding whitespace is trimmed, and invalid\n * values are rejected.\n *\n * @param fallback - The URL to use when the variable is unset, empty, or\n * whitespace-only.\n * @returns A struct that parses to the URL.\n * @example\n * const EsploraUrlStruct = defaultedUrlStruct('https://blockstream.info/api');\n */\nexport const defaultedUrlStruct = (fallback: string): Struct<string> =>\n coerce(defaulted(UrlStruct, fallback), string(), (value: string) => {\n const trimmed = value.trim();\n return trimmed === '' ? undefined : trimmed;\n });\n\n/**\n * Create a struct that parses an integer from a string, with a minimum value\n * and a default for unset variables.\n *\n * @param minValue - The minimum value for the integer.\n * @param defaultValue - The default value for the integer.\n * @returns A struct that parses an integer from a string.\n */\nexport const parseIntegerStruct = (\n minValue: number,\n defaultValue: number,\n): Struct<number> =>\n coerce(\n defaulted(min(number(), minValue), defaultValue),\n string(),\n (value: string) => (value === '' ? undefined : parseInt(value, 10)),\n );\n\n/**\n * Create a struct that parses a float from a string, with a minimum value and\n * a default for unset variables.\n *\n * @param minValue - The minimum value for the float.\n * @param defaultValue - The default value for the float.\n * @returns A struct that parses a float from a string.\n */\nexport const parseFloatStruct = (\n minValue: number,\n defaultValue: number,\n): Struct<number> =>\n coerce(\n defaulted(min(number(), minValue), defaultValue),\n string(),\n (value: string) => (value === '' ? undefined : parseFloat(value)),\n );\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnvironmentStruct = exports.Environment = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* The environments a snap can be built for, matched against the
|
|
7
|
+
* `ENVIRONMENT` build-time injection.
|
|
8
|
+
*/
|
|
9
|
+
exports.Environment = {
|
|
10
|
+
Local: 'local',
|
|
11
|
+
Test: 'test',
|
|
12
|
+
Production: 'production',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A struct for parsing the environment a snap was built for from an
|
|
16
|
+
* environment variable. Unknown values are rejected.
|
|
17
|
+
*/
|
|
18
|
+
exports.EnvironmentStruct = (0, superstruct_1.enums)(Object.values(exports.Environment));
|
|
19
|
+
//# sourceMappingURL=environmentStruct.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environmentStruct.cjs","sourceRoot":"","sources":["../../../src/utils/config/environmentStruct.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C;;;GAGG;AACU,QAAA,WAAW,GAAG;IACzB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,YAAY;CAChB,CAAC;AAIX;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAA,mBAAK,EACpC,MAAM,CAAC,MAAM,CAAC,mBAAW,CAAoC,CAC9D,CAAC","sourcesContent":["import { enums } from '@metamask/superstruct';\n\n/**\n * The environments a snap can be built for, matched against the\n * `ENVIRONMENT` build-time injection.\n */\nexport const Environment = {\n Local: 'local',\n Test: 'test',\n Production: 'production',\n} as const;\n\nexport type Environment = (typeof Environment)[keyof typeof Environment];\n\n/**\n * A struct for parsing the environment a snap was built for from an\n * environment variable. Unknown values are rejected.\n */\nexport const EnvironmentStruct = enums(\n Object.values(Environment) as [Environment, ...Environment[]],\n);\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environments a snap can be built for, matched against the
|
|
3
|
+
* `ENVIRONMENT` build-time injection.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Environment: {
|
|
6
|
+
readonly Local: "local";
|
|
7
|
+
readonly Test: "test";
|
|
8
|
+
readonly Production: "production";
|
|
9
|
+
};
|
|
10
|
+
export type Environment = (typeof Environment)[keyof typeof Environment];
|
|
11
|
+
/**
|
|
12
|
+
* A struct for parsing the environment a snap was built for from an
|
|
13
|
+
* environment variable. Unknown values are rejected.
|
|
14
|
+
*/
|
|
15
|
+
export declare const EnvironmentStruct: import("@metamask/superstruct").Struct<Environment, {
|
|
16
|
+
local: "local";
|
|
17
|
+
test: "test";
|
|
18
|
+
production: "production";
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=environmentStruct.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environmentStruct.d.cts","sourceRoot":"","sources":["../../../src/utils/config/environmentStruct.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;EAE7B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environments a snap can be built for, matched against the
|
|
3
|
+
* `ENVIRONMENT` build-time injection.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Environment: {
|
|
6
|
+
readonly Local: "local";
|
|
7
|
+
readonly Test: "test";
|
|
8
|
+
readonly Production: "production";
|
|
9
|
+
};
|
|
10
|
+
export type Environment = (typeof Environment)[keyof typeof Environment];
|
|
11
|
+
/**
|
|
12
|
+
* A struct for parsing the environment a snap was built for from an
|
|
13
|
+
* environment variable. Unknown values are rejected.
|
|
14
|
+
*/
|
|
15
|
+
export declare const EnvironmentStruct: import("@metamask/superstruct").Struct<Environment, {
|
|
16
|
+
local: "local";
|
|
17
|
+
test: "test";
|
|
18
|
+
production: "production";
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=environmentStruct.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environmentStruct.d.mts","sourceRoot":"","sources":["../../../src/utils/config/environmentStruct.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;EAE7B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { enums } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* The environments a snap can be built for, matched against the
|
|
4
|
+
* `ENVIRONMENT` build-time injection.
|
|
5
|
+
*/
|
|
6
|
+
export const Environment = {
|
|
7
|
+
Local: 'local',
|
|
8
|
+
Test: 'test',
|
|
9
|
+
Production: 'production',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A struct for parsing the environment a snap was built for from an
|
|
13
|
+
* environment variable. Unknown values are rejected.
|
|
14
|
+
*/
|
|
15
|
+
export const EnvironmentStruct = enums(Object.values(Environment));
|
|
16
|
+
//# sourceMappingURL=environmentStruct.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environmentStruct.mjs","sourceRoot":"","sources":["../../../src/utils/config/environmentStruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,8BAA8B;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,YAAY;CAChB,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CACpC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAoC,CAC9D,CAAC","sourcesContent":["import { enums } from '@metamask/superstruct';\n\n/**\n * The environments a snap can be built for, matched against the\n * `ENVIRONMENT` build-time injection.\n */\nexport const Environment = {\n Local: 'local',\n Test: 'test',\n Production: 'production',\n} as const;\n\nexport type Environment = (typeof Environment)[keyof typeof Environment];\n\n/**\n * A struct for parsing the environment a snap was built for from an\n * environment variable. Unknown values are rejected.\n */\nexport const EnvironmentStruct = enums(\n Object.values(Environment) as [Environment, ...Environment[]],\n);\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevelStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const Logger_1 = require("../logger/Logger.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* A struct for parsing a log level from an environment variable.
|
|
8
|
+
*
|
|
9
|
+
* Log levels are tunables, so the value is case-insensitive and defaults to
|
|
10
|
+
* {@link LogLevel.SILENT} when the variable is unset or empty (the build-time
|
|
11
|
+
* injection default). Unknown values are rejected.
|
|
12
|
+
*/
|
|
13
|
+
exports.LogLevelStruct = (0, superstruct_1.coerce)((0, superstruct_1.defaulted)((0, superstruct_1.enums)(Object.values(Logger_1.LogLevel)), Logger_1.LogLevel.SILENT), (0, superstruct_1.string)(), (value) => (value === '' ? undefined : value.toLowerCase()));
|
|
14
|
+
//# sourceMappingURL=logLevelStruct.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logLevelStruct.cjs","sourceRoot":"","sources":["../../../src/utils/config/logLevelStruct.ts"],"names":[],"mappings":";;;AAAA,uDAAyE;AAEzE,iDAA4C;AAE5C;;;;;;GAMG;AACU,QAAA,cAAc,GAAG,IAAA,oBAAM,EAClC,IAAA,uBAAS,EACP,IAAA,mBAAK,EAAC,MAAM,CAAC,MAAM,CAAC,iBAAQ,CAA8B,CAAC,EAC3D,iBAAQ,CAAC,MAAM,CAChB,EACD,IAAA,oBAAM,GAAE,EACR,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CACpE,CAAC","sourcesContent":["import { coerce, defaulted, enums, string } from '@metamask/superstruct';\n\nimport { LogLevel } from '../logger/Logger';\n\n/**\n * A struct for parsing a log level from an environment variable.\n *\n * Log levels are tunables, so the value is case-insensitive and defaults to\n * {@link LogLevel.SILENT} when the variable is unset or empty (the build-time\n * injection default). Unknown values are rejected.\n */\nexport const LogLevelStruct = coerce(\n defaulted(\n enums(Object.values(LogLevel) as [LogLevel, ...LogLevel[]]),\n LogLevel.SILENT,\n ),\n string(),\n (value: string) => (value === '' ? undefined : value.toLowerCase()),\n);\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogLevel } from "../logger/Logger.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* A struct for parsing a log level from an environment variable.
|
|
4
|
+
*
|
|
5
|
+
* Log levels are tunables, so the value is case-insensitive and defaults to
|
|
6
|
+
* {@link LogLevel.SILENT} when the variable is unset or empty (the build-time
|
|
7
|
+
* injection default). Unknown values are rejected.
|
|
8
|
+
*/
|
|
9
|
+
export declare const LogLevelStruct: import("@metamask/superstruct").Struct<LogLevel, {
|
|
10
|
+
silent: "silent";
|
|
11
|
+
error: "error";
|
|
12
|
+
warn: "warn";
|
|
13
|
+
info: "info";
|
|
14
|
+
debug: "debug";
|
|
15
|
+
trace: "trace";
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=logLevelStruct.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logLevelStruct.d.cts","sourceRoot":"","sources":["../../../src/utils/config/logLevelStruct.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,6BAAyB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;EAO1B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogLevel } from "../logger/Logger.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A struct for parsing a log level from an environment variable.
|
|
4
|
+
*
|
|
5
|
+
* Log levels are tunables, so the value is case-insensitive and defaults to
|
|
6
|
+
* {@link LogLevel.SILENT} when the variable is unset or empty (the build-time
|
|
7
|
+
* injection default). Unknown values are rejected.
|
|
8
|
+
*/
|
|
9
|
+
export declare const LogLevelStruct: import("@metamask/superstruct").Struct<LogLevel, {
|
|
10
|
+
silent: "silent";
|
|
11
|
+
error: "error";
|
|
12
|
+
warn: "warn";
|
|
13
|
+
info: "info";
|
|
14
|
+
debug: "debug";
|
|
15
|
+
trace: "trace";
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=logLevelStruct.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logLevelStruct.d.mts","sourceRoot":"","sources":["../../../src/utils/config/logLevelStruct.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,6BAAyB;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;;;EAO1B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { coerce, defaulted, enums, string } from "@metamask/superstruct";
|
|
2
|
+
import { LogLevel } from "../logger/Logger.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* A struct for parsing a log level from an environment variable.
|
|
5
|
+
*
|
|
6
|
+
* Log levels are tunables, so the value is case-insensitive and defaults to
|
|
7
|
+
* {@link LogLevel.SILENT} when the variable is unset or empty (the build-time
|
|
8
|
+
* injection default). Unknown values are rejected.
|
|
9
|
+
*/
|
|
10
|
+
export const LogLevelStruct = coerce(defaulted(enums(Object.values(LogLevel)), LogLevel.SILENT), string(), (value) => (value === '' ? undefined : value.toLowerCase()));
|
|
11
|
+
//# sourceMappingURL=logLevelStruct.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logLevelStruct.mjs","sourceRoot":"","sources":["../../../src/utils/config/logLevelStruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAEzE,OAAO,EAAE,QAAQ,EAAE,6BAAyB;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAClC,SAAS,CACP,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAA8B,CAAC,EAC3D,QAAQ,CAAC,MAAM,CAChB,EACD,MAAM,EAAE,EACR,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CACpE,CAAC","sourcesContent":["import { coerce, defaulted, enums, string } from '@metamask/superstruct';\n\nimport { LogLevel } from '../logger/Logger';\n\n/**\n * A struct for parsing a log level from an environment variable.\n *\n * Log levels are tunables, so the value is case-insensitive and defaults to\n * {@link LogLevel.SILENT} when the variable is unset or empty (the build-time\n * injection default). Unknown values are rejected.\n */\nexport const LogLevelStruct = coerce(\n defaulted(\n enums(Object.values(LogLevel) as [LogLevel, ...LogLevel[]]),\n LogLevel.SILENT,\n ),\n string(),\n (value: string) => (value === '' ? undefined : value.toLowerCase()),\n);\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseEnv = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* Parse and validate a raw environment record against a struct.
|
|
7
|
+
*
|
|
8
|
+
* This is the fail-fast entry point for building a snap configuration from
|
|
9
|
+
* build-time injected environment variables. Parsing happens once, when the
|
|
10
|
+
* configuration provider is constructed; an invalid environment stops the
|
|
11
|
+
* snap at startup instead of producing undefined behaviour later.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The raw environment record, e.g. `process.env` values
|
|
14
|
+
* collected into an object.
|
|
15
|
+
* @param struct - The struct describing the expected environment.
|
|
16
|
+
* @returns The parsed and validated environment.
|
|
17
|
+
* @throws If the environment does not match the struct.
|
|
18
|
+
* @example
|
|
19
|
+
* const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);
|
|
20
|
+
*/
|
|
21
|
+
const parseEnv = (value, struct) => {
|
|
22
|
+
try {
|
|
23
|
+
return (0, superstruct_1.create)(value, struct);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new Error(`Invalid environment configuration: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.parseEnv = parseEnv;
|
|
30
|
+
//# sourceMappingURL=parseEnv.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnv.cjs","sourceRoot":"","sources":["../../../src/utils/config/parseEnv.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAG/C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,QAAQ,GAAG,CACtB,KAA8B,EAC9B,MAAoB,EACd,EAAE;IACR,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,sCAAuC,KAAe,CAAC,OAAO,EAAE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,QAAQ,YAWnB","sourcesContent":["import { create } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\n\n/**\n * Parse and validate a raw environment record against a struct.\n *\n * This is the fail-fast entry point for building a snap configuration from\n * build-time injected environment variables. Parsing happens once, when the\n * configuration provider is constructed; an invalid environment stops the\n * snap at startup instead of producing undefined behaviour later.\n *\n * @param value - The raw environment record, e.g. `process.env` values\n * collected into an object.\n * @param struct - The struct describing the expected environment.\n * @returns The parsed and validated environment.\n * @throws If the environment does not match the struct.\n * @example\n * const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);\n */\nexport const parseEnv = <Type>(\n value: Record<string, unknown>,\n struct: Struct<Type>,\n): Type => {\n try {\n return create(value, struct);\n } catch (error) {\n throw new Error(\n `Invalid environment configuration: ${(error as Error).message}`,\n );\n }\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* Parse and validate a raw environment record against a struct.
|
|
4
|
+
*
|
|
5
|
+
* This is the fail-fast entry point for building a snap configuration from
|
|
6
|
+
* build-time injected environment variables. Parsing happens once, when the
|
|
7
|
+
* configuration provider is constructed; an invalid environment stops the
|
|
8
|
+
* snap at startup instead of producing undefined behaviour later.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The raw environment record, e.g. `process.env` values
|
|
11
|
+
* collected into an object.
|
|
12
|
+
* @param struct - The struct describing the expected environment.
|
|
13
|
+
* @returns The parsed and validated environment.
|
|
14
|
+
* @throws If the environment does not match the struct.
|
|
15
|
+
* @example
|
|
16
|
+
* const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);
|
|
17
|
+
*/
|
|
18
|
+
export declare const parseEnv: <Type>(value: Record<string, unknown>, struct: Struct<Type>) => Type;
|
|
19
|
+
//# sourceMappingURL=parseEnv.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnv.d.cts","sourceRoot":"","sources":["../../../src/utils/config/parseEnv.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAEpD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,EAC3B,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,KACnB,IAQF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* Parse and validate a raw environment record against a struct.
|
|
4
|
+
*
|
|
5
|
+
* This is the fail-fast entry point for building a snap configuration from
|
|
6
|
+
* build-time injected environment variables. Parsing happens once, when the
|
|
7
|
+
* configuration provider is constructed; an invalid environment stops the
|
|
8
|
+
* snap at startup instead of producing undefined behaviour later.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The raw environment record, e.g. `process.env` values
|
|
11
|
+
* collected into an object.
|
|
12
|
+
* @param struct - The struct describing the expected environment.
|
|
13
|
+
* @returns The parsed and validated environment.
|
|
14
|
+
* @throws If the environment does not match the struct.
|
|
15
|
+
* @example
|
|
16
|
+
* const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);
|
|
17
|
+
*/
|
|
18
|
+
export declare const parseEnv: <Type>(value: Record<string, unknown>, struct: Struct<Type>) => Type;
|
|
19
|
+
//# sourceMappingURL=parseEnv.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnv.d.mts","sourceRoot":"","sources":["../../../src/utils/config/parseEnv.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAEpD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,EAC3B,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,KACnB,IAQF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { create } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* Parse and validate a raw environment record against a struct.
|
|
4
|
+
*
|
|
5
|
+
* This is the fail-fast entry point for building a snap configuration from
|
|
6
|
+
* build-time injected environment variables. Parsing happens once, when the
|
|
7
|
+
* configuration provider is constructed; an invalid environment stops the
|
|
8
|
+
* snap at startup instead of producing undefined behaviour later.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The raw environment record, e.g. `process.env` values
|
|
11
|
+
* collected into an object.
|
|
12
|
+
* @param struct - The struct describing the expected environment.
|
|
13
|
+
* @returns The parsed and validated environment.
|
|
14
|
+
* @throws If the environment does not match the struct.
|
|
15
|
+
* @example
|
|
16
|
+
* const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);
|
|
17
|
+
*/
|
|
18
|
+
export const parseEnv = (value, struct) => {
|
|
19
|
+
try {
|
|
20
|
+
return create(value, struct);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new Error(`Invalid environment configuration: ${error.message}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=parseEnv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseEnv.mjs","sourceRoot":"","sources":["../../../src/utils/config/parseEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAG/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,KAA8B,EAC9B,MAAoB,EACd,EAAE;IACR,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,sCAAuC,KAAe,CAAC,OAAO,EAAE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { create } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\n\n/**\n * Parse and validate a raw environment record against a struct.\n *\n * This is the fail-fast entry point for building a snap configuration from\n * build-time injected environment variables. Parsing happens once, when the\n * configuration provider is constructed; an invalid environment stops the\n * snap at startup instead of producing undefined behaviour later.\n *\n * @param value - The raw environment record, e.g. `process.env` values\n * collected into an object.\n * @param struct - The struct describing the expected environment.\n * @returns The parsed and validated environment.\n * @throws If the environment does not match the struct.\n * @example\n * const env = parseEnv({ RPC_URL: process.env.RPC_URL }, EnvStruct);\n */\nexport const parseEnv = <Type>(\n value: Record<string, unknown>,\n struct: Struct<Type>,\n): Type => {\n try {\n return create(value, struct);\n } catch (error) {\n throw new Error(\n `Invalid environment configuration: ${(error as Error).message}`,\n );\n }\n};\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InFlightCoalescer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Coalesces concurrent async operations by key: while a call for a key is in
|
|
6
|
+
* flight, subsequent calls with the same key await the same promise instead of
|
|
7
|
+
* starting duplicate work. Once a run settles, the next call starts a fresh one.
|
|
8
|
+
*
|
|
9
|
+
* Note that coalesced callers share the run's outcome, including rejections.
|
|
10
|
+
*/
|
|
11
|
+
class InFlightCoalescer {
|
|
12
|
+
#inFlight = new Map();
|
|
13
|
+
async run(key, fn) {
|
|
14
|
+
const pending = this.#inFlight.get(key);
|
|
15
|
+
if (pending) {
|
|
16
|
+
return pending;
|
|
17
|
+
}
|
|
18
|
+
const task = Promise.resolve()
|
|
19
|
+
.then(fn)
|
|
20
|
+
.finally(() => {
|
|
21
|
+
this.#inFlight.delete(key);
|
|
22
|
+
});
|
|
23
|
+
this.#inFlight.set(key, task);
|
|
24
|
+
return task;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.InFlightCoalescer = InFlightCoalescer;
|
|
28
|
+
//# sourceMappingURL=InFlightCoalescer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InFlightCoalescer.cjs","sourceRoot":"","sources":["../../../src/utils/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,iBAAiB;IACnB,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAS,GAAW,EAAE,EAAyB;QACtD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAA0B,CAAC;QACpC,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE;aAC3B,IAAI,CAAC,EAAE,CAAC;aACR,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlBD,8CAkBC","sourcesContent":["/**\n * Coalesces concurrent async operations by key: while a call for a key is in\n * flight, subsequent calls with the same key await the same promise instead of\n * starting duplicate work. Once a run settles, the next call starts a fresh one.\n *\n * Note that coalesced callers share the run's outcome, including rejections.\n */\nexport class InFlightCoalescer {\n readonly #inFlight = new Map<string, Promise<unknown>>();\n\n async run<Result>(key: string, fn: () => Promise<Result>): Promise<Result> {\n const pending = this.#inFlight.get(key);\n if (pending) {\n return pending as Promise<Result>;\n }\n\n const task = Promise.resolve()\n .then(fn)\n .finally(() => {\n this.#inFlight.delete(key);\n });\n this.#inFlight.set(key, task);\n\n return task;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coalesces concurrent async operations by key: while a call for a key is in
|
|
3
|
+
* flight, subsequent calls with the same key await the same promise instead of
|
|
4
|
+
* starting duplicate work. Once a run settles, the next call starts a fresh one.
|
|
5
|
+
*
|
|
6
|
+
* Note that coalesced callers share the run's outcome, including rejections.
|
|
7
|
+
*/
|
|
8
|
+
export declare class InFlightCoalescer {
|
|
9
|
+
#private;
|
|
10
|
+
run<Result>(key: string, fn: () => Promise<Result>): Promise<Result>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=InFlightCoalescer.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InFlightCoalescer.d.cts","sourceRoot":"","sources":["../../../src/utils/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAGtB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAe3E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coalesces concurrent async operations by key: while a call for a key is in
|
|
3
|
+
* flight, subsequent calls with the same key await the same promise instead of
|
|
4
|
+
* starting duplicate work. Once a run settles, the next call starts a fresh one.
|
|
5
|
+
*
|
|
6
|
+
* Note that coalesced callers share the run's outcome, including rejections.
|
|
7
|
+
*/
|
|
8
|
+
export declare class InFlightCoalescer {
|
|
9
|
+
#private;
|
|
10
|
+
run<Result>(key: string, fn: () => Promise<Result>): Promise<Result>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=InFlightCoalescer.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InFlightCoalescer.d.mts","sourceRoot":"","sources":["../../../src/utils/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAGtB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAe3E"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coalesces concurrent async operations by key: while a call for a key is in
|
|
3
|
+
* flight, subsequent calls with the same key await the same promise instead of
|
|
4
|
+
* starting duplicate work. Once a run settles, the next call starts a fresh one.
|
|
5
|
+
*
|
|
6
|
+
* Note that coalesced callers share the run's outcome, including rejections.
|
|
7
|
+
*/
|
|
8
|
+
export class InFlightCoalescer {
|
|
9
|
+
#inFlight = new Map();
|
|
10
|
+
async run(key, fn) {
|
|
11
|
+
const pending = this.#inFlight.get(key);
|
|
12
|
+
if (pending) {
|
|
13
|
+
return pending;
|
|
14
|
+
}
|
|
15
|
+
const task = Promise.resolve()
|
|
16
|
+
.then(fn)
|
|
17
|
+
.finally(() => {
|
|
18
|
+
this.#inFlight.delete(key);
|
|
19
|
+
});
|
|
20
|
+
this.#inFlight.set(key, task);
|
|
21
|
+
return task;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=InFlightCoalescer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InFlightCoalescer.mjs","sourceRoot":"","sources":["../../../src/utils/dedupe/InFlightCoalescer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACnB,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEzD,KAAK,CAAC,GAAG,CAAS,GAAW,EAAE,EAAyB;QACtD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,OAA0B,CAAC;QACpC,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE;aAC3B,IAAI,CAAC,EAAE,CAAC;aACR,OAAO,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/**\n * Coalesces concurrent async operations by key: while a call for a key is in\n * flight, subsequent calls with the same key await the same promise instead of\n * starting duplicate work. Once a run settles, the next call starts a fresh one.\n *\n * Note that coalesced callers share the run's outcome, including rejections.\n */\nexport class InFlightCoalescer {\n readonly #inFlight = new Map<string, Promise<unknown>>();\n\n async run<Result>(key: string, fn: () => Promise<Result>): Promise<Result> {\n const pending = this.#inFlight.get(key);\n if (pending) {\n return pending as Promise<Result>;\n }\n\n const task = Promise.resolve()\n .then(fn)\n .finally(() => {\n this.#inFlight.delete(key);\n });\n this.#inFlight.set(key, task);\n\n return task;\n }\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeError = normalizeError;
|
|
4
|
+
exports.createWithCatchAndThrowSnapError = createWithCatchAndThrowSnapError;
|
|
5
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
|
+
const snapRpcError_1 = require("./snapRpcError.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes an unknown caught value into a Snap RPC error.
|
|
9
|
+
*
|
|
10
|
+
* Preserves existing Snap RPC errors; otherwise wraps the value in {@link SnapError}.
|
|
11
|
+
*
|
|
12
|
+
* @param error - The caught value.
|
|
13
|
+
* @returns A Snap RPC error.
|
|
14
|
+
*/
|
|
15
|
+
function normalizeError(error) {
|
|
16
|
+
return (0, snapRpcError_1.isSnapRpcError)(error)
|
|
17
|
+
? error
|
|
18
|
+
: new snaps_sdk_1.SnapError(error instanceof Error ? error : (0, snaps_sdk_1.getErrorMessage)(error));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a handler-boundary error wrapper wired with logger, tracking, and optional error normalization.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Logger, error-tracking transport, and optional custom normalizer.
|
|
24
|
+
* @param options.logError - Logger method used to record the normalized error.
|
|
25
|
+
* @param options.trackError - Snap-specific Sentry transport.
|
|
26
|
+
* @param options.normalizeErrorFn - Optional error normalizer; defaults to {@link normalizeError}.
|
|
27
|
+
* @returns A function that catches errors, tracks them, logs, and rethrows as Snap RPC errors.
|
|
28
|
+
*/
|
|
29
|
+
function createWithCatchAndThrowSnapError({ logError, trackError, normalizeErrorFn = normalizeError, }) {
|
|
30
|
+
return (fn, logErrorOverride) => withCatchAndThrowSnapErrorHandler(logErrorOverride ?? logError, trackError, normalizeErrorFn, fn);
|
|
31
|
+
}
|
|
32
|
+
async function withCatchAndThrowSnapErrorHandler(logError, trackError, normalizeErrorFn, fn) {
|
|
33
|
+
try {
|
|
34
|
+
return await fn();
|
|
35
|
+
}
|
|
36
|
+
catch (unknownError) {
|
|
37
|
+
await trackError(unknownError);
|
|
38
|
+
const error = normalizeErrorFn(unknownError);
|
|
39
|
+
logError({ error }, `[SnapError] ${JSON.stringify(error.toJSON(), null, 2)}`);
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error -- Snap RPC errors are the handler boundary surface
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../../../src/utils/errors/errors.ts"],"names":[],"mappings":";;AAyBA,wCAIC;AAmBD,4EAkBC;AAlED,mDAAiE;AAGjE,qDAAgD;AAchD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,6BAAc,EAAC,KAAK,CAAC;QAC1B,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,qBAAS,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,2BAAe,EAAC,KAAK,CAAC,CAAC,CAAC;AAC7E,CAAC;AAUD;;;;;;;;GAQG;AACH,SAAgB,gCAAgC,CAAC,EAC/C,QAAQ,EACR,UAAU,EACV,gBAAgB,GAAG,cAAc,GACO;IAIxC,OAAO,CACL,EAA4B,EAC5B,gBAA6B,EACT,EAAE,CACtB,iCAAiC,CAC/B,gBAAgB,IAAI,QAAQ,EAC5B,UAAU,EACV,gBAAgB,EAChB,EAAE,CACH,CAAC;AACN,CAAC;AAED,KAAK,UAAU,iCAAiC,CAC9C,QAAoB,EACpB,UAAwB,EACxB,gBAAkC,EAClC,EAA4B;IAE5B,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,YAAY,EAAE,CAAC;QACtB,MAAM,UAAU,CAAC,YAAY,CAAC,CAAC;QAE/B,MAAM,KAAK,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAE7C,QAAQ,CACN,EAAE,KAAK,EAAE,EACT,eAAe,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CACzD,CAAC;QAEF,mHAAmH;QACnH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { SnapError, getErrorMessage } from '@metamask/snaps-sdk';\n\nimport type { Logger } from '../logger/Logger';\nimport { isSnapRpcError } from './snapRpcError';\nimport type { SnapRpcError } from './snapRpcError';\n\n/**\n * Sends an error to the snap's tracking transport (e.g. `snap_trackError`).\n * Whether to invoke this for a given error in a given context is the caller's decision.\n */\nexport type TrackErrorFn = (error: unknown) => Promise<string | undefined>;\n\n/**\n * Converts a caught value into an error suitable for Snap RPC responses.\n */\nexport type NormalizeErrorFn = (error: unknown) => SnapRpcError;\n\n/**\n * Normalizes an unknown caught value into a Snap RPC error.\n *\n * Preserves existing Snap RPC errors; otherwise wraps the value in {@link SnapError}.\n *\n * @param error - The caught value.\n * @returns A Snap RPC error.\n */\nexport function normalizeError(error: unknown): SnapRpcError {\n return isSnapRpcError(error)\n ? error\n : new SnapError(error instanceof Error ? error : getErrorMessage(error));\n}\n\nexport type LogErrorFn = Logger['error'];\n\nexport type CreateWithCatchAndThrowSnapErrorOptions = {\n logError: LogErrorFn;\n trackError: TrackErrorFn;\n normalizeErrorFn?: NormalizeErrorFn;\n};\n\n/**\n * Creates a handler-boundary error wrapper wired with logger, tracking, and optional error normalization.\n *\n * @param options - Logger, error-tracking transport, and optional custom normalizer.\n * @param options.logError - Logger method used to record the normalized error.\n * @param options.trackError - Snap-specific Sentry transport.\n * @param options.normalizeErrorFn - Optional error normalizer; defaults to {@link normalizeError}.\n * @returns A function that catches errors, tracks them, logs, and rethrows as Snap RPC errors.\n */\nexport function createWithCatchAndThrowSnapError({\n logError,\n trackError,\n normalizeErrorFn = normalizeError,\n}: CreateWithCatchAndThrowSnapErrorOptions): <ResponseT>(\n fn: () => Promise<ResponseT>,\n logErrorOverride?: LogErrorFn,\n) => Promise<ResponseT> {\n return <ResponseT>(\n fn: () => Promise<ResponseT>,\n logErrorOverride?: LogErrorFn,\n ): Promise<ResponseT> =>\n withCatchAndThrowSnapErrorHandler(\n logErrorOverride ?? logError,\n trackError,\n normalizeErrorFn,\n fn,\n );\n}\n\nasync function withCatchAndThrowSnapErrorHandler<ResponseT>(\n logError: LogErrorFn,\n trackError: TrackErrorFn,\n normalizeErrorFn: NormalizeErrorFn,\n fn: () => Promise<ResponseT>,\n): Promise<ResponseT> {\n try {\n return await fn();\n } catch (unknownError) {\n await trackError(unknownError);\n\n const error = normalizeErrorFn(unknownError);\n\n logError(\n { error },\n `[SnapError] ${JSON.stringify(error.toJSON(), null, 2)}`,\n );\n\n // eslint-disable-next-line @typescript-eslint/only-throw-error -- Snap RPC errors are the handler boundary surface\n throw error;\n }\n}\n"]}
|