@smartico/public-api 0.0.387 → 0.0.388
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 -2
- package/dist/WSAPI/WSAPILeaderBoard.d.ts +76 -10
- package/dist/WSAPI/WSAPITypes.d.ts +16 -3
- package/dist/index.js +264 -154
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +112 -23
- 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 +31 -3
- 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
|
};
|
|
@@ -8307,7 +8307,9 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8307
8307
|
*
|
|
8308
8308
|
* The leaderboard for each period type is configured separately by
|
|
8309
8309
|
* the operator. A label may have any combination of DAILY, WEEKLY,
|
|
8310
|
-
* and MONTHLY boards configured (or none).
|
|
8310
|
+
* and MONTHLY boards configured (or none). To discover which boards
|
|
8311
|
+
* exist before loading any standings, call {@link getLeaderBoards}
|
|
8312
|
+
* (metadata only) and drive the tab selector from its `period_type_id`s.
|
|
8311
8313
|
*
|
|
8312
8314
|
* @remarks
|
|
8313
8315
|
* **Return value note** — the runtime may return `undefined` if no
|
|
@@ -8319,10 +8321,13 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8319
8321
|
* Pass a `periodType` from {@link LeaderBoardPeriodType}
|
|
8320
8322
|
* (`DAILY = 1`, `WEEKLY = 2`, `MONTHLY = 3`). Pass
|
|
8321
8323
|
* `getPreviousPeriod: true` to fetch the most-recently-ended
|
|
8322
|
-
* period's snapshot (yesterday's
|
|
8323
|
-
*
|
|
8324
|
-
*
|
|
8325
|
-
*
|
|
8324
|
+
* period's snapshot (yesterday's / last week's / last month's
|
|
8325
|
+
* results) instead of the current live period. To reach older
|
|
8326
|
+
* snapshots, pass a number instead of a boolean: `1` = previous
|
|
8327
|
+
* period, `2` = the one before that, and so on (`0` / `false` =
|
|
8328
|
+
* current). Use the snapshot's `create_date` / `version_id` to label
|
|
8329
|
+
* which historical run a previous-period board is. How far back
|
|
8330
|
+
* snapshots are retained is operator-configured.
|
|
8326
8331
|
*
|
|
8327
8332
|
* **Top-20 cap**
|
|
8328
8333
|
* The server hard-caps `users[]` at 20 entries, ordered by
|
|
@@ -8376,10 +8381,11 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8376
8381
|
* Selects which pre-configured board to
|
|
8377
8382
|
* fetch; the board itself is bound to one
|
|
8378
8383
|
* period by the operator.
|
|
8379
|
-
* @param getPreviousPeriod
|
|
8380
|
-
*
|
|
8381
|
-
*
|
|
8382
|
-
* `
|
|
8384
|
+
* @param getPreviousPeriod Which period to fetch. `false` (default)
|
|
8385
|
+
* = current in-progress period; `true` =
|
|
8386
|
+
* the most recent finalized snapshot; a
|
|
8387
|
+
* number `n` = the n-th previous snapshot
|
|
8388
|
+
* (`1` = previous, `2` = the one before, …).
|
|
8383
8389
|
* @returns Promise resolving to `LeaderBoardDetailsT`.
|
|
8384
8390
|
* **At runtime, may resolve to `undefined`**
|
|
8385
8391
|
* when no board is configured for the
|
|
@@ -8423,10 +8429,75 @@ class WSAPILeaderBoard extends WSAPIGamePick {
|
|
|
8423
8429
|
* ```
|
|
8424
8430
|
*/
|
|
8425
8431
|
async getLeaderBoard(periodType, getPreviousPeriod) {
|
|
8426
|
-
//
|
|
8427
|
-
//
|
|
8428
|
-
const
|
|
8429
|
-
|
|
8432
|
+
// Resolve the snapshot offset: false/omitted → 0 (current), true → 1
|
|
8433
|
+
// (previous), or an explicit number for older snapshots.
|
|
8434
|
+
const offset = typeof getPreviousPeriod === 'number' ? getPreviousPeriod : getPreviousPeriod ? 1 : 0;
|
|
8435
|
+
// Cache per (periodType, offset) so switching tabs or period within the
|
|
8436
|
+
// TTL doesn't return a colliding board.
|
|
8437
|
+
const cacheKey = `${onUpdateContextKey.LeaderBoards}:${periodType}:${offset}`;
|
|
8438
|
+
return OCache.use(cacheKey, ECacheContext.WSAPI, () => this.api.leaderboardsGetT(this.userExtId, periodType, offset), CACHE_DATA_SEC);
|
|
8439
|
+
}
|
|
8440
|
+
/**
|
|
8441
|
+
* Returns the list of leaderboards the operator has configured for this
|
|
8442
|
+
* label — **metadata only, without participants**. Use it to discover
|
|
8443
|
+
* which boards exist (and their period types) so you can render the
|
|
8444
|
+
* board/tab selector, then load a specific board's standings on demand
|
|
8445
|
+
* with {@link getLeaderBoard}.
|
|
8446
|
+
*
|
|
8447
|
+
* This is the lightweight discovery counterpart to {@link getLeaderBoard}:
|
|
8448
|
+
* it issues one round-trip that returns every board's identity, name,
|
|
8449
|
+
* description, rules, `period_type_id`, and prize table, but **not** the
|
|
8450
|
+
* ranked players. Fetching the full standings for one board (the top-20
|
|
8451
|
+
* `users[]` and the caller's own `me` entry) is what {@link getLeaderBoard}
|
|
8452
|
+
* does per period.
|
|
8453
|
+
*
|
|
8454
|
+
* @remarks
|
|
8455
|
+
* **Returned shape**
|
|
8456
|
+
* An array of `LeaderBoardDetailsT`, one per configured board, ordered by
|
|
8457
|
+
* `period_type_id` ascending (DAILY, WEEKLY, MONTHLY, …). On every entry
|
|
8458
|
+
* `users` is an empty array and `me` is `undefined` — this call never
|
|
8459
|
+
* carries participant data. Read `period_type_id` from each entry and pass
|
|
8460
|
+
* it to {@link getLeaderBoard} to load that board's standings.
|
|
8461
|
+
*
|
|
8462
|
+
* **Empty result**
|
|
8463
|
+
* Resolves to an empty array when the label has no leaderboards configured
|
|
8464
|
+
* — treat that as "hide the leaderboard surface".
|
|
8465
|
+
*
|
|
8466
|
+
* **Cache TTL**
|
|
8467
|
+
* Cached for 30 seconds under a dedicated key (independent of
|
|
8468
|
+
* {@link getLeaderBoard}'s per-period cache). Repeated calls within the
|
|
8469
|
+
* window return the cached list without a round-trip.
|
|
8470
|
+
*
|
|
8471
|
+
* **Refresh model**: one-shot fetch — no subscription, no push. Board
|
|
8472
|
+
* configuration changes surface on the next cache miss.
|
|
8473
|
+
*
|
|
8474
|
+
* **Idempotency / Side effects**: safe. Read-only.
|
|
8475
|
+
*
|
|
8476
|
+
* **Visitor mode**: supported. Returns the brand's public board list.
|
|
8477
|
+
*
|
|
8478
|
+
* @returns Promise resolving to the array of configured boards
|
|
8479
|
+
* (metadata only). Empty array when none are configured.
|
|
8480
|
+
*
|
|
8481
|
+
* @example
|
|
8482
|
+
* ```ts
|
|
8483
|
+
* const boards = await window._smartico.api.getLeaderBoards();
|
|
8484
|
+
*
|
|
8485
|
+
* if (boards.length === 0) {
|
|
8486
|
+
* console.log('[smartico] no leaderboards configured — hide the leaderboard surface');
|
|
8487
|
+
* return;
|
|
8488
|
+
* }
|
|
8489
|
+
*
|
|
8490
|
+
* // Render one tab per board from the lightweight list (no players yet).
|
|
8491
|
+
* console.log('[smartico] render leaderboard tabs:', boards.map(b => b.name));
|
|
8492
|
+
*
|
|
8493
|
+
* // When the user opens a tab, load that board's standings on demand.
|
|
8494
|
+
* const first = boards[0];
|
|
8495
|
+
* const full = await window._smartico.api.getLeaderBoard(first.period_type_id);
|
|
8496
|
+
* console.log('[smartico] loaded standings for', first.name, '—', full?.users.length ?? 0, 'players');
|
|
8497
|
+
* ```
|
|
8498
|
+
*/
|
|
8499
|
+
async getLeaderBoards() {
|
|
8500
|
+
return OCache.use(`${onUpdateContextKey.LeaderBoards}:list`, ECacheContext.WSAPI, () => this.api.leaderboardsGetListT(this.userExtId), CACHE_DATA_SEC);
|
|
8430
8501
|
}
|
|
8431
8502
|
}
|
|
8432
8503
|
|
|
@@ -9209,6 +9280,7 @@ var LiquidEntityData;
|
|
|
9209
9280
|
LiquidEntityData[LiquidEntityData["Tournament"] = 10] = "Tournament";
|
|
9210
9281
|
LiquidEntityData[LiquidEntityData["Raffles"] = 11] = "Raffles";
|
|
9211
9282
|
LiquidEntityData[LiquidEntityData["SingleRaffle"] = 12] = "SingleRaffle";
|
|
9283
|
+
LiquidEntityData[LiquidEntityData["Clans"] = 13] = "Clans";
|
|
9212
9284
|
})(LiquidEntityData || (LiquidEntityData = {}));
|
|
9213
9285
|
|
|
9214
9286
|
const UICustomSectionTransform = response => {
|
|
@@ -10067,9 +10139,12 @@ class SmarticoAPI {
|
|
|
10067
10139
|
}
|
|
10068
10140
|
async leaderboardGet(user_ext_id, period_type_id, prevPeriod = false, force_language) {
|
|
10069
10141
|
var _response$map$boardKe, _response$map$boardKe2;
|
|
10142
|
+
// boolean keeps back-compat (false → current, true → previous);
|
|
10143
|
+
// a number selects an arbitrary snapshot offset (1 = previous, 2 = the one before, …).
|
|
10144
|
+
const snapshot_offset = typeof prevPeriod === 'number' ? prevPeriod : prevPeriod ? 1 : 0;
|
|
10070
10145
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST, {
|
|
10071
10146
|
period_type_id,
|
|
10072
|
-
snapshot_offset
|
|
10147
|
+
snapshot_offset,
|
|
10073
10148
|
include_users: true
|
|
10074
10149
|
});
|
|
10075
10150
|
const response = await this.send(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language);
|
|
@@ -10090,6 +10165,20 @@ class SmarticoAPI {
|
|
|
10090
10165
|
async leaderboardsGetT(user_ext_id, period_type_id = LeaderBoardPeriodType.DAILY, prevPeriod = false) {
|
|
10091
10166
|
return getLeaderBoardTransform(await this.leaderboardGet(user_ext_id, period_type_id, prevPeriod));
|
|
10092
10167
|
}
|
|
10168
|
+
async leaderboardsGetList(user_ext_id, force_language) {
|
|
10169
|
+
const message = this.buildMessage(user_ext_id, ClassId.GET_LEADERS_BOARD_REQUEST, {
|
|
10170
|
+
// No period_type_id → the server returns every configured board.
|
|
10171
|
+
// include_users: false → board metadata only (no positions / userPosition).
|
|
10172
|
+
snapshot_offset: 0,
|
|
10173
|
+
include_users: false
|
|
10174
|
+
});
|
|
10175
|
+
const response = await this.send(message, ClassId.GET_LEADERS_BOARD_RESPONSE, force_language);
|
|
10176
|
+
// map is keyed by period_type_id; integer-like keys iterate in ascending order.
|
|
10177
|
+
return Object.values(response.map || {});
|
|
10178
|
+
}
|
|
10179
|
+
async leaderboardsGetListT(user_ext_id) {
|
|
10180
|
+
return (await this.leaderboardsGetList(user_ext_id)).map(getLeaderBoardTransform);
|
|
10181
|
+
}
|
|
10093
10182
|
async levelsGet(user_ext_id, force_language) {
|
|
10094
10183
|
const message = this.buildMessage(user_ext_id, ClassId.GET_LEVEL_MAP_REQUEST);
|
|
10095
10184
|
return await this.send(message, ClassId.GET_LEVEL_MAP_RESPONSE, force_language);
|