ituran-axi 0.1.4 → 0.1.5
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 +5 -3
- package/dist/cli/run.js +17 -5
- package/dist/command-lock.js +10 -7
- package/dist/commands/trips.js +7 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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;
|
package/dist/command-lock.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// One network command at a time per user
|
|
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 {
|
|
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
|
-
|
|
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 =
|
|
140
|
-
|
|
141
|
-
//
|
|
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 = () => {
|
package/dist/commands/trips.js
CHANGED
|
@@ -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.
|
|
2
|
+
export const VERSION = '0.1.5';
|