@invonetwork/web-sdk 3.18.0 → 3.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -819,6 +819,7 @@ var InvoError = class _InvoError extends Error {
819
819
  * The same code comes back from `cards.beginSetup` and from `mintPlayerToken` for the
820
820
  * same reason; those two never create players, so create the member first (for
821
821
  * example with `createSetupSession` and a `playerName`, or a currency purchase).
822
+ * `getPlayerRewards` answers it when no player has that email in this game.
822
823
  */
823
824
  get isPlayerNotFound() {
824
825
  return this.code === "PLAYER_NOT_FOUND";
@@ -833,7 +834,8 @@ var InvoError = class _InvoError extends Error {
833
834
  }
834
835
  /**
835
836
  * True when `cards.createSetupSession` was refused because `playerEmail` was missing or
836
- * is not an email address (`INVALID_PLAYER_EMAIL`, 400).
837
+ * is not an email address (`INVALID_PLAYER_EMAIL`, 400). `getPlayerRewards` answers it
838
+ * for an email that is not an email address (a blank one never leaves the SDK).
837
839
  */
838
840
  get isInvalidPlayerEmail() {
839
841
  return this.code === "INVALID_PLAYER_EMAIL";
@@ -884,6 +886,26 @@ var InvoError = class _InvoError extends Error {
884
886
  get isIdentityCheckUnavailable() {
885
887
  return this.code === "IDENTITY_CHECK_UNAVAILABLE";
886
888
  }
889
+ // ---- Loyalty rewards (InvoClient.redeemReward) ----
890
+ /** True when a reward was already redeemed and its code can no longer be shown (`already_redeemed`, 409). */
891
+ get isRewardAlreadyRedeemed() {
892
+ return this.code === "already_redeemed";
893
+ }
894
+ /** True when the player has no such reward (`vault_entry_not_found`, 404). */
895
+ get isRewardNotFound() {
896
+ return this.code === "vault_entry_not_found";
897
+ }
898
+ /**
899
+ * True when the reward cannot be redeemed right now (409): `inventory_exhausted` (no units or
900
+ * codes are left for it) or `conflict` (the reward is reserved or revoked).
901
+ */
902
+ get isRewardUnavailable() {
903
+ return this.code === "inventory_exhausted" || this.code === "conflict";
904
+ }
905
+ /** True when the reward expired before it was redeemed (`vault_entry_expired`, 410). */
906
+ get isRewardExpired() {
907
+ return this.code === "vault_entry_expired";
908
+ }
887
909
  /** Seconds to wait before retrying, when the backend throttled the call (429 `retry_after`). */
888
910
  get retryAfter() {
889
911
  const v = this.bodyObject()["retry_after"];
@@ -1902,7 +1924,125 @@ function nothingWasCharged(r) {
1902
1924
  return r.reasonCode !== null && NOTHING_CHARGED_REASONS.has(r.reasonCode);
1903
1925
  }
1904
1926
 
1927
+ // src/shared/loyalty.ts
1928
+ var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
1929
+ var rows = (v) => Array.isArray(v) ? v.filter((r) => r && typeof r === "object" && !Array.isArray(r)) : [];
1930
+ var str2 = (v) => v === void 0 || v === null ? "" : String(v);
1931
+ var strOrNull = (v) => v === void 0 || v === null ? null : String(v);
1932
+ var numOrNull = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
1933
+ var int = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
1934
+ var passThrough = (v) => v;
1935
+ function toLoyaltyStepProgress(value) {
1936
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
1937
+ const v = value;
1938
+ const current = v["current"];
1939
+ const target = v["target"];
1940
+ if (!Number.isInteger(current) || !Number.isInteger(target)) return null;
1941
+ return { current, target };
1942
+ }
1943
+ function toStep(row) {
1944
+ return {
1945
+ stepId: strOrNull(row["step_id"]),
1946
+ index: int(row["index"]),
1947
+ action: str2(row["action"]),
1948
+ label: str2(row["label"]),
1949
+ summary: str2(row["summary"]),
1950
+ windowHours: numOrNull(row["window_hours"]),
1951
+ state: str2(row["state"]),
1952
+ progress: toLoyaltyStepProgress(row["progress"]),
1953
+ raw: row
1954
+ };
1955
+ }
1956
+ function toCardReward(row) {
1957
+ return {
1958
+ vaultEntryId: str2(row["vault_entry_id"]),
1959
+ rewardId: str2(row["reward_id"]),
1960
+ state: str2(row["state"]),
1961
+ unlockedAt: str2(row["unlocked_at"]),
1962
+ expiresAt: str2(row["expires_at"]),
1963
+ redeemedAt: strOrNull(row["redeemed_at"]),
1964
+ codeMasked: strOrNull(row["code_masked"]),
1965
+ canRedeem: row["can_redeem"] === true,
1966
+ canRevealAgain: row["can_reveal_again"] === true,
1967
+ revealUntil: strOrNull(row["reveal_until"]),
1968
+ raw: row
1969
+ };
1970
+ }
1971
+ function toLoyaltyCard(row) {
1972
+ const brand = obj(row["brand"]);
1973
+ const reward = obj(row["reward"]);
1974
+ const steps = rows(row["steps"]).map(toStep);
1975
+ return {
1976
+ cardVersion: passThrough(row["card_version"]),
1977
+ mode: str2(row["mode"]),
1978
+ programId: strOrNull(row["program_id"]),
1979
+ questId: strOrNull(row["quest_id"]),
1980
+ questVersion: numOrNull(row["quest_version"]),
1981
+ campaignId: strOrNull(row["campaign_id"]),
1982
+ title: str2(row["title"]),
1983
+ description: str2(row["description"]),
1984
+ brand: { name: strOrNull(brand["name"]), logoUrl: strOrNull(brand["logo_url"]) },
1985
+ artUrl: strOrNull(row["art_url"]),
1986
+ reward: { rewardId: strOrNull(reward["reward_id"]), name: strOrNull(reward["name"]) },
1987
+ orderMode: str2(row["order_mode"]),
1988
+ status: str2(row["status"]),
1989
+ startsAt: strOrNull(row["starts_at"]),
1990
+ endsAt: strOrNull(row["ends_at"]),
1991
+ completionHours: numOrNull(row["completion_hours"]),
1992
+ completionNote: strOrNull(row["completion_note"]),
1993
+ windowEndsAt: strOrNull(row["window_ends_at"]),
1994
+ completedAt: strOrNull(row["completed_at"]),
1995
+ stepsRequired: passThrough(row["steps_required"]),
1996
+ stepsComplete: passThrough(row["steps_complete"]),
1997
+ steps,
1998
+ rewards: rows(row["rewards"]).map(toCardReward),
1999
+ raw: row
2000
+ };
2001
+ }
2002
+ function toLoyaltyCardsResult(raw) {
2003
+ return {
2004
+ cardVersion: passThrough(raw["card_version"]),
2005
+ cards: rows(raw["cards"]).map(toLoyaltyCard),
2006
+ raw
2007
+ };
2008
+ }
2009
+ function toVaultEntry(row) {
2010
+ return {
2011
+ vaultEntryId: str2(row["vault_entry_id"]),
2012
+ rewardRef: str2(row["reward_ref"]),
2013
+ programId: str2(row["program_id"]),
2014
+ questId: strOrNull(row["quest_id"]),
2015
+ units: str2(row["units"]),
2016
+ state: str2(row["state"]),
2017
+ unlockedAt: strOrNull(row["unlocked_at"]),
2018
+ expiresAt: strOrNull(row["expires_at"]),
2019
+ redeemedAt: strOrNull(row["redeemed_at"]),
2020
+ codeMasked: strOrNull(row["code_masked"]),
2021
+ raw: row
2022
+ };
2023
+ }
2024
+ function toLoyaltyVaultResult(raw) {
2025
+ return { items: rows(raw["items"]).map(toVaultEntry), raw };
2026
+ }
2027
+ function toRedeemRewardResult(raw, vaultEntryId) {
2028
+ return {
2029
+ vaultEntryId: str2(raw["vault_entry_id"] ?? vaultEntryId),
2030
+ rewardRef: str2(raw["reward_ref"]),
2031
+ state: str2(raw["state"]),
2032
+ redeemedAt: strOrNull(raw["redeemed_at"]),
2033
+ code: strOrNull(raw["code"]),
2034
+ codeMasked: strOrNull(raw["code_masked"]),
2035
+ revealedAgain: raw["revealed_again"] === true,
2036
+ revealUntil: strOrNull(raw["reveal_until"]),
2037
+ raw
2038
+ };
2039
+ }
2040
+ function toRewardsPageLink(raw) {
2041
+ return { url: str2(raw["url"]), expiresAt: str2(raw["expires_at"]), raw };
2042
+ }
2043
+
1905
2044
  // src/index.ts
2045
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1906
2046
  function toPendingCollectItem(row) {
1907
2047
  return {
1908
2048
  transferId: String(row["transfer_id"] ?? ""),
@@ -2379,8 +2519,8 @@ var InvoClient = class {
2379
2519
  "/api/sdk/transfers/pending",
2380
2520
  opts?.signal
2381
2521
  );
2382
- const rows = Array.isArray(raw["pending"]) ? raw["pending"] : [];
2383
- return { pending: rows.map(toPendingCollectItem), raw };
2522
+ const rows2 = Array.isArray(raw["pending"]) ? raw["pending"] : [];
2523
+ return { pending: rows2.map(toPendingCollectItem), raw };
2384
2524
  });
2385
2525
  }
2386
2526
  /**
@@ -2407,19 +2547,85 @@ var InvoClient = class {
2407
2547
  async getBalance(opts) {
2408
2548
  return this.withTokenRetry(async () => {
2409
2549
  const raw = await this.get("/api/sdk/balance", opts?.signal);
2410
- const rows = Array.isArray(raw["balances"]) ? raw["balances"] : [];
2550
+ const rows2 = Array.isArray(raw["balances"]) ? raw["balances"] : [];
2411
2551
  const summary = raw["summary"] ?? {};
2412
2552
  return {
2413
2553
  gameId: raw["game_id"] ?? "",
2414
2554
  gameName: String(raw["game_name"] ?? ""),
2415
- balances: rows.map(toBalanceRow),
2555
+ balances: rows2.map(toBalanceRow),
2416
2556
  totalValue: String(summary["total_value"] ?? "0"),
2417
- currencyCount: Number(summary["currency_count"] ?? rows.length),
2557
+ currencyCount: Number(summary["currency_count"] ?? rows2.length),
2418
2558
  hasFunds: summary["has_funds"] === true,
2419
2559
  raw
2420
2560
  };
2421
2561
  });
2422
2562
  }
2563
+ // ---- Loyalty and rewards (player token) ----
2564
+ /**
2565
+ * The signed-in player's loyalty cards in this game: one card per program, each step with
2566
+ * its `state` and `progress` (`{ current, target }`, or `null` when the number could not
2567
+ * be read this time: render `state` alone then), and the rewards the player unlocked.
2568
+ * A card never carries a code; a redeemed reward shows its mask. Your server reads the
2569
+ * same cards for any of your players with `InvoServer.getPlayerRewards(playerEmail)`.
2570
+ */
2571
+ async getMyRewards(opts) {
2572
+ return this.withTokenRetry(async () => {
2573
+ const raw = await this.get("/api/sdk/loyalty/me/card", opts?.signal);
2574
+ return toLoyaltyCardsResult(raw);
2575
+ });
2576
+ }
2577
+ /** Every reward the signed-in player holds or held, newest first. Codes are masked. */
2578
+ async getMyVault(opts) {
2579
+ return this.withTokenRetry(async () => {
2580
+ const raw = await this.get("/api/sdk/loyalty/me/vault", opts?.signal);
2581
+ return toLoyaltyVaultResult(raw);
2582
+ });
2583
+ }
2584
+ /**
2585
+ * Redeem one unlocked reward and return its code. This is the only response that
2586
+ * carries a code: show it straight away and never log, cache or store it. Calling again
2587
+ * for a reward this player already redeemed shows the code once more while the card's
2588
+ * `canRevealAgain` is true (`revealedAgain: true`). Never auto-retried.
2589
+ *
2590
+ * Refusals: `409 already_redeemed` (`err.isRewardAlreadyRedeemed`), `404
2591
+ * vault_entry_not_found` (`err.isRewardNotFound`), `410 vault_entry_expired`
2592
+ * (`err.isRewardExpired`), `409 inventory_exhausted` / `409 conflict`
2593
+ * (`err.isRewardUnavailable`: no units or codes left, or the reward is reserved or revoked).
2594
+ */
2595
+ async redeemReward(vaultEntryId, opts) {
2596
+ if (typeof vaultEntryId !== "string" || !UUID_RE.test(vaultEntryId.trim())) {
2597
+ throw new InvoError({
2598
+ message: `vaultEntryId must be a reward's vaultEntryId (got ${JSON.stringify(vaultEntryId)}).`,
2599
+ code: "INVALID_INPUT",
2600
+ status: 0
2601
+ });
2602
+ }
2603
+ const id = vaultEntryId.trim();
2604
+ return this.withTokenRetry(async () => {
2605
+ const raw = await this.post(
2606
+ `/api/sdk/loyalty/me/vault/${encodeURIComponent(id)}/redeem`,
2607
+ void 0,
2608
+ opts?.signal
2609
+ );
2610
+ return toRedeemRewardResult(raw, id);
2611
+ });
2612
+ }
2613
+ /**
2614
+ * A short-lived link to INVO's hosted "My rewards" page for the signed-in player: their
2615
+ * cards, progress and rewards, with a Redeem button. Open `url` in a browser or web view
2616
+ * (it cannot be embedded in an iframe). Ask for a fresh link each time the player opens
2617
+ * the page; never share or store it.
2618
+ */
2619
+ async getRewardsPageLink(opts) {
2620
+ return this.withTokenRetry(async () => {
2621
+ const raw = await this.post(
2622
+ "/api/sdk/loyalty/me/rewards-page",
2623
+ void 0,
2624
+ opts?.signal
2625
+ );
2626
+ return toRewardsPageLink(raw);
2627
+ });
2628
+ }
2423
2629
  /**
2424
2630
  * First-enrollment OTP grant (§4.2). When `enrollPasskey()` throws
2425
2631
  * `ENROLLMENT_REQUIRES_AUTHORIZATION` (`err.isEnrollmentAuthorizationRequired`), call
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as ApproveResult, C as ConfirmReceiptResult, P as PurchaseStatusResult, a as PurchaseCredited, b as PurchaseExpired, c as PurchaseRefunded, d as PurchaseRefused, e as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, L as LinkDeviceResult, j as PendingCollectResult, D as DestinationsQuery, k as DestinationsResult, B as BalanceResult, E as EnrollmentBeginResult, l as EnrollmentVerifyResult, R as RecoveryBeginResult, m as RecoveryCompleteResult } from './types-BnnVi5ws.cjs';
2
- export { n as BalanceRow, o as CheckoutPurchaseStatus, p as DestinationGame, I as InvoError, q as InvoErrorInfo, r as InvoHooks, s as InvoRequestInfo, t as InvoResponseInfo, u as PendingCollectItem, v as PurchaseRefusalReason, w as Rail, V as VerificationMethod } from './types-BnnVi5ws.cjs';
1
+ import { A as ApproveResult, C as ConfirmReceiptResult, P as PurchaseStatusResult, a as PurchaseCredited, b as PurchaseExpired, c as PurchaseRefunded, d as PurchaseRefused, e as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, L as LinkDeviceResult, j as PendingCollectResult, D as DestinationsQuery, k as DestinationsResult, B as BalanceResult, l as LoyaltyCardsResult, m as LoyaltyVaultResult, R as RedeemRewardResult, n as RewardsPageLink, E as EnrollmentBeginResult, o as EnrollmentVerifyResult, p as RecoveryBeginResult, q as RecoveryCompleteResult } from './types-BwgkJoM6.cjs';
2
+ export { r as BalanceRow, s as CheckoutPurchaseStatus, t as DestinationGame, I as InvoError, u as InvoErrorInfo, v as InvoHooks, w as InvoRequestInfo, x as InvoResponseInfo, y as LoyaltyCard, z as LoyaltyCardReward, F as LoyaltyCardStep, G as LoyaltyRewardState, J as LoyaltyStepProgress, K as LoyaltyStepState, N as LoyaltyVaultEntry, O as PendingCollectItem, Q as PurchaseRefusalReason, S as Rail, V as VerificationMethod } from './types-BwgkJoM6.cjs';
3
3
 
4
4
  /** The four device-approval flows (`begin.flow`). */
5
5
  type HostedFlow = "transfer" | "send" | "send_receipt" | "transfer_receipt";
@@ -362,6 +362,35 @@ declare class InvoClient {
362
362
  * throws. Rows include the currency symbol + icon URL (each may be null).
363
363
  */
364
364
  getBalance(opts?: CallOptions): Promise<BalanceResult>;
365
+ /**
366
+ * The signed-in player's loyalty cards in this game: one card per program, each step with
367
+ * its `state` and `progress` (`{ current, target }`, or `null` when the number could not
368
+ * be read this time: render `state` alone then), and the rewards the player unlocked.
369
+ * A card never carries a code; a redeemed reward shows its mask. Your server reads the
370
+ * same cards for any of your players with `InvoServer.getPlayerRewards(playerEmail)`.
371
+ */
372
+ getMyRewards(opts?: CallOptions): Promise<LoyaltyCardsResult>;
373
+ /** Every reward the signed-in player holds or held, newest first. Codes are masked. */
374
+ getMyVault(opts?: CallOptions): Promise<LoyaltyVaultResult>;
375
+ /**
376
+ * Redeem one unlocked reward and return its code. This is the only response that
377
+ * carries a code: show it straight away and never log, cache or store it. Calling again
378
+ * for a reward this player already redeemed shows the code once more while the card's
379
+ * `canRevealAgain` is true (`revealedAgain: true`). Never auto-retried.
380
+ *
381
+ * Refusals: `409 already_redeemed` (`err.isRewardAlreadyRedeemed`), `404
382
+ * vault_entry_not_found` (`err.isRewardNotFound`), `410 vault_entry_expired`
383
+ * (`err.isRewardExpired`), `409 inventory_exhausted` / `409 conflict`
384
+ * (`err.isRewardUnavailable`: no units or codes left, or the reward is reserved or revoked).
385
+ */
386
+ redeemReward(vaultEntryId: string, opts?: CallOptions): Promise<RedeemRewardResult>;
387
+ /**
388
+ * A short-lived link to INVO's hosted "My rewards" page for the signed-in player: their
389
+ * cards, progress and rewards, with a Redeem button. Open `url` in a browser or web view
390
+ * (it cannot be embedded in an iframe). Ask for a fresh link each time the player opens
391
+ * the page; never share or store it.
392
+ */
393
+ getRewardsPageLink(opts?: CallOptions): Promise<RewardsPageLink>;
365
394
  /**
366
395
  * First-enrollment OTP grant (§4.2). When `enrollPasskey()` throws
367
396
  * `ENROLLMENT_REQUIRES_AUTHORIZATION` (`err.isEnrollmentAuthorizationRequired`), call
@@ -424,4 +453,4 @@ declare class InvoClient {
424
453
  private confirmReceipt;
425
454
  }
426
455
 
427
- export { type ApproveHostedOptions, type ApproveHostedResult, ApproveResult, BalanceResult, CallOptions, CheckoutClient, CheckoutClientConfig, CheckoutMountHandle, ClientConfig, ConfirmReceiptResult, DestinationsQuery, DestinationsResult, EnrollmentBeginResult, type EnrollmentDecision, type EnrollmentRespond, EnrollmentVerifyResult, type HostedApprovalStatus, type HostedEnrollment, type HostedEnrollmentInput, type HostedFlow, InvoClient, LinkDeviceResult, MountCheckoutOptions, PendingCollectResult, PlatformCommerceClient, PurchaseCredited, PurchaseExpired, PurchaseRefunded, PurchaseRefused, PurchaseStatusInput, PurchaseStatusResult, RecoveryBeginResult, RecoveryCompleteResult, WaitForPurchaseInput, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged };
456
+ export { type ApproveHostedOptions, type ApproveHostedResult, ApproveResult, BalanceResult, CallOptions, CheckoutClient, CheckoutClientConfig, CheckoutMountHandle, ClientConfig, ConfirmReceiptResult, DestinationsQuery, DestinationsResult, EnrollmentBeginResult, type EnrollmentDecision, type EnrollmentRespond, EnrollmentVerifyResult, type HostedApprovalStatus, type HostedEnrollment, type HostedEnrollmentInput, type HostedFlow, InvoClient, LinkDeviceResult, LoyaltyCardsResult, LoyaltyVaultResult, MountCheckoutOptions, PendingCollectResult, PlatformCommerceClient, PurchaseCredited, PurchaseExpired, PurchaseRefunded, PurchaseRefused, PurchaseStatusInput, PurchaseStatusResult, RecoveryBeginResult, RecoveryCompleteResult, RedeemRewardResult, RewardsPageLink, WaitForPurchaseInput, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as ApproveResult, C as ConfirmReceiptResult, P as PurchaseStatusResult, a as PurchaseCredited, b as PurchaseExpired, c as PurchaseRefunded, d as PurchaseRefused, e as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, L as LinkDeviceResult, j as PendingCollectResult, D as DestinationsQuery, k as DestinationsResult, B as BalanceResult, E as EnrollmentBeginResult, l as EnrollmentVerifyResult, R as RecoveryBeginResult, m as RecoveryCompleteResult } from './types-BnnVi5ws.js';
2
- export { n as BalanceRow, o as CheckoutPurchaseStatus, p as DestinationGame, I as InvoError, q as InvoErrorInfo, r as InvoHooks, s as InvoRequestInfo, t as InvoResponseInfo, u as PendingCollectItem, v as PurchaseRefusalReason, w as Rail, V as VerificationMethod } from './types-BnnVi5ws.js';
1
+ import { A as ApproveResult, C as ConfirmReceiptResult, P as PurchaseStatusResult, a as PurchaseCredited, b as PurchaseExpired, c as PurchaseRefunded, d as PurchaseRefused, e as CheckoutClientConfig, H as Http, f as PurchaseStatusInput, g as CallOptions, W as WaitForPurchaseInput, M as MountCheckoutOptions, h as CheckoutMountHandle, i as ClientConfig, L as LinkDeviceResult, j as PendingCollectResult, D as DestinationsQuery, k as DestinationsResult, B as BalanceResult, l as LoyaltyCardsResult, m as LoyaltyVaultResult, R as RedeemRewardResult, n as RewardsPageLink, E as EnrollmentBeginResult, o as EnrollmentVerifyResult, p as RecoveryBeginResult, q as RecoveryCompleteResult } from './types-BwgkJoM6.js';
2
+ export { r as BalanceRow, s as CheckoutPurchaseStatus, t as DestinationGame, I as InvoError, u as InvoErrorInfo, v as InvoHooks, w as InvoRequestInfo, x as InvoResponseInfo, y as LoyaltyCard, z as LoyaltyCardReward, F as LoyaltyCardStep, G as LoyaltyRewardState, J as LoyaltyStepProgress, K as LoyaltyStepState, N as LoyaltyVaultEntry, O as PendingCollectItem, Q as PurchaseRefusalReason, S as Rail, V as VerificationMethod } from './types-BwgkJoM6.js';
3
3
 
4
4
  /** The four device-approval flows (`begin.flow`). */
5
5
  type HostedFlow = "transfer" | "send" | "send_receipt" | "transfer_receipt";
@@ -362,6 +362,35 @@ declare class InvoClient {
362
362
  * throws. Rows include the currency symbol + icon URL (each may be null).
363
363
  */
364
364
  getBalance(opts?: CallOptions): Promise<BalanceResult>;
365
+ /**
366
+ * The signed-in player's loyalty cards in this game: one card per program, each step with
367
+ * its `state` and `progress` (`{ current, target }`, or `null` when the number could not
368
+ * be read this time: render `state` alone then), and the rewards the player unlocked.
369
+ * A card never carries a code; a redeemed reward shows its mask. Your server reads the
370
+ * same cards for any of your players with `InvoServer.getPlayerRewards(playerEmail)`.
371
+ */
372
+ getMyRewards(opts?: CallOptions): Promise<LoyaltyCardsResult>;
373
+ /** Every reward the signed-in player holds or held, newest first. Codes are masked. */
374
+ getMyVault(opts?: CallOptions): Promise<LoyaltyVaultResult>;
375
+ /**
376
+ * Redeem one unlocked reward and return its code. This is the only response that
377
+ * carries a code: show it straight away and never log, cache or store it. Calling again
378
+ * for a reward this player already redeemed shows the code once more while the card's
379
+ * `canRevealAgain` is true (`revealedAgain: true`). Never auto-retried.
380
+ *
381
+ * Refusals: `409 already_redeemed` (`err.isRewardAlreadyRedeemed`), `404
382
+ * vault_entry_not_found` (`err.isRewardNotFound`), `410 vault_entry_expired`
383
+ * (`err.isRewardExpired`), `409 inventory_exhausted` / `409 conflict`
384
+ * (`err.isRewardUnavailable`: no units or codes left, or the reward is reserved or revoked).
385
+ */
386
+ redeemReward(vaultEntryId: string, opts?: CallOptions): Promise<RedeemRewardResult>;
387
+ /**
388
+ * A short-lived link to INVO's hosted "My rewards" page for the signed-in player: their
389
+ * cards, progress and rewards, with a Redeem button. Open `url` in a browser or web view
390
+ * (it cannot be embedded in an iframe). Ask for a fresh link each time the player opens
391
+ * the page; never share or store it.
392
+ */
393
+ getRewardsPageLink(opts?: CallOptions): Promise<RewardsPageLink>;
365
394
  /**
366
395
  * First-enrollment OTP grant (§4.2). When `enrollPasskey()` throws
367
396
  * `ENROLLMENT_REQUIRES_AUTHORIZATION` (`err.isEnrollmentAuthorizationRequired`), call
@@ -424,4 +453,4 @@ declare class InvoClient {
424
453
  private confirmReceipt;
425
454
  }
426
455
 
427
- export { type ApproveHostedOptions, type ApproveHostedResult, ApproveResult, BalanceResult, CallOptions, CheckoutClient, CheckoutClientConfig, CheckoutMountHandle, ClientConfig, ConfirmReceiptResult, DestinationsQuery, DestinationsResult, EnrollmentBeginResult, type EnrollmentDecision, type EnrollmentRespond, EnrollmentVerifyResult, type HostedApprovalStatus, type HostedEnrollment, type HostedEnrollmentInput, type HostedFlow, InvoClient, LinkDeviceResult, MountCheckoutOptions, PendingCollectResult, PlatformCommerceClient, PurchaseCredited, PurchaseExpired, PurchaseRefunded, PurchaseRefused, PurchaseStatusInput, PurchaseStatusResult, RecoveryBeginResult, RecoveryCompleteResult, WaitForPurchaseInput, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged };
456
+ export { type ApproveHostedOptions, type ApproveHostedResult, ApproveResult, BalanceResult, CallOptions, CheckoutClient, CheckoutClientConfig, CheckoutMountHandle, ClientConfig, ConfirmReceiptResult, DestinationsQuery, DestinationsResult, EnrollmentBeginResult, type EnrollmentDecision, type EnrollmentRespond, EnrollmentVerifyResult, type HostedApprovalStatus, type HostedEnrollment, type HostedEnrollmentInput, type HostedFlow, InvoClient, LinkDeviceResult, LoyaltyCardsResult, LoyaltyVaultResult, MountCheckoutOptions, PendingCollectResult, PlatformCommerceClient, PurchaseCredited, PurchaseExpired, PurchaseRefunded, PurchaseRefused, PurchaseStatusInput, PurchaseStatusResult, RecoveryBeginResult, RecoveryCompleteResult, RedeemRewardResult, RewardsPageLink, WaitForPurchaseInput, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, nothingWasCharged };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult, receiptFields } from './chunk-YW2PYARQ.js';
2
- export { InvoError } from './chunk-YW2PYARQ.js';
1
+ import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink, receiptFields } from './chunk-6IY4473A.js';
2
+ export { InvoError } from './chunk-6IY4473A.js';
3
3
 
4
4
  // src/shared/webauthn.ts
5
5
  function malformedOptions(field) {
@@ -730,6 +730,7 @@ function nothingWasCharged(r) {
730
730
  }
731
731
 
732
732
  // src/index.ts
733
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
733
734
  function toPendingCollectItem(row) {
734
735
  return {
735
736
  transferId: String(row["transfer_id"] ?? ""),
@@ -1247,6 +1248,72 @@ var InvoClient = class {
1247
1248
  };
1248
1249
  });
1249
1250
  }
1251
+ // ---- Loyalty and rewards (player token) ----
1252
+ /**
1253
+ * The signed-in player's loyalty cards in this game: one card per program, each step with
1254
+ * its `state` and `progress` (`{ current, target }`, or `null` when the number could not
1255
+ * be read this time: render `state` alone then), and the rewards the player unlocked.
1256
+ * A card never carries a code; a redeemed reward shows its mask. Your server reads the
1257
+ * same cards for any of your players with `InvoServer.getPlayerRewards(playerEmail)`.
1258
+ */
1259
+ async getMyRewards(opts) {
1260
+ return this.withTokenRetry(async () => {
1261
+ const raw = await this.get("/api/sdk/loyalty/me/card", opts?.signal);
1262
+ return toLoyaltyCardsResult(raw);
1263
+ });
1264
+ }
1265
+ /** Every reward the signed-in player holds or held, newest first. Codes are masked. */
1266
+ async getMyVault(opts) {
1267
+ return this.withTokenRetry(async () => {
1268
+ const raw = await this.get("/api/sdk/loyalty/me/vault", opts?.signal);
1269
+ return toLoyaltyVaultResult(raw);
1270
+ });
1271
+ }
1272
+ /**
1273
+ * Redeem one unlocked reward and return its code. This is the only response that
1274
+ * carries a code: show it straight away and never log, cache or store it. Calling again
1275
+ * for a reward this player already redeemed shows the code once more while the card's
1276
+ * `canRevealAgain` is true (`revealedAgain: true`). Never auto-retried.
1277
+ *
1278
+ * Refusals: `409 already_redeemed` (`err.isRewardAlreadyRedeemed`), `404
1279
+ * vault_entry_not_found` (`err.isRewardNotFound`), `410 vault_entry_expired`
1280
+ * (`err.isRewardExpired`), `409 inventory_exhausted` / `409 conflict`
1281
+ * (`err.isRewardUnavailable`: no units or codes left, or the reward is reserved or revoked).
1282
+ */
1283
+ async redeemReward(vaultEntryId, opts) {
1284
+ if (typeof vaultEntryId !== "string" || !UUID_RE.test(vaultEntryId.trim())) {
1285
+ throw new InvoError({
1286
+ message: `vaultEntryId must be a reward's vaultEntryId (got ${JSON.stringify(vaultEntryId)}).`,
1287
+ code: "INVALID_INPUT",
1288
+ status: 0
1289
+ });
1290
+ }
1291
+ const id = vaultEntryId.trim();
1292
+ return this.withTokenRetry(async () => {
1293
+ const raw = await this.post(
1294
+ `/api/sdk/loyalty/me/vault/${encodeURIComponent(id)}/redeem`,
1295
+ void 0,
1296
+ opts?.signal
1297
+ );
1298
+ return toRedeemRewardResult(raw, id);
1299
+ });
1300
+ }
1301
+ /**
1302
+ * A short-lived link to INVO's hosted "My rewards" page for the signed-in player: their
1303
+ * cards, progress and rewards, with a Redeem button. Open `url` in a browser or web view
1304
+ * (it cannot be embedded in an iframe). Ask for a fresh link each time the player opens
1305
+ * the page; never share or store it.
1306
+ */
1307
+ async getRewardsPageLink(opts) {
1308
+ return this.withTokenRetry(async () => {
1309
+ const raw = await this.post(
1310
+ "/api/sdk/loyalty/me/rewards-page",
1311
+ void 0,
1312
+ opts?.signal
1313
+ );
1314
+ return toRewardsPageLink(raw);
1315
+ });
1316
+ }
1250
1317
  /**
1251
1318
  * First-enrollment OTP grant (§4.2). When `enrollPasskey()` throws
1252
1319
  * `ENROLLMENT_REQUIRES_AUTHORIZATION` (`err.isEnrollmentAuthorizationRequired`), call