@invonetwork/web-sdk 3.29.0 → 3.30.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +1432 -1389
  2. package/README.md +2954 -2923
  3. package/dist/{chunk-FJR44FKW.js → chunk-664RAO2T.js} +25 -5
  4. package/dist/chunk-BIK6UXY7.js +6 -0
  5. package/dist/chunk-QDHOPJFL.js +1634 -0
  6. package/dist/{chunk-VP3OK4J4.js → chunk-TSTP2CWA.js} +471 -3
  7. package/dist/game-server.cjs +295 -15
  8. package/dist/game-server.d.cts +49 -9
  9. package/dist/game-server.d.ts +49 -9
  10. package/dist/game-server.js +278 -20
  11. package/dist/game.cjs +2680 -9
  12. package/dist/game.d.cts +78 -4
  13. package/dist/game.d.ts +78 -4
  14. package/dist/game.js +561 -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-Dnx5jxS4.d.ts → server-B0mvlGFY.d.ts} +17 -2
  23. package/dist/{server-UZ38eD2p.d.cts → server-DEh9wjF2.d.cts} +17 -2
  24. package/dist/server.cjs +22 -1
  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.ts → types-BTbZicgj.d.cts} +1 -40
  29. package/dist/{types-_lIm74kd.d.cts → types-BTbZicgj.d.ts} +1 -40
  30. package/dist/{types-CoW9LopI.d.cts → types-jUxfYjiD.d.cts} +76 -1
  31. package/dist/{types-CoW9LopI.d.ts → types-jUxfYjiD.d.ts} +76 -1
  32. package/dist/{version-xyYQO5hp.d.cts → version-DfVkILOj.d.cts} +1 -1
  33. package/dist/{version-xyYQO5hp.d.ts → version-DfVkILOj.d.ts} +1 -1
  34. package/package.json +1 -1
  35. package/dist/chunk-6CN236QH.js +0 -473
  36. package/dist/chunk-KZJABBVT.js +0 -6
package/dist/game.js CHANGED
@@ -1,5 +1,6 @@
1
- export { SDK_VERSION } from './chunk-KZJABBVT.js';
2
- import { newEventId } from './chunk-VP3OK4J4.js';
1
+ import { InvoClient } from './chunk-QDHOPJFL.js';
2
+ export { SDK_VERSION } from './chunk-BIK6UXY7.js';
3
+ import { newEventId } from './chunk-TSTP2CWA.js';
3
4
 
4
5
  // src/game/client.ts
5
6
  var InvoGameError = class extends Error {
@@ -10,6 +11,15 @@ var InvoGameError = class extends Error {
10
11
  this.status = status;
11
12
  }
12
13
  };
14
+ var TRANSFERS_UNKNOWN = {
15
+ enabled: false,
16
+ reason: "checking",
17
+ demo: false,
18
+ scope: "network",
19
+ recipientFields: { email: "optional", phone: "required" },
20
+ apiBaseUrl: null,
21
+ approval: "passkey"
22
+ };
13
23
  var InvoGameEconomy = class {
14
24
  constructor(options = {}) {
15
25
  this.player = null;
@@ -22,6 +32,8 @@ var InvoGameEconomy = class {
22
32
  this.pendingEarn = 0;
23
33
  this.pendingEarnReason = "earned in play";
24
34
  this.earnTimer = null;
35
+ this.transferStatusCache = null;
36
+ this.transferClient = null;
25
37
  this.base = (options.baseUrl ?? "/api/invo").replace(/\/+$/, "");
26
38
  this.storage = options.storage === void 0 ? safeLocalStorage() : options.storage;
27
39
  this.storageKey = options.storageKey ?? "invo.game.session";
@@ -29,6 +41,7 @@ var InvoGameEconomy = class {
29
41
  this.earnFlushMs = options.earnFlushMs ?? 750;
30
42
  this.pollMs = options.purchasePollMs ?? 2e3;
31
43
  this.purchaseTimeoutMs = options.purchaseTimeoutMs ?? 15 * 60 * 1e3;
44
+ this.invoFetch = options.invoFetch;
32
45
  }
33
46
  /** Subscribe; returns the unsubscribe function. */
34
47
  on(type, listener) {
@@ -278,7 +291,146 @@ var InvoGameEconomy = class {
278
291
  return null;
279
292
  }
280
293
  }
294
+ // ---------------------------------------------------------------- transfers and sends (3.30.0)
295
+ /**
296
+ * Whether players can move currency to other players here, who can receive, and which
297
+ * recipient details to ask for. Cached; pass `true` to ask the server again.
298
+ */
299
+ transferStatus(refresh = false) {
300
+ if (!this.transferStatusCache || refresh) {
301
+ this.transferStatusCache = this.request("GET", "/transfers/status").catch(() => {
302
+ this.transferStatusCache = null;
303
+ return TRANSFERS_UNKNOWN;
304
+ });
305
+ }
306
+ return this.transferStatusCache;
307
+ }
308
+ /**
309
+ * Get ready to transfer: fetches the short-lived INVO player token the approval and collect
310
+ * calls use. {@link transferDestinations} and {@link pendingTransfers} call it for you; the
311
+ * approve and collect calls need it done BEFORE the click, so the INVO window can open.
312
+ */
313
+ async prepareTransfers() {
314
+ if (this.transferClient) return;
315
+ const minted = await this.request("POST", "/transfers/token");
316
+ if (!minted.apiBaseUrl) throw new InvoGameError("TRANSFERS_UNAVAILABLE", "Transfers aren't available right now. Try again in a moment.", 503);
317
+ this.useTransferToken(minted.token, minted.apiBaseUrl);
318
+ }
319
+ useTransferToken(token, baseUrl) {
320
+ this.transferClient = new InvoClient({
321
+ token,
322
+ baseUrl,
323
+ ...this.invoFetch ? { fetch: this.invoFetch } : {},
324
+ refreshToken: async () => (await this.request("POST", "/transfers/token")).token
325
+ });
326
+ }
327
+ /**
328
+ * Where this player can send: this game first (send rail only), then every INVO game the
329
+ * destination list offers, each with its currency and per-transfer limits.
330
+ */
331
+ async transferDestinations() {
332
+ await this.prepareTransfers();
333
+ const result = await this.transferClient.getDestinations({ direction: "send" });
334
+ const here = {
335
+ gameId: result.sourceGameId,
336
+ gameName: result.sourceGameName,
337
+ currencyName: result.sourceCurrencyName,
338
+ currencySymbol: "",
339
+ minimumTransfer: "",
340
+ maximumTransfer: "",
341
+ acceptsSteamOriginValue: true,
342
+ raw: {},
343
+ thisGame: true,
344
+ kinds: ["send"]
345
+ };
346
+ const others = result.availableGames.filter((g) => String(g.gameId) !== String(result.sourceGameId)).map((g) => ({ ...g, thisGame: false, kinds: ["transfer", "send"] }));
347
+ return [here, ...others];
348
+ }
349
+ /**
350
+ * Start a transfer or send on the server. Nothing moves yet: call {@link approveTransfer}
351
+ * from the player's next click to open INVO's passkey page.
352
+ */
353
+ async startTransfer(input) {
354
+ await this.prepareTransfers();
355
+ const started = await this.request("POST", "/transfers", {
356
+ ...input,
357
+ kind: input.kind ?? "transfer",
358
+ clientRequestId: input.clientRequestId ?? newEventId()
359
+ });
360
+ if (started.playerToken) {
361
+ const status = await this.transferStatus();
362
+ if (status.apiBaseUrl) this.useTransferToken(started.playerToken, status.apiBaseUrl);
363
+ }
364
+ return started;
365
+ }
366
+ /**
367
+ * The sender approves. With a real key this opens INVO's hosted passkey page, so CALL IT
368
+ * DIRECTLY FROM A CLICK (the browser only allows the window from a user gesture). On the
369
+ * public demo key (`approval: "sandbox"`) the game server approves it in INVO's demo sandbox.
370
+ */
371
+ approveTransfer(start) {
372
+ if (start.approval === "sandbox") {
373
+ return this.sandboxStep(
374
+ start.transactionId,
375
+ start.kind,
376
+ "out",
377
+ () => this.request("POST", `/transfers/${encodeURIComponent(start.transactionId)}/approve`).then((r) => ({ claimCode: r.claimCode }))
378
+ );
379
+ }
380
+ return this.hosted(start.transactionId, start.kind, start.kind, "out");
381
+ }
382
+ /** Transfers and sends waiting for this player: ones sent to them, and ones they still need to approve. */
383
+ async pendingTransfers() {
384
+ if ((await this.transferStatus()).approval === "sandbox") {
385
+ return (await this.request("GET", "/transfers/pending")).pending;
386
+ }
387
+ await this.prepareTransfers();
388
+ return (await this.transferClient.getPendingCollect()).pending;
389
+ }
390
+ /**
391
+ * Settle a pending item on INVO's hosted page: collect one sent to this player, or approve
392
+ * one they started. CALL THIS DIRECTLY FROM A CLICK.
393
+ */
394
+ collectTransfer(item, approval = "passkey") {
395
+ const kind = item.flow === "send" ? "send" : "transfer";
396
+ const incoming = item.kind === "receiving_confirm";
397
+ if (approval === "sandbox") {
398
+ const id = encodeURIComponent(item.transferId);
399
+ return incoming ? this.sandboxStep(item.transferId, kind, "in", () => this.request("POST", `/transfers/${id}/collect`).then((r) => {
400
+ this.setWallet(r.wallet);
401
+ return { claimCode: null };
402
+ })) : this.sandboxStep(item.transferId, kind, "out", () => this.request("POST", `/transfers/${id}/approve`).then((r) => ({ claimCode: r.claimCode })));
403
+ }
404
+ return this.hosted(item.transferId, kind, incoming ? kind === "send" ? "send_receipt" : "transfer_receipt" : kind, incoming ? "in" : "out");
405
+ }
406
+ /** A demo-sandbox step done by the game server, reported like the hosted page's result. */
407
+ async sandboxStep(transactionId, kind, direction, run) {
408
+ const { claimCode } = await run();
409
+ if (direction === "out") await this.refresh().catch(() => void 0);
410
+ this.emit("transfer", { transactionId, kind, direction, status: "approved", claimCode, holdReason: null });
411
+ return { status: "approved", popupBlocked: false, approval: { claimCode } };
412
+ }
413
+ hosted(transactionId, kind, flow, direction) {
414
+ const client = this.transferClient;
415
+ if (!client) {
416
+ return Promise.reject(new InvoGameError("TRANSFERS_NOT_READY", "Call prepareTransfers() before the click that approves.", 0));
417
+ }
418
+ return client.approveHosted({ transactionId, flow }).then(async (result) => {
419
+ const approval = result.approval ?? null;
420
+ if (result.status === "approved") await this.refresh().catch(() => void 0);
421
+ this.emit("transfer", {
422
+ transactionId,
423
+ kind,
424
+ direction,
425
+ status: result.status,
426
+ claimCode: approval?.claimCode ?? null,
427
+ holdReason: approval?.holdReason ?? null
428
+ });
429
+ return result;
430
+ });
431
+ }
281
432
  clearSession() {
433
+ this.transferClient = null;
282
434
  this.token = null;
283
435
  this.player = null;
284
436
  this.wallet = null;
@@ -363,6 +515,7 @@ var ICONS = {
363
515
  info: stroke('<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>', 14),
364
516
  alert: stroke('<path d="M12 3l10 18H2L12 3z"/><path d="M12 10v4M12 17h.01"/>', 14),
365
517
  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),
518
+ arrows: stroke('<path d="M4 8h13l-4-4M20 16H7l4 4"/>', 16),
366
519
  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)
367
520
  };
368
521
  var svgId = 0;
@@ -522,6 +675,33 @@ var CSS = `
522
675
  @keyframes invo-toast{from{opacity:0;transform:translateY(12px) scale(.97)}to{opacity:1;transform:none}}
523
676
  @keyframes invo-toast-out{to{opacity:0;transform:translateY(8px) scale(.98)}}
524
677
 
678
+ .invo-ui [hidden]{display:none!important}
679
+ .invo-hero{display:flex;gap:14px;align-items:center;padding:16px;border-radius:18px;margin-bottom:16px;background:radial-gradient(120% 140% at 0% 0%,rgba(244,192,74,.14),transparent 60%),rgba(255,255,255,.03);border:1px solid var(--invo-line)}
680
+ .invo-hero-ico{display:grid;place-items:center;width:46px;height:46px;flex:none;border-radius:14px;color:#1A1405;background:linear-gradient(150deg,#FFE6A3,var(--invo-gold) 55%,#C98E1C);box-shadow:inset 0 1px 0 rgba(255,255,255,.6),0 10px 24px -8px rgba(244,192,74,.7)}
681
+ .invo-hero-ico svg{width:22px;height:22px}
682
+ .invo-hero.locked .invo-hero-ico{color:var(--invo-muted);background:rgba(255,255,255,.06);box-shadow:none}
683
+ .invo-hero b{display:block;font-size:15px;margin-bottom:3px}.invo-hero span{color:var(--invo-muted);font-size:13px;line-height:1.5}
684
+ .invo-livechip{display:inline-flex;align-items:center;height:24px;padding:0 10px;margin-bottom:10px;border-radius:999px;font:800 10px/1 var(--invo-font);letter-spacing:.14em;text-transform:uppercase;color:var(--invo-gold);background:rgba(244,192,74,.1);border:1px solid rgba(244,192,74,.35)}
685
+ .invo-seg{display:grid;grid-template-columns:1fr 1fr;gap:4px;padding:4px;margin-bottom:14px;border-radius:13px;background:rgba(0,0,0,.28);border:1px solid var(--invo-line)}
686
+ .invo-seg button{padding:9px 10px;border:0;border-radius:9px;background:transparent;color:var(--invo-muted);font:600 13px var(--invo-font);cursor:pointer;text-align:left}
687
+ .invo-seg button small{display:block;margin-top:2px;font-weight:500;font-size:11.5px;color:var(--invo-muted);opacity:.85}
688
+ .invo-seg button[aria-pressed=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)}
689
+ .invo-amount{position:relative}.invo-amount .invo-input{padding-left:14px;padding-right:84px;font-variant-numeric:tabular-nums}
690
+ .invo-amount em{position:absolute;right:14px;top:50%;transform:translateY(-50%);font-style:normal;font-weight:700;color:var(--invo-gold);font-size:13px;pointer-events:none}
691
+ .invo-hint{margin:-6px 0 14px;color:var(--invo-muted);font-size:12px;line-height:1.5}
692
+ select.invo-input{appearance:none;-webkit-appearance:none;cursor:pointer;background-image:linear-gradient(45deg,transparent 50%,var(--invo-muted) 50%),linear-gradient(135deg,var(--invo-muted) 50%,transparent 50%);background-position:calc(100% - 20px) 50%,calc(100% - 14px) 50%;background-size:6px 6px;background-repeat:no-repeat;padding-left:14px;padding-right:36px}
693
+ .invo-review{border-radius:18px;padding:4px 16px;margin-bottom:16px;background:rgba(255,255,255,.03);border:1px solid var(--invo-line)}
694
+ .invo-review-row{display:flex;justify-content:space-between;gap:12px;padding:12px 0;border-bottom:1px solid var(--invo-line);font-size:14px;color:var(--invo-muted)}
695
+ .invo-review-row:last-child{border-bottom:0}.invo-review-row b{color:var(--invo-text);text-align:right;word-break:break-word}
696
+ .invo-big{font:800 36px/1 var(--invo-font);letter-spacing:-.03em;color:var(--invo-gold);margin:6px 0 14px;font-variant-numeric:tabular-nums}
697
+ .invo-claim{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:14px;padding:12px 14px;border-radius:14px;background:rgba(0,0,0,.35);border:1px dashed rgba(244,192,74,.45);font:700 18px ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:.12em;color:var(--invo-gold)}
698
+ .invo-claim small{font:600 11px var(--invo-font);letter-spacing:.08em;text-transform:uppercase;color:var(--invo-muted)}
699
+ .invo-tlist{display:flex;flex-direction:column;gap:10px}
700
+ .invo-titem{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border-radius:16px;background:var(--invo-surface);border:1px solid var(--invo-line);animation:invo-rise .35s var(--invo-ease) backwards}
701
+ .invo-titem b{display:block;font-size:15px;font-variant-numeric:tabular-nums}.invo-titem span{color:var(--invo-muted);font-size:12.5px}
702
+ .invo-done{text-align:center;padding:4px 0}.invo-done .invo-hero-ico{margin:0 auto 14px;width:56px;height:56px;border-radius:18px}
703
+ .invo-done h3{margin:0 0 6px;font-size:20px;letter-spacing:-.02em}
704
+ .invo-hbtn.locked svg{opacity:.55}
525
705
  @media (max-width:560px){
526
706
  .invo-hbtn .invo-label{display:none}.invo-hbtn{padding:0 10px}.invo-account[data-initial]::before{margin:0 -3px}
527
707
  .invo-pill{padding:0 10px 0 8px;gap:6px}.invo-hud .invo-badge .invo-label{display:none}.invo-hud .invo-badge{padding:0 8px}
@@ -594,9 +774,14 @@ function mountInvoUI(container, economy, options = {}) {
594
774
  shopBtn.type = "button";
595
775
  shopBtn.append(svg(ICONS.bag), el("span", "invo-label", "Shop"));
596
776
  shopBtn.hidden = !!options.hideShopButton;
777
+ const transferBtn = el("button", "invo-btn invo-hbtn");
778
+ transferBtn.type = "button";
779
+ transferBtn.append(svg(ICONS.arrows), el("span", "invo-label", "Transfer"));
780
+ transferBtn.title = "Send to another player, or collect what was sent to you.";
781
+ transferBtn.hidden = !!options.hideTransferButton;
597
782
  const accountBtn = el("button", "invo-btn invo-hbtn invo-account");
598
783
  accountBtn.type = "button";
599
- hud.append(sandboxBadge, premiumPill, softPill, el("span", "invo-sep"), shopBtn, accountBtn);
784
+ hud.append(sandboxBadge, premiumPill, softPill, el("span", "invo-sep"), shopBtn, transferBtn, accountBtn);
600
785
  root.append(hud);
601
786
  const toasts = el("div", "invo-toasts");
602
787
  toasts.setAttribute("role", "status");
@@ -794,6 +979,9 @@ function mountInvoUI(container, economy, options = {}) {
794
979
  };
795
980
  const email = field("Email", "", "email", "email", "you@example.com", "email", ICONS.mail);
796
981
  const phone = field("Phone", "first sign-in only", "tel", "phone", "+1 555 555 0111", "tel", ICONS.phone);
982
+ if (economy.catalog?.playerFields?.phone === "hidden" || economy.catalog?.demo) {
983
+ phone.closest(".invo-field")?.setAttribute("hidden", "");
984
+ }
797
985
  const name = field("Player name", "optional", "text", "name", "What should we call you?", "nickname", ICONS.user);
798
986
  email.required = true;
799
987
  const error = el("div", "invo-error");
@@ -986,8 +1174,374 @@ function mountInvoUI(container, economy, options = {}) {
986
1174
  card.append(foot);
987
1175
  return card;
988
1176
  }
1177
+ function hero(iconSvg, title, text, locked = false) {
1178
+ const box = el("div", `invo-hero${locked ? " locked" : ""}`);
1179
+ const words = el("div");
1180
+ words.append(el("b", void 0, title), el("span", void 0, text));
1181
+ box.append(svg(iconSvg, "invo-hero-ico"), words);
1182
+ return box;
1183
+ }
1184
+ function transfersLocked(status) {
1185
+ openDialog(
1186
+ { title: `Send ${premiumName()} to anyone`, eyebrow: "Transfers", subtitle: "Move currency to a friend in this game or another INVO game, approved with a passkey.", narrow: true },
1187
+ (body) => {
1188
+ const ok = el("button", "invo-btn block", "Got it");
1189
+ ok.type = "button";
1190
+ ok.onclick = () => close();
1191
+ body.append(
1192
+ el("span", "invo-livechip", status.reason === "checking" ? "One moment" : "Live only"),
1193
+ hero(
1194
+ ICONS.lock,
1195
+ status.reason === "checking" ? "Checking this game's INVO key" : "Available when this game goes live",
1196
+ status.reason === "sandbox" ? "This game is on a sandbox key. Transfers switch on by themselves with the production key. To try them first, set INVO_TRANSFERS=on." : status.reason === "checking" ? "Try again in a moment." : "Transfers are switched off for this game.",
1197
+ true
1198
+ ),
1199
+ ok
1200
+ );
1201
+ }
1202
+ );
1203
+ }
1204
+ async function openTransfers(tab = "send") {
1205
+ if (economy.setupRequired) return openSetup();
1206
+ const status = await economy.transferStatus();
1207
+ if (!status.enabled) return transfersLocked(status);
1208
+ if (!economy.signedIn) return openSignIn(() => void openTransfers(tab));
1209
+ openDialog(
1210
+ {
1211
+ title: `Send ${premiumName()} to anyone`,
1212
+ eyebrow: "Transfers",
1213
+ subtitle: status.scope === "project" ? "Transfers work between players of this project." : "To a friend here or in any other INVO game. You approve each one with your passkey.",
1214
+ narrow: true
1215
+ },
1216
+ (body) => {
1217
+ const tabs = el("div", "invo-tabs");
1218
+ tabs.setAttribute("role", "tablist");
1219
+ const pane = el("div");
1220
+ const tabFor = (key, label) => {
1221
+ const b = el("button", "invo-tab", label);
1222
+ b.type = "button";
1223
+ b.setAttribute("role", "tab");
1224
+ b.setAttribute("aria-selected", String(key === tab));
1225
+ b.onclick = () => {
1226
+ tabs.querySelectorAll(".invo-tab").forEach((n) => n.setAttribute("aria-selected", "false"));
1227
+ b.setAttribute("aria-selected", "true");
1228
+ void (key === "send" ? sendPane(pane, status) : collectPane(pane, status.approval));
1229
+ };
1230
+ tabs.append(b);
1231
+ };
1232
+ tabFor("send", "Send");
1233
+ tabFor("collect", "Collect");
1234
+ body.append(tabs, pane);
1235
+ void (tab === "send" ? sendPane(pane, status) : collectPane(pane, status.approval));
1236
+ }
1237
+ );
1238
+ }
1239
+ function paneLoading(pane, text) {
1240
+ const row = el("div", "invo-status");
1241
+ row.append(el("span", "invo-spinner"), el("span", void 0, text));
1242
+ pane.replaceChildren(row);
1243
+ }
1244
+ function paneFailed(pane, message, retry) {
1245
+ const again = el("button", "invo-btn block", "Try again");
1246
+ again.type = "button";
1247
+ again.onclick = retry;
1248
+ pane.replaceChildren(el("div", "invo-error", message), again);
1249
+ }
1250
+ const draft = { kind: "transfer", gameId: "", amount: "", email: "", phone: "", myPhone: "", needMyPhone: false };
1251
+ async function sendPane(pane, status) {
1252
+ paneLoading(pane, "Finding where you can send\u2026");
1253
+ let games;
1254
+ try {
1255
+ games = await economy.transferDestinations();
1256
+ } catch (err) {
1257
+ return paneFailed(pane, err instanceof Error ? err.message : "Couldn't load destinations.", () => void sendPane(pane, status));
1258
+ }
1259
+ if (!pane.isConnected) return;
1260
+ const form = el("form");
1261
+ form.noValidate = true;
1262
+ const pick = () => games.find((g) => String(g.gameId) === game.value) ?? games[0];
1263
+ const seg = el("div", "invo-seg");
1264
+ const segButton = (kind, title, note) => {
1265
+ const b = el("button");
1266
+ b.type = "button";
1267
+ b.setAttribute("aria-pressed", String(draft.kind === kind));
1268
+ b.append(document.createTextNode(title), el("small", void 0, note));
1269
+ b.onclick = () => {
1270
+ if (draft.kind === kind) return;
1271
+ draft.kind = kind;
1272
+ void sendPane(pane, status);
1273
+ };
1274
+ seg.append(b);
1275
+ };
1276
+ segButton("transfer", "Transfer", "They collect with a passkey or a claim code");
1277
+ segButton("send", "Send", "They can collect from a link INVO sends");
1278
+ const field = (label, hint, control, iconSvg) => {
1279
+ const wrap = el("div", "invo-field");
1280
+ const l = el("label");
1281
+ l.append(document.createTextNode(label));
1282
+ if (hint) l.append(el("small", void 0, hint));
1283
+ if (iconSvg) {
1284
+ const box = el("div", "invo-inwrap");
1285
+ box.append(svg(iconSvg), control);
1286
+ wrap.append(l, box);
1287
+ } else {
1288
+ wrap.append(l, control);
1289
+ }
1290
+ form.append(wrap);
1291
+ return wrap;
1292
+ };
1293
+ const game = el("select", "invo-input");
1294
+ for (const g of games) {
1295
+ const o = el("option", void 0, g.thisGame ? `A player in this game \xB7 ${g.currencyName}` : `${g.gameName} \xB7 ${g.currencyName}`);
1296
+ o.value = String(g.gameId);
1297
+ game.append(o);
1298
+ }
1299
+ if (draft.gameId && games.some((g) => String(g.gameId) === draft.gameId)) game.value = draft.gameId;
1300
+ field("Send to", "", game);
1301
+ const limits = el("p", "invo-hint");
1302
+ form.append(limits);
1303
+ form.append(seg);
1304
+ const amountBox = el("div", "invo-amount");
1305
+ const amount = el("input", "invo-input");
1306
+ amount.inputMode = "decimal";
1307
+ amount.placeholder = "0";
1308
+ amount.value = draft.amount;
1309
+ amountBox.append(amount, el("em", void 0, premiumName()));
1310
+ const have = economy.balance("premium")?.balance;
1311
+ field("Amount", have === null || have === void 0 ? "" : `you have ${formatAmount(have)}`, amountBox);
1312
+ const email = el("input", "invo-input");
1313
+ email.type = "email";
1314
+ email.placeholder = "friend@example.com";
1315
+ email.autocomplete = "off";
1316
+ email.value = draft.email;
1317
+ const phone = el("input", "invo-input");
1318
+ phone.type = "tel";
1319
+ phone.placeholder = "+1 555 555 0111";
1320
+ phone.autocomplete = "off";
1321
+ phone.value = draft.phone;
1322
+ if (status.recipientFields.phone === "required") field("Friend's phone", "required", phone, ICONS.phone);
1323
+ field(
1324
+ "Friend's email",
1325
+ status.recipientFields.email === "required" ? "the one they sign in with" : "optional",
1326
+ email,
1327
+ ICONS.mail
1328
+ );
1329
+ const myPhone = el("input", "invo-input");
1330
+ myPhone.type = "tel";
1331
+ myPhone.placeholder = "+1 555 555 0100";
1332
+ myPhone.autocomplete = "tel";
1333
+ myPhone.value = draft.myPhone;
1334
+ field("Your phone", "as on your INVO account", myPhone, ICONS.phone).hidden = !draft.needMyPhone;
1335
+ const showLimits = () => {
1336
+ const g = pick();
1337
+ seg.hidden = g.thisGame;
1338
+ if (g.thisGame) draft.kind = "send";
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.` : "");
1341
+ };
1342
+ game.onchange = () => {
1343
+ const was = draft.kind;
1344
+ showLimits();
1345
+ seg.querySelectorAll("button").forEach((b, i) => b.setAttribute("aria-pressed", String((i === 0 ? "transfer" : "send") === draft.kind)));
1346
+ if (was !== draft.kind) draft.gameId = game.value;
1347
+ };
1348
+ showLimits();
1349
+ if (status.demo) {
1350
+ const note = el("div", "invo-callout");
1351
+ note.append(svg(ICONS.info), el("span", void 0, "Demo sandbox: transfers work between players of this project, and approving needs no passkey. On your live key, players confirm each one with their passkey."));
1352
+ form.append(note);
1353
+ }
1354
+ const error = el("div", "invo-error");
1355
+ const next = el("button", "invo-btn gold block", "Review");
1356
+ next.type = "submit";
1357
+ next.style.marginTop = "14px";
1358
+ form.append(error, next);
1359
+ form.onsubmit = (e) => {
1360
+ e.preventDefault();
1361
+ Object.assign(draft, { gameId: game.value, amount: amount.value.trim(), email: email.value.trim(), phone: phone.value.trim(), myPhone: myPhone.value.trim() });
1362
+ const g = pick();
1363
+ if (g.thisGame) draft.kind = "send";
1364
+ const n = Number(draft.amount);
1365
+ if (!(n > 0)) return void (error.textContent = "Enter an amount greater than zero.");
1366
+ const balance = economy.balance("premium")?.balance;
1367
+ if (balance !== null && balance !== void 0 && n > balance) {
1368
+ return void (error.textContent = `You have ${formatAmount(balance)} ${premiumName()}.`);
1369
+ }
1370
+ if (g.minimumTransfer && g.maximumTransfer && (n < Number(g.minimumTransfer) || n > Number(g.maximumTransfer))) {
1371
+ return void (error.textContent = `${g.gameName} accepts ${g.minimumTransfer} to ${g.maximumTransfer} per transfer.`);
1372
+ }
1373
+ if (status.recipientFields.email === "required" && !draft.email) return void (error.textContent = "Enter your friend's email.");
1374
+ if (status.recipientFields.phone === "required" && !draft.phone) return void (error.textContent = "Enter your friend's phone.");
1375
+ reviewPane(pane, status, g);
1376
+ };
1377
+ pane.replaceChildren(form);
1378
+ amount.focus({ preventScroll: true });
1379
+ }
1380
+ function reviewPane(pane, status, game) {
1381
+ const what = `${draft.amount} ${premiumName()}`;
1382
+ const wrap = el("div");
1383
+ wrap.append(el("div", "invo-eyebrow", draft.kind === "send" ? "Review send" : "Review transfer"), el("div", "invo-big", what));
1384
+ const table = el("div", "invo-review");
1385
+ const row = (k, v) => {
1386
+ const r = el("div", "invo-review-row");
1387
+ r.append(document.createTextNode(k), el("b", void 0, v));
1388
+ table.append(r);
1389
+ };
1390
+ row("To", [draft.email, status.recipientFields.phone === "required" ? draft.phone : ""].filter(Boolean).join(" \xB7 "));
1391
+ row("In", game.thisGame ? `This game (${game.currencyName})` : `${game.gameName} (${game.currencyName})`);
1392
+ row("Network fee", "10%, shared by both games and INVO");
1393
+ const error = el("div", "invo-error");
1394
+ const send = el("button", "invo-btn gold block", draft.kind === "send" ? "Send" : "Transfer");
1395
+ send.type = "button";
1396
+ const edit = el("button", "invo-btn block", "Edit");
1397
+ edit.type = "button";
1398
+ edit.style.marginTop = "10px";
1399
+ edit.onclick = () => void sendPane(pane, status);
1400
+ send.onclick = async () => {
1401
+ send.disabled = true;
1402
+ send.classList.add("busy");
1403
+ error.textContent = "";
1404
+ try {
1405
+ const started = await economy.startTransfer({
1406
+ kind: draft.kind,
1407
+ targetGameId: game.gameId,
1408
+ amount: draft.amount,
1409
+ recipientEmail: draft.email || void 0,
1410
+ recipientPhone: status.recipientFields.phone === "required" ? draft.phone : void 0,
1411
+ senderPhone: draft.myPhone || void 0
1412
+ });
1413
+ if (started.guardianPending) {
1414
+ return donePane(pane, "Waiting for a guardian", "A parent or guardian has been emailed to approve it. Nothing moves until they do.", null);
1415
+ }
1416
+ approvePane(
1417
+ pane,
1418
+ `Approve ${draft.kind === "send" ? "sending" : "transferring"} ${what}`,
1419
+ status.approval,
1420
+ () => economy.approveTransfer(started),
1421
+ (result) => {
1422
+ const claim = result.approval?.claimCode ?? null;
1423
+ donePane(
1424
+ pane,
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}.`,
1427
+ // The demo collects with the claim code on the server; only a real transfer needs it shown.
1428
+ status.approval === "sandbox" ? null : claim
1429
+ );
1430
+ Object.assign(draft, { amount: "", email: "", phone: "" });
1431
+ }
1432
+ );
1433
+ } catch (err) {
1434
+ if (err instanceof InvoGameError && err.code === "SENDER_PHONE_REQUIRED") {
1435
+ draft.needMyPhone = true;
1436
+ void sendPane(pane, status);
1437
+ return;
1438
+ }
1439
+ error.textContent = err instanceof Error ? err.message : "That didn't go through.";
1440
+ } finally {
1441
+ send.disabled = false;
1442
+ send.classList.remove("busy");
1443
+ }
1444
+ };
1445
+ wrap.append(table, error, send, edit);
1446
+ pane.replaceChildren(wrap);
1447
+ }
1448
+ function approvePane(pane, title, approval, approve, onApproved, verb = "Approve") {
1449
+ const sandbox = approval === "sandbox";
1450
+ const error = el("div", "invo-error");
1451
+ const go = el("button", "invo-btn gold block", sandbox ? `${verb} (sandbox)` : `${verb} with passkey`);
1452
+ go.type = "button";
1453
+ go.onclick = () => {
1454
+ go.disabled = true;
1455
+ go.classList.add("busy");
1456
+ error.textContent = "";
1457
+ approve().then((result) => {
1458
+ if (result.status === "approved") {
1459
+ const hold = result.approval?.holdReason;
1460
+ if (hold) return donePane(pane, "On hold", "INVO is reviewing this one. It completes on its own and you'll both be told.", null);
1461
+ return onApproved(result);
1462
+ }
1463
+ error.textContent = result.status === "denied" ? "You declined on INVO's page. Nothing moved." : result.status === "expired" ? "That approval expired. Try again." : result.status === "closed" ? "INVO's window was closed. Nothing moved." : result.message ?? "Your browser blocked INVO's window. Allow pop-ups for this site and try again.";
1464
+ }).catch((err) => {
1465
+ error.textContent = err instanceof Error ? err.message : "Approval failed.";
1466
+ }).finally(() => {
1467
+ go.disabled = false;
1468
+ go.classList.remove("busy");
1469
+ });
1470
+ };
1471
+ const secure = el("p", "invo-secure");
1472
+ secure.append(svg(ICONS.lock), document.createTextNode(sandbox ? "Demo sandbox \xB7 test currency only" : "Secured by INVO passkeys"));
1473
+ pane.replaceChildren(
1474
+ hero(
1475
+ ICONS.arrows,
1476
+ title,
1477
+ sandbox ? "Demo sandbox: this approves without a passkey. With your live key, INVO opens a secure window and the player confirms with their fingerprint, face or screen lock." : "INVO opens a secure window. Confirm with your fingerprint, face or screen lock. First time? It sets up your INVO passkey in seconds."
1478
+ ),
1479
+ error,
1480
+ go,
1481
+ secure
1482
+ );
1483
+ }
1484
+ function donePane(pane, title, message, claimCode) {
1485
+ const wrap = el("div", "invo-done");
1486
+ wrap.append(svg(ICONS.check, "invo-hero-ico"), el("h3", void 0, title), el("p", "invo-sub", message));
1487
+ if (claimCode) {
1488
+ const code = el("div", "invo-claim");
1489
+ code.append(el("span", void 0, claimCode), el("small", void 0, "Claim code"));
1490
+ wrap.append(code, el("p", "invo-hint", "If your friend can't collect in their game, they can use this code."));
1491
+ }
1492
+ const ok = el("button", "invo-btn block", "Done");
1493
+ ok.type = "button";
1494
+ ok.style.marginTop = "16px";
1495
+ ok.onclick = () => close();
1496
+ wrap.append(ok);
1497
+ pane.replaceChildren(wrap);
1498
+ }
1499
+ async function collectPane(pane, approval) {
1500
+ paneLoading(pane, "Checking for transfers\u2026");
1501
+ let items;
1502
+ try {
1503
+ items = await economy.pendingTransfers();
1504
+ } catch (err) {
1505
+ return paneFailed(pane, err instanceof Error ? err.message : "Couldn't check.", () => void collectPane(pane, approval));
1506
+ }
1507
+ if (!pane.isConnected) return;
1508
+ if (!items.length) {
1509
+ pane.replaceChildren(el("div", "invo-empty", "Nothing to collect right now."));
1510
+ return;
1511
+ }
1512
+ const list = el("div", "invo-tlist");
1513
+ for (const item of items) {
1514
+ const incoming = item.kind === "receiving_confirm";
1515
+ const what = `${item.amount ?? ""} ${item.currency}`.trim();
1516
+ const row = el("div", "invo-titem");
1517
+ const words = el("div");
1518
+ words.append(el("b", void 0, what), el("span", void 0, incoming ? `From ${item.counterpartyGame}` : `Waiting for your approval \xB7 to ${item.counterpartyGame}`));
1519
+ const act = el("button", "invo-btn gold sm", incoming ? "Collect" : "Approve");
1520
+ act.type = "button";
1521
+ if (item.held) {
1522
+ act.disabled = true;
1523
+ act.textContent = "On hold";
1524
+ }
1525
+ act.onclick = () => approvePane(
1526
+ pane,
1527
+ incoming ? `Collect ${what}` : `Approve ${what}`,
1528
+ approval,
1529
+ () => economy.collectTransfer(item, approval),
1530
+ () => donePane(pane, incoming ? "Collected" : "Approved", incoming ? `${what}, less INVO's 10% network fee, is in your wallet.` : `${what} is on its way.`, null),
1531
+ incoming ? "Collect" : "Approve"
1532
+ );
1533
+ row.append(words, act);
1534
+ list.append(row);
1535
+ }
1536
+ pane.replaceChildren(list);
1537
+ }
989
1538
  plus.onclick = () => openBuyCurrency();
990
1539
  shopBtn.onclick = () => openShop();
1540
+ transferBtn.onclick = () => void openTransfers();
1541
+ void economy.transferStatus().then((s) => {
1542
+ transferBtn.classList.toggle("locked", !s.enabled);
1543
+ if (!s.enabled) transferBtn.replaceChildren(svg(ICONS.lock), el("span", "invo-label", "Transfer"));
1544
+ });
991
1545
  accountBtn.onclick = async () => {
992
1546
  if (economy.setupRequired) return openSetup();
993
1547
  if (!economy.signedIn) return openSignIn();
@@ -1010,6 +1564,9 @@ function mountInvoUI(container, economy, options = {}) {
1010
1564
  // Popup and redirect checkouts both end here, so the confirmation shows exactly once.
1011
1565
  economy.on("purchase", (u) => {
1012
1566
  if (u.status === "credited") toast(`+${formatAmount(u.credited)} ${premiumName()} added`, "success");
1567
+ }),
1568
+ economy.on("transfer", (t2) => {
1569
+ if (t2.status === "approved" && !t2.holdReason) toast(t2.direction === "in" ? "Collected" : t2.kind === "send" ? "Sent" : "Transfer approved", "success");
1013
1570
  })
1014
1571
  ];
1015
1572
  renderHud();
@@ -1018,6 +1575,7 @@ function mountInvoUI(container, economy, options = {}) {
1018
1575
  openShop,
1019
1576
  openBuyCurrency,
1020
1577
  openSignIn: () => openSignIn(),
1578
+ openTransfers: (tab) => void openTransfers(tab),
1021
1579
  close,
1022
1580
  toast,
1023
1581
  destroy() {