@invonetwork/web-sdk 3.26.1 → 3.28.0
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 +20 -0
- package/README.md +118 -0
- package/dist/chunk-3DRWLDDF.js +6 -0
- package/dist/chunk-4YKTKXC5.js +3735 -0
- package/dist/chunk-6CN236QH.js +473 -0
- package/dist/{chunk-7BYAUHTA.js → chunk-VP3OK4J4.js} +56 -459
- package/dist/game-server.cjs +6025 -0
- package/dist/game-server.d.cts +193 -0
- package/dist/game-server.d.ts +193 -0
- package/dist/game-server.js +746 -0
- package/dist/game.cjs +2172 -0
- package/dist/game.d.cts +197 -0
- package/dist/game.d.ts +197 -0
- package/dist/game.js +1034 -0
- package/dist/index.cjs +87 -0
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +26 -2
- package/dist/server.cjs +158 -1
- package/dist/server.d.cts +50 -7
- package/dist/server.d.ts +50 -7
- package/dist/server.js +4 -3650
- package/dist/types-CoW9LopI.d.cts +143 -0
- package/dist/types-CoW9LopI.d.ts +143 -0
- package/dist/{types-Cjd4SAR8.d.cts → types-_lIm74kd.d.cts} +40 -1
- package/dist/{types-Cjd4SAR8.d.ts → types-_lIm74kd.d.ts} +40 -1
- package/dist/version-iWmcxjYu.d.cts +8 -0
- package/dist/version-iWmcxjYu.d.ts +8 -0
- package/package.json +91 -77
package/dist/game.cjs
ADDED
|
@@ -0,0 +1,2172 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/shared/errors.ts
|
|
4
|
+
var LEGACY_NOT_PENDING_RE = /^transaction not pending\b|\bcannot be confirmed\b/i;
|
|
5
|
+
var LEGACY_CURRENT_STATUS_RE = /\((?:current )?status:\s*([^)]+)\)/i;
|
|
6
|
+
var InvoError = class _InvoError extends Error {
|
|
7
|
+
constructor(args) {
|
|
8
|
+
super(args.message);
|
|
9
|
+
this.name = "InvoError";
|
|
10
|
+
this.code = args.code;
|
|
11
|
+
this.rawCode = args.rawCode ?? args.code;
|
|
12
|
+
this.publicCode = args.publicCode;
|
|
13
|
+
this.status = args.status;
|
|
14
|
+
this.body = args.body ?? null;
|
|
15
|
+
this.requestId = args.requestId;
|
|
16
|
+
Object.setPrototypeOf(this, _InvoError.prototype);
|
|
17
|
+
}
|
|
18
|
+
/** True if this is the "recipient isn't passkey-enrolled, fall back to claim code" signal. */
|
|
19
|
+
get isReceiverNotEnrolled() {
|
|
20
|
+
return this.code === "receiver_not_enrolled_use_claim_code" || /receiver_not_enrolled_use_claim_code/i.test(this.message);
|
|
21
|
+
}
|
|
22
|
+
/** True if the session/SDK token has expired and the caller should re-mint + retry. */
|
|
23
|
+
get isTokenExpired() {
|
|
24
|
+
return this.code === "SDK_TOKEN_EXPIRED";
|
|
25
|
+
}
|
|
26
|
+
/** True if `enrollPasskey()` needs the OTP-grant flow (`enrollmentBegin`/`enrollmentVerify`). */
|
|
27
|
+
get isEnrollmentAuthorizationRequired() {
|
|
28
|
+
return this.code === "ENROLLMENT_REQUIRES_AUTHORIZATION";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* True if a passkey approve/confirm was rejected because the assertion lacked user
|
|
32
|
+
* verification (`WEBAUTHN_UV_REQUIRED`, 401). Re-run the ceremony requiring UV
|
|
33
|
+
* (biometric/PIN) — the backend treats a UV-satisfied assertion as the signed step-up.
|
|
34
|
+
*/
|
|
35
|
+
get isUserVerificationRequired() {
|
|
36
|
+
return this.code === "WEBAUTHN_UV_REQUIRED";
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* True if enrolling is blocked because the identity already has an enrolled method
|
|
40
|
+
* (anti-takeover gate, register/complete → 409). Two ways forward: `linkDevice` when
|
|
41
|
+
* the player still HAS the other method, or the passkey-recovery flow
|
|
42
|
+
* (`recoveryBegin`/`recoveryComplete` — "Lost or replaced your passkey?") when they
|
|
43
|
+
* deleted/lost it — the server can't know a device-side passkey is gone.
|
|
44
|
+
*/
|
|
45
|
+
get isEnrollmentProofRequired() {
|
|
46
|
+
return this.code === "ENROLLMENT_REQUIRES_PROOF";
|
|
47
|
+
}
|
|
48
|
+
/** True if the recovery OTP was wrong or expired (attempt-capped) — let the user retry or resend. */
|
|
49
|
+
get isEnrollmentCodeInvalid() {
|
|
50
|
+
return this.code === "ENROLLMENT_CODE_INVALID";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* True if a money-OUT approve was refused because the passkey was enrolled via
|
|
54
|
+
* recovery less than 24h ago (SIM-swap protection, approve → 403). NOT a generic
|
|
55
|
+
* failure — do not retry-loop. Login and inbound confirm-receipt (collecting money)
|
|
56
|
+
* still work. Show: "For your security, transfers are paused for 24 hours after a
|
|
57
|
+
* passkey reset. You can still receive funds. Try again after {retryAfterAt}."
|
|
58
|
+
*/
|
|
59
|
+
get isPasskeyRecoveryCooldown() {
|
|
60
|
+
return this.code === "PASSKEY_RECOVERY_COOLDOWN";
|
|
61
|
+
}
|
|
62
|
+
/** The ISO timestamp when a `PASSKEY_RECOVERY_COOLDOWN` lifts (`retry_after`), when present. */
|
|
63
|
+
get retryAfterAt() {
|
|
64
|
+
const v = this.bodyObject()["retry_after"];
|
|
65
|
+
return typeof v === "string" && v && Number.isNaN(Number(v)) ? v : void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* True if an item purchase failed because the player's balance was too low (§4.8 → 400).
|
|
69
|
+
* The backend carries `required_amount` + `current_balance` on the body for the UI.
|
|
70
|
+
* Gated to status 400 so the `429 insufficient_balance_blocked` abuse throttle (which
|
|
71
|
+
* is a rate-limit, not a top-up condition) is NOT misclassified as this.
|
|
72
|
+
*/
|
|
73
|
+
get isInsufficientBalance() {
|
|
74
|
+
if (this.status !== 400) return false;
|
|
75
|
+
const b = this.bodyObject();
|
|
76
|
+
return this.code === "INSUFFICIENT_BALANCE" || "required_amount" in b || // Zero-balance variant ("Player has no balance in this tenant") carries only
|
|
77
|
+
// `current_balance` — same top-up condition, so classify it the same way.
|
|
78
|
+
"current_balance" in b || /insufficient[_ ]balance/i.test(this.message);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* True if the call needs phone-share approval before it can complete (409) — the
|
|
82
|
+
* collecting/registering identity isn't yet authorized for the phone on file. Raised by:
|
|
83
|
+
* - registration/token-mint (phone already on another INVO account), and
|
|
84
|
+
* - **claim + confirm-receipt** (`claimTransfer`/`claimCurrency`,
|
|
85
|
+
* `confirmReceiptSend`/`confirmReceiptTransfer`) — the receiver phone is contested,
|
|
86
|
+
* so INVO holds the money and texts the phone owner to approve.
|
|
87
|
+
*
|
|
88
|
+
* NOT a failure. Show `err.message` verbatim (the backend supplies the user-facing text;
|
|
89
|
+
* `phoneShareLast4` tells the UI which phone), keep the funds pending, and **retry the same
|
|
90
|
+
* call** once the phone owner approves — an approved consent makes the retry succeed
|
|
91
|
+
* idempotently. On denial/expiry the backend refunds the sender. (`phoneShareApprovalId`
|
|
92
|
+
* carries the id when the 409 came from the OTP-handshake path;
|
|
93
|
+
* `phoneShareInitiate`/`phoneShareApprove`/`phoneShareStatus` drive that fallback.)
|
|
94
|
+
*/
|
|
95
|
+
get isPhoneShareApprovalRequired() {
|
|
96
|
+
return this.code === "PHONE_SHARE_APPROVAL_REQUIRED";
|
|
97
|
+
}
|
|
98
|
+
/** The `approval_id` from a phone-share 409 body, for `phoneShareApprove`. */
|
|
99
|
+
get phoneShareApprovalId() {
|
|
100
|
+
const v = this.bodyObject()["approval_id"];
|
|
101
|
+
return typeof v === "string" && v ? v : void 0;
|
|
102
|
+
}
|
|
103
|
+
/** Last 4 digits of the phone that must approve (`phone_last4`), for the UI message. */
|
|
104
|
+
get phoneShareLast4() {
|
|
105
|
+
const v = this.bodyObject()["phone_last4"];
|
|
106
|
+
return typeof v === "string" && v ? v : void 0;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* True if a transfer/send initiate was blocked because it would move more than the player's
|
|
110
|
+
* NON-Steam balance to a non-Steam destination (`STEAM_VALUE_NON_TRANSFERABLE`, 409).
|
|
111
|
+
* Steam-purchased currency is locked to Steam titles. NOT retryable as-is — show
|
|
112
|
+
* `err.message` and cap the amount at `err.steamTransferableMax` (`err.steamOriginAmount`
|
|
113
|
+
* is the Steam-locked portion). Prevent it up front by hiding non-Steam destinations for a
|
|
114
|
+
* holder of Steam value (`DestinationGame.acceptsSteamOriginValue`).
|
|
115
|
+
*/
|
|
116
|
+
get isSteamValueNonTransferable() {
|
|
117
|
+
return this.code === "STEAM_VALUE_NON_TRANSFERABLE";
|
|
118
|
+
}
|
|
119
|
+
/** Max the player can still send to this (non-Steam) destination (`transferable_max`), a decimal string. */
|
|
120
|
+
get steamTransferableMax() {
|
|
121
|
+
const v = this.bodyObject()["transferable_max"];
|
|
122
|
+
return typeof v === "string" && v ? v : void 0;
|
|
123
|
+
}
|
|
124
|
+
/** The Steam-purchased portion locked to Steam titles (`steam_origin_amount`), a decimal string. */
|
|
125
|
+
get steamOriginAmount() {
|
|
126
|
+
const v = this.bodyObject()["steam_origin_amount"];
|
|
127
|
+
return typeof v === "string" && v ? v : void 0;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* True if a transfer/send initiate was blocked because it moves NON-Steam value INTO a
|
|
131
|
+
* Steam title (`NON_STEAM_VALUE_INTO_STEAM_BLOCKED`, 409). Show `err.message`; the fix is to
|
|
132
|
+
* pick a non-Steam destination (surfaced via `DestinationGame.acceptsSteamOriginValue`).
|
|
133
|
+
*/
|
|
134
|
+
get isNonSteamValueIntoSteamBlocked() {
|
|
135
|
+
return this.code === "NON_STEAM_VALUE_INTO_STEAM_BLOCKED";
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* True if the initiate was refused because **the caller's OWN game is in testing**
|
|
139
|
+
* (`SOURCE_GAME_NOT_LIVE`, 403). Reaches this SDK via `initiateSend` / `initiateTransfer`;
|
|
140
|
+
* the backend uses the same code on its Amazon rewards-send path too (not wrapped here),
|
|
141
|
+
* so one branch keeps working if that flow is ever added.
|
|
142
|
+
*
|
|
143
|
+
* **The caller can self-serve this**: switch the game to Live in the developer console
|
|
144
|
+
* (Game Settings → Status). Show `err.message` — it names the game and the exact control.
|
|
145
|
+
* `err.gameStatus` carries the current state if you want to render it.
|
|
146
|
+
*
|
|
147
|
+
* Deliberately distinct from {@link isTargetGameNotLive} — do NOT collapse the two into
|
|
148
|
+
* one "not live" case. The remediation differs: this one the developer can fix, the
|
|
149
|
+
* other one they cannot.
|
|
150
|
+
*/
|
|
151
|
+
get isSourceGameNotLive() {
|
|
152
|
+
return this.code === "SOURCE_GAME_NOT_LIVE";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* True if the initiate was refused because **the DESTINATION game is in testing**
|
|
156
|
+
* (`TARGET_GAME_NOT_LIVE`, 403). Reaches this SDK via `initiateSend` / `initiateTransfer`;
|
|
157
|
+
* same backend vocabulary on the Amazon rewards-send path (not wrapped here).
|
|
158
|
+
*
|
|
159
|
+
* **The caller usually CANNOT fix this** — the destination is another developer's game
|
|
160
|
+
* and only its owner can switch it to Live. Don't offer a "go fix it" action; show
|
|
161
|
+
* `err.message` and, ideally, steer the player to a different destination
|
|
162
|
+
* (`getDestinations`). `err.gameStatus` carries the current state.
|
|
163
|
+
*
|
|
164
|
+
* Deliberately distinct from {@link isSourceGameNotLive} — see the note there.
|
|
165
|
+
*/
|
|
166
|
+
get isTargetGameNotLive() {
|
|
167
|
+
return this.code === "TARGET_GAME_NOT_LIVE";
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The game's current status from a `*_GAME_NOT_LIVE` refusal (`game_status`, e.g.
|
|
171
|
+
* `"testing"`) — for rendering the actual state. Present on both the source and target
|
|
172
|
+
* refusals.
|
|
173
|
+
*/
|
|
174
|
+
get gameStatus() {
|
|
175
|
+
const v = this.bodyObject()["game_status"];
|
|
176
|
+
return typeof v === "string" && v ? v : void 0;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* True if the tenant has **no verified WebAuthn RP ID**, so passkey endpoints are dark
|
|
180
|
+
* (`WEBAUTHN_NOT_ENABLED_FOR_TENANT`, 403).
|
|
181
|
+
*
|
|
182
|
+
* **This is a configuration state, not a failure.** Passkey step-up is per-tenant and
|
|
183
|
+
* stays dark until the developer verifies a domain in the console. Treat it as
|
|
184
|
+
* "this tenant hasn't enabled passkeys yet" and fall back to the SMS/in-app path rather
|
|
185
|
+
* than surfacing an error to the player — the ceremony was never available to fail.
|
|
186
|
+
*
|
|
187
|
+
* This is currently the COMMON case, not an edge case: as of 2026-08-05 only 4 of 23
|
|
188
|
+
* sandbox tenants and **0 of 3 production tenants** have a verified RP ID. Every
|
|
189
|
+
* integration needs this branch until domain verification is widespread.
|
|
190
|
+
*
|
|
191
|
+
* The fix (for the developer's own tenant) is to verify a domain — see the passkey
|
|
192
|
+
* prerequisites in the README. Note this refusal carries the code on `code`, not
|
|
193
|
+
* `error_code`; the SDK reads both, so `err.code` is populated either way.
|
|
194
|
+
*/
|
|
195
|
+
get isWebauthnNotEnabledForTenant() {
|
|
196
|
+
return this.code === "WEBAUTHN_NOT_ENABLED_FOR_TENANT";
|
|
197
|
+
}
|
|
198
|
+
/** True if the phone-share (phone, requesting_email) pair was already approved. */
|
|
199
|
+
get isPhoneShareAlreadyApproved() {
|
|
200
|
+
return this.code === "PHONE_SHARE_ALREADY_APPROVED";
|
|
201
|
+
}
|
|
202
|
+
/** True if an idempotency-keyed request was a duplicate (item / platform purchase → 409).
|
|
203
|
+
* Also true for {@link isDuplicateClientRequestId}. */
|
|
204
|
+
get isDuplicateRequest() {
|
|
205
|
+
return this.code === "DUPLICATE_REQUEST" || this.code === "DUPLICATE_CLIENT_REQUEST_ID" || this.status === 409 && /duplicate/i.test(this.message);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* True when a Platform Commerce CARD purchase reused a `clientRequestId` that already has a
|
|
209
|
+
* payment in progress or done (`DUPLICATE_CLIENT_REQUEST_ID`, 409). The body carries
|
|
210
|
+
* `order_id` and `order_status` for that order. Read it with `platformCommerce.getStatus`
|
|
211
|
+
* rather than starting a second payment.
|
|
212
|
+
*/
|
|
213
|
+
get isDuplicateClientRequestId() {
|
|
214
|
+
return this.code === "DUPLICATE_CLIENT_REQUEST_ID";
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* True if a Platform Commerce call was rejected because the tenant isn't a platform
|
|
218
|
+
* tenant (`NOT_A_PLATFORM_TENANT`, 403). Platform Commerce (`invo.platformCommerce.*`)
|
|
219
|
+
* is only for non-game platform tenants — a game tenant should use `purchaseItem`
|
|
220
|
+
* (spend game currency) or `createCheckout`/`purchaseCurrency` (buy currency) instead.
|
|
221
|
+
*/
|
|
222
|
+
get isNotPlatformTenant() {
|
|
223
|
+
return this.code === "NOT_A_PLATFORM_TENANT";
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* True on `AMOUNT_BELOW_MINIMUM` (400), which three calls answer:
|
|
227
|
+
* - a Platform Commerce purchase, or a `purchaseItem` spend, too small for the fee to
|
|
228
|
+
* round above zero: raise the amount (`purchaseItem` rounds `totalPrice` to cents
|
|
229
|
+
* before this check);
|
|
230
|
+
* - initiate-send / initiate-transfer below the sending title's minimum (backend
|
|
231
|
+
* 2026-10-12): the limit is on {@link minimumAmount}, in the title's own currency
|
|
232
|
+
* ({@link limitCurrencyName}). On the wallet transfer route {@link code} stays
|
|
233
|
+
* `INVALID_AMOUNT`; this predicate reads `error_code` too.
|
|
234
|
+
*/
|
|
235
|
+
get isAmountBelowMinimum() {
|
|
236
|
+
return this.code === "AMOUNT_BELOW_MINIMUM" || this.bodyObject()["error_code"] === "AMOUNT_BELOW_MINIMUM";
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* True if the `rail` you sent disagrees with the storefront key you
|
|
240
|
+
* authenticated with (`RAIL_CHANNEL_MISMATCH`, 400).
|
|
241
|
+
*
|
|
242
|
+
* A storefront key already determines the rail, so the fix is to stop sending
|
|
243
|
+
* `rail` — not to send a different one. The error body carries `channel` and
|
|
244
|
+
* `rail` so you can see which storefront the key belongs to.
|
|
245
|
+
*
|
|
246
|
+
* INVO refuses rather than silently overriding, because silently overriding
|
|
247
|
+
* would bill a player through a route you did not ask for.
|
|
248
|
+
*/
|
|
249
|
+
get isRailChannelMismatch() {
|
|
250
|
+
return this.code === "RAIL_CHANNEL_MISMATCH";
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* True if a Steam purchase was attempted for a title INVO has not registered
|
|
254
|
+
* as distributed on Steam (`STEAM_RAIL_NOT_ENTITLED`, 403).
|
|
255
|
+
*
|
|
256
|
+
* Holding a `steam` storefront key does not by itself register the title —
|
|
257
|
+
* only INVO can do that. This is not retryable; contact INVO.
|
|
258
|
+
*/
|
|
259
|
+
get isSteamRailNotEntitled() {
|
|
260
|
+
return this.code === "STEAM_RAIL_NOT_ENTITLED";
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* True if a title distributed on Steam tried to sell currency on a non-Steam
|
|
264
|
+
* rail (`STEAM_PURCHASE_LAYER_REQUIRED`, 409).
|
|
265
|
+
*
|
|
266
|
+
* Currency for a Steam title must be bought through Steam. Use the dedicated
|
|
267
|
+
* Steam purchase flow. Not retryable on the same rail.
|
|
268
|
+
*/
|
|
269
|
+
get isSteamPurchaseLayerRequired() {
|
|
270
|
+
return this.code === "STEAM_PURCHASE_LAYER_REQUIRED";
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* True if the title has no Steam application registered with INVO yet
|
|
274
|
+
* (`STEAM_NOT_CONFIGURED`, 503).
|
|
275
|
+
*
|
|
276
|
+
* Steam pays whoever owns the Steam app, so every INVO title bills through
|
|
277
|
+
* ITS OWN Steam application. The studio adds their Steam app id and publisher
|
|
278
|
+
* Web API key in the INVO dashboard; until then the rail is closed. Earlier
|
|
279
|
+
* SDK versions said purchases ran through an INVO-owned Steam app and there
|
|
280
|
+
* was nothing to register — that is no longer true.
|
|
281
|
+
*
|
|
282
|
+
* Not retryable; the fix is a setup step in the dashboard.
|
|
283
|
+
*/
|
|
284
|
+
get isSteamNotConfigured() {
|
|
285
|
+
return this.code === "STEAM_NOT_CONFIGURED";
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* True if the order was started against a DIFFERENT Steam application than the
|
|
289
|
+
* title is configured for now (`STEAM_APP_CHANGED`, 409).
|
|
290
|
+
*
|
|
291
|
+
* Happens when a studio swaps their Steam app while orders are in flight. The
|
|
292
|
+
* in-flight order cannot be captured under the new app — contact INVO to
|
|
293
|
+
* settle it. New purchases work normally.
|
|
294
|
+
*/
|
|
295
|
+
get isSteamAppChanged() {
|
|
296
|
+
return this.code === "STEAM_APP_CHANGED";
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* True if the studio has not finished INVO billing setup
|
|
300
|
+
* (`PARTNER_BILLING_NOT_SET_UP`, 409).
|
|
301
|
+
*
|
|
302
|
+
* On Steam, Valve pays the STUDIO and INVO issues the player's currency, so
|
|
303
|
+
* INVO settles with the studio afterwards against a payment method they keep
|
|
304
|
+
* on file. No payment method, no sale. Not retryable; it is a dashboard step.
|
|
305
|
+
*/
|
|
306
|
+
get isPartnerBillingNotSetUp() {
|
|
307
|
+
return this.code === "PARTNER_BILLING_NOT_SET_UP";
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* True if the studio's settlement has been suspended (`PARTNER_RAIL_SUSPENDED`,
|
|
311
|
+
* 409) or they are temporarily over their settlement limit
|
|
312
|
+
* (`PARTNER_CREDIT_UNAVAILABLE`, 409).
|
|
313
|
+
*
|
|
314
|
+
* Refused BEFORE the player is charged, which is deliberate — the alternative
|
|
315
|
+
* is taking their money for currency that cannot be issued. Show a neutral
|
|
316
|
+
* "purchases are unavailable right now"; do not surface it as the player's
|
|
317
|
+
* problem, because it is not.
|
|
318
|
+
*/
|
|
319
|
+
get isPartnerSettlementUnavailable() {
|
|
320
|
+
return this.code === "PARTNER_RAIL_SUSPENDED" || this.code === "PARTNER_CREDIT_UNAVAILABLE";
|
|
321
|
+
}
|
|
322
|
+
/** True when the studio's settlement float cannot cover this purchase right
|
|
323
|
+
* now (`PARTNER_CREDIT_UNAVAILABLE`, 409) — the structure (billing profile,
|
|
324
|
+
* mandate, payment method) is in place; the MONEY is not. Fixed by the
|
|
325
|
+
* studio topping up (or a settlement sweep clearing), not by the player.
|
|
326
|
+
* Show a plain failure ("try again later"); do NOT hot-poll init — headroom
|
|
327
|
+
* changes on a human action, and each retry briefly re-reserves headroom.
|
|
328
|
+
* A manual retry MUST reuse the same purchaseReference. */
|
|
329
|
+
get isPartnerCreditUnavailable() {
|
|
330
|
+
return this.code === "PARTNER_CREDIT_UNAVAILABLE";
|
|
331
|
+
}
|
|
332
|
+
/** True when the studio's settlement rail is suspended
|
|
333
|
+
* (`PARTNER_RAIL_SUSPENDED`, 409) — collections failed repeatedly or an
|
|
334
|
+
* admin intervened. Terminal from the game's seat: no retry can succeed
|
|
335
|
+
* until the studio resolves it in the INVO console. */
|
|
336
|
+
get isPartnerRailSuspended() {
|
|
337
|
+
return this.code === "PARTNER_RAIL_SUSPENDED";
|
|
338
|
+
}
|
|
339
|
+
/** True when init-purchase was given a `packId` that is not in INVO's Steam
|
|
340
|
+
* catalogue (`UNKNOWN_STEAM_PACK`, 400). The error body's
|
|
341
|
+
* `valid_pack_ids` lists what exists; re-fetch `steamPacks()` — the
|
|
342
|
+
* catalogue is INVO's and can change without a deploy on your side. */
|
|
343
|
+
get isUnknownSteamPack() {
|
|
344
|
+
return this.code === "UNKNOWN_STEAM_PACK";
|
|
345
|
+
}
|
|
346
|
+
/** True when a web-session init was sent without the player's IP
|
|
347
|
+
* (`MISSING_PLAYER_IP`, 400). Always an integration bug: `playerIp` is
|
|
348
|
+
* required for `usersession: "web"` and must be the PLAYER's address as
|
|
349
|
+
* your server sees it — never your server's own. */
|
|
350
|
+
get isMissingPlayerIp() {
|
|
351
|
+
return this.code === "MISSING_PLAYER_IP";
|
|
352
|
+
}
|
|
353
|
+
/** True when finalize was called before the player approved the charge
|
|
354
|
+
* (409, `status: "not_authorized"` with Steam still reporting `Init`, or
|
|
355
|
+
* no status yet). THE NORMAL WAIT STATE — keep polling / wait for the
|
|
356
|
+
* client callback and call finalize again. Contrast
|
|
357
|
+
* {@link isSteamAuthorizationDead}.
|
|
358
|
+
*
|
|
359
|
+
* PENDING IS THE CLOSED SET, deliberately. The first version of this pair
|
|
360
|
+
* enumerated the DEAD statuses and made pending the complement — so a
|
|
361
|
+
* player pressing Cancel in the overlay (the most common non-approval
|
|
362
|
+
* outcome, which Steam reports as a status the list did not name)
|
|
363
|
+
* classified as "keep polling forever": the exact failure these getters
|
|
364
|
+
* exist to prevent, reintroduced by enumerating the author's hazards
|
|
365
|
+
* instead of the backend's vocabulary. Only `Init` (and an absent status)
|
|
366
|
+
* can mean "not yet"; every named status that is not Init is an outcome. */
|
|
367
|
+
get isSteamAuthorizationPending() {
|
|
368
|
+
if (this.code === "STEAM_AUTHORIZATION_PENDING") return true;
|
|
369
|
+
const b = this.body;
|
|
370
|
+
if (!b || b["status"] !== "not_authorized") return false;
|
|
371
|
+
const st = String(b["steam_status"] ?? "").toLowerCase();
|
|
372
|
+
return st === "init" || st === "";
|
|
373
|
+
}
|
|
374
|
+
/** True when finalize reports the Steam transaction TERMINALLY not-approved:
|
|
375
|
+
* `not_authorized` with any settled status — Failed, Cancelled, Refunded,
|
|
376
|
+
* Chargedback, and every other non-Init outcome. STOP polling: no later
|
|
377
|
+
* call can succeed. (Dead is the open set on purpose: an unrecognised new
|
|
378
|
+
* status stops a poller rather than trapping it, and stopping wrongly costs
|
|
379
|
+
* one support question while polling wrongly runs forever.) A finalize
|
|
380
|
+
* answering `"Order is not finalizable"` with no `not_authorized` status is
|
|
381
|
+
* equally terminal — the reconciler has already settled the order's fate. */
|
|
382
|
+
get isSteamAuthorizationDead() {
|
|
383
|
+
const b = this.body;
|
|
384
|
+
if (!b || b["status"] !== "not_authorized") return false;
|
|
385
|
+
const st = String(b["steam_status"] ?? "").toLowerCase();
|
|
386
|
+
return st !== "init" && st !== "";
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* True if a CARD purchase was below the card minimum (`BELOW_CARD_MINIMUM`, 400). Nothing
|
|
390
|
+
* was charged. Two floors answer with this code:
|
|
391
|
+
* - INVO's minimum card purchase, $2.99 by default, on coin purchases and Platform Commerce
|
|
392
|
+
* card sales (not subscriptions), enforced from 2026-10-27. Until that date a smaller
|
|
393
|
+
* purchase is accepted and the response carries `minPurchaseWarning` instead.
|
|
394
|
+
* {@link minUsd} and {@link enforcedFrom} carry the figures in force; the amount and the
|
|
395
|
+
* date are INVO settings, so read them from the error rather than hard-coding them.
|
|
396
|
+
* - the card rail's own floor of $0.50, at any date, on coin purchases (the direct route and
|
|
397
|
+
* hosted checkout session create, complete and create-intent) and Platform Commerce card
|
|
398
|
+
* purchases ({@link minUsd} reads `"0.50"` there, with no {@link enforcedFrom}).
|
|
399
|
+
* {@link minUsd} tells you which floor refused it.
|
|
400
|
+
*
|
|
401
|
+
* Card purchases only; purchases through a third-party storefront or payment rail are
|
|
402
|
+
* unaffected. Raise the amount; do not retry it unchanged.
|
|
403
|
+
*/
|
|
404
|
+
get isBelowCardMinimum() {
|
|
405
|
+
return this.code === "BELOW_CARD_MINIMUM" || this.code === "BELOW_STRIPE_MINIMUM" || this.publicCode === "BELOW_CARD_MINIMUM" || this.rawCode === "BELOW_STRIPE_MINIMUM";
|
|
406
|
+
}
|
|
407
|
+
/** On `BELOW_CARD_MINIMUM`: the minimum card purchase in force (`min_usd`), USD decimal
|
|
408
|
+
* string, for example `"2.99"`. `undefined` when the body does not carry it. */
|
|
409
|
+
get minUsd() {
|
|
410
|
+
const v = this.bodyObject()["min_usd"];
|
|
411
|
+
if (typeof v === "number" && Number.isFinite(v)) return v.toFixed(2);
|
|
412
|
+
return typeof v === "string" && v ? v : void 0;
|
|
413
|
+
}
|
|
414
|
+
/** On `BELOW_CARD_MINIMUM`: the date INVO started enforcing the minimum card purchase
|
|
415
|
+
* (`enforced_from`), ISO 8601, for example `"2026-10-27"`. `undefined` when absent. */
|
|
416
|
+
get enforcedFrom() {
|
|
417
|
+
const v = this.bodyObject()["enforced_from"];
|
|
418
|
+
return typeof v === "string" && v ? v : void 0;
|
|
419
|
+
}
|
|
420
|
+
/** True if a CARD purchase exceeded INVO's maximum single card charge
|
|
421
|
+
* (`ABOVE_CARD_MAXIMUM`, 400) — split the sale or lower the amount. Do not retry it
|
|
422
|
+
* unchanged; nothing was charged.
|
|
423
|
+
*
|
|
424
|
+
* The cap is a runtime setting ($100,000.00 by default since 2026-09-18), editable by
|
|
425
|
+
* an INVO admin without a deploy and different per environment, so this SDK does not
|
|
426
|
+
* pin it and never raises this error locally. `err.message` carries the figure that was
|
|
427
|
+
* in force for the request that failed; the live figure for a tenant is also the
|
|
428
|
+
* `max_amount` of the hosted checkout's `validate-game` read. */
|
|
429
|
+
get isAboveCardMaximum() {
|
|
430
|
+
return this.code === "ABOVE_CARD_MAXIMUM";
|
|
431
|
+
}
|
|
432
|
+
// ---- Coin purchase: INVO's card fee (2026-09-23) ----
|
|
433
|
+
/**
|
|
434
|
+
* True when an UNACKNOWLEDGED `purchaseCurrency` was refused because the amount was too
|
|
435
|
+
* small to carry INVO's card fee (`AMOUNT_BELOW_FEE`, 400). Nothing was charged.
|
|
436
|
+
*
|
|
437
|
+
* @deprecated No longer returned: under the 2026-09 pricing the partner pays the card fee,
|
|
438
|
+
* so it is never in the buyer's charge. Kept so existing code still compiles; a small card
|
|
439
|
+
* purchase now answers `BELOW_CARD_MINIMUM` ({@link isBelowCardMinimum}).
|
|
440
|
+
*/
|
|
441
|
+
get isAmountBelowFee() {
|
|
442
|
+
return this.code === "AMOUNT_BELOW_FEE";
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* True when `purchaseCurrency` was sent an `acknowledgedTotalUsd` BELOW the total INVO would
|
|
446
|
+
* charge now (`QUOTE_STALE`, 409). Nothing was charged. Quote again, show the player the new
|
|
447
|
+
* total, and retry with it. {@link expectedTotalUsd} carries INVO's figure. A higher
|
|
448
|
+
* acknowledged total (for example an older fee-inclusive one) is not refused: INVO charges
|
|
449
|
+
* the true, lower total.
|
|
450
|
+
*/
|
|
451
|
+
get isQuoteStale() {
|
|
452
|
+
return this.code === "QUOTE_STALE";
|
|
453
|
+
}
|
|
454
|
+
/** On `QUOTE_STALE`: the total INVO would charge (`expected_total_usd`), decimal string. */
|
|
455
|
+
get expectedTotalUsd() {
|
|
456
|
+
const v = this.bodyObject()["expected_total_usd"];
|
|
457
|
+
return typeof v === "string" && v ? v : void 0;
|
|
458
|
+
}
|
|
459
|
+
/** On `QUOTE_STALE` or `TAX_PLACE_UNAVAILABLE`: the total you sent, as INVO read it
|
|
460
|
+
* (`acknowledged_total_usd`). */
|
|
461
|
+
get acknowledgedTotalUsd() {
|
|
462
|
+
const v = this.bodyObject()["acknowledged_total_usd"];
|
|
463
|
+
return typeof v === "string" && v ? v : void 0;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* True when a Merchant of Record `purchaseCurrency` acknowledged a taxed total but INVO could
|
|
467
|
+
* not read the buyer's tax location from the card on this attempt, and the request carried no
|
|
468
|
+
* `country` to fall back on (`TAX_PLACE_UNAVAILABLE`, 409). Nothing was charged. Retry the
|
|
469
|
+
* purchase (a fresh attempt usually reads the card), or send the `country` (and
|
|
470
|
+
* `subdivision`) you quoted with. INVO never drops the tax a buyer was shown, so it refuses
|
|
471
|
+
* rather than charging a different figure. The body carries `retryable: true`.
|
|
472
|
+
*/
|
|
473
|
+
get isTaxPlaceUnavailable() {
|
|
474
|
+
return this.code === "TAX_PLACE_UNAVAILABLE";
|
|
475
|
+
}
|
|
476
|
+
/** On `TAX_PLACE_UNAVAILABLE`: the total without tax (`untaxed_total_usd`), decimal string. */
|
|
477
|
+
get untaxedTotalUsd() {
|
|
478
|
+
const v = this.bodyObject()["untaxed_total_usd"];
|
|
479
|
+
return typeof v === "string" && v ? v : void 0;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* True if a Platform Commerce refund targeted an order that was already refunded
|
|
483
|
+
* (409). Idempotent outcome — the original refund did happen, so treat this as
|
|
484
|
+
* success, not a failure to retry-loop.
|
|
485
|
+
*/
|
|
486
|
+
get isAlreadyRefunded() {
|
|
487
|
+
if (this.isRefundRemainingRequiresConfirmation || this.isRefundRecentlyIssued) return false;
|
|
488
|
+
return this.code === "ALREADY_REFUNDED" || this.status === 409 && /already\s+refunded/i.test(this.message);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Platform Commerce card sale already refunded in part (409
|
|
492
|
+
* `REFUND_REMAINING_REQUIRES_CONFIRMATION`): nothing moved. Retry with
|
|
493
|
+
* `refundRemaining: true` to refund the rest; `refunded_total_usd` and `remaining_usd` are
|
|
494
|
+
* on `err.body`.
|
|
495
|
+
*/
|
|
496
|
+
get isRefundRemainingRequiresConfirmation() {
|
|
497
|
+
return this.code === "REFUND_REMAINING_REQUIRES_CONFIRMATION";
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* A Platform Commerce refund of this order was applied in the last 120 seconds (409
|
|
501
|
+
* `REFUND_RECENTLY_ISSUED`): nothing moved. Re-read the order; send
|
|
502
|
+
* `confirmAdditionalRefund: true` to refund anyway.
|
|
503
|
+
*/
|
|
504
|
+
get isRefundRecentlyIssued() {
|
|
505
|
+
return this.code === "REFUND_RECENTLY_ISSUED";
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* The Platform Commerce card refund failed, was canceled or still needs an action (502
|
|
509
|
+
* `REFUND_NOT_COMPLETED`): nothing was recorded. Retry; a refund that was in fact created
|
|
510
|
+
* is found and recorded on the retry, never issued twice.
|
|
511
|
+
*/
|
|
512
|
+
get isRefundNotCompleted() {
|
|
513
|
+
return this.code === "REFUND_NOT_COMPLETED";
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* True when an approve / confirm-receipt was refused because the transaction is no
|
|
517
|
+
* longer awaiting that step (`TRANSACTION_NOT_PENDING`, 400). `approveWithDeviceCode`
|
|
518
|
+
* maps this into a non-throwing `status: "not_pending"` result; you meet it as a thrown
|
|
519
|
+
* error only from a raw call. Usually "already done" (a repeat call with a device_code
|
|
520
|
+
* that was consumed the first time) — read `currentTransactionStatus`, do not retry-loop.
|
|
521
|
+
*
|
|
522
|
+
* The message fallback is for OLDER BACKEND RELEASES. The stable
|
|
523
|
+
* `TRANSACTION_NOT_PENDING` code was added on 2026-09-04; before that the same four
|
|
524
|
+
* endpoints answered `{"status":"error","message":"Transaction not pending PIN
|
|
525
|
+
* verification (current status: …)"}` — or, on the two receipt flows, "…cannot be
|
|
526
|
+
* confirmed (current status: …)" — with **no machine code at all**. An integrator
|
|
527
|
+
* running against an older deployment must still be able to tell "already done" from a
|
|
528
|
+
* real refusal without string-matching in their own code, so the string-matching lives
|
|
529
|
+
* here, once.
|
|
530
|
+
*
|
|
531
|
+
* That fallback is deliberately narrow, because it is guessing. It requires all three
|
|
532
|
+
* of: HTTP 400, one of those two phrases, AND a readable status clause. "cannot be
|
|
533
|
+
* confirmed" is an ordinary English phrase that some future refusal could reasonably
|
|
534
|
+
* use, so a phrase match ALONE must never be able to tell a caller that money moved —
|
|
535
|
+
* and with the clause required, `currentStatus` is always populated on this path, which
|
|
536
|
+
* is what actually decides `alreadySettled`.
|
|
537
|
+
*/
|
|
538
|
+
get isTransactionNotPending() {
|
|
539
|
+
if (this.code === "TRANSACTION_NOT_PENDING") return true;
|
|
540
|
+
return this.status === 400 && LEGACY_NOT_PENDING_RE.test(this.message) && LEGACY_CURRENT_STATUS_RE.test(this.message);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* The `current_status` a `TRANSACTION_NOT_PENDING` refusal reports (e.g. `pending_claim`,
|
|
544
|
+
* `completed`, `expired`).
|
|
545
|
+
*
|
|
546
|
+
* Falls back to the `(current status: …)` clause inside the message, which is where the
|
|
547
|
+
* older releases described above put it — they carried no `current_status` field.
|
|
548
|
+
*/
|
|
549
|
+
get currentTransactionStatus() {
|
|
550
|
+
const v = this.bodyObject()["current_status"];
|
|
551
|
+
if (typeof v === "string" && v) return v;
|
|
552
|
+
const m = LEGACY_CURRENT_STATUS_RE.exec(this.message);
|
|
553
|
+
const parsed = m?.[1]?.trim();
|
|
554
|
+
return parsed ? parsed : void 0;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* True when the approve endpoint did not accept the `device_code`
|
|
558
|
+
* (`DEVICE_APPROVAL_NOT_APPROVED`, 400): unknown, another player's, bound to a
|
|
559
|
+
* different transaction or FLOW, or not yet approved. Deliberately one answer for all
|
|
560
|
+
* of those (no oracle). Check the `flow` you passed matches the one you began with,
|
|
561
|
+
* and that the poll actually said `approved` before you called approve.
|
|
562
|
+
*/
|
|
563
|
+
get isDeviceApprovalNotApproved() {
|
|
564
|
+
return this.code === "DEVICE_APPROVAL_NOT_APPROVED";
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* True when `beginDeviceApproval` was refused because an APPROVED grant for this
|
|
568
|
+
* transaction and flow is still inside its window (`DEVICE_APPROVAL_ALREADY_PENDING`,
|
|
569
|
+
* 409). The player already approved — you are missing the approve call, not a new
|
|
570
|
+
* code. If you still hold the `device_code`, call `approveWithDeviceCode`; otherwise
|
|
571
|
+
* `begin` works again after `deviceApprovalExpiresAt`. (A merely PENDING earlier grant
|
|
572
|
+
* does not 409 — `begin` supersedes it with a fresh code.)
|
|
573
|
+
*/
|
|
574
|
+
get isDeviceApprovalAlreadyPending() {
|
|
575
|
+
return this.code === "DEVICE_APPROVAL_ALREADY_PENDING";
|
|
576
|
+
}
|
|
577
|
+
/** ISO time the blocking approved grant's window closes (`expires_at` on a `DEVICE_APPROVAL_ALREADY_PENDING` 409). */
|
|
578
|
+
get deviceApprovalExpiresAt() {
|
|
579
|
+
const v = this.bodyObject()["expires_at"];
|
|
580
|
+
return typeof v === "string" && v ? v : void 0;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* True when a settle call failed on INVO's side rather than being refused by a rule
|
|
584
|
+
* (`SEND_APPROVE_FAILED` / `TRANSFER_APPROVE_FAILED` / `CONFIRM_RECEIPT_FAILED`, 400).
|
|
585
|
+
*
|
|
586
|
+
* A fault, never a rule and never retryable. Show a neutral failure and report
|
|
587
|
+
* {@link errorRef} — do not treat it as a decision about the player or the money.
|
|
588
|
+
*/
|
|
589
|
+
get isSettleFault() {
|
|
590
|
+
return this.code === "SEND_APPROVE_FAILED" || this.code === "TRANSFER_APPROVE_FAILED" || this.code === "CONFIRM_RECEIPT_FAILED";
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* The `error_ref` a settle fault carries. It names the exact server log line, so quoting
|
|
594
|
+
* it to INVO support gets the cause in one message instead of a description of symptoms.
|
|
595
|
+
*/
|
|
596
|
+
get errorRef() {
|
|
597
|
+
const v = this.bodyObject()["error_ref"];
|
|
598
|
+
return typeof v === "string" && v ? v : void 0;
|
|
599
|
+
}
|
|
600
|
+
// ---- Subscriptions ----
|
|
601
|
+
/**
|
|
602
|
+
* True when a create (`subscriptions.create` / `steamInit`) was refused because the
|
|
603
|
+
* player already has a LIVE subscription to this `itemId` (`ACTIVE_SUBSCRIPTION_EXISTS`,
|
|
604
|
+
* 409). Use `existingSubscriptionId`. This is what you hit if you regenerate
|
|
605
|
+
* `clientRequestId` inside a retry loop: replay the same key instead.
|
|
606
|
+
*/
|
|
607
|
+
get isActiveSubscriptionExists() {
|
|
608
|
+
return this.code === "ACTIVE_SUBSCRIPTION_EXISTS";
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The `subscription_id` a create refusal names: the LIVE subscription on
|
|
612
|
+
* `ACTIVE_SUBSCRIPTION_EXISTS`, the PENDING Steam row on `STEAM_AUTHORIZATION_PENDING`,
|
|
613
|
+
* or the abandoned (now `expired`) row when a Steam-side failure abandoned it after creation.
|
|
614
|
+
*/
|
|
615
|
+
get existingSubscriptionId() {
|
|
616
|
+
const v = this.bodyObject()["subscription_id"];
|
|
617
|
+
return typeof v === "string" && v ? v : void 0;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* True when the same `clientRequestId` was replayed for the same player and item but
|
|
621
|
+
* with DIFFERENT material terms (`IDEMPOTENT_REPLAY_MISMATCH`, 409). See
|
|
622
|
+
* `mismatchedFields` (any of `amount_usd`, `interval`, `interval_count`, `wallet_only`,
|
|
623
|
+
* `funding_rail`, `trial_amount_usd`; for the last an omitted value counts, so a replay
|
|
624
|
+
* without it against a paid trial is a mismatch). To change terms use `changeAmount` / `setPaymentMethod`; to create a
|
|
625
|
+
* new subscription use a new key.
|
|
626
|
+
*/
|
|
627
|
+
get isIdempotentReplayMismatch() {
|
|
628
|
+
return this.code === "IDEMPOTENT_REPLAY_MISMATCH";
|
|
629
|
+
}
|
|
630
|
+
/** The `mismatched_fields` on an `IDEMPOTENT_REPLAY_MISMATCH` 409. */
|
|
631
|
+
get mismatchedFields() {
|
|
632
|
+
const v = this.bodyObject()["mismatched_fields"];
|
|
633
|
+
return Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
|
|
634
|
+
}
|
|
635
|
+
// ---- Subscriptions: paid trials (2026-09-23) ----
|
|
636
|
+
/**
|
|
637
|
+
* True on `PAYMENT_METHOD_REQUIRED` (400). From `subscriptions.create`: a paid trial
|
|
638
|
+
* (`trialAmountUsd`) with no usable saved card; nothing was created. Save the member's card
|
|
639
|
+
* (`cards.createSetupSession`), then subscribe again. From `setPaymentMethod`: no
|
|
640
|
+
* `playerCardId` was sent.
|
|
641
|
+
*/
|
|
642
|
+
get isPaymentMethodRequired() {
|
|
643
|
+
return this.code === "PAYMENT_METHOD_REQUIRED";
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* True when `trialAmountUsd` is not a usable trial price (`TRIAL_AMOUNT_INVALID`, 400): it
|
|
647
|
+
* must be a decimal of at least `0.50` (the card minimum) and less than `amountUsd`. The
|
|
648
|
+
* message names the rule.
|
|
649
|
+
*/
|
|
650
|
+
get isTrialAmountInvalid() {
|
|
651
|
+
return this.code === "TRIAL_AMOUNT_INVALID";
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* True when a paid trial's `trialAmountUsd` would leave you nothing after INVO's card fee
|
|
655
|
+
* (`TRIAL_AMOUNT_BELOW_FEE_FLOOR`, 400). Nothing was created. The message names the smallest
|
|
656
|
+
* trial price accepted for your account. A subscription already created is not affected: a
|
|
657
|
+
* replay of its `clientRequestId` answers as before.
|
|
658
|
+
*/
|
|
659
|
+
get isTrialAmountBelowFeeFloor() {
|
|
660
|
+
return this.code === "TRIAL_AMOUNT_BELOW_FEE_FLOOR";
|
|
661
|
+
}
|
|
662
|
+
/** True when `trialAmountUsd` was sent without `trialDays` or `trialEnd` (`TRIAL_AMOUNT_REQUIRES_TRIAL`, 400). */
|
|
663
|
+
get isTrialAmountRequiresTrial() {
|
|
664
|
+
return this.code === "TRIAL_AMOUNT_REQUIRES_TRIAL";
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* True when a paid trial was asked for where it cannot be charged
|
|
668
|
+
* (`TRIAL_AMOUNT_NOT_SUPPORTED_FOR_FUNDING`, 400): with `walletOnly: true`, or on the Steam
|
|
669
|
+
* rail. Paid trials are for card subscriptions only.
|
|
670
|
+
*/
|
|
671
|
+
get isTrialAmountNotSupportedForFunding() {
|
|
672
|
+
return this.code === "TRIAL_AMOUNT_NOT_SUPPORTED_FOR_FUNDING";
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* True when one of the disclosed paid-trial consent fields is malformed (400):
|
|
676
|
+
* `CONSENT_DISCLOSED_TRIAL_AMOUNT_INVALID`, `CONSENT_DISCLOSED_TRIAL_DAYS_INVALID` (not an
|
|
677
|
+
* integer 1 to 365) or `CONSENT_DISCLOSED_TRIAL_END_INVALID` (not ISO 8601). `err.code`
|
|
678
|
+
* says which. A disclosed value that is well formed but disagrees with the trial is not
|
|
679
|
+
* refused; INVO records the disagreement.
|
|
680
|
+
*/
|
|
681
|
+
get isConsentDisclosedTrialInvalid() {
|
|
682
|
+
return this.code === "CONSENT_DISCLOSED_TRIAL_AMOUNT_INVALID" || this.code === "CONSENT_DISCLOSED_TRIAL_DAYS_INVALID" || this.code === "CONSENT_DISCLOSED_TRIAL_END_INVALID";
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* True when `changeAmount` tried to RAISE the price of a Steam subscription
|
|
686
|
+
* (`STEAM_REAUTHORIZATION_REQUIRED`, 409). The member consented to a ceiling; start a
|
|
687
|
+
* new Steam subscription at the new price and cancel this one. Decreases stage normally.
|
|
688
|
+
* The body carries `current_amount_usd` and `requested_amount_usd`.
|
|
689
|
+
*/
|
|
690
|
+
get isSteamReauthorizationRequired() {
|
|
691
|
+
return this.code === "STEAM_REAUTHORIZATION_REQUIRED";
|
|
692
|
+
}
|
|
693
|
+
/** True when `setPaymentMethod` was called on a Steam subscription (`NOT_A_CARD_SUBSCRIPTION`, 409). A rail is fixed at creation. */
|
|
694
|
+
get isNotACardSubscription() {
|
|
695
|
+
return this.code === "NOT_A_CARD_SUBSCRIPTION";
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* True when a Steam subscription was started with a key for a non-Steam channel
|
|
699
|
+
* (`STEAM_CHANNEL_REQUIRED`, 409). Use the primary game key or the `steam` channel key.
|
|
700
|
+
*/
|
|
701
|
+
get isSteamChannelRequired() {
|
|
702
|
+
return this.code === "STEAM_CHANNEL_REQUIRED";
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* True when `subscriptions.refund` targeted a period that was charged through Steam
|
|
706
|
+
* (`STEAM_REFUND_NOT_SUPPORTED`, 409). Refunds of Steam-charged periods are not
|
|
707
|
+
* supported yet; periods of a Steam subscription that the wallet covered entirely
|
|
708
|
+
* remain refundable in coins.
|
|
709
|
+
*/
|
|
710
|
+
get isSteamRefundNotSupported() {
|
|
711
|
+
return this.code === "STEAM_REFUND_NOT_SUPPORTED";
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* True when `subscriptions.refund` was refused because refunds are turned off for this
|
|
715
|
+
* game (`REFUNDS_NOT_ENABLED`, 403). Refunds are on by default for every game; INVO turns
|
|
716
|
+
* them off per game. Contact INVO.
|
|
717
|
+
*/
|
|
718
|
+
get isRefundsNotEnabled() {
|
|
719
|
+
return this.code === "REFUNDS_NOT_ENABLED";
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* True when `subscriptions.refund` targeted a period charged more than 30 days ago
|
|
723
|
+
* (`REFUND_WINDOW_CLOSED`, 409). See `periodChargedAt`, `refundWindowDays` and
|
|
724
|
+
* `refundWindowClosedAt`. A retry of a refund that already ran still returns its receipt.
|
|
725
|
+
*/
|
|
726
|
+
get isRefundWindowClosed() {
|
|
727
|
+
return this.code === "REFUND_WINDOW_CLOSED";
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* True when a refund request for this period is waiting for INVO's review
|
|
731
|
+
* (`REFUND_REQUEST_PENDING`, 409). No other refund of the period can run until it is
|
|
732
|
+
* decided. The request id is on `refundRequestId`.
|
|
733
|
+
*/
|
|
734
|
+
get isRefundRequestPending() {
|
|
735
|
+
return this.code === "REFUND_REQUEST_PENDING";
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* True when this `clientRequestId` was filed as a refund request and INVO rejected it
|
|
739
|
+
* (`REFUND_REQUEST_REJECTED`, 409). See `refundRequestId` and `decisionReason`. To try
|
|
740
|
+
* again use a NEW `clientRequestId`.
|
|
741
|
+
*/
|
|
742
|
+
get isRefundRequestRejected() {
|
|
743
|
+
return this.code === "REFUND_REQUEST_REJECTED";
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* True when two requests collided (`CONCURRENT_REQUEST`, 409): two creates for a
|
|
747
|
+
* brand-new player, or two refund requests for one period filed at the same moment.
|
|
748
|
+
* Retry with the SAME key.
|
|
749
|
+
*/
|
|
750
|
+
get isConcurrentRequest() {
|
|
751
|
+
return this.code === "CONCURRENT_REQUEST";
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* True when a subscription refund needs manual reconciliation (`REFUND_MISMATCH`, 502):
|
|
755
|
+
* the card processor already holds a refund for this request with a different amount, or
|
|
756
|
+
* the charge was already fully refunded outside this flow. Contact INVO; do not retry-loop.
|
|
757
|
+
*/
|
|
758
|
+
get isRefundMismatch() {
|
|
759
|
+
return this.code === "REFUND_MISMATCH";
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* The refund request id (`request_id`) on `REFUND_REQUEST_PENDING` and
|
|
763
|
+
* `REFUND_REQUEST_REJECTED`. Not the backend request id, which is {@link requestId}.
|
|
764
|
+
*/
|
|
765
|
+
get refundRequestId() {
|
|
766
|
+
const v = this.bodyObject()["request_id"];
|
|
767
|
+
return typeof v === "string" && v ? v : void 0;
|
|
768
|
+
}
|
|
769
|
+
/** INVO's reason on `REFUND_REQUEST_REJECTED` (may be absent). */
|
|
770
|
+
get decisionReason() {
|
|
771
|
+
const v = this.bodyObject()["decision_reason"];
|
|
772
|
+
return typeof v === "string" && v ? v : void 0;
|
|
773
|
+
}
|
|
774
|
+
/** On `REFUND_WINDOW_CLOSED`: when the period was charged (ISO 8601). */
|
|
775
|
+
get periodChargedAt() {
|
|
776
|
+
const v = this.bodyObject()["period_charged_at"];
|
|
777
|
+
return typeof v === "string" && v ? v : void 0;
|
|
778
|
+
}
|
|
779
|
+
/** On `REFUND_WINDOW_CLOSED`: the window length in days (30). */
|
|
780
|
+
get refundWindowDays() {
|
|
781
|
+
const v = this.bodyObject()["refund_window_days"];
|
|
782
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
783
|
+
}
|
|
784
|
+
/** On `REFUND_WINDOW_CLOSED`: when the window closed (ISO 8601). */
|
|
785
|
+
get refundWindowClosedAt() {
|
|
786
|
+
const v = this.bodyObject()["window_closed_at"];
|
|
787
|
+
return typeof v === "string" && v ? v : void 0;
|
|
788
|
+
}
|
|
789
|
+
/** True when the subscription is `canceled` or `expired` and the call cannot apply (`SUBSCRIPTION_TERMINAL`, 409). Start a new one. */
|
|
790
|
+
get isSubscriptionTerminal() {
|
|
791
|
+
return this.code === "SUBSCRIPTION_TERMINAL";
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* True when `subscriptions.steamFinalize` was called before the member completed the
|
|
795
|
+
* Steam authorisation (409, body `status: "not_authorized"`, with `steam_status`).
|
|
796
|
+
* THE NORMAL WAIT STATE: call finalize again after the overlay or checkout closes.
|
|
797
|
+
* The member has 24 hours; after that the row expires.
|
|
798
|
+
*/
|
|
799
|
+
get isNotAuthorized() {
|
|
800
|
+
return this.bodyObject()["status"] === "not_authorized";
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* True when a sandbox clock call was refused for a missing, wrong or never-issued
|
|
804
|
+
* `X-Sandbox-Clock-Key` (`SANDBOX_CLOCK_UNAUTHORIZED`, 401). Reveal or rotate the key on
|
|
805
|
+
* the game's Game Settings page in the sandbox console.
|
|
806
|
+
*/
|
|
807
|
+
get isSandboxClockUnauthorized() {
|
|
808
|
+
return this.code === "SANDBOX_CLOCK_UNAUTHORIZED";
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* True when INVO has paused this flow for maintenance (503): `flow_paused` on create /
|
|
812
|
+
* amount / payment-method / Steam init / card setup, `FLOW_PAUSED` on refund and the
|
|
813
|
+
* sandbox clock. Retry later WITH THE SAME idempotency key.
|
|
814
|
+
*/
|
|
815
|
+
get isFlowPaused() {
|
|
816
|
+
return this.code === "flow_paused" || this.code === "FLOW_PAUSED";
|
|
817
|
+
}
|
|
818
|
+
/** True when a create was refused because the game is not `live` (`GAME_NOT_LIVE`, 403). Make it live in the console. */
|
|
819
|
+
get isGameNotLive() {
|
|
820
|
+
return this.code === "GAME_NOT_LIVE";
|
|
821
|
+
}
|
|
822
|
+
// ---- Card setup session (the INVO-hosted card page) ----
|
|
823
|
+
/**
|
|
824
|
+
* True when `cards.createSetupSession` was refused because the member does not exist
|
|
825
|
+
* in this game yet (`PLAYER_NOT_FOUND`, 404) and no `playerName` was sent. Send
|
|
826
|
+
* `playerName` (and optionally `playerPhone`) to create the member with their card.
|
|
827
|
+
* The same code comes back from `cards.beginSetup` and from `mintPlayerToken` for the
|
|
828
|
+
* same reason; those two never create players, so create the member first (for
|
|
829
|
+
* example with `createSetupSession` and a `playerName`, or a currency purchase).
|
|
830
|
+
* `getPlayerRewards` answers it when no player has that email in this game.
|
|
831
|
+
*/
|
|
832
|
+
get isPlayerNotFound() {
|
|
833
|
+
if (this.code === "PLAYER_NOT_FOUND") return true;
|
|
834
|
+
return this.status === 404 && this.bodyObject()["error"] === "player_not_found";
|
|
835
|
+
}
|
|
836
|
+
// ---- Player registration, phone changes, identity re-key ----
|
|
837
|
+
/**
|
|
838
|
+
* True when an approve was refused because the player token predates a change to the
|
|
839
|
+
* sender's identity (`PLAYER_TOKEN_STALE`, 403): their phone was added (for example on
|
|
840
|
+
* the initiate), which gives them a new identity. Nothing moved and the token stays
|
|
841
|
+
* refused. Re-mint the player token (or use the `playerToken` from the initiate result)
|
|
842
|
+
* and retry once. The SDK never retries a money call on its own.
|
|
843
|
+
*/
|
|
844
|
+
get isPlayerTokenStale() {
|
|
845
|
+
return this.code === "PLAYER_TOKEN_STALE";
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* True when `updatePlayerPhone` was refused because the player has secured this account,
|
|
849
|
+
* so the change needs the player's own confirmation (`PHONE_CHANGE_REQUIRES_VERIFICATION`,
|
|
850
|
+
* 409). Nothing changed. Call `requestPhoneChange`: INVO emails the player, who confirms
|
|
851
|
+
* on INVO's page. {@link changeRequestEndpoint} names the route.
|
|
852
|
+
*/
|
|
853
|
+
get isPhoneChangeRequiresVerification() {
|
|
854
|
+
return this.code === "PHONE_CHANGE_REQUIRES_VERIFICATION";
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* On `PHONE_CHANGE_REQUIRES_VERIFICATION`: the route to create a change request on, as INVO
|
|
858
|
+
* returned it (`change_request_endpoint`; it carries the `/sandbox` prefix in sandbox).
|
|
859
|
+
* `requestPhoneChange` already calls it. `undefined` when the body does not carry it.
|
|
860
|
+
*/
|
|
861
|
+
get changeRequestEndpoint() {
|
|
862
|
+
const v = this.bodyObject()["change_request_endpoint"];
|
|
863
|
+
return typeof v === "string" && v ? v : void 0;
|
|
864
|
+
}
|
|
865
|
+
// ---- Player-confirmed phone change (change requests) ----
|
|
866
|
+
/**
|
|
867
|
+
* True when a game tried to confirm a phone change itself (`CONFIRM_ON_INVO_PAGE`, 409).
|
|
868
|
+
* The player confirms only on INVO's page, from the link in INVO's email; a game never
|
|
869
|
+
* collects the code.
|
|
870
|
+
*/
|
|
871
|
+
get isConfirmOnInvoPage() {
|
|
872
|
+
return this.code === "CONFIRM_ON_INVO_PAGE";
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* True when the change request is unknown, belongs to another game (`getPhoneChange`), or
|
|
876
|
+
* to another player (`approvePhoneChange`) (`CHANGE_REQUEST_NOT_FOUND`, 404).
|
|
877
|
+
*/
|
|
878
|
+
get isChangeRequestNotFound() {
|
|
879
|
+
return this.code === "CHANGE_REQUEST_NOT_FOUND";
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* True when `approvePhoneChange` came before the player entered the emailed code on INVO's
|
|
883
|
+
* page (`CHANGE_REQUEST_NOT_READY`, 409). Nothing changed; approve after they do.
|
|
884
|
+
*/
|
|
885
|
+
get isChangeRequestNotReady() {
|
|
886
|
+
return this.code === "CHANGE_REQUEST_NOT_READY";
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* True when the change request is no longer pending (`CHANGE_REQUEST_NOT_PENDING`, 409):
|
|
890
|
+
* already confirmed, expired, cancelled, refused or declined. See
|
|
891
|
+
* {@link changeRequestStatus}.
|
|
892
|
+
*/
|
|
893
|
+
get isChangeRequestNotPending() {
|
|
894
|
+
return this.code === "CHANGE_REQUEST_NOT_PENDING";
|
|
895
|
+
}
|
|
896
|
+
/** On `CHANGE_REQUEST_NOT_PENDING`: the request's current `status`. */
|
|
897
|
+
get changeRequestStatus() {
|
|
898
|
+
if (this.code !== "CHANGE_REQUEST_NOT_PENDING") return void 0;
|
|
899
|
+
const v = this.bodyObject()["status"];
|
|
900
|
+
return typeof v === "string" && v ? v : void 0;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* True when another game's change request for this player is waiting for the player
|
|
904
|
+
* (`CHANGE_REQUEST_IN_PROGRESS`, 409). Retry after it is confirmed or expires.
|
|
905
|
+
*/
|
|
906
|
+
get isChangeRequestInProgress() {
|
|
907
|
+
return this.code === "CHANGE_REQUEST_IN_PROGRESS";
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* True when phone changes for this player are paused after repeated failed confirmations
|
|
911
|
+
* (`PHONE_CHANGE_LOCKED`, 409). The player has been emailed. Retry later.
|
|
912
|
+
*/
|
|
913
|
+
get isPhoneChangeLocked() {
|
|
914
|
+
return this.code === "PHONE_CHANGE_LOCKED";
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* True when `requestPhoneChange` was refused because there were too many change requests
|
|
918
|
+
* for this player (`TOO_MANY_CHANGE_REQUESTS`, 429). Try again later; do not loop.
|
|
919
|
+
*/
|
|
920
|
+
get isTooManyChangeRequests() {
|
|
921
|
+
return this.code === "TOO_MANY_CHANGE_REQUESTS";
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* True when a phone change call could not be served right now (`PHONE_CHANGE_UNAVAILABLE`,
|
|
925
|
+
* 503) or the confirmation email could not be sent (`CONFIRMATION_EMAIL_UNAVAILABLE`, 503;
|
|
926
|
+
* that request is closed). Retry shortly.
|
|
927
|
+
*/
|
|
928
|
+
get isPhoneChangeUnavailable() {
|
|
929
|
+
return this.code === "PHONE_CHANGE_UNAVAILABLE" || this.code === "CONFIRMATION_EMAIL_UNAVAILABLE";
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* True when a phone change was refused because transfers to the player's CURRENT number
|
|
933
|
+
* are still waiting to be collected (`PENDING_TRANSFERS_TO_OLD_PHONE`, 409), on
|
|
934
|
+
* `updatePlayerPhone`, `requestPhoneChange` or `approvePhoneChange`. Changing the number
|
|
935
|
+
* now would strand them. Nothing changed. Ask the player to collect them first (or wait
|
|
936
|
+
* until they expire), then retry.
|
|
937
|
+
*/
|
|
938
|
+
get isPendingTransfersToOldPhone() {
|
|
939
|
+
return this.code === "PENDING_TRANSFERS_TO_OLD_PHONE";
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* True when a phone change was refused because transfers to the NEW number are still
|
|
943
|
+
* waiting to be collected (`PENDING_TRANSFERS_TO_NEW_PHONE`, 409), on `updatePlayerPhone`,
|
|
944
|
+
* `requestPhoneChange` or `approvePhoneChange`. Nothing changed. Retry after they are
|
|
945
|
+
* collected or expire.
|
|
946
|
+
*/
|
|
947
|
+
get isPendingTransfersToNewPhone() {
|
|
948
|
+
return this.code === "PENDING_TRANSFERS_TO_NEW_PHONE";
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* True when the player's account recently went through a sign-in recovery, so the number
|
|
952
|
+
* cannot be changed yet (`PHONE_CHANGE_RECOVERY_COOLDOWN`, 409), on `requestPhoneChange`
|
|
953
|
+
* or `approvePhoneChange`. Nothing changed. Retry later; on `approvePhoneChange`,
|
|
954
|
+
* declining (`decision: "deny"`) still works.
|
|
955
|
+
*/
|
|
956
|
+
get isPhoneChangeRecoveryCooldown() {
|
|
957
|
+
return this.code === "PHONE_CHANGE_RECOVERY_COOLDOWN";
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* True when `approvePhoneChange` was refused because this device (or its key) was set up
|
|
961
|
+
* after the change was requested, so it cannot approve it
|
|
962
|
+
* (`DEVICE_ENROLLED_AFTER_REQUEST`, 409). Nothing changed. The player approves on their
|
|
963
|
+
* earlier device, or your game creates a new request.
|
|
964
|
+
*/
|
|
965
|
+
get isDeviceEnrolledAfterRequest() {
|
|
966
|
+
return this.code === "DEVICE_ENROLLED_AFTER_REQUEST";
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* True when `approvePhoneChange` was refused because the device signal did not verify
|
|
970
|
+
* (401, the reason in `error`, for example `SIGNAL_INVALID`). Nothing changed. Sign the
|
|
971
|
+
* exact message again with a fresh nonce and timestamp.
|
|
972
|
+
*/
|
|
973
|
+
get isDeviceSignalRejected() {
|
|
974
|
+
if (this.status !== 401) return false;
|
|
975
|
+
const e = this.bodyObject()["error"];
|
|
976
|
+
return typeof e === "string" && e.startsWith("SIGNAL_");
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* True when the phone you supplied is not the one on file for that player
|
|
980
|
+
* (`PHONE_MISMATCH`). Two places answer it:
|
|
981
|
+
* - `registerPlayer` (409): the player is already in your game with a different
|
|
982
|
+
* phone. Nothing changed; use `updatePlayerPhone` to change it.
|
|
983
|
+
* - initiate-send / initiate-transfer (400, since backend 2026-10-12): the sender
|
|
984
|
+
* phone does not match. Change the number first with `requestPhoneChange`.
|
|
985
|
+
* (`mintPlayerToken` reports the same situation as `phoneMismatch: true` on success.)
|
|
986
|
+
*/
|
|
987
|
+
get isPhoneMismatch() {
|
|
988
|
+
return this.code === "PHONE_MISMATCH" || this.bodyObject()["error_code"] === "PHONE_MISMATCH";
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* True when a send or transfer amount is above the sending title's maximum or the
|
|
992
|
+
* network ceiling for one move (`AMOUNT_ABOVE_MAXIMUM`, 400). See {@link maximumAmount}.
|
|
993
|
+
*/
|
|
994
|
+
get isAmountAboveMaximum() {
|
|
995
|
+
return this.code === "AMOUNT_ABOVE_MAXIMUM" || this.bodyObject()["error_code"] === "AMOUNT_ABOVE_MAXIMUM";
|
|
996
|
+
}
|
|
997
|
+
/** The minimum amount (decimal string) on an `AMOUNT_BELOW_MINIMUM` refusal. */
|
|
998
|
+
get minimumAmount() {
|
|
999
|
+
const v = this.bodyObject()["minimum_amount"];
|
|
1000
|
+
return typeof v === "string" ? v : void 0;
|
|
1001
|
+
}
|
|
1002
|
+
/** The maximum amount (decimal string) on an `AMOUNT_ABOVE_MAXIMUM` refusal. */
|
|
1003
|
+
get maximumAmount() {
|
|
1004
|
+
const v = this.bodyObject()["maximum_amount"];
|
|
1005
|
+
return typeof v === "string" ? v : void 0;
|
|
1006
|
+
}
|
|
1007
|
+
/** The sending title's currency name on an amount-limit refusal, when it has one. */
|
|
1008
|
+
get limitCurrencyName() {
|
|
1009
|
+
const v = this.bodyObject()["currency_name"];
|
|
1010
|
+
return typeof v === "string" ? v : void 0;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* True when the phone you supplied belongs to another email
|
|
1014
|
+
* (`PHONE_SHARE_APPROVAL_REQUIRED`, 409) on `mintPlayerToken`, `registerPlayer` or
|
|
1015
|
+
* `updatePlayerPhone`. Nothing was created or changed. The same condition as
|
|
1016
|
+
* {@link isPhoneShareApprovalRequired}, named for these registration calls.
|
|
1017
|
+
*/
|
|
1018
|
+
get isPhoneShareRefused() {
|
|
1019
|
+
return this.isPhoneShareApprovalRequired;
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* True when `cards.createSetupSession` was asked to create a new member (`playerName`
|
|
1023
|
+
* sent) and INVO could not create them (`PLAYER_CREATE_FAILED`, 503). Nothing was
|
|
1024
|
+
* created and no link was minted; call again.
|
|
1025
|
+
*/
|
|
1026
|
+
get isPlayerCreateFailed() {
|
|
1027
|
+
return this.code === "PLAYER_CREATE_FAILED";
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* True when `cards.createSetupSession` was refused because `playerEmail` was missing or
|
|
1031
|
+
* is not an email address (`INVALID_PLAYER_EMAIL`, 400). `getPlayerRewards` answers it
|
|
1032
|
+
* for an email that is not an email address (a blank one never leaves the SDK).
|
|
1033
|
+
*/
|
|
1034
|
+
get isInvalidPlayerEmail() {
|
|
1035
|
+
return this.code === "INVALID_PLAYER_EMAIL";
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* True on an `INVALID_INPUT` refusal. Two sources, told apart by `status`:
|
|
1039
|
+
* `status === 0` is this SDK refusing a value before the network (every client-side
|
|
1040
|
+
* guard uses this code); `status === 400` is INVO refusing one, on
|
|
1041
|
+
* `cards.createSetupSession` a `successUrl` / `cancelUrl` that uses a script scheme
|
|
1042
|
+
* (`javascript:`, `data:`, `vbscript:`; http(s) and app deep-link schemes are fine), or,
|
|
1043
|
+
* when the member is new, a `playerName` over 255 characters or a `playerPhone` over 30.
|
|
1044
|
+
*/
|
|
1045
|
+
get isInvalidInput() {
|
|
1046
|
+
return this.code === "INVALID_INPUT";
|
|
1047
|
+
}
|
|
1048
|
+
// ---- Checkout session reads (the purchase status read) ----
|
|
1049
|
+
/**
|
|
1050
|
+
* True when a session token was refused because it belongs to a DIFFERENT checkout
|
|
1051
|
+
* session than the id in the path (`SESSION_MISMATCH`, 403). The token is the
|
|
1052
|
+
* credential and the id is only a label, so the two have to agree; pair a `sessionId`
|
|
1053
|
+
* with the `sessionToken` minted for it.
|
|
1054
|
+
*/
|
|
1055
|
+
get isCheckoutSessionMismatch() {
|
|
1056
|
+
return this.code === "SESSION_MISMATCH";
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* True when a token minted to SAVE A CARD was used where a purchase token belongs
|
|
1060
|
+
* (`WRONG_SESSION_PURPOSE`, 401). A card setup session settles nothing and has no
|
|
1061
|
+
* purchase to report on.
|
|
1062
|
+
*/
|
|
1063
|
+
get isWrongSessionPurpose() {
|
|
1064
|
+
return this.code === "WRONG_SESSION_PURPOSE";
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* True when a checkout session token is too far past its expiry to answer with
|
|
1068
|
+
* (`SESSION_EXPIRED`, 410). A lapsed token still reads its own purchase for a bounded
|
|
1069
|
+
* window, because a charge outlives a 15 minute link; past that, show the buyer the
|
|
1070
|
+
* order id you already hold and a Contact support link rather than a blank screen.
|
|
1071
|
+
*/
|
|
1072
|
+
get isCheckoutSessionExpired() {
|
|
1073
|
+
return this.code === "SESSION_EXPIRED";
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* True when a claim or a confirm-receipt could not be checked just now
|
|
1077
|
+
* (`IDENTITY_CHECK_UNAVAILABLE`, 503). Nothing was moved. Retry after a few seconds. Distinct
|
|
1078
|
+
* from `CONFIRMATION_SEND_FAILED`, which means a confirmation text could not be sent.
|
|
1079
|
+
*/
|
|
1080
|
+
get isIdentityCheckUnavailable() {
|
|
1081
|
+
return this.code === "IDENTITY_CHECK_UNAVAILABLE";
|
|
1082
|
+
}
|
|
1083
|
+
// ---- Loyalty rewards (InvoClient.redeemReward) ----
|
|
1084
|
+
/** True when a reward was already redeemed and its code can no longer be shown (`already_redeemed`, 409). */
|
|
1085
|
+
get isRewardAlreadyRedeemed() {
|
|
1086
|
+
return this.code === "already_redeemed";
|
|
1087
|
+
}
|
|
1088
|
+
/** True when the player has no such reward (`vault_entry_not_found`, 404). */
|
|
1089
|
+
get isRewardNotFound() {
|
|
1090
|
+
return this.code === "vault_entry_not_found";
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* True when the reward cannot be redeemed right now (409): `inventory_exhausted` (no units or
|
|
1094
|
+
* codes are left for it) or `conflict` (the reward is reserved or revoked).
|
|
1095
|
+
*/
|
|
1096
|
+
get isRewardUnavailable() {
|
|
1097
|
+
return this.code === "inventory_exhausted" || this.code === "conflict";
|
|
1098
|
+
}
|
|
1099
|
+
/** True when the reward expired before it was redeemed (`vault_entry_expired`, 410). */
|
|
1100
|
+
get isRewardExpired() {
|
|
1101
|
+
return this.code === "vault_entry_expired";
|
|
1102
|
+
}
|
|
1103
|
+
/** Seconds to wait before retrying, when the backend throttled the call (429 `retry_after`). */
|
|
1104
|
+
get retryAfter() {
|
|
1105
|
+
const v = this.bodyObject()["retry_after"];
|
|
1106
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
1107
|
+
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
1108
|
+
}
|
|
1109
|
+
/** `body` as a plain object, or `{}` if it's a string/number/null (non-JSON responses).
|
|
1110
|
+
* The `in` operator throws on primitives, so callers must go through this. */
|
|
1111
|
+
bodyObject() {
|
|
1112
|
+
return this.body && typeof this.body === "object" ? this.body : {};
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
// src/shared/loyalty-events.ts
|
|
1117
|
+
function newEventId() {
|
|
1118
|
+
const c = globalThis.crypto;
|
|
1119
|
+
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
1120
|
+
const bytes = new Uint8Array(16);
|
|
1121
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
1122
|
+
c.getRandomValues(bytes);
|
|
1123
|
+
} else {
|
|
1124
|
+
throw new InvoError({
|
|
1125
|
+
message: "No Web Crypto available to generate an eventId; pass `eventId` yourself.",
|
|
1126
|
+
code: "INVALID_INPUT",
|
|
1127
|
+
status: 0
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1131
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1132
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1133
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// src/game/client.ts
|
|
1137
|
+
var InvoGameError = class extends Error {
|
|
1138
|
+
constructor(code, message, status) {
|
|
1139
|
+
super(message);
|
|
1140
|
+
this.name = "InvoGameError";
|
|
1141
|
+
this.code = code;
|
|
1142
|
+
this.status = status;
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
var InvoGameEconomy = class {
|
|
1146
|
+
constructor(options = {}) {
|
|
1147
|
+
this.player = null;
|
|
1148
|
+
this.wallet = null;
|
|
1149
|
+
this.catalog = null;
|
|
1150
|
+
this.setupRequired = false;
|
|
1151
|
+
this.missingSecrets = [];
|
|
1152
|
+
this.token = null;
|
|
1153
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
1154
|
+
this.pendingEarn = 0;
|
|
1155
|
+
this.pendingEarnReason = "earned in play";
|
|
1156
|
+
this.earnTimer = null;
|
|
1157
|
+
this.base = (options.baseUrl ?? "/api/invo").replace(/\/+$/, "");
|
|
1158
|
+
this.storage = options.storage === void 0 ? safeLocalStorage() : options.storage;
|
|
1159
|
+
this.storageKey = options.storageKey ?? "invo.game.session";
|
|
1160
|
+
this.fetchImpl = options.fetch ?? ((input, init) => fetch(input, init));
|
|
1161
|
+
this.earnFlushMs = options.earnFlushMs ?? 750;
|
|
1162
|
+
this.pollMs = options.purchasePollMs ?? 2e3;
|
|
1163
|
+
this.purchaseTimeoutMs = options.purchaseTimeoutMs ?? 15 * 60 * 1e3;
|
|
1164
|
+
}
|
|
1165
|
+
/** Subscribe; returns the unsubscribe function. */
|
|
1166
|
+
on(type, listener) {
|
|
1167
|
+
let set = this.listeners.get(type);
|
|
1168
|
+
if (!set) this.listeners.set(type, set = /* @__PURE__ */ new Set());
|
|
1169
|
+
set.add(listener);
|
|
1170
|
+
return () => set.delete(listener);
|
|
1171
|
+
}
|
|
1172
|
+
emit(type, value) {
|
|
1173
|
+
for (const l of this.listeners.get(type) ?? []) {
|
|
1174
|
+
try {
|
|
1175
|
+
l(value);
|
|
1176
|
+
} catch (err) {
|
|
1177
|
+
console.error("[invo] listener failed", err);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
get signedIn() {
|
|
1182
|
+
return this.token !== null && this.player !== null;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Load the catalog, learn whether INVO is set up, restore a saved session, and resume a
|
|
1186
|
+
* checkout the player is returning from (`?invo_purchase=` in the URL). Call once at boot.
|
|
1187
|
+
*/
|
|
1188
|
+
async init() {
|
|
1189
|
+
const health = await this.request("GET", "/health").catch(() => null);
|
|
1190
|
+
this.setupRequired = health?.setupRequired === true;
|
|
1191
|
+
this.missingSecrets = health?.missing ?? [];
|
|
1192
|
+
this.emit("setup", { required: this.setupRequired, missing: this.missingSecrets });
|
|
1193
|
+
this.catalog = await this.request("GET", "/catalog");
|
|
1194
|
+
this.emit("catalog", this.catalog);
|
|
1195
|
+
const saved = this.storage?.getItem(this.storageKey) ?? null;
|
|
1196
|
+
if (saved && !this.setupRequired) {
|
|
1197
|
+
this.token = saved;
|
|
1198
|
+
try {
|
|
1199
|
+
const wallet = await this.request("GET", "/wallet");
|
|
1200
|
+
const player = this.readStoredPlayer();
|
|
1201
|
+
this.player = player;
|
|
1202
|
+
this.setWallet(wallet);
|
|
1203
|
+
this.emit("session", player);
|
|
1204
|
+
} catch {
|
|
1205
|
+
this.clearSession();
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
this.resumeReturningCheckout();
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Ask the server again whether its INVO secrets are set (after you add them and restart).
|
|
1212
|
+
* Returns true when INVO is connected; emits `setup` when that changes.
|
|
1213
|
+
*/
|
|
1214
|
+
async checkSetup() {
|
|
1215
|
+
const health = await this.request("GET", "/health").catch(() => null);
|
|
1216
|
+
if (!health) return !this.setupRequired;
|
|
1217
|
+
const required = health.setupRequired === true;
|
|
1218
|
+
const missing = health.missing ?? [];
|
|
1219
|
+
if (required !== this.setupRequired || missing.join() !== this.missingSecrets.join()) {
|
|
1220
|
+
this.setupRequired = required;
|
|
1221
|
+
this.missingSecrets = missing;
|
|
1222
|
+
this.emit("setup", { required, missing });
|
|
1223
|
+
}
|
|
1224
|
+
return !required;
|
|
1225
|
+
}
|
|
1226
|
+
/** Sign in (first time: email + phone; INVO creates the player). */
|
|
1227
|
+
async signIn(input) {
|
|
1228
|
+
const session = await this.request("POST", "/session", input);
|
|
1229
|
+
this.token = session.sessionToken;
|
|
1230
|
+
this.player = session.player;
|
|
1231
|
+
this.storage?.setItem(this.storageKey, session.sessionToken);
|
|
1232
|
+
this.storage?.setItem(`${this.storageKey}.player`, JSON.stringify(session.player));
|
|
1233
|
+
this.setWallet(session.wallet);
|
|
1234
|
+
this.emit("session", session.player);
|
|
1235
|
+
return session.player;
|
|
1236
|
+
}
|
|
1237
|
+
async signOut() {
|
|
1238
|
+
await this.flushEarnings().catch(() => void 0);
|
|
1239
|
+
if (this.token) await this.request("POST", "/session/end").catch(() => void 0);
|
|
1240
|
+
this.clearSession();
|
|
1241
|
+
}
|
|
1242
|
+
/** Re-read the wallet from the server. */
|
|
1243
|
+
async refresh() {
|
|
1244
|
+
if (!this.token) return null;
|
|
1245
|
+
const wallet = await this.request("GET", "/wallet");
|
|
1246
|
+
this.setWallet(wallet);
|
|
1247
|
+
return wallet;
|
|
1248
|
+
}
|
|
1249
|
+
/** How many of an item the player owns (from the last server answer). */
|
|
1250
|
+
quantity(itemId) {
|
|
1251
|
+
return this.wallet?.inventory[itemId] ?? 0;
|
|
1252
|
+
}
|
|
1253
|
+
owns(itemId) {
|
|
1254
|
+
return this.quantity(itemId) > 0;
|
|
1255
|
+
}
|
|
1256
|
+
item(itemId) {
|
|
1257
|
+
return this.catalog?.items.find((i) => i.id === itemId);
|
|
1258
|
+
}
|
|
1259
|
+
balance(kind) {
|
|
1260
|
+
return this.wallet ? this.wallet[kind] : null;
|
|
1261
|
+
}
|
|
1262
|
+
/** Whether the last known balance covers the item (the server decides for real). */
|
|
1263
|
+
canAfford(itemId, quantity = 1) {
|
|
1264
|
+
const item = this.item(itemId);
|
|
1265
|
+
const bal = item ? this.balance(item.currency)?.balance : null;
|
|
1266
|
+
return !!item && typeof bal === "number" && bal >= item.price * quantity;
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Buy an item. Safe to retry: one `clientRequestId` per tap, reused if the network drops,
|
|
1270
|
+
* so the player is charged once.
|
|
1271
|
+
*/
|
|
1272
|
+
async buyItem(itemId, options = {}) {
|
|
1273
|
+
await this.flushEarnings().catch(() => void 0);
|
|
1274
|
+
const clientRequestId = newEventId();
|
|
1275
|
+
const body = { clientRequestId, quantity: options.quantity ?? 1 };
|
|
1276
|
+
let result;
|
|
1277
|
+
try {
|
|
1278
|
+
result = await this.request("POST", `/items/${encodeURIComponent(itemId)}/buy`, body);
|
|
1279
|
+
} catch (err) {
|
|
1280
|
+
if (err instanceof InvoGameError && err.status === 0) {
|
|
1281
|
+
result = await this.request("POST", `/items/${encodeURIComponent(itemId)}/buy`, body);
|
|
1282
|
+
} else {
|
|
1283
|
+
throw err;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
this.setWallet(result.wallet);
|
|
1287
|
+
this.emit("item", result);
|
|
1288
|
+
return result;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Buy premium currency with real money through INVO's hosted checkout.
|
|
1292
|
+
*
|
|
1293
|
+
* Call it directly from a click handler: the checkout window is opened before anything
|
|
1294
|
+
* else so the browser does not block it. If popups are blocked it falls back to a full-page
|
|
1295
|
+
* redirect, and {@link init} resumes the purchase when the player comes back.
|
|
1296
|
+
*
|
|
1297
|
+
* Resolves when INVO's signed webhook has credited the purchase (or it failed, was
|
|
1298
|
+
* cancelled, or timed out). The wallet refreshes itself.
|
|
1299
|
+
*/
|
|
1300
|
+
buyPremium(packId, options = {}) {
|
|
1301
|
+
const mode = options.mode ?? "popup";
|
|
1302
|
+
let popup = null;
|
|
1303
|
+
if (mode === "popup" && typeof window !== "undefined") {
|
|
1304
|
+
popup = window.open("", "invo_checkout", "width=480,height=760");
|
|
1305
|
+
if (popup) {
|
|
1306
|
+
try {
|
|
1307
|
+
popup.document.title = "INVO secure checkout";
|
|
1308
|
+
popup.document.body.style.cssText = "background:#121418;color:#E9ECF2;font:16px system-ui;display:grid;place-items:center;height:100vh;margin:0";
|
|
1309
|
+
popup.document.body.textContent = "Opening secure checkout\u2026";
|
|
1310
|
+
} catch {
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
return (async () => {
|
|
1315
|
+
let checkout;
|
|
1316
|
+
try {
|
|
1317
|
+
checkout = await this.request("POST", "/checkout", { packId });
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
popup?.close();
|
|
1320
|
+
throw err;
|
|
1321
|
+
}
|
|
1322
|
+
if (popup && !popup.closed) {
|
|
1323
|
+
popup.location.href = checkout.checkoutUrl;
|
|
1324
|
+
} else {
|
|
1325
|
+
sessionStorageSafe()?.setItem("invo.game.pendingPurchase", JSON.stringify({ ref: checkout.purchaseRef, packId }));
|
|
1326
|
+
window.location.assign(checkout.checkoutUrl);
|
|
1327
|
+
return { purchaseRef: checkout.purchaseRef, packId, status: "pending", credited: null };
|
|
1328
|
+
}
|
|
1329
|
+
return this.waitForPurchase(checkout.purchaseRef, packId, popup);
|
|
1330
|
+
})();
|
|
1331
|
+
}
|
|
1332
|
+
/** Poll a checkout until the server reports the webhook result. */
|
|
1333
|
+
async waitForPurchase(purchaseRef, packId, popup) {
|
|
1334
|
+
const started = Date.now();
|
|
1335
|
+
let closedAt = null;
|
|
1336
|
+
for (; ; ) {
|
|
1337
|
+
await sleep(this.pollMs);
|
|
1338
|
+
let p = null;
|
|
1339
|
+
try {
|
|
1340
|
+
p = await this.request("GET", `/purchases/${encodeURIComponent(purchaseRef)}`);
|
|
1341
|
+
} catch {
|
|
1342
|
+
}
|
|
1343
|
+
if (p && p.status !== "pending") {
|
|
1344
|
+
if (popup && !popup.closed) popup.close();
|
|
1345
|
+
await this.refresh().catch(() => void 0);
|
|
1346
|
+
const update = { purchaseRef, packId, status: p.status, credited: p.credited };
|
|
1347
|
+
this.emit("purchase", update);
|
|
1348
|
+
return update;
|
|
1349
|
+
}
|
|
1350
|
+
if (popup && popup.closed && closedAt === null) closedAt = Date.now();
|
|
1351
|
+
if (closedAt !== null && Date.now() - closedAt > 2e4) {
|
|
1352
|
+
const update = { purchaseRef, packId, status: "cancelled", credited: null };
|
|
1353
|
+
this.emit("purchase", update);
|
|
1354
|
+
return update;
|
|
1355
|
+
}
|
|
1356
|
+
if (Date.now() - started > this.purchaseTimeoutMs) {
|
|
1357
|
+
const update = { purchaseRef, packId, status: "timeout", credited: null };
|
|
1358
|
+
this.emit("purchase", update);
|
|
1359
|
+
return update;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Credit soft currency the player earned. Calls are batched; the balance updates when the
|
|
1365
|
+
* server answers. The server rate-limits earnings, so a real game should compute rewards on
|
|
1366
|
+
* its server for anything valuable; this is for casual play loops.
|
|
1367
|
+
*/
|
|
1368
|
+
earn(amount, reason = "earned in play") {
|
|
1369
|
+
if (!this.token || !Number.isFinite(amount) || amount <= 0) return;
|
|
1370
|
+
this.pendingEarn += Math.floor(amount);
|
|
1371
|
+
this.pendingEarnReason = reason;
|
|
1372
|
+
if (!this.earnTimer) this.earnTimer = setTimeout(() => void this.flushEarnings(), this.earnFlushMs);
|
|
1373
|
+
}
|
|
1374
|
+
/** Send batched earnings now. */
|
|
1375
|
+
async flushEarnings() {
|
|
1376
|
+
if (this.earnTimer) {
|
|
1377
|
+
clearTimeout(this.earnTimer);
|
|
1378
|
+
this.earnTimer = null;
|
|
1379
|
+
}
|
|
1380
|
+
const amount = this.pendingEarn;
|
|
1381
|
+
if (!amount || !this.token) return;
|
|
1382
|
+
this.pendingEarn = 0;
|
|
1383
|
+
const eventId = newEventId();
|
|
1384
|
+
try {
|
|
1385
|
+
const res = await this.request("POST", "/earn", { amount, eventId, reason: this.pendingEarnReason });
|
|
1386
|
+
if (this.wallet) this.setWallet({ ...this.wallet, soft: res.soft, asOf: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1387
|
+
} catch (err) {
|
|
1388
|
+
if (err instanceof InvoGameError) this.emit("error", err);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
/** Report a loyalty event (sessions, milestones, registered custom events) through the server. */
|
|
1392
|
+
async reportEvent(eventType, payload = {}) {
|
|
1393
|
+
if (!this.token) return;
|
|
1394
|
+
await this.request("POST", "/events", { eventType, payload, eventId: newEventId() });
|
|
1395
|
+
}
|
|
1396
|
+
/** The player's loyalty cards. `available: false` when the game has no loyalty program. */
|
|
1397
|
+
async rewards() {
|
|
1398
|
+
return this.request("GET", "/rewards");
|
|
1399
|
+
}
|
|
1400
|
+
// ------------------------------------------------------------------ internals
|
|
1401
|
+
setWallet(wallet) {
|
|
1402
|
+
this.wallet = wallet;
|
|
1403
|
+
this.emit("wallet", wallet);
|
|
1404
|
+
}
|
|
1405
|
+
readStoredPlayer() {
|
|
1406
|
+
try {
|
|
1407
|
+
const raw = this.storage?.getItem(`${this.storageKey}.player`);
|
|
1408
|
+
return raw ? JSON.parse(raw) : null;
|
|
1409
|
+
} catch {
|
|
1410
|
+
return null;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
clearSession() {
|
|
1414
|
+
this.token = null;
|
|
1415
|
+
this.player = null;
|
|
1416
|
+
this.wallet = null;
|
|
1417
|
+
this.storage?.removeItem(this.storageKey);
|
|
1418
|
+
this.storage?.removeItem(`${this.storageKey}.player`);
|
|
1419
|
+
this.emit("session", null);
|
|
1420
|
+
}
|
|
1421
|
+
resumeReturningCheckout() {
|
|
1422
|
+
if (typeof window === "undefined" || !this.token) return;
|
|
1423
|
+
const url = new URL(window.location.href);
|
|
1424
|
+
const ref = url.searchParams.get("invo_purchase");
|
|
1425
|
+
const pending = sessionStorageSafe()?.getItem("invo.game.pendingPurchase");
|
|
1426
|
+
const saved = pending ? JSON.parse(pending) : null;
|
|
1427
|
+
if (!ref && !saved) return;
|
|
1428
|
+
sessionStorageSafe()?.removeItem("invo.game.pendingPurchase");
|
|
1429
|
+
url.searchParams.delete("invo_purchase");
|
|
1430
|
+
url.searchParams.delete("invo_status");
|
|
1431
|
+
window.history.replaceState(null, "", url.toString());
|
|
1432
|
+
const purchaseRef = ref ?? saved.ref;
|
|
1433
|
+
void this.waitForPurchase(purchaseRef, saved?.packId ?? "", null).catch(() => void 0);
|
|
1434
|
+
}
|
|
1435
|
+
async request(method, path, body) {
|
|
1436
|
+
const headers = { accept: "application/json" };
|
|
1437
|
+
if (body !== void 0) headers["content-type"] = "application/json";
|
|
1438
|
+
if (this.token) headers["authorization"] = `Bearer ${this.token}`;
|
|
1439
|
+
let res;
|
|
1440
|
+
try {
|
|
1441
|
+
res = await this.fetchImpl(`${this.base}${path}`, { method, headers, body: body === void 0 ? void 0 : JSON.stringify(body) });
|
|
1442
|
+
} catch {
|
|
1443
|
+
throw new InvoGameError("NETWORK", "Can't reach the game server. Check your connection.", 0);
|
|
1444
|
+
}
|
|
1445
|
+
const text = await res.text();
|
|
1446
|
+
let parsed = void 0;
|
|
1447
|
+
try {
|
|
1448
|
+
parsed = text ? JSON.parse(text) : void 0;
|
|
1449
|
+
} catch {
|
|
1450
|
+
}
|
|
1451
|
+
if (!res.ok) {
|
|
1452
|
+
const e = parsed?.error;
|
|
1453
|
+
const err = new InvoGameError(e?.code ?? "HTTP_" + res.status, e?.message ?? `Request failed (${res.status}).`, res.status);
|
|
1454
|
+
if (res.status === 401 && path !== "/session") this.clearSession();
|
|
1455
|
+
if (err.code === "INVO_SETUP_REQUIRED") {
|
|
1456
|
+
this.setupRequired = true;
|
|
1457
|
+
this.emit("setup", { required: true, missing: this.missingSecrets });
|
|
1458
|
+
}
|
|
1459
|
+
throw err;
|
|
1460
|
+
}
|
|
1461
|
+
return parsed;
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
function sleep(ms) {
|
|
1465
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
1466
|
+
}
|
|
1467
|
+
function safeLocalStorage() {
|
|
1468
|
+
try {
|
|
1469
|
+
return typeof localStorage === "undefined" ? null : localStorage;
|
|
1470
|
+
} catch {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
function sessionStorageSafe() {
|
|
1475
|
+
try {
|
|
1476
|
+
return typeof sessionStorage === "undefined" ? null : sessionStorage;
|
|
1477
|
+
} catch {
|
|
1478
|
+
return null;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
// src/game/ui.ts
|
|
1483
|
+
var STYLE_ID = "invo-ui-styles";
|
|
1484
|
+
var CONSOLE_URL = { sandbox: "https://dev.console.invo.network", production: "https://console.invo.network" };
|
|
1485
|
+
var stroke = (d, size = 18) => `<svg viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${d}</svg>`;
|
|
1486
|
+
var ICONS = {
|
|
1487
|
+
plus: stroke('<path d="M12 5v14M5 12h14"/>', 14),
|
|
1488
|
+
close: stroke('<path d="M6 6l12 12M18 6L6 18"/>', 16),
|
|
1489
|
+
bag: stroke('<path d="M6 7h12l1 13H5L6 7z"/><path d="M9 7a3 3 0 0 1 6 0"/>', 16),
|
|
1490
|
+
user: stroke('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>', 16),
|
|
1491
|
+
mail: stroke('<rect x="3" y="5" width="18" height="14" rx="3"/><path d="M3 8l9 6 9-6"/>', 16),
|
|
1492
|
+
phone: stroke('<rect x="7" y="2" width="10" height="20" rx="3"/><path d="M11 18h2"/>', 16),
|
|
1493
|
+
lock: stroke('<rect x="5" y="11" width="14" height="10" rx="2.5"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>', 14),
|
|
1494
|
+
check: stroke('<path d="M5 12.5l4.5 4.5L19 7.5"/>', 14),
|
|
1495
|
+
info: stroke('<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>', 14),
|
|
1496
|
+
alert: stroke('<path d="M12 3l10 18H2L12 3z"/><path d="M12 10v4M12 17h.01"/>', 14),
|
|
1497
|
+
copy: stroke('<rect x="9" y="9" width="12" height="12" rx="2.5"/><path d="M5 15V5a2 2 0 0 1 2-2h8"/>', 13),
|
|
1498
|
+
external: stroke('<path d="M14 4h6v6M20 4l-9 9"/><path d="M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/>', 13)
|
|
1499
|
+
};
|
|
1500
|
+
var svgId = 0;
|
|
1501
|
+
function gemSvg(size) {
|
|
1502
|
+
const id = `invo-gem-${++svgId}`;
|
|
1503
|
+
return `<svg viewBox="0 0 24 24" width="${size}" height="${size}" aria-hidden="true"><defs><linearGradient id="${id}" x1="0" y1="0" x2="1" y2="1"><stop offset="0" style="stop-color:color-mix(in srgb,var(--invo-gold) 45%,#fff)"/><stop offset=".5" style="stop-color:var(--invo-gold)"/><stop offset="1" style="stop-color:color-mix(in srgb,var(--invo-gold) 65%,#000)"/></linearGradient></defs><path d="M7 3.5h10l4.5 6L12 21.5 2.5 9.5z" fill="url(#${id})"/><path d="M2.5 9.5h19M7 3.5l5 6 5-6M12 9.5v12" stroke="#000" stroke-opacity=".22" stroke-width="1" fill="none"/><path d="M7 3.5h10l-1.5 2H8.5z" fill="#fff" fill-opacity=".35"/></svg>`;
|
|
1504
|
+
}
|
|
1505
|
+
function coinSvg(size) {
|
|
1506
|
+
const id = `invo-coin-${++svgId}`;
|
|
1507
|
+
return `<svg viewBox="0 0 24 24" width="${size}" height="${size}" aria-hidden="true"><defs><radialGradient id="${id}" cx=".35" cy=".3" r=".8"><stop offset="0" style="stop-color:color-mix(in srgb,var(--invo-teal) 40%,#fff)"/><stop offset=".55" style="stop-color:var(--invo-teal)"/><stop offset="1" style="stop-color:color-mix(in srgb,var(--invo-teal) 55%,#000)"/></radialGradient></defs><circle cx="12" cy="12" r="10" fill="url(#${id})"/><circle cx="12" cy="12" r="6.5" fill="none" stroke="#000" stroke-opacity=".2" stroke-width="1.5"/><circle cx="12" cy="12" r="6.5" fill="none" stroke="#fff" stroke-opacity=".25" stroke-width=".8" transform="translate(-.4 -.4)"/></svg>`;
|
|
1508
|
+
}
|
|
1509
|
+
var CSS = `
|
|
1510
|
+
.invo-ui{--invo-bg:#0E1014;--invo-surface:#20242C;--invo-gold:#F4C04A;--invo-teal:#3FD0C9;--invo-text:#EEF1F6;--invo-muted:#98A1B3;--invo-danger:#FF7A7A;--invo-line:rgba(255,255,255,.08);--invo-line-2:rgba(255,255,255,.14);--invo-font:Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;--invo-ease:cubic-bezier(.2,.8,.2,1);position:absolute;inset:0;pointer-events:none;font-family:var(--invo-font);color:var(--invo-text);z-index:50;font-size:14px;line-height:1.4;letter-spacing:-.005em;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}
|
|
1511
|
+
.invo-ui *{box-sizing:border-box}.invo-ui svg{display:block;flex:none}.invo-ui button{font-family:inherit}
|
|
1512
|
+
.invo-ui :focus-visible{outline:2px solid var(--invo-teal);outline-offset:2px}
|
|
1513
|
+
|
|
1514
|
+
.invo-hud{position:absolute;top:max(12px,env(safe-area-inset-top));display:flex;align-items:center;gap:6px;padding:5px;border-radius:999px;pointer-events:auto;max-width:calc(100% - 24px);background:linear-gradient(180deg,rgba(32,36,44,.84),rgba(16,18,23,.84));border:1px solid var(--invo-line);box-shadow:inset 0 1px 0 rgba(255,255,255,.06),0 12px 32px -8px rgba(0,0,0,.55);backdrop-filter:blur(16px) saturate(150%);-webkit-backdrop-filter:blur(16px) saturate(150%)}
|
|
1515
|
+
.invo-hud.right{right:12px}.invo-hud.left{left:12px}
|
|
1516
|
+
.invo-badge{display:inline-flex;align-items:center;gap:7px;height:26px;padding:0 10px;border-radius:999px;font:700 10px/1 var(--invo-font);letter-spacing:.14em;text-transform:uppercase;color:var(--invo-teal);background:rgba(63,208,201,.09);border:1px solid rgba(63,208,201,.26);white-space:nowrap}
|
|
1517
|
+
.invo-badge[hidden]{display:none}
|
|
1518
|
+
.invo-dot{width:6px;height:6px;border-radius:50%;background:currentColor;flex:none;animation:invo-ping 2.4s var(--invo-ease) infinite}
|
|
1519
|
+
.invo-pill{position:relative;display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 13px 0 9px;border-radius:999px;background:rgba(255,255,255,.035);border:1px solid var(--invo-line);font-weight:650;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
1520
|
+
.invo-pill.premium{padding-right:4px}
|
|
1521
|
+
.invo-cur{filter:drop-shadow(0 2px 6px rgba(0,0,0,.4))}
|
|
1522
|
+
.invo-amt{display:inline-block;min-width:1ch}
|
|
1523
|
+
.invo-amt.bump{animation:invo-bump .55s var(--invo-ease)}
|
|
1524
|
+
.invo-pill.premium .invo-amt.bump{color:var(--invo-gold)}.invo-pill.soft .invo-amt.bump{color:var(--invo-teal)}
|
|
1525
|
+
.invo-delta{position:absolute;left:50%;top:calc(100% + 4px);font:800 12px var(--invo-font);pointer-events:none;white-space:nowrap;animation:invo-delta 1.3s var(--invo-ease) forwards}
|
|
1526
|
+
.invo-pill.premium .invo-delta{color:var(--invo-gold)}.invo-pill.soft .invo-delta{color:var(--invo-teal)}
|
|
1527
|
+
.invo-plus{display:grid;place-items:center;width:26px;height:26px;padding:0;border:0;border-radius:50%;cursor:pointer;color:#1A1405;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 3px 10px -2px rgba(244,192,74,.55);transition:transform .18s var(--invo-ease),box-shadow .18s}
|
|
1528
|
+
.invo-plus:hover{transform:scale(1.1) rotate(90deg);box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 5px 16px -2px rgba(244,192,74,.7)}
|
|
1529
|
+
.invo-sep{width:1px;height:20px;background:var(--invo-line-2);margin:0 2px}
|
|
1530
|
+
|
|
1531
|
+
.invo-btn{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:8px;height:42px;padding:0 18px;border-radius:12px;border:1px solid var(--invo-line-2);background:rgba(255,255,255,.045);color:var(--invo-text);font:650 14px var(--invo-font);letter-spacing:-.005em;cursor:pointer;white-space:nowrap;transition:transform .14s var(--invo-ease),box-shadow .2s,background .2s,border-color .2s,filter .2s}
|
|
1532
|
+
.invo-btn:hover{background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.22)}
|
|
1533
|
+
.invo-btn:active{transform:translateY(1px) scale(.985)}
|
|
1534
|
+
.invo-btn.gold{border:0;color:#1A1405;background:linear-gradient(180deg,#FFDB82 0%,var(--invo-gold) 52%,color-mix(in srgb,var(--invo-gold) 82%,#8a5a00) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.6),inset 0 -1px 0 rgba(0,0,0,.14),0 8px 20px -8px rgba(244,192,74,.7)}
|
|
1535
|
+
.invo-btn.teal{border:0;color:#04201E;background:linear-gradient(180deg,color-mix(in srgb,var(--invo-teal) 60%,#fff) 0%,var(--invo-teal) 52%,color-mix(in srgb,var(--invo-teal) 80%,#00403c) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.55),inset 0 -1px 0 rgba(0,0,0,.14),0 8px 20px -8px rgba(63,208,201,.65)}
|
|
1536
|
+
.invo-btn.gold:hover,.invo-btn.teal:hover{filter:brightness(1.06) saturate(1.05)}
|
|
1537
|
+
.invo-btn.block{width:100%;height:48px;border-radius:14px;font-size:15px}
|
|
1538
|
+
.invo-btn.sm{height:36px;padding:0 14px;border-radius:10px;font-size:13px}
|
|
1539
|
+
.invo-btn[disabled]{cursor:not-allowed;opacity:.45;filter:none;box-shadow:none;transform:none}
|
|
1540
|
+
.invo-btn.done,.invo-btn.done[disabled]{opacity:1;color:var(--invo-teal);background:rgba(63,208,201,.08);border:1px solid rgba(63,208,201,.28);box-shadow:none}
|
|
1541
|
+
.invo-btn.done::before{content:"";width:13px;height:13px;background:currentColor;-webkit-mask:var(--invo-check) center/contain no-repeat;mask:var(--invo-check) center/contain no-repeat}
|
|
1542
|
+
.invo-ui{--invo-check:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E")}
|
|
1543
|
+
.invo-btn.busy{color:transparent!important}
|
|
1544
|
+
.invo-btn.busy::after{content:"";position:absolute;width:16px;height:16px;border-radius:50%;border:2px solid rgba(255,255,255,.25);border-top-color:#fff;animation:invo-spin .7s linear infinite}
|
|
1545
|
+
.invo-btn.gold.busy::after{border-color:rgba(26,20,5,.2);border-top-color:#1A1405}.invo-btn.teal.busy::after{border-color:rgba(4,32,30,.2);border-top-color:#04201E}
|
|
1546
|
+
.invo-hbtn{height:34px;padding:0 13px;border-radius:999px;border-color:transparent;background:transparent;font-size:13.5px;gap:7px}
|
|
1547
|
+
.invo-hbtn:hover{background:rgba(255,255,255,.07);border-color:var(--invo-line)}
|
|
1548
|
+
.invo-account[data-initial]::before{content:attr(data-initial);display:grid;place-items:center;width:24px;height:24px;margin-left:-7px;border-radius:50%;color:#04201E;font:800 11px var(--invo-font);background:linear-gradient(140deg,color-mix(in srgb,var(--invo-teal) 55%,#fff),var(--invo-teal));box-shadow:0 0 0 2px rgba(63,208,201,.18)}
|
|
1549
|
+
|
|
1550
|
+
.invo-overlay{position:absolute;inset:0;display:grid;place-items:center;padding:20px;pointer-events:auto;background:radial-gradient(120% 90% at 50% 0%,rgba(10,12,16,.55),rgba(4,5,8,.86));backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);animation:invo-fade .22s ease-out}
|
|
1551
|
+
.invo-dialog{position:relative;width:min(660px,100%);max-height:min(760px,calc(100% - 8px));overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.15) transparent;padding:26px;border-radius:26px;background:radial-gradient(120% 60% at 50% -10%,rgba(63,208,201,.07),transparent 60%),linear-gradient(180deg,rgba(33,37,45,.98),rgba(19,21,26,.99));border:1px solid var(--invo-line);box-shadow:0 50px 120px -30px rgba(0,0,0,.8),0 0 0 1px rgba(0,0,0,.45),inset 0 1px 0 rgba(255,255,255,.07);animation:invo-pop .34s var(--invo-ease)}
|
|
1552
|
+
.invo-dialog::before{content:"";position:absolute;left:28px;right:28px;top:0;height:1px;background:linear-gradient(90deg,transparent,var(--invo-gold) 30%,var(--invo-teal) 70%,transparent);opacity:.75}
|
|
1553
|
+
.invo-dialog.narrow{width:min(450px,100%)}
|
|
1554
|
+
.invo-dialog:focus{outline:none}
|
|
1555
|
+
.invo-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:22px}
|
|
1556
|
+
.invo-eyebrow{display:flex;align-items:center;gap:8px;margin:0 0 8px;font:700 11px/1 var(--invo-font);letter-spacing:.16em;text-transform:uppercase;color:var(--invo-teal)}
|
|
1557
|
+
.invo-dialog h2{margin:0;font-size:24px;line-height:1.15;font-weight:760;letter-spacing:-.025em}
|
|
1558
|
+
.invo-sub{margin:8px 0 0;color:var(--invo-muted);font-size:14px;line-height:1.5;max-width:46ch}
|
|
1559
|
+
.invo-x{display:grid;place-items:center;width:38px;height:38px;flex:none;border-radius:50%;border:1px solid var(--invo-line);background:rgba(255,255,255,.03);color:var(--invo-muted);cursor:pointer;transition:transform .25s var(--invo-ease),color .2s,background .2s}
|
|
1560
|
+
.invo-x:hover{color:var(--invo-text);background:rgba(255,255,255,.08);transform:rotate(90deg)}
|
|
1561
|
+
|
|
1562
|
+
.invo-tabs{display:inline-flex;flex-wrap:wrap;gap:4px;padding:4px;margin-bottom:18px;border-radius:13px;background:rgba(0,0,0,.28);border:1px solid var(--invo-line)}
|
|
1563
|
+
.invo-tab{height:32px;padding:0 15px;border:0;border-radius:9px;background:transparent;color:var(--invo-muted);font:600 13px var(--invo-font);text-transform:capitalize;cursor:pointer;transition:color .15s,background .2s,box-shadow .2s}
|
|
1564
|
+
.invo-tab:hover{color:var(--invo-text)}
|
|
1565
|
+
.invo-tab[aria-selected=true]{color:var(--invo-text);background:var(--invo-surface);box-shadow:inset 0 1px 0 rgba(255,255,255,.07),0 4px 14px -4px rgba(0,0,0,.6)}
|
|
1566
|
+
|
|
1567
|
+
.invo-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(186px,1fr));gap:14px}
|
|
1568
|
+
.invo-card{--c:var(--invo-teal);position:relative;display:flex;flex-direction:column;border-radius:20px;overflow:hidden;background:linear-gradient(180deg,rgba(255,255,255,.035),rgba(255,255,255,.01)),var(--invo-surface);border:1px solid var(--invo-line);transition:transform .25s var(--invo-ease),border-color .25s,box-shadow .25s;animation:invo-rise .4s var(--invo-ease) backwards}
|
|
1569
|
+
.invo-card:nth-child(2){animation-delay:.04s}.invo-card:nth-child(3){animation-delay:.08s}.invo-card:nth-child(4){animation-delay:.12s}.invo-card:nth-child(n+5){animation-delay:.16s}
|
|
1570
|
+
.invo-card:hover{transform:translateY(-4px);border-color:color-mix(in srgb,var(--c) 45%,transparent);box-shadow:0 22px 44px -22px color-mix(in srgb,var(--c) 70%,transparent)}
|
|
1571
|
+
.invo-card.owned{border-color:color-mix(in srgb,var(--c) 30%,transparent)}
|
|
1572
|
+
.invo-art{position:relative;height:136px;display:grid;place-items:center;overflow:hidden;background:radial-gradient(60% 80% at 50% 38%,color-mix(in srgb,var(--c) 34%,transparent),transparent 72%);border-bottom:1px solid var(--invo-line)}
|
|
1573
|
+
.invo-art::before{content:"";position:absolute;inset:0;background-image:linear-gradient(rgba(255,255,255,.04) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.04) 1px,transparent 1px);background-size:18px 18px;-webkit-mask-image:radial-gradient(circle at 50% 42%,#000 10%,transparent 70%);mask-image:radial-gradient(circle at 50% 42%,#000 10%,transparent 70%)}
|
|
1574
|
+
.invo-glyph{position:relative;display:grid;place-items:center;width:74px;height:74px;border-radius:24px;font-size:34px;line-height:1;color:rgba(10,12,16,.82);background:linear-gradient(150deg,color-mix(in srgb,var(--c) 55%,#fff) 0%,var(--c) 50%,color-mix(in srgb,var(--c) 65%,#000) 100%);box-shadow:inset 0 1px 0 rgba(255,255,255,.65),inset 0 -3px 0 rgba(0,0,0,.14),0 16px 34px -8px color-mix(in srgb,var(--c) 75%,transparent);transform:rotate(-6deg);transition:transform .4s var(--invo-ease)}
|
|
1575
|
+
.invo-card:hover .invo-glyph{transform:rotate(0) scale(1.07)}
|
|
1576
|
+
.invo-chip{position:absolute;top:10px;display:inline-flex;align-items:center;gap:5px;height:22px;padding:0 9px;border-radius:999px;font:700 10px/1 var(--invo-font);letter-spacing:.1em;text-transform:uppercase}
|
|
1577
|
+
.invo-chip.cat{left:10px;color:var(--invo-muted);background:rgba(0,0,0,.4);border:1px solid var(--invo-line);backdrop-filter:blur(6px)}
|
|
1578
|
+
.invo-chip.own{right:10px;color:#04201E;background:var(--invo-teal);box-shadow:0 4px 12px -2px rgba(63,208,201,.55)}
|
|
1579
|
+
.invo-cbody{display:flex;flex-direction:column;gap:6px;padding:14px 16px 0;flex:1}
|
|
1580
|
+
.invo-card h3{margin:0;font-size:15.5px;font-weight:720;letter-spacing:-.015em}
|
|
1581
|
+
.invo-card p{margin:0;color:var(--invo-muted);font-size:12.5px;line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
1582
|
+
.invo-pips{display:flex;gap:4px;margin-top:6px}
|
|
1583
|
+
.invo-pip{flex:1;height:4px;border-radius:3px;background:rgba(255,255,255,.08);transition:background .3s}
|
|
1584
|
+
.invo-pip.on{background:var(--c);box-shadow:0 0 10px -1px color-mix(in srgb,var(--c) 80%,transparent)}
|
|
1585
|
+
.invo-cfoot{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:14px 16px 16px}
|
|
1586
|
+
.invo-price{display:inline-flex;align-items:center;gap:7px;font-size:17px;font-weight:780;letter-spacing:-.01em;font-variant-numeric:tabular-nums}
|
|
1587
|
+
.invo-empty{padding:40px 16px;text-align:center;color:var(--invo-muted);border:1px dashed var(--invo-line-2);border-radius:18px}
|
|
1588
|
+
|
|
1589
|
+
.invo-packs{display:grid;grid-template-columns:repeat(auto-fit,minmax(176px,1fr));gap:14px}
|
|
1590
|
+
.invo-pack{position:relative;display:flex;flex-direction:column;align-items:center;text-align:center;padding:30px 16px 16px;border-radius:20px;background:radial-gradient(90% 70% at 50% 0%,rgba(244,192,74,.13),transparent 70%),var(--invo-surface);border:1px solid var(--invo-line);transition:transform .25s var(--invo-ease),border-color .25s,box-shadow .25s;animation:invo-rise .4s var(--invo-ease) backwards}
|
|
1591
|
+
.invo-pack:nth-child(2){animation-delay:.05s}.invo-pack:nth-child(3){animation-delay:.1s}
|
|
1592
|
+
.invo-pack:hover{transform:translateY(-4px);border-color:rgba(244,192,74,.45);box-shadow:0 22px 44px -22px rgba(244,192,74,.6)}
|
|
1593
|
+
.invo-pack.best{border-color:rgba(244,192,74,.5);background:radial-gradient(90% 80% at 50% 0%,rgba(244,192,74,.22),transparent 70%),var(--invo-surface)}
|
|
1594
|
+
.invo-ribbon{position:absolute;top:-1px;left:50%;transform:translateX(-50%);padding:6px 12px;border-radius:0 0 10px 10px;font:800 10px/1 var(--invo-font);letter-spacing:.14em;text-transform:uppercase;color:#1A1405;white-space:nowrap;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:0 6px 16px -6px rgba(244,192,74,.8)}
|
|
1595
|
+
.invo-stack{display:flex;align-items:flex-end;justify-content:center;height:62px;margin-bottom:12px;filter:drop-shadow(0 12px 18px rgba(244,192,74,.32))}
|
|
1596
|
+
.invo-stack svg+svg{margin-left:-16px}.invo-stack svg:nth-child(2){transform:translateY(-10px) scale(1.12)}
|
|
1597
|
+
.invo-pamt{font-size:30px;font-weight:820;line-height:1;letter-spacing:-.03em;color:var(--invo-gold);font-variant-numeric:tabular-nums}
|
|
1598
|
+
.invo-pname{margin:6px 0 16px;color:var(--invo-muted);font-size:13px}
|
|
1599
|
+
.invo-pack .invo-btn{width:100%}
|
|
1600
|
+
|
|
1601
|
+
.invo-status{display:flex;align-items:center;gap:10px;margin-top:16px;padding:12px 14px;border-radius:14px;font-size:13px;color:var(--invo-muted);background:rgba(255,255,255,.03);border:1px solid var(--invo-line)}
|
|
1602
|
+
.invo-status:empty{display:none}
|
|
1603
|
+
.invo-spinner{width:14px;height:14px;flex:none;border-radius:50%;border:2px solid rgba(255,255,255,.14);border-top-color:var(--invo-teal);animation:invo-spin .8s linear infinite}
|
|
1604
|
+
.invo-secure{display:flex;align-items:center;justify-content:center;gap:7px;margin:18px 0 0;color:var(--invo-muted);font-size:12px}
|
|
1605
|
+
.invo-secure svg{color:var(--invo-teal)}
|
|
1606
|
+
|
|
1607
|
+
.invo-field{display:flex;flex-direction:column;gap:8px;margin-bottom:14px}
|
|
1608
|
+
.invo-field label{display:flex;justify-content:space-between;align-items:baseline;font-size:12.5px;font-weight:650;color:var(--invo-text)}
|
|
1609
|
+
.invo-field label small{font-size:12px;font-weight:500;color:var(--invo-muted)}
|
|
1610
|
+
.invo-inwrap{position:relative}
|
|
1611
|
+
.invo-inwrap svg{position:absolute;left:15px;top:50%;transform:translateY(-50%);color:var(--invo-muted);pointer-events:none;transition:color .15s}
|
|
1612
|
+
.invo-inwrap:focus-within svg{color:var(--invo-teal)}
|
|
1613
|
+
.invo-input{width:100%;height:50px;padding:0 14px 0 44px;border-radius:14px;border:1px solid var(--invo-line-2);background:rgba(0,0,0,.3);color:var(--invo-text);font:500 15px var(--invo-font);transition:border-color .15s,box-shadow .2s,background .2s}
|
|
1614
|
+
.invo-input::placeholder{color:rgba(152,161,179,.55)}
|
|
1615
|
+
.invo-input:focus{outline:none;border-color:var(--invo-teal);background:rgba(0,0,0,.42);box-shadow:0 0 0 4px rgba(63,208,201,.14)}
|
|
1616
|
+
.invo-error{display:flex;align-items:center;gap:8px;margin:2px 0 14px;padding:10px 12px;border-radius:12px;font-size:13px;color:var(--invo-danger);background:rgba(255,122,122,.08);border:1px solid rgba(255,122,122,.24)}
|
|
1617
|
+
.invo-error:empty{display:none}
|
|
1618
|
+
.invo-callout{display:flex;align-items:flex-start;gap:10px;margin-top:16px;padding:12px 14px;border-radius:14px;font-size:12.5px;line-height:1.5;color:color-mix(in srgb,var(--invo-teal) 45%,#fff);background:rgba(63,208,201,.06);border:1px solid rgba(63,208,201,.2)}
|
|
1619
|
+
.invo-callout svg{margin-top:2px;color:var(--invo-teal)}
|
|
1620
|
+
|
|
1621
|
+
.invo-steps{display:flex;flex-direction:column;gap:10px;margin:0;padding:0;list-style:none;counter-reset:invo-step}
|
|
1622
|
+
.invo-step{display:grid;grid-template-columns:34px 1fr;gap:14px;padding:16px;border-radius:18px;background:rgba(255,255,255,.025);border:1px solid var(--invo-line);animation:invo-rise .4s var(--invo-ease) backwards}
|
|
1623
|
+
.invo-step:nth-child(2){animation-delay:.05s}.invo-step:nth-child(3){animation-delay:.1s}
|
|
1624
|
+
.invo-step::before{counter-increment:invo-step;content:counter(invo-step);display:grid;place-items:center;width:34px;height:34px;border-radius:11px;font:800 14px var(--invo-font);color:#1A1405;background:linear-gradient(180deg,#FFDB82,var(--invo-gold));box-shadow:inset 0 1px 0 rgba(255,255,255,.55),0 6px 14px -6px rgba(244,192,74,.7)}
|
|
1625
|
+
.invo-step h4{margin:3px 0 4px;font-size:15px;font-weight:700;letter-spacing:-.01em}
|
|
1626
|
+
.invo-step p{margin:0;color:var(--invo-muted);font-size:13px;line-height:1.5}
|
|
1627
|
+
.invo-keys{display:flex;flex-direction:column;gap:8px;margin-top:12px}
|
|
1628
|
+
.invo-key{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:6px 6px 6px 12px;border-radius:11px;background:rgba(0,0,0,.36);border:1px solid var(--invo-line)}
|
|
1629
|
+
.invo-code{font:600 12.5px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--invo-gold);overflow:hidden;text-overflow:ellipsis}
|
|
1630
|
+
.invo-copy{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;flex:none;border-radius:8px;border:1px solid var(--invo-line-2);background:rgba(255,255,255,.03);color:var(--invo-muted);font:600 12px var(--invo-font);cursor:pointer;transition:color .15s,border-color .15s}
|
|
1631
|
+
.invo-copy:hover{color:var(--invo-text)}.invo-copy.ok{color:var(--invo-teal);border-color:rgba(63,208,201,.4)}
|
|
1632
|
+
.invo-link{display:inline-flex;align-items:center;gap:6px;margin-top:10px;color:var(--invo-teal);font-weight:650;font-size:13px;text-decoration:none}
|
|
1633
|
+
.invo-link:hover{text-decoration:underline;text-underline-offset:3px}
|
|
1634
|
+
.invo-live{display:flex;align-items:center;gap:10px;margin-top:16px;padding:13px 15px;border-radius:14px;font-size:13px;color:var(--invo-muted);border:1px dashed var(--invo-line-2)}
|
|
1635
|
+
.invo-live .invo-dot{width:8px;height:8px;color:var(--invo-gold)}
|
|
1636
|
+
.invo-live.ok{color:var(--invo-teal);border-style:solid;border-color:rgba(63,208,201,.35);background:rgba(63,208,201,.06)}
|
|
1637
|
+
.invo-live.ok .invo-dot{color:var(--invo-teal);animation:none}
|
|
1638
|
+
|
|
1639
|
+
.invo-toasts{position:absolute;left:50%;bottom:max(20px,env(safe-area-inset-bottom));transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:8px;width:min(440px,calc(100% - 24px));pointer-events:none}
|
|
1640
|
+
.invo-toast{display:flex;align-items:center;gap:11px;max-width:100%;padding:10px 16px 10px 10px;border-radius:16px;font-weight:620;font-size:13.5px;background:rgba(26,29,36,.94);border:1px solid var(--invo-line-2);box-shadow:0 20px 44px -14px rgba(0,0,0,.7);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);animation:invo-toast .38s var(--invo-ease)}
|
|
1641
|
+
.invo-ti{display:grid;place-items:center;width:26px;height:26px;flex:none;border-radius:9px;color:var(--invo-muted);background:rgba(255,255,255,.06)}
|
|
1642
|
+
.invo-toast.success .invo-ti{color:var(--invo-teal);background:rgba(63,208,201,.14)}
|
|
1643
|
+
.invo-toast.error .invo-ti{color:var(--invo-danger);background:rgba(255,122,122,.14)}
|
|
1644
|
+
.invo-toast.out{animation:invo-toast-out .26s ease-in forwards}
|
|
1645
|
+
|
|
1646
|
+
@keyframes invo-fade{from{opacity:0}to{opacity:1}}
|
|
1647
|
+
@keyframes invo-pop{from{opacity:0;transform:translateY(16px) scale(.97)}to{opacity:1;transform:none}}
|
|
1648
|
+
@keyframes invo-sheet{from{transform:translateY(100%)}to{transform:none}}
|
|
1649
|
+
@keyframes invo-rise{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}
|
|
1650
|
+
@keyframes invo-spin{to{transform:rotate(360deg)}}
|
|
1651
|
+
@keyframes invo-ping{0%{box-shadow:0 0 0 0 currentColor}70%,100%{box-shadow:0 0 0 6px transparent}}
|
|
1652
|
+
@keyframes invo-bump{0%{transform:none}30%{transform:scale(1.22)}100%{transform:none}}
|
|
1653
|
+
@keyframes invo-delta{0%{opacity:0;transform:translate(-50%,-4px)}15%{opacity:1;transform:translate(-50%,0)}100%{opacity:0;transform:translate(-50%,10px)}}
|
|
1654
|
+
@keyframes invo-toast{from{opacity:0;transform:translateY(12px) scale(.97)}to{opacity:1;transform:none}}
|
|
1655
|
+
@keyframes invo-toast-out{to{opacity:0;transform:translateY(8px) scale(.98)}}
|
|
1656
|
+
|
|
1657
|
+
@media (max-width:560px){
|
|
1658
|
+
.invo-hbtn .invo-label{display:none}.invo-hbtn{padding:0 10px}.invo-account[data-initial]::before{margin:0 -3px}
|
|
1659
|
+
.invo-pill{padding:0 10px 0 8px;gap:6px}.invo-hud .invo-badge .invo-label{display:none}.invo-hud .invo-badge{padding:0 8px}
|
|
1660
|
+
.invo-overlay{place-items:end stretch;padding:0}
|
|
1661
|
+
.invo-dialog,.invo-dialog.narrow{width:100%;max-height:90%;border-radius:26px 26px 0 0;padding:22px 18px calc(22px + env(safe-area-inset-bottom));animation:invo-sheet .38s var(--invo-ease)}
|
|
1662
|
+
.invo-dialog h2{font-size:21px}
|
|
1663
|
+
.invo-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
|
|
1664
|
+
.invo-art{height:124px}.invo-glyph{width:56px;height:56px;font-size:26px;border-radius:18px;margin-top:10px}.invo-chip.cat{display:none}
|
|
1665
|
+
.invo-cfoot{flex-direction:column;align-items:stretch;gap:10px}.invo-cfoot .invo-btn{width:100%}
|
|
1666
|
+
}
|
|
1667
|
+
@media (prefers-reduced-motion:reduce){.invo-ui *,.invo-ui *::before,.invo-ui *::after{animation:none!important;transition:none!important}}
|
|
1668
|
+
`;
|
|
1669
|
+
function el(tag, cls, text) {
|
|
1670
|
+
const node = document.createElement(tag);
|
|
1671
|
+
if (cls) node.className = cls;
|
|
1672
|
+
if (text !== void 0) node.textContent = text;
|
|
1673
|
+
return node;
|
|
1674
|
+
}
|
|
1675
|
+
function svg(markup, cls = "invo-ico") {
|
|
1676
|
+
const span = el("span", cls);
|
|
1677
|
+
span.innerHTML = markup;
|
|
1678
|
+
span.style.display = "inline-grid";
|
|
1679
|
+
return span;
|
|
1680
|
+
}
|
|
1681
|
+
function formatAmount(n) {
|
|
1682
|
+
if (n === null || n === void 0) return "\u2014";
|
|
1683
|
+
return Math.round(n).toLocaleString();
|
|
1684
|
+
}
|
|
1685
|
+
function initialOf(name) {
|
|
1686
|
+
return (name.trim()[0] ?? "?").toUpperCase();
|
|
1687
|
+
}
|
|
1688
|
+
function mountInvoUI(container, economy, options = {}) {
|
|
1689
|
+
if (!document.getElementById(STYLE_ID)) {
|
|
1690
|
+
const style = el("style");
|
|
1691
|
+
style.id = STYLE_ID;
|
|
1692
|
+
style.textContent = CSS;
|
|
1693
|
+
document.head.appendChild(style);
|
|
1694
|
+
}
|
|
1695
|
+
if (getComputedStyle(container).position === "static") container.style.position = "relative";
|
|
1696
|
+
const root = el("div", "invo-ui");
|
|
1697
|
+
const t = options.theme ?? {};
|
|
1698
|
+
const vars = [
|
|
1699
|
+
["--invo-bg", t.background],
|
|
1700
|
+
["--invo-surface", t.surface],
|
|
1701
|
+
["--invo-gold", t.gold],
|
|
1702
|
+
["--invo-teal", t.teal],
|
|
1703
|
+
["--invo-text", t.text],
|
|
1704
|
+
["--invo-muted", t.muted],
|
|
1705
|
+
["--invo-font", t.font]
|
|
1706
|
+
];
|
|
1707
|
+
for (const [k, v] of vars) if (v) root.style.setProperty(k, v);
|
|
1708
|
+
container.appendChild(root);
|
|
1709
|
+
const premiumName = () => economy.catalog?.premium.name ?? "Gems";
|
|
1710
|
+
const softName = () => economy.catalog?.soft.name ?? "Coins";
|
|
1711
|
+
const hud = el("div", `invo-hud ${options.hudPosition === "top-left" ? "left" : "right"}`);
|
|
1712
|
+
const sandboxBadge = el("span", "invo-badge");
|
|
1713
|
+
sandboxBadge.append(el("span", "invo-dot"), el("span", "invo-label", "Sandbox"));
|
|
1714
|
+
sandboxBadge.title = "INVO sandbox: test money only.";
|
|
1715
|
+
sandboxBadge.hidden = true;
|
|
1716
|
+
const premiumPill = el("div", "invo-pill premium");
|
|
1717
|
+
const premiumAmt = el("span", "invo-amt", "\u2014");
|
|
1718
|
+
const plus = el("button", "invo-plus");
|
|
1719
|
+
plus.type = "button";
|
|
1720
|
+
plus.append(svg(ICONS.plus));
|
|
1721
|
+
premiumPill.append(svg(gemSvg(18), "invo-cur"), premiumAmt, plus);
|
|
1722
|
+
const softPill = el("div", "invo-pill soft");
|
|
1723
|
+
const softAmt = el("span", "invo-amt", "\u2014");
|
|
1724
|
+
softPill.append(svg(coinSvg(18), "invo-cur"), softAmt);
|
|
1725
|
+
const shopBtn = el("button", "invo-btn invo-hbtn");
|
|
1726
|
+
shopBtn.type = "button";
|
|
1727
|
+
shopBtn.append(svg(ICONS.bag), el("span", "invo-label", "Shop"));
|
|
1728
|
+
shopBtn.hidden = !!options.hideShopButton;
|
|
1729
|
+
const accountBtn = el("button", "invo-btn invo-hbtn invo-account");
|
|
1730
|
+
accountBtn.type = "button";
|
|
1731
|
+
hud.append(sandboxBadge, premiumPill, softPill, el("span", "invo-sep"), shopBtn, accountBtn);
|
|
1732
|
+
root.append(hud);
|
|
1733
|
+
const toasts = el("div", "invo-toasts");
|
|
1734
|
+
toasts.setAttribute("role", "status");
|
|
1735
|
+
toasts.setAttribute("aria-live", "polite");
|
|
1736
|
+
root.append(toasts);
|
|
1737
|
+
const shown = { premium: null, soft: null };
|
|
1738
|
+
function showBalance(kind, pill, amt, value) {
|
|
1739
|
+
const next = value ?? null;
|
|
1740
|
+
const prev = shown[kind];
|
|
1741
|
+
amt.textContent = formatAmount(next);
|
|
1742
|
+
shown[kind] = next;
|
|
1743
|
+
if (prev === null || next === null || prev === next) return;
|
|
1744
|
+
amt.classList.remove("bump");
|
|
1745
|
+
void amt.offsetWidth;
|
|
1746
|
+
amt.classList.add("bump");
|
|
1747
|
+
const delta = el("span", "invo-delta", `${next > prev ? "+" : "\u2212"}${formatAmount(Math.abs(next - prev))}`);
|
|
1748
|
+
pill.append(delta);
|
|
1749
|
+
setTimeout(() => delta.remove(), 1300);
|
|
1750
|
+
}
|
|
1751
|
+
function renderHud() {
|
|
1752
|
+
const w = economy.wallet;
|
|
1753
|
+
showBalance("premium", premiumPill, premiumAmt, economy.player ? w?.premium.balance : null);
|
|
1754
|
+
showBalance("soft", softPill, softAmt, economy.player ? w?.soft.balance : null);
|
|
1755
|
+
premiumPill.title = premiumName();
|
|
1756
|
+
softPill.title = softName();
|
|
1757
|
+
plus.setAttribute("aria-label", `Get more ${premiumName()}`);
|
|
1758
|
+
sandboxBadge.hidden = !economy.catalog?.sandbox;
|
|
1759
|
+
accountBtn.replaceChildren();
|
|
1760
|
+
if (economy.player) {
|
|
1761
|
+
accountBtn.dataset["initial"] = initialOf(economy.player.name);
|
|
1762
|
+
accountBtn.append(el("span", "invo-label", economy.player.name));
|
|
1763
|
+
accountBtn.title = `Signed in as ${economy.player.email}. Click to sign out.`;
|
|
1764
|
+
} else {
|
|
1765
|
+
delete accountBtn.dataset["initial"];
|
|
1766
|
+
accountBtn.append(svg(ICONS.user), el("span", "invo-label", "Sign in"));
|
|
1767
|
+
accountBtn.title = "Sign in to save progress and buy items.";
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
let overlay = null;
|
|
1771
|
+
let lastFocus = null;
|
|
1772
|
+
let onDialogClose = null;
|
|
1773
|
+
function openDialog(spec, build) {
|
|
1774
|
+
close();
|
|
1775
|
+
lastFocus = document.activeElement;
|
|
1776
|
+
overlay = el("div", "invo-overlay");
|
|
1777
|
+
const dialog = el("div", `invo-dialog${spec.narrow ? " narrow" : ""}`);
|
|
1778
|
+
dialog.setAttribute("role", "dialog");
|
|
1779
|
+
dialog.setAttribute("aria-modal", "true");
|
|
1780
|
+
dialog.setAttribute("aria-label", spec.title);
|
|
1781
|
+
dialog.tabIndex = -1;
|
|
1782
|
+
const head = el("div", "invo-head");
|
|
1783
|
+
const titles = el("div");
|
|
1784
|
+
if (spec.eyebrow) titles.append(el("div", "invo-eyebrow", spec.eyebrow));
|
|
1785
|
+
titles.append(el("h2", void 0, spec.title));
|
|
1786
|
+
if (spec.subtitle) titles.append(el("p", "invo-sub", spec.subtitle));
|
|
1787
|
+
const x = el("button", "invo-x");
|
|
1788
|
+
x.type = "button";
|
|
1789
|
+
x.setAttribute("aria-label", "Close");
|
|
1790
|
+
x.append(svg(ICONS.close));
|
|
1791
|
+
x.onclick = () => close();
|
|
1792
|
+
head.append(titles, x);
|
|
1793
|
+
const body = el("div");
|
|
1794
|
+
dialog.append(head, body);
|
|
1795
|
+
overlay.append(dialog);
|
|
1796
|
+
overlay.addEventListener("pointerdown", (e) => {
|
|
1797
|
+
if (e.target === overlay) close();
|
|
1798
|
+
});
|
|
1799
|
+
root.append(overlay);
|
|
1800
|
+
build(body);
|
|
1801
|
+
options.onModalChange?.(true);
|
|
1802
|
+
(dialog.querySelector("input") ?? dialog).focus({ preventScroll: true });
|
|
1803
|
+
}
|
|
1804
|
+
function close() {
|
|
1805
|
+
if (!overlay) return;
|
|
1806
|
+
onDialogClose?.();
|
|
1807
|
+
onDialogClose = null;
|
|
1808
|
+
overlay.remove();
|
|
1809
|
+
overlay = null;
|
|
1810
|
+
options.onModalChange?.(false);
|
|
1811
|
+
if (lastFocus instanceof HTMLElement) lastFocus.focus({ preventScroll: true });
|
|
1812
|
+
}
|
|
1813
|
+
function toast(message, tone = "info") {
|
|
1814
|
+
const node = el("div", `invo-toast ${tone}`);
|
|
1815
|
+
node.append(svg(tone === "success" ? ICONS.check : tone === "error" ? ICONS.alert : ICONS.info, "invo-ti"), el("span", void 0, message));
|
|
1816
|
+
toasts.append(node);
|
|
1817
|
+
setTimeout(() => {
|
|
1818
|
+
node.classList.add("out");
|
|
1819
|
+
setTimeout(() => node.remove(), 260);
|
|
1820
|
+
}, tone === "error" ? 5e3 : 3200);
|
|
1821
|
+
}
|
|
1822
|
+
function requireSignIn(then) {
|
|
1823
|
+
if (economy.setupRequired) {
|
|
1824
|
+
openSetup();
|
|
1825
|
+
return false;
|
|
1826
|
+
}
|
|
1827
|
+
if (!economy.signedIn) {
|
|
1828
|
+
openSignIn(then);
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1831
|
+
return true;
|
|
1832
|
+
}
|
|
1833
|
+
function openSetup() {
|
|
1834
|
+
openDialog(
|
|
1835
|
+
{
|
|
1836
|
+
title: "Connect INVO",
|
|
1837
|
+
eyebrow: "Developer setup",
|
|
1838
|
+
subtitle: "Your game already runs. Add your sandbox keys to switch on sign-in, the shop and payments."
|
|
1839
|
+
},
|
|
1840
|
+
(body) => {
|
|
1841
|
+
const steps = el("ol", "invo-steps");
|
|
1842
|
+
const step = (title, text, extra) => {
|
|
1843
|
+
const li = el("li", "invo-step");
|
|
1844
|
+
const content = el("div");
|
|
1845
|
+
content.append(el("h4", void 0, title), el("p", void 0, text));
|
|
1846
|
+
if (extra) content.append(extra);
|
|
1847
|
+
li.append(content);
|
|
1848
|
+
steps.append(li);
|
|
1849
|
+
};
|
|
1850
|
+
const link = el("a", "invo-link");
|
|
1851
|
+
link.href = economy.catalog?.sandbox === false ? CONSOLE_URL.production : CONSOLE_URL.sandbox;
|
|
1852
|
+
link.target = "_blank";
|
|
1853
|
+
link.rel = "noopener noreferrer";
|
|
1854
|
+
link.append(document.createTextNode("Open the INVO console"), svg(ICONS.external));
|
|
1855
|
+
step(economy.catalog?.sandbox === false ? "Get your production keys" : "Get your sandbox keys", "In the INVO console, open your game's settings and copy the game secret and the webhook signing secret.", link);
|
|
1856
|
+
const keys = el("div", "invo-keys");
|
|
1857
|
+
for (const name of economy.missingSecrets.length ? economy.missingSecrets : ["INVO_GAME_SECRET", "INVO_WEBHOOK_SECRET"]) {
|
|
1858
|
+
const row = el("div", "invo-key");
|
|
1859
|
+
const copy = el("button", "invo-copy");
|
|
1860
|
+
copy.type = "button";
|
|
1861
|
+
copy.append(svg(ICONS.copy), el("span", void 0, "Copy"));
|
|
1862
|
+
copy.onclick = async () => {
|
|
1863
|
+
try {
|
|
1864
|
+
await navigator.clipboard.writeText(name);
|
|
1865
|
+
copy.classList.add("ok");
|
|
1866
|
+
copy.lastElementChild.textContent = "Copied";
|
|
1867
|
+
setTimeout(() => {
|
|
1868
|
+
copy.classList.remove("ok");
|
|
1869
|
+
copy.lastElementChild.textContent = "Copy";
|
|
1870
|
+
}, 1600);
|
|
1871
|
+
} catch {
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
row.append(el("span", "invo-code", name), copy);
|
|
1875
|
+
keys.append(row);
|
|
1876
|
+
}
|
|
1877
|
+
step("Add them as secrets", "On Replit: Tools \u2192 Secrets. Anywhere else: environment variables. Never put them in your code.", keys);
|
|
1878
|
+
step("Restart the server", "Stop and run again. This page notices on its own.");
|
|
1879
|
+
body.append(steps);
|
|
1880
|
+
const live = el("div", "invo-live");
|
|
1881
|
+
const liveText = el("span", void 0, "Waiting for your keys\u2026");
|
|
1882
|
+
live.append(el("span", "invo-dot"), liveText);
|
|
1883
|
+
body.append(live);
|
|
1884
|
+
const timer = setInterval(async () => {
|
|
1885
|
+
if (!await economy.checkSetup()) return;
|
|
1886
|
+
clearInterval(timer);
|
|
1887
|
+
live.classList.add("ok");
|
|
1888
|
+
liveText.textContent = "Connected to INVO. You're ready to test.";
|
|
1889
|
+
await economy.init().catch(() => void 0);
|
|
1890
|
+
renderHud();
|
|
1891
|
+
setTimeout(() => {
|
|
1892
|
+
if (live.isConnected) {
|
|
1893
|
+
close();
|
|
1894
|
+
toast("INVO connected", "success");
|
|
1895
|
+
}
|
|
1896
|
+
}, 1400);
|
|
1897
|
+
}, 3e3);
|
|
1898
|
+
onDialogClose = () => clearInterval(timer);
|
|
1899
|
+
}
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
function openSignIn(after) {
|
|
1903
|
+
openDialog(
|
|
1904
|
+
{ title: "Sign in", eyebrow: "Player account", subtitle: "Save your progress and unlock the shop on any device.", narrow: true },
|
|
1905
|
+
(body) => {
|
|
1906
|
+
const form = el("form");
|
|
1907
|
+
form.noValidate = false;
|
|
1908
|
+
const field = (label, hint, type, name2, placeholder, autocomplete, icon) => {
|
|
1909
|
+
const wrap = el("div", "invo-field");
|
|
1910
|
+
const id = `invo-${name2}`;
|
|
1911
|
+
const l = el("label");
|
|
1912
|
+
l.htmlFor = id;
|
|
1913
|
+
l.append(document.createTextNode(label));
|
|
1914
|
+
if (hint) l.append(el("small", void 0, hint));
|
|
1915
|
+
const box = el("div", "invo-inwrap");
|
|
1916
|
+
const input = el("input", "invo-input");
|
|
1917
|
+
input.id = id;
|
|
1918
|
+
input.type = type;
|
|
1919
|
+
input.name = name2;
|
|
1920
|
+
input.placeholder = placeholder;
|
|
1921
|
+
input.autocomplete = autocomplete;
|
|
1922
|
+
box.append(svg(icon), input);
|
|
1923
|
+
wrap.append(l, box);
|
|
1924
|
+
form.append(wrap);
|
|
1925
|
+
return input;
|
|
1926
|
+
};
|
|
1927
|
+
const email = field("Email", "", "email", "email", "you@example.com", "email", ICONS.mail);
|
|
1928
|
+
const phone = field("Phone", "first sign-in only", "tel", "phone", "+1 555 555 0111", "tel", ICONS.phone);
|
|
1929
|
+
const name = field("Player name", "optional", "text", "name", "What should we call you?", "nickname", ICONS.user);
|
|
1930
|
+
email.required = true;
|
|
1931
|
+
const error = el("div", "invo-error");
|
|
1932
|
+
const submit = el("button", "invo-btn teal block", "Continue");
|
|
1933
|
+
submit.type = "submit";
|
|
1934
|
+
form.append(error, submit);
|
|
1935
|
+
if (economy.catalog?.sandbox) {
|
|
1936
|
+
const note = el("div", "invo-callout");
|
|
1937
|
+
note.append(svg(ICONS.info), el("span", void 0, "Sandbox mode: use test details. No real money moves."));
|
|
1938
|
+
form.append(note);
|
|
1939
|
+
}
|
|
1940
|
+
const secure = el("p", "invo-secure");
|
|
1941
|
+
secure.append(svg(ICONS.lock), document.createTextNode("Secured by INVO"));
|
|
1942
|
+
form.append(secure);
|
|
1943
|
+
form.onsubmit = async (e) => {
|
|
1944
|
+
e.preventDefault();
|
|
1945
|
+
submit.disabled = true;
|
|
1946
|
+
submit.classList.add("busy");
|
|
1947
|
+
error.textContent = "";
|
|
1948
|
+
try {
|
|
1949
|
+
await economy.signIn({ email: email.value.trim(), phone: phone.value.trim() || void 0, name: name.value.trim() || void 0 });
|
|
1950
|
+
close();
|
|
1951
|
+
toast(`Welcome, ${economy.player?.name ?? "player"}`, "success");
|
|
1952
|
+
after?.();
|
|
1953
|
+
} catch (err) {
|
|
1954
|
+
error.textContent = err instanceof Error ? err.message : "Sign-in failed.";
|
|
1955
|
+
} finally {
|
|
1956
|
+
submit.disabled = false;
|
|
1957
|
+
submit.classList.remove("busy");
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
body.append(form);
|
|
1961
|
+
}
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
function openBuyCurrency() {
|
|
1965
|
+
if (!requireSignIn(openBuyCurrency)) return;
|
|
1966
|
+
const catalog = economy.catalog;
|
|
1967
|
+
openDialog(
|
|
1968
|
+
{ title: `Get ${premiumName()}`, eyebrow: "Top up", subtitle: `${premiumName()} unlock premium items. Pick a pack; you'll pay on INVO's secure checkout.` },
|
|
1969
|
+
(body) => {
|
|
1970
|
+
const status = el("div", "invo-status");
|
|
1971
|
+
const packs = el("div", "invo-packs");
|
|
1972
|
+
(catalog?.premium.packs ?? []).forEach((pack, i) => packs.append(packCard(pack, i, status)));
|
|
1973
|
+
body.append(packs, status);
|
|
1974
|
+
const secure = el("p", "invo-secure");
|
|
1975
|
+
secure.append(svg(ICONS.lock), document.createTextNode("Secure checkout by INVO. Your balance updates the moment payment is confirmed."));
|
|
1976
|
+
body.append(secure);
|
|
1977
|
+
}
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
function setStatus(status, text, waiting) {
|
|
1981
|
+
status.replaceChildren();
|
|
1982
|
+
if (!text) return;
|
|
1983
|
+
if (waiting) status.append(el("span", "invo-spinner"));
|
|
1984
|
+
status.append(el("span", void 0, text));
|
|
1985
|
+
}
|
|
1986
|
+
function packCard(pack, index, status) {
|
|
1987
|
+
const card = el("div", `invo-pack${pack.badge ? " best" : ""}`);
|
|
1988
|
+
if (pack.badge) card.append(el("span", "invo-ribbon", pack.badge));
|
|
1989
|
+
const stack = el("div", "invo-stack");
|
|
1990
|
+
const gems = Math.min(3, index + 1);
|
|
1991
|
+
for (let g = 0; g < gems; g++) stack.append(svg(gemSvg(gems === 1 ? 52 : 44), "invo-cur"));
|
|
1992
|
+
card.append(stack);
|
|
1993
|
+
card.append(el("div", "invo-pamt", pack.amount ? pack.amount.toLocaleString() : pack.name));
|
|
1994
|
+
card.append(el("div", "invo-pname", pack.amount ? `${premiumName()} \xB7 ${pack.name}` : premiumName()));
|
|
1995
|
+
const buy = el("button", "invo-btn gold", `$${pack.usdAmount}`);
|
|
1996
|
+
buy.type = "button";
|
|
1997
|
+
buy.onclick = () => {
|
|
1998
|
+
buy.disabled = true;
|
|
1999
|
+
buy.classList.add("busy");
|
|
2000
|
+
setStatus(status, "Waiting for payment. Finish in the checkout window.", true);
|
|
2001
|
+
economy.buyPremium(pack.id).then((u) => {
|
|
2002
|
+
if (u.status === "credited") {
|
|
2003
|
+
setStatus(status, "", false);
|
|
2004
|
+
close();
|
|
2005
|
+
} else if (u.status === "pending") {
|
|
2006
|
+
setStatus(status, "Taking you to checkout\u2026", true);
|
|
2007
|
+
} else {
|
|
2008
|
+
setStatus(status, u.status === "cancelled" ? "Checkout closed. Nothing was charged." : `Purchase ${u.status}.`, false);
|
|
2009
|
+
}
|
|
2010
|
+
}).catch((err) => {
|
|
2011
|
+
setStatus(status, err instanceof Error ? err.message : "Checkout failed.", false);
|
|
2012
|
+
}).finally(() => {
|
|
2013
|
+
buy.disabled = false;
|
|
2014
|
+
buy.classList.remove("busy");
|
|
2015
|
+
});
|
|
2016
|
+
};
|
|
2017
|
+
card.append(buy);
|
|
2018
|
+
return card;
|
|
2019
|
+
}
|
|
2020
|
+
function openShop(category) {
|
|
2021
|
+
const catalog = economy.catalog;
|
|
2022
|
+
if (!catalog) return;
|
|
2023
|
+
const cats = options.categories ?? Array.from(new Set(catalog.items.map((i) => i.category)));
|
|
2024
|
+
let active = category && cats.includes(category) ? category : "all";
|
|
2025
|
+
openDialog(
|
|
2026
|
+
{ title: "Shop", eyebrow: "Powered by INVO", subtitle: `Spend ${premiumName()} or ${softName()}. Everything you buy is saved to your account.` },
|
|
2027
|
+
(body) => {
|
|
2028
|
+
const tabs = el("div", "invo-tabs");
|
|
2029
|
+
tabs.setAttribute("role", "tablist");
|
|
2030
|
+
const grid = el("div", "invo-grid");
|
|
2031
|
+
const tabFor = (key, label) => {
|
|
2032
|
+
const b = el("button", "invo-tab", label);
|
|
2033
|
+
b.type = "button";
|
|
2034
|
+
b.setAttribute("role", "tab");
|
|
2035
|
+
b.setAttribute("aria-selected", String(key === active));
|
|
2036
|
+
b.onclick = () => {
|
|
2037
|
+
active = key;
|
|
2038
|
+
tabs.querySelectorAll(".invo-tab").forEach((n) => n.setAttribute("aria-selected", "false"));
|
|
2039
|
+
b.setAttribute("aria-selected", "true");
|
|
2040
|
+
renderGrid();
|
|
2041
|
+
};
|
|
2042
|
+
tabs.append(b);
|
|
2043
|
+
};
|
|
2044
|
+
if (cats.length > 1) {
|
|
2045
|
+
tabFor("all", "All");
|
|
2046
|
+
for (const c of cats) tabFor(c, c);
|
|
2047
|
+
}
|
|
2048
|
+
const renderGrid = () => {
|
|
2049
|
+
const items = catalog.items.filter((i) => active === "all" || i.category === active);
|
|
2050
|
+
if (!items.length) grid.replaceChildren(el("div", "invo-empty", "Nothing here yet."));
|
|
2051
|
+
else grid.replaceChildren(...items.map(itemCard));
|
|
2052
|
+
};
|
|
2053
|
+
renderGrid();
|
|
2054
|
+
const unsub = economy.on("wallet", () => {
|
|
2055
|
+
renderGrid();
|
|
2056
|
+
grid.querySelectorAll(".invo-card").forEach((c) => c.style.animation = "none");
|
|
2057
|
+
});
|
|
2058
|
+
onDialogClose = unsub;
|
|
2059
|
+
if (cats.length > 1) body.append(tabs);
|
|
2060
|
+
body.append(grid);
|
|
2061
|
+
}
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
function itemCard(item) {
|
|
2065
|
+
const owned = economy.quantity(item.id);
|
|
2066
|
+
const max = item.maxOwned ?? 1;
|
|
2067
|
+
const card = el("div", `invo-card${owned > 0 ? " owned" : ""}`);
|
|
2068
|
+
card.style.setProperty("--c", item.color ?? (item.currency === "premium" ? "var(--invo-gold)" : "var(--invo-teal)"));
|
|
2069
|
+
const art = el("div", "invo-art");
|
|
2070
|
+
art.append(el("span", "invo-chip cat", item.category));
|
|
2071
|
+
if (owned > 0) {
|
|
2072
|
+
const chip = el("span", "invo-chip own");
|
|
2073
|
+
chip.append(svg(ICONS.check), document.createTextNode(max > 1 ? `${owned}/${max}` : "Owned"));
|
|
2074
|
+
art.append(chip);
|
|
2075
|
+
}
|
|
2076
|
+
art.append(el("div", "invo-glyph", item.icon ?? "\u25C6"));
|
|
2077
|
+
card.append(art);
|
|
2078
|
+
const cbody = el("div", "invo-cbody");
|
|
2079
|
+
cbody.append(el("h3", void 0, item.name), el("p", void 0, item.description ?? ""));
|
|
2080
|
+
if (max > 1) {
|
|
2081
|
+
const pips = el("div", "invo-pips");
|
|
2082
|
+
pips.title = `${owned} of ${max} owned`;
|
|
2083
|
+
for (let i = 0; i < Math.min(max, 10); i++) pips.append(el("span", `invo-pip${i < owned ? " on" : ""}`));
|
|
2084
|
+
cbody.append(pips);
|
|
2085
|
+
}
|
|
2086
|
+
card.append(cbody);
|
|
2087
|
+
const foot = el("div", "invo-cfoot");
|
|
2088
|
+
const price = el("div", `invo-price ${item.currency}`);
|
|
2089
|
+
price.append(svg(item.currency === "premium" ? gemSvg(18) : coinSvg(18), "invo-cur"), document.createTextNode(item.price.toLocaleString()));
|
|
2090
|
+
price.title = `${item.price.toLocaleString()} ${item.currency === "premium" ? premiumName() : softName()}`;
|
|
2091
|
+
const soldOut = owned >= max;
|
|
2092
|
+
const cannotAfford = economy.signedIn && !economy.canAfford(item.id);
|
|
2093
|
+
const btn = el("button", `invo-btn sm ${soldOut ? "done" : item.currency === "premium" ? "gold" : "teal"}`);
|
|
2094
|
+
btn.type = "button";
|
|
2095
|
+
const shortBy = item.price - (economy.balance(item.currency)?.balance ?? 0);
|
|
2096
|
+
btn.textContent = soldOut ? max === 1 ? "Owned" : "Maxed" : !cannotAfford ? "Buy" : item.currency === "premium" ? `Get ${premiumName()}` : `Need ${shortBy.toLocaleString()}`;
|
|
2097
|
+
if (cannotAfford && item.currency === "soft" && !soldOut) btn.className = "invo-btn sm";
|
|
2098
|
+
btn.disabled = soldOut;
|
|
2099
|
+
btn.onclick = async () => {
|
|
2100
|
+
if (!requireSignIn(() => openShop(item.category))) return;
|
|
2101
|
+
if (!economy.canAfford(item.id)) {
|
|
2102
|
+
if (item.currency === "premium") openBuyCurrency();
|
|
2103
|
+
else toast(`Not enough ${softName()} yet. Keep playing!`, "info");
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
btn.disabled = true;
|
|
2107
|
+
btn.classList.add("busy");
|
|
2108
|
+
try {
|
|
2109
|
+
await economy.buyItem(item.id);
|
|
2110
|
+
toast(`${item.name} unlocked`, "success");
|
|
2111
|
+
} catch (err) {
|
|
2112
|
+
toast(err instanceof InvoGameError || err instanceof Error ? err.message : "Purchase failed.", "error");
|
|
2113
|
+
btn.disabled = false;
|
|
2114
|
+
btn.classList.remove("busy");
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
foot.append(price, btn);
|
|
2118
|
+
card.append(foot);
|
|
2119
|
+
return card;
|
|
2120
|
+
}
|
|
2121
|
+
plus.onclick = () => openBuyCurrency();
|
|
2122
|
+
shopBtn.onclick = () => openShop();
|
|
2123
|
+
accountBtn.onclick = async () => {
|
|
2124
|
+
if (economy.setupRequired) return openSetup();
|
|
2125
|
+
if (!economy.signedIn) return openSignIn();
|
|
2126
|
+
await economy.signOut();
|
|
2127
|
+
toast("Signed out", "info");
|
|
2128
|
+
};
|
|
2129
|
+
const onKey = (e) => {
|
|
2130
|
+
if (e.key === "Escape" && overlay) {
|
|
2131
|
+
e.stopPropagation();
|
|
2132
|
+
close();
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
document.addEventListener("keydown", onKey, true);
|
|
2136
|
+
const offs = [
|
|
2137
|
+
economy.on("wallet", renderHud),
|
|
2138
|
+
economy.on("session", renderHud),
|
|
2139
|
+
economy.on("catalog", renderHud),
|
|
2140
|
+
economy.on("setup", renderHud),
|
|
2141
|
+
economy.on("error", (err) => toast(err.message, "error")),
|
|
2142
|
+
// Popup and redirect checkouts both end here, so the confirmation shows exactly once.
|
|
2143
|
+
economy.on("purchase", (u) => {
|
|
2144
|
+
if (u.status === "credited") toast(`+${formatAmount(u.credited)} ${premiumName()} added`, "success");
|
|
2145
|
+
})
|
|
2146
|
+
];
|
|
2147
|
+
renderHud();
|
|
2148
|
+
return {
|
|
2149
|
+
root,
|
|
2150
|
+
openShop,
|
|
2151
|
+
openBuyCurrency,
|
|
2152
|
+
openSignIn: () => openSignIn(),
|
|
2153
|
+
close,
|
|
2154
|
+
toast,
|
|
2155
|
+
destroy() {
|
|
2156
|
+
close();
|
|
2157
|
+
offs.forEach((off) => off());
|
|
2158
|
+
document.removeEventListener("keydown", onKey, true);
|
|
2159
|
+
root.remove();
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// src/version.ts
|
|
2165
|
+
var SDK_VERSION = "3.28.0";
|
|
2166
|
+
|
|
2167
|
+
exports.InvoGameEconomy = InvoGameEconomy;
|
|
2168
|
+
exports.InvoGameError = InvoGameError;
|
|
2169
|
+
exports.SDK_VERSION = SDK_VERSION;
|
|
2170
|
+
exports.mountInvoUI = mountInvoUI;
|
|
2171
|
+
//# sourceMappingURL=game.cjs.map
|
|
2172
|
+
//# sourceMappingURL=game.cjs.map
|