@metamask-previews/social-controllers 3.6.0-preview-44b7ded21 → 3.6.0-preview-cbae429b5
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 -10
- package/dist/SocialRealtimeService.d.ts +1 -1
- package/dist/SocialRealtimeService.d.ts.map +1 -1
- package/dist/SocialRealtimeService.js +6 -13
- package/dist/SocialRealtimeService.js.map +1 -1
- package/dist/SocialService-method-action-types.d.ts +2 -38
- package/dist/SocialService-method-action-types.d.ts.map +1 -1
- package/dist/SocialService-method-action-types.js.map +1 -1
- package/dist/SocialService.d.ts +2 -32
- package/dist/SocialService.d.ts.map +1 -1
- package/dist/SocialService.js +33 -110
- package/dist/SocialService.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/social-constants.d.ts +0 -2
- package/dist/social-constants.d.ts.map +1 -1
- package/dist/social-constants.js +0 -2
- package/dist/social-constants.js.map +1 -1
- package/dist/social-types.d.ts +7 -27
- package/dist/social-types.d.ts.map +1 -1
- package/dist/social-types.js.map +1 -1
- package/package.json +4 -4
package/dist/SocialService.js
CHANGED
|
@@ -33,13 +33,10 @@ const PositionStruct = structType({
|
|
|
33
33
|
chain: string(),
|
|
34
34
|
positionAmount: number(),
|
|
35
35
|
isOpen: optional(boolean()),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
soldUsd: nullable(number()),
|
|
41
|
-
realizedPnl: nullable(number()),
|
|
42
|
-
costBasis: nullable(number()),
|
|
36
|
+
boughtUsd: number(),
|
|
37
|
+
soldUsd: number(),
|
|
38
|
+
realizedPnl: number(),
|
|
39
|
+
costBasis: number(),
|
|
43
40
|
trades: array(TradeStruct),
|
|
44
41
|
lastTradeAt: number(),
|
|
45
42
|
tokenImageUrl: optional(nullable(string())),
|
|
@@ -185,34 +182,6 @@ const FeedResponseStruct = structType({
|
|
|
185
182
|
items: array(FeedItemStruct),
|
|
186
183
|
pagination: FeedPaginationStruct,
|
|
187
184
|
});
|
|
188
|
-
/**
|
|
189
|
-
* One malformed feed item must not blank the page. When the envelope is
|
|
190
|
-
* well-shaped, keep items that match {@link FeedItemStruct} and drop the rest.
|
|
191
|
-
* Still throw when `items` or `pagination` themselves are unusable.
|
|
192
|
-
*
|
|
193
|
-
* @param feedData - Parsed JSON body from a feed endpoint.
|
|
194
|
-
* @param invalidMessage - Error message to throw when the envelope is unusable.
|
|
195
|
-
* @returns The validated feed response, possibly with invalid items dropped.
|
|
196
|
-
*/
|
|
197
|
-
const parseFeedResponse = (feedData, invalidMessage) => {
|
|
198
|
-
if (is(feedData, FeedResponseStruct)) {
|
|
199
|
-
return feedData;
|
|
200
|
-
}
|
|
201
|
-
if (typeof feedData !== 'object' ||
|
|
202
|
-
feedData === null ||
|
|
203
|
-
!('items' in feedData) ||
|
|
204
|
-
!('pagination' in feedData)) {
|
|
205
|
-
throw new Error(invalidMessage);
|
|
206
|
-
}
|
|
207
|
-
const { items, pagination } = feedData;
|
|
208
|
-
if (!Array.isArray(items) || !is(pagination, FeedPaginationStruct)) {
|
|
209
|
-
throw new Error(invalidMessage);
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
items: items.filter((item) => is(item, FeedItemStruct)),
|
|
213
|
-
pagination,
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
185
|
const FollowersResponseStruct = structType({
|
|
217
186
|
followers: array(ProfileSummaryStruct),
|
|
218
187
|
count: number(),
|
|
@@ -258,9 +227,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
258
227
|
'fetchOpenPositions',
|
|
259
228
|
'fetchClosedPositions',
|
|
260
229
|
'fetchFollowers',
|
|
261
|
-
'fetchTraderFollowing',
|
|
262
230
|
'fetchFollowing',
|
|
263
|
-
'fetchMyFollowing',
|
|
264
231
|
'fetchMyFollowers',
|
|
265
232
|
'fetchPositionById',
|
|
266
233
|
'fetchFeed',
|
|
@@ -348,7 +315,7 @@ export class SocialService extends BaseDataService {
|
|
|
348
315
|
headers: authHeaders,
|
|
349
316
|
});
|
|
350
317
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_LEADERBOARD_FAILED);
|
|
351
|
-
const leaderboardData =
|
|
318
|
+
const leaderboardData = await response.json();
|
|
352
319
|
if (!is(leaderboardData, LeaderboardResponseStruct)) {
|
|
353
320
|
throw new Error(SocialServiceErrorMessage.FETCH_LEADERBOARD_INVALID_RESPONSE);
|
|
354
321
|
}
|
|
@@ -375,7 +342,7 @@ export class SocialService extends BaseDataService {
|
|
|
375
342
|
const authHeaders = await this.#getAuthHeaders();
|
|
376
343
|
const response = await fetch(url, { headers: authHeaders });
|
|
377
344
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_PROFILE_FAILED);
|
|
378
|
-
const traderProfileData =
|
|
345
|
+
const traderProfileData = await response.json();
|
|
379
346
|
if (!is(traderProfileData, TraderProfileResponseStruct)) {
|
|
380
347
|
throw new Error(SocialServiceErrorMessage.FETCH_TRADER_PROFILE_INVALID_RESPONSE);
|
|
381
348
|
}
|
|
@@ -419,31 +386,22 @@ export class SocialService extends BaseDataService {
|
|
|
419
386
|
/**
|
|
420
387
|
* Fetches a trader's MetaMask followers.
|
|
421
388
|
*
|
|
422
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.
|
|
423
|
-
* `mutuals: true` to append `?mutuals=true` (profiles that follow both this
|
|
424
|
-
* trader and the authenticated user; `count` is the mutual total). Requires a
|
|
425
|
-
* bearer token; the trader is identified by `addressOrId`, not the JWT
|
|
426
|
-
* subject (see {@link fetchMyFollowers} for the current user's inbound list).
|
|
389
|
+
* Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.
|
|
427
390
|
*
|
|
428
391
|
* @param options - Options bag.
|
|
429
392
|
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
430
|
-
* @param options.mutuals - When true, request mutual followers only.
|
|
431
393
|
* @returns The followers response.
|
|
432
394
|
*/
|
|
433
395
|
async fetchFollowers(options) {
|
|
434
|
-
const { addressOrId
|
|
435
|
-
const mutualsOnly = mutuals === true;
|
|
396
|
+
const { addressOrId } = options;
|
|
436
397
|
const followersResponse = await this.fetchQuery({
|
|
437
|
-
queryKey: [`${this.name}:fetchFollowers`, addressOrId
|
|
398
|
+
queryKey: [`${this.name}:fetchFollowers`, addressOrId],
|
|
438
399
|
queryFn: async () => {
|
|
439
|
-
const url =
|
|
440
|
-
if (mutualsOnly) {
|
|
441
|
-
url.searchParams.append('mutuals', 'true');
|
|
442
|
-
}
|
|
400
|
+
const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/followers`;
|
|
443
401
|
const authHeaders = await this.#getAuthHeaders();
|
|
444
|
-
const response = await fetch(url
|
|
402
|
+
const response = await fetch(url, { headers: authHeaders });
|
|
445
403
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FOLLOWERS_FAILED);
|
|
446
|
-
const followersData =
|
|
404
|
+
const followersData = await response.json();
|
|
447
405
|
if (!is(followersData, FollowersResponseStruct)) {
|
|
448
406
|
throw new Error(SocialServiceErrorMessage.FETCH_FOLLOWERS_INVALID_RESPONSE);
|
|
449
407
|
}
|
|
@@ -452,35 +410,6 @@ export class SocialService extends BaseDataService {
|
|
|
452
410
|
});
|
|
453
411
|
return followersResponse;
|
|
454
412
|
}
|
|
455
|
-
/**
|
|
456
|
-
* Fetches the list of traders a profile follows.
|
|
457
|
-
*
|
|
458
|
-
* Calls `GET ${baseUrl}/traders/${addressOrId}/following`. Requires a bearer
|
|
459
|
-
* token; the trader is identified by `addressOrId`, not the JWT subject (see
|
|
460
|
-
* {@link fetchFollowing} for the current user's outbound list).
|
|
461
|
-
*
|
|
462
|
-
* @param options - Options bag.
|
|
463
|
-
* @param options.addressOrId - Wallet address or Clicker profile ID.
|
|
464
|
-
* @returns The following response.
|
|
465
|
-
*/
|
|
466
|
-
async fetchTraderFollowing(options) {
|
|
467
|
-
const { addressOrId } = options;
|
|
468
|
-
const followingResponse = await this.fetchQuery({
|
|
469
|
-
queryKey: [`${this.name}:fetchTraderFollowing`, addressOrId],
|
|
470
|
-
queryFn: async () => {
|
|
471
|
-
const url = `${this.#v1Url}/traders/${encodeURIComponent(addressOrId)}/following`;
|
|
472
|
-
const authHeaders = await this.#getAuthHeaders();
|
|
473
|
-
const response = await fetch(url, { headers: authHeaders });
|
|
474
|
-
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_FOLLOWING_FAILED);
|
|
475
|
-
const followingData = (await response.json());
|
|
476
|
-
if (!is(followingData, FollowingResponseStruct)) {
|
|
477
|
-
throw new Error(SocialServiceErrorMessage.FETCH_TRADER_FOLLOWING_INVALID_RESPONSE);
|
|
478
|
-
}
|
|
479
|
-
return followingData;
|
|
480
|
-
},
|
|
481
|
-
});
|
|
482
|
-
return followingResponse;
|
|
483
|
-
}
|
|
484
413
|
/**
|
|
485
414
|
* Fetches a single position by its unique ID.
|
|
486
415
|
*
|
|
@@ -499,7 +428,7 @@ export class SocialService extends BaseDataService {
|
|
|
499
428
|
const authHeaders = await this.#getAuthHeaders();
|
|
500
429
|
const response = await fetch(url, { headers: authHeaders });
|
|
501
430
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_POSITION_BY_ID_FAILED);
|
|
502
|
-
const positionData =
|
|
431
|
+
const positionData = await response.json();
|
|
503
432
|
if (!is(positionData, PositionStruct)) {
|
|
504
433
|
throw new Error(SocialServiceErrorMessage.FETCH_POSITION_BY_ID_INVALID_RESPONSE);
|
|
505
434
|
}
|
|
@@ -556,8 +485,11 @@ export class SocialService extends BaseDataService {
|
|
|
556
485
|
headers: authHeaders,
|
|
557
486
|
});
|
|
558
487
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FEED_FAILED);
|
|
559
|
-
const feedData =
|
|
560
|
-
|
|
488
|
+
const feedData = await response.json();
|
|
489
|
+
if (!is(feedData, FeedResponseStruct)) {
|
|
490
|
+
throw new Error(SocialServiceErrorMessage.FETCH_FEED_INVALID_RESPONSE);
|
|
491
|
+
}
|
|
492
|
+
return feedData;
|
|
561
493
|
},
|
|
562
494
|
});
|
|
563
495
|
return feedResponse;
|
|
@@ -610,8 +542,11 @@ export class SocialService extends BaseDataService {
|
|
|
610
542
|
headers: authHeaders,
|
|
611
543
|
});
|
|
612
544
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TRADER_FEED_FAILED);
|
|
613
|
-
const feedData =
|
|
614
|
-
|
|
545
|
+
const feedData = await response.json();
|
|
546
|
+
if (!is(feedData, FeedResponseStruct)) {
|
|
547
|
+
throw new Error(SocialServiceErrorMessage.FETCH_TRADER_FEED_INVALID_RESPONSE);
|
|
548
|
+
}
|
|
549
|
+
return feedData;
|
|
615
550
|
},
|
|
616
551
|
});
|
|
617
552
|
return traderFeedResponse;
|
|
@@ -666,7 +601,10 @@ export class SocialService extends BaseDataService {
|
|
|
666
601
|
});
|
|
667
602
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_TOKEN_FEED_FAILED);
|
|
668
603
|
const feedData = (await response.json());
|
|
669
|
-
|
|
604
|
+
if (!is(feedData, FeedResponseStruct)) {
|
|
605
|
+
throw new Error(SocialServiceErrorMessage.FETCH_TOKEN_FEED_INVALID_RESPONSE);
|
|
606
|
+
}
|
|
607
|
+
return feedData;
|
|
670
608
|
},
|
|
671
609
|
});
|
|
672
610
|
return tokenFeedResponse;
|
|
@@ -696,7 +634,7 @@ export class SocialService extends BaseDataService {
|
|
|
696
634
|
body: JSON.stringify({ emotion }),
|
|
697
635
|
});
|
|
698
636
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.REACT_TO_COMMENT_FAILED);
|
|
699
|
-
const metrics =
|
|
637
|
+
const metrics = await response.json();
|
|
700
638
|
if (!is(metrics, CommentEngagementStruct)) {
|
|
701
639
|
throw new Error(SocialServiceErrorMessage.REACT_TO_COMMENT_INVALID_RESPONSE);
|
|
702
640
|
}
|
|
@@ -727,7 +665,7 @@ export class SocialService extends BaseDataService {
|
|
|
727
665
|
headers: authHeaders,
|
|
728
666
|
});
|
|
729
667
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.REMOVE_COMMENT_REACTION_FAILED);
|
|
730
|
-
const metrics =
|
|
668
|
+
const metrics = await response.json();
|
|
731
669
|
if (!is(metrics, CommentEngagementStruct)) {
|
|
732
670
|
throw new Error(SocialServiceErrorMessage.REMOVE_COMMENT_REACTION_INVALID_RESPONSE);
|
|
733
671
|
}
|
|
@@ -792,10 +730,6 @@ export class SocialService extends BaseDataService {
|
|
|
792
730
|
* Calls `GET ${baseUrl}/users/me/following`. The caller is identified
|
|
793
731
|
* server-side from the JWT sub claim carried in the Authorization header.
|
|
794
732
|
*
|
|
795
|
-
* Prefer {@link fetchMyFollowing} in new code (pairs with
|
|
796
|
-
* {@link fetchMyFollowers}). This method is unchanged and remains the
|
|
797
|
-
* `/users/me/following` read.
|
|
798
|
-
*
|
|
799
733
|
* @returns The following response.
|
|
800
734
|
*/
|
|
801
735
|
async fetchFollowing() {
|
|
@@ -807,7 +741,7 @@ export class SocialService extends BaseDataService {
|
|
|
807
741
|
const authHeaders = await this.#getAuthHeaders();
|
|
808
742
|
const response = await fetch(url, { headers: authHeaders });
|
|
809
743
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FETCH_FOLLOWING_FAILED);
|
|
810
|
-
const followingData =
|
|
744
|
+
const followingData = await response.json();
|
|
811
745
|
if (!is(followingData, FollowingResponseStruct)) {
|
|
812
746
|
throw new Error(SocialServiceErrorMessage.FETCH_FOLLOWING_INVALID_RESPONSE);
|
|
813
747
|
}
|
|
@@ -816,17 +750,6 @@ export class SocialService extends BaseDataService {
|
|
|
816
750
|
});
|
|
817
751
|
return followingResponse;
|
|
818
752
|
}
|
|
819
|
-
/**
|
|
820
|
-
* Fetches the list of traders the current user is following.
|
|
821
|
-
*
|
|
822
|
-
* Alias of {@link fetchFollowing}. Calls `GET ${baseUrl}/users/me/following`.
|
|
823
|
-
* Preferred name in new code so `/users/me` reads are both `fetchMy*`.
|
|
824
|
-
*
|
|
825
|
-
* @returns The following response.
|
|
826
|
-
*/
|
|
827
|
-
async fetchMyFollowing() {
|
|
828
|
-
return this.fetchFollowing();
|
|
829
|
-
}
|
|
830
753
|
/**
|
|
831
754
|
* Fetches the list of traders following the current user.
|
|
832
755
|
*
|
|
@@ -877,7 +800,7 @@ export class SocialService extends BaseDataService {
|
|
|
877
800
|
body: JSON.stringify({ targets }),
|
|
878
801
|
});
|
|
879
802
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.FOLLOW_FAILED);
|
|
880
|
-
const followData =
|
|
803
|
+
const followData = await response.json();
|
|
881
804
|
if (!is(followData, FollowResponseStruct)) {
|
|
882
805
|
throw new Error(SocialServiceErrorMessage.FOLLOW_INVALID_RESPONSE);
|
|
883
806
|
}
|
|
@@ -914,7 +837,7 @@ export class SocialService extends BaseDataService {
|
|
|
914
837
|
headers: authHeaders,
|
|
915
838
|
});
|
|
916
839
|
_a.#throwIfNotOk(response, SocialServiceErrorMessage.UNFOLLOW_FAILED);
|
|
917
|
-
const unfollowData =
|
|
840
|
+
const unfollowData = await response.json();
|
|
918
841
|
if (!is(unfollowData, UnfollowResponseStruct)) {
|
|
919
842
|
throw new Error(SocialServiceErrorMessage.UNFOLLOW_INVALID_RESPONSE);
|
|
920
843
|
}
|
|
@@ -1139,7 +1062,7 @@ export class SocialService extends BaseDataService {
|
|
|
1139
1062
|
headers: authHeaders,
|
|
1140
1063
|
});
|
|
1141
1064
|
_a.#throwIfNotOk(response, failedMessage);
|
|
1142
|
-
const positionsData =
|
|
1065
|
+
const positionsData = await response.json();
|
|
1143
1066
|
if (!is(positionsData, PositionsResponseStruct)) {
|
|
1144
1067
|
throw new Error(invalidMessage);
|
|
1145
1068
|
}
|