@invonetwork/web-sdk 3.28.0 → 3.29.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 +11 -0
- package/README.md +24 -1
- package/dist/{chunk-4YKTKXC5.js → chunk-FJR44FKW.js} +22 -5
- package/dist/chunk-KZJABBVT.js +6 -0
- package/dist/game-server.cjs +166 -14
- package/dist/game-server.d.cts +77 -4
- package/dist/game-server.d.ts +77 -4
- package/dist/game-server.js +147 -17
- package/dist/game.cjs +1 -1
- package/dist/game.d.cts +1 -1
- package/dist/game.d.ts +1 -1
- package/dist/game.js +1 -1
- package/dist/server-Dnx5jxS4.d.ts +2165 -0
- package/dist/server-UZ38eD2p.d.cts +2165 -0
- package/dist/server.cjs +16 -2
- package/dist/server.d.cts +3 -2159
- package/dist/server.d.ts +3 -2159
- package/dist/server.js +2 -2
- package/dist/{version-iWmcxjYu.d.cts → version-xyYQO5hp.d.cts} +1 -1
- package/dist/{version-iWmcxjYu.d.ts → version-xyYQO5hp.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-3DRWLDDF.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.29.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Public demo sandbox (INVO game templates): on the demo key, `invoGameServerFromEnv` maps every sign-in to the demo sandbox's player email format for the fork's project (`toDemoEmail`) and gives the player a fictional 555-01XX phone (`demoPhoneFor`), so no real address or number reaches INVO. The project id comes from `INVO_PROJECT_ID`, else `.invo/project.json` (option `projectFile`), else a new one written there; a copied file on a different public host (a remix) gets a fresh id.
|
|
8
|
+
- New `registerProject({ gameSecret, webhookUrl, file? })` (game-server entry): registers the fork on every start, stores the webhook signing secret and the registration token in the project file the first time, and handles a remix's `409 PROJECT_REGISTERED` by taking a fresh project id. `invoGameServerFromEnv` reads the webhook secret from that file when `INVO_WEBHOOK_SECRET` is not set, or from the new `webhookSecret` option.
|
|
9
|
+
- `verifyInvoSignature(rawBody, header, secrets)`: the INVO webhook signature check under the name the template guide uses (same as `verifyWebhook`).
|
|
10
|
+
- The key-environment lookup is retried on each call until it succeeds (a failure at boot no longer wedges the server), and a production error falls through to the sandbox lookup.
|
|
11
|
+
- `InvoGameServerSetup.environment` is `"sandbox"`, `"production"` or `"resolving"`; `sandbox` is no longer `true` for a live key whose environment is still being looked up.
|
|
12
|
+
- Nothing removed or renamed.
|
|
13
|
+
|
|
3
14
|
## 3.28.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -2398,7 +2398,7 @@ const economy = {
|
|
|
2398
2398
|
],
|
|
2399
2399
|
};
|
|
2400
2400
|
|
|
2401
|
-
// INVO_GAME_SECRET, INVO_WEBHOOK_SECRET,
|
|
2401
|
+
// INVO_GAME_SECRET, INVO_WEBHOOK_SECRET, PUBLIC_URL (the environment follows the key)
|
|
2402
2402
|
const { server, missing } = invoGameServerFromEnv({
|
|
2403
2403
|
economy,
|
|
2404
2404
|
env: process.env,
|
|
@@ -2409,6 +2409,29 @@ http.createServer(toNodeListener(server, serveYourStaticFiles)).listen(3000);
|
|
|
2409
2409
|
|
|
2410
2410
|
Point your INVO webhook at `https://<your-host>/api/invo/webhook`.
|
|
2411
2411
|
|
|
2412
|
+
**On the public demo key (INVO's game templates).** A fresh fork runs on the public demo key
|
|
2413
|
+
(`ivsdk_demo_...`, sandbox only, no signup). Register the fork on every start; the first time,
|
|
2414
|
+
the webhook signing secret and a registration token are stored in `.invo/project.json` (add it to
|
|
2415
|
+
`.gitignore`; a remix that copied it gets a fresh project id automatically):
|
|
2416
|
+
|
|
2417
|
+
```ts
|
|
2418
|
+
import { registerProject, invoGameServerFromEnv } from "@invonetwork/web-sdk/game-server";
|
|
2419
|
+
|
|
2420
|
+
if (process.env.INVO_GAME_SECRET?.startsWith("ivsdk_demo_")) {
|
|
2421
|
+
await registerProject({
|
|
2422
|
+
gameSecret: process.env.INVO_GAME_SECRET,
|
|
2423
|
+
webhookUrl: `${process.env.PUBLIC_URL}/api/invo/webhook`,
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
const { server } = invoGameServerFromEnv({ economy, env: process.env, store });
|
|
2427
|
+
```
|
|
2428
|
+
|
|
2429
|
+
On the demo key every sign-in is mapped to a demo-sandbox player email for this project and a
|
|
2430
|
+
fictional 555-01XX phone, so no real address or number reaches INVO. Going live is replacing
|
|
2431
|
+
`INVO_GAME_SECRET` with your own key (and `INVO_WEBHOOK_SECRET` with the secret from your INVO
|
|
2432
|
+
console): no code changes. `verifyInvoSignature(rawBody, header, secrets)` checks an INVO webhook
|
|
2433
|
+
signature anywhere else you need it.
|
|
2434
|
+
|
|
2412
2435
|
**Browser.**
|
|
2413
2436
|
|
|
2414
2437
|
```ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertSecureBaseUrl, Http, toRequestPhoneChangeResult, toPhoneChangeRequest, receiptFields, creditFields, toLoyaltyCardsResult, toDestinationsResult } from './chunk-6CN236QH.js';
|
|
2
|
-
import { SDK_VERSION } from './chunk-
|
|
2
|
+
import { SDK_VERSION } from './chunk-KZJABBVT.js';
|
|
3
3
|
import { InvoError, buildGameEventBody, toReportGameEventResult } from './chunk-VP3OK4J4.js';
|
|
4
4
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
5
5
|
|
|
@@ -294,6 +294,9 @@ function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
|
294
294
|
}
|
|
295
295
|
return finalizeEvent(bodyBytes);
|
|
296
296
|
}
|
|
297
|
+
function verifyInvoSignature(rawBody, signatureHeader, secrets, opts = {}) {
|
|
298
|
+
return verifyWebhook(rawBody, signatureHeader, secrets, opts);
|
|
299
|
+
}
|
|
297
300
|
async function verifyWebhookAsync(rawBody, signatureHeader, secret, opts = {}) {
|
|
298
301
|
const { secrets, sigs, message, bodyBytes } = prepareVerification(
|
|
299
302
|
rawBody,
|
|
@@ -401,7 +404,21 @@ function resolveEnvironment(gameSecret, opts = {}) {
|
|
|
401
404
|
if (hit) return hit;
|
|
402
405
|
const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
403
406
|
const p = (async () => {
|
|
404
|
-
|
|
407
|
+
let prodError = null;
|
|
408
|
+
let env = null;
|
|
409
|
+
try {
|
|
410
|
+
env = await ask(PRODUCTION_BASE_URL, gameSecret, fetchImpl);
|
|
411
|
+
} catch (err) {
|
|
412
|
+
prodError = err;
|
|
413
|
+
}
|
|
414
|
+
if (!env) {
|
|
415
|
+
try {
|
|
416
|
+
env = await ask(SANDBOX_BASE_URL, gameSecret, fetchImpl);
|
|
417
|
+
} catch (err) {
|
|
418
|
+
throw prodError ?? err;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (!env && prodError) throw prodError;
|
|
405
422
|
if (!env) {
|
|
406
423
|
throw new EnvironmentUnknownError(
|
|
407
424
|
"Neither INVO production nor the INVO sandbox recognises this key. Check INVO_GAME_SECRET in your secrets."
|
|
@@ -3730,6 +3747,6 @@ var InvoServer = class {
|
|
|
3730
3747
|
}
|
|
3731
3748
|
};
|
|
3732
3749
|
|
|
3733
|
-
export { CardsServer, DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, PayoutsServer, PlatformCommerceServer, SANDBOX_BASE_URL, SandboxServer, SandboxSubscriptionsServer, SubscriptionsServer, baseUrlForKey, createWebhookHandler, isDemoKey, isRefundPendingApproval, resolveEnvironment, verifyWebhook, verifyWebhookAsync };
|
|
3734
|
-
//# sourceMappingURL=chunk-
|
|
3735
|
-
//# sourceMappingURL=chunk-
|
|
3750
|
+
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-FJR44FKW.js.map
|
|
3752
|
+
//# sourceMappingURL=chunk-FJR44FKW.js.map
|
package/dist/game-server.cjs
CHANGED
|
@@ -64,7 +64,21 @@ function resolveEnvironment(gameSecret, opts = {}) {
|
|
|
64
64
|
if (hit) return hit;
|
|
65
65
|
const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
66
66
|
const p = (async () => {
|
|
67
|
-
|
|
67
|
+
let prodError = null;
|
|
68
|
+
let env = null;
|
|
69
|
+
try {
|
|
70
|
+
env = await ask(PRODUCTION_BASE_URL, gameSecret, fetchImpl);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
prodError = err;
|
|
73
|
+
}
|
|
74
|
+
if (!env) {
|
|
75
|
+
try {
|
|
76
|
+
env = await ask(SANDBOX_BASE_URL, gameSecret, fetchImpl);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
throw prodError ?? err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!env && prodError) throw prodError;
|
|
68
82
|
if (!env) {
|
|
69
83
|
throw new EnvironmentUnknownError(
|
|
70
84
|
"Neither INVO production nor the INVO sandbox recognises this key. Check INVO_GAME_SECRET in your secrets."
|
|
@@ -1671,7 +1685,7 @@ function toPhoneChangeRequest(raw) {
|
|
|
1671
1685
|
}
|
|
1672
1686
|
|
|
1673
1687
|
// src/version.ts
|
|
1674
|
-
var SDK_VERSION = "3.
|
|
1688
|
+
var SDK_VERSION = "3.29.0";
|
|
1675
1689
|
|
|
1676
1690
|
// src/payouts.ts
|
|
1677
1691
|
var AMOUNT = /^\d+(\.\d{1,2})?$/;
|
|
@@ -1953,6 +1967,9 @@ function verifyWebhook(rawBody, signatureHeader, secret, opts = {}) {
|
|
|
1953
1967
|
}
|
|
1954
1968
|
return finalizeEvent(bodyBytes);
|
|
1955
1969
|
}
|
|
1970
|
+
function verifyInvoSignature(rawBody, signatureHeader, secrets, opts = {}) {
|
|
1971
|
+
return verifyWebhook(rawBody, signatureHeader, secrets, opts);
|
|
1972
|
+
}
|
|
1956
1973
|
|
|
1957
1974
|
// src/server.ts
|
|
1958
1975
|
var DEFAULT_UA = `invonetwork-web-sdk/${SDK_VERSION} (+https://invo.network)`;
|
|
@@ -5266,6 +5283,119 @@ var InvoServer = class {
|
|
|
5266
5283
|
};
|
|
5267
5284
|
}
|
|
5268
5285
|
};
|
|
5286
|
+
var DEMO_EMAIL_DOMAIN = "demo.invo.network";
|
|
5287
|
+
var DEFAULT_PROJECT_FILE = ".invo/project.json";
|
|
5288
|
+
var PROJECT_ID = /^proj_[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
5289
|
+
function newDemoProjectId(now = Date.now()) {
|
|
5290
|
+
const A = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
5291
|
+
let t = now;
|
|
5292
|
+
let time = "";
|
|
5293
|
+
for (let i = 0; i < 10; i++) {
|
|
5294
|
+
time = A[t % 32] + time;
|
|
5295
|
+
t = Math.floor(t / 32);
|
|
5296
|
+
}
|
|
5297
|
+
const bytes = crypto.randomBytes(16);
|
|
5298
|
+
let rand = "";
|
|
5299
|
+
for (let i = 0; i < 16; i++) rand += A[bytes[i] % 32];
|
|
5300
|
+
return "proj_" + time + rand;
|
|
5301
|
+
}
|
|
5302
|
+
function isValidProjectId(value) {
|
|
5303
|
+
return typeof value === "string" && PROJECT_ID.test(value);
|
|
5304
|
+
}
|
|
5305
|
+
function toDemoEmail(email, projectId) {
|
|
5306
|
+
if (!isValidProjectId(projectId)) throw new Error("A valid template project id is required.");
|
|
5307
|
+
const lower = email.trim().toLowerCase();
|
|
5308
|
+
if (lower.endsWith("@" + DEMO_EMAIL_DOMAIN)) return lower;
|
|
5309
|
+
const local = (lower.split("@")[0] ?? "player").replace(/[^a-z0-9._-]/g, "").slice(0, 24) || "player";
|
|
5310
|
+
const tag = crypto.createHash("sha256").update(lower).digest("hex").slice(0, 8);
|
|
5311
|
+
return `${local}-${tag}+${projectId.slice(5).toLowerCase()}@${DEMO_EMAIL_DOMAIN}`;
|
|
5312
|
+
}
|
|
5313
|
+
function demoPhoneFor(email) {
|
|
5314
|
+
const n = BigInt("0x" + crypto.createHash("sha256").update(email.trim().toLowerCase()).digest("hex")) % BigInt(100);
|
|
5315
|
+
return "+120255501" + n.toString().padStart(2, "0");
|
|
5316
|
+
}
|
|
5317
|
+
function hostOf(url) {
|
|
5318
|
+
if (!url) return void 0;
|
|
5319
|
+
try {
|
|
5320
|
+
return new URL(url).host.toLowerCase();
|
|
5321
|
+
} catch {
|
|
5322
|
+
return void 0;
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
function readFile(file) {
|
|
5326
|
+
try {
|
|
5327
|
+
const data = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
5328
|
+
return isValidProjectId(data.projectId) ? data : null;
|
|
5329
|
+
} catch {
|
|
5330
|
+
return null;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
function writeFile(file, data) {
|
|
5334
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
5335
|
+
fs.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", { encoding: "utf8", mode: 384 });
|
|
5336
|
+
}
|
|
5337
|
+
function loadProject(opts = {}) {
|
|
5338
|
+
const file = opts.file ?? DEFAULT_PROJECT_FILE;
|
|
5339
|
+
if (opts.projectId) {
|
|
5340
|
+
if (!isValidProjectId(opts.projectId)) throw new Error('INVO_PROJECT_ID must be "proj_" + a 26-character ULID.');
|
|
5341
|
+
const saved2 = readFile(file);
|
|
5342
|
+
return saved2 && saved2.projectId === opts.projectId ? saved2 : { projectId: opts.projectId };
|
|
5343
|
+
}
|
|
5344
|
+
const host = hostOf(opts.publicUrl);
|
|
5345
|
+
const saved = readFile(file);
|
|
5346
|
+
if (saved && (!host || !saved.host || saved.host === host)) return saved;
|
|
5347
|
+
const fresh = { projectId: newDemoProjectId(), host };
|
|
5348
|
+
try {
|
|
5349
|
+
writeFile(file, fresh);
|
|
5350
|
+
} catch {
|
|
5351
|
+
}
|
|
5352
|
+
return fresh;
|
|
5353
|
+
}
|
|
5354
|
+
async function registerProject(opts) {
|
|
5355
|
+
if (!isDemoKey(opts.gameSecret)) throw new Error("registerProject is for the public demo key only.");
|
|
5356
|
+
const file = opts.file ?? DEFAULT_PROJECT_FILE;
|
|
5357
|
+
const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
5358
|
+
const base = (opts.baseUrl ?? SANDBOX_BASE_URL).replace(/\/+$/, "");
|
|
5359
|
+
let project = loadProject({ file, publicUrl: opts.webhookUrl, projectId: opts.projectId });
|
|
5360
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
5361
|
+
const res = await fetchImpl(base + "/api/demo/projects/register", {
|
|
5362
|
+
method: "POST",
|
|
5363
|
+
redirect: "error",
|
|
5364
|
+
headers: {
|
|
5365
|
+
"Content-Type": "application/json",
|
|
5366
|
+
Accept: "application/json",
|
|
5367
|
+
"X-Game-Secret-Key": opts.gameSecret,
|
|
5368
|
+
"X-Invo-Project-Id": project.projectId,
|
|
5369
|
+
"X-Invo-Project-Host": hostOf(opts.webhookUrl) ?? ""
|
|
5370
|
+
},
|
|
5371
|
+
body: JSON.stringify({ webhook_url: opts.webhookUrl, registration_token: project.registrationToken })
|
|
5372
|
+
});
|
|
5373
|
+
const body = await res.json().catch(() => ({}));
|
|
5374
|
+
if (res.status === 409 && body.error_code === "PROJECT_REGISTERED" && attempt === 0 && !opts.projectId) {
|
|
5375
|
+
project = { projectId: newDemoProjectId(), host: hostOf(opts.webhookUrl) };
|
|
5376
|
+
continue;
|
|
5377
|
+
}
|
|
5378
|
+
if (!res.ok) throw new Error(`INVO demo registration failed (${res.status} ${body.error_code ?? ""}): ${body.error ?? ""}`.trim());
|
|
5379
|
+
const created = res.status === 201;
|
|
5380
|
+
if (created) {
|
|
5381
|
+
project = {
|
|
5382
|
+
projectId: project.projectId,
|
|
5383
|
+
host: hostOf(opts.webhookUrl),
|
|
5384
|
+
webhookUrl: opts.webhookUrl,
|
|
5385
|
+
webhookSecret: body.webhook?.signing_secret ?? project.webhookSecret,
|
|
5386
|
+
registrationToken: body.registration_token ?? project.registrationToken
|
|
5387
|
+
};
|
|
5388
|
+
} else {
|
|
5389
|
+
project = { ...project, host: project.host ?? hostOf(opts.webhookUrl), webhookUrl: opts.webhookUrl };
|
|
5390
|
+
}
|
|
5391
|
+
try {
|
|
5392
|
+
writeFile(file, project);
|
|
5393
|
+
} catch {
|
|
5394
|
+
}
|
|
5395
|
+
return { projectId: project.projectId, webhookSecret: project.webhookSecret ?? null, created };
|
|
5396
|
+
}
|
|
5397
|
+
throw new Error("INVO demo registration failed.");
|
|
5398
|
+
}
|
|
5269
5399
|
|
|
5270
5400
|
// src/game/server.ts
|
|
5271
5401
|
var MAX_BODY_BYTES = 1e6;
|
|
@@ -5459,9 +5589,12 @@ function createInvoGameServer(options) {
|
|
|
5459
5589
|
const name = (rawName || email.split("@")[0] || "Player").slice(0, 64);
|
|
5460
5590
|
const id = playerIdFor(email);
|
|
5461
5591
|
const known = await store.read((s) => s.players[id] ?? null);
|
|
5462
|
-
const
|
|
5592
|
+
const demoPid = options.demoProjectId;
|
|
5593
|
+
const invoEmail = demoPid ? toDemoEmail(email, demoPid) : email;
|
|
5594
|
+
const phoneForInvo = demoPid ? demoPhoneFor(invoEmail) : phone ?? known?.phone ?? void 0;
|
|
5595
|
+
const storedPhone = demoPid ? null : phone;
|
|
5463
5596
|
try {
|
|
5464
|
-
await invo.mintPlayerToken({ playerEmail:
|
|
5597
|
+
await invo.mintPlayerToken({ playerEmail: invoEmail, playerPhone: phoneForInvo, playerName: name });
|
|
5465
5598
|
} catch (err) {
|
|
5466
5599
|
if (err instanceof InvoError && err.status === 404) {
|
|
5467
5600
|
throw new GameServerError(400, "PHONE_REQUIRED", "First sign-in needs a phone number so INVO can create your account.");
|
|
@@ -5473,7 +5606,7 @@ function createInvoGameServer(options) {
|
|
|
5473
5606
|
const expiresAt = new Date(now().getTime() + sessionTtlMs).toISOString();
|
|
5474
5607
|
const player = await store.transact((s) => {
|
|
5475
5608
|
const existing = s.players[id];
|
|
5476
|
-
const record = existing ? { ...existing, name, phone:
|
|
5609
|
+
const record = existing ? { ...existing, email: invoEmail, name, phone: storedPhone ?? existing.phone } : { id, email: invoEmail, phone: storedPhone, name, createdAt: iso() };
|
|
5477
5610
|
s.players[id] = record;
|
|
5478
5611
|
if (soft.starting > 0) {
|
|
5479
5612
|
addLedger(s, { playerId: id, currency: "soft", amount: soft.starting, reason: "starting balance", ref: `start:${id}`, at: iso() });
|
|
@@ -5812,23 +5945,33 @@ function invoGameServerFromEnv(options) {
|
|
|
5812
5945
|
const forced = env["INVO_ENV"]?.trim().toLowerCase();
|
|
5813
5946
|
const known = forced ? forced === "production" ? "production" : "sandbox" : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
|
|
5814
5947
|
const state = { environment: known };
|
|
5815
|
-
const sandboxNow = () => state.environment
|
|
5816
|
-
const
|
|
5948
|
+
const sandboxNow = () => state.environment === "sandbox";
|
|
5949
|
+
const envNow = () => state.environment ?? "resolving";
|
|
5950
|
+
const demo = isDemoKey(secret);
|
|
5951
|
+
const demoProject = demo ? loadProject({ file: options.projectFile ?? DEFAULT_PROJECT_FILE, publicUrl: env["PUBLIC_URL"], projectId: (options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0 }) : null;
|
|
5952
|
+
const webhookSecrets = (() => {
|
|
5953
|
+
const raw = options.webhookSecret ?? env["INVO_WEBHOOK_SECRET"] ?? demoProject?.webhookSecret ?? "";
|
|
5954
|
+
return (Array.isArray(raw) ? raw : raw.split(",")).map((s) => s.trim()).filter(Boolean);
|
|
5955
|
+
})();
|
|
5956
|
+
const missing = [
|
|
5957
|
+
...secret ? [] : ["INVO_GAME_SECRET"],
|
|
5958
|
+
...webhookSecrets.length ? [] : ["INVO_WEBHOOK_SECRET"]
|
|
5959
|
+
];
|
|
5817
5960
|
if (missing.length) {
|
|
5818
|
-
return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath), missing, sandbox: sandboxNow() };
|
|
5961
|
+
return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath), missing, sandbox: sandboxNow(), environment: envNow() };
|
|
5819
5962
|
}
|
|
5820
5963
|
const baseFetch = options.fetch ?? ((input, init) => fetch(input, init));
|
|
5821
|
-
const projectId = (options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0;
|
|
5964
|
+
const projectId = demoProject?.projectId ?? ((options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0);
|
|
5822
5965
|
const explicitBase = env["INVO_BASE_URL"] || (forced ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
|
|
5823
|
-
const
|
|
5966
|
+
const resolveNow = () => resolveEnvironment(secret, { fetch: baseFetch }).then((e) => {
|
|
5824
5967
|
state.environment = e;
|
|
5825
5968
|
return e;
|
|
5826
5969
|
});
|
|
5827
|
-
|
|
5970
|
+
if (!explicitBase && !known) resolveNow().catch(() => void 0);
|
|
5828
5971
|
const invoFetch = async (input, init) => {
|
|
5829
5972
|
let url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
5830
5973
|
if (!explicitBase) {
|
|
5831
|
-
const e = known ?? await
|
|
5974
|
+
const e = known ?? state.environment ?? await resolveNow();
|
|
5832
5975
|
if (e === "sandbox" && url.startsWith(PRODUCTION_BASE_URL + "/")) url = SANDBOX_BASE_URL + url.slice(PRODUCTION_BASE_URL.length);
|
|
5833
5976
|
}
|
|
5834
5977
|
const headers = new Headers(init?.headers);
|
|
@@ -5838,7 +5981,8 @@ function invoGameServerFromEnv(options) {
|
|
|
5838
5981
|
const invo = new InvoServer({ gameSecret: secret, baseUrl: explicitBase || PRODUCTION_BASE_URL, fetch: invoFetch });
|
|
5839
5982
|
const serverOptions = {
|
|
5840
5983
|
invo,
|
|
5841
|
-
webhookSecret:
|
|
5984
|
+
webhookSecret: webhookSecrets,
|
|
5985
|
+
demoProjectId: demo ? projectId : void 0,
|
|
5842
5986
|
economy: options.economy,
|
|
5843
5987
|
store: options.store,
|
|
5844
5988
|
get sandbox() {
|
|
@@ -5849,7 +5993,7 @@ function invoGameServerFromEnv(options) {
|
|
|
5849
5993
|
log: options.log
|
|
5850
5994
|
};
|
|
5851
5995
|
const server = createInvoGameServer(serverOptions);
|
|
5852
|
-
return { server, missing, sandbox: sandboxNow() };
|
|
5996
|
+
return { server, missing, sandbox: sandboxNow(), environment: envNow() };
|
|
5853
5997
|
}
|
|
5854
5998
|
function newProjectId(now = Date.now()) {
|
|
5855
5999
|
const A = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -6001,6 +6145,8 @@ function createFileGameStore(options) {
|
|
|
6001
6145
|
};
|
|
6002
6146
|
}
|
|
6003
6147
|
|
|
6148
|
+
exports.DEFAULT_PROJECT_FILE = DEFAULT_PROJECT_FILE;
|
|
6149
|
+
exports.DEMO_EMAIL_DOMAIN = DEMO_EMAIL_DOMAIN;
|
|
6004
6150
|
exports.DEMO_KEY_PREFIX = DEMO_KEY_PREFIX;
|
|
6005
6151
|
exports.EnvironmentUnknownError = EnvironmentUnknownError;
|
|
6006
6152
|
exports.GameServerError = GameServerError;
|
|
@@ -6013,13 +6159,19 @@ exports.baseUrlForKey = baseUrlForKey;
|
|
|
6013
6159
|
exports.createFileGameStore = createFileGameStore;
|
|
6014
6160
|
exports.createInvoGameServer = createInvoGameServer;
|
|
6015
6161
|
exports.createMemoryGameStore = createMemoryGameStore;
|
|
6162
|
+
exports.demoPhoneFor = demoPhoneFor;
|
|
6016
6163
|
exports.emptyGameState = emptyGameState;
|
|
6017
6164
|
exports.invoGameServerFromEnv = invoGameServerFromEnv;
|
|
6018
6165
|
exports.isDemoKey = isDemoKey;
|
|
6166
|
+
exports.isValidProjectId = isValidProjectId;
|
|
6167
|
+
exports.loadProject = loadProject;
|
|
6019
6168
|
exports.newProjectId = newProjectId;
|
|
6020
6169
|
exports.playerIdFor = playerIdFor;
|
|
6170
|
+
exports.registerProject = registerProject;
|
|
6021
6171
|
exports.resolveEnvironment = resolveEnvironment;
|
|
6172
|
+
exports.toDemoEmail = toDemoEmail;
|
|
6022
6173
|
exports.toNodeListener = toNodeListener;
|
|
6023
6174
|
exports.validateEconomy = validateEconomy;
|
|
6175
|
+
exports.verifyInvoSignature = verifyInvoSignature;
|
|
6024
6176
|
//# sourceMappingURL=game-server.cjs.map
|
|
6025
6177
|
//# sourceMappingURL=game-server.cjs.map
|
package/dist/game-server.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { InvoServer } from './server.cjs';
|
|
2
|
-
export { DEMO_KEY_PREFIX, EnvironmentUnknownError,
|
|
1
|
+
import { I as InvoServer, a as InvoEnvironment } from './server-UZ38eD2p.cjs';
|
|
2
|
+
export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-UZ38eD2p.cjs';
|
|
3
3
|
import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-CoW9LopI.cjs';
|
|
4
4
|
export { c as GameCatalog, d as GameCatalogItem, e as GameCheckout, f as GameCurrencyBalance, g as GameErrorBody, h as GameItemPurchase, i as GamePlayer, j as GamePremiumPack, k as GamePurchase, l as GameSession, m as GameWallet } from './types-CoW9LopI.cjs';
|
|
5
5
|
export { I as InvoError } from './types-_lIm74kd.cjs';
|
|
6
|
-
export { S as SDK_VERSION } from './version-
|
|
6
|
+
export { S as SDK_VERSION } from './version-xyYQO5hp.cjs';
|
|
7
7
|
|
|
8
8
|
interface StoredPlayer {
|
|
9
9
|
id: string;
|
|
@@ -109,6 +109,12 @@ interface InvoGameServerOptions {
|
|
|
109
109
|
now?: () => Date;
|
|
110
110
|
/** Structured log sink. Never receives secrets, tokens or full phone numbers. */
|
|
111
111
|
log?: (level: GameServerLogLevel, message: string, fields?: Record<string, unknown>) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Set when `invo` uses the public demo key (3.29.0): sign-ins are mapped to the demo
|
|
114
|
+
* sandbox's player email format for this project and given a fictional phone, so no real
|
|
115
|
+
* address or number ever reaches INVO. {@link invoGameServerFromEnv} sets it for you.
|
|
116
|
+
*/
|
|
117
|
+
demoProjectId?: string;
|
|
112
118
|
}
|
|
113
119
|
interface InvoGameServer {
|
|
114
120
|
readonly basePath: string;
|
|
@@ -143,6 +149,16 @@ interface InvoGameServerFromEnvOptions {
|
|
|
143
149
|
* secret. `INVO_PROJECT_ID` in `env` is used when this is not given.
|
|
144
150
|
*/
|
|
145
151
|
projectId?: string;
|
|
152
|
+
/**
|
|
153
|
+
* The webhook signing secret, when it does not come from `INVO_WEBHOOK_SECRET` (3.29.0):
|
|
154
|
+
* for example the one {@link registerProject} stored for a template fork.
|
|
155
|
+
*/
|
|
156
|
+
webhookSecret?: string | string[];
|
|
157
|
+
/**
|
|
158
|
+
* Public demo key only: where the fork's project id, webhook secret and registration token
|
|
159
|
+
* are kept. Default `.invo/project.json`. Keep it out of version control.
|
|
160
|
+
*/
|
|
161
|
+
projectFile?: string;
|
|
146
162
|
/** Override `fetch` for the calls to INVO (tests, proxies). */
|
|
147
163
|
fetch?: typeof fetch;
|
|
148
164
|
}
|
|
@@ -151,7 +167,10 @@ interface InvoGameServerSetup {
|
|
|
151
167
|
server: InvoGameServer;
|
|
152
168
|
/** Names of required environment variables that are not set. Empty when ready. */
|
|
153
169
|
missing: string[];
|
|
170
|
+
/** True once the key is known to be a sandbox key. False while a live key is being looked up. */
|
|
154
171
|
sandbox: boolean;
|
|
172
|
+
/** `"sandbox"`, `"production"`, or `"resolving"` while a key's environment is being looked up. */
|
|
173
|
+
environment: InvoEnvironment | "resolving";
|
|
155
174
|
}
|
|
156
175
|
/**
|
|
157
176
|
* Build the game server from environment variables (Replit Secrets, `.env`, your host's
|
|
@@ -190,4 +209,58 @@ interface NodeResponseLike {
|
|
|
190
209
|
*/
|
|
191
210
|
declare function toNodeListener(server: InvoGameServer, fallback?: (req: NodeRequestLike, res: NodeResponseLike) => unknown): (req: NodeRequestLike, res: NodeResponseLike) => Promise<void>;
|
|
192
211
|
|
|
193
|
-
|
|
212
|
+
declare const DEMO_EMAIL_DOMAIN = "demo.invo.network";
|
|
213
|
+
declare const DEFAULT_PROJECT_FILE = ".invo/project.json";
|
|
214
|
+
/** What the project file holds. Secrets: keep the file out of version control. */
|
|
215
|
+
interface DemoProjectFile {
|
|
216
|
+
projectId: string;
|
|
217
|
+
/** The public host the project was registered from (remix detection). */
|
|
218
|
+
host?: string;
|
|
219
|
+
webhookUrl?: string;
|
|
220
|
+
webhookSecret?: string;
|
|
221
|
+
registrationToken?: string;
|
|
222
|
+
}
|
|
223
|
+
declare function isValidProjectId(value: unknown): value is string;
|
|
224
|
+
/**
|
|
225
|
+
* The demo-sandbox email for a player, deterministic per (email, project):
|
|
226
|
+
* `<local part, cleaned>-<8 hex of sha256(email)>+<project ulid lowercase>@demo.invo.network`.
|
|
227
|
+
*/
|
|
228
|
+
declare function toDemoEmail(email: string, projectId: string): string;
|
|
229
|
+
/** The fictional phone INVO's demo sandbox accepts for a player: `+1202555 01XX`. */
|
|
230
|
+
declare function demoPhoneFor(email: string): string;
|
|
231
|
+
/**
|
|
232
|
+
* This fork's project, from `INVO_PROJECT_ID`, else the project file, else a new id written to
|
|
233
|
+
* the file. When `publicUrl`'s host differs from the host the file was registered from, the file
|
|
234
|
+
* was copied by a remix: a fresh project id replaces it.
|
|
235
|
+
*/
|
|
236
|
+
declare function loadProject(opts?: {
|
|
237
|
+
file?: string;
|
|
238
|
+
publicUrl?: string;
|
|
239
|
+
projectId?: string;
|
|
240
|
+
}): DemoProjectFile;
|
|
241
|
+
interface RegisterProjectOptions {
|
|
242
|
+
/** The public demo key (`ivsdk_demo_...`). */
|
|
243
|
+
gameSecret: string;
|
|
244
|
+
/** This fork's public webhook URL, e.g. `https://my-game.replit.app/api/invo/webhook`. */
|
|
245
|
+
webhookUrl: string;
|
|
246
|
+
file?: string;
|
|
247
|
+
projectId?: string;
|
|
248
|
+
baseUrl?: string;
|
|
249
|
+
fetch?: typeof fetch;
|
|
250
|
+
}
|
|
251
|
+
interface RegisteredProject {
|
|
252
|
+
projectId: string;
|
|
253
|
+
/** The signing secret to verify INVO webhooks with, or null if INVO never returned one. */
|
|
254
|
+
webhookSecret: string | null;
|
|
255
|
+
/** True when this call created the registration (a new fork). */
|
|
256
|
+
created: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Register this fork with the demo sandbox (call on every server start). The first call
|
|
260
|
+
* stores the webhook signing secret and the registration token in the project file; later
|
|
261
|
+
* calls change nothing unless the webhook URL moved. A `409 PROJECT_REGISTERED` (a remix that
|
|
262
|
+
* copied another fork's project id) gets a fresh project id, once.
|
|
263
|
+
*/
|
|
264
|
+
declare function registerProject(opts: RegisterProjectOptions): Promise<RegisteredProject>;
|
|
265
|
+
|
|
266
|
+
export { DEFAULT_PROJECT_FILE, DEMO_EMAIL_DOMAIN, type DemoProjectFile, type FileGameStoreOptions, GameCurrencyKind, GameEconomyConfig, GamePurchaseStatus, GameServerError, type GameServerLogLevel, type GameStore, type GameStoreState, InvoEnvironment, type InvoGameServer, type InvoGameServerFromEnvOptions, type InvoGameServerOptions, type InvoGameServerSetup, InvoServer, type LedgerEntry, type NodeRequestLike, type NodeResponseLike, type RegisterProjectOptions, type RegisteredProject, type StoredIdempotentResult, type StoredPlayer, type StoredPurchase, type StoredSession, createFileGameStore, createInvoGameServer, createMemoryGameStore, demoPhoneFor, emptyGameState, invoGameServerFromEnv, isValidProjectId, loadProject, newProjectId, playerIdFor, registerProject, toDemoEmail, toNodeListener, validateEconomy };
|
package/dist/game-server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { InvoServer } from './server.js';
|
|
2
|
-
export { DEMO_KEY_PREFIX, EnvironmentUnknownError,
|
|
1
|
+
import { I as InvoServer, a as InvoEnvironment } from './server-Dnx5jxS4.js';
|
|
2
|
+
export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, b as baseUrlForKey, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-Dnx5jxS4.js';
|
|
3
3
|
import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-CoW9LopI.js';
|
|
4
4
|
export { c as GameCatalog, d as GameCatalogItem, e as GameCheckout, f as GameCurrencyBalance, g as GameErrorBody, h as GameItemPurchase, i as GamePlayer, j as GamePremiumPack, k as GamePurchase, l as GameSession, m as GameWallet } from './types-CoW9LopI.js';
|
|
5
5
|
export { I as InvoError } from './types-_lIm74kd.js';
|
|
6
|
-
export { S as SDK_VERSION } from './version-
|
|
6
|
+
export { S as SDK_VERSION } from './version-xyYQO5hp.js';
|
|
7
7
|
|
|
8
8
|
interface StoredPlayer {
|
|
9
9
|
id: string;
|
|
@@ -109,6 +109,12 @@ interface InvoGameServerOptions {
|
|
|
109
109
|
now?: () => Date;
|
|
110
110
|
/** Structured log sink. Never receives secrets, tokens or full phone numbers. */
|
|
111
111
|
log?: (level: GameServerLogLevel, message: string, fields?: Record<string, unknown>) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Set when `invo` uses the public demo key (3.29.0): sign-ins are mapped to the demo
|
|
114
|
+
* sandbox's player email format for this project and given a fictional phone, so no real
|
|
115
|
+
* address or number ever reaches INVO. {@link invoGameServerFromEnv} sets it for you.
|
|
116
|
+
*/
|
|
117
|
+
demoProjectId?: string;
|
|
112
118
|
}
|
|
113
119
|
interface InvoGameServer {
|
|
114
120
|
readonly basePath: string;
|
|
@@ -143,6 +149,16 @@ interface InvoGameServerFromEnvOptions {
|
|
|
143
149
|
* secret. `INVO_PROJECT_ID` in `env` is used when this is not given.
|
|
144
150
|
*/
|
|
145
151
|
projectId?: string;
|
|
152
|
+
/**
|
|
153
|
+
* The webhook signing secret, when it does not come from `INVO_WEBHOOK_SECRET` (3.29.0):
|
|
154
|
+
* for example the one {@link registerProject} stored for a template fork.
|
|
155
|
+
*/
|
|
156
|
+
webhookSecret?: string | string[];
|
|
157
|
+
/**
|
|
158
|
+
* Public demo key only: where the fork's project id, webhook secret and registration token
|
|
159
|
+
* are kept. Default `.invo/project.json`. Keep it out of version control.
|
|
160
|
+
*/
|
|
161
|
+
projectFile?: string;
|
|
146
162
|
/** Override `fetch` for the calls to INVO (tests, proxies). */
|
|
147
163
|
fetch?: typeof fetch;
|
|
148
164
|
}
|
|
@@ -151,7 +167,10 @@ interface InvoGameServerSetup {
|
|
|
151
167
|
server: InvoGameServer;
|
|
152
168
|
/** Names of required environment variables that are not set. Empty when ready. */
|
|
153
169
|
missing: string[];
|
|
170
|
+
/** True once the key is known to be a sandbox key. False while a live key is being looked up. */
|
|
154
171
|
sandbox: boolean;
|
|
172
|
+
/** `"sandbox"`, `"production"`, or `"resolving"` while a key's environment is being looked up. */
|
|
173
|
+
environment: InvoEnvironment | "resolving";
|
|
155
174
|
}
|
|
156
175
|
/**
|
|
157
176
|
* Build the game server from environment variables (Replit Secrets, `.env`, your host's
|
|
@@ -190,4 +209,58 @@ interface NodeResponseLike {
|
|
|
190
209
|
*/
|
|
191
210
|
declare function toNodeListener(server: InvoGameServer, fallback?: (req: NodeRequestLike, res: NodeResponseLike) => unknown): (req: NodeRequestLike, res: NodeResponseLike) => Promise<void>;
|
|
192
211
|
|
|
193
|
-
|
|
212
|
+
declare const DEMO_EMAIL_DOMAIN = "demo.invo.network";
|
|
213
|
+
declare const DEFAULT_PROJECT_FILE = ".invo/project.json";
|
|
214
|
+
/** What the project file holds. Secrets: keep the file out of version control. */
|
|
215
|
+
interface DemoProjectFile {
|
|
216
|
+
projectId: string;
|
|
217
|
+
/** The public host the project was registered from (remix detection). */
|
|
218
|
+
host?: string;
|
|
219
|
+
webhookUrl?: string;
|
|
220
|
+
webhookSecret?: string;
|
|
221
|
+
registrationToken?: string;
|
|
222
|
+
}
|
|
223
|
+
declare function isValidProjectId(value: unknown): value is string;
|
|
224
|
+
/**
|
|
225
|
+
* The demo-sandbox email for a player, deterministic per (email, project):
|
|
226
|
+
* `<local part, cleaned>-<8 hex of sha256(email)>+<project ulid lowercase>@demo.invo.network`.
|
|
227
|
+
*/
|
|
228
|
+
declare function toDemoEmail(email: string, projectId: string): string;
|
|
229
|
+
/** The fictional phone INVO's demo sandbox accepts for a player: `+1202555 01XX`. */
|
|
230
|
+
declare function demoPhoneFor(email: string): string;
|
|
231
|
+
/**
|
|
232
|
+
* This fork's project, from `INVO_PROJECT_ID`, else the project file, else a new id written to
|
|
233
|
+
* the file. When `publicUrl`'s host differs from the host the file was registered from, the file
|
|
234
|
+
* was copied by a remix: a fresh project id replaces it.
|
|
235
|
+
*/
|
|
236
|
+
declare function loadProject(opts?: {
|
|
237
|
+
file?: string;
|
|
238
|
+
publicUrl?: string;
|
|
239
|
+
projectId?: string;
|
|
240
|
+
}): DemoProjectFile;
|
|
241
|
+
interface RegisterProjectOptions {
|
|
242
|
+
/** The public demo key (`ivsdk_demo_...`). */
|
|
243
|
+
gameSecret: string;
|
|
244
|
+
/** This fork's public webhook URL, e.g. `https://my-game.replit.app/api/invo/webhook`. */
|
|
245
|
+
webhookUrl: string;
|
|
246
|
+
file?: string;
|
|
247
|
+
projectId?: string;
|
|
248
|
+
baseUrl?: string;
|
|
249
|
+
fetch?: typeof fetch;
|
|
250
|
+
}
|
|
251
|
+
interface RegisteredProject {
|
|
252
|
+
projectId: string;
|
|
253
|
+
/** The signing secret to verify INVO webhooks with, or null if INVO never returned one. */
|
|
254
|
+
webhookSecret: string | null;
|
|
255
|
+
/** True when this call created the registration (a new fork). */
|
|
256
|
+
created: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Register this fork with the demo sandbox (call on every server start). The first call
|
|
260
|
+
* stores the webhook signing secret and the registration token in the project file; later
|
|
261
|
+
* calls change nothing unless the webhook URL moved. A `409 PROJECT_REGISTERED` (a remix that
|
|
262
|
+
* copied another fork's project id) gets a fresh project id, once.
|
|
263
|
+
*/
|
|
264
|
+
declare function registerProject(opts: RegisterProjectOptions): Promise<RegisteredProject>;
|
|
265
|
+
|
|
266
|
+
export { DEFAULT_PROJECT_FILE, DEMO_EMAIL_DOMAIN, type DemoProjectFile, type FileGameStoreOptions, GameCurrencyKind, GameEconomyConfig, GamePurchaseStatus, GameServerError, type GameServerLogLevel, type GameStore, type GameStoreState, InvoEnvironment, type InvoGameServer, type InvoGameServerFromEnvOptions, type InvoGameServerOptions, type InvoGameServerSetup, InvoServer, type LedgerEntry, type NodeRequestLike, type NodeResponseLike, type RegisterProjectOptions, type RegisteredProject, type StoredIdempotentResult, type StoredPlayer, type StoredPurchase, type StoredSession, createFileGameStore, createInvoGameServer, createMemoryGameStore, demoPhoneFor, emptyGameState, invoGameServerFromEnv, isValidProjectId, loadProject, newProjectId, playerIdFor, registerProject, toDemoEmail, toNodeListener, validateEconomy };
|