@invonetwork/web-sdk 3.30.0 → 3.30.2

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.
@@ -1478,10 +1478,53 @@ function toDestinationsResult(raw, direction) {
1478
1478
  };
1479
1479
  }
1480
1480
 
1481
+ // src/shared/receipt-fields.ts
1482
+ function creditFields(raw) {
1483
+ const c = raw["credited"];
1484
+ if (c === true) return { credited: true };
1485
+ if (c === false) {
1486
+ const r = raw["reason_code"];
1487
+ return { credited: false, reasonCode: r == null ? null : String(r) };
1488
+ }
1489
+ return {};
1490
+ }
1491
+ function receiptFields(raw) {
1492
+ const n = raw["receipt_number"];
1493
+ if (typeof n !== "string" || n === "") return {};
1494
+ const u = raw["receipt_url"];
1495
+ return typeof u === "string" && u !== "" ? { receiptNumber: n, receiptUrl: u } : { receiptNumber: n };
1496
+ }
1497
+
1498
+ // src/shared/purchase-status.ts
1499
+ function str(v) {
1500
+ return typeof v === "string" ? v : v === null || v === void 0 ? null : String(v);
1501
+ }
1502
+ function toPurchaseStatusResult(raw, sessionId) {
1503
+ return {
1504
+ status: String(raw["status"] ?? ""),
1505
+ // INVO SAYS, AND ONLY AN EXPLICIT `true` SAYS IT. A missing or malformed field reads
1506
+ // false, which keeps a poll running; the alternative, guessing terminality from
1507
+ // `status`, is how an old SDK declares a future status finished.
1508
+ terminal: raw["terminal"] === true,
1509
+ orderId: str(raw["order_id"]),
1510
+ sessionId: String(raw["session_id"] ?? sessionId),
1511
+ coinsCredited: str(raw["coins_credited"]),
1512
+ transactionId: str(raw["transaction_id"]),
1513
+ newBalance: str(raw["new_balance"]),
1514
+ reasonCode: str(raw["reason_code"]),
1515
+ message: str(raw["message"]),
1516
+ amountChargedUsd: str(raw["amount_charged_usd"]),
1517
+ listedUsd: str(raw["listed_usd"]),
1518
+ currencyName: str(raw["currency_name"]),
1519
+ ...receiptFields(raw),
1520
+ raw
1521
+ };
1522
+ }
1523
+
1481
1524
  // src/shared/loyalty.ts
1482
1525
  var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
1483
1526
  var rows = (v) => Array.isArray(v) ? v.filter((r) => r && typeof r === "object" && !Array.isArray(r)) : [];
1484
- var str = (v) => v === void 0 || v === null ? "" : String(v);
1527
+ var str2 = (v) => v === void 0 || v === null ? "" : String(v);
1485
1528
  var strOrNull = (v) => v === void 0 || v === null ? null : String(v);
1486
1529
  var numOrNull = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
1487
1530
  var int = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
@@ -1498,22 +1541,22 @@ function toStep(row) {
1498
1541
  return {
1499
1542
  stepId: strOrNull(row["step_id"]),
1500
1543
  index: int(row["index"]),
1501
- action: str(row["action"]),
1502
- label: str(row["label"]),
1503
- summary: str(row["summary"]),
1544
+ action: str2(row["action"]),
1545
+ label: str2(row["label"]),
1546
+ summary: str2(row["summary"]),
1504
1547
  windowHours: numOrNull(row["window_hours"]),
1505
- state: str(row["state"]),
1548
+ state: str2(row["state"]),
1506
1549
  progress: toLoyaltyStepProgress(row["progress"]),
1507
1550
  raw: row
1508
1551
  };
1509
1552
  }
1510
1553
  function toCardReward(row) {
1511
1554
  return {
1512
- vaultEntryId: str(row["vault_entry_id"]),
1513
- rewardId: str(row["reward_id"]),
1514
- state: str(row["state"]),
1515
- unlockedAt: str(row["unlocked_at"]),
1516
- expiresAt: str(row["expires_at"]),
1555
+ vaultEntryId: str2(row["vault_entry_id"]),
1556
+ rewardId: str2(row["reward_id"]),
1557
+ state: str2(row["state"]),
1558
+ unlockedAt: str2(row["unlocked_at"]),
1559
+ expiresAt: str2(row["expires_at"]),
1517
1560
  redeemedAt: strOrNull(row["redeemed_at"]),
1518
1561
  codeMasked: strOrNull(row["code_masked"]),
1519
1562
  canRedeem: row["can_redeem"] === true,
@@ -1528,18 +1571,18 @@ function toLoyaltyCard(row) {
1528
1571
  const steps = rows(row["steps"]).map(toStep);
1529
1572
  return {
1530
1573
  cardVersion: passThrough(row["card_version"]),
1531
- mode: str(row["mode"]),
1574
+ mode: str2(row["mode"]),
1532
1575
  programId: strOrNull(row["program_id"]),
1533
1576
  questId: strOrNull(row["quest_id"]),
1534
1577
  questVersion: numOrNull(row["quest_version"]),
1535
1578
  campaignId: strOrNull(row["campaign_id"]),
1536
- title: str(row["title"]),
1537
- description: str(row["description"]),
1579
+ title: str2(row["title"]),
1580
+ description: str2(row["description"]),
1538
1581
  brand: { name: strOrNull(brand["name"]), logoUrl: strOrNull(brand["logo_url"]) },
1539
1582
  artUrl: strOrNull(row["art_url"]),
1540
1583
  reward: { rewardId: strOrNull(reward["reward_id"]), name: strOrNull(reward["name"]) },
1541
- orderMode: str(row["order_mode"]),
1542
- status: str(row["status"]),
1584
+ orderMode: str2(row["order_mode"]),
1585
+ status: str2(row["status"]),
1543
1586
  startsAt: strOrNull(row["starts_at"]),
1544
1587
  endsAt: strOrNull(row["ends_at"]),
1545
1588
  completionHours: numOrNull(row["completion_hours"]),
@@ -1626,23 +1669,6 @@ function toReportGameEventResult(raw, eventId) {
1626
1669
  };
1627
1670
  }
1628
1671
 
1629
- // src/shared/receipt-fields.ts
1630
- function creditFields(raw) {
1631
- const c = raw["credited"];
1632
- if (c === true) return { credited: true };
1633
- if (c === false) {
1634
- const r = raw["reason_code"];
1635
- return { credited: false, reasonCode: r == null ? null : String(r) };
1636
- }
1637
- return {};
1638
- }
1639
- function receiptFields(raw) {
1640
- const n = raw["receipt_number"];
1641
- if (typeof n !== "string" || n === "") return {};
1642
- const u = raw["receipt_url"];
1643
- return typeof u === "string" && u !== "" ? { receiptNumber: n, receiptUrl: u } : { receiptNumber: n };
1644
- }
1645
-
1646
1672
  // src/shared/phone-change.ts
1647
1673
  function requireField(value, field, raw) {
1648
1674
  const s = value == null ? "" : String(value);
@@ -1656,16 +1682,16 @@ function requireField(value, field, raw) {
1656
1682
  }
1657
1683
  return s;
1658
1684
  }
1659
- var str2 = (v) => v == null ? "" : String(v);
1685
+ var str3 = (v) => v == null ? "" : String(v);
1660
1686
  var strOrNull2 = (v) => typeof v === "string" ? v : v == null ? null : String(v);
1661
1687
  function toRequestPhoneChangeResult(raw) {
1662
1688
  return {
1663
1689
  changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
1664
1690
  status: requireField(raw["status"], "status", raw),
1665
- expiresAt: str2(raw["expires_at"]),
1666
- delivery: str2(raw["delivery"]),
1667
- confirmation: str2(raw["confirmation"]),
1668
- message: str2(raw["message"]),
1691
+ expiresAt: str3(raw["expires_at"]),
1692
+ delivery: str3(raw["delivery"]),
1693
+ confirmation: str3(raw["confirmation"]),
1694
+ message: str3(raw["message"]),
1669
1695
  raw
1670
1696
  };
1671
1697
  }
@@ -1673,8 +1699,8 @@ function toPhoneChangeRequest(raw) {
1673
1699
  return {
1674
1700
  changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
1675
1701
  status: requireField(raw["status"], "status", raw),
1676
- confirmation: str2(raw["confirmation"]),
1677
- delivery: str2(raw["delivery"]),
1702
+ confirmation: str3(raw["confirmation"]),
1703
+ delivery: str3(raw["delivery"]),
1678
1704
  newPhoneMasked: strOrNull2(raw["new_phone_masked"]),
1679
1705
  createdAt: strOrNull2(raw["created_at"]),
1680
1706
  expiresAt: strOrNull2(raw["expires_at"]),
@@ -1685,7 +1711,7 @@ function toPhoneChangeRequest(raw) {
1685
1711
  }
1686
1712
 
1687
1713
  // src/version.ts
1688
- var SDK_VERSION = "3.30.0";
1714
+ var SDK_VERSION = "3.30.2";
1689
1715
 
1690
1716
  // src/payouts.ts
1691
1717
  var AMOUNT = /^\d+(\.\d{1,2})?$/;
@@ -4067,6 +4093,25 @@ var InvoServer = class {
4067
4093
  raw
4068
4094
  };
4069
4095
  }
4096
+ /**
4097
+ * Read a hosted checkout's status from INVO, server-side, with the session token that
4098
+ * {@link createCheckout} returned. Same answer as the browser's
4099
+ * `invo.checkout.getPurchaseStatus`. A game server uses it to confirm a purchase when
4100
+ * the signed webhook cannot reach it (for example a private development preview).
4101
+ * It is INVO's own record, read over TLS with the session credential, never the buyer's word.
4102
+ */
4103
+ async getCheckoutStatus(input, opts) {
4104
+ const sessionId = String(input?.sessionId ?? "").trim();
4105
+ const sessionToken = String(input?.sessionToken ?? "").trim();
4106
+ if (!sessionId) throw invalidInput2("sessionId", input?.sessionId, "is required");
4107
+ if (!sessionToken) throw invalidInput2("sessionToken", "(hidden)", "is required");
4108
+ const raw = await this.http.get(
4109
+ `/api/checkout/sessions/${encodeURIComponent(sessionId)}`,
4110
+ { kind: "bearer", token: sessionToken },
4111
+ { signal: opts?.signal }
4112
+ );
4113
+ return toPurchaseStatusResult(raw, sessionId);
4114
+ }
4070
4115
  /**
4071
4116
  * Direct purchase via the rail selector. Use when you need a specific rail.
4072
4117
  * - rail "platform" (default): standard card. May return status "requires_action"
@@ -4074,7 +4119,7 @@ var InvoServer = class {
4074
4119
  * - rail "game": returns status "pending_payment" + paymentUrl (redirect the browser).
4075
4120
  * - rail "steam": NOT a browser flow — the backend returns WRONG_RAIL_ENDPOINT.
4076
4121
  *
4077
- * INVO's card fee (3.5% + $0.30 on Open, 5.5% + $0.50 on Merchant of Record, plus 1.5% of
4122
+ * INVO's card fee (3.5% + $0.15 on Open, 5.0% + $0.15 on Merchant of Record, plus 1.5% of
4078
4123
  * the listed price (before tax) on a card issued outside the US) is charged to you, the partner. The player
4079
4124
  * pays the listed price (plus any tax) and receives the listed coins. Card purchases only;
4080
4125
  * purchases through a third-party storefront or payment rail are unaffected. Two shapes,
@@ -4163,7 +4208,7 @@ var InvoServer = class {
4163
4208
  *
4164
4209
  * The player pays the listed price plus any tax (when you pass `country`) and receives the
4165
4210
  * listed coins: `totalUsd` carries no card fee, and `processingFeeUsd` is `"0.00"`. INVO's
4166
- * card fee (3.5% + $0.30 on Open, 5.5% + $0.50 on Merchant of Record) is charged to you;
4211
+ * card fee (3.5% + $0.15 on Open, 5.0% + $0.15 on Merchant of Record) is charged to you;
4167
4212
  * `partnerFeeUsd` carries it when INVO sends it. $10.00 quotes a $10.00 total, 100.00 coins
4168
4213
  * at the default 10 per USD, and a $0.65 partner fee on Open. Show the player `totalUsd`,
4169
4214
  * then send the same figure back as `acknowledgedTotalUsd` on {@link purchaseCurrency}; the
@@ -5702,6 +5747,7 @@ function createInvoGameServer(options) {
5702
5747
  playerId: player.id,
5703
5748
  packId: pack.id,
5704
5749
  sessionId: session.sessionId,
5750
+ invoSessionToken: session.sessionToken || void 0,
5705
5751
  status: "pending",
5706
5752
  credited: null,
5707
5753
  orderId: null,
@@ -5715,8 +5761,9 @@ function createInvoGameServer(options) {
5715
5761
  }
5716
5762
  async function purchaseStatus(request, ref) {
5717
5763
  const { player } = await sessionPlayer(request);
5718
- const p = await store.read((s) => s.purchases[ref] ?? null);
5764
+ let p = await store.read((s) => s.purchases[ref] ?? null);
5719
5765
  if (!p || p.playerId !== player.id) throw new GameServerError(404, "PURCHASE_NOT_FOUND", "No such purchase.");
5766
+ if (p.status === "pending") p = await confirmFromInvo(p) ?? p;
5720
5767
  const out = {
5721
5768
  purchaseRef: p.purchaseRef,
5722
5769
  packId: p.packId,
@@ -5727,6 +5774,37 @@ function createInvoGameServer(options) {
5727
5774
  };
5728
5775
  return json(200, out);
5729
5776
  }
5777
+ async function confirmFromInvo(p) {
5778
+ if (!p.sessionId || !p.invoSessionToken) return null;
5779
+ let result;
5780
+ try {
5781
+ result = await invo.getCheckoutStatus({ sessionId: p.sessionId, sessionToken: p.invoSessionToken });
5782
+ } catch (err) {
5783
+ log("warn", "checkout status read failed", { code: err instanceof InvoError ? err.code : "ERROR" });
5784
+ return null;
5785
+ }
5786
+ if (!result.terminal) return null;
5787
+ const at = iso();
5788
+ return store.transact((s) => {
5789
+ const purchase = s.purchases[p.purchaseRef];
5790
+ if (!purchase || purchase.status !== "pending") return purchase ?? null;
5791
+ if (result.status === "credited") {
5792
+ const amount = toNumber(result.coinsCredited) ?? 0;
5793
+ const orderId = result.orderId ?? "";
5794
+ const ref = `order:${orderId}`;
5795
+ if (orderId && !s.ledgerRefs[ref]) {
5796
+ addLedger(s, { playerId: purchase.playerId, currency: "premium", amount, reason: "premium purchase (INVO, confirmed by status)", ref, at });
5797
+ }
5798
+ purchase.status = "credited";
5799
+ purchase.credited = amount;
5800
+ purchase.orderId = orderId || null;
5801
+ } else {
5802
+ purchase.status = "failed";
5803
+ }
5804
+ purchase.updatedAt = at;
5805
+ return purchase;
5806
+ });
5807
+ }
5730
5808
  async function webhook(request) {
5731
5809
  const raw = await readText(request);
5732
5810
  let event;
@@ -6100,7 +6178,7 @@ function createInvoGameServer(options) {
6100
6178
  const { player } = await sessionPlayer(request);
6101
6179
  const move = await store.read((s) => s.demoMoves?.[id] ?? null);
6102
6180
  if (!move || move.fromPlayerId !== player.id) throw new GameServerError(404, "TRANSFER_NOT_FOUND", "That transfer isn't yours to approve.");
6103
- if (move.status !== "started") return json(200, { status: "approved", claimCode: move.claimCode, replayed: true });
6181
+ if (move.status !== "started") return json(200, { status: "approved", claimCode: null, replayed: true });
6104
6182
  try {
6105
6183
  const approved = await invo.sandbox.approveDemoMove(id, move.kind);
6106
6184
  await store.transact((s) => {
@@ -6112,7 +6190,7 @@ function createInvoGameServer(options) {
6112
6190
  }
6113
6191
  });
6114
6192
  log("info", "demo transfer approved", { kind: move.kind, playerId: player.id, transactionId: id });
6115
- return json(200, { status: "approved", claimCode: approved.claimCode, replayed: false });
6193
+ return json(200, { status: "approved", claimCode: null, replayed: false });
6116
6194
  } catch (err) {
6117
6195
  if (err instanceof InvoError) throw fromInvoError(err);
6118
6196
  throw err;
@@ -1,9 +1,9 @@
1
- import { I as InvoServer, a as InvoEnvironment } from './server-DEh9wjF2.cjs';
2
- export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-DEh9wjF2.cjs';
1
+ import { I as InvoServer, a as InvoEnvironment } from './server-4EjDN-L5.cjs';
2
+ export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-4EjDN-L5.cjs';
3
3
  import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-jUxfYjiD.cjs';
4
4
  export { c as GameCatalog, d as GameCatalogItem, e as GameCheckout, f as GameCurrencyBalance, g as GameErrorBody, h as GameItemPurchase, i as GamePlayer, j as GamePremiumPack, k as GamePurchase, l as GameSession, m as GameTransferInput, n as GameTransferKind, o as GameTransferStart, p as GameTransferStatus, q as GameWallet } from './types-jUxfYjiD.cjs';
5
- export { I as InvoError } from './types-BTbZicgj.cjs';
6
- export { S as SDK_VERSION } from './version-DfVkILOj.cjs';
5
+ export { I as InvoError } from './types-D_NgeTKV.cjs';
6
+ export { S as SDK_VERSION } from './version-ENZ-BpKg.cjs';
7
7
  import './loyalty-events-CmDw2ZoR.cjs';
8
8
 
9
9
  interface StoredPlayer {
@@ -38,6 +38,8 @@ interface StoredPurchase {
38
38
  playerId: string;
39
39
  packId: string;
40
40
  sessionId: string;
41
+ /** INVO's checkout session token, kept on the server to confirm the purchase if the webhook can't arrive. */
42
+ invoSessionToken?: string;
41
43
  status: GamePurchaseStatus;
42
44
  credited: number | null;
43
45
  orderId: string | null;
@@ -1,9 +1,9 @@
1
- import { I as InvoServer, a as InvoEnvironment } from './server-B0mvlGFY.js';
2
- export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-B0mvlGFY.js';
1
+ import { I as InvoServer, a as InvoEnvironment } from './server-Brl2YvfT.js';
2
+ export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-Brl2YvfT.js';
3
3
  import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-jUxfYjiD.js';
4
4
  export { c as GameCatalog, d as GameCatalogItem, e as GameCheckout, f as GameCurrencyBalance, g as GameErrorBody, h as GameItemPurchase, i as GamePlayer, j as GamePremiumPack, k as GamePurchase, l as GameSession, m as GameTransferInput, n as GameTransferKind, o as GameTransferStart, p as GameTransferStatus, q as GameWallet } from './types-jUxfYjiD.js';
5
- export { I as InvoError } from './types-BTbZicgj.js';
6
- export { S as SDK_VERSION } from './version-DfVkILOj.js';
5
+ export { I as InvoError } from './types-D_NgeTKV.js';
6
+ export { S as SDK_VERSION } from './version-ENZ-BpKg.js';
7
7
  import './loyalty-events-CmDw2ZoR.js';
8
8
 
9
9
  interface StoredPlayer {
@@ -38,6 +38,8 @@ interface StoredPurchase {
38
38
  playerId: string;
39
39
  packId: string;
40
40
  sessionId: string;
41
+ /** INVO's checkout session token, kept on the server to confirm the purchase if the webhook can't arrive. */
42
+ invoSessionToken?: string;
41
43
  status: GamePurchaseStatus;
42
44
  credited: number | null;
43
45
  orderId: string | null;
@@ -1,8 +1,8 @@
1
- import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-664RAO2T.js';
2
- export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-664RAO2T.js';
3
- export { SDK_VERSION } from './chunk-BIK6UXY7.js';
4
- import { InvoError } from './chunk-TSTP2CWA.js';
5
- export { InvoError } from './chunk-TSTP2CWA.js';
1
+ import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-PED5RLYP.js';
2
+ export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-PED5RLYP.js';
3
+ export { SDK_VERSION } from './chunk-EJR7SOQK.js';
4
+ import { InvoError } from './chunk-TCT2QSVB.js';
5
+ export { InvoError } from './chunk-TCT2QSVB.js';
6
6
  import { createHash, randomBytes } from 'crypto';
7
7
  import { promises, readFileSync, mkdirSync, writeFileSync } from 'fs';
8
8
  import * as path from 'path';
@@ -406,6 +406,7 @@ function createInvoGameServer(options) {
406
406
  playerId: player.id,
407
407
  packId: pack.id,
408
408
  sessionId: session.sessionId,
409
+ invoSessionToken: session.sessionToken || void 0,
409
410
  status: "pending",
410
411
  credited: null,
411
412
  orderId: null,
@@ -419,8 +420,9 @@ function createInvoGameServer(options) {
419
420
  }
420
421
  async function purchaseStatus(request, ref) {
421
422
  const { player } = await sessionPlayer(request);
422
- const p = await store.read((s) => s.purchases[ref] ?? null);
423
+ let p = await store.read((s) => s.purchases[ref] ?? null);
423
424
  if (!p || p.playerId !== player.id) throw new GameServerError(404, "PURCHASE_NOT_FOUND", "No such purchase.");
425
+ if (p.status === "pending") p = await confirmFromInvo(p) ?? p;
424
426
  const out = {
425
427
  purchaseRef: p.purchaseRef,
426
428
  packId: p.packId,
@@ -431,6 +433,37 @@ function createInvoGameServer(options) {
431
433
  };
432
434
  return json(200, out);
433
435
  }
436
+ async function confirmFromInvo(p) {
437
+ if (!p.sessionId || !p.invoSessionToken) return null;
438
+ let result;
439
+ try {
440
+ result = await invo.getCheckoutStatus({ sessionId: p.sessionId, sessionToken: p.invoSessionToken });
441
+ } catch (err) {
442
+ log("warn", "checkout status read failed", { code: err instanceof InvoError ? err.code : "ERROR" });
443
+ return null;
444
+ }
445
+ if (!result.terminal) return null;
446
+ const at = iso();
447
+ return store.transact((s) => {
448
+ const purchase = s.purchases[p.purchaseRef];
449
+ if (!purchase || purchase.status !== "pending") return purchase ?? null;
450
+ if (result.status === "credited") {
451
+ const amount = toNumber(result.coinsCredited) ?? 0;
452
+ const orderId = result.orderId ?? "";
453
+ const ref = `order:${orderId}`;
454
+ if (orderId && !s.ledgerRefs[ref]) {
455
+ addLedger(s, { playerId: purchase.playerId, currency: "premium", amount, reason: "premium purchase (INVO, confirmed by status)", ref, at });
456
+ }
457
+ purchase.status = "credited";
458
+ purchase.credited = amount;
459
+ purchase.orderId = orderId || null;
460
+ } else {
461
+ purchase.status = "failed";
462
+ }
463
+ purchase.updatedAt = at;
464
+ return purchase;
465
+ });
466
+ }
434
467
  async function webhook(request) {
435
468
  const raw = await readText(request);
436
469
  let event;
@@ -804,7 +837,7 @@ function createInvoGameServer(options) {
804
837
  const { player } = await sessionPlayer(request);
805
838
  const move = await store.read((s) => s.demoMoves?.[id] ?? null);
806
839
  if (!move || move.fromPlayerId !== player.id) throw new GameServerError(404, "TRANSFER_NOT_FOUND", "That transfer isn't yours to approve.");
807
- if (move.status !== "started") return json(200, { status: "approved", claimCode: move.claimCode, replayed: true });
840
+ if (move.status !== "started") return json(200, { status: "approved", claimCode: null, replayed: true });
808
841
  try {
809
842
  const approved = await invo.sandbox.approveDemoMove(id, move.kind);
810
843
  await store.transact((s) => {
@@ -816,7 +849,7 @@ function createInvoGameServer(options) {
816
849
  }
817
850
  });
818
851
  log("info", "demo transfer approved", { kind: move.kind, playerId: player.id, transactionId: id });
819
- return json(200, { status: "approved", claimCode: approved.claimCode, replayed: false });
852
+ return json(200, { status: "approved", claimCode: null, replayed: false });
820
853
  } catch (err) {
821
854
  if (err instanceof InvoError) throw fromInvoError(err);
822
855
  throw err;
package/dist/game.cjs CHANGED
@@ -4582,7 +4582,7 @@ function mountInvoUI(container, economy, options = {}) {
4582
4582
  seg.hidden = g.thisGame;
4583
4583
  if (g.thisGame) draft.kind = "send";
4584
4584
  const range = g.minimumTransfer && g.maximumTransfer ? `${g.minimumTransfer} to ${g.maximumTransfer} per transfer. ` : "";
4585
- limits.textContent = g.thisGame ? `To another player of this game. INVO's network fee is 10%.` : `${g.gameName} accepts ${range}INVO's network fee is 10%.` + (status.demo ? ` In this demo, ${g.gameName} can't collect it, so it's refunded after 24 hours.` : "");
4585
+ limits.textContent = g.thisGame ? `To another player of this game. INVO's network fee is 10%.` : `${g.gameName} accepts ${range}INVO's network fee is 10%.` + (status.demo ? ` In this demo it's delivered to ${g.gameName} automatically once you approve.` : "");
4586
4586
  };
4587
4587
  game.onchange = () => {
4588
4588
  const was = draft.kind;
@@ -4668,7 +4668,7 @@ function mountInvoUI(container, economy, options = {}) {
4668
4668
  donePane(
4669
4669
  pane,
4670
4670
  draft.kind === "send" ? "Sent" : "Transferred",
4671
- game.thisGame ? `${what} is on its way. Your friend collects it from Transfer \u2192 Collect.` : `${what} is on its way. Your friend collects it in ${game.gameName}.`,
4671
+ game.thisGame ? `${what} is on its way. Your friend collects it from Transfer \u2192 Collect.` : status.demo ? `${what} has been delivered to ${game.gameName}.` : `${what} is on its way. Your friend collects it in ${game.gameName}.`,
4672
4672
  // The demo collects with the claim code on the server; only a real transfer needs it shown.
4673
4673
  status.approval === "sandbox" ? null : claim
4674
4674
  );
@@ -4833,7 +4833,7 @@ function mountInvoUI(container, economy, options = {}) {
4833
4833
  }
4834
4834
 
4835
4835
  // src/version.ts
4836
- var SDK_VERSION = "3.30.0";
4836
+ var SDK_VERSION = "3.30.2";
4837
4837
 
4838
4838
  exports.InvoGameEconomy = InvoGameEconomy;
4839
4839
  exports.InvoGameError = InvoGameError;
package/dist/game.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as GamePlayer, q as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, n as GameTransferKind, d as GameCatalogItem, f as GameCurrencyBalance, p as GameTransferStatus, m as GameTransferInput, o as GameTransferStart } from './types-jUxfYjiD.cjs';
2
2
  export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-jUxfYjiD.cjs';
3
- import { A as ApproveHostedResult } from './hosted-approval-DcY4U2RN.cjs';
4
- import { D as DestinationGame, P as PendingCollectItem } from './types-BTbZicgj.cjs';
5
- export { S as SDK_VERSION } from './version-DfVkILOj.cjs';
3
+ import { A as ApproveHostedResult } from './hosted-approval-P5ddmN-J.cjs';
4
+ import { D as DestinationGame, P as PendingCollectItem } from './types-D_NgeTKV.cjs';
5
+ export { S as SDK_VERSION } from './version-ENZ-BpKg.cjs';
6
6
 
7
7
  /**
8
8
  * INVO game economy client (3.27.0), the browser half. It talks ONLY to your game server
package/dist/game.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as GamePlayer, q as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, n as GameTransferKind, d as GameCatalogItem, f as GameCurrencyBalance, p as GameTransferStatus, m as GameTransferInput, o as GameTransferStart } from './types-jUxfYjiD.js';
2
2
  export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-jUxfYjiD.js';
3
- import { A as ApproveHostedResult } from './hosted-approval-DiKmtjEh.js';
4
- import { D as DestinationGame, P as PendingCollectItem } from './types-BTbZicgj.js';
5
- export { S as SDK_VERSION } from './version-DfVkILOj.js';
3
+ import { A as ApproveHostedResult } from './hosted-approval-C3SWGsVT.js';
4
+ import { D as DestinationGame, P as PendingCollectItem } from './types-D_NgeTKV.js';
5
+ export { S as SDK_VERSION } from './version-ENZ-BpKg.js';
6
6
 
7
7
  /**
8
8
  * INVO game economy client (3.27.0), the browser half. It talks ONLY to your game server
package/dist/game.js CHANGED
@@ -1,6 +1,6 @@
1
- import { InvoClient } from './chunk-QDHOPJFL.js';
2
- export { SDK_VERSION } from './chunk-BIK6UXY7.js';
3
- import { newEventId } from './chunk-TSTP2CWA.js';
1
+ import { InvoClient } from './chunk-7O5JT3LK.js';
2
+ export { SDK_VERSION } from './chunk-EJR7SOQK.js';
3
+ import { newEventId } from './chunk-TCT2QSVB.js';
4
4
 
5
5
  // src/game/client.ts
6
6
  var InvoGameError = class extends Error {
@@ -1337,7 +1337,7 @@ function mountInvoUI(container, economy, options = {}) {
1337
1337
  seg.hidden = g.thisGame;
1338
1338
  if (g.thisGame) draft.kind = "send";
1339
1339
  const range = g.minimumTransfer && g.maximumTransfer ? `${g.minimumTransfer} to ${g.maximumTransfer} per transfer. ` : "";
1340
- limits.textContent = g.thisGame ? `To another player of this game. INVO's network fee is 10%.` : `${g.gameName} accepts ${range}INVO's network fee is 10%.` + (status.demo ? ` In this demo, ${g.gameName} can't collect it, so it's refunded after 24 hours.` : "");
1340
+ limits.textContent = g.thisGame ? `To another player of this game. INVO's network fee is 10%.` : `${g.gameName} accepts ${range}INVO's network fee is 10%.` + (status.demo ? ` In this demo it's delivered to ${g.gameName} automatically once you approve.` : "");
1341
1341
  };
1342
1342
  game.onchange = () => {
1343
1343
  const was = draft.kind;
@@ -1423,7 +1423,7 @@ function mountInvoUI(container, economy, options = {}) {
1423
1423
  donePane(
1424
1424
  pane,
1425
1425
  draft.kind === "send" ? "Sent" : "Transferred",
1426
- game.thisGame ? `${what} is on its way. Your friend collects it from Transfer \u2192 Collect.` : `${what} is on its way. Your friend collects it in ${game.gameName}.`,
1426
+ game.thisGame ? `${what} is on its way. Your friend collects it from Transfer \u2192 Collect.` : status.demo ? `${what} has been delivered to ${game.gameName}.` : `${what} is on its way. Your friend collects it in ${game.gameName}.`,
1427
1427
  // The demo collects with the claim code on the server; only a real transfer needs it shown.
1428
1428
  status.approval === "sandbox" ? null : claim
1429
1429
  );
@@ -1,4 +1,4 @@
1
- import { A as ApproveResult, j as ConfirmReceiptResult } from './types-BTbZicgj.js';
1
+ import { A as ApproveResult, j as ConfirmReceiptResult } from './types-D_NgeTKV.js';
2
2
 
3
3
  /** The four device-approval flows (`begin.flow`). */
4
4
  type HostedFlow = "transfer" | "send" | "send_receipt" | "transfer_receipt";
@@ -1,4 +1,4 @@
1
- import { A as ApproveResult, j as ConfirmReceiptResult } from './types-BTbZicgj.cjs';
1
+ import { A as ApproveResult, j as ConfirmReceiptResult } from './types-D_NgeTKV.cjs';
2
2
 
3
3
  /** The four device-approval flows (`begin.flow`). */
4
4
  type HostedFlow = "transfer" | "send" | "send_receipt" | "transfer_receipt";
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as PurchaseStatusResult, b as PurchaseCredited, c as PurchaseExpired, d as PurchaseRefunded, e as PurchaseRefused, C as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, A as ApproveResult, j as ConfirmReceiptResult, k as PhoneChangeApprovalsResult, l as ApprovePhoneChangeInput, m as ApprovePhoneChangeResult, L as LinkDeviceResult, n as PendingCollectResult, o as DestinationsQuery, p as DestinationsResult, B as BalanceResult, q as LoyaltyCardsResult, r as LoyaltyVaultResult, R as RedeemRewardResult, s as RewardsPageLink, E as EnrollmentBeginResult, t as EnrollmentVerifyResult, u as RecoveryBeginResult, v as RecoveryCompleteResult } from './types-BTbZicgj.cjs';
2
- export { w as BalanceRow, x as CheckoutPurchaseStatus, y as ClaimDelivery, D as DestinationGame, I as InvoError, z as InvoErrorInfo, F as InvoHooks, G as InvoRequestInfo, J as InvoResponseInfo, K as LoyaltyCard, N as LoyaltyCardReward, O as LoyaltyCardStep, Q as LoyaltyRewardState, S as LoyaltyStepProgress, T as LoyaltyStepState, U as LoyaltyVaultEntry, P as PendingCollectItem, V as PhoneChangeApproval, X as PhoneChangeDeviceSignal, Y as PurchaseRefusalReason, Z as Rail, _ as VerificationMethod } from './types-BTbZicgj.cjs';
3
- import { a as ApproveHostedOptions, A as ApproveHostedResult } from './hosted-approval-DcY4U2RN.cjs';
4
- export { E as EnrollmentDecision, b as EnrollmentRespond, H as HostedApprovalStatus, c as HostedEnrollment, d as HostedEnrollmentInput, e as HostedFlow } from './hosted-approval-DcY4U2RN.cjs';
1
+ import { a as PurchaseStatusResult, b as PurchaseCredited, c as PurchaseExpired, d as PurchaseRefunded, e as PurchaseRefused, C as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, A as ApproveResult, j as ConfirmReceiptResult, k as PhoneChangeApprovalsResult, l as ApprovePhoneChangeInput, m as ApprovePhoneChangeResult, L as LinkDeviceResult, n as PendingCollectResult, o as DestinationsQuery, p as DestinationsResult, B as BalanceResult, q as LoyaltyCardsResult, r as LoyaltyVaultResult, R as RedeemRewardResult, s as RewardsPageLink, E as EnrollmentBeginResult, t as EnrollmentVerifyResult, u as RecoveryBeginResult, v as RecoveryCompleteResult } from './types-D_NgeTKV.cjs';
2
+ export { w as BalanceRow, x as CheckoutPurchaseStatus, y as ClaimDelivery, D as DestinationGame, I as InvoError, z as InvoErrorInfo, F as InvoHooks, G as InvoRequestInfo, J as InvoResponseInfo, K as LoyaltyCard, N as LoyaltyCardReward, O as LoyaltyCardStep, Q as LoyaltyRewardState, S as LoyaltyStepProgress, T as LoyaltyStepState, U as LoyaltyVaultEntry, P as PendingCollectItem, V as PhoneChangeApproval, X as PhoneChangeDeviceSignal, Y as PurchaseRefusalReason, Z as Rail, _ as VerificationMethod } from './types-D_NgeTKV.cjs';
3
+ import { a as ApproveHostedOptions, A as ApproveHostedResult } from './hosted-approval-P5ddmN-J.cjs';
4
+ export { E as EnrollmentDecision, b as EnrollmentRespond, H as HostedApprovalStatus, c as HostedEnrollment, d as HostedEnrollmentInput, e as HostedFlow } from './hosted-approval-P5ddmN-J.cjs';
5
5
  import { R as ReportGameEventInput, a as ReportGameEventResult } from './loyalty-events-CmDw2ZoR.cjs';
6
6
  export { G as GameEventType } from './loyalty-events-CmDw2ZoR.cjs';
7
7
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as PurchaseStatusResult, b as PurchaseCredited, c as PurchaseExpired, d as PurchaseRefunded, e as PurchaseRefused, C as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, A as ApproveResult, j as ConfirmReceiptResult, k as PhoneChangeApprovalsResult, l as ApprovePhoneChangeInput, m as ApprovePhoneChangeResult, L as LinkDeviceResult, n as PendingCollectResult, o as DestinationsQuery, p as DestinationsResult, B as BalanceResult, q as LoyaltyCardsResult, r as LoyaltyVaultResult, R as RedeemRewardResult, s as RewardsPageLink, E as EnrollmentBeginResult, t as EnrollmentVerifyResult, u as RecoveryBeginResult, v as RecoveryCompleteResult } from './types-BTbZicgj.js';
2
- export { w as BalanceRow, x as CheckoutPurchaseStatus, y as ClaimDelivery, D as DestinationGame, I as InvoError, z as InvoErrorInfo, F as InvoHooks, G as InvoRequestInfo, J as InvoResponseInfo, K as LoyaltyCard, N as LoyaltyCardReward, O as LoyaltyCardStep, Q as LoyaltyRewardState, S as LoyaltyStepProgress, T as LoyaltyStepState, U as LoyaltyVaultEntry, P as PendingCollectItem, V as PhoneChangeApproval, X as PhoneChangeDeviceSignal, Y as PurchaseRefusalReason, Z as Rail, _ as VerificationMethod } from './types-BTbZicgj.js';
3
- import { a as ApproveHostedOptions, A as ApproveHostedResult } from './hosted-approval-DiKmtjEh.js';
4
- export { E as EnrollmentDecision, b as EnrollmentRespond, H as HostedApprovalStatus, c as HostedEnrollment, d as HostedEnrollmentInput, e as HostedFlow } from './hosted-approval-DiKmtjEh.js';
1
+ import { a as PurchaseStatusResult, b as PurchaseCredited, c as PurchaseExpired, d as PurchaseRefunded, e as PurchaseRefused, C as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, A as ApproveResult, j as ConfirmReceiptResult, k as PhoneChangeApprovalsResult, l as ApprovePhoneChangeInput, m as ApprovePhoneChangeResult, L as LinkDeviceResult, n as PendingCollectResult, o as DestinationsQuery, p as DestinationsResult, B as BalanceResult, q as LoyaltyCardsResult, r as LoyaltyVaultResult, R as RedeemRewardResult, s as RewardsPageLink, E as EnrollmentBeginResult, t as EnrollmentVerifyResult, u as RecoveryBeginResult, v as RecoveryCompleteResult } from './types-D_NgeTKV.js';
2
+ export { w as BalanceRow, x as CheckoutPurchaseStatus, y as ClaimDelivery, D as DestinationGame, I as InvoError, z as InvoErrorInfo, F as InvoHooks, G as InvoRequestInfo, J as InvoResponseInfo, K as LoyaltyCard, N as LoyaltyCardReward, O as LoyaltyCardStep, Q as LoyaltyRewardState, S as LoyaltyStepProgress, T as LoyaltyStepState, U as LoyaltyVaultEntry, P as PendingCollectItem, V as PhoneChangeApproval, X as PhoneChangeDeviceSignal, Y as PurchaseRefusalReason, Z as Rail, _ as VerificationMethod } from './types-D_NgeTKV.js';
3
+ import { a as ApproveHostedOptions, A as ApproveHostedResult } from './hosted-approval-C3SWGsVT.js';
4
+ export { E as EnrollmentDecision, b as EnrollmentRespond, H as HostedApprovalStatus, c as HostedEnrollment, d as HostedEnrollmentInput, e as HostedFlow } from './hosted-approval-C3SWGsVT.js';
5
5
  import { R as ReportGameEventInput, a as ReportGameEventResult } from './loyalty-events-CmDw2ZoR.js';
6
6
  export { G as GameEventType } from './loyalty-events-CmDw2ZoR.js';
7
7
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { CheckoutClient, InvoClient, PlatformCommerceClient, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged } from './chunk-QDHOPJFL.js';
2
- export { InvoError, phoneChangeSignalMessage } from './chunk-TSTP2CWA.js';
1
+ export { CheckoutClient, InvoClient, PlatformCommerceClient } from './chunk-7O5JT3LK.js';
2
+ export { InvoError, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged, phoneChangeSignalMessage } from './chunk-TCT2QSVB.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map