@invonetwork/web-sdk 3.26.0 → 3.27.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 +1369 -1350
- package/README.md +119 -1
- package/dist/chunk-2DYTV74W.js +3681 -0
- package/dist/chunk-3YDO7GSH.js +6 -0
- package/dist/chunk-6CN236QH.js +473 -0
- package/dist/{chunk-7BYAUHTA.js → chunk-VP3OK4J4.js} +56 -459
- package/dist/game-server.cjs +5933 -0
- package/dist/game-server.d.cts +185 -0
- package/dist/game-server.d.ts +185 -0
- package/dist/game-server.js +716 -0
- package/dist/game.cjs +2172 -0
- package/dist/game.d.cts +197 -0
- package/dist/game.d.ts +197 -0
- package/dist/game.js +1034 -0
- package/dist/index.cjs +87 -0
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +26 -2
- package/dist/server.cjs +98 -1
- package/dist/server.d.cts +28 -10
- package/dist/server.d.ts +28 -10
- package/dist/server.js +4 -3649
- package/dist/types-CoW9LopI.d.cts +143 -0
- package/dist/types-CoW9LopI.d.ts +143 -0
- package/dist/{types-Cjd4SAR8.d.cts → types-_lIm74kd.d.cts} +40 -1
- package/dist/{types-Cjd4SAR8.d.ts → types-_lIm74kd.d.ts} +40 -1
- package/dist/version-BXFwI0-s.d.cts +8 -0
- package/dist/version-BXFwI0-s.d.ts +8 -0
- package/package.json +91 -77
|
@@ -1135,474 +1135,71 @@ function errorFromResponse(status, body, requestId) {
|
|
|
1135
1135
|
return new InvoError({ message, code, rawCode, publicCode, status, body, requestId });
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
|
-
// src/shared/
|
|
1139
|
-
var
|
|
1140
|
-
var
|
|
1141
|
-
function
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
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 });
|
|
1138
|
+
// src/shared/loyalty-events.ts
|
|
1139
|
+
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
|
+
var ISO_WITH_ZONE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
1141
|
+
function invalid(label, value, why) {
|
|
1142
|
+
return new InvoError({
|
|
1143
|
+
message: `${label} ${why} (got ${JSON.stringify(value)}).`,
|
|
1144
|
+
code: "INVALID_INPUT",
|
|
1145
|
+
status: 0
|
|
1318
1146
|
});
|
|
1319
1147
|
}
|
|
1320
|
-
function
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
if (
|
|
1325
|
-
|
|
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/loyalty.ts
|
|
1403
|
-
var obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
1404
|
-
var rows = (v) => Array.isArray(v) ? v.filter((r) => r && typeof r === "object" && !Array.isArray(r)) : [];
|
|
1405
|
-
var str = (v) => v === void 0 || v === null ? "" : String(v);
|
|
1406
|
-
var strOrNull = (v) => v === void 0 || v === null ? null : String(v);
|
|
1407
|
-
var numOrNull = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
1408
|
-
var int = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
1409
|
-
var passThrough = (v) => v;
|
|
1410
|
-
function toLoyaltyStepProgress(value) {
|
|
1411
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1412
|
-
const v = value;
|
|
1413
|
-
const current = v["current"];
|
|
1414
|
-
const target = v["target"];
|
|
1415
|
-
if (!Number.isInteger(current) || !Number.isInteger(target)) return null;
|
|
1416
|
-
return { current, target };
|
|
1417
|
-
}
|
|
1418
|
-
function toStep(row) {
|
|
1419
|
-
return {
|
|
1420
|
-
stepId: strOrNull(row["step_id"]),
|
|
1421
|
-
index: int(row["index"]),
|
|
1422
|
-
action: str(row["action"]),
|
|
1423
|
-
label: str(row["label"]),
|
|
1424
|
-
summary: str(row["summary"]),
|
|
1425
|
-
windowHours: numOrNull(row["window_hours"]),
|
|
1426
|
-
state: str(row["state"]),
|
|
1427
|
-
progress: toLoyaltyStepProgress(row["progress"]),
|
|
1428
|
-
raw: row
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
function toCardReward(row) {
|
|
1432
|
-
return {
|
|
1433
|
-
vaultEntryId: str(row["vault_entry_id"]),
|
|
1434
|
-
rewardId: str(row["reward_id"]),
|
|
1435
|
-
state: str(row["state"]),
|
|
1436
|
-
unlockedAt: str(row["unlocked_at"]),
|
|
1437
|
-
expiresAt: str(row["expires_at"]),
|
|
1438
|
-
redeemedAt: strOrNull(row["redeemed_at"]),
|
|
1439
|
-
codeMasked: strOrNull(row["code_masked"]),
|
|
1440
|
-
canRedeem: row["can_redeem"] === true,
|
|
1441
|
-
canRevealAgain: row["can_reveal_again"] === true,
|
|
1442
|
-
revealUntil: strOrNull(row["reveal_until"]),
|
|
1443
|
-
raw: row
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
function toLoyaltyCard(row) {
|
|
1447
|
-
const brand = obj(row["brand"]);
|
|
1448
|
-
const reward = obj(row["reward"]);
|
|
1449
|
-
const steps = rows(row["steps"]).map(toStep);
|
|
1450
|
-
return {
|
|
1451
|
-
cardVersion: passThrough(row["card_version"]),
|
|
1452
|
-
mode: str(row["mode"]),
|
|
1453
|
-
programId: strOrNull(row["program_id"]),
|
|
1454
|
-
questId: strOrNull(row["quest_id"]),
|
|
1455
|
-
questVersion: numOrNull(row["quest_version"]),
|
|
1456
|
-
campaignId: strOrNull(row["campaign_id"]),
|
|
1457
|
-
title: str(row["title"]),
|
|
1458
|
-
description: str(row["description"]),
|
|
1459
|
-
brand: { name: strOrNull(brand["name"]), logoUrl: strOrNull(brand["logo_url"]) },
|
|
1460
|
-
artUrl: strOrNull(row["art_url"]),
|
|
1461
|
-
reward: { rewardId: strOrNull(reward["reward_id"]), name: strOrNull(reward["name"]) },
|
|
1462
|
-
orderMode: str(row["order_mode"]),
|
|
1463
|
-
status: str(row["status"]),
|
|
1464
|
-
startsAt: strOrNull(row["starts_at"]),
|
|
1465
|
-
endsAt: strOrNull(row["ends_at"]),
|
|
1466
|
-
completionHours: numOrNull(row["completion_hours"]),
|
|
1467
|
-
completionNote: strOrNull(row["completion_note"]),
|
|
1468
|
-
windowEndsAt: strOrNull(row["window_ends_at"]),
|
|
1469
|
-
completedAt: strOrNull(row["completed_at"]),
|
|
1470
|
-
stepsRequired: passThrough(row["steps_required"]),
|
|
1471
|
-
stepsComplete: passThrough(row["steps_complete"]),
|
|
1472
|
-
steps,
|
|
1473
|
-
rewards: rows(row["rewards"]).map(toCardReward),
|
|
1474
|
-
raw: row
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1477
|
-
function toLoyaltyCardsResult(raw) {
|
|
1478
|
-
return {
|
|
1479
|
-
cardVersion: passThrough(raw["card_version"]),
|
|
1480
|
-
cards: rows(raw["cards"]).map(toLoyaltyCard),
|
|
1481
|
-
raw
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
function toVaultEntry(row) {
|
|
1485
|
-
return {
|
|
1486
|
-
vaultEntryId: str(row["vault_entry_id"]),
|
|
1487
|
-
rewardRef: str(row["reward_ref"]),
|
|
1488
|
-
programId: str(row["program_id"]),
|
|
1489
|
-
questId: strOrNull(row["quest_id"]),
|
|
1490
|
-
units: str(row["units"]),
|
|
1491
|
-
state: str(row["state"]),
|
|
1492
|
-
unlockedAt: strOrNull(row["unlocked_at"]),
|
|
1493
|
-
expiresAt: strOrNull(row["expires_at"]),
|
|
1494
|
-
redeemedAt: strOrNull(row["redeemed_at"]),
|
|
1495
|
-
codeMasked: strOrNull(row["code_masked"]),
|
|
1496
|
-
raw: row
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1499
|
-
function toLoyaltyVaultResult(raw) {
|
|
1500
|
-
return { items: rows(raw["items"]).map(toVaultEntry), raw };
|
|
1501
|
-
}
|
|
1502
|
-
function toRedeemRewardResult(raw, vaultEntryId) {
|
|
1503
|
-
return {
|
|
1504
|
-
vaultEntryId: str(raw["vault_entry_id"] ?? vaultEntryId),
|
|
1505
|
-
rewardRef: str(raw["reward_ref"]),
|
|
1506
|
-
state: str(raw["state"]),
|
|
1507
|
-
redeemedAt: strOrNull(raw["redeemed_at"]),
|
|
1508
|
-
code: strOrNull(raw["code"]),
|
|
1509
|
-
codeMasked: strOrNull(raw["code_masked"]),
|
|
1510
|
-
revealedAgain: raw["revealed_again"] === true,
|
|
1511
|
-
revealUntil: strOrNull(raw["reveal_until"]),
|
|
1512
|
-
raw
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
function toRewardsPageLink(raw) {
|
|
1516
|
-
return { url: str(raw["url"]), expiresAt: str(raw["expires_at"]), raw };
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
// src/shared/phone-change.ts
|
|
1520
|
-
function phoneChangeSignalMessage(changeRequestId, nonce, timestamp, decision = "approve") {
|
|
1521
|
-
const action = decision === "deny" ? "phone-change-deny" : "phone-change";
|
|
1522
|
-
return `${action}|${changeRequestId}|${nonce}|${Math.trunc(timestamp)}`;
|
|
1523
|
-
}
|
|
1524
|
-
function requireField(value, field, raw) {
|
|
1525
|
-
const s = value == null ? "" : String(value);
|
|
1526
|
-
if (!s) {
|
|
1148
|
+
function newEventId() {
|
|
1149
|
+
const c = globalThis.crypto;
|
|
1150
|
+
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
1151
|
+
const bytes = new Uint8Array(16);
|
|
1152
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
1153
|
+
c.getRandomValues(bytes);
|
|
1154
|
+
} else {
|
|
1527
1155
|
throw new InvoError({
|
|
1528
|
-
message:
|
|
1529
|
-
code: "
|
|
1530
|
-
status: 0
|
|
1531
|
-
body: raw
|
|
1156
|
+
message: "No Web Crypto available to generate an eventId; pass `eventId` yourself.",
|
|
1157
|
+
code: "INVALID_INPUT",
|
|
1158
|
+
status: 0
|
|
1532
1159
|
});
|
|
1533
1160
|
}
|
|
1534
|
-
|
|
1161
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1162
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1163
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1164
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
1535
1165
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
confirmation: str2(raw["confirmation"]),
|
|
1554
|
-
delivery: str2(raw["delivery"]),
|
|
1555
|
-
newPhoneMasked: strOrNull2(raw["new_phone_masked"]),
|
|
1556
|
-
createdAt: strOrNull2(raw["created_at"]),
|
|
1557
|
-
expiresAt: strOrNull2(raw["expires_at"]),
|
|
1558
|
-
confirmedAt: strOrNull2(raw["confirmed_at"]),
|
|
1559
|
-
confirmedVia: strOrNull2(raw["confirmed_via"]),
|
|
1560
|
-
raw
|
|
1561
|
-
};
|
|
1562
|
-
}
|
|
1563
|
-
function toPhoneChangeApprovalsResult(raw) {
|
|
1564
|
-
const rows2 = Array.isArray(raw["approvals"]) ? raw["approvals"] : [];
|
|
1565
|
-
const approvals = rows2.filter((r) => r && typeof r === "object").map((r) => ({
|
|
1566
|
-
changeRequestId: str2(r["change_request_id"]),
|
|
1567
|
-
gameName: strOrNull2(r["game_name"]),
|
|
1568
|
-
oldPhoneMasked: strOrNull2(r["old_phone_masked"]),
|
|
1569
|
-
newPhoneMasked: strOrNull2(r["new_phone_masked"]),
|
|
1570
|
-
expiresAt: strOrNull2(r["expires_at"])
|
|
1571
|
-
}));
|
|
1572
|
-
return { approvals, raw };
|
|
1573
|
-
}
|
|
1574
|
-
function toApprovePhoneChangeResult(raw, changeRequestId) {
|
|
1575
|
-
const id = str2(raw["change_request_id"] ?? changeRequestId);
|
|
1576
|
-
const status = requireField(raw["status"], "status", raw);
|
|
1577
|
-
if (status === "denied") {
|
|
1578
|
-
return { status: "denied", changeRequestId: id, raw };
|
|
1166
|
+
function buildGameEventBody(input) {
|
|
1167
|
+
if (!input || typeof input !== "object") throw invalid("input", input, "must be an object");
|
|
1168
|
+
const { eventType, payload } = input;
|
|
1169
|
+
if (typeof eventType !== "string" || !eventType.startsWith("game.") || eventType.length > 120) {
|
|
1170
|
+
throw invalid("eventType", eventType, "must be a game.* event type");
|
|
1171
|
+
}
|
|
1172
|
+
const eventId = input.eventId === void 0 ? newEventId() : input.eventId;
|
|
1173
|
+
if (typeof eventId !== "string" || !UUID.test(eventId)) {
|
|
1174
|
+
throw invalid("eventId", eventId, "must be a UUID");
|
|
1175
|
+
}
|
|
1176
|
+
const body = { event_type: eventType, event_id: eventId };
|
|
1177
|
+
if (input.occurredAt !== void 0) {
|
|
1178
|
+
const at = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : input.occurredAt;
|
|
1179
|
+
if (typeof at !== "string" || !ISO_WITH_ZONE.test(at) || Number.isNaN(Date.parse(at))) {
|
|
1180
|
+
throw invalid("occurredAt", input.occurredAt, "must be ISO 8601 with a timezone, or a Date");
|
|
1181
|
+
}
|
|
1182
|
+
body["occurred_at"] = at;
|
|
1579
1183
|
}
|
|
1580
|
-
if (
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
}
|
|
1184
|
+
if (payload !== void 0) {
|
|
1185
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
1186
|
+
throw invalid("payload", payload, "must be a plain object");
|
|
1187
|
+
}
|
|
1188
|
+
body["payload"] = payload;
|
|
1189
|
+
} else {
|
|
1190
|
+
body["payload"] = {};
|
|
1587
1191
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1192
|
+
return { body, eventId };
|
|
1193
|
+
}
|
|
1194
|
+
function toReportGameEventResult(raw, eventId) {
|
|
1195
|
+
const echoed = raw["event_id"];
|
|
1196
|
+
return {
|
|
1197
|
+
accepted: true,
|
|
1198
|
+
eventId: typeof echoed === "string" && echoed ? echoed : eventId,
|
|
1595
1199
|
raw
|
|
1596
1200
|
};
|
|
1597
|
-
if (typeof raw["player_token"] === "string" && raw["player_token"]) {
|
|
1598
|
-
out.playerToken = raw["player_token"];
|
|
1599
|
-
if (typeof raw["player_token_expires_at"] === "string") {
|
|
1600
|
-
out.playerTokenExpiresAt = raw["player_token_expires_at"];
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
return out;
|
|
1604
1201
|
}
|
|
1605
1202
|
|
|
1606
|
-
export {
|
|
1607
|
-
//# sourceMappingURL=chunk-
|
|
1608
|
-
//# sourceMappingURL=chunk-
|
|
1203
|
+
export { InvoError, buildGameEventBody, errorFromResponse, newEventId, toReportGameEventResult };
|
|
1204
|
+
//# sourceMappingURL=chunk-VP3OK4J4.js.map
|
|
1205
|
+
//# sourceMappingURL=chunk-VP3OK4J4.js.map
|