@invonetwork/web-sdk 3.20.0 → 3.22.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.
@@ -7,6 +7,7 @@ var InvoError = class _InvoError extends Error {
7
7
  this.name = "InvoError";
8
8
  this.code = args.code;
9
9
  this.rawCode = args.rawCode ?? args.code;
10
+ this.publicCode = args.publicCode;
10
11
  this.status = args.status;
11
12
  this.body = args.body ?? null;
12
13
  this.requestId = args.requestId;
@@ -392,7 +393,7 @@ var InvoError = class _InvoError extends Error {
392
393
  * unaffected. Raise the amount; do not retry it unchanged.
393
394
  */
394
395
  get isBelowCardMinimum() {
395
- return this.code === "BELOW_CARD_MINIMUM" || this.rawCode === "BELOW_STRIPE_MINIMUM";
396
+ return this.code === "BELOW_CARD_MINIMUM" || this.code === "BELOW_STRIPE_MINIMUM" || this.publicCode === "BELOW_CARD_MINIMUM" || this.rawCode === "BELOW_STRIPE_MINIMUM";
396
397
  }
397
398
  /** On `BELOW_CARD_MINIMUM`: the minimum card purchase in force (`min_usd`), USD decimal
398
399
  * string, for example `"2.99"`. `undefined` when the body does not carry it. */
@@ -820,7 +821,167 @@ var InvoError = class _InvoError extends Error {
820
821
  * `getPlayerRewards` answers it when no player has that email in this game.
821
822
  */
822
823
  get isPlayerNotFound() {
823
- return this.code === "PLAYER_NOT_FOUND";
824
+ if (this.code === "PLAYER_NOT_FOUND") return true;
825
+ return this.status === 404 && this.bodyObject()["error"] === "player_not_found";
826
+ }
827
+ // ---- Player registration, phone changes, identity re-key ----
828
+ /**
829
+ * True when an approve was refused because the player token predates a change to the
830
+ * sender's identity (`PLAYER_TOKEN_STALE`, 403): their phone was added (for example on
831
+ * the initiate), which gives them a new identity. Nothing moved and the token stays
832
+ * refused. Re-mint the player token (or use the `playerToken` from the initiate result)
833
+ * and retry once. The SDK never retries a money call on its own.
834
+ */
835
+ get isPlayerTokenStale() {
836
+ return this.code === "PLAYER_TOKEN_STALE";
837
+ }
838
+ /**
839
+ * True when `updatePlayerPhone` was refused because the player has secured this account,
840
+ * so the change needs the player's own confirmation (`PHONE_CHANGE_REQUIRES_VERIFICATION`,
841
+ * 409). Nothing changed. Call `requestPhoneChange`: INVO emails the player, who confirms
842
+ * on INVO's page. {@link changeRequestEndpoint} names the route.
843
+ */
844
+ get isPhoneChangeRequiresVerification() {
845
+ return this.code === "PHONE_CHANGE_REQUIRES_VERIFICATION";
846
+ }
847
+ /**
848
+ * On `PHONE_CHANGE_REQUIRES_VERIFICATION`: the route to create a change request on, as INVO
849
+ * returned it (`change_request_endpoint`; it carries the `/sandbox` prefix in sandbox).
850
+ * `requestPhoneChange` already calls it. `undefined` when the body does not carry it.
851
+ */
852
+ get changeRequestEndpoint() {
853
+ const v = this.bodyObject()["change_request_endpoint"];
854
+ return typeof v === "string" && v ? v : void 0;
855
+ }
856
+ // ---- Player-confirmed phone change (change requests) ----
857
+ /**
858
+ * True when a game tried to confirm a phone change itself (`CONFIRM_ON_INVO_PAGE`, 409).
859
+ * The player confirms only on INVO's page, from the link in INVO's email; a game never
860
+ * collects the code.
861
+ */
862
+ get isConfirmOnInvoPage() {
863
+ return this.code === "CONFIRM_ON_INVO_PAGE";
864
+ }
865
+ /**
866
+ * True when the change request is unknown, belongs to another game (`getPhoneChange`), or
867
+ * to another player (`approvePhoneChange`) (`CHANGE_REQUEST_NOT_FOUND`, 404).
868
+ */
869
+ get isChangeRequestNotFound() {
870
+ return this.code === "CHANGE_REQUEST_NOT_FOUND";
871
+ }
872
+ /**
873
+ * True when `approvePhoneChange` came before the player entered the emailed code on INVO's
874
+ * page (`CHANGE_REQUEST_NOT_READY`, 409). Nothing changed; approve after they do.
875
+ */
876
+ get isChangeRequestNotReady() {
877
+ return this.code === "CHANGE_REQUEST_NOT_READY";
878
+ }
879
+ /**
880
+ * True when the change request is no longer pending (`CHANGE_REQUEST_NOT_PENDING`, 409):
881
+ * already confirmed, expired, cancelled, refused or declined. See
882
+ * {@link changeRequestStatus}.
883
+ */
884
+ get isChangeRequestNotPending() {
885
+ return this.code === "CHANGE_REQUEST_NOT_PENDING";
886
+ }
887
+ /** On `CHANGE_REQUEST_NOT_PENDING`: the request's current `status`. */
888
+ get changeRequestStatus() {
889
+ if (this.code !== "CHANGE_REQUEST_NOT_PENDING") return void 0;
890
+ const v = this.bodyObject()["status"];
891
+ return typeof v === "string" && v ? v : void 0;
892
+ }
893
+ /**
894
+ * True when another game's change request for this player is waiting for the player
895
+ * (`CHANGE_REQUEST_IN_PROGRESS`, 409). Retry after it is confirmed or expires.
896
+ */
897
+ get isChangeRequestInProgress() {
898
+ return this.code === "CHANGE_REQUEST_IN_PROGRESS";
899
+ }
900
+ /**
901
+ * True when phone changes for this player are paused after repeated failed confirmations
902
+ * (`PHONE_CHANGE_LOCKED`, 409). The player has been emailed. Retry later.
903
+ */
904
+ get isPhoneChangeLocked() {
905
+ return this.code === "PHONE_CHANGE_LOCKED";
906
+ }
907
+ /**
908
+ * True when `requestPhoneChange` was refused because there were too many change requests
909
+ * for this player (`TOO_MANY_CHANGE_REQUESTS`, 429). Try again later; do not loop.
910
+ */
911
+ get isTooManyChangeRequests() {
912
+ return this.code === "TOO_MANY_CHANGE_REQUESTS";
913
+ }
914
+ /**
915
+ * True when a phone change call could not be served right now (`PHONE_CHANGE_UNAVAILABLE`,
916
+ * 503) or the confirmation email could not be sent (`CONFIRMATION_EMAIL_UNAVAILABLE`, 503;
917
+ * that request is closed). Retry shortly.
918
+ */
919
+ get isPhoneChangeUnavailable() {
920
+ return this.code === "PHONE_CHANGE_UNAVAILABLE" || this.code === "CONFIRMATION_EMAIL_UNAVAILABLE";
921
+ }
922
+ /**
923
+ * True when a phone change was refused because transfers to the player's CURRENT number
924
+ * are still waiting to be collected (`PENDING_TRANSFERS_TO_OLD_PHONE`, 409), on
925
+ * `updatePlayerPhone`, `requestPhoneChange` or `approvePhoneChange`. Changing the number
926
+ * now would strand them. Nothing changed. Ask the player to collect them first (or wait
927
+ * until they expire), then retry.
928
+ */
929
+ get isPendingTransfersToOldPhone() {
930
+ return this.code === "PENDING_TRANSFERS_TO_OLD_PHONE";
931
+ }
932
+ /**
933
+ * True when a phone change was refused because transfers to the NEW number are still
934
+ * waiting to be collected (`PENDING_TRANSFERS_TO_NEW_PHONE`, 409), on `updatePlayerPhone`,
935
+ * `requestPhoneChange` or `approvePhoneChange`. Nothing changed. Retry after they are
936
+ * collected or expire.
937
+ */
938
+ get isPendingTransfersToNewPhone() {
939
+ return this.code === "PENDING_TRANSFERS_TO_NEW_PHONE";
940
+ }
941
+ /**
942
+ * True when the player's account recently went through a sign-in recovery, so the number
943
+ * cannot be changed yet (`PHONE_CHANGE_RECOVERY_COOLDOWN`, 409), on `requestPhoneChange`
944
+ * or `approvePhoneChange`. Nothing changed. Retry later; on `approvePhoneChange`,
945
+ * declining (`decision: "deny"`) still works.
946
+ */
947
+ get isPhoneChangeRecoveryCooldown() {
948
+ return this.code === "PHONE_CHANGE_RECOVERY_COOLDOWN";
949
+ }
950
+ /**
951
+ * True when `approvePhoneChange` was refused because this device (or its key) was set up
952
+ * after the change was requested, so it cannot approve it
953
+ * (`DEVICE_ENROLLED_AFTER_REQUEST`, 409). Nothing changed. The player approves on their
954
+ * earlier device, or your game creates a new request.
955
+ */
956
+ get isDeviceEnrolledAfterRequest() {
957
+ return this.code === "DEVICE_ENROLLED_AFTER_REQUEST";
958
+ }
959
+ /**
960
+ * True when `approvePhoneChange` was refused because the device signal did not verify
961
+ * (401, the reason in `error`, for example `SIGNAL_INVALID`). Nothing changed. Sign the
962
+ * exact message again with a fresh nonce and timestamp.
963
+ */
964
+ get isDeviceSignalRejected() {
965
+ if (this.status !== 401) return false;
966
+ const e = this.bodyObject()["error"];
967
+ return typeof e === "string" && e.startsWith("SIGNAL_");
968
+ }
969
+ /**
970
+ * True when `registerPlayer` found the player already in your game with a DIFFERENT
971
+ * phone (`PHONE_MISMATCH`, 409). Nothing changed; use `updatePlayerPhone` to change it.
972
+ * (`mintPlayerToken` reports the same situation as `phoneMismatch: true` on success.)
973
+ */
974
+ get isPhoneMismatch() {
975
+ return this.code === "PHONE_MISMATCH";
976
+ }
977
+ /**
978
+ * True when the phone you supplied belongs to another email
979
+ * (`PHONE_SHARE_APPROVAL_REQUIRED`, 409) on `mintPlayerToken`, `registerPlayer` or
980
+ * `updatePlayerPhone`. Nothing was created or changed. The same condition as
981
+ * {@link isPhoneShareApprovalRequired}, named for these registration calls.
982
+ */
983
+ get isPhoneShareRefused() {
984
+ return this.isPhoneShareApprovalRequired;
824
985
  }
825
986
  /**
826
987
  * True when `cards.createSetupSession` was asked to create a new member (`playerName`
@@ -920,11 +1081,13 @@ function errorFromResponse(status, body, requestId) {
920
1081
  let message = `INVO request failed (HTTP ${status})`;
921
1082
  let code;
922
1083
  let rawCode;
1084
+ let publicCode;
923
1085
  if (body && typeof body === "object") {
924
1086
  const b = body;
925
1087
  if (typeof b["code"] === "string") rawCode = b["code"];
926
1088
  else if (typeof b["error_code"] === "string") rawCode = b["error_code"];
927
- code = typeof b["error_code_public"] === "string" ? b["error_code_public"] : rawCode;
1089
+ if (typeof b["error_code_public"] === "string") publicCode = b["error_code_public"];
1090
+ code = publicCode ?? rawCode;
928
1091
  if (typeof b["error"] === "string") message = b["error"];
929
1092
  else if (typeof b["message"] === "string") message = b["message"];
930
1093
  if (!code && typeof b["error"] === "string" && /^(flow_paused|spending_limit_exceeded|receiver_not_enrolled_use_claim_code|no_channel_on_file|rate_limited|service_unavailable|authorization_pending|slow_down|expired_token|access_denied|invalid_grant)$/.test(
@@ -936,7 +1099,7 @@ function errorFromResponse(status, body, requestId) {
936
1099
  } else if (typeof body === "string" && body.trim()) {
937
1100
  message = body;
938
1101
  }
939
- return new InvoError({ message, code, rawCode, status, body, requestId });
1102
+ return new InvoError({ message, code, rawCode, publicCode, status, body, requestId });
940
1103
  }
941
1104
 
942
1105
  // src/shared/http.ts
@@ -1320,6 +1483,93 @@ function toRewardsPageLink(raw) {
1320
1483
  return { url: str(raw["url"]), expiresAt: str(raw["expires_at"]), raw };
1321
1484
  }
1322
1485
 
1323
- export { Http, InvoError, assertSecureBaseUrl, creditFields, receiptFields, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink };
1324
- //# sourceMappingURL=chunk-6IY4473A.js.map
1325
- //# sourceMappingURL=chunk-6IY4473A.js.map
1486
+ // src/shared/phone-change.ts
1487
+ function phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision = "approve") {
1488
+ const action = decision === "deny" ? "phone-change-deny" : "phone-change";
1489
+ return `${action}|${changeRequestId}|${nonce}|${Math.trunc(timestamp)}`;
1490
+ }
1491
+ function requireField(value, field, raw) {
1492
+ const s = value == null ? "" : String(value);
1493
+ if (!s) {
1494
+ throw new InvoError({
1495
+ message: `INVO response was missing the required \`${field}\` field.`,
1496
+ code: "INVALID_RESPONSE",
1497
+ status: 0,
1498
+ body: raw
1499
+ });
1500
+ }
1501
+ return s;
1502
+ }
1503
+ var str2 = (v) => v == null ? "" : String(v);
1504
+ var strOrNull2 = (v) => typeof v === "string" ? v : v == null ? null : String(v);
1505
+ function toRequestPhoneChangeResult(raw) {
1506
+ return {
1507
+ changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
1508
+ status: requireField(raw["status"], "status", raw),
1509
+ expiresAt: str2(raw["expires_at"]),
1510
+ delivery: str2(raw["delivery"]),
1511
+ confirmation: str2(raw["confirmation"]),
1512
+ message: str2(raw["message"]),
1513
+ raw
1514
+ };
1515
+ }
1516
+ function toPhoneChangeRequest(raw) {
1517
+ return {
1518
+ changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
1519
+ status: requireField(raw["status"], "status", raw),
1520
+ confirmation: str2(raw["confirmation"]),
1521
+ delivery: str2(raw["delivery"]),
1522
+ newPhoneMasked: strOrNull2(raw["new_phone_masked"]),
1523
+ createdAt: strOrNull2(raw["created_at"]),
1524
+ expiresAt: strOrNull2(raw["expires_at"]),
1525
+ confirmedAt: strOrNull2(raw["confirmed_at"]),
1526
+ confirmedVia: strOrNull2(raw["confirmed_via"]),
1527
+ raw
1528
+ };
1529
+ }
1530
+ function toPhoneChangeApprovalsResult(raw) {
1531
+ const rows2 = Array.isArray(raw["approvals"]) ? raw["approvals"] : [];
1532
+ const approvals = rows2.filter((r) => r && typeof r === "object").map((r) => ({
1533
+ changeRequestId: str2(r["change_request_id"]),
1534
+ gameName: strOrNull2(r["game_name"]),
1535
+ oldPhoneMasked: strOrNull2(r["old_phone_masked"]),
1536
+ newPhoneMasked: strOrNull2(r["new_phone_masked"]),
1537
+ expiresAt: strOrNull2(r["expires_at"])
1538
+ }));
1539
+ return { approvals, raw };
1540
+ }
1541
+ function toApprovePhoneChangeResult(raw, changeRequestId) {
1542
+ const id = str2(raw["change_request_id"] ?? changeRequestId);
1543
+ const status = requireField(raw["status"], "status", raw);
1544
+ if (status === "denied") {
1545
+ return { status: "denied", changeRequestId: id, raw };
1546
+ }
1547
+ if (status !== "confirmed") {
1548
+ throw new InvoError({
1549
+ message: `INVO answered an unexpected phone change status \`${status}\`.`,
1550
+ code: "INVALID_RESPONSE",
1551
+ status: 0,
1552
+ body: raw
1553
+ });
1554
+ }
1555
+ const out = {
1556
+ status: "confirmed",
1557
+ changeRequestId: id,
1558
+ identityId: str2(raw["identity_id"]),
1559
+ previousIdentityId: str2(raw["previous_identity_id"]),
1560
+ playersUpdated: Number(raw["players_updated"] ?? 0) || 0,
1561
+ verifiedPhone: raw["verified_phone"] === true,
1562
+ raw
1563
+ };
1564
+ if (typeof raw["player_token"] === "string" && raw["player_token"]) {
1565
+ out.playerToken = raw["player_token"];
1566
+ if (typeof raw["player_token_expires_at"] === "string") {
1567
+ out.playerTokenExpiresAt = raw["player_token_expires_at"];
1568
+ }
1569
+ }
1570
+ return out;
1571
+ }
1572
+
1573
+ export { Http, InvoError, assertSecureBaseUrl, creditFields, phoneChangeSignalMessage, receiptFields, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toPhoneChangeApprovalsResult, toPhoneChangeRequest, toRedeemRewardResult, toRequestPhoneChangeResult, toRewardsPageLink };
1574
+ //# sourceMappingURL=chunk-BOD4WOWO.js.map
1575
+ //# sourceMappingURL=chunk-BOD4WOWO.js.map