@metamask-previews/social-controllers 3.22.0-preview-e1d02b2 → 3.22.0-preview-20f24a578
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 +7 -0
- package/dist/SocialRealtimeService.d.ts.map +1 -1
- package/dist/SocialRealtimeService.js +6 -18
- package/dist/SocialRealtimeService.js.map +1 -1
- package/dist/SocialService.d.ts.map +1 -1
- package/dist/SocialService.js +23 -114
- package/dist/SocialService.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/realtime-feed-item.d.ts +2 -2
- package/dist/realtime-feed-item.d.ts.map +1 -1
- package/dist/realtime-feed-item.js +62 -150
- package/dist/realtime-feed-item.js.map +1 -1
- package/dist/social-constants.d.ts +0 -25
- package/dist/social-constants.d.ts.map +1 -1
- package/dist/social-constants.js +0 -25
- package/dist/social-constants.js.map +1 -1
- package/dist/social-types.d.ts +24 -292
- package/dist/social-types.d.ts.map +1 -1
- package/dist/social-types.js +0 -74
- package/dist/social-types.js.map +1 -1
- package/package.json +3 -5
- package/dist/structs.d.ts +0 -2112
- package/dist/structs.d.ts.map +0 -1
- package/dist/structs.js +0 -284
- package/dist/structs.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,9 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Remove all runtime validation of data received from the Social backend over HTTP (`SocialService`) and WebSocket (`SocialRealtimeService`) ([#11667](https://github.com/MetaMask/core/pull/11667))
|
|
13
|
+
- `SocialService` methods now return parsed JSON responses directly without schema validation or item filtering.
|
|
14
|
+
- `SocialRealtimeService` and `parseRealtimeFeedItem` no longer validate WebSocket event envelopes or payloads; raw hydrated positions are still normalized into `FeedItem`.
|
|
12
15
|
- Bump `@metamask/profile-sync-controller` from `^36.1.1` to `^36.1.2` ([#11474](https://github.com/MetaMask/core/pull/11474))
|
|
13
16
|
- Bump `@metamask/utils` from `^12.0.1` to `^12.0.2` ([#11474](https://github.com/MetaMask/core/pull/11474))
|
|
14
17
|
|
|
18
|
+
### Removed
|
|
19
|
+
|
|
20
|
+
- **BREAKING:** Remove `TradeStruct` export, internal superstruct schemas, `*_INVALID_RESPONSE` constants from `SocialServiceErrorMessage`, and the `@metamask/superstruct` dependency ([#11667](https://github.com/MetaMask/core/pull/11667))
|
|
21
|
+
|
|
15
22
|
## [3.22.0]
|
|
16
23
|
|
|
17
24
|
### Added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialRealtimeService.d.ts","sourceRoot":"","sources":["../src/SocialRealtimeService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gCAAgC,EAGjC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,eAAO,MAAM,oBAAoB;aAC/B,GAAG,EAAE,oBAAoB;aACzB,QAAQ,EAAE,yBAAyB;CAC3B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAExE,eAAO,MAAM,wBAAwB,EAAG,WAAoB,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,qBAAqB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,CACpC,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE,uBAAuB,KAC3B,IAAI,CAAC;AACV,MAAM,MAAM,2BAA2B,GAAG,MAAM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,EAAG,uBAAuB,CAAU;IA4BjD,YAAY,EACV,SAAS,EACT,MAAM,EACN,SAA+B,GAChC,EAAE,4BAA4B,EA6B9B;IAED,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI,CAGzD;IAED,oBAAoB,CAAC,QAAQ,EAAE,2BAA2B,GAAG,MAAM,IAAI,CAGtE;IAEK,SAAS,CAAC,MAAM,EAAE,SAAS,uBAAuB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBzE;IAgCK,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAU9C;CA8JF"}
|
|
@@ -5,7 +5,6 @@ export const SOCIAL_FEED_CHANNELS = {
|
|
|
5
5
|
trending: 'social.v1.feed.trending',
|
|
6
6
|
};
|
|
7
7
|
export const SOCIAL_FEED_CHANNEL_TYPE = 'social.v1';
|
|
8
|
-
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
9
8
|
const normalizeScopes = (scopes) => {
|
|
10
9
|
const normalized = [...new Set(scopes)];
|
|
11
10
|
if (normalized.length === 0) {
|
|
@@ -16,26 +15,15 @@ const normalizeScopes = (scopes) => {
|
|
|
16
15
|
const haveSameScopes = (left, right) => left.length === right.length && left.every((scope) => right.includes(scope));
|
|
17
16
|
const scopeForChannel = (channel) => Object.entries(SOCIAL_FEED_CHANNELS).find(([, value]) => value === channel)?.[0] ?? undefined;
|
|
18
17
|
const parseSocialFeedEvent = (data) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
data.kind !== 'feed-item' ||
|
|
25
|
-
typeof data.eventId !== 'string' ||
|
|
26
|
-
typeof data.feedItemId !== 'string' ||
|
|
27
|
-
typeof data.revision !== 'number' ||
|
|
28
|
-
typeof data.occurredAt !== 'string' ||
|
|
29
|
-
feedItem === undefined) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
return { ...data, data: feedItem };
|
|
18
|
+
const event = data;
|
|
19
|
+
return {
|
|
20
|
+
...event,
|
|
21
|
+
data: parseRealtimeFeedItem(event.data),
|
|
22
|
+
};
|
|
33
23
|
};
|
|
34
24
|
const parseSocialFeedEvents = (data) => {
|
|
35
25
|
const entries = Array.isArray(data) ? data : [data];
|
|
36
|
-
return entries
|
|
37
|
-
.map((entry) => parseSocialFeedEvent(entry))
|
|
38
|
-
.filter((event) => event !== undefined);
|
|
26
|
+
return entries.map((entry) => parseSocialFeedEvent(entry));
|
|
39
27
|
};
|
|
40
28
|
/**
|
|
41
29
|
* Social realtime subscription service built on the shared backend WebSocket.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialRealtimeService.js","sourceRoot":"","sources":["../src/SocialRealtimeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAOxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,GAAG,EAAE,oBAAoB;IACzB,QAAQ,EAAE,yBAAyB;CAC3B,CAAC;AAIX,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAoB,CAAC;AAwB7D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AAE9C,MAAM,eAAe,GAAG,CACtB,MAA0C,EACf,EAAE;IAC7B,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,IAAwC,EACxC,KAAyC,EAChC,EAAE,CACX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AAC,WAAW,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,4BAA4B;QAChC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;YACxD,IAAI,CAAC;gBACH,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC;gBACjC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACpD,CAAC;YAAC,MAAM,CAAC;gBACP,4DAA4D;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,YAAuC;QACzD,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,qBAAqB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebSocketState } from '@metamask/core-backend';\nimport type {\n BackendWebSocketServiceMessenger,\n ServerNotificationMessage,\n WebSocketSubscription,\n} from '@metamask/core-backend';\n\nimport { parseRealtimeFeedItem } from './realtime-feed-item.js';\nimport type { RealtimeFeedEventData } from './realtime-feed-item.js';\n\nexport const SOCIAL_FEED_CHANNELS = {\n all: 'social.v1.feed.all',\n trending: 'social.v1.feed.trending',\n} as const;\n\nexport type SocialFeedRealtimeScope = keyof typeof SOCIAL_FEED_CHANNELS;\n\nexport const SOCIAL_FEED_CHANNEL_TYPE = 'social.v1' as const;\n\nexport type SocialFeedEvent = {\n version: 1;\n kind: 'feed-item';\n eventId: string;\n feedItemId: string;\n revision: number;\n occurredAt: string;\n data: RealtimeFeedEventData;\n};\n\nexport type SocialFeedEventListener = (\n event: SocialFeedEvent,\n scope: SocialFeedRealtimeScope,\n) => void;\nexport type SocialFeedReconnectListener = () => void;\n\nexport type SocialRealtimeServiceOptions = {\n messenger: BackendWebSocketServiceMessenger;\n scopes: readonly SocialFeedRealtimeScope[];\n isEnabled?: () => boolean;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null;\n\nconst normalizeScopes = (\n scopes: readonly SocialFeedRealtimeScope[],\n): SocialFeedRealtimeScope[] => {\n const normalized = [...new Set(scopes)];\n if (normalized.length === 0) {\n throw new Error('At least one Social feed scope is required');\n }\n return normalized;\n};\n\nconst haveSameScopes = (\n left: readonly SocialFeedRealtimeScope[],\n right: readonly SocialFeedRealtimeScope[],\n): boolean =>\n left.length === right.length && left.every((scope) => right.includes(scope));\n\nconst scopeForChannel = (\n channel: string,\n): SocialFeedRealtimeScope | undefined =>\n (Object.entries(SOCIAL_FEED_CHANNELS).find(\n ([, value]) => value === channel,\n )?.[0] as SocialFeedRealtimeScope | undefined) ?? undefined;\n\nconst parseSocialFeedEvent = (data: unknown): SocialFeedEvent | undefined => {\n if (!isRecord(data)) {\n return undefined;\n }\n\n const feedItem = parseRealtimeFeedItem(data.data);\n if (\n data.version !== 1 ||\n data.kind !== 'feed-item' ||\n typeof data.eventId !== 'string' ||\n typeof data.feedItemId !== 'string' ||\n typeof data.revision !== 'number' ||\n typeof data.occurredAt !== 'string' ||\n feedItem === undefined\n ) {\n return undefined;\n }\n\n return { ...data, data: feedItem } as unknown as SocialFeedEvent;\n};\n\nconst parseSocialFeedEvents = (data: unknown): SocialFeedEvent[] => {\n const entries = Array.isArray(data) ? data : [data];\n\n return entries\n .map((entry) => parseSocialFeedEvent(entry))\n .filter((event): event is SocialFeedEvent => event !== undefined);\n};\n\n/**\n * Social realtime subscription service built on the shared backend WebSocket.\n *\n * Clients explicitly select one or more global feed scopes. Additional Social\n * channels can be added here without creating another WebSocket connection.\n */\nexport class SocialRealtimeService {\n readonly name = 'SocialRealtimeService' as const;\n\n readonly #messenger: BackendWebSocketServiceMessenger;\n\n readonly #listeners = new Set<SocialFeedEventListener>();\n\n readonly #reconnectListeners = new Set<SocialFeedReconnectListener>();\n\n readonly #isEnabled: () => boolean;\n\n #scopes: SocialFeedRealtimeScope[];\n\n #scopeUpdatePromise: Promise<void> | undefined;\n\n #active = false;\n\n #subscription: WebSocketSubscription | undefined;\n\n #subscriptionToken: symbol | undefined;\n\n #subscriptionPromise: Promise<void> | undefined;\n\n readonly #pendingUnsubscriptions = new Set<WebSocketSubscription>();\n\n #connectionVersion = 0;\n\n #wasDisconnected = false;\n\n constructor({\n messenger,\n scopes,\n isEnabled = (): boolean => true,\n }: SocialRealtimeServiceOptions) {\n this.#messenger = messenger;\n this.#scopes = normalizeScopes(scopes);\n this.#isEnabled = isEnabled;\n\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n ({ state }: { state: WebSocketState }): void => {\n if (state === WebSocketState.DISCONNECTED) {\n this.#connectionVersion += 1;\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n this.#wasDisconnected = true;\n }\n\n if (state === WebSocketState.CONNECTED && this.#active) {\n const isReconnect = this.#wasDisconnected;\n this.#wasDisconnected = false;\n // eslint-disable-next-line no-void\n void this.#subscribeToFeed()\n .then(() => {\n if (isReconnect) {\n this.#reconnectListeners.forEach((listener) => listener());\n }\n })\n .catch(() => undefined);\n }\n },\n );\n }\n\n addListener(listener: SocialFeedEventListener): () => void {\n this.#listeners.add(listener);\n return () => this.#listeners.delete(listener);\n }\n\n addReconnectListener(listener: SocialFeedReconnectListener): () => void {\n this.#reconnectListeners.add(listener);\n return () => this.#reconnectListeners.delete(listener);\n }\n\n async setScopes(scopes: readonly SocialFeedRealtimeScope[]): Promise<void> {\n const normalizedScopes = normalizeScopes(scopes);\n\n const scopeUpdate = this.#scopeUpdatePromise\n ? this.#scopeUpdatePromise\n .catch(() => undefined)\n .then(() => this.#applyScopes(normalizedScopes))\n : this.#applyScopes(normalizedScopes);\n this.#scopeUpdatePromise = scopeUpdate;\n\n try {\n await scopeUpdate;\n } finally {\n if (this.#scopeUpdatePromise === scopeUpdate) {\n this.#scopeUpdatePromise = Promise.resolve();\n }\n }\n }\n\n async #applyScopes(\n normalizedScopes: SocialFeedRealtimeScope[],\n ): Promise<void> {\n if (!this.#active) {\n this.#scopes = normalizedScopes;\n return;\n }\n\n if (this.#subscription && haveSameScopes(this.#scopes, normalizedScopes)) {\n return;\n }\n\n const previousScopes = this.#scopes;\n const connectionVersion = this.#connectionVersion;\n this.#scopes = normalizedScopes;\n\n try {\n await this.#resubscribeToFeed();\n } catch (error) {\n if (\n this.#active &&\n this.#connectionVersion === connectionVersion &&\n this.#subscription\n ) {\n this.#scopes = previousScopes;\n }\n throw error;\n }\n }\n\n async setActive(active: boolean): Promise<void> {\n this.#active = active && this.#isEnabled();\n\n if (!this.#active) {\n await this.#unsubscribeFromFeed();\n return;\n }\n\n await this.#retryPendingUnsubscriptions();\n await this.#subscribeToFeed();\n }\n\n async #subscribeToFeed(): Promise<void> {\n if (!this.#active || this.#subscription) {\n return;\n }\n\n while (this.#subscriptionPromise) {\n await this.#subscriptionPromise;\n\n if (!this.#active || this.#subscription) {\n return;\n }\n }\n\n const subscriptionPromise = Promise.resolve().then(\n async (): Promise<void> => {\n await this.#messenger.call('BackendWebSocketService:connect');\n\n const subscriptionToken = Symbol('social-feed-subscription');\n\n // Each service needs its own callback and subscription lifecycle.\n const subscription = await this.#messenger.call(\n 'BackendWebSocketService:subscribe',\n {\n channels: this.#scopes.map((scope) => SOCIAL_FEED_CHANNELS[scope]),\n channelType: SOCIAL_FEED_CHANNEL_TYPE,\n callback: (notification: ServerNotificationMessage) => {\n if (this.#subscriptionToken !== subscriptionToken) {\n return;\n }\n this.#handleNotification(notification);\n },\n },\n );\n\n if (!this.#active) {\n await subscription.unsubscribe();\n return;\n }\n\n this.#subscription = subscription;\n this.#subscriptionToken = subscriptionToken;\n },\n );\n this.#subscriptionPromise = subscriptionPromise;\n\n try {\n await subscriptionPromise;\n } finally {\n this.#subscriptionPromise = undefined;\n }\n }\n\n async #resubscribeToFeed(): Promise<void> {\n while (this.#subscriptionPromise) {\n await this.#subscriptionPromise;\n }\n\n await this.#retryPendingUnsubscriptions();\n\n const existingSubscription = this.#subscription;\n const existingSubscriptionToken = this.#subscriptionToken;\n const connectionVersion = this.#connectionVersion;\n this.#subscription = undefined;\n\n try {\n await this.#subscribeToFeed();\n } catch (error) {\n if (this.#active && this.#connectionVersion === connectionVersion) {\n this.#subscription = existingSubscription;\n this.#subscriptionToken = existingSubscriptionToken;\n } else {\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n\n if (existingSubscription) {\n try {\n await existingSubscription.unsubscribe();\n } catch {\n this.#pendingUnsubscriptions.add(existingSubscription);\n }\n }\n }\n throw error;\n }\n\n const replacementSubscription = this.#subscription as\n | WebSocketSubscription\n | undefined;\n // The backend answers a repeat subscribe to the same channels with the same\n // subscription id. Unsubscribing the old handle would end the replacement.\n if (\n existingSubscription &&\n existingSubscription !== this.#subscription &&\n existingSubscription.subscriptionId !==\n replacementSubscription?.subscriptionId\n ) {\n try {\n await existingSubscription.unsubscribe();\n } catch (error) {\n if (this.#active && this.#connectionVersion === connectionVersion) {\n this.#subscription = existingSubscription;\n this.#subscriptionToken = existingSubscriptionToken;\n } else {\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n this.#pendingUnsubscriptions.add(existingSubscription);\n }\n\n if (replacementSubscription) {\n try {\n await replacementSubscription.unsubscribe();\n } catch {\n this.#pendingUnsubscriptions.add(replacementSubscription);\n }\n }\n\n throw error;\n }\n }\n }\n\n async #unsubscribeFromFeed(): Promise<void> {\n const subscription = this.#subscription;\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n\n try {\n if (subscription) {\n await subscription.unsubscribe();\n }\n } finally {\n await this.#retryPendingUnsubscriptions();\n }\n }\n\n async #retryPendingUnsubscriptions(): Promise<void> {\n for (const subscription of this.#pendingUnsubscriptions) {\n try {\n await subscription.unsubscribe();\n this.#pendingUnsubscriptions.delete(subscription);\n } catch {\n // Keep the subscription queued for a later cleanup attempt.\n }\n }\n }\n\n #handleNotification(notification: ServerNotificationMessage): void {\n const scope = scopeForChannel(notification.channel);\n if (!scope || !this.#scopes.includes(scope)) {\n return;\n }\n\n parseSocialFeedEvents(notification.data).forEach((event) => {\n this.#listeners.forEach((listener) => listener(event, scope));\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SocialRealtimeService.js","sourceRoot":"","sources":["../src/SocialRealtimeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAOxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,GAAG,EAAE,oBAAoB;IACzB,QAAQ,EAAE,yBAAyB;CAC3B,CAAC;AAIX,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAoB,CAAC;AAwB7D,MAAM,eAAe,GAAG,CACtB,MAA0C,EACf,EAAE;IAC7B,MAAM,UAAU,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,IAAwC,EACxC,KAAyC,EAChC,EAAE,CACX,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,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C,KAAK,CAAC,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,qBAAqB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebSocketState } from '@metamask/core-backend';\nimport type {\n BackendWebSocketServiceMessenger,\n ServerNotificationMessage,\n WebSocketSubscription,\n} from '@metamask/core-backend';\n\nimport { parseRealtimeFeedItem } from './realtime-feed-item.js';\nimport type { RealtimeFeedEventData } from './realtime-feed-item.js';\n\nexport const SOCIAL_FEED_CHANNELS = {\n all: 'social.v1.feed.all',\n trending: 'social.v1.feed.trending',\n} as const;\n\nexport type SocialFeedRealtimeScope = keyof typeof SOCIAL_FEED_CHANNELS;\n\nexport const SOCIAL_FEED_CHANNEL_TYPE = 'social.v1' as const;\n\nexport type SocialFeedEvent = {\n version: 1;\n kind: 'feed-item';\n eventId: string;\n feedItemId: string;\n revision: number;\n occurredAt: string;\n data: RealtimeFeedEventData;\n};\n\nexport type SocialFeedEventListener = (\n event: SocialFeedEvent,\n scope: SocialFeedRealtimeScope,\n) => void;\nexport type SocialFeedReconnectListener = () => void;\n\nexport type SocialRealtimeServiceOptions = {\n messenger: BackendWebSocketServiceMessenger;\n scopes: readonly SocialFeedRealtimeScope[];\n isEnabled?: () => boolean;\n};\n\nconst normalizeScopes = (\n scopes: readonly SocialFeedRealtimeScope[],\n): SocialFeedRealtimeScope[] => {\n const normalized = [...new Set(scopes)];\n if (normalized.length === 0) {\n throw new Error('At least one Social feed scope is required');\n }\n return normalized;\n};\n\nconst haveSameScopes = (\n left: readonly SocialFeedRealtimeScope[],\n right: readonly SocialFeedRealtimeScope[],\n): boolean =>\n left.length === right.length && left.every((scope) => right.includes(scope));\n\nconst scopeForChannel = (\n channel: string,\n): SocialFeedRealtimeScope | undefined =>\n (Object.entries(SOCIAL_FEED_CHANNELS).find(\n ([, value]) => value === channel,\n )?.[0] as SocialFeedRealtimeScope | undefined) ?? undefined;\n\nconst parseSocialFeedEvent = (data: unknown): SocialFeedEvent => {\n const event = data as SocialFeedEvent;\n return {\n ...event,\n data: parseRealtimeFeedItem(event.data),\n };\n};\n\nconst parseSocialFeedEvents = (data: unknown): SocialFeedEvent[] => {\n const entries = Array.isArray(data) ? data : [data];\n\n return entries.map((entry) => parseSocialFeedEvent(entry));\n};\n\n/**\n * Social realtime subscription service built on the shared backend WebSocket.\n *\n * Clients explicitly select one or more global feed scopes. Additional Social\n * channels can be added here without creating another WebSocket connection.\n */\nexport class SocialRealtimeService {\n readonly name = 'SocialRealtimeService' as const;\n\n readonly #messenger: BackendWebSocketServiceMessenger;\n\n readonly #listeners = new Set<SocialFeedEventListener>();\n\n readonly #reconnectListeners = new Set<SocialFeedReconnectListener>();\n\n readonly #isEnabled: () => boolean;\n\n #scopes: SocialFeedRealtimeScope[];\n\n #scopeUpdatePromise: Promise<void> | undefined;\n\n #active = false;\n\n #subscription: WebSocketSubscription | undefined;\n\n #subscriptionToken: symbol | undefined;\n\n #subscriptionPromise: Promise<void> | undefined;\n\n readonly #pendingUnsubscriptions = new Set<WebSocketSubscription>();\n\n #connectionVersion = 0;\n\n #wasDisconnected = false;\n\n constructor({\n messenger,\n scopes,\n isEnabled = (): boolean => true,\n }: SocialRealtimeServiceOptions) {\n this.#messenger = messenger;\n this.#scopes = normalizeScopes(scopes);\n this.#isEnabled = isEnabled;\n\n this.#messenger.subscribe(\n 'BackendWebSocketService:connectionStateChanged',\n ({ state }: { state: WebSocketState }): void => {\n if (state === WebSocketState.DISCONNECTED) {\n this.#connectionVersion += 1;\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n this.#wasDisconnected = true;\n }\n\n if (state === WebSocketState.CONNECTED && this.#active) {\n const isReconnect = this.#wasDisconnected;\n this.#wasDisconnected = false;\n // eslint-disable-next-line no-void\n void this.#subscribeToFeed()\n .then(() => {\n if (isReconnect) {\n this.#reconnectListeners.forEach((listener) => listener());\n }\n })\n .catch(() => undefined);\n }\n },\n );\n }\n\n addListener(listener: SocialFeedEventListener): () => void {\n this.#listeners.add(listener);\n return () => this.#listeners.delete(listener);\n }\n\n addReconnectListener(listener: SocialFeedReconnectListener): () => void {\n this.#reconnectListeners.add(listener);\n return () => this.#reconnectListeners.delete(listener);\n }\n\n async setScopes(scopes: readonly SocialFeedRealtimeScope[]): Promise<void> {\n const normalizedScopes = normalizeScopes(scopes);\n\n const scopeUpdate = this.#scopeUpdatePromise\n ? this.#scopeUpdatePromise\n .catch(() => undefined)\n .then(() => this.#applyScopes(normalizedScopes))\n : this.#applyScopes(normalizedScopes);\n this.#scopeUpdatePromise = scopeUpdate;\n\n try {\n await scopeUpdate;\n } finally {\n if (this.#scopeUpdatePromise === scopeUpdate) {\n this.#scopeUpdatePromise = Promise.resolve();\n }\n }\n }\n\n async #applyScopes(\n normalizedScopes: SocialFeedRealtimeScope[],\n ): Promise<void> {\n if (!this.#active) {\n this.#scopes = normalizedScopes;\n return;\n }\n\n if (this.#subscription && haveSameScopes(this.#scopes, normalizedScopes)) {\n return;\n }\n\n const previousScopes = this.#scopes;\n const connectionVersion = this.#connectionVersion;\n this.#scopes = normalizedScopes;\n\n try {\n await this.#resubscribeToFeed();\n } catch (error) {\n if (\n this.#active &&\n this.#connectionVersion === connectionVersion &&\n this.#subscription\n ) {\n this.#scopes = previousScopes;\n }\n throw error;\n }\n }\n\n async setActive(active: boolean): Promise<void> {\n this.#active = active && this.#isEnabled();\n\n if (!this.#active) {\n await this.#unsubscribeFromFeed();\n return;\n }\n\n await this.#retryPendingUnsubscriptions();\n await this.#subscribeToFeed();\n }\n\n async #subscribeToFeed(): Promise<void> {\n if (!this.#active || this.#subscription) {\n return;\n }\n\n while (this.#subscriptionPromise) {\n await this.#subscriptionPromise;\n\n if (!this.#active || this.#subscription) {\n return;\n }\n }\n\n const subscriptionPromise = Promise.resolve().then(\n async (): Promise<void> => {\n await this.#messenger.call('BackendWebSocketService:connect');\n\n const subscriptionToken = Symbol('social-feed-subscription');\n\n // Each service needs its own callback and subscription lifecycle.\n const subscription = await this.#messenger.call(\n 'BackendWebSocketService:subscribe',\n {\n channels: this.#scopes.map((scope) => SOCIAL_FEED_CHANNELS[scope]),\n channelType: SOCIAL_FEED_CHANNEL_TYPE,\n callback: (notification: ServerNotificationMessage) => {\n if (this.#subscriptionToken !== subscriptionToken) {\n return;\n }\n this.#handleNotification(notification);\n },\n },\n );\n\n if (!this.#active) {\n await subscription.unsubscribe();\n return;\n }\n\n this.#subscription = subscription;\n this.#subscriptionToken = subscriptionToken;\n },\n );\n this.#subscriptionPromise = subscriptionPromise;\n\n try {\n await subscriptionPromise;\n } finally {\n this.#subscriptionPromise = undefined;\n }\n }\n\n async #resubscribeToFeed(): Promise<void> {\n while (this.#subscriptionPromise) {\n await this.#subscriptionPromise;\n }\n\n await this.#retryPendingUnsubscriptions();\n\n const existingSubscription = this.#subscription;\n const existingSubscriptionToken = this.#subscriptionToken;\n const connectionVersion = this.#connectionVersion;\n this.#subscription = undefined;\n\n try {\n await this.#subscribeToFeed();\n } catch (error) {\n if (this.#active && this.#connectionVersion === connectionVersion) {\n this.#subscription = existingSubscription;\n this.#subscriptionToken = existingSubscriptionToken;\n } else {\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n\n if (existingSubscription) {\n try {\n await existingSubscription.unsubscribe();\n } catch {\n this.#pendingUnsubscriptions.add(existingSubscription);\n }\n }\n }\n throw error;\n }\n\n const replacementSubscription = this.#subscription as\n | WebSocketSubscription\n | undefined;\n // The backend answers a repeat subscribe to the same channels with the same\n // subscription id. Unsubscribing the old handle would end the replacement.\n if (\n existingSubscription &&\n existingSubscription !== this.#subscription &&\n existingSubscription.subscriptionId !==\n replacementSubscription?.subscriptionId\n ) {\n try {\n await existingSubscription.unsubscribe();\n } catch (error) {\n if (this.#active && this.#connectionVersion === connectionVersion) {\n this.#subscription = existingSubscription;\n this.#subscriptionToken = existingSubscriptionToken;\n } else {\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n this.#pendingUnsubscriptions.add(existingSubscription);\n }\n\n if (replacementSubscription) {\n try {\n await replacementSubscription.unsubscribe();\n } catch {\n this.#pendingUnsubscriptions.add(replacementSubscription);\n }\n }\n\n throw error;\n }\n }\n }\n\n async #unsubscribeFromFeed(): Promise<void> {\n const subscription = this.#subscription;\n this.#subscription = undefined;\n this.#subscriptionToken = undefined;\n\n try {\n if (subscription) {\n await subscription.unsubscribe();\n }\n } finally {\n await this.#retryPendingUnsubscriptions();\n }\n }\n\n async #retryPendingUnsubscriptions(): Promise<void> {\n for (const subscription of this.#pendingUnsubscriptions) {\n try {\n await subscription.unsubscribe();\n this.#pendingUnsubscriptions.delete(subscription);\n } catch {\n // Keep the subscription queued for a later cleanup attempt.\n }\n }\n }\n\n #handleNotification(notification: ServerNotificationMessage): void {\n const scope = scopeForChannel(notification.channel);\n if (!scope || !this.#scopes.includes(scope)) {\n return;\n }\n\n parseSocialFeedEvents(notification.data).forEach((event) => {\n this.#listeners.forEach((listener) => listener(event, scope));\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SocialService.d.ts","sourceRoot":"","sources":["../src/SocialService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"S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AG,OAAO,CAAC,gBAAgB,CAAC,CAyBlE;IAED;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkBzC;IAED;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkBxC;IAED;;;;;;;;;;;;;;;OAeG;IACG,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC,CAkBzD;IAED;;;;;;;;;;;;;OAaG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBhD;IAED;;;;;;;;;;OAUG;IACG,cAAc,CAAC,EAAE,SAAS,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBxE;IAED;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAuBlC;IAED;;;;;;;;;;OAUG;IACG,mBAAmB,CACvB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,sBAAsB,CAAC,CAuBjC;IAED;;;;;;;OAOG;IACG,qBAAqB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAgB/D;IAED;;;;;;;OAOG;IACG,gBAAgB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAerD;IAED;;;;;;;;;OASG;IACG,iBAAiB,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAEzE;IAED;;;;;;;;OAQG;IACG,UAAU,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAElE;CA8FF"}
|
package/dist/SocialService.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import { BaseDataService } from '@metamask/base-data-service';
|
|
3
3
|
import { HttpError } from '@metamask/controller-utils';
|
|
4
|
-
import { is } from '@metamask/superstruct';
|
|
5
4
|
import { serviceName, SocialServiceErrorMessage } from './social-constants.js';
|
|
6
|
-
import { BlockedContentResponseStruct, BlockedProfilesResponseStruct, CommentEngagementStruct, CommentTranslationStruct, CopyTradeIntentResponseStruct, FollowResponseStruct, FollowersResponseStruct, FollowingResponseStruct, GifPageResponseStruct, LeaderboardResponseStruct, ModerationStatusResponseStruct, PositionStruct, PositionsResponseStruct, QuoteTokensResponseStruct, SwapCommentResponseStruct, TraderProfileResponseStruct, UnfollowResponseStruct, parseFeedResponse, } from './structs.js';
|
|
7
5
|
// ---------------------------------------------------------------------------
|
|
8
6
|
// ---------------------------------------------------------------------------
|
|
9
7
|
// Messenger types
|
|
@@ -113,11 +111,7 @@ export class SocialService extends BaseDataService {
|
|
|
113
111
|
headers: authHeaders,
|
|
114
112
|
});
|
|
115
113
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED);
|
|
116
|
-
|
|
117
|
-
if (!is(leaderboardData, LeaderboardResponseStruct)) {
|
|
118
|
-
throw new Error(SocialServiceErrorMessage.FETCH_LEADERBOARD_INVALID_RESPONSE);
|
|
119
|
-
}
|
|
120
|
-
return leaderboardData;
|
|
114
|
+
return (await response.json());
|
|
121
115
|
},
|
|
122
116
|
});
|
|
123
117
|
return leaderboardResponse;
|
|
@@ -143,11 +137,7 @@ export class SocialService extends BaseDataService {
|
|
|
143
137
|
const authHeaders = await this.#getAuthHeaders();
|
|
144
138
|
const response = await fetch(url, { headers: authHeaders });
|
|
145
139
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED);
|
|
146
|
-
|
|
147
|
-
if (!is(traderProfileData, TraderProfileResponseStruct)) {
|
|
148
|
-
throw new Error(SocialServiceErrorMessage.FETCH_TRADER_PROFILE_INVALID_RESPONSE);
|
|
149
|
-
}
|
|
150
|
-
return traderProfileData;
|
|
140
|
+
return (await response.json());
|
|
151
141
|
},
|
|
152
142
|
});
|
|
153
143
|
return traderProfileResponse;
|
|
@@ -212,11 +202,7 @@ export class SocialService extends BaseDataService {
|
|
|
212
202
|
const authHeaders = await this.#getAuthHeaders();
|
|
213
203
|
const response = await fetch(url.toString(), { headers: authHeaders });
|
|
214
204
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED);
|
|
215
|
-
|
|
216
|
-
if (!is(followersData, FollowersResponseStruct)) {
|
|
217
|
-
throw new Error(SocialServiceErrorMessage.FETCH_FOLLOWERS_INVALID_RESPONSE);
|
|
218
|
-
}
|
|
219
|
-
return followersData;
|
|
205
|
+
return (await response.json());
|
|
220
206
|
},
|
|
221
207
|
});
|
|
222
208
|
return followersResponse;
|
|
@@ -242,11 +228,7 @@ export class SocialService extends BaseDataService {
|
|
|
242
228
|
const authHeaders = await this.#getAuthHeaders();
|
|
243
229
|
const response = await fetch(url, { headers: authHeaders });
|
|
244
230
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_FOLLOWING_FAILED);
|
|
245
|
-
|
|
246
|
-
if (!is(followingData, FollowingResponseStruct)) {
|
|
247
|
-
throw new Error(SocialServiceErrorMessage.FETCH_TRADER_FOLLOWING_INVALID_RESPONSE);
|
|
248
|
-
}
|
|
249
|
-
return followingData;
|
|
231
|
+
return (await response.json());
|
|
250
232
|
},
|
|
251
233
|
});
|
|
252
234
|
return followingResponse;
|
|
@@ -269,11 +251,7 @@ export class SocialService extends BaseDataService {
|
|
|
269
251
|
const authHeaders = await this.#getAuthHeaders();
|
|
270
252
|
const response = await fetch(url, { headers: authHeaders });
|
|
271
253
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_POSITION_BY_ID_FAILED);
|
|
272
|
-
|
|
273
|
-
if (!is(positionData, PositionStruct)) {
|
|
274
|
-
throw new Error(SocialServiceErrorMessage.FETCH_POSITION_BY_ID_INVALID_RESPONSE);
|
|
275
|
-
}
|
|
276
|
-
return positionData;
|
|
254
|
+
return (await response.json());
|
|
277
255
|
},
|
|
278
256
|
});
|
|
279
257
|
return positionResponse;
|
|
@@ -342,8 +320,7 @@ export class SocialService extends BaseDataService {
|
|
|
342
320
|
headers: authHeaders,
|
|
343
321
|
});
|
|
344
322
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FEED_FAILED);
|
|
345
|
-
|
|
346
|
-
return parseFeedResponse(feedData, SocialServiceErrorMessage.FETCH_FEED_INVALID_RESPONSE);
|
|
323
|
+
return (await response.json());
|
|
347
324
|
},
|
|
348
325
|
});
|
|
349
326
|
return feedResponse;
|
|
@@ -396,8 +373,7 @@ export class SocialService extends BaseDataService {
|
|
|
396
373
|
headers: authHeaders,
|
|
397
374
|
});
|
|
398
375
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_FEED_FAILED);
|
|
399
|
-
|
|
400
|
-
return parseFeedResponse(feedData, SocialServiceErrorMessage.FETCH_TRADER_FEED_INVALID_RESPONSE);
|
|
376
|
+
return (await response.json());
|
|
401
377
|
},
|
|
402
378
|
});
|
|
403
379
|
return traderFeedResponse;
|
|
@@ -451,8 +427,7 @@ export class SocialService extends BaseDataService {
|
|
|
451
427
|
headers: authHeaders,
|
|
452
428
|
});
|
|
453
429
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TOKEN_FEED_FAILED);
|
|
454
|
-
|
|
455
|
-
return parseFeedResponse(feedData, SocialServiceErrorMessage.FETCH_TOKEN_FEED_INVALID_RESPONSE);
|
|
430
|
+
return (await response.json());
|
|
456
431
|
},
|
|
457
432
|
});
|
|
458
433
|
return tokenFeedResponse;
|
|
@@ -482,11 +457,7 @@ export class SocialService extends BaseDataService {
|
|
|
482
457
|
body: JSON.stringify({ emotion }),
|
|
483
458
|
});
|
|
484
459
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.REACT_TO_COMMENT_FAILED);
|
|
485
|
-
|
|
486
|
-
if (!is(metrics, CommentEngagementStruct)) {
|
|
487
|
-
throw new Error(SocialServiceErrorMessage.REACT_TO_COMMENT_INVALID_RESPONSE);
|
|
488
|
-
}
|
|
489
|
-
return metrics;
|
|
460
|
+
return (await response.json());
|
|
490
461
|
},
|
|
491
462
|
});
|
|
492
463
|
}
|
|
@@ -513,11 +484,7 @@ export class SocialService extends BaseDataService {
|
|
|
513
484
|
headers: authHeaders,
|
|
514
485
|
});
|
|
515
486
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.REMOVE_COMMENT_REACTION_FAILED);
|
|
516
|
-
|
|
517
|
-
if (!is(metrics, CommentEngagementStruct)) {
|
|
518
|
-
throw new Error(SocialServiceErrorMessage.REMOVE_COMMENT_REACTION_INVALID_RESPONSE);
|
|
519
|
-
}
|
|
520
|
-
return metrics;
|
|
487
|
+
return (await response.json());
|
|
521
488
|
},
|
|
522
489
|
});
|
|
523
490
|
}
|
|
@@ -564,11 +531,7 @@ export class SocialService extends BaseDataService {
|
|
|
564
531
|
}),
|
|
565
532
|
});
|
|
566
533
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.CREATE_SWAP_COMMENT_FAILED);
|
|
567
|
-
|
|
568
|
-
if (!is(comment, SwapCommentResponseStruct)) {
|
|
569
|
-
throw new Error(SocialServiceErrorMessage.CREATE_SWAP_COMMENT_INVALID_RESPONSE);
|
|
570
|
-
}
|
|
571
|
-
return comment;
|
|
534
|
+
return (await response.json());
|
|
572
535
|
},
|
|
573
536
|
});
|
|
574
537
|
}
|
|
@@ -600,11 +563,7 @@ export class SocialService extends BaseDataService {
|
|
|
600
563
|
body: JSON.stringify({ targetLanguage }),
|
|
601
564
|
});
|
|
602
565
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.TRANSLATE_COMMENT_FAILED);
|
|
603
|
-
|
|
604
|
-
if (!is(translation, CommentTranslationStruct)) {
|
|
605
|
-
throw new Error(SocialServiceErrorMessage.TRANSLATE_COMMENT_INVALID_RESPONSE);
|
|
606
|
-
}
|
|
607
|
-
return translation;
|
|
566
|
+
return (await response.json());
|
|
608
567
|
},
|
|
609
568
|
});
|
|
610
569
|
}
|
|
@@ -641,11 +600,7 @@ export class SocialService extends BaseDataService {
|
|
|
641
600
|
body: JSON.stringify({ origin, copierAccount, execution }),
|
|
642
601
|
});
|
|
643
602
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.CREATE_COPY_TRADE_INTENT_FAILED);
|
|
644
|
-
|
|
645
|
-
if (!is(intent, CopyTradeIntentResponseStruct)) {
|
|
646
|
-
throw new Error(SocialServiceErrorMessage.CREATE_COPY_TRADE_INTENT_INVALID_RESPONSE);
|
|
647
|
-
}
|
|
648
|
-
return intent;
|
|
603
|
+
return (await response.json());
|
|
649
604
|
},
|
|
650
605
|
});
|
|
651
606
|
}
|
|
@@ -670,11 +625,7 @@ export class SocialService extends BaseDataService {
|
|
|
670
625
|
const authHeaders = await this.#getAuthHeaders();
|
|
671
626
|
const response = await fetch(url, { headers: authHeaders });
|
|
672
627
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED);
|
|
673
|
-
|
|
674
|
-
if (!is(followingData, FollowingResponseStruct)) {
|
|
675
|
-
throw new Error(SocialServiceErrorMessage.FETCH_FOLLOWING_INVALID_RESPONSE);
|
|
676
|
-
}
|
|
677
|
-
return followingData;
|
|
628
|
+
return (await response.json());
|
|
678
629
|
},
|
|
679
630
|
});
|
|
680
631
|
return followingResponse;
|
|
@@ -707,11 +658,7 @@ export class SocialService extends BaseDataService {
|
|
|
707
658
|
const authHeaders = await this.#getAuthHeaders();
|
|
708
659
|
const response = await fetch(url, { headers: authHeaders });
|
|
709
660
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_MY_FOLLOWERS_FAILED);
|
|
710
|
-
|
|
711
|
-
if (!is(followersData, FollowersResponseStruct)) {
|
|
712
|
-
throw new Error(SocialServiceErrorMessage.FETCH_MY_FOLLOWERS_INVALID_RESPONSE);
|
|
713
|
-
}
|
|
714
|
-
return followersData;
|
|
661
|
+
return (await response.json());
|
|
715
662
|
},
|
|
716
663
|
});
|
|
717
664
|
return followersResponse;
|
|
@@ -740,11 +687,7 @@ export class SocialService extends BaseDataService {
|
|
|
740
687
|
body: JSON.stringify({ targets }),
|
|
741
688
|
});
|
|
742
689
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FOLLOW_FAILED);
|
|
743
|
-
|
|
744
|
-
if (!is(followData, FollowResponseStruct)) {
|
|
745
|
-
throw new Error(SocialServiceErrorMessage.FOLLOW_INVALID_RESPONSE);
|
|
746
|
-
}
|
|
747
|
-
return followData;
|
|
690
|
+
return (await response.json());
|
|
748
691
|
},
|
|
749
692
|
});
|
|
750
693
|
return followResponse;
|
|
@@ -777,11 +720,7 @@ export class SocialService extends BaseDataService {
|
|
|
777
720
|
headers: authHeaders,
|
|
778
721
|
});
|
|
779
722
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.UNFOLLOW_FAILED);
|
|
780
|
-
|
|
781
|
-
if (!is(unfollowData, UnfollowResponseStruct)) {
|
|
782
|
-
throw new Error(SocialServiceErrorMessage.UNFOLLOW_INVALID_RESPONSE);
|
|
783
|
-
}
|
|
784
|
-
return unfollowData;
|
|
723
|
+
return (await response.json());
|
|
785
724
|
},
|
|
786
725
|
});
|
|
787
726
|
return unfollowResponse;
|
|
@@ -940,11 +879,7 @@ export class SocialService extends BaseDataService {
|
|
|
940
879
|
headers: authHeaders,
|
|
941
880
|
});
|
|
942
881
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_BLOCKED_PROFILES_FAILED);
|
|
943
|
-
|
|
944
|
-
if (!is(blockedProfiles, BlockedProfilesResponseStruct)) {
|
|
945
|
-
throw new Error(SocialServiceErrorMessage.FETCH_BLOCKED_PROFILES_INVALID_RESPONSE);
|
|
946
|
-
}
|
|
947
|
-
return blockedProfiles;
|
|
882
|
+
return (await response.json());
|
|
948
883
|
},
|
|
949
884
|
});
|
|
950
885
|
}
|
|
@@ -974,11 +909,7 @@ export class SocialService extends BaseDataService {
|
|
|
974
909
|
headers: authHeaders,
|
|
975
910
|
});
|
|
976
911
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_BLOCKED_CONTENT_FAILED);
|
|
977
|
-
|
|
978
|
-
if (!is(blockedContent, BlockedContentResponseStruct)) {
|
|
979
|
-
throw new Error(SocialServiceErrorMessage.FETCH_BLOCKED_CONTENT_INVALID_RESPONSE);
|
|
980
|
-
}
|
|
981
|
-
return blockedContent;
|
|
912
|
+
return (await response.json());
|
|
982
913
|
},
|
|
983
914
|
});
|
|
984
915
|
}
|
|
@@ -1000,11 +931,7 @@ export class SocialService extends BaseDataService {
|
|
|
1000
931
|
headers: authHeaders,
|
|
1001
932
|
});
|
|
1002
933
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_MODERATION_STATUS_FAILED);
|
|
1003
|
-
|
|
1004
|
-
if (!is(status, ModerationStatusResponseStruct)) {
|
|
1005
|
-
throw new Error(SocialServiceErrorMessage.FETCH_MODERATION_STATUS_INVALID_RESPONSE);
|
|
1006
|
-
}
|
|
1007
|
-
return status;
|
|
934
|
+
return (await response.json());
|
|
1008
935
|
},
|
|
1009
936
|
});
|
|
1010
937
|
}
|
|
@@ -1025,11 +952,7 @@ export class SocialService extends BaseDataService {
|
|
|
1025
952
|
headers: authHeaders,
|
|
1026
953
|
});
|
|
1027
954
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_QUOTE_TOKENS_FAILED);
|
|
1028
|
-
|
|
1029
|
-
if (!is(quoteTokens, QuoteTokensResponseStruct)) {
|
|
1030
|
-
throw new Error(SocialServiceErrorMessage.FETCH_QUOTE_TOKENS_INVALID_RESPONSE);
|
|
1031
|
-
}
|
|
1032
|
-
return quoteTokens;
|
|
955
|
+
return (await response.json());
|
|
1033
956
|
},
|
|
1034
957
|
});
|
|
1035
958
|
}
|
|
@@ -1070,9 +993,6 @@ export class SocialService extends BaseDataService {
|
|
|
1070
993
|
const failedMessage = resource === 'trending'
|
|
1071
994
|
? SocialServiceErrorMessage.FETCH_TRENDING_GIFS_FAILED
|
|
1072
995
|
: SocialServiceErrorMessage.FETCH_SEARCH_GIFS_FAILED;
|
|
1073
|
-
const invalidMessage = resource === 'trending'
|
|
1074
|
-
? SocialServiceErrorMessage.FETCH_TRENDING_GIFS_INVALID_RESPONSE
|
|
1075
|
-
: SocialServiceErrorMessage.FETCH_SEARCH_GIFS_INVALID_RESPONSE;
|
|
1076
996
|
return await this.fetchQuery({
|
|
1077
997
|
queryKey: [`${this.name}:${method}`, gifQueryCacheKey(params)],
|
|
1078
998
|
staleTime: GIF_STALE_TIME_MS,
|
|
@@ -1084,11 +1004,7 @@ export class SocialService extends BaseDataService {
|
|
|
1084
1004
|
headers: authHeaders,
|
|
1085
1005
|
});
|
|
1086
1006
|
_a.#throwIfNotOk(response, failedMessage);
|
|
1087
|
-
|
|
1088
|
-
if (!is(body, GifPageResponseStruct)) {
|
|
1089
|
-
throw new Error(invalidMessage);
|
|
1090
|
-
}
|
|
1091
|
-
return body;
|
|
1007
|
+
return (await response.json());
|
|
1092
1008
|
},
|
|
1093
1009
|
});
|
|
1094
1010
|
}
|
|
@@ -1104,9 +1020,6 @@ export class SocialService extends BaseDataService {
|
|
|
1104
1020
|
const failedMessage = status === 'open'
|
|
1105
1021
|
? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_FAILED
|
|
1106
1022
|
: SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_FAILED;
|
|
1107
|
-
const invalidMessage = status === 'open'
|
|
1108
|
-
? SocialServiceErrorMessage.FETCH_OPEN_POSITIONS_INVALID_RESPONSE
|
|
1109
|
-
: SocialServiceErrorMessage.FETCH_CLOSED_POSITIONS_INVALID_RESPONSE;
|
|
1110
1023
|
const positionsResponse = await this.fetchQuery({
|
|
1111
1024
|
queryKey: [
|
|
1112
1025
|
`${this.name}:fetch${status === 'open' ? 'Open' : 'Closed'}Positions`,
|
|
@@ -1139,11 +1052,7 @@ export class SocialService extends BaseDataService {
|
|
|
1139
1052
|
headers: authHeaders,
|
|
1140
1053
|
});
|
|
1141
1054
|
_a.#throwIfNotOk(response, failedMessage);
|
|
1142
|
-
|
|
1143
|
-
if (!is(positionsData, PositionsResponseStruct)) {
|
|
1144
|
-
throw new Error(invalidMessage);
|
|
1145
|
-
}
|
|
1146
|
-
return positionsData;
|
|
1055
|
+
return (await response.json());
|
|
1147
1056
|
},
|
|
1148
1057
|
});
|
|
1149
1058
|
return positionsResponse;
|