esim-cli 2026.1202.214 → 2026.1202.216

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/README.md CHANGED
@@ -41,9 +41,9 @@ esim market buy --schema
41
41
 
42
42
  Root help lists top-level commands by group. Run `esim help <group>` for one-line summaries, and `esim <noun> --help` for the available verbs. A bare noun such as `battle` or `market` opens its default view. Command help and schema describe parameters, defaults, fields, write behavior and the relevant wiki page.
43
43
 
44
- Run `esim login` and approve the link in your browser after checking that the verification code matches the terminal. Use `esim login --no-browser` to open the printed link yourself. The CLI saves the credential under `${XDG_CONFIG_HOME:-~/.config}/esim/credentials.json` and uses it when the API URL matches. `esim logout` deletes the local file. To revoke the API token, open **API token** on the web account page (`/account`).
44
+ Run `esim login` and approve the link in your browser after checking that the verification code matches the terminal. Use `esim login --no-browser` to open the printed link yourself. The CLI saves the credential under `${XDG_CONFIG_HOME:-~/.config}/esim/credentials.json` and uses it when the API origin (scheme, host and port) matches. `esim logout` deletes the local file. To revoke the API token, open **API token** on the web account page (`/account`).
45
45
 
46
- The executable reads `ESIM_API_URL` and defaults to `https://esim.350124.xyz`. For local development, set `ESIM_API_URL=http://127.0.0.1:8766`. `ESIM_API_TOKEN` overrides both the saved credential and `ESIM_SESSION_COOKIE`. `ESIM_SESSION_COOKIE` accepts a development cookie in the form `citizen=…` and overrides the saved credential.
46
+ The executable reads `ESIM_API_URL` and defaults to `https://esim.350124.xyz`. For local development, set `ESIM_API_URL=http://127.0.0.1:8766`. For player commands, `ESIM_API_TOKEN` overrides both the saved credential and `ESIM_SESSION_COOKIE`. `ESIM_SESSION_COOKIE` accepts a development cookie in the form `citizen=…` and overrides the saved credential.
47
47
 
48
48
  Text is the default output. Use `--json` to get the full structured output. `--fields a,b.c` projects keys before rendering either format, including keys inside arrays. Lists default to 20 entries. Use `--cursor` for the next page or `--all --max N` to bound the result. Errors go to stderr in the selected format. Exit codes are 0 for success, 2 for usage, 3 for business or authentication rejection, and 4 for transport or API failure.
49
49
 
@@ -61,7 +61,7 @@ Use `claim <task>` or `claim --chest` to collect one reward. Bare `claim` exits
61
61
 
62
62
  ## Administration
63
63
 
64
- `esim admin --help` lists the commands available in the installed CLI. Supply the administrator's current `citizen=…` cookie through `ESIM_SESSION_COOKIE` using a private environment. The API checks the account's administrator role. Admin uses HTTPS, with HTTP allowed on loopback for local development. API requests reject redirects.
64
+ Run `esim login` and approve the device code in your browser with an administrator account on the target server. The installed CLI uses that saved device credential for `esim admin`. The API checks your current administrator role on every request. If you signed in before the server supported CLI administration, run `esim login` again. Admin uses HTTPS, with HTTP allowed on loopback for local development. API requests reject redirects. Run `esim admin --help` to see the available commands.
65
65
 
66
66
  ```sh
67
67
  esim admin feedback list --status open --kind bug
package/dist/esim.js CHANGED
@@ -14939,7 +14939,7 @@ var catalog = [
14939
14939
  { operationId: "GetCivilPetition", name: "get-civil-petition", method: "GET", path: "/api/countries/{nation}/civil-war", spec: "battle.yaml", write: false, retry: "unsafe", description: "GetCivilPetition", parameters: [{ name: "nation", in: "path", required: true, schema: { type: "integer" } }], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", required: ["id", "population", "supporters"], properties: { id: { type: "integer", format: "int64" }, population: { type: "integer" }, supporters: { type: "integer" }, closesAt: { type: "string", format: "date-time" }, battle: { type: "integer", format: "int64" } } } } }, responseFields: ["id", "population", "supporters", "closesAt", "battle"] },
14940
14940
  { operationId: "ActCivilPetition", name: "act-civil-petition", method: "POST", path: "/api/countries/{nation}/civil-war", spec: "battle.yaml", write: true, retry: "unsafe", description: "ActCivilPetition", parameters: [{ name: "nation", in: "path", required: true, schema: { type: "integer" } }, { name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", required: ["petition"], properties: { petition: { type: "integer", format: "int64", minimum: 0, description: "Zero creates a new petition." } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", required: ["id", "population", "supporters"], properties: { id: { type: "integer", format: "int64" }, population: { type: "integer" }, supporters: { type: "integer" }, closesAt: { type: "string", format: "date-time" }, battle: { type: "integer", format: "int64" } } } } }, responseFields: ["id", "population", "supporters", "closesAt", "battle"] },
14941
14941
  { operationId: "GetPrizePreferences", name: "get-prize-preferences", method: "GET", path: "/api/me/prize-preferences", spec: "battle.yaml", write: false, retry: "unsafe", description: "GetPrizePreferences", parameters: [], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14942
- { operationId: "SavePrizePreferences", name: "save-prize-preferences", method: "PUT", path: "/api/me/prize-preferences", spec: "battle.yaml", write: true, retry: "natural", description: "Saves the personal reward order. Changes are rejected with prize_preferences_locked during the five-minute lock window of a scheduled-end prize event.", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14942
+ { operationId: "SavePrizePreferences", name: "save-prize-preferences", method: "PUT", path: "/api/me/prize-preferences", spec: "battle.yaml", write: true, retry: "natural", description: "Saves the personal reward order. Each tournament uses the latest order saved when settlement reads it.", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14943
14943
  { operationId: "ListWars", name: "list-wars", method: "GET", path: "/api/wars", spec: "battle.yaml", write: false, retry: "unsafe", description: "Public. Lists wars and diplomacy proposals, newest first.", parameters: [{ name: "country", in: "query", schema: { type: "integer", minimum: 0 } }, { name: "votable", in: "query", description: "Requires a citizen session and limits proposals to those the caller can vote on.", schema: { type: "boolean" } }], requiresCredentials: false, responses: { "200": { kind: "json", schema: { type: "object", required: ["wars", "proposals"], properties: { wars: { type: "array", items: { type: "object", required: ["id", "attacker", "defender", "startedAt", "peacePending"], properties: { id: { type: "integer", format: "int64", minimum: 1 }, attacker: { type: "integer" }, defender: { type: "integer" }, startedAt: { type: "string", format: "date-time" }, endedAt: { type: "string", format: "date-time" }, endReason: { type: "string", enum: ["peace", "conquest"] }, activeBattleId: { type: "integer", format: "int64", minimum: 1 }, peacePending: { type: "boolean" } } } }, proposals: { type: "array", items: { type: "object", required: ["id", "kind", "proposer", "targetCountry", "author", "createdAt", "closesAt", "status", "yes", "no", "costOnApproval"], properties: { lawId: { type: "integer", format: "int64", minimum: 1 }, authorSummary: { type: "object", additionalProperties: false, required: ["id", "name", "nation"], properties: { id: { type: "string", pattern: "^[1-9][0-9]*$", description: "Decimal encoding of the citizen ID." }, name: { type: "string" }, nation: { type: "integer", minimum: 0 } } }, costOnApproval: { type: "integer", format: "int64", minimum: 0, description: "Gold in minor units debited from the proposer's treasury when the proposal is approved. Declarations cost a fixed fee; peace is free." }, id: { type: "integer", format: "int64", minimum: 1 }, kind: { type: "string", enum: ["declare", "peace"] }, proposer: { type: "integer" }, targetCountry: { type: "integer" }, author: { type: "integer", format: "int64", minimum: 1 }, warId: { type: "integer", format: "int64", minimum: 1 }, createdAt: { type: "string", format: "date-time" }, closesAt: { type: "string", format: "date-time" }, status: { type: "string", enum: ["ACTIVE", "ACCEPTED_SUCCESS", "ACCEPTED_FAILED", "REJECTED"] }, yes: { type: "integer", minimum: 0 }, no: { type: "integer", minimum: 0 } } } } } } } }, responseFields: ["wars", "proposals"] },
14944
14944
  { operationId: "ProposeWar", name: "propose-war", method: "POST", path: "/api/wars/proposals", spec: "battle.yaml", write: true, retry: "unsafe", description: "ProposeWar", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", required: ["kind", "targetCountry"], properties: { kind: { type: "string", enum: ["declare", "peace"] }, targetCountry: { type: "integer", minimum: 0 } } } }, requiresCredentials: true, responses: { "201": { kind: "json", schema: { type: "object", required: ["id", "kind", "proposer", "targetCountry", "author", "createdAt", "closesAt", "status", "yes", "no", "costOnApproval"], properties: { lawId: { type: "integer", format: "int64", minimum: 1 }, authorSummary: { type: "object", additionalProperties: false, required: ["id", "name", "nation"], properties: { id: { type: "string", pattern: "^[1-9][0-9]*$", description: "Decimal encoding of the citizen ID." }, name: { type: "string" }, nation: { type: "integer", minimum: 0 } } }, costOnApproval: { type: "integer", format: "int64", minimum: 0, description: "Gold in minor units debited from the proposer's treasury when the proposal is approved. Declarations cost a fixed fee; peace is free." }, id: { type: "integer", format: "int64", minimum: 1 }, kind: { type: "string", enum: ["declare", "peace"] }, proposer: { type: "integer" }, targetCountry: { type: "integer" }, author: { type: "integer", format: "int64", minimum: 1 }, warId: { type: "integer", format: "int64", minimum: 1 }, createdAt: { type: "string", format: "date-time" }, closesAt: { type: "string", format: "date-time" }, status: { type: "string", enum: ["ACTIVE", "ACCEPTED_SUCCESS", "ACCEPTED_FAILED", "REJECTED"] }, yes: { type: "integer", minimum: 0 }, no: { type: "integer", minimum: 0 } } } } }, responseFields: ["lawId", "authorSummary", "costOnApproval", "id", "kind", "proposer", "targetCountry", "author", "warId", "createdAt", "closesAt", "status", "yes", "no"] },
14945
14945
  { operationId: "ListWarTargets", name: "list-war-targets", method: "GET", path: "/api/wars/targets", spec: "battle.yaml", write: false, retry: "unsafe", description: "List regions controlled by active war opponents, with the authenticated citizen's current ability to start an attack.", parameters: [{ name: "cursor", in: "query", description: "Opaque cursor returned by the preceding page for the same filters.", schema: { type: "string", minLength: 1, maxLength: 512 } }, { name: "limit", in: "query", schema: { type: "integer", minimum: 1, maximum: 100, default: 20 } }, { name: "country", in: "query", description: "Filter by the target region's controlling country.", schema: { type: "integer", minimum: 0 } }], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["items", "nextCursor"], properties: { items: { type: "array", items: { type: "object", additionalProperties: false, required: ["region", "adjacent", "war", "canStart"], properties: { region: { type: "object", additionalProperties: false, required: ["land", "owner"], properties: { land: { type: "integer", minimum: 0 }, homeNation: { type: "integer", minimum: 0 }, owner: { type: "integer", minimum: 0 } } }, adjacent: { type: "array", items: { type: "object", additionalProperties: false, required: ["land", "owner"], properties: { land: { type: "integer", minimum: 0 }, homeNation: { type: "integer", minimum: 0 }, owner: { type: "integer", minimum: 0 } } } }, war: { type: "integer", format: "int64" }, battle: { type: "integer", format: "int64" }, canStart: { type: "boolean" }, errorCode: { type: "string" }, reason: { type: "string" } } } }, nextCursor: { type: ["string", "null"] } } } } }, responseFields: ["items", "nextCursor"] },
@@ -17702,7 +17702,7 @@ var prizeRows = (keys) => keys.map((key, index) => ({ rank: index + 1, reward: k
17702
17702
  var prizeHelp = [
17703
17703
  "Country tournaments and the RW Tournament have a prize pool: ten packs, one of each reward, for every participating country.",
17704
17704
  "Citizens with damage pick in order of their damage in the event; each takes the first reward in their order that nobody above them in their country took.",
17705
- "The order saved five minutes before the event ends counts. The RW Tournament refuses changes in its last five minutes; for country tournaments, changes in the last five minutes do not count for that event.",
17705
+ "Each tournament uses your latest saved order when it settles, even if settlement happens after the event ends.",
17706
17706
  "Damage bonuses last 72 hours from the end of the event; when several are active, the highest applies. Military unit cups and duels have no prize pool."
17707
17707
  ];
17708
17708
  var confirmBattle = (args) => [`esim battle show ${Number(args.id)}`];
@@ -19193,18 +19193,7 @@ ${dropRule(result.kind === "practice")}`;
19193
19193
  output: { rewards: "Saved order: rank, reward key, prize and what it delivers", changed: "Preference order change", alreadyDone: "The reward order already matched" },
19194
19194
  async run(ctx, args) {
19195
19195
  const before = await ctx.call("get-prize-preferences");
19196
- let result;
19197
- try {
19198
- result = await ctx.call("save-prize-preferences", {}, { rewards: String(args.rewards).split(",") });
19199
- } catch (error) {
19200
- if (!(error instanceof CommandError) || error.error !== "prize_preferences_locked")
19201
- throw error;
19202
- throw new CommandError(3, error.error, "Prize preferences are locked for the last five minutes of the RW Tournament; your saved order still applies.", "", undefined, {
19203
- ...error.details,
19204
- context: { savedOrder: before.rewards.join(",") },
19205
- next: [{ run: "esim battle prizes" }]
19206
- });
19207
- }
19196
+ const result = await ctx.call("save-prize-preferences", {}, { rewards: String(args.rewards).split(",") });
19208
19197
  if ("alreadyDone" in result)
19209
19198
  return { rewards: prizeRows(before.rewards), alreadyDone: true };
19210
19199
  const reordered = change(before.rewards, result.rewards);
@@ -38396,9 +38385,49 @@ var adminOperations = [
38396
38385
  { operationId: "ResolveAdminFeedback", name: "resolve-admin-feedback", method: "POST", path: "/api/admin/feedback/{id}/resolve", spec: "feedback.yaml", write: true, retry: "unsafe", description: "Requires an administrator session and a same-origin JSON request. Closes an open report and records the review in the audit log.", parameters: [{ name: "id", in: "path", required: true, schema: { type: "integer", format: "int64", minimum: 1 } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["status", "reply"], properties: { status: { type: "string", enum: ["accepted", "rejected", "duplicate"], "x-enum-varnames": ["ResolveAccepted", "ResolveRejected", "ResolveDuplicate"], description: "Use accepted after verifying that the fix is available to players." }, reply: { type: "string", minLength: 1, maxLength: 2000 }, duplicateOf: { type: "integer", format: "int64", minimum: 1, description: "Required only for duplicate." } } } }, requiresCredentials: true, responses: { "204": { kind: "empty" } }, responseFields: [] }
38397
38386
  ];
38398
38387
 
38388
+ // login-credentials.ts
38389
+ var tokenSchema = string2().regex(/^esim_[A-Za-z0-9_-]+$/);
38390
+ var credentialSchema = object({ apiUrl: string2(), token: tokenSchema });
38391
+ function httpApiUrl(apiUrl) {
38392
+ const url = URL.canParse(apiUrl) ? new URL(apiUrl) : undefined;
38393
+ if (url && ["http:", "https:"].includes(url.protocol) && !url.username && !url.password)
38394
+ return url;
38395
+ }
38396
+ async function resolveCredentials(env, apiUrl, store) {
38397
+ if (env.ESIM_API_TOKEN)
38398
+ return { token: env.ESIM_API_TOKEN };
38399
+ if (env.ESIM_SESSION_COOKIE)
38400
+ return { cookie: env.ESIM_SESSION_COOKIE };
38401
+ return readSavedCredential(apiUrl, store);
38402
+ }
38403
+ async function readSavedCredential(apiUrl, store) {
38404
+ const origin = httpApiUrl(apiUrl)?.origin;
38405
+ if (!origin)
38406
+ return;
38407
+ const text = await store.read().catch(() => {
38408
+ throw new CommandError(4, "credentials_file_error", "Could not access the local CLI credentials file.", "Check access to the credentials file and run esim login again.");
38409
+ });
38410
+ if (text === undefined)
38411
+ return;
38412
+ let stored;
38413
+ try {
38414
+ stored = JSON.parse(text);
38415
+ } catch {
38416
+ return;
38417
+ }
38418
+ const credentials = credentialSchema.safeParse(stored);
38419
+ if (credentials.success && httpApiUrl(credentials.data.apiUrl)?.origin === origin)
38420
+ return { token: credentials.data.token };
38421
+ }
38422
+ function saveCredentials(store, credentials) {
38423
+ return store.write(JSON.stringify(credentials) + `
38424
+ `);
38425
+ }
38426
+
38399
38427
  // admin.ts
38400
38428
  var commands3 = [...coreAdminCommands, ...moderationCommands];
38401
38429
  var operations2 = new Map(adminOperations.map((operation) => [operation.operationId, operation]));
38430
+ var loginHint = "Run esim login for this server using an administrator account.";
38402
38431
  function commandUsage(command) {
38403
38432
  return `${command.usage}${command.write ? " (--dry-run | --yes)" : ""} [--json]`;
38404
38433
  }
@@ -38411,7 +38440,7 @@ function groupHelp2(path, matches) {
38411
38440
  ...matches.map((command) => ` ${commandUsage(command)}
38412
38441
  ${command.summary}`),
38413
38442
  "",
38414
- "Set ESIM_SESSION_COOKIE to a current administrator session before running a command."
38443
+ loginHint
38415
38444
  ].join(`
38416
38445
  `);
38417
38446
  }
@@ -38459,9 +38488,9 @@ function parse4(command, argv) {
38459
38488
  return { positionals, values: Object.fromEntries(values), dryRun, confirmed };
38460
38489
  }
38461
38490
  function adminOrigin(baseUrl) {
38462
- const url = URL.canParse(baseUrl) ? new URL(baseUrl) : undefined;
38491
+ const url = httpApiUrl(baseUrl);
38463
38492
  const loopback = url && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
38464
- if (!url || url.username || url.password || !(url.protocol === "https:" || url.protocol === "http:" && loopback)) {
38493
+ if (!url || !(url.protocol === "https:" || url.protocol === "http:" && loopback)) {
38465
38494
  throw new CommandError(2, "invalid_api_url", "Admin requires HTTPS or a loopback HTTP address.", "Check ESIM_API_URL.");
38466
38495
  }
38467
38496
  return url.origin;
@@ -38478,8 +38507,11 @@ function failureFor(error, operationId, input) {
38478
38507
  if (conflict && operationId === "ResolveAdminFeedback") {
38479
38508
  throw new CommandError(3, "feedback_already_closed", "This feedback report is already closed.", readFeedback);
38480
38509
  }
38510
+ if (error.error === "session_required" || error.error === "not_allowed_for_token") {
38511
+ throw new CommandError(3, error.error, "A current CLI device login is required for this administrator request.", loginHint);
38512
+ }
38481
38513
  if (error.error === "forbidden" || error.error === "http_403") {
38482
- throw new CommandError(3, "forbidden", "The API refused this administrator request.", "Check that ESIM_SESSION_COOKIE belongs to an administrator on this server.");
38514
+ throw new CommandError(3, "forbidden", "The API refused this administrator request.", "Check that the signed-in account has administrator access on this server. Run esim login again if needed.");
38483
38515
  }
38484
38516
  if (error.exitCode === 4 && (operationId === "UpdateWorldSpeed" || operationId === "ResolveAdminFeedback")) {
38485
38517
  throw new CommandError(4, error.error, error.message, operationId === "UpdateWorldSpeed" ? "Run esim admin config show to check whether the speed change was applied." : readFeedback);
@@ -38498,12 +38530,12 @@ function redact(value, secret) {
38498
38530
  }
38499
38531
  return value;
38500
38532
  }
38501
- async function runAdmin(argv, options, cookie) {
38533
+ async function runAdmin(argv, options, store) {
38502
38534
  const json = jsonRequested(argv);
38503
38535
  const help = flagRequested(argv, "--help");
38504
38536
  const words = help ? argv.filter((word) => word !== "--help" && word !== "--json") : argv;
38505
38537
  const command = commands3.find((entry) => entry.path.every((part, index) => part === words[index]));
38506
- const secret = cookie?.slice("citizen=".length) ?? "";
38538
+ let secret = "";
38507
38539
  try {
38508
38540
  if (!command) {
38509
38541
  const matches = commands3.filter((entry) => words.every((word, index) => entry.path[index] === word));
@@ -38521,17 +38553,20 @@ ${command.summary}
38521
38553
  return 0;
38522
38554
  }
38523
38555
  const args = parse4(command, argv.slice(command.path.length));
38524
- if (!cookie) {
38525
- throw new CommandError(3, "session_required", "A current administrator session is required.", "Set ESIM_SESSION_COOKIE to your citizen session cookie.");
38556
+ const baseUrl = adminOrigin(options.env.baseUrl);
38557
+ const credentials = await readSavedCredential(baseUrl, store);
38558
+ if (!credentials) {
38559
+ throw new CommandError(3, "session_required", "A current CLI device login is required.", loginHint);
38526
38560
  }
38561
+ secret = credentials.token;
38527
38562
  const { fetch: fetch2, stdout, stderr, columns } = options;
38528
38563
  const transport = {
38529
38564
  fetch: fetch2,
38530
38565
  stdout,
38531
38566
  stderr,
38532
38567
  columns,
38533
- credentials: { cookie },
38534
- env: { baseUrl: adminOrigin(options.env.baseUrl), signal: options.env.signal },
38568
+ credentials,
38569
+ env: { baseUrl, signal: options.env.signal },
38535
38570
  apiUrlEnvVar: "ESIM_API_URL"
38536
38571
  };
38537
38572
  const result = await command.run({
@@ -38572,34 +38607,8 @@ ${command.summary}
38572
38607
  }
38573
38608
  }
38574
38609
 
38575
- // login-credentials.ts
38576
- var tokenSchema = string2().regex(/^esim_[A-Za-z0-9_-]+$/);
38577
- var credentialSchema = object({ apiUrl: string2(), token: tokenSchema });
38578
- async function resolveCredentials(env, apiUrl, store) {
38579
- if (env.ESIM_API_TOKEN)
38580
- return { token: env.ESIM_API_TOKEN };
38581
- if (env.ESIM_SESSION_COOKIE)
38582
- return { cookie: env.ESIM_SESSION_COOKIE };
38583
- const text = await store.read();
38584
- if (text === undefined)
38585
- return;
38586
- let stored;
38587
- try {
38588
- stored = JSON.parse(text);
38589
- } catch {
38590
- return;
38591
- }
38592
- const credentials = credentialSchema.safeParse(stored);
38593
- if (credentials.success && credentials.data.apiUrl === apiUrl)
38594
- return { token: credentials.data.token };
38595
- }
38596
- function saveCredentials(store, credentials) {
38597
- return store.write(JSON.stringify(credentials) + `
38598
- `);
38599
- }
38600
-
38601
38610
  // version.ts
38602
- var version2 = "2026.1202.214";
38611
+ var version2 = "2026.1202.216";
38603
38612
  var installKind = version2 === "dev" ? "source" : typeof ESIM_CLI_EXECUTABLE === "boolean" && ESIM_CLI_EXECUTABLE ? "executable" : "npm";
38604
38613
  var npmLatestUrl = "https://registry.npmjs.org/esim-cli/latest";
38605
38614
  var releaseUrl = (release) => `https://github.com/CorrectRoadH/open-esim/releases/download/cli-v${release}`;
@@ -38663,8 +38672,8 @@ var identity = object({ citizen: object({ pid: string2().regex(/^[1-9][0-9]*$/),
38663
38672
  var noticeTimeout = 3000;
38664
38673
  var sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
38665
38674
  function apiOrigin(apiUrl) {
38666
- const url2 = URL.canParse(apiUrl) ? new URL(apiUrl) : undefined;
38667
- if (!url2 || !["http:", "https:"].includes(url2.protocol) || url2.username || url2.password) {
38675
+ const url2 = httpApiUrl(apiUrl);
38676
+ if (!url2) {
38668
38677
  throw new CommandError(2, "invalid_api_url", "Set ESIM_API_URL to an HTTP or HTTPS URL.", "");
38669
38678
  }
38670
38679
  return url2.origin;
@@ -38732,7 +38741,7 @@ Verification code: ${userCode}
38732
38741
  if (poll.data.status === "pending")
38733
38742
  continue;
38734
38743
  const { token } = poll.data;
38735
- await saveCredentials(executable.credentials, { apiUrl: options.env.baseUrl, token });
38744
+ await saveCredentials(executable.credentials, { apiUrl: apiOrigin(options.env.baseUrl), token });
38736
38745
  const operation = operations.get("me");
38737
38746
  if (!operation)
38738
38747
  invalidResponse();
@@ -38843,7 +38852,7 @@ async function runCommandLine(input, executable) {
38843
38852
  apiUrlEnvVar: "ESIM_API_URL"
38844
38853
  };
38845
38854
  if (isAdminInvocation(argv)) {
38846
- return runAdmin(name === "admin" ? args : ["--help", ...args.slice(1)], options, executable.env.ESIM_SESSION_COOKIE);
38855
+ return runAdmin(name === "admin" ? args : ["--help", ...args.slice(1)], options, executable.credentials);
38847
38856
  }
38848
38857
  try {
38849
38858
  if (name === "--version" && !args.filter((arg) => arg !== "--json").length) {
package/dist/index.js CHANGED
@@ -14935,7 +14935,7 @@ var catalog = [
14935
14935
  { operationId: "GetCivilPetition", name: "get-civil-petition", method: "GET", path: "/api/countries/{nation}/civil-war", spec: "battle.yaml", write: false, retry: "unsafe", description: "GetCivilPetition", parameters: [{ name: "nation", in: "path", required: true, schema: { type: "integer" } }], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", required: ["id", "population", "supporters"], properties: { id: { type: "integer", format: "int64" }, population: { type: "integer" }, supporters: { type: "integer" }, closesAt: { type: "string", format: "date-time" }, battle: { type: "integer", format: "int64" } } } } }, responseFields: ["id", "population", "supporters", "closesAt", "battle"] },
14936
14936
  { operationId: "ActCivilPetition", name: "act-civil-petition", method: "POST", path: "/api/countries/{nation}/civil-war", spec: "battle.yaml", write: true, retry: "unsafe", description: "ActCivilPetition", parameters: [{ name: "nation", in: "path", required: true, schema: { type: "integer" } }, { name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", required: ["petition"], properties: { petition: { type: "integer", format: "int64", minimum: 0, description: "Zero creates a new petition." } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", required: ["id", "population", "supporters"], properties: { id: { type: "integer", format: "int64" }, population: { type: "integer" }, supporters: { type: "integer" }, closesAt: { type: "string", format: "date-time" }, battle: { type: "integer", format: "int64" } } } } }, responseFields: ["id", "population", "supporters", "closesAt", "battle"] },
14937
14937
  { operationId: "GetPrizePreferences", name: "get-prize-preferences", method: "GET", path: "/api/me/prize-preferences", spec: "battle.yaml", write: false, retry: "unsafe", description: "GetPrizePreferences", parameters: [], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14938
- { operationId: "SavePrizePreferences", name: "save-prize-preferences", method: "PUT", path: "/api/me/prize-preferences", spec: "battle.yaml", write: true, retry: "natural", description: "Saves the personal reward order. Changes are rejected with prize_preferences_locked during the five-minute lock window of a scheduled-end prize event.", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14938
+ { operationId: "SavePrizePreferences", name: "save-prize-preferences", method: "PUT", path: "/api/me/prize-preferences", spec: "battle.yaml", write: true, retry: "natural", description: "Saves the personal reward order. Each tournament uses the latest order saved when settlement reads it.", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } }, requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["rewards"], properties: { rewards: { type: "array", minItems: 10, maxItems: 10, uniqueItems: true, items: { type: "string" } } } } } }, responseFields: ["rewards"] },
14939
14939
  { operationId: "ListWars", name: "list-wars", method: "GET", path: "/api/wars", spec: "battle.yaml", write: false, retry: "unsafe", description: "Public. Lists wars and diplomacy proposals, newest first.", parameters: [{ name: "country", in: "query", schema: { type: "integer", minimum: 0 } }, { name: "votable", in: "query", description: "Requires a citizen session and limits proposals to those the caller can vote on.", schema: { type: "boolean" } }], requiresCredentials: false, responses: { "200": { kind: "json", schema: { type: "object", required: ["wars", "proposals"], properties: { wars: { type: "array", items: { type: "object", required: ["id", "attacker", "defender", "startedAt", "peacePending"], properties: { id: { type: "integer", format: "int64", minimum: 1 }, attacker: { type: "integer" }, defender: { type: "integer" }, startedAt: { type: "string", format: "date-time" }, endedAt: { type: "string", format: "date-time" }, endReason: { type: "string", enum: ["peace", "conquest"] }, activeBattleId: { type: "integer", format: "int64", minimum: 1 }, peacePending: { type: "boolean" } } } }, proposals: { type: "array", items: { type: "object", required: ["id", "kind", "proposer", "targetCountry", "author", "createdAt", "closesAt", "status", "yes", "no", "costOnApproval"], properties: { lawId: { type: "integer", format: "int64", minimum: 1 }, authorSummary: { type: "object", additionalProperties: false, required: ["id", "name", "nation"], properties: { id: { type: "string", pattern: "^[1-9][0-9]*$", description: "Decimal encoding of the citizen ID." }, name: { type: "string" }, nation: { type: "integer", minimum: 0 } } }, costOnApproval: { type: "integer", format: "int64", minimum: 0, description: "Gold in minor units debited from the proposer's treasury when the proposal is approved. Declarations cost a fixed fee; peace is free." }, id: { type: "integer", format: "int64", minimum: 1 }, kind: { type: "string", enum: ["declare", "peace"] }, proposer: { type: "integer" }, targetCountry: { type: "integer" }, author: { type: "integer", format: "int64", minimum: 1 }, warId: { type: "integer", format: "int64", minimum: 1 }, createdAt: { type: "string", format: "date-time" }, closesAt: { type: "string", format: "date-time" }, status: { type: "string", enum: ["ACTIVE", "ACCEPTED_SUCCESS", "ACCEPTED_FAILED", "REJECTED"] }, yes: { type: "integer", minimum: 0 }, no: { type: "integer", minimum: 0 } } } } } } } }, responseFields: ["wars", "proposals"] },
14940
14940
  { operationId: "ProposeWar", name: "propose-war", method: "POST", path: "/api/wars/proposals", spec: "battle.yaml", write: true, retry: "unsafe", description: "ProposeWar", parameters: [{ name: "Origin", in: "header", required: true, description: "The same origin as the request.", schema: { type: "string", format: "uri" } }], body: { required: true, schema: { type: "object", required: ["kind", "targetCountry"], properties: { kind: { type: "string", enum: ["declare", "peace"] }, targetCountry: { type: "integer", minimum: 0 } } } }, requiresCredentials: true, responses: { "201": { kind: "json", schema: { type: "object", required: ["id", "kind", "proposer", "targetCountry", "author", "createdAt", "closesAt", "status", "yes", "no", "costOnApproval"], properties: { lawId: { type: "integer", format: "int64", minimum: 1 }, authorSummary: { type: "object", additionalProperties: false, required: ["id", "name", "nation"], properties: { id: { type: "string", pattern: "^[1-9][0-9]*$", description: "Decimal encoding of the citizen ID." }, name: { type: "string" }, nation: { type: "integer", minimum: 0 } } }, costOnApproval: { type: "integer", format: "int64", minimum: 0, description: "Gold in minor units debited from the proposer's treasury when the proposal is approved. Declarations cost a fixed fee; peace is free." }, id: { type: "integer", format: "int64", minimum: 1 }, kind: { type: "string", enum: ["declare", "peace"] }, proposer: { type: "integer" }, targetCountry: { type: "integer" }, author: { type: "integer", format: "int64", minimum: 1 }, warId: { type: "integer", format: "int64", minimum: 1 }, createdAt: { type: "string", format: "date-time" }, closesAt: { type: "string", format: "date-time" }, status: { type: "string", enum: ["ACTIVE", "ACCEPTED_SUCCESS", "ACCEPTED_FAILED", "REJECTED"] }, yes: { type: "integer", minimum: 0 }, no: { type: "integer", minimum: 0 } } } } }, responseFields: ["lawId", "authorSummary", "costOnApproval", "id", "kind", "proposer", "targetCountry", "author", "warId", "createdAt", "closesAt", "status", "yes", "no"] },
14941
14941
  { operationId: "ListWarTargets", name: "list-war-targets", method: "GET", path: "/api/wars/targets", spec: "battle.yaml", write: false, retry: "unsafe", description: "List regions controlled by active war opponents, with the authenticated citizen's current ability to start an attack.", parameters: [{ name: "cursor", in: "query", description: "Opaque cursor returned by the preceding page for the same filters.", schema: { type: "string", minLength: 1, maxLength: 512 } }, { name: "limit", in: "query", schema: { type: "integer", minimum: 1, maximum: 100, default: 20 } }, { name: "country", in: "query", description: "Filter by the target region's controlling country.", schema: { type: "integer", minimum: 0 } }], requiresCredentials: true, responses: { "200": { kind: "json", schema: { type: "object", additionalProperties: false, required: ["items", "nextCursor"], properties: { items: { type: "array", items: { type: "object", additionalProperties: false, required: ["region", "adjacent", "war", "canStart"], properties: { region: { type: "object", additionalProperties: false, required: ["land", "owner"], properties: { land: { type: "integer", minimum: 0 }, homeNation: { type: "integer", minimum: 0 }, owner: { type: "integer", minimum: 0 } } }, adjacent: { type: "array", items: { type: "object", additionalProperties: false, required: ["land", "owner"], properties: { land: { type: "integer", minimum: 0 }, homeNation: { type: "integer", minimum: 0 }, owner: { type: "integer", minimum: 0 } } } }, war: { type: "integer", format: "int64" }, battle: { type: "integer", format: "int64" }, canStart: { type: "boolean" }, errorCode: { type: "string" }, reason: { type: "string" } } } }, nextCursor: { type: ["string", "null"] } } } } }, responseFields: ["items", "nextCursor"] },
@@ -17698,7 +17698,7 @@ var prizeRows = (keys) => keys.map((key, index) => ({ rank: index + 1, reward: k
17698
17698
  var prizeHelp = [
17699
17699
  "Country tournaments and the RW Tournament have a prize pool: ten packs, one of each reward, for every participating country.",
17700
17700
  "Citizens with damage pick in order of their damage in the event; each takes the first reward in their order that nobody above them in their country took.",
17701
- "The order saved five minutes before the event ends counts. The RW Tournament refuses changes in its last five minutes; for country tournaments, changes in the last five minutes do not count for that event.",
17701
+ "Each tournament uses your latest saved order when it settles, even if settlement happens after the event ends.",
17702
17702
  "Damage bonuses last 72 hours from the end of the event; when several are active, the highest applies. Military unit cups and duels have no prize pool."
17703
17703
  ];
17704
17704
  var confirmBattle = (args) => [`esim battle show ${Number(args.id)}`];
@@ -19189,18 +19189,7 @@ ${dropRule(result.kind === "practice")}`;
19189
19189
  output: { rewards: "Saved order: rank, reward key, prize and what it delivers", changed: "Preference order change", alreadyDone: "The reward order already matched" },
19190
19190
  async run(ctx, args) {
19191
19191
  const before = await ctx.call("get-prize-preferences");
19192
- let result;
19193
- try {
19194
- result = await ctx.call("save-prize-preferences", {}, { rewards: String(args.rewards).split(",") });
19195
- } catch (error) {
19196
- if (!(error instanceof CommandError) || error.error !== "prize_preferences_locked")
19197
- throw error;
19198
- throw new CommandError(3, error.error, "Prize preferences are locked for the last five minutes of the RW Tournament; your saved order still applies.", "", undefined, {
19199
- ...error.details,
19200
- context: { savedOrder: before.rewards.join(",") },
19201
- next: [{ run: "esim battle prizes" }]
19202
- });
19203
- }
19192
+ const result = await ctx.call("save-prize-preferences", {}, { rewards: String(args.rewards).split(",") });
19204
19193
  if ("alreadyDone" in result)
19205
19194
  return { rewards: prizeRows(before.rewards), alreadyDone: true };
19206
19195
  const reordered = change(before.rewards, result.rewards);
@@ -38402,9 +38391,49 @@ var adminOperations = [
38402
38391
  { operationId: "ResolveAdminFeedback", name: "resolve-admin-feedback", method: "POST", path: "/api/admin/feedback/{id}/resolve", spec: "feedback.yaml", write: true, retry: "unsafe", description: "Requires an administrator session and a same-origin JSON request. Closes an open report and records the review in the audit log.", parameters: [{ name: "id", in: "path", required: true, schema: { type: "integer", format: "int64", minimum: 1 } }], body: { required: true, schema: { type: "object", additionalProperties: false, required: ["status", "reply"], properties: { status: { type: "string", enum: ["accepted", "rejected", "duplicate"], "x-enum-varnames": ["ResolveAccepted", "ResolveRejected", "ResolveDuplicate"], description: "Use accepted after verifying that the fix is available to players." }, reply: { type: "string", minLength: 1, maxLength: 2000 }, duplicateOf: { type: "integer", format: "int64", minimum: 1, description: "Required only for duplicate." } } } }, requiresCredentials: true, responses: { "204": { kind: "empty" } }, responseFields: [] }
38403
38392
  ];
38404
38393
 
38394
+ // login-credentials.ts
38395
+ var tokenSchema = string2().regex(/^esim_[A-Za-z0-9_-]+$/);
38396
+ var credentialSchema = object({ apiUrl: string2(), token: tokenSchema });
38397
+ function httpApiUrl(apiUrl) {
38398
+ const url = URL.canParse(apiUrl) ? new URL(apiUrl) : undefined;
38399
+ if (url && ["http:", "https:"].includes(url.protocol) && !url.username && !url.password)
38400
+ return url;
38401
+ }
38402
+ async function resolveCredentials(env, apiUrl, store) {
38403
+ if (env.ESIM_API_TOKEN)
38404
+ return { token: env.ESIM_API_TOKEN };
38405
+ if (env.ESIM_SESSION_COOKIE)
38406
+ return { cookie: env.ESIM_SESSION_COOKIE };
38407
+ return readSavedCredential(apiUrl, store);
38408
+ }
38409
+ async function readSavedCredential(apiUrl, store) {
38410
+ const origin = httpApiUrl(apiUrl)?.origin;
38411
+ if (!origin)
38412
+ return;
38413
+ const text = await store.read().catch(() => {
38414
+ throw new CommandError(4, "credentials_file_error", "Could not access the local CLI credentials file.", "Check access to the credentials file and run esim login again.");
38415
+ });
38416
+ if (text === undefined)
38417
+ return;
38418
+ let stored;
38419
+ try {
38420
+ stored = JSON.parse(text);
38421
+ } catch {
38422
+ return;
38423
+ }
38424
+ const credentials = credentialSchema.safeParse(stored);
38425
+ if (credentials.success && httpApiUrl(credentials.data.apiUrl)?.origin === origin)
38426
+ return { token: credentials.data.token };
38427
+ }
38428
+ function saveCredentials(store, credentials) {
38429
+ return store.write(JSON.stringify(credentials) + `
38430
+ `);
38431
+ }
38432
+
38405
38433
  // admin.ts
38406
38434
  var commands3 = [...coreAdminCommands, ...moderationCommands];
38407
38435
  var operations2 = new Map(adminOperations.map((operation) => [operation.operationId, operation]));
38436
+ var loginHint = "Run esim login for this server using an administrator account.";
38408
38437
  function commandUsage(command) {
38409
38438
  return `${command.usage}${command.write ? " (--dry-run | --yes)" : ""} [--json]`;
38410
38439
  }
@@ -38417,7 +38446,7 @@ function groupHelp2(path, matches) {
38417
38446
  ...matches.map((command) => ` ${commandUsage(command)}
38418
38447
  ${command.summary}`),
38419
38448
  "",
38420
- "Set ESIM_SESSION_COOKIE to a current administrator session before running a command."
38449
+ loginHint
38421
38450
  ].join(`
38422
38451
  `);
38423
38452
  }
@@ -38465,9 +38494,9 @@ function parse4(command, argv) {
38465
38494
  return { positionals, values: Object.fromEntries(values), dryRun, confirmed };
38466
38495
  }
38467
38496
  function adminOrigin(baseUrl) {
38468
- const url = URL.canParse(baseUrl) ? new URL(baseUrl) : undefined;
38497
+ const url = httpApiUrl(baseUrl);
38469
38498
  const loopback = url && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
38470
- if (!url || url.username || url.password || !(url.protocol === "https:" || url.protocol === "http:" && loopback)) {
38499
+ if (!url || !(url.protocol === "https:" || url.protocol === "http:" && loopback)) {
38471
38500
  throw new CommandError(2, "invalid_api_url", "Admin requires HTTPS or a loopback HTTP address.", "Check ESIM_API_URL.");
38472
38501
  }
38473
38502
  return url.origin;
@@ -38484,8 +38513,11 @@ function failureFor(error, operationId, input) {
38484
38513
  if (conflict && operationId === "ResolveAdminFeedback") {
38485
38514
  throw new CommandError(3, "feedback_already_closed", "This feedback report is already closed.", readFeedback);
38486
38515
  }
38516
+ if (error.error === "session_required" || error.error === "not_allowed_for_token") {
38517
+ throw new CommandError(3, error.error, "A current CLI device login is required for this administrator request.", loginHint);
38518
+ }
38487
38519
  if (error.error === "forbidden" || error.error === "http_403") {
38488
- throw new CommandError(3, "forbidden", "The API refused this administrator request.", "Check that ESIM_SESSION_COOKIE belongs to an administrator on this server.");
38520
+ throw new CommandError(3, "forbidden", "The API refused this administrator request.", "Check that the signed-in account has administrator access on this server. Run esim login again if needed.");
38489
38521
  }
38490
38522
  if (error.exitCode === 4 && (operationId === "UpdateWorldSpeed" || operationId === "ResolveAdminFeedback")) {
38491
38523
  throw new CommandError(4, error.error, error.message, operationId === "UpdateWorldSpeed" ? "Run esim admin config show to check whether the speed change was applied." : readFeedback);
@@ -38504,12 +38536,12 @@ function redact(value, secret) {
38504
38536
  }
38505
38537
  return value;
38506
38538
  }
38507
- async function runAdmin(argv, options, cookie) {
38539
+ async function runAdmin(argv, options, store) {
38508
38540
  const json = jsonRequested(argv);
38509
38541
  const help = flagRequested(argv, "--help");
38510
38542
  const words = help ? argv.filter((word) => word !== "--help" && word !== "--json") : argv;
38511
38543
  const command = commands3.find((entry) => entry.path.every((part, index) => part === words[index]));
38512
- const secret = cookie?.slice("citizen=".length) ?? "";
38544
+ let secret = "";
38513
38545
  try {
38514
38546
  if (!command) {
38515
38547
  const matches = commands3.filter((entry) => words.every((word, index) => entry.path[index] === word));
@@ -38527,17 +38559,20 @@ ${command.summary}
38527
38559
  return 0;
38528
38560
  }
38529
38561
  const args = parse4(command, argv.slice(command.path.length));
38530
- if (!cookie) {
38531
- throw new CommandError(3, "session_required", "A current administrator session is required.", "Set ESIM_SESSION_COOKIE to your citizen session cookie.");
38562
+ const baseUrl = adminOrigin(options.env.baseUrl);
38563
+ const credentials = await readSavedCredential(baseUrl, store);
38564
+ if (!credentials) {
38565
+ throw new CommandError(3, "session_required", "A current CLI device login is required.", loginHint);
38532
38566
  }
38567
+ secret = credentials.token;
38533
38568
  const { fetch: fetch2, stdout, stderr, columns } = options;
38534
38569
  const transport = {
38535
38570
  fetch: fetch2,
38536
38571
  stdout,
38537
38572
  stderr,
38538
38573
  columns,
38539
- credentials: { cookie },
38540
- env: { baseUrl: adminOrigin(options.env.baseUrl), signal: options.env.signal },
38574
+ credentials,
38575
+ env: { baseUrl, signal: options.env.signal },
38541
38576
  apiUrlEnvVar: "ESIM_API_URL"
38542
38577
  };
38543
38578
  const result = await command.run({
@@ -38578,34 +38613,8 @@ ${command.summary}
38578
38613
  }
38579
38614
  }
38580
38615
 
38581
- // login-credentials.ts
38582
- var tokenSchema = string2().regex(/^esim_[A-Za-z0-9_-]+$/);
38583
- var credentialSchema = object({ apiUrl: string2(), token: tokenSchema });
38584
- async function resolveCredentials(env, apiUrl, store) {
38585
- if (env.ESIM_API_TOKEN)
38586
- return { token: env.ESIM_API_TOKEN };
38587
- if (env.ESIM_SESSION_COOKIE)
38588
- return { cookie: env.ESIM_SESSION_COOKIE };
38589
- const text = await store.read();
38590
- if (text === undefined)
38591
- return;
38592
- let stored;
38593
- try {
38594
- stored = JSON.parse(text);
38595
- } catch {
38596
- return;
38597
- }
38598
- const credentials = credentialSchema.safeParse(stored);
38599
- if (credentials.success && credentials.data.apiUrl === apiUrl)
38600
- return { token: credentials.data.token };
38601
- }
38602
- function saveCredentials(store, credentials) {
38603
- return store.write(JSON.stringify(credentials) + `
38604
- `);
38605
- }
38606
-
38607
38616
  // version.ts
38608
- var version2 = "2026.1202.214";
38617
+ var version2 = "2026.1202.216";
38609
38618
  var installKind = version2 === "dev" ? "source" : typeof ESIM_CLI_EXECUTABLE === "boolean" && ESIM_CLI_EXECUTABLE ? "executable" : "npm";
38610
38619
  var npmLatestUrl = "https://registry.npmjs.org/esim-cli/latest";
38611
38620
  var releaseVersion = /^\d+\.\d+\.\d+$/;
@@ -38668,8 +38677,8 @@ var identity = object({ citizen: object({ pid: string2().regex(/^[1-9][0-9]*$/),
38668
38677
  var noticeTimeout = 3000;
38669
38678
  var sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
38670
38679
  function apiOrigin(apiUrl) {
38671
- const url2 = URL.canParse(apiUrl) ? new URL(apiUrl) : undefined;
38672
- if (!url2 || !["http:", "https:"].includes(url2.protocol) || url2.username || url2.password) {
38680
+ const url2 = httpApiUrl(apiUrl);
38681
+ if (!url2) {
38673
38682
  throw new CommandError(2, "invalid_api_url", "Set ESIM_API_URL to an HTTP or HTTPS URL.", "");
38674
38683
  }
38675
38684
  return url2.origin;
@@ -38737,7 +38746,7 @@ Verification code: ${userCode}
38737
38746
  if (poll.data.status === "pending")
38738
38747
  continue;
38739
38748
  const { token } = poll.data;
38740
- await saveCredentials(executable.credentials, { apiUrl: options.env.baseUrl, token });
38749
+ await saveCredentials(executable.credentials, { apiUrl: apiOrigin(options.env.baseUrl), token });
38741
38750
  const operation = operations.get("me");
38742
38751
  if (!operation)
38743
38752
  invalidResponse();
@@ -38848,7 +38857,7 @@ async function runCommandLine(input, executable) {
38848
38857
  apiUrlEnvVar: "ESIM_API_URL"
38849
38858
  };
38850
38859
  if (isAdminInvocation(argv)) {
38851
- return runAdmin(name === "admin" ? args : ["--help", ...args.slice(1)], options, executable.env.ESIM_SESSION_COOKIE);
38860
+ return runAdmin(name === "admin" ? args : ["--help", ...args.slice(1)], options, executable.credentials);
38852
38861
  }
38853
38862
  try {
38854
38863
  if (name === "--version" && !args.filter((arg) => arg !== "--json").length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esim-cli",
3
- "version": "2026.1202.214",
3
+ "version": "2026.1202.216",
4
4
  "description": "Command-line client and agent project for Open E-Sim",
5
5
  "type": "module",
6
6
  "license": "MIT",