@smartico/public-api 0.0.379 → 0.0.380
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/.nvmrc +1 -1
- package/README.md +31 -2
- package/dist/Store/BuyStoreItemErrorCode.d.ts +9 -1
- package/dist/Tournaments/TournamentRegistrationError.d.ts +3 -1
- package/dist/WSAPI/WSAPI.d.ts +13 -1235
- package/dist/WSAPI/WSAPIAvatars.d.ts +78 -0
- package/dist/WSAPI/WSAPIBase.d.ts +71 -0
- package/dist/WSAPI/WSAPIBonuses.d.ts +26 -0
- package/dist/WSAPI/WSAPIClans.d.ts +388 -0
- package/dist/WSAPI/WSAPIGamePick.d.ts +308 -0
- package/dist/WSAPI/WSAPIGeneral.d.ts +30 -0
- package/dist/WSAPI/WSAPIInbox.d.ts +126 -0
- package/dist/WSAPI/WSAPIJackpots.d.ts +109 -0
- package/dist/WSAPI/WSAPILeaderBoard.d.ts +25 -0
- package/dist/WSAPI/WSAPIMiniGames.d.ts +94 -0
- package/dist/WSAPI/WSAPIMissions.d.ts +517 -0
- package/dist/WSAPI/WSAPIRaffles.d.ts +119 -0
- package/dist/WSAPI/WSAPIStore.d.ts +656 -0
- package/dist/WSAPI/WSAPITournaments.d.ts +501 -0
- package/dist/WSAPI/WSAPITypes.d.ts +145 -85
- package/dist/WSAPI/WSAPIUser.d.ts +383 -0
- package/dist/index.js +3818 -1528
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +3180 -981
- package/dist/index.modern.mjs.map +1 -1
- package/docs/api/README.md +56 -2
- package/docs/api/classes/WSAPIAvatars.md +116 -0
- package/docs/api/classes/WSAPIBonuses.md +50 -0
- package/docs/api/classes/WSAPIClans.md +66 -0
- package/docs/api/classes/WSAPIGamePick.md +181 -0
- package/docs/api/classes/WSAPIGeneral.md +63 -0
- package/docs/api/classes/WSAPIInbox.md +277 -0
- package/docs/api/classes/WSAPIJackpots.md +185 -0
- package/docs/api/classes/WSAPILeaderBoard.md +39 -0
- package/docs/api/classes/WSAPIMiniGames.md +175 -0
- package/docs/api/classes/WSAPIMissions.md +611 -0
- package/docs/api/classes/WSAPIRaffles.md +195 -0
- package/docs/api/classes/WSAPIStore.md +744 -0
- package/docs/api/classes/WSAPITournaments.md +104 -0
- package/docs/api/classes/WSAPIUser.md +200 -0
- package/docs/api/enumerations/AchievementClaimPeriodTypeId.md +13 -0
- package/docs/api/enumerations/BuyStoreItemErrorCode.md +32 -0
- package/docs/api/interfaces/ClanPrizePublicMeta.md +41 -0
- package/docs/api/interfaces/ClanPrizeStructureEntry.md +7 -1
- package/docs/api/interfaces/ClanPublicMeta.md +4 -0
- package/docs/api/interfaces/SAWTemplateUI.md +10 -0
- package/docs/api/interfaces/TAchCategory.md +19 -4
- package/docs/api/interfaces/TBuyStoreItemResult.md +26 -8
- package/docs/api/interfaces/TMissionClaimRewardResult.md +14 -3
- package/docs/api/interfaces/TMissionOptInResult.md +10 -3
- package/docs/api/interfaces/TMissionOrBadge.md +6 -2
- package/docs/api/interfaces/TStoreItem.md +21 -1
- package/docs/api/interfaces/TTournamentDetailed.md +8 -0
- package/docs/api/interfaces/UserAchievement.md +1 -1
- package/docs/ui/clans/UIGuide_getClanInfo.md +153 -0
- package/docs/ui/clans/UIGuide_getClans.md +172 -0
- package/docs/ui/clans/UIGuide_joinClan.md +196 -0
- package/docs/ui/missions/UIGuide_getAchCategories.md +17 -0
- package/docs/ui/missions/UIGuide_getBadges.md +237 -0
- package/docs/ui/missions/UIGuide_getMissions.md +268 -0
- package/docs/ui/missions/UIGuide_requestMissionClaimReward.md +21 -0
- package/docs/ui/missions/UIGuide_requestMissionOptIn.md +16 -0
- package/docs/ui/store/UIGuide_buyStoreItem.md +133 -0
- package/docs/ui/store/UIGuide_getStoreCategories.md +19 -0
- package/docs/ui/store/UIGuide_getStoreItems.md +264 -0
- package/docs/ui/store/UIGuide_getStorePurchasedItems.md +122 -0
- package/docs/ui/tournaments/UIGuide_getClanTournamentPlayers.md +140 -0
- package/docs/ui/tournaments/UIGuide_getTournamentInstanceInfo.md +265 -0
- package/docs/ui/tournaments/UIGuide_getTournamentsList.md +236 -0
- package/docs/ui/tournaments/UIGuide_registerInTournament.md +156 -0
- package/docs/ui/user/UIGuide_getLevels.md +162 -0
- package/docs/ui/user/UIGuide_getUserProfile.md +213 -0
- package/package.json +3 -3
- package/scripts/postdoc-cleanup.js +195 -0
- package/src/Missions/MissionsUtils.ts +5 -2
- package/src/Store/BuyStoreItemErrorCode.ts +8 -0
- package/src/Store/StoreItem.ts +1 -0
- package/src/Store/StoreItemPurchased.ts +1 -0
- package/src/Store/StoreItemType.ts +1 -1
- package/src/Tournaments/TournamentRegistrationError.ts +4 -0
- package/src/WSAPI/WSAPI.ts +27 -2007
- package/src/WSAPI/WSAPIAvatars.ts +127 -0
- package/src/WSAPI/WSAPIBase.ts +93 -0
- package/src/WSAPI/WSAPIBonuses.ts +54 -0
- package/src/WSAPI/WSAPIClans.ts +417 -0
- package/src/WSAPI/WSAPIGamePick.ts +382 -0
- package/src/WSAPI/WSAPIGeneral.ts +57 -0
- package/src/WSAPI/WSAPIInbox.ts +222 -0
- package/src/WSAPI/WSAPIJackpots.ts +212 -0
- package/src/WSAPI/WSAPILeaderBoard.ts +40 -0
- package/src/WSAPI/WSAPIMiniGames.ts +181 -0
- package/src/WSAPI/WSAPIMissions.ts +572 -0
- package/src/WSAPI/WSAPIRaffles.ts +175 -0
- package/src/WSAPI/WSAPIStore.ts +732 -0
- package/src/WSAPI/WSAPITournaments.ts +541 -0
- package/src/WSAPI/WSAPITypes.ts +145 -87
- package/src/WSAPI/WSAPIUser.ts +456 -0
- package/tsconfig.json +17 -1
- package/docs/api/classes/WSAPI.md +0 -1927
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
import { TBuyStoreItemResult, TStoreCategory, TStoreItem } from './WSAPITypes';
|
|
2
|
+
import { WSAPIBonuses } from './WSAPIBonuses';
|
|
3
|
+
/** @group Store */
|
|
4
|
+
export declare class WSAPIStore extends WSAPIBonuses {
|
|
5
|
+
private storeHistoryOnUpdateParams;
|
|
6
|
+
private storeHistoryCacheKey;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the catalog of buyable store items visible to the current user,
|
|
9
|
+
* scoped server-side to what the user is qualified to see. Optionally
|
|
10
|
+
* subscribes to live updates via `onUpdate`: the callback is invoked with
|
|
11
|
+
* the full refreshed catalog after every purchase the user makes from this
|
|
12
|
+
* device.
|
|
13
|
+
*
|
|
14
|
+
* The returned list is the canonical source of truth for store state
|
|
15
|
+
* (`can_buy`, `pool`, `discounted_price`, `active_till_date`, etc.).
|
|
16
|
+
* Consumers should NEVER mutate it optimistically — always re-fetch (or
|
|
17
|
+
* wait for the `onUpdate` callback) to observe the new state.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* **Preconditions**
|
|
21
|
+
* The catalog is per-user. Visitor mode is supported with caveats (see
|
|
22
|
+
* "Visitor mode" below). For the authenticated path, the user's balances
|
|
23
|
+
* (`ach_points_balance`, `ach_gems_balance`, `ach_diamonds_balance` from
|
|
24
|
+
* {@link getUserProfile}) must be tracked client-side to drive the
|
|
25
|
+
* affordability state of the Buy button — the SDK does not pre-compute
|
|
26
|
+
* affordability into `can_buy`.
|
|
27
|
+
*
|
|
28
|
+
* **Subscription model (`onUpdate`)**
|
|
29
|
+
* The callback receives the FULL refreshed catalog (never a diff/patch).
|
|
30
|
+
* Each subsequent call to `getStoreItems({ onUpdate })` REPLACES the prior
|
|
31
|
+
* callback — only one active subscriber at a time. Pass
|
|
32
|
+
* `onUpdate: undefined` (or omit it) to keep the prior callback in place;
|
|
33
|
+
* the callback is never auto-cleared.
|
|
34
|
+
*
|
|
35
|
+
* **Update triggers**
|
|
36
|
+
*
|
|
37
|
+
* Fires after: any `buyStoreItem(...)` call resolves on this connection
|
|
38
|
+
* (success OR failure). This is the ONLY trigger. The refreshed array
|
|
39
|
+
* reflects pool decrement on the just-bought item, per-period purchase
|
|
40
|
+
* cap re-evaluation on `can_buy`, and any `purchased_today` /
|
|
41
|
+
* `purchased_this_week` / `purchased_this_month` flips visible via
|
|
42
|
+
* {@link getStorePurchasedItems}.
|
|
43
|
+
*
|
|
44
|
+
* Does NOT fire for:
|
|
45
|
+
* - Operator-side BO catalog edits (price, ribbons, pool seed, segment
|
|
46
|
+
* conditions, new/removed items) — surface only on the next cache miss.
|
|
47
|
+
* - Concurrent purchases by OTHER users — the current user's view of
|
|
48
|
+
* `pool` may be stale until they themselves refresh.
|
|
49
|
+
* - User balance changes from gameplay — the catalog is independent of
|
|
50
|
+
* balance; the consumer drives Buy-button affordability from a
|
|
51
|
+
* separately-tracked balance source.
|
|
52
|
+
* - Items going past their `active_till_date` while the page is open —
|
|
53
|
+
* the item simply disappears on the next refresh.
|
|
54
|
+
*
|
|
55
|
+
* **Server-side filtering** (what's already excluded before the SDK sees it)
|
|
56
|
+
* - Items outside the `[active_from_date, active_till_date]` window —
|
|
57
|
+
* past the till-date, items are ALWAYS filtered out server-side.
|
|
58
|
+
* - Items the user fails visibility-segment / visibility-condition
|
|
59
|
+
* checks for.
|
|
60
|
+
* - Items configured to hide-when-empty whose pool has reached 0
|
|
61
|
+
* (per-item operator flag). Items without that flag are still returned
|
|
62
|
+
* with `pool === 0` so a "Sold out" state can be rendered.
|
|
63
|
+
* - Items where the per-period bought-count cap is reached (and the
|
|
64
|
+
* operator chose to hide rather than just disable).
|
|
65
|
+
*
|
|
66
|
+
* **Reading state from the returned item**
|
|
67
|
+
* The catalog row carries everything a Buy button needs except the user's
|
|
68
|
+
* balance: `can_buy` already reflects segment / visibility / per-period
|
|
69
|
+
* cap checks, but the SDK does NOT pre-compute balance affordability —
|
|
70
|
+
* compare `discounted_price ?? price` against the user's balance for
|
|
71
|
+
* `purchase_type` (`ach_points_balance` / `ach_gems_balance` /
|
|
72
|
+
* `ach_diamonds_balance` from {@link getUserProfile}). `purchase_type` is
|
|
73
|
+
* per-item (`'points'` / `'gems'` / `'diamonds'`); operators can mix
|
|
74
|
+
* currencies within a single catalog. For sold-out display, `pool === 0`
|
|
75
|
+
* means the operator chose to keep the item visible — render an "Out of
|
|
76
|
+
* stock" overlay. When `discounted_price` is set, render `price` with a
|
|
77
|
+
* strikethrough and `discounted_price` as the active price; the
|
|
78
|
+
* accompanying `discount_price_ribbon` is either a percentage preset
|
|
79
|
+
* (`'10'`, `'15'`, `'20'`, `'25'`, `'50'`) or the literal `'custom'`
|
|
80
|
+
* (in which case `custom_ribbon_image` is the artwork at 250×300 px).
|
|
81
|
+
* A live countdown for time-limited items is rendered only when the
|
|
82
|
+
* operator has enabled the per-item `show_timer` flag.
|
|
83
|
+
*
|
|
84
|
+
* **Cross-references**
|
|
85
|
+
* `category_ids` joins to `TStoreCategory.id` from
|
|
86
|
+
* {@link getStoreCategories} (many-to-many — an item can belong to
|
|
87
|
+
* multiple categories). Items with `only_in_custom_section: true` are
|
|
88
|
+
* returned in the catalog but intended for their custom-section view
|
|
89
|
+
* only — filter them client-side for the main store view. The
|
|
90
|
+
* history-only fields (`purchase_ts`, `purchase_points_amount`, the
|
|
91
|
+
* `purchased_*` booleans) are populated only by
|
|
92
|
+
* {@link getStorePurchasedItems}, not by this method.
|
|
93
|
+
*
|
|
94
|
+
* **Idempotency**: yes. `getStoreItems` is a pure read. Calling it
|
|
95
|
+
* repeatedly within the 30-second cache window resolves from the cache
|
|
96
|
+
* without a network round-trip.
|
|
97
|
+
*
|
|
98
|
+
* **Side effects** (of a successful purchase that triggers `onUpdate`)
|
|
99
|
+
* Documented here because the consumer's `onUpdate` handler will observe
|
|
100
|
+
* the resulting state changes on the next refreshed array:
|
|
101
|
+
* - Points / gems / diamonds balance deducted per `purchase_type`. The
|
|
102
|
+
* new balance becomes visible on the user's gamification profile via
|
|
103
|
+
* the SDK's user-properties update channel (`ach_points_balance` /
|
|
104
|
+
* `ach_gems_balance` / `ach_diamonds_balance`).
|
|
105
|
+
* - `pool` decremented for limited-stock items.
|
|
106
|
+
* - `type = 'bonus'` → a CRM bonus is granted; surfaces via
|
|
107
|
+
* {@link getBonuses}.
|
|
108
|
+
* - `type = 'raffleticket'` → raffle tickets granted; surfaces via
|
|
109
|
+
* `getRaffles`.
|
|
110
|
+
* - `type = 'changelevel'` → user's level adjusted; surfaces via
|
|
111
|
+
* {@link getCurrentLevel}.
|
|
112
|
+
* - `type = 'minigamespin'` → SAW spin attempts granted; visible via the
|
|
113
|
+
* mini-game APIs.
|
|
114
|
+
* - `type = 'prizedrop'` → one prize-drop attempt granted.
|
|
115
|
+
* - `type = 'tangible'` → no automatic gameplay effect; the purchase is
|
|
116
|
+
* recorded for the operator's manual fulfillment (e.g. physical merch).
|
|
117
|
+
*
|
|
118
|
+
* **UI guidance**: see [UI Guide — `getStoreItems`](../../docs/ui/store/UIGuide_getStoreItems.md).
|
|
119
|
+
*
|
|
120
|
+
* @param params Optional. Omit to fetch without subscribing.
|
|
121
|
+
* @param params.onUpdate Callback invoked with the full refreshed
|
|
122
|
+
* catalog after every {@link buyStoreItem}
|
|
123
|
+
* round-trip on this connection. Each call to
|
|
124
|
+
* `getStoreItems` overwrites the prior
|
|
125
|
+
* callback. Never fires in visitor mode.
|
|
126
|
+
* @returns Promise resolving to the catalog of store
|
|
127
|
+
* items visible to the user. Empty array if
|
|
128
|
+
* the user has no items (or if the visitor
|
|
129
|
+
* proxy user has none configured).
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* // 1. Initial fetch + subscribe to live updates
|
|
134
|
+
* const items = await window._smartico.api.getStoreItems({
|
|
135
|
+
* onUpdate: (refreshed) => {
|
|
136
|
+
* console.log('[smartico] store catalog refreshed after a purchase — re-render the entire store UI from this array, do not merge with prior state:', refreshed);
|
|
137
|
+
*
|
|
138
|
+
* // 2. onUpdate fires only after the current user's own purchase
|
|
139
|
+
* // round-trip. Pool counts and can_buy flags are now current
|
|
140
|
+
* // for this user.
|
|
141
|
+
* const soldOut = refreshed.filter(i => i.pool === 0);
|
|
142
|
+
* if (soldOut.length > 0) {
|
|
143
|
+
* console.log('[smartico] these items are now sold out — render an "Out of stock" overlay on each:', soldOut.map(i => i.id));
|
|
144
|
+
* }
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* // 3. Live affordability per item. Compare each item's price against
|
|
149
|
+
* // the user's balance for its purchase_type (read from
|
|
150
|
+
* // getUserProfile(), kept live by the SDK's user-properties channel).
|
|
151
|
+
* const profile = window._smartico.api.getUserProfile();
|
|
152
|
+
* const balances = {
|
|
153
|
+
* points: profile?.ach_points_balance ?? 0,
|
|
154
|
+
* gems: profile?.ach_gems_balance ?? 0,
|
|
155
|
+
* diamonds: profile?.ach_diamonds_balance ?? 0,
|
|
156
|
+
* };
|
|
157
|
+
*
|
|
158
|
+
* // 4. Filter out items that are custom-section-only for the main view.
|
|
159
|
+
* const mainViewItems = items.filter(i => !i.only_in_custom_section);
|
|
160
|
+
*
|
|
161
|
+
* // 5. Bucket each item's button state for rendering.
|
|
162
|
+
* for (const i of mainViewItems) {
|
|
163
|
+
* const activePrice = i.discounted_price ?? i.price;
|
|
164
|
+
* const canAfford = balances[i.purchase_type] >= activePrice;
|
|
165
|
+
* if (i.pool === 0) {
|
|
166
|
+
* console.log('[smartico] item', i.id, 'is sold out — render disabled Buy with "Out of stock" overlay');
|
|
167
|
+
* } else if (i.can_buy === false) {
|
|
168
|
+
* console.log('[smartico] item', i.id, 'is not eligible — render disabled Buy and surface cant_buy_message on the popup:', i.cant_buy_message);
|
|
169
|
+
* } else if (!canAfford) {
|
|
170
|
+
* console.log('[smartico] item', i.id, 'is unaffordable — render disabled Buy and show "short by" line on popup; deficit =', activePrice - balances[i.purchase_type], i.purchase_type);
|
|
171
|
+
* } else {
|
|
172
|
+
* console.log('[smartico] item', i.id, 'is buyable — render enabled Buy at price', activePrice, i.purchase_type);
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
*
|
|
176
|
+
* // 6. Visitor-mode equivalent: onUpdate is accepted but never fires.
|
|
177
|
+
* // Re-poll if you need fresh data; buyStoreItem is not supported.
|
|
178
|
+
* // const visitorItems = await window._smartico.vapi('EN').getStoreItems();
|
|
179
|
+
* // console.log('[smartico] visitor catalog is the brand proxy user\'s — per-user fields are not meaningful');
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getStoreItems({ onUpdate }?: {
|
|
183
|
+
onUpdate?: (data: TStoreItem[]) => void;
|
|
184
|
+
}): Promise<TStoreItem[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Purchase a specific store item on behalf of the current user. Spends
|
|
187
|
+
* the user's points / gems / diamonds (depending on the item's
|
|
188
|
+
* `purchase_type`) and triggers reward delivery (bonus issuance, mini-game
|
|
189
|
+
* spin grant, level change, prize-drop, raffle ticket, or tangible item).
|
|
190
|
+
*
|
|
191
|
+
* A successful response (`err_code === 0`) means the funds have already
|
|
192
|
+
* been debited and the reward has been queued / granted server-side. The
|
|
193
|
+
* user's balance change arrives over a separate push channel, not in this
|
|
194
|
+
* response — see "Refresh after success" below.
|
|
195
|
+
*
|
|
196
|
+
* @remarks
|
|
197
|
+
* **Preconditions**
|
|
198
|
+
* Read the candidate item from `getStoreItems()` first and gate the call
|
|
199
|
+
* on these fields:
|
|
200
|
+
* - `can_buy === true` — server-derived; combines segment / visibility
|
|
201
|
+
* conditions and any operator-set restrictions.
|
|
202
|
+
* - `pool == null || pool > 0` — `null` means unlimited stock; a positive
|
|
203
|
+
* number means N units remain.
|
|
204
|
+
* - User's balance for the item's `purchase_type`
|
|
205
|
+
* (`'points'` / `'gems'` / `'diamonds'`) is `>= price` (or
|
|
206
|
+
* `>= discounted_price` if set). Balances are not on `TStoreItem` —
|
|
207
|
+
* read them from the user properties returned by `getUserState()`.
|
|
208
|
+
* - If `active_till_date` is set, it is in the future.
|
|
209
|
+
*
|
|
210
|
+
* Calling without satisfying these will most likely return a non-zero
|
|
211
|
+
* `err_code` (one of the codes below). The SDK does not pre-validate
|
|
212
|
+
* — it forwards the request to the server unconditionally.
|
|
213
|
+
*
|
|
214
|
+
* **Error codes** (in `err_code`)
|
|
215
|
+
* - `0` — success; funds debited and reward delivered.
|
|
216
|
+
* - `1` — generic server error / control-group rejection. Treat as a
|
|
217
|
+
* transient failure; show a "try again later" message.
|
|
218
|
+
* - `106` — label mismatch detected before the purchase transaction
|
|
219
|
+
* (e.g. cross-label item id). From a consumer perspective: the item is
|
|
220
|
+
* not purchasable by this user.
|
|
221
|
+
* - `11000` (`SHOP_NO_BALANCE`) — insufficient **points** balance.
|
|
222
|
+
* Show an insufficient-balance message that names how many points are
|
|
223
|
+
* missing (`price - current_points_balance`). The Buy button on the
|
|
224
|
+
* item should already be disabled when this is the case; this code
|
|
225
|
+
* normally fires only on a stale local balance.
|
|
226
|
+
* - `11001` (`SHOP_WRONG_LABEL`) — user-vs-item label mismatch detected
|
|
227
|
+
* inside the purchase transaction. Distinct from `106`; both mean
|
|
228
|
+
* "not purchasable by this user" from the consumer's perspective.
|
|
229
|
+
* Surface as a generic "item not available" message.
|
|
230
|
+
* - `11002` (`SHOP_FAILED_TO_BUY_BONUS`) — the bonus configured on the
|
|
231
|
+
* store item couldn't be issued (bad / disabled bonus config on the
|
|
232
|
+
* operator side). Funds are NOT debited. Surface a generic error and
|
|
233
|
+
* advise the user to contact support if it persists.
|
|
234
|
+
* - `11003` (`SHOP_FAILED_TO_BUY_SHOP_ITEM_CONDITION`) — the item's
|
|
235
|
+
* **visibility** segment condition is not satisfied. Shouldn't be
|
|
236
|
+
* reachable through a correctly-rendered UI (the item shouldn't be
|
|
237
|
+
* shown in the first place); usually indicates a stale local store
|
|
238
|
+
* list. Re-fetch via `getStoreItems()`.
|
|
239
|
+
* - `11004` (`SHOP_FAILED_TO_BUY_SHOP_ITEM_CONDITION_PURSHASE`) — the
|
|
240
|
+
* item's **purchase** segment condition is not satisfied (the item is
|
|
241
|
+
* visible but the user is not in the buyable segment). Surface a
|
|
242
|
+
* localized "try again later" / "you're not eligible" message; do not
|
|
243
|
+
* retry automatically.
|
|
244
|
+
* - `11005` (`SHOP_FAILED_TO_BUY_MATCHING_BONUS`) — matching-bonus
|
|
245
|
+
* coupon issuance failed (variant of `11002` for matching-deposit
|
|
246
|
+
* bonuses). Funds are NOT debited. Surface a generic error.
|
|
247
|
+
* - `11006` (`SHOP_FAILED_MAX_BOUGHT_ITEMS_REACHED`) — per-user purchase
|
|
248
|
+
* cap reached (e.g. "max 1 per day"). Surface the item's
|
|
249
|
+
* `limit_message` if set, otherwise `err_message`. Do not retry.
|
|
250
|
+
* - `11007` — bonus was issued but a follow-up redemption step failed
|
|
251
|
+
* server-side. Funds **are** debited and the purchase event is recorded;
|
|
252
|
+
* the consumer's UI should refresh the store list (auto-refresh will
|
|
253
|
+
* fire) and surface a soft warning rather than a hard error.
|
|
254
|
+
* - `11009` (`SHOP_FAILED_POOL_EMPTY`) — stock pool is empty / sold out.
|
|
255
|
+
* Show a "sold out" message; auto-refresh will mark the item as such
|
|
256
|
+
* in subsequent `getStoreItems()` updates.
|
|
257
|
+
* - `11011` (`SHOP_NO_BALANCE_GEMS`) — insufficient **gems** balance.
|
|
258
|
+
* Same handling as `11000` but for the gems currency.
|
|
259
|
+
* - `11012` (`SHOP_NO_BALANCE_DIAMONDS`) — insufficient **diamonds**
|
|
260
|
+
* balance. Same handling as `11000` but for the diamonds currency.
|
|
261
|
+
* - `11014` (`SHOP_FAILED_PURCHASE_LIMITATION`) — outside the configured
|
|
262
|
+
* purchase window (purchase weekday / time-of-day / window). Surface
|
|
263
|
+
* the item's `purchase_limit_message` if set, otherwise `err_message`.
|
|
264
|
+
* - `9999` — uncaught server exception. Treat as a transient failure;
|
|
265
|
+
* surface a generic error and allow retry.
|
|
266
|
+
* - other non-zero — generic server error. Surface `err_message` if any.
|
|
267
|
+
*
|
|
268
|
+
* **Idempotency**: NOT idempotent. The server performs no de-duplication —
|
|
269
|
+
* a second successful call deducts funds again and grants the reward
|
|
270
|
+
* again (subject to per-user purchase caps). The SDK itself does **not**
|
|
271
|
+
* enforce a single in-flight call. The consumer MUST guard the call site
|
|
272
|
+
* against double-clicks (set a local "buying" flag on click, clear it on
|
|
273
|
+
* response).
|
|
274
|
+
*
|
|
275
|
+
* **Refresh after success (and after failure)**
|
|
276
|
+
* The SDK automatically re-fetches the store item list and the
|
|
277
|
+
* purchased-items history on every response (success or error). Any
|
|
278
|
+
* `onUpdate` callback registered via `getStoreItems({ onUpdate })` (or
|
|
279
|
+
* the purchased-items equivalent) fires shortly after with the updated
|
|
280
|
+
* arrays — reflecting the new `pool`, `can_buy`, and any `purchased_*`
|
|
281
|
+
* flags. The user's balance (points / gems / diamonds) is exposed on the
|
|
282
|
+
* user-properties channel and updates independently; if the UI displays
|
|
283
|
+
* the balance, subscribe to user-property updates separately (it does
|
|
284
|
+
* NOT flow through `getStoreItems`).
|
|
285
|
+
*
|
|
286
|
+
* **Side effects** (consumer-observable on success)
|
|
287
|
+
* - User's points / gems / diamonds balance decreases by `price`
|
|
288
|
+
* (or `discounted_price` if set).
|
|
289
|
+
* - Item's `pool` decrements by 1 (when `pool != null`).
|
|
290
|
+
* - Per-user purchase counters update — `purchased_today`,
|
|
291
|
+
* `purchased_this_week`, `purchased_this_month` on the next
|
|
292
|
+
* `getStoreItems()` refresh.
|
|
293
|
+
* - The reward is delivered: bonus issuance, mini-game spin grant,
|
|
294
|
+
* level change, prize drop, raffle ticket, or tangible-item record.
|
|
295
|
+
* Each reward type pushes its own follow-up update (e.g. a new
|
|
296
|
+
* bonus appears in `getBonuses()`, the spin shows up in
|
|
297
|
+
* `getMiniGames()`). Subscribe to each relevant channel separately.
|
|
298
|
+
* - A purchase row is appended to the user's purchase history,
|
|
299
|
+
* surfaced via the purchased-items list.
|
|
300
|
+
*
|
|
301
|
+
* **UI guidance**: see [UI Guide — `buyStoreItem`](../../docs/ui/store/UIGuide_buyStoreItem.md).
|
|
302
|
+
*
|
|
303
|
+
* @param item_id The store item `id` (from `getStoreItems()`).
|
|
304
|
+
* @returns `{ err_code, err_message }`; success when `err_code === 0`.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* const items = await window._smartico.api.getStoreItems({
|
|
309
|
+
* onUpdate: (next) => console.log('[smartico] store items updated — re-render store grid with this fresh array', next),
|
|
310
|
+
* });
|
|
311
|
+
* const item = items.find(i => i.id === itemId);
|
|
312
|
+
*
|
|
313
|
+
* if (!item) {
|
|
314
|
+
* console.log('[smartico] item not in current store list — keep UI as-is, possibly refresh getStoreItems');
|
|
315
|
+
* return;
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* // Local pre-checks: keep these aligned with the Buy-button decision matrix above.
|
|
319
|
+
* const effectivePrice = item.discounted_price ?? item.price;
|
|
320
|
+
* const inStock = item.pool == null || item.pool > 0;
|
|
321
|
+
* const inWindow = !item.active_till_date || Date.now() < item.active_till_date;
|
|
322
|
+
* if (!item.can_buy || !inStock || !inWindow) {
|
|
323
|
+
* console.log('[smartico] buy not applicable — show disabled state with operator copy if any:', item.cant_buy_message);
|
|
324
|
+
* return;
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* console.log('[smartico] buy starting — set in-flight flag, show loading dots on Buy button, keep detail modal open');
|
|
328
|
+
* const r = await window._smartico.api.buyStoreItem(item.id);
|
|
329
|
+
* console.log('[smartico] buy response received — clear in-flight flag');
|
|
330
|
+
*
|
|
331
|
+
* if (r.err_code === 0) {
|
|
332
|
+
* console.log('[smartico] purchase successful — close the detail modal, show a success toast; getStoreItems onUpdate above will fire with the refreshed list (do NOT manually re-fetch)');
|
|
333
|
+
* } else if (r.err_code === 11000 || r.err_code === 11011 || r.err_code === 11012) {
|
|
334
|
+
* console.error('[smartico] insufficient balance for this purchase_type — show insufficient-balance UI and how many units are missing:', item.purchase_type, effectivePrice);
|
|
335
|
+
* } else if (r.err_code === 11009) {
|
|
336
|
+
* console.error('[smartico] item sold out — show a dedicated "Sold out" message; the auto-refresh will mark the card as such shortly');
|
|
337
|
+
* } else if (r.err_code === 11006) {
|
|
338
|
+
* console.error('[smartico] per-user purchase cap reached — surface the operator-defined limit message:', item.limit_message || r.err_message);
|
|
339
|
+
* } else if (r.err_code === 11014) {
|
|
340
|
+
* console.error('[smartico] outside purchase window — surface the operator-defined purchase-limit message:', item.purchase_limit_message || r.err_message);
|
|
341
|
+
* } else if (r.err_code === 11004 || r.err_code === 11003) {
|
|
342
|
+
* console.error('[smartico] user not eligible / stale visibility — show a localized "try again later" message and let auto-refresh reconcile');
|
|
343
|
+
* } else {
|
|
344
|
+
* console.error('[smartico] buy failed — show a generic error toast/modal with this message:', r.err_message);
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
buyStoreItem(item_id: number): Promise<TBuyStoreItemResult>;
|
|
349
|
+
/**
|
|
350
|
+
* Returns the list of active store categories configured for the current label.
|
|
351
|
+
* Categories are operator-defined groupings used to organize store items into tabs,
|
|
352
|
+
* sections, or filter chips in the gamification store UI.
|
|
353
|
+
*
|
|
354
|
+
* @remarks
|
|
355
|
+
* **What categories are**
|
|
356
|
+
* - Operator-defined groupings, configured per-label by the brand operator.
|
|
357
|
+
* Only active categories are returned; inactive / archived / deleted ones are
|
|
358
|
+
* filtered out server-side.
|
|
359
|
+
* - Each `TStoreCategory` exposes `{ id, name, order }`. `name` is the display label;
|
|
360
|
+
* `order` is the relative position (lower = appears first).
|
|
361
|
+
* - The same set of categories is returned to every user of the label — there is no
|
|
362
|
+
* per-segment / per-currency / per-device filtering on the category list. Item-level
|
|
363
|
+
* segment visibility happens on {@link getStoreItems}, not here.
|
|
364
|
+
*
|
|
365
|
+
* **Localization / translation**
|
|
366
|
+
* - `name` is **pre-translated server-side** to the authenticated user's stored language.
|
|
367
|
+
* In visitor mode, the language passed to `_smartico.vapi(lang)` drives the translation.
|
|
368
|
+
* Consumers never need to translate `name` themselves.
|
|
369
|
+
* - Fallback if no translation exists for the user's language: the operator-set default
|
|
370
|
+
* (typically the brand's English) value is returned. The field is never null for an
|
|
371
|
+
* active category.
|
|
372
|
+
*
|
|
373
|
+
* **Sort order**
|
|
374
|
+
* The server does NOT pre-sort. Sort client-side before rendering:
|
|
375
|
+
* `categories.sort((a, b) => a.order - b.order)`.
|
|
376
|
+
*
|
|
377
|
+
* **How store items join to categories**
|
|
378
|
+
* Each `TStoreItem` exposes `category_ids: number[]` (zero-or-more, many-to-many).
|
|
379
|
+
* A single store item can belong to multiple categories, or to none. To render a
|
|
380
|
+
* "category → items" view:
|
|
381
|
+
* `items.filter(i => i.category_ids.includes(cat.id))`.
|
|
382
|
+
*
|
|
383
|
+
* **Uncategorized items**
|
|
384
|
+
* Items with `category_ids: []` are NOT represented by a synthetic "Other" entry
|
|
385
|
+
* in the response. The convention used by the reference store UI is to synthesize
|
|
386
|
+
* a client-side bucket (e.g. labelled "General") for items that have no category, OR
|
|
387
|
+
* for items whose `category_ids` reference a category that is no longer returned by
|
|
388
|
+
* this method (e.g. archived since the item was tagged). If you choose to render
|
|
389
|
+
* such a synthetic bucket, place it first (the reference UI uses an `order: -1`
|
|
390
|
+
* convention so it precedes all operator-defined categories).
|
|
391
|
+
*
|
|
392
|
+
* **Empty categories**
|
|
393
|
+
* A category may be returned even if zero items currently reference it (since this
|
|
394
|
+
* method does not join against items). The reference store UI hides such empty
|
|
395
|
+
* categories from its tab strip — replicate that filter if you don't want to render
|
|
396
|
+
* tabs that lead to empty content panels.
|
|
397
|
+
*
|
|
398
|
+
* **Refresh cadence / cache**
|
|
399
|
+
* - The SDK caches the response for 30 seconds. Subsequent calls within that window
|
|
400
|
+
* return the cached array without a network round-trip.
|
|
401
|
+
* - The cache is NOT invalidated by store-item push events or purchases — operator-driven
|
|
402
|
+
* category changes propagate at the next 30 s cache miss.
|
|
403
|
+
* - Cache is fully cleared on login / logout.
|
|
404
|
+
* - In **visitor mode**, additional server-side caching applies on top of the SDK cache;
|
|
405
|
+
* worst-case staleness for an edited/added category is on the order of a few minutes
|
|
406
|
+
* for anonymous viewers.
|
|
407
|
+
*
|
|
408
|
+
* **Idempotency**: safe. Read-only metadata fetch. Cache de-duplicates concurrent calls.
|
|
409
|
+
*
|
|
410
|
+
* **Side effects**: none — pure metadata read.
|
|
411
|
+
*
|
|
412
|
+
* **UI guidance**: see [UI Guide — `getStoreCategories`](../../docs/ui/store/UIGuide_getStoreCategories.md).
|
|
413
|
+
*
|
|
414
|
+
* @returns Array of `{ id, name, order }`. Empty array if no active categories are
|
|
415
|
+
* configured for the label. `name` is pre-translated. Order is NOT applied — caller
|
|
416
|
+
* must sort.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* const [categories, items] = await Promise.all([
|
|
421
|
+
* window._smartico.api.getStoreCategories(),
|
|
422
|
+
* window._smartico.api.getStoreItems(),
|
|
423
|
+
* ]);
|
|
424
|
+
*
|
|
425
|
+
* if (categories.length === 0) {
|
|
426
|
+
* console.log('[smartico] no store categories configured — render items as a flat grid without tabs:', items.length);
|
|
427
|
+
* } else {
|
|
428
|
+
* // Sort categories; build per-category item buckets; hide empty categories
|
|
429
|
+
* const sorted = [...categories].sort((a, b) => a.order - b.order);
|
|
430
|
+
* const tabs = sorted
|
|
431
|
+
* .map(cat => ({ cat, items: items.filter(i => i.category_ids?.includes(cat.id)) }))
|
|
432
|
+
* .filter(t => t.items.length > 0);
|
|
433
|
+
*
|
|
434
|
+
* // Optional: synthesize an "Other" bucket for items with no (or unknown) category
|
|
435
|
+
* const knownIds = new Set(categories.map(c => c.id));
|
|
436
|
+
* const orphans = items.filter(i => !i.category_ids?.length || !i.category_ids.some(id => knownIds.has(id)));
|
|
437
|
+
* if (orphans.length > 0) {
|
|
438
|
+
* console.log('[smartico] uncategorized store items — render a client-synthesized "Other" tab at the front of the tab strip:', orphans.length);
|
|
439
|
+
* }
|
|
440
|
+
*
|
|
441
|
+
* console.log('[smartico] render store tabs in this order with these counts:', tabs.map(t => `${t.cat.name} (${t.items.length})`));
|
|
442
|
+
* }
|
|
443
|
+
*
|
|
444
|
+
* // Visitor mode — same shape, language driven by vapi(lang) argument
|
|
445
|
+
* const visitorCats = await window._smartico.vapi('DE').getStoreCategories();
|
|
446
|
+
* console.log('[smartico] visitor-mode store categories (names translated to DE):', visitorCats);
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
getStoreCategories(): Promise<TStoreCategory[]>;
|
|
450
|
+
/**
|
|
451
|
+
* Fetches the authenticated user's **store purchase history** — a paginated,
|
|
452
|
+
* newest-first list of past store purchases (one row per redemption).
|
|
453
|
+
*
|
|
454
|
+
* Designed for a "My Purchases" / "Order History" screen. Each entry carries
|
|
455
|
+
* the same descriptive fields as the catalog card plus three history-only
|
|
456
|
+
* fields: `purchase_ts` (when the purchase happened), `purchase_points_amount`
|
|
457
|
+
* (the amount actually paid at that time — a price snapshot, not the
|
|
458
|
+
* current `price`), and `purchase_type` (`'points' | 'gems' | 'diamonds'`).
|
|
459
|
+
*
|
|
460
|
+
* @remarks
|
|
461
|
+
* **Preconditions**
|
|
462
|
+
* - User must be authenticated. Visitor mode is not supported (the SDK only
|
|
463
|
+
* exposes this method on the authenticated `_smartico.api`, not on
|
|
464
|
+
* `_smartico.vapi`).
|
|
465
|
+
* - No prerequisite calls — calling without first fetching
|
|
466
|
+
* {@link getStoreItems} or {@link getStoreCategories} is fine.
|
|
467
|
+
*
|
|
468
|
+
* **Pagination semantics**
|
|
469
|
+
* - **Offset-based**, newest-first. The server orders rows by purchase
|
|
470
|
+
* timestamp **descending** and the SDK does NOT re-sort — items arrive
|
|
471
|
+
* ready to render in display order.
|
|
472
|
+
* - `limit` — page size. **The SDK default is 20.** There is no server-side
|
|
473
|
+
* hard cap, but 20 matches what the default Smartico UI uses end-to-end; the
|
|
474
|
+
* protocol and storage layers were sized for this page size. Treat `20`
|
|
475
|
+
* as the conventional/recommended value; passing a much larger limit will
|
|
476
|
+
* return more rows but is not the supported integration pattern.
|
|
477
|
+
* Avoid `limit <= 0` — the server peeks `limit + 1` rows internally, so
|
|
478
|
+
* `limit = 0` returns 1 row with a misleading "has more" signal, and
|
|
479
|
+
* negative values produce undefined results.
|
|
480
|
+
* - `offset` — number of items to skip from the start. The SDK default is
|
|
481
|
+
* `0` (first page). For load-more pagination, pass
|
|
482
|
+
* `offset = (previously-loaded items).length` on each subsequent call.
|
|
483
|
+
* - **No `hasMore` on the returned array.** `TStoreItem[]` is a flat list;
|
|
484
|
+
* the underlying protocol response carries `hasMore` but it is not
|
|
485
|
+
* surfaced through this method. Two ways for consumers to know they
|
|
486
|
+
* reached the end:
|
|
487
|
+
* 1. The returned array is shorter than `limit` (definitive end), or
|
|
488
|
+
* 2. A subsequent call at `offset = previous.length` returns `[]`.
|
|
489
|
+
* Either is reliable.
|
|
490
|
+
* - No date-range / category / status filter parameters — pagination is the
|
|
491
|
+
* only server-side slicing. Apply any further filtering client-side.
|
|
492
|
+
*
|
|
493
|
+
* **No per-item fulfillment status**
|
|
494
|
+
* - History entries do NOT carry a `delivered` / `pending` / `cancelled` /
|
|
495
|
+
* `refunded` field. The list contains rows for committed purchase
|
|
496
|
+
* attempts; the server query does not filter by transaction-status, so in
|
|
497
|
+
* practice the rows that appear are completed purchases (failed
|
|
498
|
+
* transactions roll back and don't write a row). Treat every item as a
|
|
499
|
+
* completed transaction unless a future SDK release adds an explicit
|
|
500
|
+
* status field.
|
|
501
|
+
*
|
|
502
|
+
* **Bonus-type entries**
|
|
503
|
+
* - When the user redeemed a bonus item, the entry's `type` field surfaces
|
|
504
|
+
* as `'bonus'`. **Known limitation:** the SDK transform currently maps
|
|
505
|
+
* both `Bonus` and `Tangible` server-side item types to the same string
|
|
506
|
+
* `'bonus'` — so the `type` field on history rows cannot distinguish a
|
|
507
|
+
* bonus redemption from a tangible-prize redemption. The actual bonus
|
|
508
|
+
* payload (wallet credit, free spins, etc.) is dispatched by the server
|
|
509
|
+
* asynchronously and is NOT embedded in the history entry — consumers
|
|
510
|
+
* that need bonus details should subscribe to bonus push events
|
|
511
|
+
* separately rather than reading them from this list.
|
|
512
|
+
* - History rows render identically across types — there is no deep-link to
|
|
513
|
+
* the bonus wallet or re-claim affordance on the row itself.
|
|
514
|
+
*
|
|
515
|
+
* **Per-row data**
|
|
516
|
+
* Each row uses the `TStoreItem` shape but populates four history-only
|
|
517
|
+
* fields not present on `getStoreItems` output. `purchase_ts` is the
|
|
518
|
+
* Unix-ms timestamp of the purchase — format with
|
|
519
|
+
* `new Date(purchase_ts).toLocaleString()` in the user's local timezone;
|
|
520
|
+
* no relative labels ("Today" / "Yesterday") are produced by the SDK.
|
|
521
|
+
* `purchase_points_amount` is the amount actually paid at the time of
|
|
522
|
+
* purchase — a snapshot of the historical price, which may differ from
|
|
523
|
+
* the item's current `price`. `purchase_type` is the currency actually
|
|
524
|
+
* charged (`'points' | 'gems' | 'diamonds'`); render the matching
|
|
525
|
+
* balance icon next to the amount. The convenience booleans
|
|
526
|
+
* `purchased_today` / `purchased_this_week` / `purchased_this_month` are
|
|
527
|
+
* computed client-side from the consumer's local clock — useful for
|
|
528
|
+
* grouping rows under "Today" / "This Week" headers.
|
|
529
|
+
*
|
|
530
|
+
* **Catalog fields on a history row**
|
|
531
|
+
* The promotional fields (`ribbon`, `discounted_price`,
|
|
532
|
+
* `discount_price_ribbon`, `custom_ribbon_image`, `active_till_date`)
|
|
533
|
+
* reflect the CURRENT catalog state of the item, NOT its state at
|
|
534
|
+
* purchase time — the default Smartico UI hides them on history rows to
|
|
535
|
+
* avoid implying that the historical purchase carried the current
|
|
536
|
+
* promotional banner. Descriptive marketing fields (`description`,
|
|
537
|
+
* `hint_text`, `related_games`) are typically suppressed on a compact
|
|
538
|
+
* history row. The current-purchasability fields `can_buy` and `pool`
|
|
539
|
+
* reflect now, not then — useful only if you render a "Buy Again"
|
|
540
|
+
* affordance on the row. One implementation gotcha: unlike
|
|
541
|
+
* `getStoreItems`, this method's transform does NOT auto-parse JSON
|
|
542
|
+
* strings in `custom_data` — call `JSON.parse()` yourself if you store
|
|
543
|
+
* JSON there.
|
|
544
|
+
*
|
|
545
|
+
* **Cache & refresh**
|
|
546
|
+
* - The SDK caches each `(limit, offset)` page separately for 30 seconds.
|
|
547
|
+
* Repeated calls within that window resolve from cache without a
|
|
548
|
+
* network round-trip.
|
|
549
|
+
* - The cache is invalidated and `onUpdate` (when registered) is invoked
|
|
550
|
+
* automatically after a successful {@link buyStoreItem} call — the SDK
|
|
551
|
+
* re-fetches the same page parameters that were registered together with
|
|
552
|
+
* the current `onUpdate` callback and pushes the fresh array.
|
|
553
|
+
* - Multi-tab caveat: if the user has the same brand open in multiple
|
|
554
|
+
* tabs, **all open tabs** receive the `onUpdate` event on a purchase,
|
|
555
|
+
* not only the tab that initiated the buy. The event is scoped to the
|
|
556
|
+
* current authenticated user — a different user's purchase never fires
|
|
557
|
+
* this callback.
|
|
558
|
+
* - Only ONE `onUpdate` callback can be registered at a time. Each call to
|
|
559
|
+
* `getStorePurchasedItems({ onUpdate })` overwrites the previous handler.
|
|
560
|
+
*
|
|
561
|
+
* **Idempotency**: safe. Pure read.
|
|
562
|
+
*
|
|
563
|
+
* **Side effects**: none — read-only.
|
|
564
|
+
*
|
|
565
|
+
* **UI guidance**: see [UI Guide — `getStorePurchasedItems`](../../docs/ui/store/UIGuide_getStorePurchasedItems.md).
|
|
566
|
+
*
|
|
567
|
+
* @param params - Optional pagination + callback bag.
|
|
568
|
+
* @param params.limit - Page size. Defaults to `20`. Use `20` as the
|
|
569
|
+
* conventional value (matches the default Smartico UI end-to-end). Avoid
|
|
570
|
+
* non-positive values.
|
|
571
|
+
* @param params.offset - Number of rows to skip from the newest end.
|
|
572
|
+
* Defaults to `0`. For load-more pagination pass the current array
|
|
573
|
+
* length.
|
|
574
|
+
* @param params.onUpdate - Optional callback invoked after a successful
|
|
575
|
+
* {@link buyStoreItem} elsewhere in the session. Receives the refreshed
|
|
576
|
+
* page for the same `(limit, offset)` used on the call that registered
|
|
577
|
+
* this callback. Only ONE callback can be registered; each new call
|
|
578
|
+
* overwrites the previous one. Pass a stable handler or
|
|
579
|
+
* re-register intentionally on screen entry.
|
|
580
|
+
*
|
|
581
|
+
* @returns Promise resolving to an array of `TStoreItem` history entries
|
|
582
|
+
* in newest-first order. Empty array if the user has no purchases (or
|
|
583
|
+
* the requested `offset` is beyond the end). Each entry carries
|
|
584
|
+
* `purchase_ts`, `purchase_points_amount`, `purchase_type`, and the
|
|
585
|
+
* `purchased_today/this_week/this_month` convenience flags in addition
|
|
586
|
+
* to the standard item fields.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* // Initial load + subscribe to refresh-on-purchase.
|
|
591
|
+
* const handleHistoryUpdate = (items: TStoreItem[]) => {
|
|
592
|
+
* console.log(
|
|
593
|
+
* '[smartico] purchase history refreshed — re-render the history list with these',
|
|
594
|
+
* items.length,
|
|
595
|
+
* 'items (newest first):',
|
|
596
|
+
* items,
|
|
597
|
+
* );
|
|
598
|
+
* };
|
|
599
|
+
*
|
|
600
|
+
* try {
|
|
601
|
+
* const firstPage = await _smartico.api.getStorePurchasedItems({
|
|
602
|
+
* limit: 20,
|
|
603
|
+
* offset: 0,
|
|
604
|
+
* onUpdate: handleHistoryUpdate,
|
|
605
|
+
* });
|
|
606
|
+
*
|
|
607
|
+
* if (firstPage.length === 0) {
|
|
608
|
+
* console.log('[smartico] no purchase history — render the empty state ("No purchases yet")');
|
|
609
|
+
* } else {
|
|
610
|
+
* console.log(
|
|
611
|
+
* '[smartico] render',
|
|
612
|
+
* firstPage.length,
|
|
613
|
+
* 'history rows (newest first). Show "Load more" button if length === 20:',
|
|
614
|
+
* firstPage,
|
|
615
|
+
* );
|
|
616
|
+
*
|
|
617
|
+
* // Inspect the first entry's history-only fields.
|
|
618
|
+
* const first = firstPage[0];
|
|
619
|
+
* console.log(
|
|
620
|
+
* '[smartico] most-recent purchase: name=', first.name,
|
|
621
|
+
* 'paid', first.purchase_points_amount, first.purchase_type,
|
|
622
|
+
* 'at', new Date(first.purchase_ts ?? 0).toLocaleString(),
|
|
623
|
+
* '— format with toLocaleString (user-local time) on the row.',
|
|
624
|
+
* );
|
|
625
|
+
* }
|
|
626
|
+
*
|
|
627
|
+
* // Load-more pattern: fetch page 2 once the user scrolls / clicks "Load more".
|
|
628
|
+
* if (firstPage.length === 20) {
|
|
629
|
+
* const nextPage = await _smartico.api.getStorePurchasedItems({
|
|
630
|
+
* limit: 20,
|
|
631
|
+
* offset: firstPage.length,
|
|
632
|
+
* });
|
|
633
|
+
* const isLastPage = nextPage.length < 20;
|
|
634
|
+
* console.log(
|
|
635
|
+
* '[smartico] appended page 2 —',
|
|
636
|
+
* nextPage.length,
|
|
637
|
+
* 'rows.',
|
|
638
|
+
* isLastPage ? 'Hide "Load more" — end reached.' : 'Keep "Load more" visible.',
|
|
639
|
+
* );
|
|
640
|
+
* }
|
|
641
|
+
* } catch (e) {
|
|
642
|
+
* console.error(
|
|
643
|
+
* '[smartico] failed to load purchase history — show a generic error placeholder or retry with backoff:',
|
|
644
|
+
* e,
|
|
645
|
+
* );
|
|
646
|
+
* }
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
getStorePurchasedItems({ limit, offset, onUpdate, }?: {
|
|
650
|
+
limit?: number;
|
|
651
|
+
offset?: number;
|
|
652
|
+
onUpdate?: (data: TStoreItem[]) => void;
|
|
653
|
+
}): Promise<TStoreItem[]>;
|
|
654
|
+
protected updateStorePurchasedItems(): Promise<void>;
|
|
655
|
+
protected updateStoreItems(): Promise<void>;
|
|
656
|
+
}
|