@smartico/public-api 0.0.416 → 0.0.418

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.416",
3
+ "version": "0.0.418",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,22 @@
1
+ /** Activity-log entry type as returned on the v2 wire (`type_id`). */
2
+ export enum ActivityLogActivities {
3
+ Gems = 1,
4
+ Diamonds = 2,
5
+ Points = 3,
6
+ LevelChanged = 4,
7
+ Bonus = 5,
8
+ PrizeDrop = 6,
9
+ Minigame = 7,
10
+ RaffleTicket = 8,
11
+ Avatar = 9,
12
+ Task = 10,
13
+ Mission = 11,
14
+ Badge = 12,
15
+ TangiblePrize = 13,
16
+ Jackpot = 14,
17
+ Spin = 15,
18
+ NoPrize = 16,
19
+ Leaderboard = 17,
20
+ Tournament = 18,
21
+ ClanTournament = 19,
22
+ }
@@ -0,0 +1,8 @@
1
+ export interface ActivityLogMeta {
2
+ name?: string;
3
+ image_url?: string;
4
+ position?: number;
5
+ user_points_balance_before?: number;
6
+ points_requested?: number;
7
+ user_points_ever?: number;
8
+ }
@@ -6,6 +6,8 @@ export interface GetActivityLogRequest extends ProtocolMessage {
6
6
  endTimeSeconds: number;
7
7
  limit: number;
8
8
  offset: number;
9
+ /** Optional v2 filter — {@link ActivityLogActivities} values to include. */
10
+ types?: number[];
9
11
  }
10
12
 
11
13
 
@@ -1,6 +1,7 @@
1
1
  import { ProtocolResponse } from '../Base/ProtocolResponse';
2
2
  import { ActivityLogEntry } from './ActivityLogEntry';
3
- import { TActivityLog } from '../WSAPI/WSAPITypes';
3
+ import { ActivityLogActivities } from './ActivityLogActivities';
4
+ import { TActivityLog, TActivityLogEntry } from '../WSAPI/WSAPITypes';
4
5
  import { UserBalanceType } from './UserBalanceType';
5
6
 
6
7
  export interface GetActivityLogResponse extends ProtocolResponse {
@@ -14,11 +15,11 @@ export const ActivityLogTransform = (items: ActivityLogEntry[]): TActivityLog[]
14
15
 
15
16
  return items.map((item: any): TActivityLog => {
16
17
  const itemTransformed: Partial<TActivityLog> = {
17
- create_date: item.create_date,
18
+ create_date: item.create_date?.seconds ?? item.create_date,
18
19
  user_ext_id: item.user_ext_id,
19
20
  crm_brand_id: item.crm_brand_id,
20
21
  source_type_id: item.source_type_id,
21
- }
22
+ };
22
23
 
23
24
  item.type = item.type ?? UserBalanceType.Points;
24
25
 
@@ -39,4 +40,37 @@ export const ActivityLogTransform = (items: ActivityLogEntry[]): TActivityLog[]
39
40
  });
40
41
  };
41
42
 
43
+ export const ActivityLogV2Transform = (items: any[]): TActivityLogEntry[] => {
44
+ if (!items) {
45
+ return [];
46
+ }
42
47
 
48
+ return items.map((r) => {
49
+ const isGems = r.type_id === ActivityLogActivities.Gems || r.type === UserBalanceType.Gems;
50
+ const isDiamonds = r.type_id === ActivityLogActivities.Diamonds || r.type === UserBalanceType.Diamonds;
51
+
52
+ const x: TActivityLogEntry = {
53
+ create_date: r.create_date?.seconds ?? r.create_date,
54
+ user_ext_id: r.user_ext_id,
55
+ crm_brand_id: r.crm_brand_id,
56
+ type: isGems ? UserBalanceType.Gems : isDiamonds ? UserBalanceType.Diamonds : UserBalanceType.Points,
57
+ amount: r.points_collected ?? r.amount,
58
+ balance: r.user_points_balance ?? r.balance,
59
+ total_ever: r.user_points_ever,
60
+ source_type_id: r.source_type_id,
61
+ activity_type_id: r.type_id,
62
+ context_value_1: r.context_value_1,
63
+ meta: r.context_value_meta,
64
+ source_entity_name: r.source_entity_name,
65
+ source_entity_id: r.source_entity_id,
66
+ source_reference_id: r.source_reference_id,
67
+ source_root_id: r.source_root_id,
68
+ is_wallet_entry:
69
+ r.type_id == null
70
+ || r.type_id === ActivityLogActivities.Gems
71
+ || r.type_id === ActivityLogActivities.Diamonds
72
+ || r.type_id === ActivityLogActivities.Points,
73
+ };
74
+ return x;
75
+ });
76
+ };
@@ -1,7 +1,7 @@
1
1
  export * from './GetActivityLogRequest';
2
2
  export * from './GetActivityLogResponse';
3
3
  export * from './ActivityLogEntry';
4
+ export * from './ActivityLogActivities';
5
+ export * from './ActivityLogMeta';
4
6
  export * from './PointChangeSourceType';
5
7
  export * from './UserBalanceType';
6
-
7
-
@@ -102,6 +102,7 @@ import {
102
102
  TRaffle,
103
103
  TLevelCurrent,
104
104
  TActivityLog,
105
+ TActivityLogEntry,
105
106
  TRaffleDraw,
106
107
  TAvatarDefinition,
107
108
  TAvatarCustomized,
@@ -136,7 +137,7 @@ import { GetRelatedAchTourRequest } from './Missions/GetRelatedAchTourRequest';
136
137
  import { GetRelatedAchTourResponse } from './Missions/GetRelatedAchTourResponse';
137
138
  import { GetRafflesResponse, raffleTransform } from './Raffle/GetRafflesResponse';
138
139
  import { GetRafflesRequest } from './Raffle/GetRafflesRequest';
139
- import { GetActivityLogRequest, GetActivityLogResponse, ActivityLogTransform } from './ActivityLog';
140
+ import { GetActivityLogRequest, GetActivityLogResponse, ActivityLogTransform, ActivityLogV2Transform } from './ActivityLog';
140
141
  import { GetClanListRequest, GetClanListResponse, GetClanInfoRequest, GetClanInfoResponse, JoinClanRequest, JoinClanResponse } from './Clans';
141
142
  import { InboxCategories } from './Inbox/InboxCategories';
142
143
  import { GetDrawRunRequest, GetDrawRunResponse, GetRaffleDrawRunsHistoryRequest, GetRaffleDrawRunsHistoryResponse, RaffleClaimPrizeRequest, RaffleClaimPrizeResponse, RaffleOptinRequest, RaffleOptinResponse, drawRunTransform, GetRaffleWonPrizesRequest, GetRaffleWonPrizesResponse } from './Raffle';
@@ -1778,6 +1779,29 @@ class SmarticoAPI {
1778
1779
  return await this.send<GetActivityLogResponse>(message, ClassId.GET_POINT_HISTORY_RESPONSE);
1779
1780
  }
1780
1781
 
1782
+ public async getActivityLogV2(
1783
+ user_ext_id: string,
1784
+ startTimeSeconds: number,
1785
+ endTimeSeconds: number,
1786
+ limit: number,
1787
+ offset: number,
1788
+ types?: number[],
1789
+ ): Promise<GetActivityLogResponse> {
1790
+ const message = this.buildMessage<GetActivityLogRequest, GetActivityLogResponse>(
1791
+ user_ext_id,
1792
+ ClassId.GET_POINT_HISTORY_REQUEST,
1793
+ {
1794
+ startTimeSeconds: Math.floor(startTimeSeconds),
1795
+ endTimeSeconds: Math.floor(endTimeSeconds),
1796
+ limit,
1797
+ offset,
1798
+ ...(types ? { types } : {}),
1799
+ },
1800
+ );
1801
+
1802
+ return await this.send<GetActivityLogResponse>(message, ClassId.GET_POINT_HISTORY_RESPONSE);
1803
+ }
1804
+
1781
1805
  public async getActivityLogT(
1782
1806
  user_ext_id: string,
1783
1807
  startTimeSeconds: number,
@@ -1792,6 +1816,22 @@ class SmarticoAPI {
1792
1816
  (await this.getActivityLog(user_ext_id, startTimeSeconds, endTimeSeconds, limit, offset)).logHistory,
1793
1817
  );
1794
1818
  }
1819
+
1820
+ public async getActivityLogV2T(
1821
+ user_ext_id: string,
1822
+ startTimeSeconds: number,
1823
+ endTimeSeconds: number,
1824
+ from: number = 0,
1825
+ to: number = 50,
1826
+ types?: number[],
1827
+ ): Promise<TActivityLogEntry[]> {
1828
+ const limit = to - from > 50 ? 50 : to - from;
1829
+ const offset = from;
1830
+
1831
+ return ActivityLogV2Transform(
1832
+ (await this.getActivityLogV2(user_ext_id, startTimeSeconds, endTimeSeconds, limit, offset, types)).logHistory,
1833
+ );
1834
+ }
1795
1835
  }
1796
1836
 
1797
1837
  export { SmarticoAPI, MessageSender };
@@ -40,6 +40,7 @@ export enum onUpdateContextKey {
40
40
  CurrentLevel = 'currentLevel',
41
41
  InboxUnreadCount = 'inboxUnreadCount',
42
42
  ActivityLog = 'activityLog',
43
+ ActivityLogV2 = 'activityLogV2',
43
44
  AvatarsList = 'avatarsList',
44
45
  AvatarsCustomized = 'avatarsCustomized',
45
46
  AvatarPrompts = 'avatarPrompts',
@@ -7,6 +7,8 @@ import { AchCustomLayoutTheme, AchCustomSectionType, AchMissionsTabsOptions, Ach
7
7
  import { PrizeModifiers } from '../MiniGames/PrizeModifiers';
8
8
  import { InboxCategories } from '../Inbox/InboxCategories';
9
9
  import { RaffleDrawInstanceState, RaffleDrawTypeExecution, RaffleTicketCapVisualization } from '../Raffle';
10
+ import { ActivityLogActivities } from '../ActivityLog/ActivityLogActivities';
11
+ import { ActivityLogMeta } from '../ActivityLog/ActivityLogMeta';
10
12
  import { PointChangeSourceType } from '../ActivityLog/PointChangeSourceType';
11
13
  import { UserBalanceType } from '../ActivityLog/UserBalanceType';
12
14
  import { SAWGPMarketType } from '../GamePick/MarketsType';
@@ -1804,6 +1806,29 @@ export interface TActivityLog {
1804
1806
  source_type_id: PointChangeSourceType;
1805
1807
  }
1806
1808
 
1809
+ /**
1810
+ * Full activity-log row returned by {@link WSAPIUser.getActivityLogV2}.
1811
+ * Includes wallet changes and non-wallet activities (missions, badges, levels, …).
1812
+ */
1813
+ export interface TActivityLogEntry {
1814
+ create_date: number;
1815
+ user_ext_id: string;
1816
+ crm_brand_id: number;
1817
+ type: UserBalanceType;
1818
+ amount: number;
1819
+ balance: number;
1820
+ total_ever?: number;
1821
+ source_type_id: PointChangeSourceType;
1822
+ activity_type_id?: ActivityLogActivities;
1823
+ context_value_1?: number;
1824
+ meta?: ActivityLogMeta;
1825
+ source_entity_name?: string;
1826
+ source_entity_id?: number;
1827
+ source_reference_id?: number;
1828
+ source_root_id?: number;
1829
+ is_wallet_entry: boolean;
1830
+ }
1831
+
1807
1832
 
1808
1833
  /**
1809
1834
  * Result of `_smartico.api.requestRaffleOptin({raffle_id, draw_id, raffle_run_id})`.
@@ -2,6 +2,7 @@ import { CoreUtils } from '../Core';
2
2
  import { ECacheContext, OCache } from '../OCache';
3
3
  import {
4
4
  TActivityLog,
5
+ TActivityLogEntry,
5
6
  TLevel,
6
7
  TLevelCurrent,
7
8
  TSegmentCheckResult,
@@ -639,4 +640,43 @@ export class WSAPIUser extends WSAPIBase {
639
640
  onUpdate(payload);
640
641
  }
641
642
  }
643
+
644
+ /**
645
+ * Returns the full activity log (v2) — wallet changes **and** non-wallet
646
+ * activities (missions, badges, levels, tournaments, avatars, …).
647
+ *
648
+ * **Backwards compatibility**: existing integrations should keep using
649
+ * {@link getActivityLog}, which returns wallet-only {@link TActivityLog}
650
+ * rows with the original field contract unchanged.
651
+ *
652
+ * **Pagination** — same `from` / `to` offset model as {@link getActivityLog}
653
+ * (server caps a single response at 50 entries).
654
+ *
655
+ * **Filtering** — pass `types` with {@link ActivityLogActivities} values to
656
+ * request a server-side subset (e.g. missions only). Omit for all activity types.
657
+ *
658
+ * @returns Array of {@link TActivityLogEntry} ordered newest-first.
659
+ */
660
+ public async getActivityLogV2({
661
+ startTimeSeconds,
662
+ endTimeSeconds,
663
+ from,
664
+ to,
665
+ types,
666
+ }: {
667
+ startTimeSeconds: number;
668
+ endTimeSeconds: number;
669
+ from: number;
670
+ to: number;
671
+ types?: number[];
672
+ }): Promise<TActivityLogEntry[]> {
673
+ const cacheKey = `${onUpdateContextKey.ActivityLogV2}:${startTimeSeconds}:${endTimeSeconds}:${from}:${to}:${types?.join(',') ?? ''}`;
674
+
675
+ return await OCache.use(
676
+ cacheKey,
677
+ ECacheContext.WSAPI,
678
+ () => this.api.getActivityLogV2T(this.userExtId, startTimeSeconds, endTimeSeconds, from, to, types),
679
+ CACHE_DATA_SEC,
680
+ );
681
+ }
642
682
  }
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ export * from './CookieStore';
12
12
  // AchRelatedGame, BonusStatus, BonusMetaMap, BonusTemplateMetaMap — are intentionally
13
13
  // omitted; import those from their domain module.)
14
14
  export type {
15
- TAchCategory, TActivityLog, TAvatarCustomized, TAvatarDefinition, TAvatarPrompt,
15
+ TAchCategory, TActivityLog, TActivityLogEntry, TAvatarCustomized, TAvatarDefinition, TAvatarPrompt,
16
16
  TBonus, TBuyStoreItemResult, TClaimBonusResult, TClan, TClanInfo, TClanJoinResult,
17
17
  TClanTournamentPlayers, TClans, TGetTranslations, TInboxMessage, TInboxMessageBody,
18
18
  TLevel, TLevelCurrent, TMiniGamePlayBatchResult, TMiniGamePlayResult, TMiniGamePrize,