@metamask-previews/core-backend 11.0.0-preview-d1cca62 → 11.0.0-preview-c6cdff1dd
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 +0 -4
- package/README.md +0 -31
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/ws/RampsActivityService.d.ts +0 -62
- package/dist/ws/RampsActivityService.d.ts.map +0 -1
- package/dist/ws/RampsActivityService.js +0 -207
- package/dist/ws/RampsActivityService.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `RampsActivityService` for validated, profile-scoped ramps activity notifications over `BackendWebSocketService` (`ramps-activity.v1.<profileId>`) ([#10304](https://github.com/MetaMask/core/pull/10304))
|
|
13
|
-
|
|
14
10
|
### Changed
|
|
15
11
|
|
|
16
12
|
- Bump `uuid` from `^9.0.1` to `^11.1.1` ([#10243](https://github.com/MetaMask/core/pull/10243))
|
package/README.md
CHANGED
|
@@ -38,7 +38,6 @@ Core backend services for MetaMask, serving as the data layer between Backend se
|
|
|
38
38
|
- [Constructor Options](#constructor-options-1)
|
|
39
39
|
- [Methods](#methods-1)
|
|
40
40
|
- [Events Published](#events-published)
|
|
41
|
-
- [RampsActivityService](#rampsactivityservice)
|
|
42
41
|
|
|
43
42
|
## Installation
|
|
44
43
|
|
|
@@ -656,33 +655,3 @@ interface AccountActivityServiceOptions {
|
|
|
656
655
|
- `AccountActivityService:balanceUpdated` - Real-time balance changes
|
|
657
656
|
- `AccountActivityService:transactionUpdated` - Transaction status updates
|
|
658
657
|
- `AccountActivityService:statusChanged` - Chain/service status changes
|
|
659
|
-
|
|
660
|
-
### RampsActivityService
|
|
661
|
-
|
|
662
|
-
Profile-scoped service for receiving ramps activity notifications through
|
|
663
|
-
`BackendWebSocketService`. It derives the
|
|
664
|
-
`ramps-activity.v1.<profileId>` channel from
|
|
665
|
-
`AuthenticationController:getSessionProfile`, preferring
|
|
666
|
-
`canonicalProfileId` (the same identity Ramps uses as MoonPay `external_id`)
|
|
667
|
-
and falling back to the per-SRP `profileId`. It validates every server event at
|
|
668
|
-
runtime, and automatically resubscribes after WebSocket reconnects, profile
|
|
669
|
-
changes, and wallet unlocks.
|
|
670
|
-
|
|
671
|
-
```typescript
|
|
672
|
-
const rampsActivityService = new RampsActivityService({
|
|
673
|
-
messenger: rampsActivityServiceMessenger,
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
await rampsActivityService.init();
|
|
677
|
-
|
|
678
|
-
messenger.subscribe('RampsActivityService:eventReceived', (event) => {
|
|
679
|
-
if (event.needsFetch) {
|
|
680
|
-
// Refresh ramps data via RampsController (GET is source of truth).
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
```
|
|
684
|
-
|
|
685
|
-
Published events:
|
|
686
|
-
|
|
687
|
-
- `RampsActivityService:eventReceived` - A validated profile-scoped ramps activity event
|
|
688
|
-
- `RampsActivityService:statusChanged` - The backend WebSocket connection status
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
export { BackendWebSocketService, getCloseReason, WebSocketState, WebSocketEventType, } from './ws/BackendWebSocketService.js';
|
|
2
2
|
export type { BackendWebSocketServiceOptions, ClientRequestMessage, ServerResponseMessage, ServerNotificationMessage, WebSocketMessage, ChannelCallback, WebSocketSubscription, WebSocketConnectionInfo, BackendWebSocketServiceActions, BackendWebSocketServiceConnectionStateChangedEvent, BackendWebSocketServiceEvents, BackendWebSocketServiceMessenger, } from './ws/BackendWebSocketService.js';
|
|
3
3
|
export { AccountActivityService, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS, } from './ws/AccountActivityService.js';
|
|
4
|
-
export type { SystemNotificationData, SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AccountActivityServiceMessenger, } from './ws/AccountActivityService.js';
|
|
4
|
+
export type { SystemNotificationData, SubscriptionOptions, AccountActivityServiceOptions, AccountActivityServiceActions, AllowedActions as AccountActivityServiceAllowedActions, AccountActivityServiceTransactionUpdatedEvent, AccountActivityServiceBalanceUpdatedEvent, AccountActivityServiceSubscriptionErrorEvent, AccountActivityServiceStatusChangedEvent, AccountActivityServiceEvents, AllowedEvents as AccountActivityServiceAllowedEvents, AccountActivityServiceMessenger, } from './ws/AccountActivityService.js';
|
|
5
5
|
export type { Transaction, Asset, Balance, Transfer, BalanceUpdate, AccountActivityMessage, } from './types.js';
|
|
6
|
-
export { RampsActivityService, RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS, RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS, } from './ws/RampsActivityService.js';
|
|
7
|
-
export type { RampsActivityEntity, RampsActivityEvent, RampsActivityServiceOptions, RampsActivityServiceActions, RampsActivityServiceEventReceivedEvent, RampsActivityServiceStatusChangedEvent, RampsActivityServiceEvents, RampsActivityServiceMessenger, } from './ws/RampsActivityService.js';
|
|
8
6
|
export { ApiPlatformClientService, apiPlatformClientServiceName, } from './ApiPlatformClientService.js';
|
|
9
7
|
export type { ApiPlatformClientServiceOptions, ApiPlatformClientServiceActions, ApiPlatformClientServiceEvents, ApiPlatformClientServiceMessenger, } from './ApiPlatformClientService.js';
|
|
10
8
|
export { OHLCVService, OHLCV_SERVICE_ALLOWED_ACTIONS, OHLCV_SERVICE_ALLOWED_EVENTS, } from './ws/ohlcv/index.js';
|
|
11
|
-
export type { OHLCVBar, OHLCVSubscriptionOptions, OHLCVSystemNotificationData, OHLCVServiceOptions, OHLCVServiceActions, OHLCVServiceBarUpdatedEvent, OHLCVServiceChainStatusChangedEvent, OHLCVServiceSubscriptionErrorEvent, OHLCVServiceEvents, OHLCVServiceMessenger, } from './ws/ohlcv/index.js';
|
|
9
|
+
export type { OHLCVBar, OHLCVSubscriptionOptions, OHLCVSystemNotificationData, OHLCVServiceOptions, OHLCVServiceActions, OHLCVServiceAllowedActions, OHLCVServiceBarUpdatedEvent, OHLCVServiceChainStatusChangedEvent, OHLCVServiceSubscriptionErrorEvent, OHLCVServiceEvents, OHLCVServiceAllowedEvents, OHLCVServiceMessenger, } from './ws/ohlcv/index.js';
|
|
12
10
|
export { ApiPlatformClient, createApiPlatformClient, AccountsApiClient, PricesApiClient, TokenApiClient, TokensApiClient, API_URLS, STALE_TIMES, GC_TIMES, V6_DEFI_POSITION_TYPES, calculateRetryDelay, getQueryOptionsOverrides, shouldRetry, HttpError, } from './api/index.js';
|
|
13
11
|
export type { ApiPlatformClientOptions, ApiUrls, FetchOptions, PageInfo, SupportedCurrency, MarketDataDetails, V5BalanceItem, V5BalancesResponse, V2BalanceItem, V2BalancesResponse, V4BalancesResponse, V6VsCurrency, V6DeFiPositionType, V6BalanceMetadata, V6StellarTokenBalanceMetadata, V6TokenBalanceMetadata, V6BalanceItem, V6BalancesResponse, V1SupportedNetworksResponse, V2SupportedNetworksResponse, V2ActiveNetworksResponse, V1TransactionByHashResponse, V1AccountTransactionsResponse, V4MultiAccountTransactionsResponse, ValueTransfer, V1AccountRelationshipResult, NftItem, V2NftsResponse, TokenDiscoveryItem, V2TokensResponse, V3SpotPricesResponse, CoinGeckoSpotPrice, ExchangeRateInfo, V1ExchangeRatesResponse, PriceSupportedNetworksResponse, V1HistoricalPricesResponse, V3HistoricalPricesResponse, TokenMetadata, V1TokenDescriptionResponse, NetworkInfo, TopAsset, TrendingSortBy, TrendingToken, TopGainersSortOption, TrendingSortOption, V1SuggestedOccurrenceFloorsResponse, V1TokenSupportedNetworksResponse, V2TokenSupportedNetworksResponse, V3AssetResponse, } from './api/index.js';
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,YAAY,EACV,8BAA8B,EAC9B,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,kDAAkD,EAClD,6BAA6B,EAC7B,gCAAgC,GACjC,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EACL,sBAAsB,EACtB,wCAAwC,EACxC,uCAAuC,GACxC,MAAM,gCAAgC,CAAC;AAExC,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC7B,6CAA6C,EAC7C,yCAAyC,EACzC,4CAA4C,EAC5C,wCAAwC,EACxC,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAMxC,YAAY,EACV,WAAW,EACX,KAAK,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,YAAY,EACV,8BAA8B,EAC9B,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9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Z,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EAEjB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,6BAA6B,EAC7B,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,6BAA6B,EAC7B,kCAAkC,EAClC,aAAa,EACb,2BAA2B,EAC3B,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAEhB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,8BAA8B,EAC9B,0BAA0B,EAC1B,0BAA0B,EAE1B,aAAa,EACb,0BAA0B,EAC1B,WAAW,EACX,QAAQ,EACR,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,mCAAmC,EAEnC,gCAAgC,EAChC,gCAAgC,EAChC,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,6 @@ export { BackendWebSocketService, getCloseReason, WebSocketState, WebSocketEvent
|
|
|
8
8
|
// ============================================================================
|
|
9
9
|
export { AccountActivityService, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS, ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS, } from './ws/AccountActivityService.js';
|
|
10
10
|
// ============================================================================
|
|
11
|
-
// RAMPS ACTIVITY SERVICE
|
|
12
|
-
// ============================================================================
|
|
13
|
-
export { RampsActivityService, RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS, RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS, } from './ws/RampsActivityService.js';
|
|
14
|
-
// ============================================================================
|
|
15
11
|
// API PLATFORM CLIENT SERVICE
|
|
16
12
|
// ============================================================================
|
|
17
13
|
export { ApiPlatformClientService, apiPlatformClientServiceName, } from './ApiPlatformClientService.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAiBzC,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,OAAO,EACL,sBAAsB,EACtB,wCAAwC,EACxC,uCAAuC,GACxC,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAiBzC,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,OAAO,EACL,sBAAsB,EACtB,wCAAwC,EACxC,uCAAuC,GACxC,MAAM,gCAAgC,CAAC;AA8BxC,+EAA+E;AAC/E,8BAA8B;AAC9B,+EAA+E;AAE/E,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AASvC,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E,OAAO,EACL,YAAY,EACZ,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,qBAAqB,CAAC;AAiB7B,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E,OAAO,EACL,iBAAiB,EACjB,uBAAuB;AACvB,yBAAyB;AACzB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,eAAe;AACf,YAAY;AACZ,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,sBAAsB;AACtB,UAAU;AACV,mBAAmB,EACnB,wBAAwB,EACxB,WAAW;AACX,SAAS;AACT,SAAS,GACV,MAAM,gBAAgB,CAAC","sourcesContent":["// Core Backend Package Exports\n\n// ============================================================================\n// BACKEND WEBSOCKET SERVICE\n// ============================================================================\n\nexport {\n BackendWebSocketService,\n getCloseReason,\n WebSocketState,\n WebSocketEventType,\n} from './ws/BackendWebSocketService.js';\n\nexport type {\n BackendWebSocketServiceOptions,\n ClientRequestMessage,\n ServerResponseMessage,\n ServerNotificationMessage,\n WebSocketMessage,\n ChannelCallback,\n WebSocketSubscription,\n WebSocketConnectionInfo,\n BackendWebSocketServiceActions,\n BackendWebSocketServiceConnectionStateChangedEvent,\n BackendWebSocketServiceEvents,\n BackendWebSocketServiceMessenger,\n} from './ws/BackendWebSocketService.js';\n\n// ============================================================================\n// ACCOUNT ACTIVITY SERVICE\n// ============================================================================\n\nexport {\n AccountActivityService,\n ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS,\n ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS,\n} from './ws/AccountActivityService.js';\n\nexport type {\n SystemNotificationData,\n SubscriptionOptions,\n AccountActivityServiceOptions,\n AccountActivityServiceActions,\n AllowedActions as AccountActivityServiceAllowedActions,\n AccountActivityServiceTransactionUpdatedEvent,\n AccountActivityServiceBalanceUpdatedEvent,\n AccountActivityServiceSubscriptionErrorEvent,\n AccountActivityServiceStatusChangedEvent,\n AccountActivityServiceEvents,\n AllowedEvents as AccountActivityServiceAllowedEvents,\n AccountActivityServiceMessenger,\n} from './ws/AccountActivityService.js';\n\n// ============================================================================\n// SHARED TYPES\n// ============================================================================\n\nexport type {\n Transaction,\n Asset,\n Balance,\n Transfer,\n BalanceUpdate,\n AccountActivityMessage,\n} from './types.js';\n\n// ============================================================================\n// API PLATFORM CLIENT SERVICE\n// ============================================================================\n\nexport {\n ApiPlatformClientService,\n apiPlatformClientServiceName,\n} from './ApiPlatformClientService.js';\n\nexport type {\n ApiPlatformClientServiceOptions,\n ApiPlatformClientServiceActions,\n ApiPlatformClientServiceEvents,\n ApiPlatformClientServiceMessenger,\n} from './ApiPlatformClientService.js';\n\n// ============================================================================\n// OHLCV SERVICE\n// ============================================================================\n\nexport {\n OHLCVService,\n OHLCV_SERVICE_ALLOWED_ACTIONS,\n OHLCV_SERVICE_ALLOWED_EVENTS,\n} from './ws/ohlcv/index.js';\n\nexport type {\n OHLCVBar,\n OHLCVSubscriptionOptions,\n OHLCVSystemNotificationData,\n OHLCVServiceOptions,\n OHLCVServiceActions,\n OHLCVServiceAllowedActions,\n OHLCVServiceBarUpdatedEvent,\n OHLCVServiceChainStatusChangedEvent,\n OHLCVServiceSubscriptionErrorEvent,\n OHLCVServiceEvents,\n OHLCVServiceAllowedEvents,\n OHLCVServiceMessenger,\n} from './ws/ohlcv/index.js';\n\n// ============================================================================\n// API PLATFORM CLIENT\n// ============================================================================\n\nexport {\n ApiPlatformClient,\n createApiPlatformClient,\n // Individual API clients\n AccountsApiClient,\n PricesApiClient,\n TokenApiClient,\n TokensApiClient,\n // Constants\n API_URLS,\n STALE_TIMES,\n GC_TIMES,\n V6_DEFI_POSITION_TYPES,\n // Helpers\n calculateRetryDelay,\n getQueryOptionsOverrides,\n shouldRetry,\n // Errors\n HttpError,\n} from './api/index.js';\n\n// ============================================================================\n// API PLATFORM CLIENT TYPES\n// ============================================================================\n\nexport type {\n // Client options\n ApiPlatformClientOptions,\n ApiUrls,\n FetchOptions,\n // Shared types\n PageInfo,\n SupportedCurrency,\n MarketDataDetails,\n // Accounts API types\n V5BalanceItem,\n V5BalancesResponse,\n V2BalanceItem,\n V2BalancesResponse,\n V4BalancesResponse,\n V6VsCurrency,\n V6DeFiPositionType,\n V6BalanceMetadata,\n V6StellarTokenBalanceMetadata,\n V6TokenBalanceMetadata,\n V6BalanceItem,\n V6BalancesResponse,\n V1SupportedNetworksResponse,\n V2SupportedNetworksResponse,\n V2ActiveNetworksResponse,\n V1TransactionByHashResponse,\n V1AccountTransactionsResponse,\n V4MultiAccountTransactionsResponse,\n ValueTransfer,\n V1AccountRelationshipResult,\n NftItem,\n V2NftsResponse,\n TokenDiscoveryItem,\n V2TokensResponse,\n // Prices API types\n V3SpotPricesResponse,\n CoinGeckoSpotPrice,\n ExchangeRateInfo,\n V1ExchangeRatesResponse,\n PriceSupportedNetworksResponse,\n V1HistoricalPricesResponse,\n V3HistoricalPricesResponse,\n // Token API types\n TokenMetadata,\n V1TokenDescriptionResponse,\n NetworkInfo,\n TopAsset,\n TrendingSortBy,\n TrendingToken,\n TopGainersSortOption,\n TrendingSortOption,\n V1SuggestedOccurrenceFloorsResponse,\n // Tokens API types\n V1TokenSupportedNetworksResponse,\n V2TokenSupportedNetworksResponse,\n V3AssetResponse,\n} from './api/index.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { KeyringControllerUnlockEvent } from '@metamask/keyring-controller';
|
|
2
|
-
import type { Messenger } from '@metamask/messenger';
|
|
3
|
-
import type { AuthenticationController } from '@metamask/profile-sync-controller';
|
|
4
|
-
import type { BackendWebSocketServiceMethodActions } from './BackendWebSocketService-method-action-types.js';
|
|
5
|
-
import type { BackendWebSocketServiceConnectionStateChangedEvent } from './BackendWebSocketService.js';
|
|
6
|
-
import { WebSocketState } from './BackendWebSocketService.js';
|
|
7
|
-
declare const SERVICE_NAME = "RampsActivityService";
|
|
8
|
-
export type RampsActivityEntity = {
|
|
9
|
-
id: string;
|
|
10
|
-
kind?: string;
|
|
11
|
-
status?: string;
|
|
12
|
-
transactionStatus?: string;
|
|
13
|
-
transactionHash?: string;
|
|
14
|
-
};
|
|
15
|
-
export type RampsActivityEvent = {
|
|
16
|
-
eventId: string;
|
|
17
|
-
type: string;
|
|
18
|
-
category: string;
|
|
19
|
-
occurredAt: string;
|
|
20
|
-
entity: RampsActivityEntity | null;
|
|
21
|
-
needsFetch: boolean;
|
|
22
|
-
};
|
|
23
|
-
export type RampsActivityServiceOptions = {
|
|
24
|
-
messenger: RampsActivityServiceMessenger;
|
|
25
|
-
};
|
|
26
|
-
export type RampsActivityServiceActions = never;
|
|
27
|
-
export declare const RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS: readonly ['AuthenticationController:getSessionProfile', 'BackendWebSocketService:connect', 'BackendWebSocketService:subscribe', 'BackendWebSocketService:getConnectionInfo', 'BackendWebSocketService:channelHasSubscription', 'BackendWebSocketService:findSubscriptionsByChannelPrefix'];
|
|
28
|
-
export declare const RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS: readonly ['AuthenticationController:stateChange', 'AuthenticationController:profileSignIn', 'BackendWebSocketService:connectionStateChanged', 'KeyringController:unlock'];
|
|
29
|
-
export type RampsActivityServiceAllowedActions = AuthenticationController.AuthenticationControllerGetSessionProfileAction | BackendWebSocketServiceMethodActions;
|
|
30
|
-
export type RampsActivityServiceEventReceivedEvent = {
|
|
31
|
-
type: 'RampsActivityService:eventReceived';
|
|
32
|
-
payload: [RampsActivityEvent];
|
|
33
|
-
};
|
|
34
|
-
export type RampsActivityServiceStatusChangedEvent = {
|
|
35
|
-
type: 'RampsActivityService:statusChanged';
|
|
36
|
-
payload: [{
|
|
37
|
-
status: WebSocketState;
|
|
38
|
-
}];
|
|
39
|
-
};
|
|
40
|
-
export type RampsActivityServiceEvents = RampsActivityServiceEventReceivedEvent | RampsActivityServiceStatusChangedEvent;
|
|
41
|
-
export type RampsActivityServiceAllowedEvents = AuthenticationController.AuthenticationControllerStateChangeEvent | AuthenticationController.AuthenticationControllerProfileSignInEvent | BackendWebSocketServiceConnectionStateChangedEvent | KeyringControllerUnlockEvent;
|
|
42
|
-
export type RampsActivityServiceMessenger = Messenger<typeof SERVICE_NAME, RampsActivityServiceActions | RampsActivityServiceAllowedActions, RampsActivityServiceEvents | RampsActivityServiceAllowedEvents>;
|
|
43
|
-
/**
|
|
44
|
-
* Subscribes to profile-scoped ramps activity through
|
|
45
|
-
* {@link BackendWebSocketService}. The service owns no domain state; it only
|
|
46
|
-
* tracks its subscription lifecycle and publishes validated notifications.
|
|
47
|
-
*/
|
|
48
|
-
export declare class RampsActivityService {
|
|
49
|
-
#private;
|
|
50
|
-
readonly name = "RampsActivityService";
|
|
51
|
-
constructor({ messenger }: RampsActivityServiceOptions);
|
|
52
|
-
/**
|
|
53
|
-
* Connect and subscribe for the current authentication profile.
|
|
54
|
-
*/
|
|
55
|
-
init(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Stop future subscriptions and remove all active ramps subscriptions.
|
|
58
|
-
*/
|
|
59
|
-
destroy(): Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
export {};
|
|
62
|
-
//# sourceMappingURL=RampsActivityService.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RampsActivityService.d.ts","sourceRoot":"","sources":["../../src/ws/RampsActivityService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAGlF,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,kDAAkD,CAAC;AAC7G,OAAO,KAAK,EACV,kDAAkD,EAGnD,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,QAAA,MAAM,YAAY,yBAAyB,CAAC;AAM5C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;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AM7B,YAAY,EAAE,SAAS,EAAE,EAAE,2BAA2B,EAiCrD;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;IAwHD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAG7B;CACF"}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { projectLogger, createModuleLogger } from '../logger.js';
|
|
2
|
-
import { WebSocketState } from './BackendWebSocketService.js';
|
|
3
|
-
const SERVICE_NAME = 'RampsActivityService';
|
|
4
|
-
const SUBSCRIPTION_NAMESPACE = 'ramps-activity.v1';
|
|
5
|
-
const MESSENGER_EXPOSED_METHODS = [];
|
|
6
|
-
const log = createModuleLogger(projectLogger, SERVICE_NAME);
|
|
7
|
-
export const RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS = [
|
|
8
|
-
'AuthenticationController:getSessionProfile',
|
|
9
|
-
'BackendWebSocketService:connect',
|
|
10
|
-
'BackendWebSocketService:subscribe',
|
|
11
|
-
'BackendWebSocketService:getConnectionInfo',
|
|
12
|
-
'BackendWebSocketService:channelHasSubscription',
|
|
13
|
-
'BackendWebSocketService:findSubscriptionsByChannelPrefix',
|
|
14
|
-
];
|
|
15
|
-
export const RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS = [
|
|
16
|
-
'AuthenticationController:stateChange',
|
|
17
|
-
'AuthenticationController:profileSignIn',
|
|
18
|
-
'BackendWebSocketService:connectionStateChanged',
|
|
19
|
-
'KeyringController:unlock',
|
|
20
|
-
];
|
|
21
|
-
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
22
|
-
const getHasOwnProperty = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
23
|
-
const getOptionalString = (value, key) => {
|
|
24
|
-
const property = value[key];
|
|
25
|
-
if (property === undefined) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
return typeof property === 'string' ? property : false;
|
|
29
|
-
};
|
|
30
|
-
const parseEntity = (value) => {
|
|
31
|
-
if (value === null) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
if (!isRecord(value) || typeof value.id !== 'string') {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const kind = getOptionalString(value, 'kind');
|
|
38
|
-
const status = getOptionalString(value, 'status');
|
|
39
|
-
const transactionStatus = getOptionalString(value, 'transactionStatus');
|
|
40
|
-
const transactionHash = getOptionalString(value, 'transactionHash');
|
|
41
|
-
if (kind === false ||
|
|
42
|
-
status === false ||
|
|
43
|
-
transactionStatus === false ||
|
|
44
|
-
transactionHash === false) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
id: value.id,
|
|
49
|
-
...(kind === undefined ? {} : { kind }),
|
|
50
|
-
...(status === undefined ? {} : { status }),
|
|
51
|
-
...(transactionStatus === undefined ? {} : { transactionStatus }),
|
|
52
|
-
...(transactionHash === undefined ? {} : { transactionHash }),
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
const parseRampsActivityEvent = (value) => {
|
|
56
|
-
if (!isRecord(value) ||
|
|
57
|
-
typeof value.eventId !== 'string' ||
|
|
58
|
-
typeof value.type !== 'string' ||
|
|
59
|
-
typeof value.category !== 'string' ||
|
|
60
|
-
value.category.length === 0 ||
|
|
61
|
-
typeof value.occurredAt !== 'string' ||
|
|
62
|
-
typeof value.needsFetch !== 'boolean' ||
|
|
63
|
-
getHasOwnProperty(value, 'payload') ||
|
|
64
|
-
getHasOwnProperty(value, 'customerId') ||
|
|
65
|
-
getHasOwnProperty(value, 'userId')) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
const entity = parseEntity(value.entity);
|
|
69
|
-
if (entity === false) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
eventId: value.eventId,
|
|
74
|
-
type: value.type,
|
|
75
|
-
category: value.category,
|
|
76
|
-
occurredAt: value.occurredAt,
|
|
77
|
-
entity,
|
|
78
|
-
needsFetch: value.needsFetch,
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Subscribes to profile-scoped ramps activity through
|
|
83
|
-
* {@link BackendWebSocketService}. The service owns no domain state; it only
|
|
84
|
-
* tracks its subscription lifecycle and publishes validated notifications.
|
|
85
|
-
*/
|
|
86
|
-
export class RampsActivityService {
|
|
87
|
-
name = SERVICE_NAME;
|
|
88
|
-
#messenger;
|
|
89
|
-
#isDestroyed = false;
|
|
90
|
-
constructor({ messenger }) {
|
|
91
|
-
this.#messenger = messenger;
|
|
92
|
-
this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
93
|
-
this.#messenger.subscribe('BackendWebSocketService:connectionStateChanged',
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
95
|
-
async (connectionInfo) => await this.#handleConnectionStateChange(connectionInfo));
|
|
96
|
-
this.#messenger.subscribe('AuthenticationController:stateChange',
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
98
|
-
async (isSignedIn) => await this.#handleAuthenticationStateChange(isSignedIn),
|
|
99
|
-
// Messenger compares selector results with `!==`. Return the boolean
|
|
100
|
-
// primitive so token/session writes do not resubscribe.
|
|
101
|
-
(state) => state.isSignedIn);
|
|
102
|
-
this.#messenger.subscribe('AuthenticationController:profileSignIn',
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
104
|
-
async () => await this.#replaceSubscription());
|
|
105
|
-
this.#messenger.subscribe('KeyringController:unlock',
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
107
|
-
async () => await this.#replaceSubscription());
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Connect and subscribe for the current authentication profile.
|
|
111
|
-
*/
|
|
112
|
-
async init() {
|
|
113
|
-
await this.#replaceSubscription();
|
|
114
|
-
}
|
|
115
|
-
async #handleConnectionStateChange(connectionInfo) {
|
|
116
|
-
if (this.#isDestroyed) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
this.#messenger.publish('RampsActivityService:statusChanged', {
|
|
120
|
-
status: connectionInfo.state,
|
|
121
|
-
});
|
|
122
|
-
if (connectionInfo.state === WebSocketState.CONNECTED) {
|
|
123
|
-
await this.#subscribeToCurrentProfile();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async #handleAuthenticationStateChange(isSignedIn) {
|
|
127
|
-
if (isSignedIn) {
|
|
128
|
-
await this.#replaceSubscription();
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
await this.#unsubscribeAll();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async #replaceSubscription() {
|
|
135
|
-
if (this.#isDestroyed) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
await this.#unsubscribeAll();
|
|
139
|
-
await this.#subscribeToCurrentProfile();
|
|
140
|
-
}
|
|
141
|
-
async #subscribeToCurrentProfile() {
|
|
142
|
-
if (this.#isDestroyed) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
await this.#messenger.call('BackendWebSocketService:connect');
|
|
147
|
-
const profile = await this.#messenger.call('AuthenticationController:getSessionProfile');
|
|
148
|
-
const profileId = this.#getChannelProfileId(profile);
|
|
149
|
-
if (!profileId || this.#isDestroyed) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const channel = `${SUBSCRIPTION_NAMESPACE}.${profileId}`;
|
|
153
|
-
const connectionInfo = this.#messenger.call('BackendWebSocketService:getConnectionInfo');
|
|
154
|
-
if (connectionInfo.state !== WebSocketState.CONNECTED) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (this.#messenger.call('BackendWebSocketService:channelHasSubscription', channel)) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (this.#isDestroyed) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
await this.#messenger.call('BackendWebSocketService:subscribe', {
|
|
164
|
-
channels: [channel],
|
|
165
|
-
channelType: SUBSCRIPTION_NAMESPACE,
|
|
166
|
-
callback: (notification) => this.#handleNotification(notification),
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
log('Unable to subscribe to ramps activity', { error });
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
#getChannelProfileId(profile) {
|
|
174
|
-
const canonical = profile.canonicalProfileId;
|
|
175
|
-
if (typeof canonical === 'string' && canonical.length > 0) {
|
|
176
|
-
return canonical;
|
|
177
|
-
}
|
|
178
|
-
const { profileId } = profile;
|
|
179
|
-
return typeof profileId === 'string' && profileId.length > 0
|
|
180
|
-
? profileId
|
|
181
|
-
: undefined;
|
|
182
|
-
}
|
|
183
|
-
#handleNotification(notification) {
|
|
184
|
-
const event = parseRampsActivityEvent(notification.data);
|
|
185
|
-
if (!event) {
|
|
186
|
-
log('Ignoring malformed ramps activity event', {
|
|
187
|
-
channel: notification.channel,
|
|
188
|
-
});
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
this.#messenger.publish('RampsActivityService:eventReceived', event);
|
|
192
|
-
}
|
|
193
|
-
async #unsubscribeAll() {
|
|
194
|
-
const subscriptions = this.#messenger.call('BackendWebSocketService:findSubscriptionsByChannelPrefix', SUBSCRIPTION_NAMESPACE);
|
|
195
|
-
for (const subscription of subscriptions) {
|
|
196
|
-
await subscription.unsubscribe();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Stop future subscriptions and remove all active ramps subscriptions.
|
|
201
|
-
*/
|
|
202
|
-
async destroy() {
|
|
203
|
-
this.#isDestroyed = true;
|
|
204
|
-
await this.#unsubscribeAll();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
//# sourceMappingURL=RampsActivityService.js.map
|
|
@@ -1 +0,0 @@
|
|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;QACzB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import type { KeyringControllerUnlockEvent } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport type { BackendWebSocketServiceMethodActions } from './BackendWebSocketService-method-action-types.js';\nimport type {\n BackendWebSocketServiceConnectionStateChangedEvent,\n ServerNotificationMessage,\n WebSocketConnectionInfo,\n} from './BackendWebSocketService.js';\nimport { WebSocketState } from './BackendWebSocketService.js';\n\nconst SERVICE_NAME = 'RampsActivityService';\nconst SUBSCRIPTION_NAMESPACE = 'ramps-activity.v1';\nconst MESSENGER_EXPOSED_METHODS = [] as const;\n\nconst log = createModuleLogger(projectLogger, SERVICE_NAME);\n\nexport type RampsActivityEntity = {\n id: string;\n kind?: string;\n status?: string;\n transactionStatus?: string;\n transactionHash?: string;\n};\n\nexport type RampsActivityEvent = {\n eventId: string;\n type: string;\n category: string;\n occurredAt: string;\n entity: RampsActivityEntity | null;\n needsFetch: boolean;\n};\n\nexport type RampsActivityServiceOptions = {\n messenger: RampsActivityServiceMessenger;\n};\n\nexport type RampsActivityServiceActions = never;\n\nexport const RAMPS_ACTIVITY_SERVICE_ALLOWED_ACTIONS = [\n 'AuthenticationController:getSessionProfile',\n 'BackendWebSocketService:connect',\n 'BackendWebSocketService:subscribe',\n 'BackendWebSocketService:getConnectionInfo',\n 'BackendWebSocketService:channelHasSubscription',\n 'BackendWebSocketService:findSubscriptionsByChannelPrefix',\n] as const;\n\nexport const RAMPS_ACTIVITY_SERVICE_ALLOWED_EVENTS = [\n 'AuthenticationController:stateChange',\n 'AuthenticationController:profileSignIn',\n 'BackendWebSocketService:connectionStateChanged',\n 'KeyringController:unlock',\n] as const;\n\nexport type RampsActivityServiceAllowedActions =\n | AuthenticationController.AuthenticationControllerGetSessionProfileAction\n | BackendWebSocketServiceMethodActions;\n\nexport type RampsActivityServiceEventReceivedEvent = {\n type: 'RampsActivityService:eventReceived';\n payload: [RampsActivityEvent];\n};\n\nexport type RampsActivityServiceStatusChangedEvent = {\n type: 'RampsActivityService:statusChanged';\n payload: [{ status: WebSocketState }];\n};\n\nexport type RampsActivityServiceEvents =\n | RampsActivityServiceEventReceivedEvent\n | RampsActivityServiceStatusChangedEvent;\n\nexport type RampsActivityServiceAllowedEvents =\n | AuthenticationController.AuthenticationControllerStateChangeEvent\n | AuthenticationController.AuthenticationControllerProfileSignInEvent\n | BackendWebSocketServiceConnectionStateChangedEvent\n | KeyringControllerUnlockEvent;\n\nexport type RampsActivityServiceMessenger = Messenger<\n typeof SERVICE_NAME,\n RampsActivityServiceActions | RampsActivityServiceAllowedActions,\n RampsActivityServiceEvents | RampsActivityServiceAllowedEvents\n>;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst getHasOwnProperty = (\n value: Record<string, unknown>,\n key: string,\n): boolean => Object.prototype.hasOwnProperty.call(value, key);\n\nconst getOptionalString = (\n value: Record<string, unknown>,\n key: string,\n): string | undefined | false => {\n const property = value[key];\n if (property === undefined) {\n return undefined;\n }\n return typeof property === 'string' ? property : false;\n};\n\nconst parseEntity = (value: unknown): RampsActivityEntity | null | false => {\n if (value === null) {\n return null;\n }\n if (!isRecord(value) || typeof value.id !== 'string') {\n return false;\n }\n\n const kind = getOptionalString(value, 'kind');\n const status = getOptionalString(value, 'status');\n const transactionStatus = getOptionalString(value, 'transactionStatus');\n const transactionHash = getOptionalString(value, 'transactionHash');\n if (\n kind === false ||\n status === false ||\n transactionStatus === false ||\n transactionHash === false\n ) {\n return false;\n }\n\n return {\n id: value.id,\n ...(kind === undefined ? {} : { kind }),\n ...(status === undefined ? {} : { status }),\n ...(transactionStatus === undefined ? {} : { transactionStatus }),\n ...(transactionHash === undefined ? {} : { transactionHash }),\n };\n};\n\nconst parseRampsActivityEvent = (\n value: unknown,\n): RampsActivityEvent | undefined => {\n if (\n !isRecord(value) ||\n typeof value.eventId !== 'string' ||\n typeof value.type !== 'string' ||\n typeof value.category !== 'string' ||\n value.category.length === 0 ||\n typeof value.occurredAt !== 'string' ||\n typeof value.needsFetch !== 'boolean' ||\n getHasOwnProperty(value, 'payload') ||\n getHasOwnProperty(value, 'customerId') ||\n getHasOwnProperty(value, 'userId')\n ) {\n return undefined;\n }\n\n const entity = parseEntity(value.entity);\n if (entity === false) {\n return undefined;\n }\n\n return {\n eventId: value.eventId,\n type: value.type,\n category: value.category,\n occurredAt: value.occurredAt,\n entity,\n needsFetch: value.needsFetch,\n };\n};\n\n/**\n * Subscribes to profile-scoped ramps activity through\n * {@link BackendWebSocketService}. The service owns no domain state; it only\n * tracks its subscription lifecycle and publishes validated notifications.\n */\nexport class RampsActivityService {\n readonly name = SERVICE_NAME;\n\n readonly #messenger: RampsActivityServiceMessenger;\n\n #isDestroyed = false;\n\n constructor({ messenger }: RampsActivityServiceOptions) {\n this.#messenger = messenger;\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (connectionInfo: WebSocketConnectionInfo) =>\n await this.#handleConnectionStateChange(connectionInfo),\n );\n this.#messenger.subscribe(\n 'AuthenticationController:stateChange',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (isSignedIn: boolean) =>\n await this.#handleAuthenticationStateChange(isSignedIn),\n // Messenger compares selector results with `!==`. Return the boolean\n // primitive so token/session writes do not resubscribe.\n (state: AuthenticationController.AuthenticationControllerState) =>\n state.isSignedIn,\n );\n this.#messenger.subscribe(\n 'AuthenticationController:profileSignIn',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => await this.#replaceSubscription(),\n );\n this.#messenger.subscribe(\n 'KeyringController:unlock',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => await this.#replaceSubscription(),\n );\n }\n\n /**\n * Connect and subscribe for the current authentication profile.\n */\n async init(): Promise<void> {\n await this.#replaceSubscription();\n }\n\n async #handleConnectionStateChange(\n connectionInfo: WebSocketConnectionInfo,\n ): Promise<void> {\n if (this.#isDestroyed) {\n return;\n }\n\n this.#messenger.publish('RampsActivityService:statusChanged', {\n status: connectionInfo.state,\n });\n\n if (connectionInfo.state === WebSocketState.CONNECTED) {\n await this.#subscribeToCurrentProfile();\n }\n }\n\n async #handleAuthenticationStateChange(isSignedIn: boolean): Promise<void> {\n if (isSignedIn) {\n await this.#replaceSubscription();\n } else {\n await this.#unsubscribeAll();\n }\n }\n\n async #replaceSubscription(): Promise<void> {\n if (this.#isDestroyed) {\n return;\n }\n\n await this.#unsubscribeAll();\n await this.#subscribeToCurrentProfile();\n }\n\n async #subscribeToCurrentProfile(): Promise<void> {\n if (this.#isDestroyed) {\n return;\n }\n\n try {\n await this.#messenger.call('BackendWebSocketService:connect');\n const profile = await this.#messenger.call(\n 'AuthenticationController:getSessionProfile',\n );\n const profileId = this.#getChannelProfileId(profile);\n if (!profileId || this.#isDestroyed) {\n return;\n }\n\n const channel = `${SUBSCRIPTION_NAMESPACE}.${profileId}`;\n const connectionInfo = this.#messenger.call(\n 'BackendWebSocketService:getConnectionInfo',\n );\n if (connectionInfo.state !== WebSocketState.CONNECTED) {\n return;\n }\n\n if (\n this.#messenger.call(\n 'BackendWebSocketService:channelHasSubscription',\n channel,\n )\n ) {\n return;\n }\n\n if (this.#isDestroyed) {\n return;\n }\n\n await this.#messenger.call('BackendWebSocketService:subscribe', {\n channels: [channel],\n channelType: SUBSCRIPTION_NAMESPACE,\n callback: (notification: ServerNotificationMessage) =>\n this.#handleNotification(notification),\n });\n } catch (error) {\n log('Unable to subscribe to ramps activity', { error });\n }\n }\n\n #getChannelProfileId(profile: {\n canonicalProfileId?: string;\n profileId?: string;\n }): string | undefined {\n const canonical = profile.canonicalProfileId;\n if (typeof canonical === 'string' && canonical.length > 0) {\n return canonical;\n }\n\n const { profileId } = profile;\n return typeof profileId === 'string' && profileId.length > 0\n ? profileId\n : undefined;\n }\n\n #handleNotification(notification: ServerNotificationMessage): void {\n const event = parseRampsActivityEvent(notification.data);\n if (!event) {\n log('Ignoring malformed ramps activity event', {\n channel: notification.channel,\n });\n return;\n }\n\n this.#messenger.publish('RampsActivityService:eventReceived', event);\n }\n\n async #unsubscribeAll(): Promise<void> {\n const subscriptions = this.#messenger.call(\n 'BackendWebSocketService:findSubscriptionsByChannelPrefix',\n SUBSCRIPTION_NAMESPACE,\n );\n\n for (const subscription of subscriptions) {\n await subscription.unsubscribe();\n }\n }\n\n /**\n * Stop future subscriptions and remove all active ramps subscriptions.\n */\n async destroy(): Promise<void> {\n this.#isDestroyed = true;\n await this.#unsubscribeAll();\n }\n}\n"]}
|