@playbasis-ai/qwikcard-sdk 2.3.17 → 2.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +33 -2
- package/dist/web/widgetAssets.d.ts +2 -2
- package/dist/web/widgetAssets.d.ts.map +1 -1
- package/dist/web/widgetAssets.js +2 -2
- package/package.json +1 -1
- package/src/api/client.ts +49 -5
- package/src/web/widgetAssets.ts +2 -4
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -311,12 +311,56 @@ export class PlaybasisClient {
|
|
|
311
311
|
if (options?.limit) params.set('limit', String(options.limit));
|
|
312
312
|
if (options?.cursor) params.set('cursor', options.cursor);
|
|
313
313
|
|
|
314
|
-
const data = await this.request<
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
const data = await this.request<
|
|
315
|
+
| { entries?: LeaderboardEntry[]; total?: number }
|
|
316
|
+
| { items?: LeaderboardEntry[]; total?: number }
|
|
317
|
+
| { leaderboard?: { entries?: LeaderboardEntry[]; total?: number } }
|
|
318
|
+
>('GET', `/leaderboards/${encodeURIComponent(leaderboardId)}?${params}`);
|
|
319
|
+
const leaderboardData = data as { leaderboard?: { entries?: LeaderboardEntry[]; total?: number } };
|
|
320
|
+
const entries =
|
|
321
|
+
'entries' in data
|
|
322
|
+
? data.entries
|
|
323
|
+
: 'items' in data
|
|
324
|
+
? data.items
|
|
325
|
+
: leaderboardData.leaderboard?.entries;
|
|
326
|
+
const total =
|
|
327
|
+
'total' in data && typeof data.total === 'number'
|
|
328
|
+
? data.total
|
|
329
|
+
: leaderboardData.leaderboard?.total ?? entries?.length ?? 0;
|
|
330
|
+
|
|
331
|
+
const normalizedEntries = (entries || []).map((entry, index) => {
|
|
332
|
+
const raw = entry as LeaderboardEntry & {
|
|
333
|
+
balance?: number;
|
|
334
|
+
points?: number;
|
|
335
|
+
value?: number;
|
|
336
|
+
name?: string;
|
|
337
|
+
id?: string;
|
|
338
|
+
};
|
|
339
|
+
const score =
|
|
340
|
+
typeof raw.score === 'number'
|
|
341
|
+
? raw.score
|
|
342
|
+
: typeof raw.balance === 'number'
|
|
343
|
+
? raw.balance
|
|
344
|
+
: typeof raw.points === 'number'
|
|
345
|
+
? raw.points
|
|
346
|
+
: typeof raw.value === 'number'
|
|
347
|
+
? raw.value
|
|
348
|
+
: 0;
|
|
349
|
+
const rank = typeof raw.rank === 'number' ? raw.rank : index + 1;
|
|
350
|
+
const displayName = raw.displayName || raw.name || raw.playerId || 'Player';
|
|
351
|
+
const playerId = raw.playerId || raw.id || displayName;
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
playerId,
|
|
355
|
+
displayName,
|
|
356
|
+
rank,
|
|
357
|
+
score,
|
|
358
|
+
metadata: raw.metadata,
|
|
359
|
+
};
|
|
360
|
+
});
|
|
317
361
|
return {
|
|
318
|
-
entries:
|
|
319
|
-
total
|
|
362
|
+
entries: normalizedEntries,
|
|
363
|
+
total,
|
|
320
364
|
};
|
|
321
365
|
}
|
|
322
366
|
|