@smartico/public-api 0.0.387 → 0.0.389
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/README.md +1 -1
- package/dist/CustomSections/AchCustomSection.d.ts +2 -1
- package/dist/SmarticoAPI.d.ts +4 -3
- package/dist/WSAPI/WSAPIAvatars.d.ts +1 -4
- package/dist/WSAPI/WSAPILeaderBoard.d.ts +76 -10
- package/dist/WSAPI/WSAPITypes.d.ts +16 -3
- package/dist/index.js +268 -159
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +116 -28
- package/dist/index.modern.mjs.map +1 -1
- package/docs/api/classes/WSAPILeaderBoard.md +86 -10
- package/docs/api/interfaces/LeaderBoardDetailsT.md +19 -0
- package/docs/api/interfaces/LeaderBoardUserT.md +14 -2
- package/docs/native/PROTOCOL.md +34 -6
- package/docs/ui/leaderboard/UIGuide_getLeaderBoard.md +15 -0
- package/package.json +1 -1
- package/src/CustomSections/AchCustomSection.ts +1 -0
- package/src/Leaderboard/LeaderBoards.ts +9 -12
- package/src/SmarticoAPI.ts +33 -5
- package/src/WSAPI/WSAPIAvatars.ts +2 -5
- package/src/WSAPI/WSAPILeaderBoard.ts +91 -14
- package/src/WSAPI/WSAPITypes.ts +16 -3
package/dist/index.modern.mjs
CHANGED
|
@@ -2082,33 +2082,33 @@ const pointsRewardTransform = reward_points => {
|
|
|
2082
2082
|
};
|
|
2083
2083
|
const getLeaderBoardPlayerTransformed = (user, isMe) => {
|
|
2084
2084
|
if (user) {
|
|
2085
|
-
|
|
2085
|
+
return {
|
|
2086
2086
|
public_username: (user == null ? void 0 : user.public_username) || user.user_alt_name,
|
|
2087
2087
|
avatar_url: user.avatar_url,
|
|
2088
|
+
level_id: user.level_id,
|
|
2088
2089
|
position: user.position_in_board,
|
|
2089
2090
|
points: user.points_accumulated,
|
|
2090
|
-
|
|
2091
|
+
// The `me` entry is the current user by definition, so force `true`
|
|
2092
|
+
// there; list rows carry the server-provided flag.
|
|
2093
|
+
is_me: isMe ? true : user.is_me
|
|
2091
2094
|
};
|
|
2092
|
-
if (isMe) {
|
|
2093
|
-
delete x.is_me;
|
|
2094
|
-
}
|
|
2095
|
-
return x;
|
|
2096
2095
|
}
|
|
2097
2096
|
return null;
|
|
2098
2097
|
};
|
|
2099
2098
|
const getLeaderBoardTransform = board => {
|
|
2100
2099
|
if (board) {
|
|
2101
|
-
|
|
2100
|
+
return {
|
|
2102
2101
|
board_id: board.board_id,
|
|
2103
2102
|
name: board.board_public_meta.name,
|
|
2104
2103
|
description: board.board_public_meta.description,
|
|
2105
2104
|
rules: board.board_public_meta.rules,
|
|
2106
2105
|
period_type_id: board.period_type_id,
|
|
2106
|
+
version_id: board.versiod_id,
|
|
2107
|
+
create_date: board.create_date,
|
|
2107
2108
|
rewards: pointsRewardTransform(board.reward_points),
|
|
2108
|
-
users: board.positions.map(p => getLeaderBoardPlayerTransformed(p)),
|
|
2109
|
+
users: (board.positions || []).map(p => getLeaderBoardPlayerTransformed(p)),
|
|
2109
2110
|
me: getLeaderBoardPlayerTransformed(board.userPosition, true)
|
|
2110
2111
|
};
|
|
2111
|
-
return x;
|
|
2112
2112
|
}
|
|
2113
2113
|
return null;
|
|
2114
2114
|
};
|
|
@@ -7593,7 +7593,6 @@ class WSAPIAvatars extends WSAPIMiniGames {
|
|
|
7593
7593
|
*
|
|
7594
7594
|
* **Visitor mode**: not supported (throws).
|
|
7595
7595
|
*
|
|
7596
|
-
* @param props.label_id Numeric Smartico label (brand) ID the user belongs to.
|
|
7597
7596
|
* @param props.user_id Numeric Smartico user ID.
|
|
7598
7597
|
* @param props.prompt_id Style-prompt ID (`prompt_id`) from {@link getAvatarPrompts}.
|
|
7599
7598
|
* @param props.avatar_url CDN URL of the base avatar to customize.
|
|
@@ -7603,13 +7602,12 @@ class WSAPIAvatars extends WSAPIMiniGames {
|
|
|
7603
7602
|
*
|
|
7604
7603
|
* @example
|
|
7605
7604
|
* ```ts
|
|
7606
|
-
* //
|
|
7605
|
+
* // user_id identifies the Smartico user being customized.
|
|
7607
7606
|
* const prompts = await window._smartico.api.getAvatarPrompts();
|
|
7608
7607
|
* const prompt = prompts[0];
|
|
7609
7608
|
*
|
|
7610
7609
|
* console.log('[smartico] generating avatar — show a spinner for ~5-20s and disable the Generate button');
|
|
7611
7610
|
* const result = await window._smartico.api.avatarsCustomize({
|
|
7612
|
-
* label_id,
|
|
7613
7611
|
* user_id,
|
|
7614
7612
|
* prompt_id: prompt.prompt_id,
|
|
7615
7613
|
* avatar_url: baseAvatar.avatar_url,
|
|
@@ -7629,7 +7627,7 @@ class WSAPIAvatars extends WSAPIMiniGames {
|
|
|
7629
7627
|
* ```
|
|
7630
7628
|
*/
|
|
7631
7629
|
async avatarsCustomize(props) {
|
|
7632
|
-
const required = ['
|
|
7630
|
+
const required = ['user_id', 'prompt_id', 'avatar_url', 'avatar_real_id'];
|
|
7633
7631
|
for (const field of required) {
|
|
7634
7632
|
if (!props[field]) {
|
|
7635
7633
|
throw new Error(`${field} is required`);
|
|
@@ -8307,7 +8305,9 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8307
8305
|
*
|
|
8308
8306
|
* The leaderboard for each period type is configured separately by
|
|
8309
8307
|
* the operator. A label may have any combination of DAILY, WEEKLY,
|
|
8310
|
-
* and MONTHLY boards configured (or none).
|
|
8308
|
+
* and MONTHLY boards configured (or none). To discover which boards
|
|
8309
|
+
* exist before loading any standings, call {@link getLeaderBoards}
|
|
8310
|
+
* (metadata only) and drive the tab selector from its `period_type_id`s.
|
|
8311
8311
|
*
|
|
8312
8312
|
* @remarks
|
|
8313
8313
|
* **Return value note** — the runtime may return `undefined` if no
|
|
@@ -8319,10 +8319,13 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8319
8319
|
* Pass a `periodType` from {@link LeaderBoardPeriodType}
|
|
8320
8320
|
* (`DAILY = 1`, `WEEKLY = 2`, `MONTHLY = 3`). Pass
|
|
8321
8321
|
* `getPreviousPeriod: true` to fetch the most-recently-ended
|
|
8322
|
-
* period's snapshot (yesterday's
|
|
8323
|
-
*
|
|
8324
|
-
*
|
|
8325
|
-
*
|
|
8322
|
+
* period's snapshot (yesterday's / last week's / last month's
|
|
8323
|
+
* results) instead of the current live period. To reach older
|
|
8324
|
+
* snapshots, pass a number instead of a boolean: `1` = previous
|
|
8325
|
+
* period, `2` = the one before that, and so on (`0` / `false` =
|
|
8326
|
+
* current). Use the snapshot's `create_date` / `version_id` to label
|
|
8327
|
+
* which historical run a previous-period board is. How far back
|
|
8328
|
+
* snapshots are retained is operator-configured.
|
|
8326
8329
|
*
|
|
8327
8330
|
* **Top-20 cap**
|
|
8328
8331
|
* The server hard-caps `users[]` at 20 entries, ordered by
|
|
@@ -8376,10 +8379,11 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8376
8379
|
* Selects which pre-configured board to
|
|
8377
8380
|
* fetch; the board itself is bound to one
|
|
8378
8381
|
* period by the operator.
|
|
8379
|
-
* @param getPreviousPeriod
|
|
8380
|
-
*
|
|
8381
|
-
*
|
|
8382
|
-
* `
|
|
8382
|
+
* @param getPreviousPeriod Which period to fetch. `false` (default)
|
|
8383
|
+
* = current in-progress period; `true` =
|
|
8384
|
+
* the most recent finalized snapshot; a
|
|
8385
|
+
* number `n` = the n-th previous snapshot
|
|
8386
|
+
* (`1` = previous, `2` = the one before, …).
|
|
8383
8387
|
* @returns Promise resolving to `LeaderBoardDetailsT`.
|
|
8384
8388
|
* **At runtime, may resolve to `undefined`**
|
|
8385
8389
|
* when no board is configured for the
|
|
@@ -8423,10 +8427,75 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8423
8427
|
* ```
|
|
8424
8428
|
*/
|
|
8425
8429
|
async getLeaderBoard(periodType, getPreviousPeriod) {
|
|
8426
|
-
//
|
|
8427
|
-
//
|
|
8428
|
-
const
|
|
8429
|
-
|
|
8430
|
+
// Resolve the snapshot offset: false/omitted → 0 (current), true → 1
|
|
8431
|
+
// (previous), or an explicit number for older snapshots.
|
|
8432
|
+
const offset = typeof getPreviousPeriod === 'number' ? getPreviousPeriod : getPreviousPeriod ? 1 : 0;
|
|
8433
|
+
// Cache per (periodType, offset) so switching tabs or period within the
|
|
8434
|
+
// TTL doesn't return a colliding board.
|
|
8435
|
+
const cacheKey = `${onUpdateContextKey.LeaderBoards}:${periodType}:${offset}`;
|
|
8436
|
+
return OCache.use(cacheKey, ECacheContext.WSAPI, () => this.api.leaderboardsGetT(this.userExtId, periodType, offset), CACHE_DATA_SEC);
|
|
8437
|
+
}
|
|
8438
|
+
/**
|
|
8439
|
+
* Returns the list of leaderboards the operator has configured for this
|
|
8440
|
+
* label — **metadata only, without participants**. Use it to discover
|
|
8441
|
+
* which boards exist (and their period types) so you can render the
|
|
8442
|
+
* board/tab selector, then load a specific board's standings on demand
|
|
8443
|
+
* with {@link getLeaderBoard}.
|
|
8444
|
+
*
|
|
8445
|
+
* This is the lightweight discovery counterpart to {@link getLeaderBoard}:
|
|
8446
|
+
* it issues one round-trip that returns every board's identity, name,
|
|
8447
|
+
* description, rules, `period_type_id`, and prize table, but **not** the
|
|
8448
|
+
* ranked players. Fetching the full standings for one board (the top-20
|
|
8449
|
+
* `users[]` and the caller's own `me` entry) is what {@link getLeaderBoard}
|
|
8450
|
+
* does per period.
|
|
8451
|
+
*
|
|
8452
|
+
* @remarks
|
|
8453
|
+
* **Returned shape**
|
|
8454
|
+
* An array of `LeaderBoardDetailsT`, one per configured board, ordered by
|
|
8455
|
+
* `period_type_id` ascending (DAILY, WEEKLY, MONTHLY, …). On every entry
|
|
8456
|
+
* `users` is an empty array and `me` is `undefined` — this call never
|
|
8457
|
+
* carries participant data. Read `period_type_id` from each entry and pass
|
|
8458
|
+
* it to {@link getLeaderBoard} to load that board's standings.
|
|
8459
|
+
*
|
|
8460
|
+
* **Empty result**
|
|
8461
|
+
* Resolves to an empty array when the label has no leaderboards configured
|
|
8462
|
+
* — treat that as "hide the leaderboard surface".
|
|
8463
|
+
*
|
|
8464
|
+
* **Cache TTL**
|
|
8465
|
+
* Cached for 30 seconds under a dedicated key (independent of
|
|
8466
|
+
* {@link getLeaderBoard}'s per-period cache). Repeated calls within the
|
|
8467
|
+
* window return the cached list without a round-trip.
|
|
8468
|
+
*
|
|
8469
|
+
* **Refresh model**: one-shot fetch — no subscription, no push. Board
|
|
8470
|
+
* configuration changes surface on the next cache miss.
|
|
8471
|
+
*
|
|
8472
|
+
* **Idempotency / Side effects**: safe. Read-only.
|
|
8473
|
+
*
|
|
8474
|
+
* **Visitor mode**: supported. Returns the brand's public board list.
|
|
8475
|
+
*
|
|
8476
|
+
* @returns Promise resolving to the array of configured boards
|
|
8477
|
+
* (metadata only). Empty array when none are configured.
|
|
8478
|
+
*
|
|
8479
|
+
* @example
|
|
8480
|
+
* ```ts
|
|
8481
|
+
* const boards = await window._smartico.api.getLeaderBoards();
|
|
8482
|
+
*
|
|
8483
|
+
* if (boards.length === 0) {
|
|
8484
|
+
* console.log('[smartico] no leaderboards configured — hide the leaderboard surface');
|
|
8485
|
+
* return;
|
|
8486
|
+
* }
|
|
8487
|
+
*
|
|
8488
|
+
* // Render one tab per board from the lightweight list (no players yet).
|
|
8489
|
+
* console.log('[smartico] render leaderboard tabs:', boards.map(b => b.name));
|
|
8490
|
+
*
|
|
8491
|
+
* // When the user opens a tab, load that board's standings on demand.
|
|
8492
|
+
* const first = boards[0];
|
|
8493
|
+
* const full = await window._smartico.api.getLeaderBoard(first.period_type_id);
|
|
8494
|
+
* console.log('[smartico] loaded standings for', first.name, '—', full?.users.length ?? 0, 'players');
|
|
8495
|
+
* ```
|
|
8496
|
+
*/
|
|
8497
|
+
async getLeaderBoards() {
|
|
8498
|
+
return OCache.use(`${onUpdateContextKey.LeaderBoards}:list`, ECacheContext.WSAPI, () => this.api.leaderboardsGetListT(this.userExtId), CACHE_DATA_SEC);
|
|
8430
8499
|
}
|
|
8431
8500
|
}
|
|
8432
8501
|
|
|
@@ -9209,6 +9278,7 @@ var LiquidEntityData;
|
|
|
9209
9278
|
LiquidEntityData[LiquidEntityData["Tournament"] = 10] = "Tournament";
|
|
9210
9279
|
LiquidEntityData[LiquidEntityData["Raffles"] = 11] = "Raffles";
|
|
9211
9280
|
LiquidEntityData[LiquidEntityData["SingleRaffle"] = 12] = "SingleRaffle";
|
|
9281
|
+
LiquidEntityData[LiquidEntityData["Clans"] = 13] = "Clans";
|
|
9212
9282
|
})(LiquidEntityData || (LiquidEntityData = {}));
|
|
9213
9283
|
|
|
9214
9284
|
const UICustomSectionTransform = response => {
|
|
@@ -10067,9 +10137,12 @@ class SmarticoAPI {
|
|
|
10067
10137
|
}
|
|
10068
10138
|
async leaderboardGet(user_ext_id, period_type_id, prevPeriod = false, force_language) {
|
|
10069
10139
|
var _response$map$boardKe, _response$map$boardKe2;
|
|
10140
|
+
// boolean keeps back-compat (false → current, true → previous);
|
|
10141
|
+
// a number selects an arbitrary snapshot offset (1 = previous, 2 = the one before, …).
|
|
10142
|
+
const snapshot_offset = typeof prevPeriod === 'number' ? prevPeriod : prevPeriod ? 1 : 0;
|
|
10070
10143
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST, {
|
|
10071
10144
|
period_type_id,
|
|
10072
|
-
snapshot_offset
|
|
10145
|
+
snapshot_offset,
|
|
10073
10146
|
include_users: true
|
|
10074
10147
|
});
|
|
10075
10148
|
const response = await this.send(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language);
|
|
@@ -10090,6 +10163,20 @@ class SmarticoAPI {
|
|
|
10090
10163
|
async leaderboardsGetT(user_ext_id, period_type_id = LeaderBoardPeriodType.DAILY, prevPeriod = false) {
|
|
10091
10164
|
return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
|
|
10092
10165
|
}
|
|
10166
|
+
async leaderboardsGetList(user_ext_id, force_language) {
|
|
10167
|
+
const message = this.buildMessage(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST, {
|
|
10168
|
+
// No period_type_id → the server returns every configured board.
|
|
10169
|
+
// include_users: false → board metadata only (no positions / userPosition).
|
|
10170
|
+
snapshot_offset: 0,
|
|
10171
|
+
include_users: false
|
|
10172
|
+
});
|
|
10173
|
+
const response = await this.send(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language);
|
|
10174
|
+
// map is keyed by period_type_id; integer-like keys iterate in ascending order.
|
|
10175
|
+
return Object.values(response.map || {});
|
|
10176
|
+
}
|
|
10177
|
+
async leaderboardsGetListT(user_ext_id) {
|
|
10178
|
+
return (await this.leaderboardsGetList(user_ext_id)).map(getLeaderBoardTransform);
|
|
10179
|
+
}
|
|
10093
10180
|
async levelsGet(user_ext_id, force_language) {
|
|
10094
10181
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
|
|
10095
10182
|
return await this.send(message, ClassId.GET_LEVEL_MAP_RESPONSE, force_language);
|
|
@@ -10401,7 +10488,8 @@ class SmarticoAPI {
|
|
|
10401
10488
|
return this.sendAvatarApi({
|
|
10402
10489
|
method: 'avatar-customize',
|
|
10403
10490
|
body: {
|
|
10404
|
-
label_id
|
|
10491
|
+
// The server resolves label_id from label_api_key.
|
|
10492
|
+
label_api_key: this.label_api_key,
|
|
10405
10493
|
user_id: params.user_id,
|
|
10406
10494
|
user_ext_id: (_this$tracker = this.tracker) == null ? void 0 : _this$tracker.getExtUserId(),
|
|
10407
10495
|
brand_key: this.brand_api_key || ((_this$tracker2 = this.tracker) == null || (_this$tracker2 = _this$tracker2.params) == null ? void 0 : _this$tracker2.brand_key),
|