@invonetwork/web-sdk 3.21.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. */
@@ -837,11 +838,134 @@ var InvoError = class _InvoError extends Error {
837
838
  /**
838
839
  * True when `updatePlayerPhone` was refused because the player has secured this account,
839
840
  * so the change needs the player's own confirmation (`PHONE_CHANGE_REQUIRES_VERIFICATION`,
840
- * 409). Nothing changed. Until that confirmation flow is available, contact INVO support.
841
+ * 409). Nothing changed. Call `requestPhoneChange`: INVO emails the player, who confirms
842
+ * on INVO's page. {@link changeRequestEndpoint} names the route.
841
843
  */
842
844
  get isPhoneChangeRequiresVerification() {
843
845
  return this.code === "PHONE_CHANGE_REQUIRES_VERIFICATION";
844
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
+ }
845
969
  /**
846
970
  * True when `registerPlayer` found the player already in your game with a DIFFERENT
847
971
  * phone (`PHONE_MISMATCH`, 409). Nothing changed; use `updatePlayerPhone` to change it.
@@ -957,11 +1081,13 @@ function errorFromResponse(status, body, requestId) {
957
1081
  let message = `INVO request failed (HTTP ${status})`;
958
1082
  let code;
959
1083
  let rawCode;
1084
+ let publicCode;
960
1085
  if (body && typeof body === "object") {
961
1086
  const b = body;
962
1087
  if (typeof b["code"] === "string") rawCode = b["code"];
963
1088
  else if (typeof b["error_code"] === "string") rawCode = b["error_code"];
964
- 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;
965
1091
  if (typeof b["error"] === "string") message = b["error"];
966
1092
  else if (typeof b["message"] === "string") message = b["message"];
967
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(
@@ -973,7 +1099,7 @@ function errorFromResponse(status, body, requestId) {
973
1099
  } else if (typeof body === "string" && body.trim()) {
974
1100
  message = body;
975
1101
  }
976
- return new InvoError({ message, code, rawCode, status, body, requestId });
1102
+ return new InvoError({ message, code, rawCode, publicCode, status, body, requestId });
977
1103
  }
978
1104
 
979
1105
  // src/shared/http.ts
@@ -1357,6 +1483,93 @@ function toRewardsPageLink(raw) {
1357
1483
  return { url: str(raw["url"]), expiresAt: str(raw["expires_at"]), raw };
1358
1484
  }
1359
1485
 
1360
- export { Http, InvoError, assertSecureBaseUrl, creditFields, receiptFields, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink };
1361
- //# sourceMappingURL=chunk-7L4O5Q7K.js.map
1362
- //# sourceMappingURL=chunk-7L4O5Q7K.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
package/dist/index.cjs CHANGED
@@ -9,6 +9,7 @@ var InvoError = class _InvoError extends Error {
9
9
  this.name = "InvoError";
10
10
  this.code = args.code;
11
11
  this.rawCode = args.rawCode ?? args.code;
12
+ this.publicCode = args.publicCode;
12
13
  this.status = args.status;
13
14
  this.body = args.body ?? null;
14
15
  this.requestId = args.requestId;
@@ -394,7 +395,7 @@ var InvoError = class _InvoError extends Error {
394
395
  * unaffected. Raise the amount; do not retry it unchanged.
395
396
  */
396
397
  get isBelowCardMinimum() {
397
- return this.code === "BELOW_CARD_MINIMUM" || this.rawCode === "BELOW_STRIPE_MINIMUM";
398
+ return this.code === "BELOW_CARD_MINIMUM" || this.code === "BELOW_STRIPE_MINIMUM" || this.publicCode === "BELOW_CARD_MINIMUM" || this.rawCode === "BELOW_STRIPE_MINIMUM";
398
399
  }
399
400
  /** On `BELOW_CARD_MINIMUM`: the minimum card purchase in force (`min_usd`), USD decimal
400
401
  * string, for example `"2.99"`. `undefined` when the body does not carry it. */
@@ -839,11 +840,134 @@ var InvoError = class _InvoError extends Error {
839
840
  /**
840
841
  * True when `updatePlayerPhone` was refused because the player has secured this account,
841
842
  * so the change needs the player's own confirmation (`PHONE_CHANGE_REQUIRES_VERIFICATION`,
842
- * 409). Nothing changed. Until that confirmation flow is available, contact INVO support.
843
+ * 409). Nothing changed. Call `requestPhoneChange`: INVO emails the player, who confirms
844
+ * on INVO's page. {@link changeRequestEndpoint} names the route.
843
845
  */
844
846
  get isPhoneChangeRequiresVerification() {
845
847
  return this.code === "PHONE_CHANGE_REQUIRES_VERIFICATION";
846
848
  }
849
+ /**
850
+ * On `PHONE_CHANGE_REQUIRES_VERIFICATION`: the route to create a change request on, as INVO
851
+ * returned it (`change_request_endpoint`; it carries the `/sandbox` prefix in sandbox).
852
+ * `requestPhoneChange` already calls it. `undefined` when the body does not carry it.
853
+ */
854
+ get changeRequestEndpoint() {
855
+ const v = this.bodyObject()["change_request_endpoint"];
856
+ return typeof v === "string" && v ? v : void 0;
857
+ }
858
+ // ---- Player-confirmed phone change (change requests) ----
859
+ /**
860
+ * True when a game tried to confirm a phone change itself (`CONFIRM_ON_INVO_PAGE`, 409).
861
+ * The player confirms only on INVO's page, from the link in INVO's email; a game never
862
+ * collects the code.
863
+ */
864
+ get isConfirmOnInvoPage() {
865
+ return this.code === "CONFIRM_ON_INVO_PAGE";
866
+ }
867
+ /**
868
+ * True when the change request is unknown, belongs to another game (`getPhoneChange`), or
869
+ * to another player (`approvePhoneChange`) (`CHANGE_REQUEST_NOT_FOUND`, 404).
870
+ */
871
+ get isChangeRequestNotFound() {
872
+ return this.code === "CHANGE_REQUEST_NOT_FOUND";
873
+ }
874
+ /**
875
+ * True when `approvePhoneChange` came before the player entered the emailed code on INVO's
876
+ * page (`CHANGE_REQUEST_NOT_READY`, 409). Nothing changed; approve after they do.
877
+ */
878
+ get isChangeRequestNotReady() {
879
+ return this.code === "CHANGE_REQUEST_NOT_READY";
880
+ }
881
+ /**
882
+ * True when the change request is no longer pending (`CHANGE_REQUEST_NOT_PENDING`, 409):
883
+ * already confirmed, expired, cancelled, refused or declined. See
884
+ * {@link changeRequestStatus}.
885
+ */
886
+ get isChangeRequestNotPending() {
887
+ return this.code === "CHANGE_REQUEST_NOT_PENDING";
888
+ }
889
+ /** On `CHANGE_REQUEST_NOT_PENDING`: the request's current `status`. */
890
+ get changeRequestStatus() {
891
+ if (this.code !== "CHANGE_REQUEST_NOT_PENDING") return void 0;
892
+ const v = this.bodyObject()["status"];
893
+ return typeof v === "string" && v ? v : void 0;
894
+ }
895
+ /**
896
+ * True when another game's change request for this player is waiting for the player
897
+ * (`CHANGE_REQUEST_IN_PROGRESS`, 409). Retry after it is confirmed or expires.
898
+ */
899
+ get isChangeRequestInProgress() {
900
+ return this.code === "CHANGE_REQUEST_IN_PROGRESS";
901
+ }
902
+ /**
903
+ * True when phone changes for this player are paused after repeated failed confirmations
904
+ * (`PHONE_CHANGE_LOCKED`, 409). The player has been emailed. Retry later.
905
+ */
906
+ get isPhoneChangeLocked() {
907
+ return this.code === "PHONE_CHANGE_LOCKED";
908
+ }
909
+ /**
910
+ * True when `requestPhoneChange` was refused because there were too many change requests
911
+ * for this player (`TOO_MANY_CHANGE_REQUESTS`, 429). Try again later; do not loop.
912
+ */
913
+ get isTooManyChangeRequests() {
914
+ return this.code === "TOO_MANY_CHANGE_REQUESTS";
915
+ }
916
+ /**
917
+ * True when a phone change call could not be served right now (`PHONE_CHANGE_UNAVAILABLE`,
918
+ * 503) or the confirmation email could not be sent (`CONFIRMATION_EMAIL_UNAVAILABLE`, 503;
919
+ * that request is closed). Retry shortly.
920
+ */
921
+ get isPhoneChangeUnavailable() {
922
+ return this.code === "PHONE_CHANGE_UNAVAILABLE" || this.code === "CONFIRMATION_EMAIL_UNAVAILABLE";
923
+ }
924
+ /**
925
+ * True when a phone change was refused because transfers to the player's CURRENT number
926
+ * are still waiting to be collected (`PENDING_TRANSFERS_TO_OLD_PHONE`, 409), on
927
+ * `updatePlayerPhone`, `requestPhoneChange` or `approvePhoneChange`. Changing the number
928
+ * now would strand them. Nothing changed. Ask the player to collect them first (or wait
929
+ * until they expire), then retry.
930
+ */
931
+ get isPendingTransfersToOldPhone() {
932
+ return this.code === "PENDING_TRANSFERS_TO_OLD_PHONE";
933
+ }
934
+ /**
935
+ * True when a phone change was refused because transfers to the NEW number are still
936
+ * waiting to be collected (`PENDING_TRANSFERS_TO_NEW_PHONE`, 409), on `updatePlayerPhone`,
937
+ * `requestPhoneChange` or `approvePhoneChange`. Nothing changed. Retry after they are
938
+ * collected or expire.
939
+ */
940
+ get isPendingTransfersToNewPhone() {
941
+ return this.code === "PENDING_TRANSFERS_TO_NEW_PHONE";
942
+ }
943
+ /**
944
+ * True when the player's account recently went through a sign-in recovery, so the number
945
+ * cannot be changed yet (`PHONE_CHANGE_RECOVERY_COOLDOWN`, 409), on `requestPhoneChange`
946
+ * or `approvePhoneChange`. Nothing changed. Retry later; on `approvePhoneChange`,
947
+ * declining (`decision: "deny"`) still works.
948
+ */
949
+ get isPhoneChangeRecoveryCooldown() {
950
+ return this.code === "PHONE_CHANGE_RECOVERY_COOLDOWN";
951
+ }
952
+ /**
953
+ * True when `approvePhoneChange` was refused because this device (or its key) was set up
954
+ * after the change was requested, so it cannot approve it
955
+ * (`DEVICE_ENROLLED_AFTER_REQUEST`, 409). Nothing changed. The player approves on their
956
+ * earlier device, or your game creates a new request.
957
+ */
958
+ get isDeviceEnrolledAfterRequest() {
959
+ return this.code === "DEVICE_ENROLLED_AFTER_REQUEST";
960
+ }
961
+ /**
962
+ * True when `approvePhoneChange` was refused because the device signal did not verify
963
+ * (401, the reason in `error`, for example `SIGNAL_INVALID`). Nothing changed. Sign the
964
+ * exact message again with a fresh nonce and timestamp.
965
+ */
966
+ get isDeviceSignalRejected() {
967
+ if (this.status !== 401) return false;
968
+ const e = this.bodyObject()["error"];
969
+ return typeof e === "string" && e.startsWith("SIGNAL_");
970
+ }
847
971
  /**
848
972
  * True when `registerPlayer` found the player already in your game with a DIFFERENT
849
973
  * phone (`PHONE_MISMATCH`, 409). Nothing changed; use `updatePlayerPhone` to change it.
@@ -959,11 +1083,13 @@ function errorFromResponse(status, body, requestId) {
959
1083
  let message = `INVO request failed (HTTP ${status})`;
960
1084
  let code;
961
1085
  let rawCode;
1086
+ let publicCode;
962
1087
  if (body && typeof body === "object") {
963
1088
  const b = body;
964
1089
  if (typeof b["code"] === "string") rawCode = b["code"];
965
1090
  else if (typeof b["error_code"] === "string") rawCode = b["error_code"];
966
- code = typeof b["error_code_public"] === "string" ? b["error_code_public"] : rawCode;
1091
+ if (typeof b["error_code_public"] === "string") publicCode = b["error_code_public"];
1092
+ code = publicCode ?? rawCode;
967
1093
  if (typeof b["error"] === "string") message = b["error"];
968
1094
  else if (typeof b["message"] === "string") message = b["message"];
969
1095
  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(
@@ -975,7 +1101,7 @@ function errorFromResponse(status, body, requestId) {
975
1101
  } else if (typeof body === "string" && body.trim()) {
976
1102
  message = body;
977
1103
  }
978
- return new InvoError({ message, code, rawCode, status, body, requestId });
1104
+ return new InvoError({ message, code, rawCode, publicCode, status, body, requestId });
979
1105
  }
980
1106
 
981
1107
  // src/shared/http.ts
@@ -2078,7 +2204,82 @@ function toRewardsPageLink(raw) {
2078
2204
  return { url: str2(raw["url"]), expiresAt: str2(raw["expires_at"]), raw };
2079
2205
  }
2080
2206
 
2207
+ // src/shared/phone-change.ts
2208
+ function phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision = "approve") {
2209
+ const action = decision === "deny" ? "phone-change-deny" : "phone-change";
2210
+ return `${action}|${changeRequestId}|${nonce}|${Math.trunc(timestamp)}`;
2211
+ }
2212
+ function requireField(value, field, raw) {
2213
+ const s = value == null ? "" : String(value);
2214
+ if (!s) {
2215
+ throw new InvoError({
2216
+ message: `INVO response was missing the required \`${field}\` field.`,
2217
+ code: "INVALID_RESPONSE",
2218
+ status: 0,
2219
+ body: raw
2220
+ });
2221
+ }
2222
+ return s;
2223
+ }
2224
+ var str3 = (v) => v == null ? "" : String(v);
2225
+ var strOrNull2 = (v) => typeof v === "string" ? v : v == null ? null : String(v);
2226
+ function toPhoneChangeApprovalsResult(raw) {
2227
+ const rows2 = Array.isArray(raw["approvals"]) ? raw["approvals"] : [];
2228
+ const approvals = rows2.filter((r) => r && typeof r === "object").map((r) => ({
2229
+ changeRequestId: str3(r["change_request_id"]),
2230
+ gameName: strOrNull2(r["game_name"]),
2231
+ oldPhoneMasked: strOrNull2(r["old_phone_masked"]),
2232
+ newPhoneMasked: strOrNull2(r["new_phone_masked"]),
2233
+ expiresAt: strOrNull2(r["expires_at"])
2234
+ }));
2235
+ return { approvals, raw };
2236
+ }
2237
+ function toApprovePhoneChangeResult(raw, changeRequestId) {
2238
+ const id = str3(raw["change_request_id"] ?? changeRequestId);
2239
+ const status = requireField(raw["status"], "status", raw);
2240
+ if (status === "denied") {
2241
+ return { status: "denied", changeRequestId: id, raw };
2242
+ }
2243
+ if (status !== "confirmed") {
2244
+ throw new InvoError({
2245
+ message: `INVO answered an unexpected phone change status \`${status}\`.`,
2246
+ code: "INVALID_RESPONSE",
2247
+ status: 0,
2248
+ body: raw
2249
+ });
2250
+ }
2251
+ const out = {
2252
+ status: "confirmed",
2253
+ changeRequestId: id,
2254
+ identityId: str3(raw["identity_id"]),
2255
+ previousIdentityId: str3(raw["previous_identity_id"]),
2256
+ playersUpdated: Number(raw["players_updated"] ?? 0) || 0,
2257
+ verifiedPhone: raw["verified_phone"] === true,
2258
+ raw
2259
+ };
2260
+ if (typeof raw["player_token"] === "string" && raw["player_token"]) {
2261
+ out.playerToken = raw["player_token"];
2262
+ if (typeof raw["player_token_expires_at"] === "string") {
2263
+ out.playerTokenExpiresAt = raw["player_token_expires_at"];
2264
+ }
2265
+ }
2266
+ return out;
2267
+ }
2268
+
2081
2269
  // src/index.ts
2270
+ function clientInvalidInput(message) {
2271
+ return new InvoError({ message, code: "INVALID_INPUT", status: 0 });
2272
+ }
2273
+ function randomNonce() {
2274
+ const c = globalThis.crypto;
2275
+ if (!c || typeof c.getRandomValues !== "function") {
2276
+ throw clientInvalidInput(
2277
+ "No secure random source in this environment; pass a deviceSignal you built yourself."
2278
+ );
2279
+ }
2280
+ const bytes = c.getRandomValues(new Uint8Array(16));
2281
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
2282
+ }
2082
2283
  var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2083
2284
  function toPendingCollectItem(row) {
2084
2285
  return {
@@ -2515,6 +2716,99 @@ var InvoClient = class {
2515
2716
  async confirmReceiptTransfer(transactionId, opts) {
2516
2717
  return this.confirmReceipt("transfers", transactionId, opts);
2517
2718
  }
2719
+ /**
2720
+ * Phone changes waiting for THIS player's enrolled device to approve
2721
+ * (`GET /api/sdk/players/phone/change-approvals`, player token). A row appears after the
2722
+ * player entered the emailed code on INVO's page for a change whose `confirmation` is
2723
+ * `"email_code_and_device"`. Show each one ("Approve changing your number to
2724
+ * ***-***-0123?") and answer it with {@link approvePhoneChange}. Read-only.
2725
+ */
2726
+ async listPhoneChangeApprovals(opts) {
2727
+ return this.withTokenRetry(async () => {
2728
+ const raw = await this.get(
2729
+ "/api/sdk/players/phone/change-approvals",
2730
+ opts?.signal
2731
+ );
2732
+ return toPhoneChangeApprovalsResult(raw);
2733
+ });
2734
+ }
2735
+ /**
2736
+ * Approve (or, with `decision: "deny"`, decline) a phone change from the player's enrolled
2737
+ * device (`POST /api/sdk/players/phone/change-requests/{id}/approve`, player token).
2738
+ *
2739
+ * The device key signs `phone-change|<changeRequestId>|<nonce>|<timestamp>` to approve or
2740
+ * `phone-change-deny|<changeRequestId>|<nonce>|<timestamp>` to decline (`timestamp` in
2741
+ * epoch seconds). Either pass `sign`, and the SDK makes a fresh nonce and timestamp, builds
2742
+ * that message and asks you for the base64 signature; or pass a `deviceSignal` you signed
2743
+ * yourself (build the message with {@link phoneChangeSignalMessage}). This is a device key
2744
+ * registered with INVO, not a passkey.
2745
+ *
2746
+ * `status: "confirmed"` means the change is applied: store `identityId` and use
2747
+ * `playerToken` (tokens minted before the change are stale). `status: "denied"` means
2748
+ * nothing changed. Refusals: 409 `err.isChangeRequestNotReady` (the player has not entered
2749
+ * the code on INVO's page yet), 409 `err.isChangeRequestNotPending` (`err.changeRequestStatus`),
2750
+ * 409 `err.isDeviceEnrolledAfterRequest` (this device was set up after the change was
2751
+ * requested; approve on the earlier device, or the game creates a new request), 409
2752
+ * `err.isPhoneChangeRecoveryCooldown` (a recent sign-in recovery; retry later, declining
2753
+ * still works), 404 `err.isChangeRequestNotFound`, 401 `err.isDeviceSignalRejected`, 403
2754
+ * `DEVICE_REQUIRES_ELEVATION`, or any refusal of the change itself (for example
2755
+ * `err.isPendingTransfersToOldPhone`).
2756
+ */
2757
+ async approvePhoneChange(changeRequestId, input, opts) {
2758
+ if (typeof changeRequestId !== "string" || !changeRequestId.trim()) {
2759
+ throw clientInvalidInput("changeRequestId is required.");
2760
+ }
2761
+ if (!input || typeof input.deviceFingerprint !== "string" || !input.deviceFingerprint.trim()) {
2762
+ throw clientInvalidInput("deviceFingerprint is required.");
2763
+ }
2764
+ const decision = input.decision ?? "approve";
2765
+ if (decision !== "approve" && decision !== "deny") {
2766
+ throw clientInvalidInput('decision must be "approve" or "deny".');
2767
+ }
2768
+ const hasSignal = input.deviceSignal !== void 0;
2769
+ const hasSigner = typeof input.sign === "function";
2770
+ if (hasSignal === hasSigner) {
2771
+ throw clientInvalidInput("Pass exactly one of deviceSignal or sign.");
2772
+ }
2773
+ if (hasSignal) {
2774
+ const sig = input.deviceSignal;
2775
+ if (!sig || typeof sig.nonce !== "string" || !sig.nonce || typeof sig.timestamp !== "number" || !Number.isInteger(sig.timestamp) || typeof sig.signature !== "string" || !sig.signature) {
2776
+ throw clientInvalidInput(
2777
+ "deviceSignal needs a nonce (string), an integer epoch-seconds timestamp and a base64 signature."
2778
+ );
2779
+ }
2780
+ }
2781
+ const id = encodeURIComponent(changeRequestId);
2782
+ const signal = opts?.signal;
2783
+ return this.withTokenRetry(async () => {
2784
+ let deviceSignal;
2785
+ if (hasSignal) {
2786
+ const sig = input.deviceSignal;
2787
+ deviceSignal = {
2788
+ transfer_id: changeRequestId,
2789
+ nonce: sig.nonce,
2790
+ timestamp: sig.timestamp,
2791
+ signature: sig.signature
2792
+ };
2793
+ } else {
2794
+ const nonce = randomNonce();
2795
+ const timestamp = Math.floor(Date.now() / 1e3);
2796
+ const signature = await input.sign(
2797
+ phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision)
2798
+ );
2799
+ if (typeof signature !== "string" || !signature) {
2800
+ throw clientInvalidInput("sign must return the base64 signature as a non-empty string.");
2801
+ }
2802
+ deviceSignal = { transfer_id: changeRequestId, nonce, timestamp, signature };
2803
+ }
2804
+ const raw = await this.post(
2805
+ `/api/sdk/players/phone/change-requests/${id}/approve`,
2806
+ { device_fingerprint: input.deviceFingerprint, device_signal: deviceSignal, decision },
2807
+ signal
2808
+ );
2809
+ return toApprovePhoneChangeResult(raw, changeRequestId);
2810
+ });
2811
+ }
2518
2812
  /**
2519
2813
  * Interchangeable methods (§4.6): prove an *already-enrolled* method (e.g. the
2520
2814
  * INVO app device key) to authorize adding a new partner passkey. The returned
@@ -2860,5 +3154,6 @@ exports.isPurchaseExpired = isPurchaseExpired;
2860
3154
  exports.isPurchaseRefunded = isPurchaseRefunded;
2861
3155
  exports.isPurchaseRefused = isPurchaseRefused;
2862
3156
  exports.nothingWasCharged = nothingWasCharged;
3157
+ exports.phoneChangeSignalMessage = phoneChangeSignalMessage;
2863
3158
  //# sourceMappingURL=index.cjs.map
2864
3159
  //# sourceMappingURL=index.cjs.map