@invonetwork/web-sdk 3.29.1 → 3.30.1
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 +1442 -1397
- package/README.md +2954 -2923
- package/dist/chunk-3ECVREIM.js +6 -0
- package/dist/chunk-7O5JT3LK.js +1590 -0
- package/dist/{chunk-VP3OK4J4.js → chunk-TCT2QSVB.js} +515 -3
- package/dist/{chunk-YONO4JE5.js → chunk-V2RQYQQD.js} +44 -5
- package/dist/game-server.cjs +387 -42
- package/dist/game-server.d.cts +42 -6
- package/dist/game-server.d.ts +42 -6
- package/dist/game-server.js +286 -8
- package/dist/game.cjs +2677 -9
- package/dist/game.d.cts +78 -4
- package/dist/game.d.ts +78 -4
- package/dist/game.js +558 -3
- package/dist/hosted-approval-DcY4U2RN.d.cts +96 -0
- package/dist/hosted-approval-DiKmtjEh.d.ts +96 -0
- package/dist/index.d.cts +7 -96
- package/dist/index.d.ts +7 -96
- package/dist/index.js +2 -1635
- package/dist/loyalty-events-CmDw2ZoR.d.cts +40 -0
- package/dist/loyalty-events-CmDw2ZoR.d.ts +40 -0
- package/dist/{server-Bxo_wgHx.d.cts → server-BAOn3KH3.d.cts} +28 -2
- package/dist/{server-BYY6tM6X.d.ts → server-DHmQU1eN.d.ts} +28 -2
- package/dist/server.cjs +106 -40
- package/dist/server.d.cts +4 -3
- package/dist/server.d.ts +4 -3
- package/dist/server.js +3 -4
- package/dist/{types-_lIm74kd.d.cts → types-BTbZicgj.d.cts} +1 -40
- package/dist/{types-_lIm74kd.d.ts → types-BTbZicgj.d.ts} +1 -40
- package/dist/{types-CLyJDuXd.d.cts → types-jUxfYjiD.d.cts} +64 -1
- package/dist/{types-CLyJDuXd.d.ts → types-jUxfYjiD.d.ts} +64 -1
- package/dist/{version-DOaYbHu7.d.cts → version-CR7XECyP.d.cts} +1 -1
- package/dist/{version-DOaYbHu7.d.ts → version-CR7XECyP.d.ts} +1 -1
- package/package.json +91 -91
- package/dist/chunk-6CN236QH.js +0 -473
- package/dist/chunk-VOGZZ6QS.js +0 -6
|
@@ -1135,6 +1135,431 @@ function errorFromResponse(status, body, requestId) {
|
|
|
1135
1135
|
return new InvoError({ message, code, rawCode, publicCode, status, body, requestId });
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
|
+
// src/shared/http.ts
|
|
1139
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
1140
|
+
var MAX_RETRY_AFTER_MS = 2e4;
|
|
1141
|
+
function assertSecureBaseUrl(baseUrl) {
|
|
1142
|
+
let u;
|
|
1143
|
+
try {
|
|
1144
|
+
u = new URL(baseUrl);
|
|
1145
|
+
} catch {
|
|
1146
|
+
throw new Error(`Invalid baseUrl: ${baseUrl}`);
|
|
1147
|
+
}
|
|
1148
|
+
const isLocal = u.hostname === "localhost" || u.hostname === "127.0.0.1" || u.hostname === "[::1]";
|
|
1149
|
+
if (u.protocol === "https:" || u.protocol === "http:" && isLocal) return;
|
|
1150
|
+
throw new Error(
|
|
1151
|
+
`baseUrl must use https:// (got "${u.protocol}//"). Plaintext would expose the token/secret on the wire.`
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
var _Http = class _Http {
|
|
1155
|
+
constructor(opts) {
|
|
1156
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
1157
|
+
this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT;
|
|
1158
|
+
const f = opts.fetchImpl ?? globalThis.fetch;
|
|
1159
|
+
if (typeof f !== "function") {
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
"No fetch implementation available. Use Node >=18, or pass `fetch` in the config."
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
this.fetchImpl = f.bind(globalThis);
|
|
1165
|
+
this.userAgent = opts.userAgent;
|
|
1166
|
+
this.maxRetries = Math.max(0, opts.maxRetries ?? 2);
|
|
1167
|
+
this.retryBaseDelayMs = opts.retryBaseDelayMs ?? 250;
|
|
1168
|
+
this.hooks = opts.hooks;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* @param opts.idempotent - mark this POST safe to auto-retry (it carries an
|
|
1172
|
+
* idempotency key, or has no side effect). Default false: non-idempotent POSTs
|
|
1173
|
+
* (e.g. single-use WebAuthn assertions) are NEVER auto-retried.
|
|
1174
|
+
*/
|
|
1175
|
+
async post(path, body, auth, opts) {
|
|
1176
|
+
return this.request("POST", path, body, auth, opts?.idempotent ?? false, opts?.signal, opts?.headers);
|
|
1177
|
+
}
|
|
1178
|
+
// GET is always idempotent → safe to retry.
|
|
1179
|
+
async get(path, auth, opts) {
|
|
1180
|
+
return this.request("GET", path, void 0, auth, true, opts?.signal, opts?.headers);
|
|
1181
|
+
}
|
|
1182
|
+
authHeaders(auth) {
|
|
1183
|
+
switch (auth.kind) {
|
|
1184
|
+
case "game-secret":
|
|
1185
|
+
return { "X-Game-Secret-Key": auth.secret };
|
|
1186
|
+
case "bearer":
|
|
1187
|
+
return { Authorization: `Bearer ${auth.token}` };
|
|
1188
|
+
case "none":
|
|
1189
|
+
return {};
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
async request(method, path, body, auth, idempotent, signal, extraHeaders) {
|
|
1193
|
+
const url = `${this.baseUrl}${path}`;
|
|
1194
|
+
const headers = {
|
|
1195
|
+
Accept: "application/json",
|
|
1196
|
+
...this.authHeaders(auth),
|
|
1197
|
+
// Per-call extras (e.g. the sandbox clock key) — never able to override the auth header.
|
|
1198
|
+
...extraHeaders ?? {},
|
|
1199
|
+
...this.authHeaders(auth)
|
|
1200
|
+
};
|
|
1201
|
+
if (this.userAgent) headers["User-Agent"] = this.userAgent;
|
|
1202
|
+
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
1203
|
+
const payload = body !== void 0 ? JSON.stringify(body) : void 0;
|
|
1204
|
+
for (let attempt = 0; ; attempt++) {
|
|
1205
|
+
if (signal?.aborted) throw abortError(path);
|
|
1206
|
+
const start = Date.now();
|
|
1207
|
+
this.fire("onRequest", { method, url, attempt });
|
|
1208
|
+
const controller = new AbortController();
|
|
1209
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
1210
|
+
const onAbort = () => controller.abort();
|
|
1211
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1212
|
+
let res;
|
|
1213
|
+
let networkError;
|
|
1214
|
+
try {
|
|
1215
|
+
res = await this.fetchImpl(url, {
|
|
1216
|
+
method,
|
|
1217
|
+
headers,
|
|
1218
|
+
body: payload,
|
|
1219
|
+
signal: controller.signal,
|
|
1220
|
+
redirect: "manual"
|
|
1221
|
+
});
|
|
1222
|
+
} catch (err) {
|
|
1223
|
+
networkError = new InvoError({
|
|
1224
|
+
message: err instanceof Error && err.name === "AbortError" ? `Request to ${path} timed out after ${this.timeoutMs}ms` : `Network error calling ${path}: ${err?.message ?? err}`,
|
|
1225
|
+
status: 0,
|
|
1226
|
+
body: null
|
|
1227
|
+
});
|
|
1228
|
+
} finally {
|
|
1229
|
+
clearTimeout(timer);
|
|
1230
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1231
|
+
}
|
|
1232
|
+
if (networkError) {
|
|
1233
|
+
if (signal?.aborted) throw abortError(path);
|
|
1234
|
+
const willRetry = idempotent && attempt < this.maxRetries;
|
|
1235
|
+
this.fire("onError", { method, url, attempt, error: networkError, willRetry });
|
|
1236
|
+
if (willRetry) {
|
|
1237
|
+
await sleep(this.backoff(attempt), signal);
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
throw networkError;
|
|
1241
|
+
}
|
|
1242
|
+
if (res.type === "opaqueredirect" || res.status >= 300 && res.status < 400) {
|
|
1243
|
+
throw new InvoError({
|
|
1244
|
+
message: `Refused to follow a redirect from ${path} \u2014 credentials are never re-sent to a redirected URL.`,
|
|
1245
|
+
code: "UNEXPECTED_REDIRECT",
|
|
1246
|
+
status: res.status || 0,
|
|
1247
|
+
body: null
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
const requestId = pickRequestId(res.headers);
|
|
1251
|
+
const text = await res.text();
|
|
1252
|
+
let parsed = null;
|
|
1253
|
+
if (text) {
|
|
1254
|
+
try {
|
|
1255
|
+
parsed = JSON.parse(text);
|
|
1256
|
+
} catch {
|
|
1257
|
+
parsed = text;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
this.fire("onResponse", {
|
|
1261
|
+
method,
|
|
1262
|
+
url,
|
|
1263
|
+
attempt,
|
|
1264
|
+
status: res.status,
|
|
1265
|
+
durationMs: Date.now() - start,
|
|
1266
|
+
requestId
|
|
1267
|
+
});
|
|
1268
|
+
if (!res.ok) {
|
|
1269
|
+
const err = errorFromResponse(res.status, parsed, requestId);
|
|
1270
|
+
let wait;
|
|
1271
|
+
if (idempotent && attempt < this.maxRetries && _Http.RETRIABLE_STATUS.has(res.status)) {
|
|
1272
|
+
if (res.status === 429) {
|
|
1273
|
+
const ra = retryAfterMs(parsed, res.headers);
|
|
1274
|
+
wait = ra === void 0 ? this.backoff(attempt) : ra <= MAX_RETRY_AFTER_MS ? ra : void 0;
|
|
1275
|
+
} else {
|
|
1276
|
+
wait = this.backoff(attempt);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
this.fire("onError", { method, url, attempt, error: err, willRetry: wait !== void 0 });
|
|
1280
|
+
if (wait !== void 0) {
|
|
1281
|
+
await sleep(wait, signal);
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
throw err;
|
|
1285
|
+
}
|
|
1286
|
+
return parsed ?? {};
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
/** Invoke an observability hook, swallowing any error it throws (best-effort). */
|
|
1290
|
+
fire(name, info) {
|
|
1291
|
+
const hook = this.hooks?.[name];
|
|
1292
|
+
if (!hook) return;
|
|
1293
|
+
try {
|
|
1294
|
+
hook(info);
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
/** Exponential backoff with full jitter: base * 2^attempt, randomized. */
|
|
1299
|
+
backoff(attempt) {
|
|
1300
|
+
const ceil = this.retryBaseDelayMs * 2 ** attempt;
|
|
1301
|
+
return Math.floor(Math.random() * ceil) + this.retryBaseDelayMs;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
/** HTTP statuses worth retrying — rate limit + transient gateway/server errors. */
|
|
1305
|
+
_Http.RETRIABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
1306
|
+
var Http = _Http;
|
|
1307
|
+
function sleep(ms, signal) {
|
|
1308
|
+
return new Promise((resolve) => {
|
|
1309
|
+
if (signal?.aborted) return resolve();
|
|
1310
|
+
const timer = setTimeout(done, ms);
|
|
1311
|
+
const onAbort = () => done();
|
|
1312
|
+
function done() {
|
|
1313
|
+
clearTimeout(timer);
|
|
1314
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1315
|
+
resolve();
|
|
1316
|
+
}
|
|
1317
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
function abortError(path) {
|
|
1321
|
+
return new InvoError({ message: `Request to ${path} was aborted`, code: "ABORTED", status: 0 });
|
|
1322
|
+
}
|
|
1323
|
+
function pickRequestId(headers) {
|
|
1324
|
+
if (!headers || typeof headers.get !== "function") return void 0;
|
|
1325
|
+
return headers.get("x-invo-request-id") ?? headers.get("x-request-id") ?? void 0;
|
|
1326
|
+
}
|
|
1327
|
+
function retryAfterMs(parsed, headers) {
|
|
1328
|
+
if (parsed && typeof parsed === "object") {
|
|
1329
|
+
const v = parsed["retry_after"];
|
|
1330
|
+
const n = typeof v === "string" ? v.trim() === "" ? NaN : Number(v) : v;
|
|
1331
|
+
if (typeof n === "number" && Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
1332
|
+
}
|
|
1333
|
+
const header = headers && typeof headers.get === "function" ? headers.get("retry-after") : null;
|
|
1334
|
+
if (header) {
|
|
1335
|
+
const n = Number(header);
|
|
1336
|
+
if (Number.isFinite(n) && n >= 0) return n * 1e3;
|
|
1337
|
+
}
|
|
1338
|
+
return void 0;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// src/shared/destinations.ts
|
|
1342
|
+
function toDestinationGame(row) {
|
|
1343
|
+
const s = (k) => row[k] === void 0 || row[k] === null ? void 0 : String(row[k]);
|
|
1344
|
+
return {
|
|
1345
|
+
gameId: row["game_id"] ?? "",
|
|
1346
|
+
gameName: String(row["game_name"] ?? ""),
|
|
1347
|
+
tenantType: s("tenant_type"),
|
|
1348
|
+
developerName: s("developer_name"),
|
|
1349
|
+
publisherName: s("publisher_name"),
|
|
1350
|
+
genre: s("genre"),
|
|
1351
|
+
platform: s("platform"),
|
|
1352
|
+
gameStatus: s("game_status"),
|
|
1353
|
+
gameIcon: s("game_icon"),
|
|
1354
|
+
gamePoster: s("game_poster"),
|
|
1355
|
+
gameUrl: s("game_url"),
|
|
1356
|
+
gameDescription: s("game_description"),
|
|
1357
|
+
currencyName: String(row["currency_name"] ?? ""),
|
|
1358
|
+
currencySymbol: String(row["currency_symbol"] ?? ""),
|
|
1359
|
+
currencySymbolUrl: s("currency_symbol_url"),
|
|
1360
|
+
minimumTransfer: String(row["minimum_transfer"] ?? ""),
|
|
1361
|
+
maximumTransfer: String(row["maximum_transfer"] ?? ""),
|
|
1362
|
+
acceptsSteamOriginValue: row["accepts_steam_origin_value"] === true,
|
|
1363
|
+
raw: row
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
function toDestinationsResult(raw, direction) {
|
|
1367
|
+
const games = Array.isArray(raw["available_games"]) ? raw["available_games"] : [];
|
|
1368
|
+
return {
|
|
1369
|
+
status: String(raw["status"] ?? ""),
|
|
1370
|
+
sourceGameId: raw["source_game_id"] ?? "",
|
|
1371
|
+
sourceGameName: String(raw["source_game_name"] ?? ""),
|
|
1372
|
+
sourceGameIcon: raw["source_game_icon"],
|
|
1373
|
+
sourceCurrencyName: String(raw["source_currency_name"] ?? ""),
|
|
1374
|
+
sourceCurrencyIcon: raw["source_currency_icon"],
|
|
1375
|
+
universalTransfers: raw["universal_transfers"] === true,
|
|
1376
|
+
transferMode: String(raw["transfer_mode"] ?? ""),
|
|
1377
|
+
availableGames: games.map(toDestinationGame),
|
|
1378
|
+
totalDestinations: Number(raw["total_destinations"] ?? games.length),
|
|
1379
|
+
direction: String(raw["direction"] ?? direction),
|
|
1380
|
+
linkedGameIds: Array.isArray(raw["linked_game_ids"]) ? raw["linked_game_ids"] : void 0,
|
|
1381
|
+
raw
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// src/shared/receipt-fields.ts
|
|
1386
|
+
function creditFields(raw) {
|
|
1387
|
+
const c = raw["credited"];
|
|
1388
|
+
if (c === true) return { credited: true };
|
|
1389
|
+
if (c === false) {
|
|
1390
|
+
const r = raw["reason_code"];
|
|
1391
|
+
return { credited: false, reasonCode: r == null ? null : String(r) };
|
|
1392
|
+
}
|
|
1393
|
+
return {};
|
|
1394
|
+
}
|
|
1395
|
+
function receiptFields(raw) {
|
|
1396
|
+
const n = raw["receipt_number"];
|
|
1397
|
+
if (typeof n !== "string" || n === "") return {};
|
|
1398
|
+
const u = raw["receipt_url"];
|
|
1399
|
+
return typeof u === "string" && u !== "" ? { receiptNumber: n, receiptUrl: u } : { receiptNumber: n };
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// src/shared/purchase-status.ts
|
|
1403
|
+
function str(v) {
|
|
1404
|
+
return typeof v === "string" ? v : v === null || v === void 0 ? null : String(v);
|
|
1405
|
+
}
|
|
1406
|
+
function toPurchaseStatusResult(raw, sessionId) {
|
|
1407
|
+
return {
|
|
1408
|
+
status: String(raw["status"] ?? ""),
|
|
1409
|
+
// INVO SAYS, AND ONLY AN EXPLICIT `true` SAYS IT. A missing or malformed field reads
|
|
1410
|
+
// false, which keeps a poll running; the alternative, guessing terminality from
|
|
1411
|
+
// `status`, is how an old SDK declares a future status finished.
|
|
1412
|
+
terminal: raw["terminal"] === true,
|
|
1413
|
+
orderId: str(raw["order_id"]),
|
|
1414
|
+
sessionId: String(raw["session_id"] ?? sessionId),
|
|
1415
|
+
coinsCredited: str(raw["coins_credited"]),
|
|
1416
|
+
transactionId: str(raw["transaction_id"]),
|
|
1417
|
+
newBalance: str(raw["new_balance"]),
|
|
1418
|
+
reasonCode: str(raw["reason_code"]),
|
|
1419
|
+
message: str(raw["message"]),
|
|
1420
|
+
amountChargedUsd: str(raw["amount_charged_usd"]),
|
|
1421
|
+
listedUsd: str(raw["listed_usd"]),
|
|
1422
|
+
currencyName: str(raw["currency_name"]),
|
|
1423
|
+
...receiptFields(raw),
|
|
1424
|
+
raw
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
function isPurchaseCredited(r) {
|
|
1428
|
+
return r.status === "credited";
|
|
1429
|
+
}
|
|
1430
|
+
function isPurchaseRefused(r) {
|
|
1431
|
+
return r.status === "refused";
|
|
1432
|
+
}
|
|
1433
|
+
function isPurchaseRefunded(r) {
|
|
1434
|
+
return r.status === "refunded";
|
|
1435
|
+
}
|
|
1436
|
+
function isPurchaseExpired(r) {
|
|
1437
|
+
return r.status === "expired";
|
|
1438
|
+
}
|
|
1439
|
+
var NOTHING_CHARGED_REASONS = /* @__PURE__ */ new Set(["PAYMENT_DECLINED", "PAYMENT_CANCELLED"]);
|
|
1440
|
+
function nothingWasCharged(r) {
|
|
1441
|
+
if (r.status === "expired") return true;
|
|
1442
|
+
if (r.status !== "refused") return false;
|
|
1443
|
+
return r.reasonCode !== null && NOTHING_CHARGED_REASONS.has(r.reasonCode);
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
// src/shared/loyalty.ts
|
|
1447
|
+
var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
1448
|
+
var rows = (v) => Array.isArray(v) ? v.filter((r) => r && typeof r === "object" && !Array.isArray(r)) : [];
|
|
1449
|
+
var str2 = (v) => v === void 0 || v === null ? "" : String(v);
|
|
1450
|
+
var strOrNull = (v) => v === void 0 || v === null ? null : String(v);
|
|
1451
|
+
var numOrNull = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
1452
|
+
var int = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
1453
|
+
var passThrough = (v) => v;
|
|
1454
|
+
function toLoyaltyStepProgress(value) {
|
|
1455
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1456
|
+
const v = value;
|
|
1457
|
+
const current = v["current"];
|
|
1458
|
+
const target = v["target"];
|
|
1459
|
+
if (!Number.isInteger(current) || !Number.isInteger(target)) return null;
|
|
1460
|
+
return { current, target };
|
|
1461
|
+
}
|
|
1462
|
+
function toStep(row) {
|
|
1463
|
+
return {
|
|
1464
|
+
stepId: strOrNull(row["step_id"]),
|
|
1465
|
+
index: int(row["index"]),
|
|
1466
|
+
action: str2(row["action"]),
|
|
1467
|
+
label: str2(row["label"]),
|
|
1468
|
+
summary: str2(row["summary"]),
|
|
1469
|
+
windowHours: numOrNull(row["window_hours"]),
|
|
1470
|
+
state: str2(row["state"]),
|
|
1471
|
+
progress: toLoyaltyStepProgress(row["progress"]),
|
|
1472
|
+
raw: row
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
function toCardReward(row) {
|
|
1476
|
+
return {
|
|
1477
|
+
vaultEntryId: str2(row["vault_entry_id"]),
|
|
1478
|
+
rewardId: str2(row["reward_id"]),
|
|
1479
|
+
state: str2(row["state"]),
|
|
1480
|
+
unlockedAt: str2(row["unlocked_at"]),
|
|
1481
|
+
expiresAt: str2(row["expires_at"]),
|
|
1482
|
+
redeemedAt: strOrNull(row["redeemed_at"]),
|
|
1483
|
+
codeMasked: strOrNull(row["code_masked"]),
|
|
1484
|
+
canRedeem: row["can_redeem"] === true,
|
|
1485
|
+
canRevealAgain: row["can_reveal_again"] === true,
|
|
1486
|
+
revealUntil: strOrNull(row["reveal_until"]),
|
|
1487
|
+
raw: row
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
function toLoyaltyCard(row) {
|
|
1491
|
+
const brand = obj(row["brand"]);
|
|
1492
|
+
const reward = obj(row["reward"]);
|
|
1493
|
+
const steps = rows(row["steps"]).map(toStep);
|
|
1494
|
+
return {
|
|
1495
|
+
cardVersion: passThrough(row["card_version"]),
|
|
1496
|
+
mode: str2(row["mode"]),
|
|
1497
|
+
programId: strOrNull(row["program_id"]),
|
|
1498
|
+
questId: strOrNull(row["quest_id"]),
|
|
1499
|
+
questVersion: numOrNull(row["quest_version"]),
|
|
1500
|
+
campaignId: strOrNull(row["campaign_id"]),
|
|
1501
|
+
title: str2(row["title"]),
|
|
1502
|
+
description: str2(row["description"]),
|
|
1503
|
+
brand: { name: strOrNull(brand["name"]), logoUrl: strOrNull(brand["logo_url"]) },
|
|
1504
|
+
artUrl: strOrNull(row["art_url"]),
|
|
1505
|
+
reward: { rewardId: strOrNull(reward["reward_id"]), name: strOrNull(reward["name"]) },
|
|
1506
|
+
orderMode: str2(row["order_mode"]),
|
|
1507
|
+
status: str2(row["status"]),
|
|
1508
|
+
startsAt: strOrNull(row["starts_at"]),
|
|
1509
|
+
endsAt: strOrNull(row["ends_at"]),
|
|
1510
|
+
completionHours: numOrNull(row["completion_hours"]),
|
|
1511
|
+
completionNote: strOrNull(row["completion_note"]),
|
|
1512
|
+
windowEndsAt: strOrNull(row["window_ends_at"]),
|
|
1513
|
+
completedAt: strOrNull(row["completed_at"]),
|
|
1514
|
+
stepsRequired: passThrough(row["steps_required"]),
|
|
1515
|
+
stepsComplete: passThrough(row["steps_complete"]),
|
|
1516
|
+
steps,
|
|
1517
|
+
rewards: rows(row["rewards"]).map(toCardReward),
|
|
1518
|
+
raw: row
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
function toLoyaltyCardsResult(raw) {
|
|
1522
|
+
return {
|
|
1523
|
+
cardVersion: passThrough(raw["card_version"]),
|
|
1524
|
+
cards: rows(raw["cards"]).map(toLoyaltyCard),
|
|
1525
|
+
raw
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
function toVaultEntry(row) {
|
|
1529
|
+
return {
|
|
1530
|
+
vaultEntryId: str2(row["vault_entry_id"]),
|
|
1531
|
+
rewardRef: str2(row["reward_ref"]),
|
|
1532
|
+
programId: str2(row["program_id"]),
|
|
1533
|
+
questId: strOrNull(row["quest_id"]),
|
|
1534
|
+
units: str2(row["units"]),
|
|
1535
|
+
state: str2(row["state"]),
|
|
1536
|
+
unlockedAt: strOrNull(row["unlocked_at"]),
|
|
1537
|
+
expiresAt: strOrNull(row["expires_at"]),
|
|
1538
|
+
redeemedAt: strOrNull(row["redeemed_at"]),
|
|
1539
|
+
codeMasked: strOrNull(row["code_masked"]),
|
|
1540
|
+
raw: row
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
function toLoyaltyVaultResult(raw) {
|
|
1544
|
+
return { items: rows(raw["items"]).map(toVaultEntry), raw };
|
|
1545
|
+
}
|
|
1546
|
+
function toRedeemRewardResult(raw, vaultEntryId) {
|
|
1547
|
+
return {
|
|
1548
|
+
vaultEntryId: str2(raw["vault_entry_id"] ?? vaultEntryId),
|
|
1549
|
+
rewardRef: str2(raw["reward_ref"]),
|
|
1550
|
+
state: str2(raw["state"]),
|
|
1551
|
+
redeemedAt: strOrNull(raw["redeemed_at"]),
|
|
1552
|
+
code: strOrNull(raw["code"]),
|
|
1553
|
+
codeMasked: strOrNull(raw["code_masked"]),
|
|
1554
|
+
revealedAgain: raw["revealed_again"] === true,
|
|
1555
|
+
revealUntil: strOrNull(raw["reveal_until"]),
|
|
1556
|
+
raw
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
function toRewardsPageLink(raw) {
|
|
1560
|
+
return { url: str2(raw["url"]), expiresAt: str2(raw["expires_at"]), raw };
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1138
1563
|
// src/shared/loyalty-events.ts
|
|
1139
1564
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
1140
1565
|
var ISO_WITH_ZONE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
@@ -1200,6 +1625,93 @@ function toReportGameEventResult(raw, eventId) {
|
|
|
1200
1625
|
};
|
|
1201
1626
|
}
|
|
1202
1627
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1628
|
+
// src/shared/phone-change.ts
|
|
1629
|
+
function phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision = "approve") {
|
|
1630
|
+
const action = decision === "deny" ? "phone-change-deny" : "phone-change";
|
|
1631
|
+
return `${action}|${changeRequestId}|${nonce}|${Math.trunc(timestamp)}`;
|
|
1632
|
+
}
|
|
1633
|
+
function requireField(value, field, raw) {
|
|
1634
|
+
const s = value == null ? "" : String(value);
|
|
1635
|
+
if (!s) {
|
|
1636
|
+
throw new InvoError({
|
|
1637
|
+
message: `INVO response was missing the required \`${field}\` field.`,
|
|
1638
|
+
code: "INVALID_RESPONSE",
|
|
1639
|
+
status: 0,
|
|
1640
|
+
body: raw
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
return s;
|
|
1644
|
+
}
|
|
1645
|
+
var str3 = (v) => v == null ? "" : String(v);
|
|
1646
|
+
var strOrNull2 = (v) => typeof v === "string" ? v : v == null ? null : String(v);
|
|
1647
|
+
function toRequestPhoneChangeResult(raw) {
|
|
1648
|
+
return {
|
|
1649
|
+
changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
|
|
1650
|
+
status: requireField(raw["status"], "status", raw),
|
|
1651
|
+
expiresAt: str3(raw["expires_at"]),
|
|
1652
|
+
delivery: str3(raw["delivery"]),
|
|
1653
|
+
confirmation: str3(raw["confirmation"]),
|
|
1654
|
+
message: str3(raw["message"]),
|
|
1655
|
+
raw
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
function toPhoneChangeRequest(raw) {
|
|
1659
|
+
return {
|
|
1660
|
+
changeRequestId: requireField(raw["change_request_id"], "change_request_id", raw),
|
|
1661
|
+
status: requireField(raw["status"], "status", raw),
|
|
1662
|
+
confirmation: str3(raw["confirmation"]),
|
|
1663
|
+
delivery: str3(raw["delivery"]),
|
|
1664
|
+
newPhoneMasked: strOrNull2(raw["new_phone_masked"]),
|
|
1665
|
+
createdAt: strOrNull2(raw["created_at"]),
|
|
1666
|
+
expiresAt: strOrNull2(raw["expires_at"]),
|
|
1667
|
+
confirmedAt: strOrNull2(raw["confirmed_at"]),
|
|
1668
|
+
confirmedVia: strOrNull2(raw["confirmed_via"]),
|
|
1669
|
+
raw
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
function toPhoneChangeApprovalsResult(raw) {
|
|
1673
|
+
const rows2 = Array.isArray(raw["approvals"]) ? raw["approvals"] : [];
|
|
1674
|
+
const approvals = rows2.filter((r) => r && typeof r === "object").map((r) => ({
|
|
1675
|
+
changeRequestId: str3(r["change_request_id"]),
|
|
1676
|
+
gameName: strOrNull2(r["game_name"]),
|
|
1677
|
+
oldPhoneMasked: strOrNull2(r["old_phone_masked"]),
|
|
1678
|
+
newPhoneMasked: strOrNull2(r["new_phone_masked"]),
|
|
1679
|
+
expiresAt: strOrNull2(r["expires_at"])
|
|
1680
|
+
}));
|
|
1681
|
+
return { approvals, raw };
|
|
1682
|
+
}
|
|
1683
|
+
function toApprovePhoneChangeResult(raw, changeRequestId) {
|
|
1684
|
+
const id = str3(raw["change_request_id"] ?? changeRequestId);
|
|
1685
|
+
const status = requireField(raw["status"], "status", raw);
|
|
1686
|
+
if (status === "denied") {
|
|
1687
|
+
return { status: "denied", changeRequestId: id, raw };
|
|
1688
|
+
}
|
|
1689
|
+
if (status !== "confirmed") {
|
|
1690
|
+
throw new InvoError({
|
|
1691
|
+
message: `INVO answered an unexpected phone change status \`${status}\`.`,
|
|
1692
|
+
code: "INVALID_RESPONSE",
|
|
1693
|
+
status: 0,
|
|
1694
|
+
body: raw
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
const out = {
|
|
1698
|
+
status: "confirmed",
|
|
1699
|
+
changeRequestId: id,
|
|
1700
|
+
identityId: str3(raw["identity_id"]),
|
|
1701
|
+
previousIdentityId: str3(raw["previous_identity_id"]),
|
|
1702
|
+
playersUpdated: Number(raw["players_updated"] ?? 0) || 0,
|
|
1703
|
+
verifiedPhone: raw["verified_phone"] === true,
|
|
1704
|
+
raw
|
|
1705
|
+
};
|
|
1706
|
+
if (typeof raw["player_token"] === "string" && raw["player_token"]) {
|
|
1707
|
+
out.playerToken = raw["player_token"];
|
|
1708
|
+
if (typeof raw["player_token_expires_at"] === "string") {
|
|
1709
|
+
out.playerTokenExpiresAt = raw["player_token_expires_at"];
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
return out;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
export { Http, InvoError, assertSecureBaseUrl, buildGameEventBody, creditFields, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, newEventId, nothingWasCharged, phoneChangeSignalMessage, receiptFields, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toPhoneChangeApprovalsResult, toPhoneChangeRequest, toPurchaseStatusResult, toRedeemRewardResult, toReportGameEventResult, toRequestPhoneChangeResult, toRewardsPageLink };
|
|
1716
|
+
//# sourceMappingURL=chunk-TCT2QSVB.js.map
|
|
1717
|
+
//# sourceMappingURL=chunk-TCT2QSVB.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { InvoError, buildGameEventBody, toReportGameEventResult } from './chunk-VP3OK4J4.js';
|
|
1
|
+
import { SDK_VERSION } from './chunk-3ECVREIM.js';
|
|
2
|
+
import { InvoError, assertSecureBaseUrl, Http, toRequestPhoneChangeResult, toPhoneChangeRequest, toPurchaseStatusResult, receiptFields, creditFields, toLoyaltyCardsResult, buildGameEventBody, toReportGameEventResult, toDestinationsResult } from './chunk-TCT2QSVB.js';
|
|
4
3
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
5
4
|
|
|
6
5
|
// src/payouts.ts
|
|
@@ -2216,6 +2215,27 @@ var SandboxSubscriptionsServer = class {
|
|
|
2216
2215
|
var SandboxServer = class {
|
|
2217
2216
|
constructor(http, auth, clockKey) {
|
|
2218
2217
|
this.subscriptions = new SandboxSubscriptionsServer(http, auth, clockKey);
|
|
2218
|
+
this.http = http;
|
|
2219
|
+
this.auth = auth;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Public demo key only (3.30.0): approve a send or transfer the demo player started, without
|
|
2223
|
+
* a passkey. INVO's demo sandbox answers with the claim code, which the recipient's game
|
|
2224
|
+
* server then uses with `claimCurrency` (a send) or `claimTransfer` (a transfer). Refused on
|
|
2225
|
+
* every other key and in production.
|
|
2226
|
+
*/
|
|
2227
|
+
async approveDemoMove(transactionId, kind, opts) {
|
|
2228
|
+
if (typeof transactionId !== "string" || !transactionId.trim()) {
|
|
2229
|
+
throw invalidInput2("transactionId", transactionId, "is required");
|
|
2230
|
+
}
|
|
2231
|
+
const path = `/test-auth/${kind === "send" ? "sends" : "transfers"}/${encodeURIComponent(transactionId)}/approve`;
|
|
2232
|
+
const raw = await this.http.post(path, {}, this.auth, { signal: opts?.signal });
|
|
2233
|
+
return {
|
|
2234
|
+
status: String(raw["status"] ?? ""),
|
|
2235
|
+
claimCode: typeof raw["claim_code"] === "string" ? raw["claim_code"] : null,
|
|
2236
|
+
claimCodeExpiresAt: typeof raw["claim_code_expires_at"] === "string" ? raw["claim_code_expires_at"] : null,
|
|
2237
|
+
raw
|
|
2238
|
+
};
|
|
2219
2239
|
}
|
|
2220
2240
|
};
|
|
2221
2241
|
var InvoServer = class {
|
|
@@ -2509,6 +2529,25 @@ var InvoServer = class {
|
|
|
2509
2529
|
raw
|
|
2510
2530
|
};
|
|
2511
2531
|
}
|
|
2532
|
+
/**
|
|
2533
|
+
* Read a hosted checkout's status from INVO, server-side, with the session token that
|
|
2534
|
+
* {@link createCheckout} returned. Same answer as the browser's
|
|
2535
|
+
* `invo.checkout.getPurchaseStatus`. A game server uses it to confirm a purchase when
|
|
2536
|
+
* the signed webhook cannot reach it (for example a private development preview).
|
|
2537
|
+
* It is INVO's own record, read over TLS with the session credential, never the buyer's word.
|
|
2538
|
+
*/
|
|
2539
|
+
async getCheckoutStatus(input, opts) {
|
|
2540
|
+
const sessionId = String(input?.sessionId ?? "").trim();
|
|
2541
|
+
const sessionToken = String(input?.sessionToken ?? "").trim();
|
|
2542
|
+
if (!sessionId) throw invalidInput2("sessionId", input?.sessionId, "is required");
|
|
2543
|
+
if (!sessionToken) throw invalidInput2("sessionToken", "(hidden)", "is required");
|
|
2544
|
+
const raw = await this.http.get(
|
|
2545
|
+
`/api/checkout/sessions/${encodeURIComponent(sessionId)}`,
|
|
2546
|
+
{ kind: "bearer", token: sessionToken },
|
|
2547
|
+
{ signal: opts?.signal }
|
|
2548
|
+
);
|
|
2549
|
+
return toPurchaseStatusResult(raw, sessionId);
|
|
2550
|
+
}
|
|
2512
2551
|
/**
|
|
2513
2552
|
* Direct purchase via the rail selector. Use when you need a specific rail.
|
|
2514
2553
|
* - rail "platform" (default): standard card. May return status "requires_action"
|
|
@@ -3748,5 +3787,5 @@ var InvoServer = class {
|
|
|
3748
3787
|
};
|
|
3749
3788
|
|
|
3750
3789
|
export { CardsServer, DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, PayoutsServer, PlatformCommerceServer, SANDBOX_BASE_URL, SandboxServer, SandboxSubscriptionsServer, SubscriptionsServer, baseUrlForKey, createWebhookHandler, isDemoKey, isRefundPendingApproval, resolveEnvironment, verifyInvoSignature, verifyWebhook, verifyWebhookAsync };
|
|
3751
|
-
//# sourceMappingURL=chunk-
|
|
3752
|
-
//# sourceMappingURL=chunk-
|
|
3790
|
+
//# sourceMappingURL=chunk-V2RQYQQD.js.map
|
|
3791
|
+
//# sourceMappingURL=chunk-V2RQYQQD.js.map
|