@invonetwork/web-sdk 3.33.0 → 3.34.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.
@@ -345,6 +345,17 @@ var InvoError = class _InvoError extends Error {
345
345
  get isPaymentsPaused() {
346
346
  return this.code === "PAYMENTS_PAUSED";
347
347
  }
348
+ /** The key belongs to the other INVO environment (`KEY_FOR_OTHER_ENVIRONMENT`, 401;
349
+ * additive, 3.34.0): a test key (`ivsdk_test_`) sent to production, or a live key
350
+ * (`ivsdk_live_`) sent to the sandbox. Never retried. Use the key for the environment
351
+ * you are calling, or point the SDK at the environment the key is for. The code is
352
+ * matched on any code field (`code`, `rawCode`, `publicCode`, or the body's
353
+ * `error_code` / `code`), since the 401 may carry a different `code`. */
354
+ get isKeyForOtherEnvironment() {
355
+ const C = "KEY_FOR_OTHER_ENVIRONMENT";
356
+ const b = this.bodyObject();
357
+ return this.code === C || this.rawCode === C || this.publicCode === C || b["error_code"] === C || b["code"] === C;
358
+ }
348
359
  /** A buyer-approved balance purchase cannot start (`BALANCE_UNAVAILABLE`, 400; 3.33.0):
349
360
  * the buyer is unknown here or their balance is short. One answer on purpose; the
350
361
  * balance is never disclosed. Offer another way to pay. */
@@ -830,7 +841,7 @@ var InvoError = class _InvoError extends Error {
830
841
  /**
831
842
  * True when a sandbox clock call was refused for a missing, wrong or never-issued
832
843
  * `X-Sandbox-Clock-Key` (`SANDBOX_CLOCK_UNAUTHORIZED`, 401). Reveal or rotate the key on
833
- * the game's Game Settings page in the sandbox console.
844
+ * the game's Game Settings page in the INVO console in test mode (console.invo.network/test).
834
845
  */
835
846
  get isSandboxClockUnauthorized() {
836
847
  return this.code === "SANDBOX_CLOCK_UNAUTHORIZED";
@@ -1763,5 +1774,5 @@ function toApprovePhoneChangeResult(raw, changeRequestId) {
1763
1774
  }
1764
1775
 
1765
1776
  export { Http, InvoError, assertSecureBaseUrl, buildGameEventBody, creditFields, isPurchaseCredited, isPurchaseExpired, isPurchaseRefunded, isPurchaseRefused, newEventId, nothingWasCharged, phoneChangeSignalMessage, receiptFields, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toPhoneChangeApprovalsResult, toPhoneChangeRequest, toPurchaseStatusResult, toRedeemRewardResult, toReportGameEventResult, toRequestPhoneChangeResult, toRewardsPageLink };
1766
- //# sourceMappingURL=chunk-HQLPT2DY.js.map
1767
- //# sourceMappingURL=chunk-HQLPT2DY.js.map
1777
+ //# sourceMappingURL=chunk-3BR7URPM.js.map
1778
+ //# sourceMappingURL=chunk-3BR7URPM.js.map
@@ -0,0 +1,6 @@
1
+ // src/version.ts
2
+ var SDK_VERSION = "3.34.1";
3
+
4
+ export { SDK_VERSION };
5
+ //# sourceMappingURL=chunk-6763YM7P.js.map
6
+ //# sourceMappingURL=chunk-6763YM7P.js.map
@@ -1,5 +1,5 @@
1
- import { SDK_VERSION } from './chunk-VWUFSA6U.js';
2
- import { InvoError, assertSecureBaseUrl, Http, toRequestPhoneChangeResult, toPhoneChangeRequest, toPurchaseStatusResult, receiptFields, creditFields, toLoyaltyCardsResult, buildGameEventBody, toReportGameEventResult, toDestinationsResult } from './chunk-HQLPT2DY.js';
1
+ import { SDK_VERSION } from './chunk-6763YM7P.js';
2
+ import { InvoError, assertSecureBaseUrl, Http, toRequestPhoneChangeResult, toPhoneChangeRequest, toPurchaseStatusResult, receiptFields, creditFields, toLoyaltyCardsResult, buildGameEventBody, toReportGameEventResult, toDestinationsResult } from './chunk-3BR7URPM.js';
3
3
  import { createHmac, timingSafeEqual } from 'crypto';
4
4
 
5
5
  // src/payouts.ts
@@ -194,6 +194,152 @@ var PayoutsServer = class {
194
194
  }
195
195
  };
196
196
 
197
+ // src/environment.ts
198
+ var PRODUCTION_BASE_URL = "https://invo.network";
199
+ var SANDBOX_BASE_URL = "https://sandbox.invo.network/sandbox";
200
+ var DEMO_KEY_PREFIX = "ivsdk_demo_";
201
+ var TEST_KEY_PREFIX = "ivsdk_test_";
202
+ var LIVE_KEY_PREFIX = "ivsdk_live_";
203
+ var KEY_ENVIRONMENT_PATH = "/api/sdk/key-environment";
204
+ function environmentFromKeyPrefix(gameSecret) {
205
+ if (typeof gameSecret !== "string") return null;
206
+ if (gameSecret.startsWith(LIVE_KEY_PREFIX)) return "production";
207
+ if (gameSecret.startsWith(TEST_KEY_PREFIX) || gameSecret.startsWith(DEMO_KEY_PREFIX)) return "sandbox";
208
+ return null;
209
+ }
210
+ function environmentForBaseUrl(baseUrl) {
211
+ if (typeof baseUrl !== "string" || !baseUrl.trim()) return null;
212
+ let url;
213
+ try {
214
+ url = new URL(baseUrl.trim());
215
+ } catch {
216
+ return null;
217
+ }
218
+ const host = url.hostname.toLowerCase().replace(/\.$/, "");
219
+ if (host === "sandbox.invo.network") return "sandbox";
220
+ if (host === "invo.network" || host === "www.invo.network") {
221
+ const first = url.pathname.split("/").filter(Boolean)[0]?.toLowerCase();
222
+ return first === "sandbox" ? "sandbox" : "production";
223
+ }
224
+ return null;
225
+ }
226
+ var KeyEnvironmentMismatchError = class extends Error {
227
+ constructor(message, keyEnvironment, configuredEnvironment) {
228
+ super(message);
229
+ this.name = "KeyEnvironmentMismatchError";
230
+ this.keyEnvironment = keyEnvironment;
231
+ this.configuredEnvironment = configuredEnvironment;
232
+ }
233
+ };
234
+ function strictKeyEnvironment(gameSecret) {
235
+ if (typeof gameSecret !== "string") return null;
236
+ if (gameSecret.startsWith(LIVE_KEY_PREFIX)) return "production";
237
+ if (gameSecret.startsWith(TEST_KEY_PREFIX)) return "sandbox";
238
+ return null;
239
+ }
240
+ function describeKey(env) {
241
+ return env === "production" ? `a live key (${LIVE_KEY_PREFIX})` : `a test key (${TEST_KEY_PREFIX})`;
242
+ }
243
+ function fixFor(keyEnv) {
244
+ return keyEnv === "production" ? `Use ${PRODUCTION_BASE_URL}, or a test key.` : `Use ${SANDBOX_BASE_URL}, or a live key.`;
245
+ }
246
+ function displayUrl(baseUrl) {
247
+ try {
248
+ const u = new URL(baseUrl.trim());
249
+ return `${u.protocol}//${u.host}${u.pathname}`.replace(/\/+$/, "");
250
+ } catch {
251
+ return "(the configured URL)";
252
+ }
253
+ }
254
+ function assertKeyMatchesBaseUrl(gameSecret, baseUrl, setting = "baseUrl") {
255
+ const keyEnv = strictKeyEnvironment(gameSecret);
256
+ if (!keyEnv) return;
257
+ const urlEnv = environmentForBaseUrl(baseUrl);
258
+ if (!urlEnv || urlEnv === keyEnv) return;
259
+ const where = urlEnv === "production" ? "production" : "the sandbox";
260
+ const shown = displayUrl(String(baseUrl));
261
+ throw new KeyEnvironmentMismatchError(
262
+ `This is ${describeKey(keyEnv)} but ${setting} points at ${where} ${shown}. ${fixFor(keyEnv)}`,
263
+ keyEnv,
264
+ urlEnv
265
+ );
266
+ }
267
+ function assertKeyMatchesEnvironment(gameSecret, environment, setting = "INVO_ENV", rawValue) {
268
+ const keyEnv = strictKeyEnvironment(gameSecret);
269
+ if (!keyEnv || keyEnv === environment) return;
270
+ const other = keyEnv === "production" ? "a test key" : "a live key";
271
+ const raw = rawValue?.trim();
272
+ const shown = raw && raw.toLowerCase() !== environment ? `"${raw}" (read as ${environment})` : environment;
273
+ throw new KeyEnvironmentMismatchError(
274
+ `This is ${describeKey(keyEnv)} but ${setting} is ${shown}. Remove ${setting} (the key picks the environment), or use ${other}.`,
275
+ keyEnv,
276
+ environment
277
+ );
278
+ }
279
+ var EnvironmentUnknownError = class extends Error {
280
+ constructor(message) {
281
+ super(message);
282
+ this.name = "EnvironmentUnknownError";
283
+ }
284
+ };
285
+ function isDemoKey(gameSecret) {
286
+ return typeof gameSecret === "string" && gameSecret.startsWith(DEMO_KEY_PREFIX);
287
+ }
288
+ var cache = /* @__PURE__ */ new Map();
289
+ async function ask(baseUrl, gameSecret, fetchImpl) {
290
+ let res;
291
+ try {
292
+ res = await fetchImpl(baseUrl + KEY_ENVIRONMENT_PATH, {
293
+ method: "GET",
294
+ headers: { "X-Game-Secret-Key": gameSecret, Accept: "application/json" },
295
+ redirect: "error"
296
+ });
297
+ } catch {
298
+ throw new EnvironmentUnknownError("Could not reach INVO to check the key.");
299
+ }
300
+ if (res.status === 401 || res.status === 403 || res.status === 404) return null;
301
+ if (!res.ok) throw new EnvironmentUnknownError(`INVO answered ${res.status} while checking the key.`);
302
+ const body = await res.json().catch(() => ({}));
303
+ return body.environment === "production" || body.environment === "sandbox" ? body.environment : null;
304
+ }
305
+ function resolveEnvironment(gameSecret, opts = {}) {
306
+ if (!gameSecret) return Promise.reject(new Error("A game secret is required."));
307
+ const byPrefix = environmentFromKeyPrefix(gameSecret);
308
+ if (byPrefix) return Promise.resolve(byPrefix);
309
+ const hit = cache.get(gameSecret);
310
+ if (hit) return hit;
311
+ const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
312
+ const p = (async () => {
313
+ let prodError = null;
314
+ let env = null;
315
+ try {
316
+ env = await ask(PRODUCTION_BASE_URL, gameSecret, fetchImpl);
317
+ } catch (err) {
318
+ prodError = err;
319
+ }
320
+ if (!env) {
321
+ try {
322
+ env = await ask(SANDBOX_BASE_URL, gameSecret, fetchImpl);
323
+ } catch (err) {
324
+ throw prodError ?? err;
325
+ }
326
+ }
327
+ if (!env && prodError) throw prodError;
328
+ if (!env) {
329
+ throw new EnvironmentUnknownError(
330
+ "Neither INVO production nor the INVO sandbox recognises this key. Check INVO_GAME_SECRET in your secrets."
331
+ );
332
+ }
333
+ return env;
334
+ })();
335
+ cache.set(gameSecret, p);
336
+ p.catch(() => cache.delete(gameSecret));
337
+ return p;
338
+ }
339
+ async function baseUrlForKey(gameSecret, opts = {}) {
340
+ return await resolveEnvironment(gameSecret, opts) === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL;
341
+ }
342
+
197
343
  // src/shared/types.ts
198
344
  function isRefundPendingApproval(r) {
199
345
  return r.status === "pending_approval";
@@ -365,74 +511,6 @@ async function hmacHexSubtle(secret, message) {
365
511
  return hex;
366
512
  }
367
513
 
368
- // src/environment.ts
369
- var PRODUCTION_BASE_URL = "https://invo.network";
370
- var SANDBOX_BASE_URL = "https://sandbox.invo.network/sandbox";
371
- var DEMO_KEY_PREFIX = "ivsdk_demo_";
372
- var KEY_ENVIRONMENT_PATH = "/api/sdk/key-environment";
373
- var EnvironmentUnknownError = class extends Error {
374
- constructor(message) {
375
- super(message);
376
- this.name = "EnvironmentUnknownError";
377
- }
378
- };
379
- function isDemoKey(gameSecret) {
380
- return typeof gameSecret === "string" && gameSecret.startsWith(DEMO_KEY_PREFIX);
381
- }
382
- var cache = /* @__PURE__ */ new Map();
383
- async function ask(baseUrl, gameSecret, fetchImpl) {
384
- let res;
385
- try {
386
- res = await fetchImpl(baseUrl + KEY_ENVIRONMENT_PATH, {
387
- method: "GET",
388
- headers: { "X-Game-Secret-Key": gameSecret, Accept: "application/json" },
389
- redirect: "error"
390
- });
391
- } catch {
392
- throw new EnvironmentUnknownError("Could not reach INVO to check the key.");
393
- }
394
- if (res.status === 401 || res.status === 403 || res.status === 404) return null;
395
- if (!res.ok) throw new EnvironmentUnknownError(`INVO answered ${res.status} while checking the key.`);
396
- const body = await res.json().catch(() => ({}));
397
- return body.environment === "production" || body.environment === "sandbox" ? body.environment : null;
398
- }
399
- function resolveEnvironment(gameSecret, opts = {}) {
400
- if (!gameSecret) return Promise.reject(new Error("A game secret is required."));
401
- if (isDemoKey(gameSecret)) return Promise.resolve("sandbox");
402
- const hit = cache.get(gameSecret);
403
- if (hit) return hit;
404
- const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
405
- const p = (async () => {
406
- let prodError = null;
407
- let env = null;
408
- try {
409
- env = await ask(PRODUCTION_BASE_URL, gameSecret, fetchImpl);
410
- } catch (err) {
411
- prodError = err;
412
- }
413
- if (!env) {
414
- try {
415
- env = await ask(SANDBOX_BASE_URL, gameSecret, fetchImpl);
416
- } catch (err) {
417
- throw prodError ?? err;
418
- }
419
- }
420
- if (!env && prodError) throw prodError;
421
- if (!env) {
422
- throw new EnvironmentUnknownError(
423
- "Neither INVO production nor the INVO sandbox recognises this key. Check INVO_GAME_SECRET in your secrets."
424
- );
425
- }
426
- return env;
427
- })();
428
- cache.set(gameSecret, p);
429
- p.catch(() => cache.delete(gameSecret));
430
- return p;
431
- }
432
- async function baseUrlForKey(gameSecret, opts = {}) {
433
- return await resolveEnvironment(gameSecret, opts) === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL;
434
- }
435
-
436
514
  // src/server.ts
437
515
  var DEFAULT_UA = `invonetwork-web-sdk/${SDK_VERSION} (+https://invo.network)`;
438
516
  var MAX_USD_AMOUNT = 999999.99;
@@ -2212,7 +2290,7 @@ var SandboxSubscriptionsServer = class {
2212
2290
  throw invalidInput2(
2213
2291
  "sandboxClockKey",
2214
2292
  this.clockKey,
2215
- 'is required for invo.sandbox.subscriptions.* \u2014 pass it to new InvoServer({ sandboxClockKey }) from the sandbox console (Game Settings, "Sandbox clock key")'
2293
+ 'is required for invo.sandbox.subscriptions.*: pass it to new InvoServer({ sandboxClockKey }) from the INVO console in test mode, console.invo.network/test (Game Settings, "Sandbox clock key")'
2216
2294
  );
2217
2295
  }
2218
2296
  const raw = await this.http.post(
@@ -2309,6 +2387,7 @@ var InvoServer = class {
2309
2387
  if (!config.gameSecret) throw new Error("InvoServer requires a `gameSecret`.");
2310
2388
  if (!config.baseUrl) throw new Error("InvoServer requires a `baseUrl`.");
2311
2389
  assertSecureBaseUrl(config.baseUrl);
2390
+ assertKeyMatchesBaseUrl(config.gameSecret.trim(), config.baseUrl);
2312
2391
  this.http = new Http({
2313
2392
  baseUrl: config.baseUrl,
2314
2393
  timeoutMs: config.timeoutMs,
@@ -3854,6 +3933,6 @@ var InvoServer = class {
3854
3933
  }
3855
3934
  };
3856
3935
 
3857
- 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 };
3858
- //# sourceMappingURL=chunk-DHVHKFQH.js.map
3859
- //# sourceMappingURL=chunk-DHVHKFQH.js.map
3936
+ export { CardsServer, DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, KeyEnvironmentMismatchError, LIVE_KEY_PREFIX, PRODUCTION_BASE_URL, PayoutsServer, PlatformCommerceServer, SANDBOX_BASE_URL, SandboxServer, SandboxSubscriptionsServer, SubscriptionsServer, TEST_KEY_PREFIX, assertKeyMatchesBaseUrl, assertKeyMatchesEnvironment, baseUrlForKey, createWebhookHandler, environmentForBaseUrl, environmentFromKeyPrefix, isDemoKey, isRefundPendingApproval, resolveEnvironment, verifyInvoSignature, verifyWebhook, verifyWebhookAsync };
3937
+ //# sourceMappingURL=chunk-MJXQ3Q7C.js.map
3938
+ //# sourceMappingURL=chunk-MJXQ3Q7C.js.map
@@ -1,4 +1,4 @@
1
- import { InvoError, assertSecureBaseUrl, Http, toPurchaseStatusResult, toPhoneChangeApprovalsResult, phoneChangeSignalMessage, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink, buildGameEventBody, toReportGameEventResult } from './chunk-HQLPT2DY.js';
1
+ import { InvoError, assertSecureBaseUrl, Http, toPurchaseStatusResult, toPhoneChangeApprovalsResult, phoneChangeSignalMessage, toApprovePhoneChangeResult, toDestinationsResult, toLoyaltyCardsResult, toLoyaltyVaultResult, toRedeemRewardResult, toRewardsPageLink, buildGameEventBody, toReportGameEventResult } from './chunk-3BR7URPM.js';
2
2
 
3
3
  // src/shared/webauthn.ts
4
4
  function malformedOptions(field) {
@@ -1586,5 +1586,5 @@ var InvoClient = class {
1586
1586
  };
1587
1587
 
1588
1588
  export { CheckoutClient, InvoClient, PlatformCommerceClient };
1589
- //# sourceMappingURL=chunk-MJAJXYFX.js.map
1590
- //# sourceMappingURL=chunk-MJAJXYFX.js.map
1589
+ //# sourceMappingURL=chunk-PEYWNML4.js.map
1590
+ //# sourceMappingURL=chunk-PEYWNML4.js.map
@@ -30,7 +30,84 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
30
30
  var PRODUCTION_BASE_URL = "https://invo.network";
31
31
  var SANDBOX_BASE_URL = "https://sandbox.invo.network/sandbox";
32
32
  var DEMO_KEY_PREFIX = "ivsdk_demo_";
33
+ var TEST_KEY_PREFIX = "ivsdk_test_";
34
+ var LIVE_KEY_PREFIX = "ivsdk_live_";
33
35
  var KEY_ENVIRONMENT_PATH = "/api/sdk/key-environment";
36
+ function environmentFromKeyPrefix(gameSecret) {
37
+ if (typeof gameSecret !== "string") return null;
38
+ if (gameSecret.startsWith(LIVE_KEY_PREFIX)) return "production";
39
+ if (gameSecret.startsWith(TEST_KEY_PREFIX) || gameSecret.startsWith(DEMO_KEY_PREFIX)) return "sandbox";
40
+ return null;
41
+ }
42
+ function environmentForBaseUrl(baseUrl) {
43
+ if (typeof baseUrl !== "string" || !baseUrl.trim()) return null;
44
+ let url;
45
+ try {
46
+ url = new URL(baseUrl.trim());
47
+ } catch {
48
+ return null;
49
+ }
50
+ const host = url.hostname.toLowerCase().replace(/\.$/, "");
51
+ if (host === "sandbox.invo.network") return "sandbox";
52
+ if (host === "invo.network" || host === "www.invo.network") {
53
+ const first = url.pathname.split("/").filter(Boolean)[0]?.toLowerCase();
54
+ return first === "sandbox" ? "sandbox" : "production";
55
+ }
56
+ return null;
57
+ }
58
+ var KeyEnvironmentMismatchError = class extends Error {
59
+ constructor(message, keyEnvironment, configuredEnvironment) {
60
+ super(message);
61
+ this.name = "KeyEnvironmentMismatchError";
62
+ this.keyEnvironment = keyEnvironment;
63
+ this.configuredEnvironment = configuredEnvironment;
64
+ }
65
+ };
66
+ function strictKeyEnvironment(gameSecret) {
67
+ if (typeof gameSecret !== "string") return null;
68
+ if (gameSecret.startsWith(LIVE_KEY_PREFIX)) return "production";
69
+ if (gameSecret.startsWith(TEST_KEY_PREFIX)) return "sandbox";
70
+ return null;
71
+ }
72
+ function describeKey(env) {
73
+ return env === "production" ? `a live key (${LIVE_KEY_PREFIX})` : `a test key (${TEST_KEY_PREFIX})`;
74
+ }
75
+ function fixFor(keyEnv) {
76
+ return keyEnv === "production" ? `Use ${PRODUCTION_BASE_URL}, or a test key.` : `Use ${SANDBOX_BASE_URL}, or a live key.`;
77
+ }
78
+ function displayUrl(baseUrl) {
79
+ try {
80
+ const u = new URL(baseUrl.trim());
81
+ return `${u.protocol}//${u.host}${u.pathname}`.replace(/\/+$/, "");
82
+ } catch {
83
+ return "(the configured URL)";
84
+ }
85
+ }
86
+ function assertKeyMatchesBaseUrl(gameSecret, baseUrl, setting = "baseUrl") {
87
+ const keyEnv = strictKeyEnvironment(gameSecret);
88
+ if (!keyEnv) return;
89
+ const urlEnv = environmentForBaseUrl(baseUrl);
90
+ if (!urlEnv || urlEnv === keyEnv) return;
91
+ const where = urlEnv === "production" ? "production" : "the sandbox";
92
+ const shown = displayUrl(String(baseUrl));
93
+ throw new KeyEnvironmentMismatchError(
94
+ `This is ${describeKey(keyEnv)} but ${setting} points at ${where} ${shown}. ${fixFor(keyEnv)}`,
95
+ keyEnv,
96
+ urlEnv
97
+ );
98
+ }
99
+ function assertKeyMatchesEnvironment(gameSecret, environment, setting = "INVO_ENV", rawValue) {
100
+ const keyEnv = strictKeyEnvironment(gameSecret);
101
+ if (!keyEnv || keyEnv === environment) return;
102
+ const other = keyEnv === "production" ? "a test key" : "a live key";
103
+ const raw = rawValue?.trim();
104
+ const shown = raw && raw.toLowerCase() !== environment ? `"${raw}" (read as ${environment})` : environment;
105
+ throw new KeyEnvironmentMismatchError(
106
+ `This is ${describeKey(keyEnv)} but ${setting} is ${shown}. Remove ${setting} (the key picks the environment), or use ${other}.`,
107
+ keyEnv,
108
+ environment
109
+ );
110
+ }
34
111
  var EnvironmentUnknownError = class extends Error {
35
112
  constructor(message) {
36
113
  super(message);
@@ -59,7 +136,8 @@ async function ask(baseUrl, gameSecret, fetchImpl) {
59
136
  }
60
137
  function resolveEnvironment(gameSecret, opts = {}) {
61
138
  if (!gameSecret) return Promise.reject(new Error("A game secret is required."));
62
- if (isDemoKey(gameSecret)) return Promise.resolve("sandbox");
139
+ const byPrefix = environmentFromKeyPrefix(gameSecret);
140
+ if (byPrefix) return Promise.resolve(byPrefix);
63
141
  const hit = cache.get(gameSecret);
64
142
  if (hit) return hit;
65
143
  const fetchImpl = opts.fetch ?? ((input, init) => fetch(input, init));
@@ -441,6 +519,17 @@ var InvoError = class _InvoError extends Error {
441
519
  get isPaymentsPaused() {
442
520
  return this.code === "PAYMENTS_PAUSED";
443
521
  }
522
+ /** The key belongs to the other INVO environment (`KEY_FOR_OTHER_ENVIRONMENT`, 401;
523
+ * additive, 3.34.0): a test key (`ivsdk_test_`) sent to production, or a live key
524
+ * (`ivsdk_live_`) sent to the sandbox. Never retried. Use the key for the environment
525
+ * you are calling, or point the SDK at the environment the key is for. The code is
526
+ * matched on any code field (`code`, `rawCode`, `publicCode`, or the body's
527
+ * `error_code` / `code`), since the 401 may carry a different `code`. */
528
+ get isKeyForOtherEnvironment() {
529
+ const C = "KEY_FOR_OTHER_ENVIRONMENT";
530
+ const b = this.bodyObject();
531
+ return this.code === C || this.rawCode === C || this.publicCode === C || b["error_code"] === C || b["code"] === C;
532
+ }
444
533
  /** A buyer-approved balance purchase cannot start (`BALANCE_UNAVAILABLE`, 400; 3.33.0):
445
534
  * the buyer is unknown here or their balance is short. One answer on purpose; the
446
535
  * balance is never disclosed. Offer another way to pay. */
@@ -926,7 +1015,7 @@ var InvoError = class _InvoError extends Error {
926
1015
  /**
927
1016
  * True when a sandbox clock call was refused for a missing, wrong or never-issued
928
1017
  * `X-Sandbox-Clock-Key` (`SANDBOX_CLOCK_UNAUTHORIZED`, 401). Reveal or rotate the key on
929
- * the game's Game Settings page in the sandbox console.
1018
+ * the game's Game Settings page in the INVO console in test mode (console.invo.network/test).
930
1019
  */
931
1020
  get isSandboxClockUnauthorized() {
932
1021
  return this.code === "SANDBOX_CLOCK_UNAUTHORIZED";
@@ -1761,7 +1850,7 @@ function toPhoneChangeRequest(raw) {
1761
1850
  }
1762
1851
 
1763
1852
  // src/version.ts
1764
- var SDK_VERSION = "3.33.0";
1853
+ var SDK_VERSION = "3.34.1";
1765
1854
 
1766
1855
  // src/payouts.ts
1767
1856
  var AMOUNT = /^\d+(\.\d{1,2})?$/;
@@ -3826,7 +3915,7 @@ var SandboxSubscriptionsServer = class {
3826
3915
  throw invalidInput2(
3827
3916
  "sandboxClockKey",
3828
3917
  this.clockKey,
3829
- 'is required for invo.sandbox.subscriptions.* \u2014 pass it to new InvoServer({ sandboxClockKey }) from the sandbox console (Game Settings, "Sandbox clock key")'
3918
+ 'is required for invo.sandbox.subscriptions.*: pass it to new InvoServer({ sandboxClockKey }) from the INVO console in test mode, console.invo.network/test (Game Settings, "Sandbox clock key")'
3830
3919
  );
3831
3920
  }
3832
3921
  const raw = await this.http.post(
@@ -3923,6 +4012,7 @@ var InvoServer = class {
3923
4012
  if (!config.gameSecret) throw new Error("InvoServer requires a `gameSecret`.");
3924
4013
  if (!config.baseUrl) throw new Error("InvoServer requires a `baseUrl`.");
3925
4014
  assertSecureBaseUrl(config.baseUrl);
4015
+ assertKeyMatchesBaseUrl(config.gameSecret.trim(), config.baseUrl);
3926
4016
  this.http = new Http({
3927
4017
  baseUrl: config.baseUrl,
3928
4018
  timeoutMs: config.timeoutMs,
@@ -6413,7 +6503,9 @@ function invoGameServerFromEnv(options) {
6413
6503
  const env = options.env;
6414
6504
  const secret = env["INVO_GAME_SECRET"]?.trim() ?? "";
6415
6505
  const forced = env["INVO_ENV"]?.trim().toLowerCase();
6416
- const known = forced ? forced === "production" ? "production" : "sandbox" : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
6506
+ const forcedEnv = forced ? forced === "production" ? "production" : "sandbox" : null;
6507
+ const prefixEnv = isDemoKey(secret) ? null : environmentFromKeyPrefix(secret);
6508
+ const known = forcedEnv ? forcedEnv : prefixEnv ? prefixEnv : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
6417
6509
  const state = { environment: known };
6418
6510
  const sandboxNow = () => state.environment === "sandbox";
6419
6511
  const envNow = () => state.environment ?? "resolving";
@@ -6430,9 +6522,11 @@ function invoGameServerFromEnv(options) {
6430
6522
  if (missing.length) {
6431
6523
  return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath, demo), missing, sandbox: sandboxNow(), environment: envNow(), demo };
6432
6524
  }
6525
+ if (forcedEnv) assertKeyMatchesEnvironment(secret, forcedEnv, "INVO_ENV", env["INVO_ENV"]);
6526
+ assertKeyMatchesBaseUrl(secret, env["INVO_BASE_URL"], "INVO_BASE_URL");
6433
6527
  const baseFetch = options.fetch ?? ((input, init) => fetch(input, init));
6434
6528
  const projectId = demoProject?.projectId ?? ((options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0);
6435
- const explicitBase = env["INVO_BASE_URL"] || (forced ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
6529
+ const explicitBase = env["INVO_BASE_URL"] || (forced || prefixEnv ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
6436
6530
  const resolveNow = () => resolveEnvironment(secret, { fetch: baseFetch }).then((e) => {
6437
6531
  state.environment = e;
6438
6532
  return e;
@@ -6628,15 +6722,20 @@ exports.EnvironmentUnknownError = EnvironmentUnknownError;
6628
6722
  exports.GameServerError = GameServerError;
6629
6723
  exports.InvoError = InvoError;
6630
6724
  exports.InvoServer = InvoServer;
6725
+ exports.KeyEnvironmentMismatchError = KeyEnvironmentMismatchError;
6726
+ exports.LIVE_KEY_PREFIX = LIVE_KEY_PREFIX;
6631
6727
  exports.PRODUCTION_BASE_URL = PRODUCTION_BASE_URL;
6632
6728
  exports.SANDBOX_BASE_URL = SANDBOX_BASE_URL;
6633
6729
  exports.SDK_VERSION = SDK_VERSION;
6730
+ exports.TEST_KEY_PREFIX = TEST_KEY_PREFIX;
6634
6731
  exports.baseUrlForKey = baseUrlForKey;
6635
6732
  exports.createFileGameStore = createFileGameStore;
6636
6733
  exports.createInvoGameServer = createInvoGameServer;
6637
6734
  exports.createMemoryGameStore = createMemoryGameStore;
6638
6735
  exports.demoPhoneFor = demoPhoneFor;
6639
6736
  exports.emptyGameState = emptyGameState;
6737
+ exports.environmentForBaseUrl = environmentForBaseUrl;
6738
+ exports.environmentFromKeyPrefix = environmentFromKeyPrefix;
6640
6739
  exports.invoGameServerFromEnv = invoGameServerFromEnv;
6641
6740
  exports.isDemoKey = isDemoKey;
6642
6741
  exports.isValidProjectId = isValidProjectId;
@@ -1,9 +1,9 @@
1
- import { I as InvoServer, a as InvoEnvironment } from './server-5_g5C-no.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-5_g5C-no.cjs';
1
+ import { I as InvoServer, a as InvoEnvironment } from './server-A1s7zqzG.cjs';
2
+ export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, K as KeyEnvironmentMismatchError, L as LIVE_KEY_PREFIX, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, T as TEST_KEY_PREFIX, b as baseUrlForKey, e as environmentForBaseUrl, c as environmentFromKeyPrefix, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-A1s7zqzG.cjs';
3
3
  import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-jUxfYjiD.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 GameTransferInput, n as GameTransferKind, o as GameTransferStart, p as GameTransferStatus, q as GameWallet } from './types-jUxfYjiD.cjs';
5
- export { I as InvoError } from './types-DUfQR48n.cjs';
6
- export { S as SDK_VERSION } from './version-DKfrEYU1.cjs';
5
+ export { I as InvoError } from './types-B4J9Ifd2.cjs';
6
+ export { S as SDK_VERSION } from './version-DB2wgiPY.cjs';
7
7
  import './loyalty-events-CmDw2ZoR.cjs';
8
8
 
9
9
  interface StoredPlayer {
@@ -217,12 +217,16 @@ interface InvoGameServerSetup {
217
217
  * game itself stays playable.
218
218
  *
219
219
  * - `INVO_GAME_SECRET` (required): your INVO key. The environment follows the key (3.28.0): the
220
- * public demo key (`ivsdk_demo_...`) is the sandbox; any other key is looked up once with
221
- * `GET /api/sdk/key-environment`. Going live is swapping this key, nothing else.
220
+ * public demo key (`ivsdk_demo_...`) and test keys (`ivsdk_test_...`, 3.34.0) are the sandbox,
221
+ * live keys (`ivsdk_live_...`, 3.34.0) are production, and any other key is looked up once
222
+ * with `GET /api/sdk/key-environment`. Going live is swapping this key, nothing else.
222
223
  * - `INVO_WEBHOOK_SECRET` (required): the webhook signing secret; several, comma-separated, while rotating
223
224
  * - `INVO_PROJECT_ID`: this copy's project id, when `projectId` is not passed
224
- * - `INVO_ENV`: `sandbox` or `production`, only to override the key-based choice
225
- * - `INVO_BASE_URL`: override the API base (rarely needed)
225
+ * - `INVO_ENV`: `sandbox` or `production`, only to override the key-based choice. With a live
226
+ * or test key it must agree with the key, or this throws `KeyEnvironmentMismatchError`.
227
+ * - `INVO_BASE_URL`: override the API base (rarely needed). With a live or test key, an INVO
228
+ * host for the other environment throws `KeyEnvironmentMismatchError`; any other host
229
+ * (your own proxy) is not checked.
226
230
  * - `PUBLIC_URL`: the game's public origin, for checkout return links
227
231
  */
228
232
  declare function invoGameServerFromEnv(options: InvoGameServerFromEnvOptions): InvoGameServerSetup;
@@ -1,9 +1,9 @@
1
- import { I as InvoServer, a as InvoEnvironment } from './server-Dhao5prR.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-Dhao5prR.js';
1
+ import { I as InvoServer, a as InvoEnvironment } from './server-JARGQrat.js';
2
+ export { D as DEMO_KEY_PREFIX, E as EnvironmentUnknownError, K as KeyEnvironmentMismatchError, L as LIVE_KEY_PREFIX, P as PRODUCTION_BASE_URL, S as SANDBOX_BASE_URL, T as TEST_KEY_PREFIX, b as baseUrlForKey, e as environmentForBaseUrl, c as environmentFromKeyPrefix, i as isDemoKey, r as resolveEnvironment, v as verifyInvoSignature } from './server-JARGQrat.js';
3
3
  import { G as GameCurrencyKind, a as GamePurchaseStatus, b as GameEconomyConfig } from './types-jUxfYjiD.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 GameTransferInput, n as GameTransferKind, o as GameTransferStart, p as GameTransferStatus, q as GameWallet } from './types-jUxfYjiD.js';
5
- export { I as InvoError } from './types-DUfQR48n.js';
6
- export { S as SDK_VERSION } from './version-DKfrEYU1.js';
5
+ export { I as InvoError } from './types-B4J9Ifd2.js';
6
+ export { S as SDK_VERSION } from './version-DB2wgiPY.js';
7
7
  import './loyalty-events-CmDw2ZoR.js';
8
8
 
9
9
  interface StoredPlayer {
@@ -217,12 +217,16 @@ interface InvoGameServerSetup {
217
217
  * game itself stays playable.
218
218
  *
219
219
  * - `INVO_GAME_SECRET` (required): your INVO key. The environment follows the key (3.28.0): the
220
- * public demo key (`ivsdk_demo_...`) is the sandbox; any other key is looked up once with
221
- * `GET /api/sdk/key-environment`. Going live is swapping this key, nothing else.
220
+ * public demo key (`ivsdk_demo_...`) and test keys (`ivsdk_test_...`, 3.34.0) are the sandbox,
221
+ * live keys (`ivsdk_live_...`, 3.34.0) are production, and any other key is looked up once
222
+ * with `GET /api/sdk/key-environment`. Going live is swapping this key, nothing else.
222
223
  * - `INVO_WEBHOOK_SECRET` (required): the webhook signing secret; several, comma-separated, while rotating
223
224
  * - `INVO_PROJECT_ID`: this copy's project id, when `projectId` is not passed
224
- * - `INVO_ENV`: `sandbox` or `production`, only to override the key-based choice
225
- * - `INVO_BASE_URL`: override the API base (rarely needed)
225
+ * - `INVO_ENV`: `sandbox` or `production`, only to override the key-based choice. With a live
226
+ * or test key it must agree with the key, or this throws `KeyEnvironmentMismatchError`.
227
+ * - `INVO_BASE_URL`: override the API base (rarely needed). With a live or test key, an INVO
228
+ * host for the other environment throws `KeyEnvironmentMismatchError`; any other host
229
+ * (your own proxy) is not checked.
226
230
  * - `PUBLIC_URL`: the game's public origin, for checkout return links
227
231
  */
228
232
  declare function invoGameServerFromEnv(options: InvoGameServerFromEnvOptions): InvoGameServerSetup;
@@ -1,8 +1,8 @@
1
- import { isDemoKey, SANDBOX_BASE_URL, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-DHVHKFQH.js';
2
- export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, baseUrlForKey, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-DHVHKFQH.js';
3
- export { SDK_VERSION } from './chunk-VWUFSA6U.js';
4
- import { InvoError } from './chunk-HQLPT2DY.js';
5
- export { InvoError } from './chunk-HQLPT2DY.js';
1
+ import { isDemoKey, SANDBOX_BASE_URL, environmentFromKeyPrefix, assertKeyMatchesEnvironment, assertKeyMatchesBaseUrl, PRODUCTION_BASE_URL, InvoServer, resolveEnvironment, verifyWebhook } from './chunk-MJXQ3Q7C.js';
2
+ export { DEMO_KEY_PREFIX, EnvironmentUnknownError, InvoServer, KeyEnvironmentMismatchError, LIVE_KEY_PREFIX, PRODUCTION_BASE_URL, SANDBOX_BASE_URL, TEST_KEY_PREFIX, baseUrlForKey, environmentForBaseUrl, environmentFromKeyPrefix, isDemoKey, resolveEnvironment, verifyInvoSignature } from './chunk-MJXQ3Q7C.js';
3
+ export { SDK_VERSION } from './chunk-6763YM7P.js';
4
+ import { InvoError } from './chunk-3BR7URPM.js';
5
+ export { InvoError } from './chunk-3BR7URPM.js';
6
6
  import { createHash, randomBytes } from 'crypto';
7
7
  import { promises, readFileSync, mkdirSync, writeFileSync } from 'fs';
8
8
  import * as path from 'path';
@@ -954,7 +954,9 @@ function invoGameServerFromEnv(options) {
954
954
  const env = options.env;
955
955
  const secret = env["INVO_GAME_SECRET"]?.trim() ?? "";
956
956
  const forced = env["INVO_ENV"]?.trim().toLowerCase();
957
- const known = forced ? forced === "production" ? "production" : "sandbox" : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
957
+ const forcedEnv = forced ? forced === "production" ? "production" : "sandbox" : null;
958
+ const prefixEnv = isDemoKey(secret) ? null : environmentFromKeyPrefix(secret);
959
+ const known = forcedEnv ? forcedEnv : prefixEnv ? prefixEnv : env["INVO_BASE_URL"] || !secret || isDemoKey(secret) ? "sandbox" : null;
958
960
  const state = { environment: known };
959
961
  const sandboxNow = () => state.environment === "sandbox";
960
962
  const envNow = () => state.environment ?? "resolving";
@@ -971,9 +973,11 @@ function invoGameServerFromEnv(options) {
971
973
  if (missing.length) {
972
974
  return { server: setupRequiredServer(options.economy, missing, sandboxNow(), options.basePath, demo), missing, sandbox: sandboxNow(), environment: envNow(), demo };
973
975
  }
976
+ if (forcedEnv) assertKeyMatchesEnvironment(secret, forcedEnv, "INVO_ENV", env["INVO_ENV"]);
977
+ assertKeyMatchesBaseUrl(secret, env["INVO_BASE_URL"], "INVO_BASE_URL");
974
978
  const baseFetch = options.fetch ?? ((input, init) => fetch(input, init));
975
979
  const projectId = demoProject?.projectId ?? ((options.projectId ?? env["INVO_PROJECT_ID"])?.trim() || void 0);
976
- const explicitBase = env["INVO_BASE_URL"] || (forced ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
980
+ const explicitBase = env["INVO_BASE_URL"] || (forced || prefixEnv ? state.environment === "production" ? PRODUCTION_BASE_URL : SANDBOX_BASE_URL : "");
977
981
  const resolveNow = () => resolveEnvironment(secret, { fetch: baseFetch }).then((e) => {
978
982
  state.environment = e;
979
983
  return e;