ituran-axi 0.1.4 → 0.1.6

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
@@ -109,11 +109,13 @@ ituran-axi handles these, and says so in its output where it matters:
109
109
  - Keypad driver codes above 2^53 stay exact.
110
110
  - A model year or odometer of 0 means "not set".
111
111
 
112
- Commands sharing a user's cache run their HTTP reads one command at a time, including sign-in. Requests within a command keep the existing limit of two in flight, starting at least 400 ms apart. The next command waits at least 400 ms after the previous command finishes. The command lock is `~/.cache/ituran-axi/command.lock` (or under `XDG_CACHE_HOME`). Waiting is limited to 30 seconds, or the remaining `COMIS_DEADLINE` minus one second. A busy lock returns `busy` without sending a request. Wait for the other command to finish before trying again.
112
+ Commands for the same host user run their HTTP reads one command at a time, including sign-in. Requests within a command keep the existing limit of two in flight, starting at least 400 ms apart. The next command waits at least 400 ms after the previous command finishes. The command lock is `/tmp/ituran-axi-<uid>/command.lock`, independent of `TMPDIR`, `HOME` and `XDG_CACHE_HOME`. Set `ITURAN_AXI_LOCK_DIR` to override its directory. Wrappers with separate filesystem namespaces must set this to the same writable directory shared by every command; keep it stable across accounts and tokens. A busy lock returns `busy` without sending a request. Wait for the other command to finish before trying again.
113
113
 
114
- The lock records its owner's PID, hostname and a random token. The holder refreshes its heartbeat every two seconds. A dead PID on the same host, or a heartbeat missing for ten seconds, permits automatic recovery. Release checks the owner token, so an old holder cannot remove a replacement lock. If cache storage is unavailable, the client tries a shared per-user lock under the system temporary directory. If that is also unavailable, it continues without a process lock, with the same output. Cache and cleanup errors never replace a successful result. Separate users, cache directories and hosts need their own coordination; the 400 ms gap between commands also depends on writable cache storage.
114
+ The lock records its owner's PID, hostname and a random token. The holder refreshes its heartbeat every two seconds. A dead PID on the same host, or a heartbeat missing for ten seconds, permits automatic recovery. Release checks the owner token, so an old holder cannot remove a replacement lock. If the selected lock directory is unavailable, reads continue without a process lock, with the same output. Cleanup errors never replace a successful result. Separate users and hosts need external coordination; the gap between commands also depends on writable lock storage.
115
115
 
116
- Request timeouts cover the response body too: 60 seconds for reads, 30 seconds for sign-in, shortened by `COMIS_DEADLINE` when set. A timeout aborts the request and cancels the response body. The CLI flushes its output and exits, releasing Node's proxy dispatcher sockets even if a proxy has not answered CONNECT.
116
+ Network commands have a 25-second overall budget, including lock waiting, sign-in, pacing, retries and all pages or windows. `COMIS_DEADLINE` can shorten this budget, with a one-second margin for output and cleanup. Reads and sign-in also have individual timeouts (60 and 30 seconds), shortened to the remaining command budget. Timeouts cover the response body, abort the request and cancel the body. The CLI flushes its error and exits, releasing Node's proxy dispatcher sockets even if a proxy has not answered CONNECT.
117
+
118
+ `trips` accepts at most 56 days per command, including `--by plate`. Longer ranges return a usage error before any trip requests. Split them into shorter windows. `--limit` limits output rows; calculating the exact count still reads each weekly window. This bound keeps counts, page hints and totals consistent for accepted windows.
117
119
 
118
120
  ## Output and errors
119
121
 
@@ -19,4 +19,7 @@ const code = await main(process.argv.slice(2), {
19
19
  // after fetch has aborted. This is a one-command process: once cleanup has
20
20
  // finished and stdout has drained, exit to release the dispatcher and sockets.
21
21
  // Setting only exitCode leaves that socket holding the process open.
22
- process.stdout.end(() => process.exit(code));
22
+ // Never end stdout: it may be a socket the caller's shell also writes to, and
23
+ // ending a socket shuts down writing for every process that shares it. An
24
+ // empty write's callback runs only after every earlier write has flushed.
25
+ process.stdout.write('', () => process.exit(code));
package/dist/cli/run.js CHANGED
@@ -143,7 +143,7 @@ export const COMMANDS = [
143
143
  page: PAGE,
144
144
  full: FULL,
145
145
  },
146
- summary: 'Trips in a window, default the last 24h',
146
+ summary: 'Trips, default 24h, at most 56 days',
147
147
  run: trips,
148
148
  },
149
149
  {
@@ -486,6 +486,7 @@ function remember(spec, io, error) {
486
486
  }
487
487
  }
488
488
  export async function main(argv, io) {
489
+ const commandDeadline = Date.now() + 25_000;
489
490
  let spec = HOME;
490
491
  let usageText = `${BIN} [command] [flags]`;
491
492
  try {
@@ -529,10 +530,21 @@ export async function main(argv, io) {
529
530
  }
530
531
  // Help and local logout do not need network serialization. Validate the
531
532
  // connection before creating a lock so missing settings stay actionable.
532
- const input = { ...parsed, io };
533
- const out = spec.name === 'logout'
534
- ? await spec.run(input)
535
- : await withCommandLock(io.env, connected(io.env).deadline, () => spec.run(input));
533
+ let out;
534
+ if (spec.name === 'logout') {
535
+ out = await spec.run({ ...parsed, io });
536
+ }
537
+ else {
538
+ const settings = connected(io.env);
539
+ const deadline = Math.min(commandDeadline, settings.deadline ?? Infinity);
540
+ // One deadline covers lock waiting, sign-in, pacing, retries and every
541
+ // page/window. A task deadline further in the future cannot extend it.
542
+ const commandIo = {
543
+ ...io,
544
+ env: { ...io.env, COMIS_DEADLINE: String(deadline) },
545
+ };
546
+ out = await withCommandLock(commandIo.env, deadline, () => spec.run({ ...parsed, io: commandIo }));
547
+ }
536
548
  remember(spec, io, null);
537
549
  io.stdout(out);
538
550
  return 0;
@@ -1,9 +1,9 @@
1
- // One network command at a time per user's cache, across accounts and tokens.
1
+ // One network command at a time per host user, across accounts and tokens.
2
2
  // A heartbeat lease and owner token let killed processes recover without
3
3
  // deleting or refreshing a replacement owner's lock.
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { closeSync, fstatSync, futimesSync, linkSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
6
- import { homedir, hostname, tmpdir } from 'node:os';
6
+ import { hostname } from 'node:os';
7
7
  import { join } from 'node:path';
8
8
  import { setTimeout as sleep } from 'node:timers/promises';
9
9
  import { AxiError } from './errors.js';
@@ -130,16 +130,19 @@ export async function withCommandLock(env, deadline, fn) {
130
130
  throw new AxiError('unreachable', 'The time for this command ran out before Ituran was asked.');
131
131
  }
132
132
  const until = performance.now() + waitMs;
133
- const root = env.XDG_CACHE_HOME || join(env.HOME || homedir(), '.cache');
133
+ // Never derive this from TMPDIR or XDG_CACHE_HOME: workbench commands
134
+ // can each receive different temporary and cache directories. Wrappers
135
+ // with private /tmp mounts must supply one shared, writable directory.
136
+ const dir = env.ITURAN_AXI_LOCK_DIR ||
137
+ join('/tmp', `ituran-axi-${process.getuid?.() ?? 'user'}`);
134
138
  const owner = {
135
139
  pid: process.pid,
136
140
  hostname: hostname(),
137
141
  token: randomUUID(),
138
142
  };
139
- const held = (await acquire(join(root, 'ituran-axi'), until, owner)) ??
140
- (await acquire(join(tmpdir(), `ituran-axi-${process.getuid?.() ?? 'user'}`), until, owner));
141
- // Cache storage is an optimization. Preserve reads even if both locations
142
- // are unavailable; contention on a usable lock never takes this fallback.
143
+ const held = await acquire(dir, until, owner);
144
+ // Preserve reads when the selected directory is unavailable. A usable
145
+ // lock's contention never takes this unlocked fallback.
143
146
  if (!held)
144
147
  return fn();
145
148
  const ownsPath = () => {
@@ -11,6 +11,7 @@ const round1 = (v) => typeof v === 'number' ? Math.round(v * 10) / 10 : null;
11
11
  const RECENT_HOURS = 6;
12
12
  /** Ituran fails an account-wide month of trips with HTTP 500, but answers a week. */
13
13
  export const TRIP_SPAN_DAYS = 7;
14
+ const MAX_TRIP_DAYS = 56;
14
15
  const LATE_NOTE = 'Ituran matches trips by their end time and lists a trip up to a few hours after it ends.';
15
16
  function windowFlags(values) {
16
17
  return {
@@ -116,6 +117,12 @@ export async function trips(input) {
116
117
  const plates = [...new Set(input.positionals.map(normalizePlate))];
117
118
  const acc = await account(ctx);
118
119
  const w = windowOf(windowFlags(values), acc.zone, ctx.now, '24h');
120
+ // joinedRows reads every week's count, even for --limit 1. Bound that
121
+ // work before scheduling any trip requests, including --by plate.
122
+ if (naiveMs(w.to) - naiveMs(w.from) >=
123
+ MAX_TRIP_DAYS * 86_400_000) {
124
+ throw usage('Trips cover at most 56 days per command. Ask for a shorter window; --limit only limits output rows.');
125
+ }
119
126
  const by = str(values.by);
120
127
  if (by !== undefined) {
121
128
  if (by !== 'plate')
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Kept equal to package.json by test/unit/version.test.ts.
2
- export const VERSION = '0.1.4';
2
+ export const VERSION = '0.1.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ituran-axi",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "A read-only command-line tool that lets AI agents read Ituran vehicle tracking",
5
5
  "license": "MIT",
6
6
  "type": "module",