@invonetwork/web-sdk 3.29.1 → 3.30.1

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +1442 -1397
  2. package/README.md +2954 -2923
  3. package/dist/chunk-3ECVREIM.js +6 -0
  4. package/dist/chunk-7O5JT3LK.js +1590 -0
  5. package/dist/{chunk-VP3OK4J4.js → chunk-TCT2QSVB.js} +515 -3
  6. package/dist/{chunk-YONO4JE5.js → chunk-V2RQYQQD.js} +44 -5
  7. package/dist/game-server.cjs +387 -42
  8. package/dist/game-server.d.cts +42 -6
  9. package/dist/game-server.d.ts +42 -6
  10. package/dist/game-server.js +286 -8
  11. package/dist/game.cjs +2677 -9
  12. package/dist/game.d.cts +78 -4
  13. package/dist/game.d.ts +78 -4
  14. package/dist/game.js +558 -3
  15. package/dist/hosted-approval-DcY4U2RN.d.cts +96 -0
  16. package/dist/hosted-approval-DiKmtjEh.d.ts +96 -0
  17. package/dist/index.d.cts +7 -96
  18. package/dist/index.d.ts +7 -96
  19. package/dist/index.js +2 -1635
  20. package/dist/loyalty-events-CmDw2ZoR.d.cts +40 -0
  21. package/dist/loyalty-events-CmDw2ZoR.d.ts +40 -0
  22. package/dist/{server-Bxo_wgHx.d.cts → server-BAOn3KH3.d.cts} +28 -2
  23. package/dist/{server-BYY6tM6X.d.ts → server-DHmQU1eN.d.ts} +28 -2
  24. package/dist/server.cjs +106 -40
  25. package/dist/server.d.cts +4 -3
  26. package/dist/server.d.ts +4 -3
  27. package/dist/server.js +3 -4
  28. package/dist/{types-_lIm74kd.d.cts → types-BTbZicgj.d.cts} +1 -40
  29. package/dist/{types-_lIm74kd.d.ts → types-BTbZicgj.d.ts} +1 -40
  30. package/dist/{types-CLyJDuXd.d.cts → types-jUxfYjiD.d.cts} +64 -1
  31. package/dist/{types-CLyJDuXd.d.ts → types-jUxfYjiD.d.ts} +64 -1
  32. package/dist/{version-DOaYbHu7.d.cts → version-CR7XECyP.d.cts} +1 -1
  33. package/dist/{version-DOaYbHu7.d.ts → version-CR7XECyP.d.ts} +1 -1
  34. package/package.json +91 -91
  35. package/dist/chunk-6CN236QH.js +0 -473
  36. package/dist/chunk-VOGZZ6QS.js +0 -6
@@ -1,9 +1,10 @@
1
- import { I as InvoServer, a as InvoEnvironment } from './server-BYY6tM6X.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-BYY6tM6X.js';
3
- import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-CLyJDuXd.js';
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 GameWallet } from './types-CLyJDuXd.js';
5
- export { I as InvoError } from './types-_lIm74kd.js';
6
- export { S as SDK_VERSION } from './version-DOaYbHu7.js';
1
+ import { I as InvoServer, a as InvoEnvironment } from './server-DHmQU1eN.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-DHmQU1eN.js';
3
+ import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-jUxfYjiD.js';
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-CR7XECyP.js';
7
+ import './loyalty-events-CmDw2ZoR.js';
7
8
 
8
9
  interface StoredPlayer {
9
10
  id: string;
@@ -37,6 +38,8 @@ interface StoredPurchase {
37
38
  playerId: string;
38
39
  packId: string;
39
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;
40
43
  status: GamePurchaseStatus;
41
44
  credited: number | null;
42
45
  orderId: string | null;
@@ -62,6 +65,29 @@ interface GameStoreState {
62
65
  inventory: Record<string, Record<string, number>>;
63
66
  /** Webhook idempotency key → time processed. */
64
67
  webhooks: Record<string, string>;
68
+ /**
69
+ * Public demo key only (3.30.0): sends and transfers between players of this project, by
70
+ * INVO transaction id. The server approves them in INVO's demo sandbox and keeps the claim
71
+ * code so the recipient can collect. Absent in stores written before 3.30.0.
72
+ */
73
+ demoMoves?: Record<string, StoredDemoMove>;
74
+ }
75
+ interface StoredDemoMove {
76
+ transactionId: string;
77
+ kind: "send" | "transfer";
78
+ fromPlayerId: string;
79
+ fromName: string;
80
+ /** The recipient's demo email (already mapped with `toDemoEmail`). */
81
+ toEmail: string;
82
+ amount: string;
83
+ currencyName: string;
84
+ /** True when it lands in this game, so a player of this game can collect it. */
85
+ sameGame: boolean;
86
+ destinationName: string;
87
+ status: "started" | "approved" | "collected";
88
+ claimCode: string | null;
89
+ claimCodeExpiresAt: string | null;
90
+ createdAt: string;
65
91
  }
66
92
  interface GameStore {
67
93
  /** Read a consistent snapshot. Do not mutate it. */
@@ -115,6 +141,16 @@ interface InvoGameServerOptions {
115
141
  * address or number ever reaches INVO. {@link invoGameServerFromEnv} sets it for you.
116
142
  */
117
143
  demoProjectId?: string;
144
+ /**
145
+ * Player-to-player transfers and sends (3.30.0). `"auto"` (the default) turns them on for
146
+ * the public demo key and in production, and off on other sandbox keys; `true` or `false`
147
+ * forces it. {@link invoGameServerFromEnv} reads `INVO_TRANSFERS` (`on`, `off`, `auto`).
148
+ */
149
+ transfers?: boolean | "auto";
150
+ /** Where the key's environment stands, for `transfers: "auto"`. Default: from `sandbox`. */
151
+ environment?: () => InvoEnvironment | "resolving";
152
+ /** INVO's API base for the browser's player-token calls, or null while unknown. */
153
+ playerApiBaseUrl?: () => string | null;
118
154
  }
119
155
  interface InvoGameServer {
120
156
  readonly basePath: string;
@@ -1,9 +1,8 @@
1
- import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-YONO4JE5.js';
2
- export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-YONO4JE5.js';
3
- import './chunk-6CN236QH.js';
4
- export { SDK_VERSION } from './chunk-VOGZZ6QS.js';
5
- import { InvoError } from './chunk-VP3OK4J4.js';
6
- export { InvoError } from './chunk-VP3OK4J4.js';
1
+ import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-V2RQYQQD.js';
2
+ export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-V2RQYQQD.js';
3
+ export { SDK_VERSION } from './chunk-3ECVREIM.js';
4
+ import { InvoError } from './chunk-TCT2QSVB.js';
5
+ export { InvoError } from './chunk-TCT2QSVB.js';
7
6
  import { createHash, randomBytes } from 'crypto';
8
7
  import { promises, readFileSync, mkdirSync, writeFileSync } from 'fs';
9
8
  import * as path from 'path';
@@ -150,6 +149,19 @@ var GameServerError = class extends Error {
150
149
  this.requestId = requestId;
151
150
  }
152
151
  };
152
+ function moveDetails(raw) {
153
+ const d = (raw?.["send_details"] ?? raw?.["transfer_details"] ?? {}) || {};
154
+ const pick = (...keys) => {
155
+ for (const k of keys) if (d[k] !== void 0 && d[k] !== null && d[k] !== "") return String(d[k]);
156
+ return null;
157
+ };
158
+ const toId = pick("receiving_game_id", "target_game_id");
159
+ const fromId = pick("sending_game_id", "source_game_id");
160
+ const toName = pick("receiving_game", "target_game", "target_game_name");
161
+ const fromName = pick("sending_game", "source_game", "source_game_name");
162
+ const sameGame = fromId !== null && toId !== null ? fromId === toId : toName !== null && toName === fromName;
163
+ return { sameGame, destinationName: toName, currencyName: pick("currency", "currency_name") ?? (typeof raw?.["currency_name"] === "string" ? raw["currency_name"] : null) };
164
+ }
153
165
  function validateEconomy(economy) {
154
166
  const problems = [];
155
167
  if (!economy?.premium?.name) problems.push("premium.name is required");
@@ -255,6 +267,7 @@ function createInvoGameServer(options) {
255
267
  maxPerMinute: economy.soft.maxEarnPerMinute ?? 1e4
256
268
  };
257
269
  const iso = () => now().toISOString();
270
+ const environmentNow = options.environment ?? (() => options.sandbox ? "sandbox" : "production");
258
271
  function toPlayer(p) {
259
272
  return { id: p.id, email: p.email, name: p.name, phoneMasked: maskPhone(p.phone) };
260
273
  }
@@ -393,6 +406,7 @@ function createInvoGameServer(options) {
393
406
  playerId: player.id,
394
407
  packId: pack.id,
395
408
  sessionId: session.sessionId,
409
+ invoSessionToken: session.sessionToken || void 0,
396
410
  status: "pending",
397
411
  credited: null,
398
412
  orderId: null,
@@ -406,8 +420,9 @@ function createInvoGameServer(options) {
406
420
  }
407
421
  async function purchaseStatus(request, ref) {
408
422
  const { player } = await sessionPlayer(request);
409
- const p = await store.read((s) => s.purchases[ref] ?? null);
423
+ let p = await store.read((s) => s.purchases[ref] ?? null);
410
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;
411
426
  const out = {
412
427
  purchaseRef: p.purchaseRef,
413
428
  packId: p.packId,
@@ -418,6 +433,37 @@ function createInvoGameServer(options) {
418
433
  };
419
434
  return json(200, out);
420
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
+ }
421
467
  async function webhook(request) {
422
468
  const raw = await readText(request);
423
469
  let event;
@@ -642,6 +688,223 @@ function createInvoGameServer(options) {
642
688
  throw err;
643
689
  }
644
690
  }
691
+ function transferStatus() {
692
+ const demo = !!options.demoProjectId;
693
+ const environment = environmentNow();
694
+ const setting = options.transfers ?? "auto";
695
+ let reason = null;
696
+ if (setting === false) reason = "off";
697
+ else if (setting === "auto" && !demo) {
698
+ if (environment === "resolving") reason = "checking";
699
+ else if (environment === "sandbox") reason = "sandbox";
700
+ }
701
+ return {
702
+ enabled: reason === null,
703
+ reason,
704
+ demo,
705
+ scope: demo ? "project" : "network",
706
+ recipientFields: demo ? { email: "required", phone: "hidden" } : { email: "optional", phone: "required" },
707
+ apiBaseUrl: reason === null ? options.playerApiBaseUrl?.() ?? null : null,
708
+ approval: demo ? "sandbox" : "passkey"
709
+ };
710
+ }
711
+ function requireTransfers() {
712
+ const status = transferStatus();
713
+ if (!status.enabled) {
714
+ throw new GameServerError(
715
+ 403,
716
+ "TRANSFERS_DISABLED",
717
+ status.reason === "sandbox" ? "Transfers are off on this sandbox key. Set INVO_TRANSFERS=on to try them, or use your production key." : status.reason === "checking" ? "Checking this game's INVO key. Try again in a moment." : "Transfers are switched off for this game."
718
+ );
719
+ }
720
+ return status;
721
+ }
722
+ async function transferToken(request) {
723
+ const status = requireTransfers();
724
+ const { player } = await sessionPlayer(request);
725
+ try {
726
+ const minted = await invo.mintPlayerToken({ playerEmail: player.email });
727
+ return json(200, { token: minted.token, expiresAt: minted.expiresAt, apiBaseUrl: status.apiBaseUrl }, { "cache-control": "no-store" });
728
+ } catch (err) {
729
+ if (err instanceof InvoError) throw fromInvoError(err);
730
+ throw err;
731
+ }
732
+ }
733
+ async function startTransfer(request) {
734
+ requireTransfers();
735
+ const { player } = await sessionPlayer(request);
736
+ const body = await readJson(request);
737
+ const kind = body["kind"] === "send" ? "send" : "transfer";
738
+ const amount = String(body["amount"] ?? "").trim();
739
+ if (!/^\d{1,9}(\.\d{1,2})?$/.test(amount) || Number(amount) <= 0) {
740
+ throw new GameServerError(400, "INVALID_AMOUNT", "Enter an amount greater than zero.");
741
+ }
742
+ const targetGameId = body["targetGameId"];
743
+ if ((typeof targetGameId !== "string" || !targetGameId.trim()) && typeof targetGameId !== "number") {
744
+ throw new GameServerError(400, "INVALID_GAME", "Pick a game to send to.");
745
+ }
746
+ const requestId = typeof body["clientRequestId"] === "string" ? body["clientRequestId"] : "";
747
+ if (requestId && !REQUEST_ID.test(requestId)) {
748
+ throw new GameServerError(400, "INVALID_REQUEST_ID", "clientRequestId must be 8 to 64 letters, digits, - or _.");
749
+ }
750
+ const clientRequestId = requestId || randomBytes(16).toString("hex");
751
+ const typedEmail = typeof body["recipientEmail"] === "string" ? body["recipientEmail"].trim().toLowerCase() : "";
752
+ if (typedEmail && !EMAIL.test(typedEmail)) throw new GameServerError(400, "INVALID_EMAIL", "Check the recipient's email address.");
753
+ let senderPhone;
754
+ let recipientEmail;
755
+ let recipientPhone;
756
+ const demoPid = options.demoProjectId;
757
+ if (demoPid) {
758
+ if (!typedEmail) {
759
+ throw new GameServerError(400, "RECIPIENT_EMAIL_REQUIRED", "Enter your friend's email: the one they sign in to this game with.");
760
+ }
761
+ recipientEmail = toDemoEmail(typedEmail, demoPid);
762
+ if (recipientEmail === player.email) throw new GameServerError(400, "RECIPIENT_IS_SENDER", "Pick someone other than yourself.");
763
+ recipientPhone = demoPhoneFor(recipientEmail);
764
+ senderPhone = demoPhoneFor(player.email);
765
+ } else {
766
+ recipientPhone = typeof body["recipientPhone"] === "string" ? body["recipientPhone"].replace(/[\s()-]/g, "") : "";
767
+ if (!E164.test(recipientPhone)) {
768
+ throw new GameServerError(400, "INVALID_PHONE", "Enter the recipient's phone in international format, e.g. +15555550111.");
769
+ }
770
+ recipientEmail = typedEmail || void 0;
771
+ const typedSender = typeof body["senderPhone"] === "string" ? body["senderPhone"].replace(/[\s()-]/g, "") : "";
772
+ senderPhone = typedSender || player.phone || "";
773
+ if (!E164.test(senderPhone)) throw new GameServerError(400, "SENDER_PHONE_REQUIRED", "Add the phone number on your INVO account to send.");
774
+ }
775
+ try {
776
+ const started = kind === "send" ? await invo.initiateSend({
777
+ clientRequestId,
778
+ senderPlayerName: player.name,
779
+ senderPlayerEmail: player.email,
780
+ senderPlayerPhone: senderPhone,
781
+ receiverPlayerPhone: recipientPhone,
782
+ ...recipientEmail ? { receiverPlayerEmail: recipientEmail } : {},
783
+ receivingGameId: targetGameId,
784
+ amount
785
+ }) : await invo.initiateTransfer({
786
+ clientRequestId,
787
+ sourcePlayerName: player.name,
788
+ sourcePlayerEmail: player.email,
789
+ sourcePlayerPhone: senderPhone,
790
+ targetPlayerPhone: recipientPhone,
791
+ ...recipientEmail ? { targetPlayerEmail: recipientEmail } : {},
792
+ targetGameId,
793
+ amount
794
+ });
795
+ log("info", "transfer started", { kind, playerId: player.id, transactionId: started.transactionId });
796
+ if (demoPid && recipientEmail) {
797
+ const details = moveDetails(started.raw);
798
+ const move = {
799
+ transactionId: started.transactionId,
800
+ kind,
801
+ fromPlayerId: player.id,
802
+ fromName: player.name,
803
+ toEmail: recipientEmail,
804
+ amount,
805
+ currencyName: details.currencyName ?? economy.premium.name,
806
+ sameGame: details.sameGame,
807
+ destinationName: details.destinationName ?? "",
808
+ status: "started",
809
+ claimCode: null,
810
+ claimCodeExpiresAt: null,
811
+ createdAt: iso()
812
+ };
813
+ await store.transact((s) => void ((s.demoMoves ?? (s.demoMoves = {}))[move.transactionId] = move));
814
+ }
815
+ const answer = {
816
+ transactionId: started.transactionId,
817
+ kind,
818
+ guardianPending: Boolean(started.guardianApproval),
819
+ playerToken: started.playerToken ?? null,
820
+ approval: demoPid ? "sandbox" : "passkey"
821
+ };
822
+ return json(200, answer, { "cache-control": "no-store" });
823
+ } catch (err) {
824
+ if (err instanceof InvoError) throw fromInvoError(err);
825
+ throw err;
826
+ }
827
+ }
828
+ function requireDemo() {
829
+ requireTransfers();
830
+ if (!options.demoProjectId) {
831
+ throw new GameServerError(409, "PASSKEY_REQUIRED", "Approve and collect on INVO's page with your passkey.");
832
+ }
833
+ return options.demoProjectId;
834
+ }
835
+ async function approveMove(request, id) {
836
+ requireDemo();
837
+ const { player } = await sessionPlayer(request);
838
+ const move = await store.read((s) => s.demoMoves?.[id] ?? null);
839
+ if (!move || move.fromPlayerId !== player.id) throw new GameServerError(404, "TRANSFER_NOT_FOUND", "That transfer isn't yours to approve.");
840
+ if (move.status !== "started") return json(200, { status: "approved", claimCode: null, replayed: true });
841
+ try {
842
+ const approved = await invo.sandbox.approveDemoMove(id, move.kind);
843
+ await store.transact((s) => {
844
+ const m = s.demoMoves?.[id];
845
+ if (m && m.status === "started") {
846
+ m.status = "approved";
847
+ m.claimCode = approved.claimCode;
848
+ m.claimCodeExpiresAt = approved.claimCodeExpiresAt;
849
+ }
850
+ });
851
+ log("info", "demo transfer approved", { kind: move.kind, playerId: player.id, transactionId: id });
852
+ return json(200, { status: "approved", claimCode: null, replayed: false });
853
+ } catch (err) {
854
+ if (err instanceof InvoError) throw fromInvoError(err);
855
+ throw err;
856
+ }
857
+ }
858
+ async function pendingMoves(request) {
859
+ requireDemo();
860
+ const { player } = await sessionPlayer(request);
861
+ const nowMs = now().getTime();
862
+ const moves = await store.read((s) => Object.values(s.demoMoves ?? {}));
863
+ const pending = moves.filter(
864
+ (m) => m.toEmail === player.email && m.status === "approved" && m.sameGame && (!m.claimCodeExpiresAt || Date.parse(m.claimCodeExpiresAt) > nowMs) || m.fromPlayerId === player.id && m.status === "started"
865
+ ).sort((a, b) => b.createdAt.localeCompare(a.createdAt)).map((m) => {
866
+ const incoming = m.toEmail === player.email;
867
+ return {
868
+ transferId: m.transactionId,
869
+ kind: incoming ? "receiving_confirm" : "identity_gate",
870
+ flow: m.kind,
871
+ amount: m.amount,
872
+ currency: m.currencyName,
873
+ counterpartyGame: incoming ? `${m.fromName}, in this game` : m.destinationName || "another game",
874
+ expiresAt: m.claimCodeExpiresAt,
875
+ stepUpRequired: false,
876
+ held: false,
877
+ holdReason: null,
878
+ raw: {}
879
+ };
880
+ });
881
+ return json(200, { pending }, { "cache-control": "no-store" });
882
+ }
883
+ async function collectMove(request, id) {
884
+ requireDemo();
885
+ const { player } = await sessionPlayer(request);
886
+ const move = await store.read((s) => s.demoMoves?.[id] ?? null);
887
+ if (!move || move.toEmail !== player.email) throw new GameServerError(404, "TRANSFER_NOT_FOUND", "There's nothing to collect with that id.");
888
+ if (move.status === "collected") return json(200, { status: "collected", replayed: true, wallet: await readWallet(player) });
889
+ if (move.status !== "approved" || !move.claimCode) throw new GameServerError(409, "NOT_APPROVED_YET", "The sender hasn't approved this one yet.");
890
+ if (!move.sameGame) throw new GameServerError(409, "OTHER_GAME", `This one is waiting in ${move.destinationName || "another game"}; collect it there.`);
891
+ try {
892
+ if (move.kind === "send") {
893
+ await invo.claimCurrency({ claimCode: move.claimCode, receiverPlayerName: player.name, receiverPlayerEmail: player.email, receiverPlayerPhone: demoPhoneFor(player.email) });
894
+ } else {
895
+ throw new GameServerError(409, "OTHER_GAME", "Collect this transfer in the game it was sent to.");
896
+ }
897
+ } catch (err) {
898
+ if (err instanceof InvoError) throw fromInvoError(err);
899
+ throw err;
900
+ }
901
+ await store.transact((s) => {
902
+ const m = s.demoMoves?.[id];
903
+ if (m) m.status = "collected";
904
+ });
905
+ log("info", "demo transfer collected", { kind: move.kind, playerId: player.id, transactionId: id });
906
+ return json(200, { status: "collected", replayed: false, wallet: await readWallet(player) });
907
+ }
645
908
  async function route(request, sub, method) {
646
909
  if (method === "GET" && sub === "/health") return json(200, { ok: true, setupRequired: false, sandbox: options.sandbox, demo: !!options.demoProjectId });
647
910
  if (method === "GET" && sub === "/catalog") return catalog();
@@ -659,6 +922,15 @@ function createInvoGameServer(options) {
659
922
  if (method === "POST" && sub === "/earn") return earn(request);
660
923
  if (method === "POST" && sub === "/events") return events(request);
661
924
  if (method === "GET" && sub === "/rewards") return rewards(request);
925
+ if (method === "GET" && sub === "/transfers/status") return json(200, transferStatus());
926
+ if (method === "POST" && sub === "/transfers/token") return transferToken(request);
927
+ if (method === "POST" && sub === "/transfers") return startTransfer(request);
928
+ if (method === "GET" && sub === "/transfers/pending") return pendingMoves(request);
929
+ const move = /^\/transfers\/([^/]+)\/(approve|collect)$/.exec(sub);
930
+ if (method === "POST" && move) {
931
+ const id = decodeURIComponent(move[1]);
932
+ return move[2] === "approve" ? approveMove(request, id) : collectMove(request, id);
933
+ }
662
934
  return json(404, { error: { code: "NOT_FOUND", message: "No such route." } });
663
935
  }
664
936
  return {
@@ -729,7 +1001,13 @@ function invoGameServerFromEnv(options) {
729
1001
  },
730
1002
  basePath: options.basePath,
731
1003
  publicUrl: env["PUBLIC_URL"] || void 0,
732
- log: options.log
1004
+ log: options.log,
1005
+ transfers: (() => {
1006
+ const t = env["INVO_TRANSFERS"]?.trim().toLowerCase();
1007
+ return t === "on" ? true : t === "off" ? false : "auto";
1008
+ })(),
1009
+ environment: envNow,
1010
+ playerApiBaseUrl: () => explicitBase || (state.environment === "production" ? PRODUCTION_BASE_URL : state.environment === "sandbox" ? SANDBOX_BASE_URL : null)
733
1011
  };
734
1012
  const server = createInvoGameServer(serverOptions);
735
1013
  return { server, missing, sandbox: sandboxNow(), environment: envNow(), demo };