@smartico/public-api 0.0.417 → 0.0.419
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/dist/ActivityLog/ActivityLogActivities.d.ts +2 -23
- package/dist/ActivityLog/ActivityLogMeta.d.ts +1 -19
- package/dist/ActivityLog/GetActivityLogResponse.d.ts +2 -4
- package/dist/ActivityLog/PointChangeSourceType.d.ts +2 -1
- package/dist/ActivityLog/index.d.ts +0 -1
- package/dist/Base/ClassId.d.ts +1 -0
- package/dist/WSAPI/WSAPIMiniGames.d.ts +4 -4
- package/dist/WSAPI/WSAPITypes.d.ts +0 -2
- package/dist/index.js +59 -392
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +60 -380
- package/dist/index.modern.mjs.map +1 -1
- package/docs/api/README.md +5 -0
- package/docs/api/classes/WSAPIJackpots.md +3 -1
- package/docs/api/classes/WSAPIMiniGames.md +7 -2
- package/docs/api/classes/WSAPIUser.md +49 -0
- package/docs/api/enumerations/ActivityLogActivities.md +123 -0
- package/docs/api/enumerations/PointChangeSourceType.md +6 -0
- package/docs/api/interfaces/ActivityLogMeta.md +37 -0
- package/docs/api/interfaces/SAWPrizeDropAknowledgeCancelRequest.md +47 -0
- package/docs/api/interfaces/SAWPrizeDropAknowledgeCancelResponse.md +41 -0
- package/docs/api/interfaces/SAWTemplateUI.md +1 -1
- package/docs/api/interfaces/TActivityLogEntry.md +100 -0
- package/docs/capabilities/getActivityLogV2.md +62 -0
- package/docs/capabilities/getJackpotWinners.md +3 -1
- package/docs/capabilities/miniGameWinAcknowledgeRequest.md +1 -1
- package/docs/native/PROTOCOL.md +33 -1
- package/package.json +1 -1
- package/src/ActivityLog/ActivityLogActivities.ts +1 -44
- package/src/ActivityLog/ActivityLogMeta.ts +1 -20
- package/src/ActivityLog/GetActivityLogResponse.ts +59 -25
- package/src/ActivityLog/PointChangeSourceType.ts +1 -0
- package/src/ActivityLog/index.ts +0 -1
- package/src/Base/ClassId.ts +2 -0
- package/src/WSAPI/WSAPIMiniGames.ts +4 -4
- package/src/WSAPI/WSAPITypes.ts +0 -2
- package/tsconfig.json +4 -1
- package/src/ActivityLog/ActivityLogMapper.ts +0 -358
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
export interface ActivityLogPublicMeta {
|
|
2
|
-
name?: string;
|
|
3
|
-
image_url?: string;
|
|
4
|
-
image?: string;
|
|
5
|
-
url?: string;
|
|
6
|
-
avatar_url?: string;
|
|
7
|
-
avatar_id?: string;
|
|
8
|
-
icon_url?: string;
|
|
9
|
-
position?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
1
|
export interface ActivityLogMeta {
|
|
13
|
-
image_url?: string;
|
|
14
|
-
image?: string;
|
|
15
|
-
url?: string;
|
|
16
|
-
avatar_url?: string;
|
|
17
|
-
avatar_id?: string;
|
|
18
|
-
icon_url?: string;
|
|
19
2
|
name?: string;
|
|
3
|
+
image_url?: string;
|
|
20
4
|
position?: number;
|
|
21
|
-
score?: number;
|
|
22
5
|
user_points_balance_before?: number;
|
|
23
6
|
points_requested?: number;
|
|
24
7
|
user_points_ever?: number;
|
|
25
|
-
public_meta?: ActivityLogPublicMeta;
|
|
26
|
-
public_map?: ActivityLogPublicMeta;
|
|
27
8
|
}
|
|
@@ -1,42 +1,76 @@
|
|
|
1
1
|
import { ProtocolResponse } from '../Base/ProtocolResponse';
|
|
2
2
|
import { ActivityLogEntry } from './ActivityLogEntry';
|
|
3
|
-
import {
|
|
3
|
+
import { ActivityLogActivities } from './ActivityLogActivities';
|
|
4
4
|
import { TActivityLog, TActivityLogEntry } from '../WSAPI/WSAPITypes';
|
|
5
|
+
import { UserBalanceType } from './UserBalanceType';
|
|
5
6
|
|
|
6
7
|
export interface GetActivityLogResponse extends ProtocolResponse {
|
|
7
8
|
logHistory: ActivityLogEntry[];
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
const row: TActivityLog = {
|
|
12
|
-
create_date: entry.create_date,
|
|
13
|
-
user_ext_id: entry.user_ext_id,
|
|
14
|
-
crm_brand_id: entry.crm_brand_id,
|
|
15
|
-
type: resolveWalletDisplayType(entry),
|
|
16
|
-
amount: entry.amount,
|
|
17
|
-
balance: entry.balance,
|
|
18
|
-
source_type_id: entry.source_type_id,
|
|
19
|
-
};
|
|
20
|
-
if (entry.total_ever !== undefined) {
|
|
21
|
-
row.total_ever = entry.total_ever;
|
|
22
|
-
}
|
|
23
|
-
return row;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/** Maps wire rows to wallet-only {@link TActivityLog} — legacy consumer contract. */
|
|
27
|
-
export const ActivityLogTransform = (items: ActivityLogEntry[] | unknown[]): TActivityLog[] => {
|
|
11
|
+
export const ActivityLogTransform = (items: ActivityLogEntry[]): TActivityLog[] => {
|
|
28
12
|
if (!items) {
|
|
29
13
|
return [];
|
|
30
14
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
|
|
16
|
+
return items.map((item: any): TActivityLog => {
|
|
17
|
+
const itemTransformed: Partial<TActivityLog> = {
|
|
18
|
+
create_date: item.create_date?.seconds ?? item.create_date,
|
|
19
|
+
user_ext_id: item.user_ext_id,
|
|
20
|
+
crm_brand_id: item.crm_brand_id,
|
|
21
|
+
source_type_id: item.source_type_id,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
item.type = item.type ?? UserBalanceType.Points;
|
|
25
|
+
|
|
26
|
+
if (item.type === UserBalanceType.Diamonds || item.type === UserBalanceType.Gems) {
|
|
27
|
+
itemTransformed.type = item.type;
|
|
28
|
+
itemTransformed.amount = item.amount;
|
|
29
|
+
itemTransformed.balance = item.balance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (item.type === UserBalanceType.Points) {
|
|
33
|
+
itemTransformed.type = UserBalanceType.Points;
|
|
34
|
+
itemTransformed.amount = item.points_collected;
|
|
35
|
+
itemTransformed.balance = item.user_points_balance;
|
|
36
|
+
itemTransformed.total_ever = item.user_points_ever;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return itemTransformed as TActivityLog;
|
|
40
|
+
});
|
|
34
41
|
};
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
export const ActivityLogV2Transform = (items: ActivityLogEntry[] | unknown[]): TActivityLogEntry[] => {
|
|
43
|
+
export const ActivityLogV2Transform = (items: any[]): TActivityLogEntry[] => {
|
|
38
44
|
if (!items) {
|
|
39
45
|
return [];
|
|
40
46
|
}
|
|
41
|
-
|
|
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
|
+
});
|
|
42
76
|
};
|
package/src/ActivityLog/index.ts
CHANGED
|
@@ -3,6 +3,5 @@ export * from './GetActivityLogResponse';
|
|
|
3
3
|
export * from './ActivityLogEntry';
|
|
4
4
|
export * from './ActivityLogActivities';
|
|
5
5
|
export * from './ActivityLogMeta';
|
|
6
|
-
export * from './ActivityLogMapper';
|
|
7
6
|
export * from './PointChangeSourceType';
|
|
8
7
|
export * from './UserBalanceType';
|
package/src/Base/ClassId.ts
CHANGED
|
@@ -545,10 +545,10 @@ export class WSAPIMiniGames extends WSAPIRaffles {
|
|
|
545
545
|
* (played with `acknowledge: false`), or the
|
|
546
546
|
* `client_request_id` of a
|
|
547
547
|
* {@link getMiniGamesHistory} row.
|
|
548
|
-
* @param
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
548
|
+
* @param lose Optional. When `true`, finalises the spin as
|
|
549
|
+
* lost — the prize is not credited and returns
|
|
550
|
+
* to the prize pool (see "Finalising as lost").
|
|
551
|
+
* Omit (or pass `false`) to deliver the win.
|
|
552
552
|
*
|
|
553
553
|
* @example
|
|
554
554
|
* ```ts
|
package/src/WSAPI/WSAPITypes.ts
CHANGED
|
@@ -1811,7 +1811,6 @@ export interface TActivityLog {
|
|
|
1811
1811
|
* Includes wallet changes and non-wallet activities (missions, badges, levels, …).
|
|
1812
1812
|
*/
|
|
1813
1813
|
export interface TActivityLogEntry {
|
|
1814
|
-
entry_key: string;
|
|
1815
1814
|
create_date: number;
|
|
1816
1815
|
user_ext_id: string;
|
|
1817
1816
|
crm_brand_id: number;
|
|
@@ -1828,7 +1827,6 @@ export interface TActivityLogEntry {
|
|
|
1828
1827
|
source_reference_id?: number;
|
|
1829
1828
|
source_root_id?: number;
|
|
1830
1829
|
is_wallet_entry: boolean;
|
|
1831
|
-
is_level_entry?: boolean;
|
|
1832
1830
|
}
|
|
1833
1831
|
|
|
1834
1832
|
|
package/tsconfig.json
CHANGED
|
@@ -93,7 +93,10 @@
|
|
|
93
93
|
"src/Avatars/AvatarCustomized.ts",
|
|
94
94
|
"src/Avatars/AvatarPrompt.ts",
|
|
95
95
|
"src/Avatars/AvatarCustomizeResponse.ts",
|
|
96
|
-
"src/Avatars/AvatarCustomizeErrorCode.ts"
|
|
96
|
+
"src/Avatars/AvatarCustomizeErrorCode.ts",
|
|
97
|
+
"src/ActivityLog/ActivityLogEntry.ts",
|
|
98
|
+
"src/ActivityLog/ActivityLogActivities.ts",
|
|
99
|
+
"src/ActivityLog/ActivityLogMeta.ts",
|
|
97
100
|
],
|
|
98
101
|
"out": "docs/api",
|
|
99
102
|
"projectDocuments": ["docs/SmarticoObject.md", "docs/Callbacks.md", "docs/Transforms.md"],
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { PointChangeSourceType } from './PointChangeSourceType';
|
|
2
|
-
import { UserBalanceType } from './UserBalanceType';
|
|
3
|
-
import {
|
|
4
|
-
ActivityLogActivities,
|
|
5
|
-
activityTypeIdToBalanceType,
|
|
6
|
-
isWalletActivityTypeId,
|
|
7
|
-
} from './ActivityLogActivities';
|
|
8
|
-
import { ActivityLogMeta, ActivityLogPublicMeta } from './ActivityLogMeta';
|
|
9
|
-
import { TActivityLogEntry } from '../WSAPI/WSAPITypes';
|
|
10
|
-
|
|
11
|
-
const POINTS_COLLECTED_SENTINEL = -1;
|
|
12
|
-
|
|
13
|
-
const parseCreateDate = (raw: unknown): number => {
|
|
14
|
-
if (raw === undefined || raw === null) {
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
if (typeof raw === 'number') {
|
|
18
|
-
return raw;
|
|
19
|
-
}
|
|
20
|
-
if (typeof raw === 'object' && raw !== null) {
|
|
21
|
-
if ('seconds' in raw) {
|
|
22
|
-
return Number((raw as { seconds: number }).seconds);
|
|
23
|
-
}
|
|
24
|
-
if ('epochSecond' in raw) {
|
|
25
|
-
return Number((raw as { epochSecond: number }).epochSecond);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (typeof raw === 'string') {
|
|
29
|
-
const ms = Date.parse(raw);
|
|
30
|
-
if (!Number.isNaN(ms)) {
|
|
31
|
-
return Math.floor(ms / 1000);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return 0;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const readWireNumber = (log: Record<string, unknown>, ...keys: string[]): number | undefined => {
|
|
38
|
-
for (const key of keys) {
|
|
39
|
-
const value = log[key];
|
|
40
|
-
if (value !== undefined && value !== null && value !== '') {
|
|
41
|
-
return Number(value);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const normalizeWireLog = (raw: Record<string, unknown>): Record<string, unknown> => {
|
|
48
|
-
const log: Record<string, unknown> = { ...raw };
|
|
49
|
-
const explicitTypeId = readWireNumber(log, 'type_id');
|
|
50
|
-
if (explicitTypeId !== undefined) {
|
|
51
|
-
log.type_id = explicitTypeId;
|
|
52
|
-
} else {
|
|
53
|
-
const wireType = readWireNumber(log, 'type');
|
|
54
|
-
if (wireType !== undefined && wireType > UserBalanceType.Diamonds) {
|
|
55
|
-
log.type_id = wireType;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (log.context_value_1 === undefined && log.ctx_1 !== undefined) {
|
|
59
|
-
log.context_value_1 = log.ctx_1;
|
|
60
|
-
}
|
|
61
|
-
if (log.context_value_meta === undefined && log.ctx_meta !== undefined) {
|
|
62
|
-
log.context_value_meta = log.ctx_meta;
|
|
63
|
-
}
|
|
64
|
-
if (log.source_reference_id === undefined && log.source_ref_id !== undefined) {
|
|
65
|
-
log.source_reference_id = log.source_ref_id;
|
|
66
|
-
}
|
|
67
|
-
if (log.source_entity_id === undefined && log.source_root_id !== undefined) {
|
|
68
|
-
log.source_entity_id = log.source_root_id;
|
|
69
|
-
}
|
|
70
|
-
return log;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const isActivityLogWireEntry = (log: Record<string, unknown>): boolean => {
|
|
74
|
-
if (log.is_activity_log === true) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
if (log.label_id !== undefined && log.label_id !== null) {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
if (log.ctx_meta !== undefined || log.context_value_meta !== undefined) {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
if (log.ctx_1 !== undefined || log.context_value_1 !== undefined) {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
if (log.user_id !== undefined && log.user_id !== null) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
const wireTypeId = readWireNumber(log, 'type_id');
|
|
90
|
-
return wireTypeId !== undefined && wireTypeId > UserBalanceType.Diamonds;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const readWireBalanceType = (log: Record<string, unknown>): UserBalanceType | undefined => {
|
|
94
|
-
const balanceType = readWireNumber(log, 'type');
|
|
95
|
-
if (balanceType === UserBalanceType.Gems || balanceType === UserBalanceType.Diamonds) {
|
|
96
|
-
return balanceType;
|
|
97
|
-
}
|
|
98
|
-
return undefined;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const hasGemsOrDiamondsWalletFields = (log: Record<string, unknown>): boolean =>
|
|
102
|
-
log.amount !== undefined
|
|
103
|
-
|| log.balance !== undefined
|
|
104
|
-
|| readWireNumber(log, 'amount', 'collected_amount') !== undefined
|
|
105
|
-
|| readWireNumber(log, 'balance', 'user_balance') !== undefined;
|
|
106
|
-
|
|
107
|
-
const isGemsOrDiamondsWalletWireEntry = (log: Record<string, unknown>): boolean => {
|
|
108
|
-
const balanceType = readWireBalanceType(log);
|
|
109
|
-
return balanceType !== undefined && hasGemsOrDiamondsWalletFields(log);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const resolveWalletAmount = (log: Record<string, unknown>, isPoints: boolean): number => {
|
|
113
|
-
const pointsCollected = readWireNumber(log, 'points_collected');
|
|
114
|
-
if (isPoints && pointsCollected !== undefined && pointsCollected !== POINTS_COLLECTED_SENTINEL) {
|
|
115
|
-
return pointsCollected;
|
|
116
|
-
}
|
|
117
|
-
if (isPoints) {
|
|
118
|
-
const amount = readWireNumber(log, 'amount', 'collected_amount');
|
|
119
|
-
return amount === undefined ? 0 : amount;
|
|
120
|
-
}
|
|
121
|
-
const amount = readWireNumber(log, 'amount', 'collected_amount');
|
|
122
|
-
return amount === undefined ? 0 : amount;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const resolveWalletBalance = (log: Record<string, unknown>, isPoints: boolean): number => {
|
|
126
|
-
if (isPoints) {
|
|
127
|
-
const balance = readWireNumber(log, 'balance', 'user_points_balance', 'user_balance');
|
|
128
|
-
return balance === undefined ? 0 : balance;
|
|
129
|
-
}
|
|
130
|
-
const balance = readWireNumber(log, 'balance', 'user_balance');
|
|
131
|
-
return balance === undefined ? 0 : balance;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const resolveSourceTypeId = (log: Record<string, unknown>): PointChangeSourceType => {
|
|
135
|
-
const sourceTypeId = readWireNumber(log, 'source_type_id', 'entity_type_id');
|
|
136
|
-
return (sourceTypeId === undefined ? 0 : sourceTypeId) as PointChangeSourceType;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const parseMeta = (contextValueMeta: unknown): ActivityLogMeta | undefined => {
|
|
140
|
-
if (!contextValueMeta) {
|
|
141
|
-
return undefined;
|
|
142
|
-
}
|
|
143
|
-
let meta: ActivityLogMeta | undefined;
|
|
144
|
-
if (typeof contextValueMeta === 'object') {
|
|
145
|
-
meta = contextValueMeta as ActivityLogMeta;
|
|
146
|
-
} else if (typeof contextValueMeta === 'string') {
|
|
147
|
-
try {
|
|
148
|
-
meta = JSON.parse(contextValueMeta) as ActivityLogMeta;
|
|
149
|
-
} catch {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (!meta) {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
const nested = meta.public_meta ?? meta.public_map;
|
|
157
|
-
const pickImage = (src?: ActivityLogMeta | ActivityLogPublicMeta): string | undefined =>
|
|
158
|
-
src?.image_url ?? src?.image ?? src?.url ?? src?.avatar_url ?? src?.icon_url ?? src?.avatar_id;
|
|
159
|
-
if (nested) {
|
|
160
|
-
return {
|
|
161
|
-
...meta,
|
|
162
|
-
name: meta.name ?? nested.name,
|
|
163
|
-
image_url: pickImage(meta) ?? pickImage(nested),
|
|
164
|
-
position: meta.position ?? nested.position ?? meta.score,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
const topImage = pickImage(meta);
|
|
168
|
-
if (topImage && meta.image_url === undefined) {
|
|
169
|
-
return { ...meta, image_url: topImage, position: meta.position ?? meta.score };
|
|
170
|
-
}
|
|
171
|
-
if (meta.score !== undefined && meta.position === undefined) {
|
|
172
|
-
return { ...meta, position: meta.score };
|
|
173
|
-
}
|
|
174
|
-
return meta;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const isLegacyPointsEntry = (log: Record<string, unknown>): boolean => {
|
|
178
|
-
if (isActivityLogWireEntry(log)) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
const pointsCollected = readWireNumber(log, 'points_collected');
|
|
182
|
-
return pointsCollected !== undefined && pointsCollected !== POINTS_COLLECTED_SENTINEL;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const isLegacyGemsDiamondsEntry = (log: Record<string, unknown>): boolean => {
|
|
186
|
-
if (isActivityLogWireEntry(log)) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
const balanceType = readWireNumber(log, 'type');
|
|
190
|
-
return (balanceType === UserBalanceType.Gems || balanceType === UserBalanceType.Diamonds)
|
|
191
|
-
&& log.amount !== undefined;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const isV2Entry = (log: Record<string, unknown>): boolean =>
|
|
195
|
-
isActivityLogWireEntry(log) || (log.type_id !== undefined && log.type_id !== null);
|
|
196
|
-
|
|
197
|
-
const resolveSourceEntityName = (log: Record<string, unknown>, meta: ActivityLogMeta | undefined): string | undefined => {
|
|
198
|
-
const fromWire = log.source_entity_name ?? log.source_public_name;
|
|
199
|
-
if (typeof fromWire === 'string' && fromWire.length > 0) {
|
|
200
|
-
return fromWire;
|
|
201
|
-
}
|
|
202
|
-
if (meta?.name) {
|
|
203
|
-
return meta.name;
|
|
204
|
-
}
|
|
205
|
-
return undefined;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const buildEntryKey = (log: Record<string, unknown>, index: number): string =>
|
|
209
|
-
[
|
|
210
|
-
parseCreateDate(log.create_date),
|
|
211
|
-
log.type_id ?? log.type ?? 'legacy',
|
|
212
|
-
log.source_type_id ?? '',
|
|
213
|
-
log.source_entity_id ?? log.source_root_id ?? '',
|
|
214
|
-
log.context_value_1 ?? log.ctx_1 ?? '',
|
|
215
|
-
index,
|
|
216
|
-
].join('-');
|
|
217
|
-
|
|
218
|
-
const mapLegacyPointsEntry = (log: Record<string, unknown>, index: number): TActivityLogEntry => ({
|
|
219
|
-
entry_key: buildEntryKey(log, index),
|
|
220
|
-
create_date: parseCreateDate(log.create_date),
|
|
221
|
-
user_ext_id: String(log.user_ext_id ?? ''),
|
|
222
|
-
crm_brand_id: Number(log.crm_brand_id ?? 0),
|
|
223
|
-
type: UserBalanceType.Points,
|
|
224
|
-
amount: resolveWalletAmount(log, true),
|
|
225
|
-
balance: resolveWalletBalance(log, true),
|
|
226
|
-
total_ever: readWireNumber(log, 'user_points_ever', 'collected_ever'),
|
|
227
|
-
context_value_1: readWireNumber(log, 'context_value_1', 'ctx_1'),
|
|
228
|
-
source_type_id: resolveSourceTypeId(log),
|
|
229
|
-
activity_type_id: ActivityLogActivities.Points,
|
|
230
|
-
is_wallet_entry: true,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const mapLegacyGemsDiamondsEntry = (log: Record<string, unknown>, index: number): TActivityLogEntry => {
|
|
234
|
-
const wireType = readWireNumber(log, 'type') as UserBalanceType;
|
|
235
|
-
const activityTypeId = wireType === UserBalanceType.Gems
|
|
236
|
-
? ActivityLogActivities.Gems
|
|
237
|
-
: ActivityLogActivities.Diamonds;
|
|
238
|
-
return {
|
|
239
|
-
entry_key: buildEntryKey(log, index),
|
|
240
|
-
create_date: parseCreateDate(log.create_date),
|
|
241
|
-
user_ext_id: String(log.user_ext_id ?? ''),
|
|
242
|
-
crm_brand_id: Number(log.crm_brand_id ?? 0),
|
|
243
|
-
type: activityTypeIdToBalanceType(activityTypeId),
|
|
244
|
-
amount: resolveWalletAmount(log, false),
|
|
245
|
-
balance: resolveWalletBalance(log, false),
|
|
246
|
-
context_value_1: readWireNumber(log, 'context_value_1', 'ctx_1'),
|
|
247
|
-
source_type_id: resolveSourceTypeId(log),
|
|
248
|
-
activity_type_id: activityTypeId,
|
|
249
|
-
is_wallet_entry: true,
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const mapV2Entry = (log: Record<string, unknown>, index: number): TActivityLogEntry | null => {
|
|
254
|
-
const typeId = readWireNumber(log, 'type_id');
|
|
255
|
-
const contextValue1 = readWireNumber(log, 'context_value_1', 'ctx_1');
|
|
256
|
-
|
|
257
|
-
const meta = parseMeta(log.context_value_meta);
|
|
258
|
-
const sourceEntityName = resolveSourceEntityName(log, meta);
|
|
259
|
-
const sourceEntityId = readWireNumber(log, 'source_entity_id', 'source_root_id');
|
|
260
|
-
const sourceReferenceId = readWireNumber(log, 'source_reference_id', 'source_ref_id');
|
|
261
|
-
const sourceRootId = readWireNumber(log, 'source_root_id');
|
|
262
|
-
const gemsOrDiamondsWallet = isGemsOrDiamondsWalletWireEntry(log);
|
|
263
|
-
const isWalletEntry = (typeId !== undefined && isWalletActivityTypeId(typeId)) || gemsOrDiamondsWallet;
|
|
264
|
-
|
|
265
|
-
const base = {
|
|
266
|
-
entry_key: buildEntryKey(log, index),
|
|
267
|
-
create_date: parseCreateDate(log.create_date),
|
|
268
|
-
user_ext_id: String(log.user_ext_id ?? ''),
|
|
269
|
-
crm_brand_id: Number(log.crm_brand_id ?? 0),
|
|
270
|
-
source_type_id: resolveSourceTypeId(log),
|
|
271
|
-
activity_type_id: typeId as ActivityLogActivities,
|
|
272
|
-
context_value_1: contextValue1,
|
|
273
|
-
meta,
|
|
274
|
-
source_entity_name: sourceEntityName,
|
|
275
|
-
source_entity_id: sourceEntityId && sourceEntityId > 0 ? sourceEntityId : undefined,
|
|
276
|
-
source_reference_id: sourceReferenceId && sourceReferenceId > 0 ? sourceReferenceId : undefined,
|
|
277
|
-
source_root_id: sourceRootId && sourceRootId > 0 ? sourceRootId : undefined,
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
if (isWalletEntry) {
|
|
281
|
-
const wireBalanceType = readWireBalanceType(log);
|
|
282
|
-
const balanceType = wireBalanceType ?? (typeId !== undefined ? activityTypeIdToBalanceType(typeId as ActivityLogActivities) : UserBalanceType.Points);
|
|
283
|
-
const walletActivityTypeId = typeId !== undefined && isWalletActivityTypeId(typeId)
|
|
284
|
-
? typeId
|
|
285
|
-
: balanceType === UserBalanceType.Gems
|
|
286
|
-
? ActivityLogActivities.Gems
|
|
287
|
-
: balanceType === UserBalanceType.Diamonds
|
|
288
|
-
? ActivityLogActivities.Diamonds
|
|
289
|
-
: ActivityLogActivities.Points;
|
|
290
|
-
const isPoints = balanceType === UserBalanceType.Points;
|
|
291
|
-
const totalEver = isPoints
|
|
292
|
-
? readWireNumber(log, 'user_points_ever', 'collected_ever')
|
|
293
|
-
?? (meta?.user_points_ever !== undefined ? Number(meta.user_points_ever) : undefined)
|
|
294
|
-
: undefined;
|
|
295
|
-
return {
|
|
296
|
-
...base,
|
|
297
|
-
activity_type_id: walletActivityTypeId as ActivityLogActivities,
|
|
298
|
-
type: balanceType,
|
|
299
|
-
amount: resolveWalletAmount(log, isPoints),
|
|
300
|
-
balance: resolveWalletBalance(log, isPoints),
|
|
301
|
-
total_ever: totalEver === POINTS_COLLECTED_SENTINEL ? undefined : totalEver,
|
|
302
|
-
is_wallet_entry: true,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
...base,
|
|
308
|
-
type: UserBalanceType.Points,
|
|
309
|
-
amount: 0,
|
|
310
|
-
balance: 0,
|
|
311
|
-
is_wallet_entry: false,
|
|
312
|
-
is_level_entry: typeId === ActivityLogActivities.LevelChanged,
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const mapWireEntry = (log: Record<string, unknown>, index: number): TActivityLogEntry | null => {
|
|
317
|
-
const normalized = normalizeWireLog(log);
|
|
318
|
-
if (isLegacyPointsEntry(normalized)) {
|
|
319
|
-
return mapLegacyPointsEntry(normalized, index);
|
|
320
|
-
}
|
|
321
|
-
if (isLegacyGemsDiamondsEntry(normalized)) {
|
|
322
|
-
return mapLegacyGemsDiamondsEntry(normalized, index);
|
|
323
|
-
}
|
|
324
|
-
if (isV2Entry(normalized)) {
|
|
325
|
-
return mapV2Entry(normalized, index);
|
|
326
|
-
}
|
|
327
|
-
return null;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
export const mapActivityLogHistory = (logHistory: unknown[]): TActivityLogEntry[] => {
|
|
331
|
-
const entries: TActivityLogEntry[] = [];
|
|
332
|
-
(logHistory || []).forEach((raw, index) => {
|
|
333
|
-
const mapped = mapWireEntry(raw as Record<string, unknown>, index);
|
|
334
|
-
if (mapped) {
|
|
335
|
-
entries.push(mapped);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
return entries;
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
export const resolveWalletDisplayType = (entry: TActivityLogEntry): UserBalanceType => {
|
|
342
|
-
switch (entry.activity_type_id) {
|
|
343
|
-
case ActivityLogActivities.Gems:
|
|
344
|
-
return UserBalanceType.Gems;
|
|
345
|
-
case ActivityLogActivities.Diamonds:
|
|
346
|
-
return UserBalanceType.Diamonds;
|
|
347
|
-
case ActivityLogActivities.Points:
|
|
348
|
-
return UserBalanceType.Points;
|
|
349
|
-
}
|
|
350
|
-
switch (Number(entry.type)) {
|
|
351
|
-
case UserBalanceType.Gems:
|
|
352
|
-
return UserBalanceType.Gems;
|
|
353
|
-
case UserBalanceType.Diamonds:
|
|
354
|
-
return UserBalanceType.Diamonds;
|
|
355
|
-
default:
|
|
356
|
-
return UserBalanceType.Points;
|
|
357
|
-
}
|
|
358
|
-
};
|