@smartico/public-api 0.0.416 → 0.0.417
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 +44 -0
- package/dist/ActivityLog/ActivityLogMapper.d.ts +4 -0
- package/dist/ActivityLog/ActivityLogMeta.d.ts +26 -0
- package/dist/ActivityLog/GetActivityLogRequest.d.ts +2 -0
- package/dist/ActivityLog/GetActivityLogResponse.d.ts +5 -2
- package/dist/ActivityLog/index.d.ts +3 -0
- package/dist/SmarticoAPI.d.ts +3 -1
- package/dist/WSAPI/WSAPIBase.d.ts +1 -0
- package/dist/WSAPI/WSAPITypes.d.ts +26 -0
- package/dist/WSAPI/WSAPIUser.d.ts +24 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +484 -25
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +443 -23
- package/dist/index.modern.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ActivityLog/ActivityLogActivities.ts +66 -0
- package/src/ActivityLog/ActivityLogMapper.ts +358 -0
- package/src/ActivityLog/ActivityLogMeta.ts +27 -0
- package/src/ActivityLog/GetActivityLogRequest.ts +2 -0
- package/src/ActivityLog/GetActivityLogResponse.ts +30 -30
- package/src/ActivityLog/index.ts +3 -2
- package/src/SmarticoAPI.ts +41 -1
- package/src/WSAPI/WSAPIBase.ts +1 -0
- package/src/WSAPI/WSAPITypes.ts +27 -0
- package/src/WSAPI/WSAPIUser.ts +40 -0
- package/src/index.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { UserBalanceType } from './UserBalanceType';
|
|
2
|
+
|
|
3
|
+
/** Activity-log entry type as returned on the v2 wire (`type_id`). */
|
|
4
|
+
export enum ActivityLogActivities {
|
|
5
|
+
Gems = 1,
|
|
6
|
+
Diamonds = 2,
|
|
7
|
+
Points = 3,
|
|
8
|
+
LevelChanged = 4,
|
|
9
|
+
Bonus = 5,
|
|
10
|
+
PrizeDrop = 6,
|
|
11
|
+
Minigame = 7,
|
|
12
|
+
RaffleTicket = 8,
|
|
13
|
+
Avatar = 9,
|
|
14
|
+
Task = 10,
|
|
15
|
+
Mission = 11,
|
|
16
|
+
Badge = 12,
|
|
17
|
+
TangiblePrize = 13,
|
|
18
|
+
Jackpot = 14,
|
|
19
|
+
Spin = 15,
|
|
20
|
+
NoPrize = 16,
|
|
21
|
+
Leaderboard = 17,
|
|
22
|
+
Tournament = 18,
|
|
23
|
+
ClanTournament = 19,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum WalletChangeType {
|
|
27
|
+
Add = 1,
|
|
28
|
+
Deduct = 2,
|
|
29
|
+
Set = 3,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export enum LevelChangeType {
|
|
33
|
+
Increase = 1,
|
|
34
|
+
Decrease = 2,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Wire ctx_1 for Mission / Badge / Task — see SMR-44986. */
|
|
38
|
+
export enum AchievementChangeType {
|
|
39
|
+
Complete = 1,
|
|
40
|
+
Unlock = 2,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Wire ctx_1 for Jackpot rows — SMR-44986. */
|
|
44
|
+
export enum JackpotContextValue {
|
|
45
|
+
Registration = 1,
|
|
46
|
+
Win = 3,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const WALLET_TYPE_IDS = new Set<number>([
|
|
50
|
+
ActivityLogActivities.Gems,
|
|
51
|
+
ActivityLogActivities.Diamonds,
|
|
52
|
+
ActivityLogActivities.Points,
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
export const isWalletActivityTypeId = (typeId: number): boolean => WALLET_TYPE_IDS.has(typeId);
|
|
56
|
+
|
|
57
|
+
export const activityTypeIdToBalanceType = (typeId: ActivityLogActivities): UserBalanceType => {
|
|
58
|
+
switch (typeId) {
|
|
59
|
+
case ActivityLogActivities.Gems:
|
|
60
|
+
return UserBalanceType.Gems;
|
|
61
|
+
case ActivityLogActivities.Diamonds:
|
|
62
|
+
return UserBalanceType.Diamonds;
|
|
63
|
+
default:
|
|
64
|
+
return UserBalanceType.Points;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
@@ -0,0 +1,358 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
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
|
+
name?: string;
|
|
20
|
+
position?: number;
|
|
21
|
+
score?: number;
|
|
22
|
+
user_points_balance_before?: number;
|
|
23
|
+
points_requested?: number;
|
|
24
|
+
user_points_ever?: number;
|
|
25
|
+
public_meta?: ActivityLogPublicMeta;
|
|
26
|
+
public_map?: ActivityLogPublicMeta;
|
|
27
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
import { ProtocolResponse } from '../Base/ProtocolResponse';
|
|
2
2
|
import { ActivityLogEntry } from './ActivityLogEntry';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { mapActivityLogHistory, resolveWalletDisplayType } from './ActivityLogMapper';
|
|
4
|
+
import { TActivityLog, TActivityLogEntry } from '../WSAPI/WSAPITypes';
|
|
5
5
|
|
|
6
6
|
export interface GetActivityLogResponse extends ProtocolResponse {
|
|
7
7
|
logHistory: ActivityLogEntry[];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const toTActivityLog = (entry: TActivityLogEntry): TActivityLog => {
|
|
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
28
|
if (!items) {
|
|
12
29
|
return [];
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
create_date: item.create_date,
|
|
18
|
-
user_ext_id: item.user_ext_id,
|
|
19
|
-
crm_brand_id: item.crm_brand_id,
|
|
20
|
-
source_type_id: item.source_type_id,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
item.type = item.type ?? UserBalanceType.Points;
|
|
24
|
-
|
|
25
|
-
if (item.type === UserBalanceType.Diamonds || item.type === UserBalanceType.Gems) {
|
|
26
|
-
itemTransformed.type = item.type;
|
|
27
|
-
itemTransformed.amount = item.amount;
|
|
28
|
-
itemTransformed.balance = item.balance;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (item.type === UserBalanceType.Points) {
|
|
32
|
-
itemTransformed.type = UserBalanceType.Points;
|
|
33
|
-
itemTransformed.amount = item.points_collected;
|
|
34
|
-
itemTransformed.balance = item.user_points_balance;
|
|
35
|
-
itemTransformed.total_ever = item.user_points_ever;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return itemTransformed as TActivityLog;
|
|
39
|
-
});
|
|
31
|
+
return mapActivityLogHistory(items)
|
|
32
|
+
.filter((entry) => entry.is_wallet_entry)
|
|
33
|
+
.map(toTActivityLog);
|
|
40
34
|
};
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
/** Maps wire rows to the full v2 {@link TActivityLogEntry} shape. */
|
|
37
|
+
export const ActivityLogV2Transform = (items: ActivityLogEntry[] | unknown[]): TActivityLogEntry[] => {
|
|
38
|
+
if (!items) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return mapActivityLogHistory(items);
|
|
42
|
+
};
|
package/src/ActivityLog/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './GetActivityLogRequest';
|
|
2
2
|
export * from './GetActivityLogResponse';
|
|
3
3
|
export * from './ActivityLogEntry';
|
|
4
|
+
export * from './ActivityLogActivities';
|
|
5
|
+
export * from './ActivityLogMeta';
|
|
6
|
+
export * from './ActivityLogMapper';
|
|
4
7
|
export * from './PointChangeSourceType';
|
|
5
8
|
export * from './UserBalanceType';
|
|
6
|
-
|
|
7
|
-
|
package/src/SmarticoAPI.ts
CHANGED
|
@@ -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 };
|
package/src/WSAPI/WSAPIBase.ts
CHANGED
|
@@ -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',
|
package/src/WSAPI/WSAPITypes.ts
CHANGED
|
@@ -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,31 @@ 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
|
+
entry_key: string;
|
|
1815
|
+
create_date: number;
|
|
1816
|
+
user_ext_id: string;
|
|
1817
|
+
crm_brand_id: number;
|
|
1818
|
+
type: UserBalanceType;
|
|
1819
|
+
amount: number;
|
|
1820
|
+
balance: number;
|
|
1821
|
+
total_ever?: number;
|
|
1822
|
+
source_type_id: PointChangeSourceType;
|
|
1823
|
+
activity_type_id?: ActivityLogActivities;
|
|
1824
|
+
context_value_1?: number;
|
|
1825
|
+
meta?: ActivityLogMeta;
|
|
1826
|
+
source_entity_name?: string;
|
|
1827
|
+
source_entity_id?: number;
|
|
1828
|
+
source_reference_id?: number;
|
|
1829
|
+
source_root_id?: number;
|
|
1830
|
+
is_wallet_entry: boolean;
|
|
1831
|
+
is_level_entry?: boolean;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1807
1834
|
|
|
1808
1835
|
/**
|
|
1809
1836
|
* Result of `_smartico.api.requestRaffleOptin({raffle_id, draw_id, raffle_run_id})`.
|