@metamask-previews/social-controllers 2.8.0-preview-3866c0ff1 → 2.8.0-preview-e3275932a

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/SocialController-method-action-types.cjs +7 -0
  3. package/dist/SocialController-method-action-types.cjs.map +1 -0
  4. package/dist/{SocialController-method-action-types.d.ts → SocialController-method-action-types.d.cts} +2 -2
  5. package/dist/SocialController-method-action-types.d.cts.map +1 -0
  6. package/dist/SocialController-method-action-types.d.mts +71 -0
  7. package/dist/SocialController-method-action-types.d.mts.map +1 -0
  8. package/dist/{SocialController-method-action-types.js → SocialController-method-action-types.mjs} +1 -1
  9. package/dist/SocialController-method-action-types.mjs.map +1 -0
  10. package/dist/SocialController.cjs +160 -0
  11. package/dist/SocialController.cjs.map +1 -0
  12. package/dist/{SocialController.d.ts → SocialController.d.cts} +8 -8
  13. package/dist/SocialController.d.cts.map +1 -0
  14. package/dist/SocialController.d.mts +80 -0
  15. package/dist/SocialController.d.mts.map +1 -0
  16. package/dist/{SocialController.js → SocialController.mjs} +3 -3
  17. package/dist/SocialController.mjs.map +1 -0
  18. package/dist/SocialService-method-action-types.cjs +7 -0
  19. package/dist/SocialService-method-action-types.cjs.map +1 -0
  20. package/dist/{SocialService-method-action-types.d.ts → SocialService-method-action-types.d.cts} +2 -2
  21. package/dist/SocialService-method-action-types.d.cts.map +1 -0
  22. package/dist/SocialService-method-action-types.d.mts +194 -0
  23. package/dist/SocialService-method-action-types.d.mts.map +1 -0
  24. package/dist/{SocialService-method-action-types.js → SocialService-method-action-types.mjs} +1 -1
  25. package/dist/SocialService-method-action-types.mjs.map +1 -0
  26. package/dist/SocialService.cjs +635 -0
  27. package/dist/SocialService.cjs.map +1 -0
  28. package/dist/{SocialService.d.ts → SocialService.d.cts} +9 -9
  29. package/dist/SocialService.d.cts.map +1 -0
  30. package/dist/SocialService.d.mts +171 -0
  31. package/dist/SocialService.d.mts.map +1 -0
  32. package/dist/{SocialService.js → SocialService.mjs} +131 -128
  33. package/dist/SocialService.mjs.map +1 -0
  34. package/dist/index.cjs +14 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/{index.d.ts → index.d.cts} +10 -10
  37. package/dist/index.d.cts.map +1 -0
  38. package/dist/index.d.mts +10 -0
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/index.mjs +5 -0
  41. package/dist/index.mjs.map +1 -0
  42. package/dist/social-constants.cjs +31 -0
  43. package/dist/social-constants.cjs.map +1 -0
  44. package/dist/social-constants.d.cts +28 -0
  45. package/dist/social-constants.d.cts.map +1 -0
  46. package/dist/social-constants.d.mts +28 -0
  47. package/dist/social-constants.d.mts.map +1 -0
  48. package/dist/{social-constants.js → social-constants.mjs} +1 -1
  49. package/dist/social-constants.mjs.map +1 -0
  50. package/dist/social-types.cjs +27 -0
  51. package/dist/social-types.cjs.map +1 -0
  52. package/dist/{social-types.d.ts → social-types.d.cts} +14 -14
  53. package/dist/social-types.d.cts.map +1 -0
  54. package/dist/social-types.d.mts +343 -0
  55. package/dist/social-types.d.mts.map +1 -0
  56. package/dist/{social-types.js → social-types.mjs} +2 -2
  57. package/dist/social-types.mjs.map +1 -0
  58. package/package.json +16 -12
  59. package/dist/SocialController-method-action-types.d.ts.map +0 -1
  60. package/dist/SocialController-method-action-types.js.map +0 -1
  61. package/dist/SocialController.d.ts.map +0 -1
  62. package/dist/SocialController.js.map +0 -1
  63. package/dist/SocialService-method-action-types.d.ts.map +0 -1
  64. package/dist/SocialService-method-action-types.js.map +0 -1
  65. package/dist/SocialService.d.ts.map +0 -1
  66. package/dist/SocialService.js.map +0 -1
  67. package/dist/index.d.ts.map +0 -1
  68. package/dist/index.js +0 -5
  69. package/dist/index.js.map +0 -1
  70. package/dist/social-constants.d.ts +0 -28
  71. package/dist/social-constants.d.ts.map +0 -1
  72. package/dist/social-constants.js.map +0 -1
  73. package/dist/social-types.d.ts.map +0 -1
  74. package/dist/social-types.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -19,7 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
 
20
20
  ### Changed
21
21
 
22
- - **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
23
22
  - Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#9754](https://github.com/MetaMask/core/pull/9754))
24
23
  - Bump `@metamask/base-data-service` from `^0.1.3` to `^1.0.0` ([#9972](https://github.com/MetaMask/core/pull/9972))
25
24
 
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=SocialController-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.cjs","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialController } from './SocialController.js';\n\n/**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\nexport type SocialControllerUpdateLeaderboardAction = {\n type: `SocialController:updateLeaderboard`;\n handler: SocialController['updateLeaderboard'];\n};\n\n/**\n * Follows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialControllerFollowTraderAction = {\n type: `SocialController:followTrader`;\n handler: SocialController['followTrader'];\n};\n\n/**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialControllerUnfollowTraderAction = {\n type: `SocialController:unfollowTrader`;\n handler: SocialController['unfollowTrader'];\n};\n\n/**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\nexport type SocialControllerUpdateFollowingAction = {\n type: `SocialController:updateFollowing`;\n handler: SocialController['updateFollowing'];\n};\n\n/**\n * Opts the current user out of the PnL leaderboard.\n */\nexport type SocialControllerOptOutOfLeaderboardAction = {\n type: `SocialController:optOutOfLeaderboard`;\n handler: SocialController['optOutOfLeaderboard'];\n};\n\n/**\n * Opts the current user back into the PnL leaderboard.\n */\nexport type SocialControllerOptInToLeaderboardAction = {\n type: `SocialController:optInToLeaderboard`;\n handler: SocialController['optInToLeaderboard'];\n};\n\n/**\n * Union of all SocialController action types.\n */\nexport type SocialControllerMethodActions =\n | SocialControllerUpdateLeaderboardAction\n | SocialControllerFollowTraderAction\n | SocialControllerUnfollowTraderAction\n | SocialControllerUpdateFollowingAction\n | SocialControllerOptOutOfLeaderboardAction\n | SocialControllerOptInToLeaderboardAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { SocialController } from './SocialController.js';
5
+ import type { SocialController } from "./SocialController.cjs";
6
6
  /**
7
7
  * Fetches the leaderboard and persists the entries to state.
8
8
  *
@@ -68,4 +68,4 @@ export type SocialControllerOptInToLeaderboardAction = {
68
68
  * Union of all SocialController action types.
69
69
  */
70
70
  export type SocialControllerMethodActions = SocialControllerUpdateLeaderboardAction | SocialControllerFollowTraderAction | SocialControllerUnfollowTraderAction | SocialControllerUpdateFollowingAction | SocialControllerOptOutOfLeaderboardAction | SocialControllerOptInToLeaderboardAction;
71
- //# sourceMappingURL=SocialController-method-action-types.d.ts.map
71
+ //# sourceMappingURL=SocialController-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.d.cts","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA8B;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,uCAAuC,GACvC,kCAAkC,GAClC,oCAAoC,GACpC,qCAAqC,GACrC,yCAAyC,GACzC,wCAAwC,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * This file is auto generated.
3
+ * Do not edit manually.
4
+ */
5
+ import type { SocialController } from "./SocialController.mjs";
6
+ /**
7
+ * Fetches the leaderboard and persists the entries to state.
8
+ *
9
+ * @param options - Optional leaderboard query parameters.
10
+ * @returns The leaderboard response from the social-api.
11
+ */
12
+ export type SocialControllerUpdateLeaderboardAction = {
13
+ type: `SocialController:updateLeaderboard`;
14
+ handler: SocialController['updateLeaderboard'];
15
+ };
16
+ /**
17
+ * Follows one or more traders on behalf of the current user and updates
18
+ * the following list in state. The caller is identified server-side from
19
+ * the JWT attached by the SocialService.
20
+ *
21
+ * @param options - Options bag.
22
+ * @param options.targets - Addresses or profile IDs to follow.
23
+ * @returns The follow response with confirmed follows.
24
+ */
25
+ export type SocialControllerFollowTraderAction = {
26
+ type: `SocialController:followTrader`;
27
+ handler: SocialController['followTrader'];
28
+ };
29
+ /**
30
+ * Unfollows one or more traders on behalf of the current user and updates
31
+ * the following list in state. The caller is identified server-side from
32
+ * the JWT attached by the SocialService.
33
+ *
34
+ * @param options - Options bag.
35
+ * @param options.targets - Addresses or profile IDs to unfollow.
36
+ * @returns The unfollow response with confirmed unfollows.
37
+ */
38
+ export type SocialControllerUnfollowTraderAction = {
39
+ type: `SocialController:unfollowTrader`;
40
+ handler: SocialController['unfollowTrader'];
41
+ };
42
+ /**
43
+ * Fetches the list of traders the current user follows and replaces
44
+ * the following addresses in state. The caller is identified server-side
45
+ * from the JWT attached by the SocialService.
46
+ *
47
+ * @returns The following response.
48
+ */
49
+ export type SocialControllerUpdateFollowingAction = {
50
+ type: `SocialController:updateFollowing`;
51
+ handler: SocialController['updateFollowing'];
52
+ };
53
+ /**
54
+ * Opts the current user out of the PnL leaderboard.
55
+ */
56
+ export type SocialControllerOptOutOfLeaderboardAction = {
57
+ type: `SocialController:optOutOfLeaderboard`;
58
+ handler: SocialController['optOutOfLeaderboard'];
59
+ };
60
+ /**
61
+ * Opts the current user back into the PnL leaderboard.
62
+ */
63
+ export type SocialControllerOptInToLeaderboardAction = {
64
+ type: `SocialController:optInToLeaderboard`;
65
+ handler: SocialController['optInToLeaderboard'];
66
+ };
67
+ /**
68
+ * Union of all SocialController action types.
69
+ */
70
+ export type SocialControllerMethodActions = SocialControllerUpdateLeaderboardAction | SocialControllerFollowTraderAction | SocialControllerUnfollowTraderAction | SocialControllerUpdateFollowingAction | SocialControllerOptOutOfLeaderboardAction | SocialControllerOptInToLeaderboardAction;
71
+ //# sourceMappingURL=SocialController-method-action-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.d.mts","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA8B;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,uCAAuC,GACvC,kCAAkC,GAClC,oCAAoC,GACpC,qCAAqC,GACrC,yCAAyC,GACzC,wCAAwC,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=SocialController-method-action-types.js.map
6
+ //# sourceMappingURL=SocialController-method-action-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController-method-action-types.mjs","sourceRoot":"","sources":["../src/SocialController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialController } from './SocialController.js';\n\n/**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\nexport type SocialControllerUpdateLeaderboardAction = {\n type: `SocialController:updateLeaderboard`;\n handler: SocialController['updateLeaderboard'];\n};\n\n/**\n * Follows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialControllerFollowTraderAction = {\n type: `SocialController:followTrader`;\n handler: SocialController['followTrader'];\n};\n\n/**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialControllerUnfollowTraderAction = {\n type: `SocialController:unfollowTrader`;\n handler: SocialController['unfollowTrader'];\n};\n\n/**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\nexport type SocialControllerUpdateFollowingAction = {\n type: `SocialController:updateFollowing`;\n handler: SocialController['updateFollowing'];\n};\n\n/**\n * Opts the current user out of the PnL leaderboard.\n */\nexport type SocialControllerOptOutOfLeaderboardAction = {\n type: `SocialController:optOutOfLeaderboard`;\n handler: SocialController['optOutOfLeaderboard'];\n};\n\n/**\n * Opts the current user back into the PnL leaderboard.\n */\nexport type SocialControllerOptInToLeaderboardAction = {\n type: `SocialController:optInToLeaderboard`;\n handler: SocialController['optInToLeaderboard'];\n};\n\n/**\n * Union of all SocialController action types.\n */\nexport type SocialControllerMethodActions =\n | SocialControllerUpdateLeaderboardAction\n | SocialControllerFollowTraderAction\n | SocialControllerUnfollowTraderAction\n | SocialControllerUpdateFollowingAction\n | SocialControllerOptOutOfLeaderboardAction\n | SocialControllerOptInToLeaderboardAction;\n"]}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SocialController = exports.getDefaultSocialControllerState = void 0;
4
+ const base_controller_1 = require("@metamask/base-controller");
5
+ const social_constants_js_1 = require("./social-constants.cjs");
6
+ // === MESSENGER ===
7
+ const MESSENGER_EXPOSED_METHODS = [
8
+ 'updateLeaderboard',
9
+ 'followTrader',
10
+ 'unfollowTrader',
11
+ 'updateFollowing',
12
+ 'optOutOfLeaderboard',
13
+ 'optInToLeaderboard',
14
+ ];
15
+ // === DEFAULT STATE ===
16
+ /**
17
+ * Returns the default state for the SocialController.
18
+ *
19
+ * @returns A fresh default state object.
20
+ */
21
+ function getDefaultSocialControllerState() {
22
+ return {
23
+ leaderboardEntries: [],
24
+ followingAddresses: [],
25
+ followingProfileIds: [],
26
+ };
27
+ }
28
+ exports.getDefaultSocialControllerState = getDefaultSocialControllerState;
29
+ // === STATE METADATA ===
30
+ const socialControllerMetadata = {
31
+ leaderboardEntries: {
32
+ persist: true,
33
+ includeInDebugSnapshot: false,
34
+ includeInStateLogs: false,
35
+ usedInUi: true,
36
+ },
37
+ followingAddresses: {
38
+ persist: true,
39
+ includeInDebugSnapshot: false,
40
+ includeInStateLogs: false,
41
+ usedInUi: true,
42
+ },
43
+ followingProfileIds: {
44
+ persist: true,
45
+ includeInDebugSnapshot: false,
46
+ includeInStateLogs: false,
47
+ usedInUi: true,
48
+ },
49
+ };
50
+ // === CONTROLLER ===
51
+ /**
52
+ * Controller that manages social trading state for the extension UI.
53
+ *
54
+ * Acts as a simple store with no TTL or eviction — the UI decides when
55
+ * to re-fetch, and the social-api's own cache layer handles upstream
56
+ * rate-limiting. State is persisted across sessions so the UI can render
57
+ * immediately on startup while a fresh fetch is in flight.
58
+ */
59
+ class SocialController extends base_controller_1.BaseController {
60
+ constructor({ messenger, state }) {
61
+ super({
62
+ name: social_constants_js_1.controllerName,
63
+ metadata: socialControllerMetadata,
64
+ state: {
65
+ ...getDefaultSocialControllerState(),
66
+ ...state,
67
+ },
68
+ messenger,
69
+ });
70
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
71
+ }
72
+ /**
73
+ * Fetches the leaderboard and persists the entries to state.
74
+ *
75
+ * @param options - Optional leaderboard query parameters.
76
+ * @returns The leaderboard response from the social-api.
77
+ */
78
+ async updateLeaderboard(options) {
79
+ const leaderboardResponse = await this.messenger.call('SocialService:fetchLeaderboard', options);
80
+ this.update((state) => {
81
+ state.leaderboardEntries = leaderboardResponse.traders;
82
+ });
83
+ return leaderboardResponse;
84
+ }
85
+ /**
86
+ * Follows one or more traders on behalf of the current user and updates
87
+ * the following list in state. The caller is identified server-side from
88
+ * the JWT attached by the SocialService.
89
+ *
90
+ * @param options - Options bag.
91
+ * @param options.targets - Addresses or profile IDs to follow.
92
+ * @returns The follow response with confirmed follows.
93
+ */
94
+ async followTrader(options) {
95
+ const followResponse = await this.messenger.call('SocialService:follow', options);
96
+ const newAddresses = [
97
+ ...new Set(followResponse.followed.map((profile) => profile.address)),
98
+ ];
99
+ const newProfileIds = [
100
+ ...new Set(followResponse.followed.map((profile) => profile.profileId)),
101
+ ];
102
+ this.update((state) => {
103
+ const existing = new Set(state.followingAddresses);
104
+ const uniqueNewAddresses = newAddresses.filter((address) => !existing.has(address));
105
+ state.followingAddresses.push(...uniqueNewAddresses);
106
+ const existingIds = new Set(state.followingProfileIds);
107
+ const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));
108
+ state.followingProfileIds.push(...uniqueNewIds);
109
+ });
110
+ return followResponse;
111
+ }
112
+ /**
113
+ * Unfollows one or more traders on behalf of the current user and updates
114
+ * the following list in state. The caller is identified server-side from
115
+ * the JWT attached by the SocialService.
116
+ *
117
+ * @param options - Options bag.
118
+ * @param options.targets - Addresses or profile IDs to unfollow.
119
+ * @returns The unfollow response with confirmed unfollows.
120
+ */
121
+ async unfollowTrader(options) {
122
+ const unfollowResponse = await this.messenger.call('SocialService:unfollow', options);
123
+ const removedAddresses = new Set(unfollowResponse.unfollowed.map((profile) => profile.address));
124
+ const removedProfileIds = new Set(unfollowResponse.unfollowed.map((profile) => profile.profileId));
125
+ this.update((state) => {
126
+ state.followingAddresses = state.followingAddresses.filter((address) => !removedAddresses.has(address));
127
+ state.followingProfileIds = state.followingProfileIds.filter((id) => !removedProfileIds.has(id));
128
+ });
129
+ return unfollowResponse;
130
+ }
131
+ /**
132
+ * Fetches the list of traders the current user follows and replaces
133
+ * the following addresses in state. The caller is identified server-side
134
+ * from the JWT attached by the SocialService.
135
+ *
136
+ * @returns The following response.
137
+ */
138
+ async updateFollowing() {
139
+ const followingResponse = await this.messenger.call('SocialService:fetchFollowing');
140
+ this.update((state) => {
141
+ state.followingAddresses = followingResponse.following.map((profile) => profile.address);
142
+ state.followingProfileIds = followingResponse.following.map((profile) => profile.profileId);
143
+ });
144
+ return followingResponse;
145
+ }
146
+ /**
147
+ * Opts the current user out of the PnL leaderboard.
148
+ */
149
+ async optOutOfLeaderboard() {
150
+ await this.messenger.call('SocialService:optOutOfLeaderboard');
151
+ }
152
+ /**
153
+ * Opts the current user back into the PnL leaderboard.
154
+ */
155
+ async optInToLeaderboard() {
156
+ await this.messenger.call('SocialService:optInToLeaderboard');
157
+ }
158
+ }
159
+ exports.SocialController = SocialController;
160
+ //# sourceMappingURL=SocialController.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.cjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,gEAAuD;AAqBvD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,mBAAmB;IACnB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,qBAAqB;IACrB,oBAAoB;CACZ,CAAC;AAiDX,wBAAwB;AAExB;;;;GAIG;AACH,SAAgB,+BAA+B;IAC7C,OAAO;QACL,kBAAkB,EAAE,EAAE;QACtB,kBAAkB,EAAE,EAAE;QACtB,mBAAmB,EAAE,EAAE;KACxB,CAAC;AACJ,CAAC;AAND,0EAMC;AAED,yBAAyB;AAEzB,MAAM,wBAAwB,GAAyC;IACrE,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,qBAAqB;AAErB;;;;;;;GAOG;AACH,MAAa,gBAAiB,SAAQ,gCAIrC;IACC,YAAY,EAAE,SAAS,EAAE,KAAK,EAA2B;QACvD,KAAK,CAAC;YACJ,IAAI,EAAE,oCAAc;YACpB,QAAQ,EAAE,wBAAwB;YAClC,KAAK,EAAE;gBACL,GAAG,+BAA+B,EAAE;gBACpC,GAAG,KAAK;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,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,CAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACxD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACzD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAChE,CAAC;CACF;AAvJD,4CAuJC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { controllerName } from './social-constants.js';\nimport type {\n FetchLeaderboardOptions,\n FollowOptions,\n FollowResponse,\n FollowingResponse,\n LeaderboardResponse,\n SocialControllerState,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types.js';\nimport type { SocialControllerMethodActions } from './SocialController-method-action-types.js';\nimport type {\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFollowAction,\n SocialServiceOptInToLeaderboardAction,\n SocialServiceOptOutOfLeaderboardAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types.js';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'updateLeaderboard',\n 'followTrader',\n 'unfollowTrader',\n 'updateFollowing',\n 'optOutOfLeaderboard',\n 'optInToLeaderboard',\n] as const;\n\n// === ACTION TYPES ===\n\nexport type SocialControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerActions =\n | SocialControllerGetStateAction\n | SocialControllerMethodActions;\n\n// === EVENT TYPES ===\n\nexport type SocialControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerEvents = SocialControllerStateChangeEvent;\n\n// === ALLOWED ACTIONS/EVENTS ===\n\ntype AllowedActions =\n | SocialServiceFetchLeaderboardAction\n | SocialServiceFollowAction\n | SocialServiceUnfollowAction\n | SocialServiceFetchFollowingAction\n | SocialServiceOptOutOfLeaderboardAction\n | SocialServiceOptInToLeaderboardAction;\n\ntype AllowedEvents = never;\n\n// === MESSENGER TYPE ===\n\nexport type SocialControllerMessenger = Messenger<\n typeof controllerName,\n SocialControllerActions | AllowedActions,\n SocialControllerEvents | AllowedEvents\n>;\n\n// === OPTIONS ===\n\nexport type SocialControllerOptions = {\n messenger: SocialControllerMessenger;\n state?: Partial<SocialControllerState>;\n};\n\n// === DEFAULT STATE ===\n\n/**\n * Returns the default state for the SocialController.\n *\n * @returns A fresh default state object.\n */\nexport function getDefaultSocialControllerState(): SocialControllerState {\n return {\n leaderboardEntries: [],\n followingAddresses: [],\n followingProfileIds: [],\n };\n}\n\n// === STATE METADATA ===\n\nconst socialControllerMetadata: StateMetadata<SocialControllerState> = {\n leaderboardEntries: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n followingAddresses: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n followingProfileIds: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n};\n\n// === CONTROLLER ===\n\n/**\n * Controller that manages social trading state for the extension UI.\n *\n * Acts as a simple store with no TTL or eviction — the UI decides when\n * to re-fetch, and the social-api's own cache layer handles upstream\n * rate-limiting. State is persisted across sessions so the UI can render\n * immediately on startup while a fresh fetch is in flight.\n */\nexport class SocialController extends BaseController<\n typeof controllerName,\n SocialControllerState,\n SocialControllerMessenger\n> {\n constructor({ messenger, state }: SocialControllerOptions) {\n super({\n name: controllerName,\n metadata: socialControllerMetadata,\n state: {\n ...getDefaultSocialControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\n async updateLeaderboard(\n options?: FetchLeaderboardOptions,\n ): Promise<LeaderboardResponse> {\n const leaderboardResponse = await this.messenger.call(\n 'SocialService:fetchLeaderboard',\n options,\n );\n\n this.update((state) => {\n state.leaderboardEntries = leaderboardResponse.traders;\n });\n\n return leaderboardResponse;\n }\n\n /**\n * Follows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\n async followTrader(options: FollowOptions): Promise<FollowResponse> {\n const followResponse = await this.messenger.call(\n 'SocialService:follow',\n options,\n );\n\n const newAddresses = [\n ...new Set(followResponse.followed.map((profile) => profile.address)),\n ];\n const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\n ];\n\n this.update((state) => {\n const existing = new Set(state.followingAddresses);\n const uniqueNewAddresses = newAddresses.filter(\n (address) => !existing.has(address),\n );\n state.followingAddresses.push(...uniqueNewAddresses);\n\n const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\n async unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse> {\n const unfollowResponse = await this.messenger.call(\n 'SocialService:unfollow',\n options,\n );\n\n const removedAddresses = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.address),\n );\n const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\n );\n });\n\n return unfollowResponse;\n }\n\n /**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\n async updateFollowing(): Promise<FollowingResponse> {\n const followingResponse = await this.messenger.call(\n 'SocialService:fetchFollowing',\n );\n\n this.update((state) => {\n state.followingAddresses = followingResponse.following.map(\n (profile) => profile.address,\n );\n state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n\n /**\n * Opts the current user out of the PnL leaderboard.\n */\n async optOutOfLeaderboard(): Promise<void> {\n await this.messenger.call('SocialService:optOutOfLeaderboard');\n }\n\n /**\n * Opts the current user back into the PnL leaderboard.\n */\n async optInToLeaderboard(): Promise<void> {\n await this.messenger.call('SocialService:optInToLeaderboard');\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
- import { BaseController } from '@metamask/base-controller';
3
- import type { Messenger } from '@metamask/messenger';
4
- import { controllerName } from './social-constants.js';
5
- import type { FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from './social-types.js';
6
- import type { SocialControllerMethodActions } from './SocialController-method-action-types.js';
7
- import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceOptInToLeaderboardAction, SocialServiceOptOutOfLeaderboardAction, SocialServiceUnfollowAction } from './SocialService-method-action-types.js';
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import { controllerName } from "./social-constants.cjs";
5
+ import type { FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.cjs";
6
+ import type { SocialControllerMethodActions } from "./SocialController-method-action-types.cjs";
7
+ import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceOptInToLeaderboardAction, SocialServiceOptOutOfLeaderboardAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.cjs";
8
8
  export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
9
9
  export type SocialControllerActions = SocialControllerGetStateAction | SocialControllerMethodActions;
10
10
  export type SocialControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SocialControllerState>;
@@ -77,4 +77,4 @@ export declare class SocialController extends BaseController<typeof controllerNa
77
77
  optInToLeaderboard(): Promise<void>;
78
78
  }
79
79
  export {};
80
- //# sourceMappingURL=SocialController.d.ts.map
80
+ //# sourceMappingURL=SocialController.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.d.cts","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE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,cAAc,CAClD,OAAO,cAAc,EACrB,qBAAqB,EACrB,yBAAyB,CAC1B;gBACa,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAiBzD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAa/B;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BnE;;;;;;;;OAQG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBzE;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAiBnD;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1C"}
@@ -0,0 +1,80 @@
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
3
+ import type { Messenger } from "@metamask/messenger";
4
+ import { controllerName } from "./social-constants.mjs";
5
+ import type { FetchLeaderboardOptions, FollowOptions, FollowResponse, FollowingResponse, LeaderboardResponse, SocialControllerState, UnfollowOptions, UnfollowResponse } from "./social-types.mjs";
6
+ import type { SocialControllerMethodActions } from "./SocialController-method-action-types.mjs";
7
+ import type { SocialServiceFetchFollowingAction, SocialServiceFetchLeaderboardAction, SocialServiceFollowAction, SocialServiceOptInToLeaderboardAction, SocialServiceOptOutOfLeaderboardAction, SocialServiceUnfollowAction } from "./SocialService-method-action-types.mjs";
8
+ export type SocialControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SocialControllerState>;
9
+ export type SocialControllerActions = SocialControllerGetStateAction | SocialControllerMethodActions;
10
+ export type SocialControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SocialControllerState>;
11
+ export type SocialControllerEvents = SocialControllerStateChangeEvent;
12
+ type AllowedActions = SocialServiceFetchLeaderboardAction | SocialServiceFollowAction | SocialServiceUnfollowAction | SocialServiceFetchFollowingAction | SocialServiceOptOutOfLeaderboardAction | SocialServiceOptInToLeaderboardAction;
13
+ type AllowedEvents = never;
14
+ export type SocialControllerMessenger = Messenger<typeof controllerName, SocialControllerActions | AllowedActions, SocialControllerEvents | AllowedEvents>;
15
+ export type SocialControllerOptions = {
16
+ messenger: SocialControllerMessenger;
17
+ state?: Partial<SocialControllerState>;
18
+ };
19
+ /**
20
+ * Returns the default state for the SocialController.
21
+ *
22
+ * @returns A fresh default state object.
23
+ */
24
+ export declare function getDefaultSocialControllerState(): SocialControllerState;
25
+ /**
26
+ * Controller that manages social trading state for the extension UI.
27
+ *
28
+ * Acts as a simple store with no TTL or eviction — the UI decides when
29
+ * to re-fetch, and the social-api's own cache layer handles upstream
30
+ * rate-limiting. State is persisted across sessions so the UI can render
31
+ * immediately on startup while a fresh fetch is in flight.
32
+ */
33
+ export declare class SocialController extends BaseController<typeof controllerName, SocialControllerState, SocialControllerMessenger> {
34
+ constructor({ messenger, state }: SocialControllerOptions);
35
+ /**
36
+ * Fetches the leaderboard and persists the entries to state.
37
+ *
38
+ * @param options - Optional leaderboard query parameters.
39
+ * @returns The leaderboard response from the social-api.
40
+ */
41
+ updateLeaderboard(options?: FetchLeaderboardOptions): Promise<LeaderboardResponse>;
42
+ /**
43
+ * Follows one or more traders on behalf of the current user and updates
44
+ * the following list in state. The caller is identified server-side from
45
+ * the JWT attached by the SocialService.
46
+ *
47
+ * @param options - Options bag.
48
+ * @param options.targets - Addresses or profile IDs to follow.
49
+ * @returns The follow response with confirmed follows.
50
+ */
51
+ followTrader(options: FollowOptions): Promise<FollowResponse>;
52
+ /**
53
+ * Unfollows one or more traders on behalf of the current user and updates
54
+ * the following list in state. The caller is identified server-side from
55
+ * the JWT attached by the SocialService.
56
+ *
57
+ * @param options - Options bag.
58
+ * @param options.targets - Addresses or profile IDs to unfollow.
59
+ * @returns The unfollow response with confirmed unfollows.
60
+ */
61
+ unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse>;
62
+ /**
63
+ * Fetches the list of traders the current user follows and replaces
64
+ * the following addresses in state. The caller is identified server-side
65
+ * from the JWT attached by the SocialService.
66
+ *
67
+ * @returns The following response.
68
+ */
69
+ updateFollowing(): Promise<FollowingResponse>;
70
+ /**
71
+ * Opts the current user out of the PnL leaderboard.
72
+ */
73
+ optOutOfLeaderboard(): Promise<void>;
74
+ /**
75
+ * Opts the current user back into the PnL leaderboard.
76
+ */
77
+ optInToLeaderboard(): Promise<void>;
78
+ }
79
+ export {};
80
+ //# sourceMappingURL=SocialController.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.d.mts","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,cAAc,EAAE,+BAA8B;AACvD,OAAO,KAAK,EACV,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EACjB,2BAA0B;AAC3B,OAAO,KAAK,EAAE,6BAA6B,EAAE,mDAAkD;AAC/F,OAAO,KAAK,EACV,iCAAiC,EACjC,mCAAmC,EACnC,yBAAyB,EACzB,qCAAqC,EACrC,sCAAsC,EACtC,2BAA2B,EAC5B,gDAA+C;AAehD,MAAM,MAAM,8BAA8B,GAAG,wBAAwB,CACnE,OAAO,cAAc,EACrB,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,8BAA8B,GAC9B,6BAA6B,CAAC;AAIlC,MAAM,MAAM,gCAAgC,GAAG,0BAA0B,CACvE,OAAO,cAAc,EACrB,qBAAqB,CACtB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,gCAAgC,CAAC;AAItE,KAAK,cAAc,GACf,mCAAmC,GACnC,yBAAyB,GACzB,2BAA2B,GAC3B,iCAAiC,GACjC,sCAAsC,GACtC,qCAAqC,CAAC;AAE1C,KAAK,aAAa,GAAG,KAAK,CAAC;AAI3B,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAC/C,OAAO,cAAc,EACrB,uBAAuB,GAAG,cAAc,EACxC,sBAAsB,GAAG,aAAa,CACvC,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,yBAAyB,CAAC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACxC,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,+BAA+B,IAAI,qBAAqB,CAMvE;AA2BD;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAClD,OAAO,cAAc,EACrB,qBAAqB,EACrB,yBAAyB,CAC1B;gBACa,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAiBzD;;;;;OAKG;IACG,iBAAiB,CACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAa/B;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BnE;;;;;;;;OAQG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyBzE;;;;;;OAMG;IACG,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAiBnD;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAG1C"}
@@ -1,5 +1,5 @@
1
- import { BaseController } from '@metamask/base-controller';
2
- import { controllerName } from './social-constants.js';
1
+ import { BaseController } from "@metamask/base-controller";
2
+ import { controllerName } from "./social-constants.mjs";
3
3
  // === MESSENGER ===
4
4
  const MESSENGER_EXPOSED_METHODS = [
5
5
  'updateLeaderboard',
@@ -152,4 +152,4 @@ export class SocialController extends BaseController {
152
152
  await this.messenger.call('SocialService:optInToLeaderboard');
153
153
  }
154
154
  }
155
- //# sourceMappingURL=SocialController.js.map
155
+ //# sourceMappingURL=SocialController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialController.mjs","sourceRoot":"","sources":["../src/SocialController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,cAAc,EAAE,+BAA8B;AAqBvD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,mBAAmB;IACnB,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,qBAAqB;IACrB,oBAAoB;CACZ,CAAC;AAiDX,wBAAwB;AAExB;;;;GAIG;AACH,MAAM,UAAU,+BAA+B;IAC7C,OAAO;QACL,kBAAkB,EAAE,EAAE;QACtB,kBAAkB,EAAE,EAAE;QACtB,mBAAmB,EAAE,EAAE;KACxB,CAAC;AACJ,CAAC;AAED,yBAAyB;AAEzB,MAAM,wBAAwB,GAAyC;IACrE,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;QACnB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,qBAAqB;AAErB;;;;;;;GAOG;AACH,MAAM,OAAO,gBAA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,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAC1D,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CACnC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,8BAA8B,CAC/B,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACxD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;YACF,KAAK,CAAC,mBAAmB,GAAG,iBAAiB,CAAC,SAAS,CAAC,GAAG,CACzD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAC/B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { controllerName } from './social-constants.js';\nimport type {\n FetchLeaderboardOptions,\n FollowOptions,\n FollowResponse,\n FollowingResponse,\n LeaderboardResponse,\n SocialControllerState,\n UnfollowOptions,\n UnfollowResponse,\n} from './social-types.js';\nimport type { SocialControllerMethodActions } from './SocialController-method-action-types.js';\nimport type {\n SocialServiceFetchFollowingAction,\n SocialServiceFetchLeaderboardAction,\n SocialServiceFollowAction,\n SocialServiceOptInToLeaderboardAction,\n SocialServiceOptOutOfLeaderboardAction,\n SocialServiceUnfollowAction,\n} from './SocialService-method-action-types.js';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'updateLeaderboard',\n 'followTrader',\n 'unfollowTrader',\n 'updateFollowing',\n 'optOutOfLeaderboard',\n 'optInToLeaderboard',\n] as const;\n\n// === ACTION TYPES ===\n\nexport type SocialControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerActions =\n | SocialControllerGetStateAction\n | SocialControllerMethodActions;\n\n// === EVENT TYPES ===\n\nexport type SocialControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SocialControllerState\n>;\n\nexport type SocialControllerEvents = SocialControllerStateChangeEvent;\n\n// === ALLOWED ACTIONS/EVENTS ===\n\ntype AllowedActions =\n | SocialServiceFetchLeaderboardAction\n | SocialServiceFollowAction\n | SocialServiceUnfollowAction\n | SocialServiceFetchFollowingAction\n | SocialServiceOptOutOfLeaderboardAction\n | SocialServiceOptInToLeaderboardAction;\n\ntype AllowedEvents = never;\n\n// === MESSENGER TYPE ===\n\nexport type SocialControllerMessenger = Messenger<\n typeof controllerName,\n SocialControllerActions | AllowedActions,\n SocialControllerEvents | AllowedEvents\n>;\n\n// === OPTIONS ===\n\nexport type SocialControllerOptions = {\n messenger: SocialControllerMessenger;\n state?: Partial<SocialControllerState>;\n};\n\n// === DEFAULT STATE ===\n\n/**\n * Returns the default state for the SocialController.\n *\n * @returns A fresh default state object.\n */\nexport function getDefaultSocialControllerState(): SocialControllerState {\n return {\n leaderboardEntries: [],\n followingAddresses: [],\n followingProfileIds: [],\n };\n}\n\n// === STATE METADATA ===\n\nconst socialControllerMetadata: StateMetadata<SocialControllerState> = {\n leaderboardEntries: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n followingAddresses: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n followingProfileIds: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n usedInUi: true,\n },\n};\n\n// === CONTROLLER ===\n\n/**\n * Controller that manages social trading state for the extension UI.\n *\n * Acts as a simple store with no TTL or eviction — the UI decides when\n * to re-fetch, and the social-api's own cache layer handles upstream\n * rate-limiting. State is persisted across sessions so the UI can render\n * immediately on startup while a fresh fetch is in flight.\n */\nexport class SocialController extends BaseController<\n typeof controllerName,\n SocialControllerState,\n SocialControllerMessenger\n> {\n constructor({ messenger, state }: SocialControllerOptions) {\n super({\n name: controllerName,\n metadata: socialControllerMetadata,\n state: {\n ...getDefaultSocialControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches the leaderboard and persists the entries to state.\n *\n * @param options - Optional leaderboard query parameters.\n * @returns The leaderboard response from the social-api.\n */\n async updateLeaderboard(\n options?: FetchLeaderboardOptions,\n ): Promise<LeaderboardResponse> {\n const leaderboardResponse = await this.messenger.call(\n 'SocialService:fetchLeaderboard',\n options,\n );\n\n this.update((state) => {\n state.leaderboardEntries = leaderboardResponse.traders;\n });\n\n return leaderboardResponse;\n }\n\n /**\n * Follows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\n async followTrader(options: FollowOptions): Promise<FollowResponse> {\n const followResponse = await this.messenger.call(\n 'SocialService:follow',\n options,\n );\n\n const newAddresses = [\n ...new Set(followResponse.followed.map((profile) => profile.address)),\n ];\n const newProfileIds = [\n ...new Set(followResponse.followed.map((profile) => profile.profileId)),\n ];\n\n this.update((state) => {\n const existing = new Set(state.followingAddresses);\n const uniqueNewAddresses = newAddresses.filter(\n (address) => !existing.has(address),\n );\n state.followingAddresses.push(...uniqueNewAddresses);\n\n const existingIds = new Set(state.followingProfileIds);\n const uniqueNewIds = newProfileIds.filter((id) => !existingIds.has(id));\n state.followingProfileIds.push(...uniqueNewIds);\n });\n\n return followResponse;\n }\n\n /**\n * Unfollows one or more traders on behalf of the current user and updates\n * the following list in state. The caller is identified server-side from\n * the JWT attached by the SocialService.\n *\n * @param options - Options bag.\n * @param options.targets - Addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\n async unfollowTrader(options: UnfollowOptions): Promise<UnfollowResponse> {\n const unfollowResponse = await this.messenger.call(\n 'SocialService:unfollow',\n options,\n );\n\n const removedAddresses = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.address),\n );\n const removedProfileIds = new Set(\n unfollowResponse.unfollowed.map((profile) => profile.profileId),\n );\n\n this.update((state) => {\n state.followingAddresses = state.followingAddresses.filter(\n (address) => !removedAddresses.has(address),\n );\n state.followingProfileIds = state.followingProfileIds.filter(\n (id) => !removedProfileIds.has(id),\n );\n });\n\n return unfollowResponse;\n }\n\n /**\n * Fetches the list of traders the current user follows and replaces\n * the following addresses in state. The caller is identified server-side\n * from the JWT attached by the SocialService.\n *\n * @returns The following response.\n */\n async updateFollowing(): Promise<FollowingResponse> {\n const followingResponse = await this.messenger.call(\n 'SocialService:fetchFollowing',\n );\n\n this.update((state) => {\n state.followingAddresses = followingResponse.following.map(\n (profile) => profile.address,\n );\n state.followingProfileIds = followingResponse.following.map(\n (profile) => profile.profileId,\n );\n });\n\n return followingResponse;\n }\n\n /**\n * Opts the current user out of the PnL leaderboard.\n */\n async optOutOfLeaderboard(): Promise<void> {\n await this.messenger.call('SocialService:optOutOfLeaderboard');\n }\n\n /**\n * Opts the current user back into the PnL leaderboard.\n */\n async optInToLeaderboard(): Promise<void> {\n await this.messenger.call('SocialService:optInToLeaderboard');\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=SocialService-method-action-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialService-method-action-types.cjs","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SocialService } from './SocialService.js';\n\n/**\n * Fetches the leaderboard of top traders.\n *\n * Calls `GET ${baseUrl}/leaderboard`.\n *\n * @param options - Optional query parameters for sorting, chain filtering, and limit.\n * @returns The leaderboard response with ranked traders.\n */\nexport type SocialServiceFetchLeaderboardAction = {\n type: `SocialService:fetchLeaderboard`;\n handler: SocialService['fetchLeaderboard'];\n};\n\n/**\n * Fetches a trader's profile by address or profile ID.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/profile`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The trader profile response.\n */\nexport type SocialServiceFetchTraderProfileAction = {\n type: `SocialService:fetchTraderProfile`;\n handler: SocialService['fetchTraderProfile'];\n};\n\n/**\n * Fetches a trader's open positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/open`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchOpenPositionsAction = {\n type: `SocialService:fetchOpenPositions`;\n handler: SocialService['fetchOpenPositions'];\n};\n\n/**\n * Fetches a trader's closed positions.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/positions/closed`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @param options.chain - Filter by chain.\n * @param options.sort - Sort by 'value' or 'latest'.\n * @param options.limit - Number of results per page.\n * @param options.page - Page number (1-based).\n * @returns The positions response.\n */\nexport type SocialServiceFetchClosedPositionsAction = {\n type: `SocialService:fetchClosedPositions`;\n handler: SocialService['fetchClosedPositions'];\n};\n\n/**\n * Fetches a trader's MetaMask followers.\n *\n * Calls `GET ${baseUrl}/traders/${addressOrId}/followers`.\n *\n * @param options - Options bag.\n * @param options.addressOrId - Wallet address or Clicker profile ID.\n * @returns The followers response.\n */\nexport type SocialServiceFetchFollowersAction = {\n type: `SocialService:fetchFollowers`;\n handler: SocialService['fetchFollowers'];\n};\n\n/**\n * Fetches a single position by its unique ID.\n *\n * Calls `GET ${baseUrl}/traders/position/${positionId}`.\n *\n * @param options - Options bag.\n * @param options.positionId - Unique position ID (UUID).\n * @returns The position.\n */\nexport type SocialServiceFetchPositionByIdAction = {\n type: `SocialService:fetchPositionById`;\n handler: SocialService['fetchPositionById'];\n};\n\n/**\n * Fetches a page of the trader-activity feed.\n *\n * Calls `GET ${baseUrl}/feed`. For the `following` scope the current user is\n * identified server-side from the JWT sub claim carried in the Authorization\n * header; the `leaderboard` scope is generic and shared by all users.\n *\n * Cursor pagination supports infinite scroll: pass `pagination.olderCursor`\n * from a prior response back as `olderThan` to load older items, and\n * `pagination.newerCursor` as `newerThan` to fetch newer items.\n *\n * @param options - Options bag.\n * @param options.scope - `following` (default) or `leaderboard`.\n * @param options.chains - Filter by one or more chains.\n * @param options.limit - Number of results per page.\n * @param options.olderThan - Cursor for older items (scroll down).\n * @param options.newerThan - Cursor for newer items (refresh).\n * @returns The feed response with items and pagination cursors.\n */\nexport type SocialServiceFetchFeedAction = {\n type: `SocialService:fetchFeed`;\n handler: SocialService['fetchFeed'];\n};\n\n/**\n * Fetches the list of traders the current user is following.\n *\n * Calls `GET ${baseUrl}/users/me/following`. The caller is identified\n * server-side from the JWT sub claim carried in the Authorization header.\n *\n * @returns The following response.\n */\nexport type SocialServiceFetchFollowingAction = {\n type: `SocialService:fetchFollowing`;\n handler: SocialService['fetchFollowing'];\n};\n\n/**\n * Follows one or more traders on behalf of the current user.\n *\n * Calls `PUT ${baseUrl}/users/me/follows`. The caller is identified\n * server-side from the JWT sub claim carried in the Authorization header.\n *\n * @param options - Options bag.\n * @param options.targets - Array of wallet addresses or profile IDs to follow.\n * @returns The follow response with confirmed follows.\n */\nexport type SocialServiceFollowAction = {\n type: `SocialService:follow`;\n handler: SocialService['follow'];\n};\n\n/**\n * Unfollows one or more traders on behalf of the current user.\n *\n * Calls `DELETE ${baseUrl}/users/me/follows?targets=...`. Targets are sent\n * as query params because Fastify does not parse request bodies on DELETE\n * requests per RFC 9110. The caller is identified server-side from the JWT\n * sub claim carried in the Authorization header.\n *\n * @param options - Options bag.\n * @param options.targets - Array of wallet addresses or profile IDs to unfollow.\n * @returns The unfollow response with confirmed unfollows.\n */\nexport type SocialServiceUnfollowAction = {\n type: `SocialService:unfollow`;\n handler: SocialService['unfollow'];\n};\n\n/**\n * Opts the current user out of the PnL leaderboard.\n */\nexport type SocialServiceOptOutOfLeaderboardAction = {\n type: `SocialService:optOutOfLeaderboard`;\n handler: SocialService['optOutOfLeaderboard'];\n};\n\n/**\n * Opts the current user back into the PnL leaderboard.\n */\nexport type SocialServiceOptInToLeaderboardAction = {\n type: `SocialService:optInToLeaderboard`;\n handler: SocialService['optInToLeaderboard'];\n};\n\n/**\n * Asks the social-api to refresh its cached copy of the current user's\n * notification preferences.\n *\n * Calls `POST ${baseUrl}/notifications/preferences/cache-refresh`. The caller\n * is identified server-side from the JWT sub claim carried in the\n * Authorization header, so it can only ever refresh its own entry.\n *\n * The client calls this immediately after writing a preference change to\n * Authenticated User Storage (AUS), which is the source of truth. The social\n * api re-reads from AUS and repopulates its cache so the change is honoured\n * near-instantly rather than after the cache TTL lapses. It is a pure\n * optimisation on top of that bounded TTL: the write has already succeeded by\n * the time this runs, so callers should treat it as best-effort and must not\n * roll back the AUS write if it fails.\n */\nexport type SocialServiceRefreshNotificationPreferencesCacheAction = {\n type: `SocialService:refreshNotificationPreferencesCache`;\n handler: SocialService['refreshNotificationPreferencesCache'];\n};\n\n/**\n * Union of all SocialService action types.\n */\nexport type SocialServiceMethodActions =\n | SocialServiceFetchLeaderboardAction\n | SocialServiceFetchTraderProfileAction\n | SocialServiceFetchOpenPositionsAction\n | SocialServiceFetchClosedPositionsAction\n | SocialServiceFetchFollowersAction\n | SocialServiceFetchPositionByIdAction\n | SocialServiceFetchFeedAction\n | SocialServiceFetchFollowingAction\n | SocialServiceFollowAction\n | SocialServiceUnfollowAction\n | SocialServiceOptOutOfLeaderboardAction\n | SocialServiceOptInToLeaderboardAction\n | SocialServiceRefreshNotificationPreferencesCacheAction;\n"]}
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { SocialService } from './SocialService.js';
5
+ import type { SocialService } from "./SocialService.cjs";
6
6
  /**
7
7
  * Fetches the leaderboard of top traders.
8
8
  *
@@ -191,4 +191,4 @@ export type SocialServiceRefreshNotificationPreferencesCacheAction = {
191
191
  * Union of all SocialService action types.
192
192
  */
193
193
  export type SocialServiceMethodActions = SocialServiceFetchLeaderboardAction | SocialServiceFetchTraderProfileAction | SocialServiceFetchOpenPositionsAction | SocialServiceFetchClosedPositionsAction | SocialServiceFetchFollowersAction | SocialServiceFetchPositionByIdAction | SocialServiceFetchFeedAction | SocialServiceFetchFollowingAction | SocialServiceFollowAction | SocialServiceUnfollowAction | SocialServiceOptOutOfLeaderboardAction | SocialServiceOptInToLeaderboardAction | SocialServiceRefreshNotificationPreferencesCacheAction;
194
- //# sourceMappingURL=SocialService-method-action-types.d.ts.map
194
+ //# sourceMappingURL=SocialService-method-action-types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialService-method-action-types.d.cts","sourceRoot":"","sources":["../src/SocialService-method-action-types.ts"],"names":[],"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