@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.
- package/CHANGELOG.md +63 -0
- package/README.md +289 -34
- package/dist/{chunk-6IY4473A.js → chunk-BOD4WOWO.js} +257 -7
- package/dist/index.cjs +347 -6
- package/dist/index.d.cts +58 -5
- package/dist/index.d.ts +58 -5
- package/dist/index.js +119 -4
- package/dist/server.cjs +598 -41
- package/dist/server.d.cts +233 -28
- package/dist/server.d.ts +233 -28
- package/dist/server.js +380 -27
- package/dist/{types-BwgkJoM6.d.cts → types-C7vpPqsF.d.cts} +425 -6
- package/dist/{types-BwgkJoM6.d.ts → types-C7vpPqsF.d.ts} +425 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InvoError, assertSecureBaseUrl, Http, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink, receiptFields } from './chunk-
|
|
2
|
-
export { InvoError } from './chunk-
|
|
1
|
+
import { InvoError, assertSecureBaseUrl, Http, toPhoneChangeApprovalsResult, phoneChangeSignalMessage, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink, receiptFields } from './chunk-BOD4WOWO.js';
|
|
2
|
+
export { InvoError, phoneChangeSignalMessage } from './chunk-BOD4WOWO.js';
|
|
3
3
|
|
|
4
4
|
// src/shared/webauthn.ts
|
|
5
5
|
function malformedOptions(field) {
|
|
@@ -730,6 +730,19 @@ function nothingWasCharged(r) {
|
|
|
730
730
|
}
|
|
731
731
|
|
|
732
732
|
// src/index.ts
|
|
733
|
+
function clientInvalidInput(message) {
|
|
734
|
+
return new InvoError({ message, code: "INVALID_INPUT", status: 0 });
|
|
735
|
+
}
|
|
736
|
+
function randomNonce() {
|
|
737
|
+
const c = globalThis.crypto;
|
|
738
|
+
if (!c || typeof c.getRandomValues !== "function") {
|
|
739
|
+
throw clientInvalidInput(
|
|
740
|
+
"No secure random source in this environment; pass a deviceSignal you built yourself."
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
const bytes = c.getRandomValues(new Uint8Array(16));
|
|
744
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
745
|
+
}
|
|
733
746
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
734
747
|
function toPendingCollectItem(row) {
|
|
735
748
|
return {
|
|
@@ -770,6 +783,7 @@ function toApproveResult(raw, transactionId) {
|
|
|
770
783
|
risk: raw["risk"],
|
|
771
784
|
guardianApproval: raw["guardian_approval"] ?? void 0,
|
|
772
785
|
pollEndpoint: raw["poll_endpoint"],
|
|
786
|
+
...typeof raw["claim_delivery"] === "string" && raw["claim_delivery"] ? { claimDelivery: raw["claim_delivery"] } : {},
|
|
773
787
|
raw
|
|
774
788
|
};
|
|
775
789
|
}
|
|
@@ -1131,11 +1145,19 @@ var InvoClient = class {
|
|
|
1131
1145
|
};
|
|
1132
1146
|
return runHostedApproval(opts, api);
|
|
1133
1147
|
}
|
|
1134
|
-
/**
|
|
1148
|
+
/**
|
|
1149
|
+
* Approve a SEND with the player's passkey.
|
|
1150
|
+
*
|
|
1151
|
+
* Throws 403 `err.isPlayerTokenStale` when the player token predates a change to the
|
|
1152
|
+
* sender's identity (their phone was added on the initiate). Not retried automatically,
|
|
1153
|
+
* because this call moves money: re-mint the player token (or use the `playerToken`
|
|
1154
|
+
* your server got back from `initiateSend`) and retry once.
|
|
1155
|
+
*/
|
|
1135
1156
|
async approveSend(transactionId, opts) {
|
|
1136
1157
|
return this.approve("send", transactionId, opts);
|
|
1137
1158
|
}
|
|
1138
|
-
/** Approve a TRANSFER with the player's passkey (returns the sender's claim code).
|
|
1159
|
+
/** Approve a TRANSFER with the player's passkey (returns the sender's claim code). Same
|
|
1160
|
+
* `err.isPlayerTokenStale` handling as {@link approveSend}: re-mint and retry once. */
|
|
1139
1161
|
async approveTransfer(transactionId, opts) {
|
|
1140
1162
|
return this.approve("transfers", transactionId, opts);
|
|
1141
1163
|
}
|
|
@@ -1157,6 +1179,99 @@ var InvoClient = class {
|
|
|
1157
1179
|
async confirmReceiptTransfer(transactionId, opts) {
|
|
1158
1180
|
return this.confirmReceipt("transfers", transactionId, opts);
|
|
1159
1181
|
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Phone changes waiting for THIS player's enrolled device to approve
|
|
1184
|
+
* (`GET /api/sdk/players/phone/change-approvals`, player token). A row appears after the
|
|
1185
|
+
* player entered the emailed code on INVO's page for a change whose `confirmation` is
|
|
1186
|
+
* `"email_code_and_device"`. Show each one ("Approve changing your number to
|
|
1187
|
+
* ***-***-0123?") and answer it with {@link approvePhoneChange}. Read-only.
|
|
1188
|
+
*/
|
|
1189
|
+
async listPhoneChangeApprovals(opts) {
|
|
1190
|
+
return this.withTokenRetry(async () => {
|
|
1191
|
+
const raw = await this.get(
|
|
1192
|
+
"/api/sdk/players/phone/change-approvals",
|
|
1193
|
+
opts?.signal
|
|
1194
|
+
);
|
|
1195
|
+
return toPhoneChangeApprovalsResult(raw);
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Approve (or, with `decision: "deny"`, decline) a phone change from the player's enrolled
|
|
1200
|
+
* device (`POST /api/sdk/players/phone/change-requests/{id}/approve`, player token).
|
|
1201
|
+
*
|
|
1202
|
+
* The device key signs `phone-change|<changeRequestId>|<nonce>|<timestamp>` to approve or
|
|
1203
|
+
* `phone-change-deny|<changeRequestId>|<nonce>|<timestamp>` to decline (`timestamp` in
|
|
1204
|
+
* epoch seconds). Either pass `sign`, and the SDK makes a fresh nonce and timestamp, builds
|
|
1205
|
+
* that message and asks you for the base64 signature; or pass a `deviceSignal` you signed
|
|
1206
|
+
* yourself (build the message with {@link phoneChangeSignalMessage}). This is a device key
|
|
1207
|
+
* registered with INVO, not a passkey.
|
|
1208
|
+
*
|
|
1209
|
+
* `status: "confirmed"` means the change is applied: store `identityId` and use
|
|
1210
|
+
* `playerToken` (tokens minted before the change are stale). `status: "denied"` means
|
|
1211
|
+
* nothing changed. Refusals: 409 `err.isChangeRequestNotReady` (the player has not entered
|
|
1212
|
+
* the code on INVO's page yet), 409 `err.isChangeRequestNotPending` (`err.changeRequestStatus`),
|
|
1213
|
+
* 409 `err.isDeviceEnrolledAfterRequest` (this device was set up after the change was
|
|
1214
|
+
* requested; approve on the earlier device, or the game creates a new request), 409
|
|
1215
|
+
* `err.isPhoneChangeRecoveryCooldown` (a recent sign-in recovery; retry later, declining
|
|
1216
|
+
* still works), 404 `err.isChangeRequestNotFound`, 401 `err.isDeviceSignalRejected`, 403
|
|
1217
|
+
* `DEVICE_REQUIRES_ELEVATION`, or any refusal of the change itself (for example
|
|
1218
|
+
* `err.isPendingTransfersToOldPhone`).
|
|
1219
|
+
*/
|
|
1220
|
+
async approvePhoneChange(changeRequestId, input, opts) {
|
|
1221
|
+
if (typeof changeRequestId !== "string" || !changeRequestId.trim()) {
|
|
1222
|
+
throw clientInvalidInput("changeRequestId is required.");
|
|
1223
|
+
}
|
|
1224
|
+
if (!input || typeof input.deviceFingerprint !== "string" || !input.deviceFingerprint.trim()) {
|
|
1225
|
+
throw clientInvalidInput("deviceFingerprint is required.");
|
|
1226
|
+
}
|
|
1227
|
+
const decision = input.decision ?? "approve";
|
|
1228
|
+
if (decision !== "approve" && decision !== "deny") {
|
|
1229
|
+
throw clientInvalidInput('decision must be "approve" or "deny".');
|
|
1230
|
+
}
|
|
1231
|
+
const hasSignal = input.deviceSignal !== void 0;
|
|
1232
|
+
const hasSigner = typeof input.sign === "function";
|
|
1233
|
+
if (hasSignal === hasSigner) {
|
|
1234
|
+
throw clientInvalidInput("Pass exactly one of deviceSignal or sign.");
|
|
1235
|
+
}
|
|
1236
|
+
if (hasSignal) {
|
|
1237
|
+
const sig = input.deviceSignal;
|
|
1238
|
+
if (!sig || typeof sig.nonce !== "string" || !sig.nonce || typeof sig.timestamp !== "number" || !Number.isInteger(sig.timestamp) || typeof sig.signature !== "string" || !sig.signature) {
|
|
1239
|
+
throw clientInvalidInput(
|
|
1240
|
+
"deviceSignal needs a nonce (string), an integer epoch-seconds timestamp and a base64 signature."
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
const id = encodeURIComponent(changeRequestId);
|
|
1245
|
+
const signal = opts?.signal;
|
|
1246
|
+
return this.withTokenRetry(async () => {
|
|
1247
|
+
let deviceSignal;
|
|
1248
|
+
if (hasSignal) {
|
|
1249
|
+
const sig = input.deviceSignal;
|
|
1250
|
+
deviceSignal = {
|
|
1251
|
+
transfer_id: changeRequestId,
|
|
1252
|
+
nonce: sig.nonce,
|
|
1253
|
+
timestamp: sig.timestamp,
|
|
1254
|
+
signature: sig.signature
|
|
1255
|
+
};
|
|
1256
|
+
} else {
|
|
1257
|
+
const nonce = randomNonce();
|
|
1258
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
1259
|
+
const signature = await input.sign(
|
|
1260
|
+
phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision)
|
|
1261
|
+
);
|
|
1262
|
+
if (typeof signature !== "string" || !signature) {
|
|
1263
|
+
throw clientInvalidInput("sign must return the base64 signature as a non-empty string.");
|
|
1264
|
+
}
|
|
1265
|
+
deviceSignal = { transfer_id: changeRequestId, nonce, timestamp, signature };
|
|
1266
|
+
}
|
|
1267
|
+
const raw = await this.post(
|
|
1268
|
+
`/api/sdk/players/phone/change-requests/${id}/approve`,
|
|
1269
|
+
{ device_fingerprint: input.deviceFingerprint, device_signal: deviceSignal, decision },
|
|
1270
|
+
signal
|
|
1271
|
+
);
|
|
1272
|
+
return toApprovePhoneChangeResult(raw, changeRequestId);
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1160
1275
|
/**
|
|
1161
1276
|
* Interchangeable methods (§4.6): prove an *already-enrolled* method (e.g. the
|
|
1162
1277
|
* INVO app device key) to authorize adding a new partner passkey. The returned
|