@invonetwork/web-sdk 3.28.0 → 3.29.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 +19 -0
- package/README.md +24 -1
- package/dist/chunk-VOGZZ6QS.js +6 -0
- package/dist/{chunk-4YKTKXC5.js → chunk-YONO4JE5.js} +22 -5
- package/dist/game-server.cjs +184 -19
- package/dist/game-server.d.cts +85 -6
- package/dist/game-server.d.ts +85 -6
- package/dist/game-server.js +165 -22
- package/dist/game.cjs +4 -1
- package/dist/game.d.cts +3 -3
- package/dist/game.d.ts +3 -3
- package/dist/game.js +4 -1
- package/dist/server-BYY6tM6X.d.ts +2165 -0
- package/dist/server-Bxo_wgHx.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/{types-CoW9LopI.d.cts → types-CLyJDuXd.d.cts} +12 -0
- package/dist/{types-CoW9LopI.d.ts → types-CLyJDuXd.d.ts} +12 -0
- package/dist/{version-iWmcxjYu.d.cts → version-DOaYbHu7.d.cts} +1 -1
- package/dist/{version-iWmcxjYu.d.ts → version-DOaYbHu7.d.ts} +1 -1
- package/package.json +91 -91
- package/dist/chunk-3DRWLDDF.js +0 -6
package/dist/game-server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { InvoServer } from './server.js';
|
|
2
|
-
export { DEMO_KEY_PREFIX, EnvironmentUnknownError,
|
|
3
|
-
import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-
|
|
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-
|
|
1
|
+
import { I as InvoServer, a as InvoEnvironment } from './server-BYY6tM6X.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-BYY6tM6X.js';
|
|
3
|
+
import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-CLyJDuXd.js';
|
|
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-CLyJDuXd.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-DOaYbHu7.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,12 @@ 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";
|
|
174
|
+
/** True when the key is INVO's public demo key (3.29.1). */
|
|
175
|
+
demo: boolean;
|
|
155
176
|
}
|
|
156
177
|
/**
|
|
157
178
|
* Build the game server from environment variables (Replit Secrets, `.env`, your host's
|
|
@@ -190,4 +211,62 @@ interface NodeResponseLike {
|
|
|
190
211
|
*/
|
|
191
212
|
declare function toNodeListener(server: InvoGameServer, fallback?: (req: NodeRequestLike, res: NodeResponseLike) => unknown): (req: NodeRequestLike, res: NodeResponseLike) => Promise<void>;
|
|
192
213
|
|
|
193
|
-
|
|
214
|
+
declare const DEMO_EMAIL_DOMAIN = "demo.invo.network";
|
|
215
|
+
declare const DEFAULT_PROJECT_FILE = ".invo/project.json";
|
|
216
|
+
/** What the project file holds. Secrets: keep the file out of version control. */
|
|
217
|
+
interface DemoProjectFile {
|
|
218
|
+
projectId: string;
|
|
219
|
+
/** The public host the project was registered from (remix detection outside Replit). */
|
|
220
|
+
host?: string;
|
|
221
|
+
/** Replit's REPL_ID when the file was written. A different REPL_ID means a remix. */
|
|
222
|
+
replId?: string;
|
|
223
|
+
webhookUrl?: string;
|
|
224
|
+
webhookSecret?: string;
|
|
225
|
+
registrationToken?: string;
|
|
226
|
+
}
|
|
227
|
+
declare function isValidProjectId(value: unknown): value is string;
|
|
228
|
+
/**
|
|
229
|
+
* The demo-sandbox email for a player, deterministic per (email, project):
|
|
230
|
+
* `<local part, cleaned>-<8 hex of sha256(email)>+<project ulid lowercase>@demo.invo.network`.
|
|
231
|
+
*/
|
|
232
|
+
declare function toDemoEmail(email: string, projectId: string): string;
|
|
233
|
+
/** The fictional phone INVO's demo sandbox accepts for a player: `+1202555 01XX`. */
|
|
234
|
+
declare function demoPhoneFor(email: string): string;
|
|
235
|
+
/**
|
|
236
|
+
* This fork's project, from `INVO_PROJECT_ID`, else the project file, else a new id written to
|
|
237
|
+
* the file. A project file copied by a remix (see `sameFork`) is replaced by a fresh project id.
|
|
238
|
+
*/
|
|
239
|
+
declare function loadProject(opts?: {
|
|
240
|
+
file?: string;
|
|
241
|
+
publicUrl?: string;
|
|
242
|
+
projectId?: string;
|
|
243
|
+
replId?: string;
|
|
244
|
+
}): DemoProjectFile;
|
|
245
|
+
interface RegisterProjectOptions {
|
|
246
|
+
/** The public demo key (`ivsdk_demo_...`). */
|
|
247
|
+
gameSecret: string;
|
|
248
|
+
/** This fork's public webhook URL, e.g. `https://my-game.replit.app/api/invo/webhook`. */
|
|
249
|
+
webhookUrl: string;
|
|
250
|
+
file?: string;
|
|
251
|
+
projectId?: string;
|
|
252
|
+
baseUrl?: string;
|
|
253
|
+
fetch?: typeof fetch;
|
|
254
|
+
/** Overrides Replit's REPL_ID (tests). */
|
|
255
|
+
replId?: string;
|
|
256
|
+
}
|
|
257
|
+
interface RegisteredProject {
|
|
258
|
+
projectId: string;
|
|
259
|
+
/** The signing secret to verify INVO webhooks with, or null if INVO never returned one. */
|
|
260
|
+
webhookSecret: string | null;
|
|
261
|
+
/** True when this call created the registration (a new fork). */
|
|
262
|
+
created: boolean;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Register this fork with the demo sandbox (call on every server start). The first call
|
|
266
|
+
* stores the webhook signing secret and the registration token in the project file; later
|
|
267
|
+
* calls change nothing unless the webhook URL moved. A `409 PROJECT_REGISTERED` (a remix that
|
|
268
|
+
* copied another fork's project id) gets a fresh project id, once.
|
|
269
|
+
*/
|
|
270
|
+
declare function registerProject(opts: RegisterProjectOptions): Promise<RegisteredProject>;
|
|
271
|
+
|
|
272
|
+
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.js
CHANGED
|
@@ -1,13 +1,140 @@
|
|
|
1
|
-
import { isDemoKey, PRODUCTION_BASE_URL,
|
|
2
|
-
export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment } from './chunk-
|
|
1
|
+
import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-YONO4JE5.js';
|
|
2
|
+
export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-YONO4JE5.js';
|
|
3
3
|
import './chunk-6CN236QH.js';
|
|
4
|
-
export { SDK_VERSION } from './chunk-
|
|
4
|
+
export { SDK_VERSION } from './chunk-VOGZZ6QS.js';
|
|
5
5
|
import { InvoError } from './chunk-VP3OK4J4.js';
|
|
6
6
|
export { InvoError } from './chunk-VP3OK4J4.js';
|
|
7
7
|
import { createHash, randomBytes } from 'crypto';
|
|
8
|
-
import { promises } from 'fs';
|
|
8
|
+
import { promises, readFileSync, mkdirSync, writeFileSync } from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
|
+
import { dirname } from 'path';
|
|
10
11
|
|
|
12
|
+
var DEMO_EMAIL_DOMAIN = "demo.invo.network";
|
|
13
|
+
var DEFAULT_PROJECT_FILE = ".invo/project.json";
|
|
14
|
+
var PROJECT_ID = /^proj_[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
15
|
+
function newDemoProjectId(now = Date.now()) {
|
|
16
|
+
const A = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
17
|
+
let t = now;
|
|
18
|
+
let time = "";
|
|
19
|
+
for (let i = 0; i < 10; i++) {
|
|
20
|
+
time = A[t % 32] + time;
|
|
21
|
+
t = Math.floor(t / 32);
|
|
22
|
+
}
|
|
23
|
+
const bytes = randomBytes(16);
|
|
24
|
+
let rand = "";
|
|
25
|
+
for (let i = 0; i < 16; i++) rand += A[bytes[i] % 32];
|
|
26
|
+
return "proj_" + time + rand;
|
|
27
|
+
}
|
|
28
|
+
function isValidProjectId(value) {
|
|
29
|
+
return typeof value === "string" && PROJECT_ID.test(value);
|
|
30
|
+
}
|
|
31
|
+
function toDemoEmail(email, projectId) {
|
|
32
|
+
if (!isValidProjectId(projectId)) throw new Error("A valid template project id is required.");
|
|
33
|
+
const lower = email.trim().toLowerCase();
|
|
34
|
+
if (lower.endsWith("@" + DEMO_EMAIL_DOMAIN)) return lower;
|
|
35
|
+
const local = (lower.split("@")[0] ?? "player").replace(/[^a-z0-9._-]/g, "").slice(0, 24) || "player";
|
|
36
|
+
const tag = createHash("sha256").update(lower).digest("hex").slice(0, 8);
|
|
37
|
+
return `${local}-${tag}+${projectId.slice(5).toLowerCase()}@${DEMO_EMAIL_DOMAIN}`;
|
|
38
|
+
}
|
|
39
|
+
function demoPhoneFor(email) {
|
|
40
|
+
const n = BigInt("0x" + createHash("sha256").update(email.trim().toLowerCase()).digest("hex")) % BigInt(100);
|
|
41
|
+
return "+120255501" + n.toString().padStart(2, "0");
|
|
42
|
+
}
|
|
43
|
+
function hostOf(url) {
|
|
44
|
+
if (!url) return void 0;
|
|
45
|
+
try {
|
|
46
|
+
return new URL(url).host.toLowerCase();
|
|
47
|
+
} catch {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function readFile(file) {
|
|
52
|
+
try {
|
|
53
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
54
|
+
return isValidProjectId(data.projectId) ? data : null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function writeFile(file, data) {
|
|
60
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
61
|
+
writeFileSync(file, JSON.stringify(data, null, 2) + "\n", { encoding: "utf8", mode: 384 });
|
|
62
|
+
}
|
|
63
|
+
function currentReplId(override) {
|
|
64
|
+
const v = override ?? (typeof process !== "undefined" ? process.env.REPL_ID : void 0);
|
|
65
|
+
return v && v.trim() ? v.trim() : void 0;
|
|
66
|
+
}
|
|
67
|
+
function sameFork(saved, host, replId) {
|
|
68
|
+
if (replId && saved.replId) return saved.replId === replId;
|
|
69
|
+
return !host || !saved.host || saved.host === host;
|
|
70
|
+
}
|
|
71
|
+
function loadProject(opts = {}) {
|
|
72
|
+
const file = opts.file ?? DEFAULT_PROJECT_FILE;
|
|
73
|
+
const replId = currentReplId(opts.replId);
|
|
74
|
+
if (opts.projectId) {
|
|
75
|
+
if (!isValidProjectId(opts.projectId)) throw new Error('INVO_PROJECT_ID must be "proj_" + a 26-character ULID.');
|
|
76
|
+
const saved2 = readFile(file);
|
|
77
|
+
return saved2 && saved2.projectId === opts.projectId ? saved2 : { projectId: opts.projectId, replId };
|
|
78
|
+
}
|
|
79
|
+
const host = hostOf(opts.publicUrl);
|
|
80
|
+
const saved = readFile(file);
|
|
81
|
+
if (saved && sameFork(saved, host, replId)) return replId && !saved.replId ? { ...saved, replId } : saved;
|
|
82
|
+
const fresh = { projectId: newDemoProjectId(), host, replId };
|
|
83
|
+
try {
|
|
84
|
+
writeFile(file, fresh);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
return fresh;
|
|
88
|
+
}
|
|
89
|
+
async function registerProject(opts) {
|
|
90
|
+
if (!isDemoKey(opts.gameSecret)) throw new Error("registerProject is for the public demo key only.");
|
|
91
|
+
const file = opts.file ?? DEFAULT_PROJECT_FILE;
|
|
92
|
+
const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
93
|
+
const base = (opts.baseUrl ?? SANDBOX_BASE_URL).replace(/\/+$/, "");
|
|
94
|
+
const replId = currentReplId(opts.replId);
|
|
95
|
+
let project = loadProject({ file, publicUrl: opts.webhookUrl, projectId: opts.projectId, replId });
|
|
96
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
97
|
+
const res = await fetchImpl(base + "/api/demo/projects/register", {
|
|
98
|
+
method: "POST",
|
|
99
|
+
redirect: "error",
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
Accept: "application/json",
|
|
103
|
+
"X-Game-Secret-Key": opts.gameSecret,
|
|
104
|
+
"X-Invo-Project-Id": project.projectId,
|
|
105
|
+
"X-Invo-Project-Host": hostOf(opts.webhookUrl) ?? ""
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({ webhook_url: opts.webhookUrl, registration_token: project.registrationToken })
|
|
108
|
+
});
|
|
109
|
+
const body = await res.json().catch(() => ({}));
|
|
110
|
+
if (res.status === 409 && body.error_code === "PROJECT_REGISTERED" && attempt === 0 && !opts.projectId) {
|
|
111
|
+
project = { projectId: newDemoProjectId(), host: hostOf(opts.webhookUrl), replId };
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!res.ok) throw new Error(`INVO demo registration failed (${res.status} ${body.error_code ?? ""}): ${body.error ?? ""}`.trim());
|
|
115
|
+
const created = res.status === 201;
|
|
116
|
+
if (created) {
|
|
117
|
+
project = {
|
|
118
|
+
projectId: project.projectId,
|
|
119
|
+
host: hostOf(opts.webhookUrl),
|
|
120
|
+
replId,
|
|
121
|
+
webhookUrl: opts.webhookUrl,
|
|
122
|
+
webhookSecret: body.webhook?.signing_secret ?? project.webhookSecret,
|
|
123
|
+
registrationToken: body.registration_token ?? project.registrationToken
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
project = { ...project, host: hostOf(opts.webhookUrl) ?? project.host, replId: replId ?? project.replId, webhookUrl: opts.webhookUrl };
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
writeFile(file, project);
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
return { projectId: project.projectId, webhookSecret: project.webhookSecret ?? null, created };
|
|
133
|
+
}
|
|
134
|
+
throw new Error("INVO demo registration failed.");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/game/server.ts
|
|
11
138
|
var MAX_BODY_BYTES = 1e6;
|
|
12
139
|
var EMAIL = /^[^\s@]{1,64}@[^\s@]{1,255}\.[^\s@]{2,63}$/;
|
|
13
140
|
var E164 = /^\+[1-9]\d{6,14}$/;
|
|
@@ -183,7 +310,9 @@ function createInvoGameServer(options) {
|
|
|
183
310
|
premium: { name: economy.premium.name, packs: economy.premium.packs },
|
|
184
311
|
soft: { name: economy.soft.name },
|
|
185
312
|
items: economy.items,
|
|
186
|
-
sandbox: options.sandbox
|
|
313
|
+
sandbox: options.sandbox,
|
|
314
|
+
demo: !!options.demoProjectId,
|
|
315
|
+
playerFields: { phone: options.demoProjectId ? "hidden" : "first_sign_in" }
|
|
187
316
|
};
|
|
188
317
|
return json(200, body);
|
|
189
318
|
}
|
|
@@ -199,9 +328,12 @@ function createInvoGameServer(options) {
|
|
|
199
328
|
const name = (rawName || email.split("@")[0] || "Player").slice(0, 64);
|
|
200
329
|
const id = playerIdFor(email);
|
|
201
330
|
const known = await store.read((s) => s.players[id] ?? null);
|
|
202
|
-
const
|
|
331
|
+
const demoPid = options.demoProjectId;
|
|
332
|
+
const invoEmail = demoPid ? toDemoEmail(email, demoPid) : email;
|
|
333
|
+
const phoneForInvo = demoPid ? demoPhoneFor(invoEmail) : phone ?? known?.phone ?? void 0;
|
|
334
|
+
const storedPhone = demoPid ? null : phone;
|
|
203
335
|
try {
|
|
204
|
-
await invo.mintPlayerToken({ playerEmail:
|
|
336
|
+
await invo.mintPlayerToken({ playerEmail: invoEmail, playerPhone: phoneForInvo, playerName: name });
|
|
205
337
|
} catch (err) {
|
|
206
338
|
if (err instanceof InvoError && err.status === 404) {
|
|
207
339
|
throw new GameServerError(400, "PHONE_REQUIRED", "First sign-in needs a phone number so INVO can create your account.");
|
|
@@ -213,7 +345,7 @@ function createInvoGameServer(options) {
|
|
|
213
345
|
const expiresAt = new Date(now().getTime() + sessionTtlMs).toISOString();
|
|
214
346
|
const player = await store.transact((s) => {
|
|
215
347
|
const existing = s.players[id];
|
|
216
|
-
const record = existing ? { ...existing, name, phone:
|
|
348
|
+
const record = existing ? { ...existing, email: invoEmail, name, phone: storedPhone ?? existing.phone } : { id, email: invoEmail, phone: storedPhone, name, createdAt: iso() };
|
|
217
349
|
s.players[id] = record;
|
|
218
350
|
if (soft.starting > 0) {
|
|
219
351
|
addLedger(s, { playerId: id, currency: "soft", amount: soft.starting, reason: "starting balance", ref: `start:${id}`, at: iso() });
|
|
@@ -511,7 +643,7 @@ function createInvoGameServer(options) {
|
|
|
511
643
|
}
|
|
512
644
|
}
|
|
513
645
|
async function route(request, sub, method) {
|
|
514
|
-
if (method === "GET" && sub === "/health") return json(200, { ok: true, setupRequired: false, sandbox: options.sandbox });
|
|
646
|
+
if (method === "GET" && sub === "/health") return json(200, { ok: true, setupRequired: false, sandbox: options.sandbox, demo: !!options.demoProjectId });
|
|
515
647
|
if (method === "GET" && sub === "/catalog") return catalog();
|
|
516
648
|
if (method === "POST" && sub === "/session") return signIn(request);
|
|
517
649
|
if (method === "POST" && sub === "/session/end") return signOut(request);
|
|
@@ -552,23 +684,33 @@ function invoGameServerFromEnv(options) {
|
|
|
552
684
|
const forced = env["INVO_ENV"]?.trim().toLowerCase();
|
|
553
685
|
const known = forced ? forced === "production" ? "production" : "sandbox" : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
|
|
554
686
|
const state = { environment: known };
|
|
555
|
-
const sandboxNow = () => state.environment
|
|
556
|
-
const
|
|
687
|
+
const sandboxNow = () => state.environment === "sandbox";
|
|
688
|
+
const envNow = () => state.environment ?? "resolving";
|
|
689
|
+
const demo = isDemoKey(secret);
|
|
690
|
+
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;
|
|
691
|
+
const webhookSecrets = (() => {
|
|
692
|
+
const raw = options.webhookSecret ?? env["INVO_WEBHOOK_SECRET"] ?? demoProject?.webhookSecret ?? "";
|
|
693
|
+
return (Array.isArray(raw) ? raw : raw.split(",")).map((s) => s.trim()).filter(Boolean);
|
|
694
|
+
})();
|
|
695
|
+
const missing = [
|
|
696
|
+
...secret ? [] : ["INVO_GAME_SECRET"],
|
|
697
|
+
...webhookSecrets.length ? [] : ["INVO_WEBHOOK_SECRET"]
|
|
698
|
+
];
|
|
557
699
|
if (missing.length) {
|
|
558
|
-
return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath), missing, sandbox: sandboxNow() };
|
|
700
|
+
return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath, demo), missing, sandbox: sandboxNow(), environment: envNow(), demo };
|
|
559
701
|
}
|
|
560
702
|
const baseFetch = options.fetch ?? ((input, init) => fetch(input, init));
|
|
561
|
-
const projectId = (options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0;
|
|
703
|
+
const projectId = demoProject?.projectId ?? ((options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0);
|
|
562
704
|
const explicitBase = env["INVO_BASE_URL"] || (forced ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
|
|
563
|
-
const
|
|
705
|
+
const resolveNow = () => resolveEnvironment(secret, { fetch: baseFetch }).then((e) => {
|
|
564
706
|
state.environment = e;
|
|
565
707
|
return e;
|
|
566
708
|
});
|
|
567
|
-
|
|
709
|
+
if (!explicitBase && !known) resolveNow().catch(() => void 0);
|
|
568
710
|
const invoFetch = async (input, init) => {
|
|
569
711
|
let url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
570
712
|
if (!explicitBase) {
|
|
571
|
-
const e = known ?? await
|
|
713
|
+
const e = known ?? state.environment ?? await resolveNow();
|
|
572
714
|
if (e === "sandbox" && url.startsWith(PRODUCTION_BASE_URL + "/")) url = SANDBOX_BASE_URL + url.slice(PRODUCTION_BASE_URL.length);
|
|
573
715
|
}
|
|
574
716
|
const headers = new Headers(init?.headers);
|
|
@@ -578,7 +720,8 @@ function invoGameServerFromEnv(options) {
|
|
|
578
720
|
const invo = new InvoServer({ gameSecret: secret, baseUrl: explicitBase || PRODUCTION_BASE_URL, fetch: invoFetch });
|
|
579
721
|
const serverOptions = {
|
|
580
722
|
invo,
|
|
581
|
-
webhookSecret:
|
|
723
|
+
webhookSecret: webhookSecrets,
|
|
724
|
+
demoProjectId: demo ? projectId : void 0,
|
|
582
725
|
economy: options.economy,
|
|
583
726
|
store: options.store,
|
|
584
727
|
get sandbox() {
|
|
@@ -589,7 +732,7 @@ function invoGameServerFromEnv(options) {
|
|
|
589
732
|
log: options.log
|
|
590
733
|
};
|
|
591
734
|
const server = createInvoGameServer(serverOptions);
|
|
592
|
-
return { server, missing, sandbox: sandboxNow() };
|
|
735
|
+
return { server, missing, sandbox: sandboxNow(), environment: envNow(), demo };
|
|
593
736
|
}
|
|
594
737
|
function newProjectId(now = Date.now()) {
|
|
595
738
|
const A = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
@@ -604,7 +747,7 @@ function newProjectId(now = Date.now()) {
|
|
|
604
747
|
for (let i = 0; i < 16; i++) rand += A[bytes[i] % 32];
|
|
605
748
|
return "proj_" + time + rand;
|
|
606
749
|
}
|
|
607
|
-
function setupRequiredServer(economy, missing, sandbox, basePathOpt) {
|
|
750
|
+
function setupRequiredServer(economy, missing, sandbox, basePathOpt, demo = false) {
|
|
608
751
|
const basePath = (basePathOpt ?? "/api/invo").replace(/\/+$/, "");
|
|
609
752
|
const message = `Add ${missing.join(" and ")} to your environment (on Replit: Tools \u2192 Secrets), then restart.`;
|
|
610
753
|
return {
|
|
@@ -613,9 +756,9 @@ function setupRequiredServer(economy, missing, sandbox, basePathOpt) {
|
|
|
613
756
|
const url = new URL(request.url);
|
|
614
757
|
if (url.pathname !== basePath && !url.pathname.startsWith(basePath + "/")) return null;
|
|
615
758
|
const sub = url.pathname.slice(basePath.length) || "/";
|
|
616
|
-
if (request.method === "GET" && sub === "/health") return json(200, { ok: true, setupRequired: true, missing, sandbox });
|
|
759
|
+
if (request.method === "GET" && sub === "/health") return json(200, { ok: true, setupRequired: true, missing, sandbox, demo });
|
|
617
760
|
if (request.method === "GET" && sub === "/catalog") {
|
|
618
|
-
const body = { premium: { name: economy.premium.name, packs: economy.premium.packs }, soft: { name: economy.soft.name }, items: economy.items, sandbox };
|
|
761
|
+
const body = { premium: { name: economy.premium.name, packs: economy.premium.packs }, soft: { name: economy.soft.name }, items: economy.items, sandbox, demo, playerFields: { phone: demo ? "hidden" : "first_sign_in" } };
|
|
619
762
|
return json(200, body);
|
|
620
763
|
}
|
|
621
764
|
return json(503, { error: { code: "INVO_SETUP_REQUIRED", message } });
|
|
@@ -741,6 +884,6 @@ function createFileGameStore(options) {
|
|
|
741
884
|
};
|
|
742
885
|
}
|
|
743
886
|
|
|
744
|
-
export { GameServerError, createFileGameStore, createInvoGameServer, createMemoryGameStore, emptyGameState, invoGameServerFromEnv, newProjectId, playerIdFor, toNodeListener, validateEconomy };
|
|
887
|
+
export { DEFAULT_PROJECT_FILE, DEMO_EMAIL_DOMAIN, GameServerError, createFileGameStore, createInvoGameServer, createMemoryGameStore, demoPhoneFor, emptyGameState, invoGameServerFromEnv, isValidProjectId, loadProject, newProjectId, playerIdFor, registerProject, toDemoEmail, toNodeListener, validateEconomy };
|
|
745
888
|
//# sourceMappingURL=game-server.js.map
|
|
746
889
|
//# sourceMappingURL=game-server.js.map
|
package/dist/game.cjs
CHANGED
|
@@ -1926,6 +1926,9 @@ function mountInvoUI(container, economy, options = {}) {
|
|
|
1926
1926
|
};
|
|
1927
1927
|
const email = field("Email", "", "email", "email", "you@example.com", "email", ICONS.mail);
|
|
1928
1928
|
const phone = field("Phone", "first sign-in only", "tel", "phone", "+1 555 555 0111", "tel", ICONS.phone);
|
|
1929
|
+
if (economy.catalog?.playerFields?.phone === "hidden" || economy.catalog?.demo) {
|
|
1930
|
+
phone.closest(".invo-field")?.setAttribute("hidden", "");
|
|
1931
|
+
}
|
|
1929
1932
|
const name = field("Player name", "optional", "text", "name", "What should we call you?", "nickname", ICONS.user);
|
|
1930
1933
|
email.required = true;
|
|
1931
1934
|
const error = el("div", "invo-error");
|
|
@@ -2162,7 +2165,7 @@ function mountInvoUI(container, economy, options = {}) {
|
|
|
2162
2165
|
}
|
|
2163
2166
|
|
|
2164
2167
|
// src/version.ts
|
|
2165
|
-
var SDK_VERSION = "3.
|
|
2168
|
+
var SDK_VERSION = "3.29.1";
|
|
2166
2169
|
|
|
2167
2170
|
exports.InvoGameEconomy = InvoGameEconomy;
|
|
2168
2171
|
exports.InvoGameError = InvoGameError;
|
package/dist/game.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as GamePlayer, m as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, d as GameCatalogItem, f as GameCurrencyBalance } from './types-
|
|
2
|
-
export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-
|
|
3
|
-
export { S as SDK_VERSION } from './version-
|
|
1
|
+
import { i as GamePlayer, m as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, d as GameCatalogItem, f as GameCurrencyBalance } from './types-CLyJDuXd.cjs';
|
|
2
|
+
export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-CLyJDuXd.cjs';
|
|
3
|
+
export { S as SDK_VERSION } from './version-DOaYbHu7.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* INVO game economy client (3.27.0), the browser half. It talks ONLY to your game server
|
package/dist/game.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as GamePlayer, m as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, d as GameCatalogItem, f as GameCurrencyBalance } from './types-
|
|
2
|
-
export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-
|
|
3
|
-
export { S as SDK_VERSION } from './version-
|
|
1
|
+
import { i as GamePlayer, m as GameWallet, c as GameCatalog, k as GamePurchase, h as GameItemPurchase, d as GameCatalogItem, f as GameCurrencyBalance } from './types-CLyJDuXd.js';
|
|
2
|
+
export { e as GameCheckout, G as GameCurrencyKind, b as GameEconomyConfig, g as GameErrorBody, j as GamePremiumPack, a as GamePurchaseStatus, l as GameSession } from './types-CLyJDuXd.js';
|
|
3
|
+
export { S as SDK_VERSION } from './version-DOaYbHu7.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* INVO game economy client (3.27.0), the browser half. It talks ONLY to your game server
|
package/dist/game.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SDK_VERSION } from './chunk-
|
|
1
|
+
export { SDK_VERSION } from './chunk-VOGZZ6QS.js';
|
|
2
2
|
import { newEventId } from './chunk-VP3OK4J4.js';
|
|
3
3
|
|
|
4
4
|
// src/game/client.ts
|
|
@@ -794,6 +794,9 @@ function mountInvoUI(container, economy, options = {}) {
|
|
|
794
794
|
};
|
|
795
795
|
const email = field("Email", "", "email", "email", "you@example.com", "email", ICONS.mail);
|
|
796
796
|
const phone = field("Phone", "first sign-in only", "tel", "phone", "+1 555 555 0111", "tel", ICONS.phone);
|
|
797
|
+
if (economy.catalog?.playerFields?.phone === "hidden" || economy.catalog?.demo) {
|
|
798
|
+
phone.closest(".invo-field")?.setAttribute("hidden", "");
|
|
799
|
+
}
|
|
797
800
|
const name = field("Player name", "optional", "text", "name", "What should we call you?", "nickname", ICONS.user);
|
|
798
801
|
email.required = true;
|
|
799
802
|
const error = el("div", "invo-error");
|