@trazum/cli 3.0.1 → 3.0.3
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 +4 -1
- package/assets/trazum-statusline.sh +45 -0
- package/dist/base-cost.d.ts +173 -0
- package/dist/base-cost.d.ts.map +1 -0
- package/dist/base-cost.js +244 -0
- package/dist/base-cost.js.map +1 -0
- package/dist/bill-range.d.ts +118 -0
- package/dist/bill-range.d.ts.map +1 -0
- package/dist/bill-range.js +122 -0
- package/dist/bill-range.js.map +1 -0
- package/dist/command-help.d.ts +17 -0
- package/dist/command-help.d.ts.map +1 -0
- package/dist/command-help.js +69 -0
- package/dist/command-help.js.map +1 -0
- package/dist/filter.d.ts +7 -1
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +10 -18
- package/dist/filter.js.map +1 -1
- package/dist/gateway-metrics.d.ts +83 -0
- package/dist/gateway-metrics.d.ts.map +1 -0
- package/dist/gateway-metrics.js +181 -0
- package/dist/gateway-metrics.js.map +1 -0
- package/dist/gateway-server.d.ts +23 -5
- package/dist/gateway-server.d.ts.map +1 -1
- package/dist/gateway-server.js +26 -1
- package/dist/gateway-server.js.map +1 -1
- package/dist/gateway-spend.d.ts +11 -1
- package/dist/gateway-spend.d.ts.map +1 -1
- package/dist/gateway-spend.js +44 -32
- package/dist/gateway-spend.js.map +1 -1
- package/dist/git.d.ts +70 -0
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +145 -0
- package/dist/git.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +358 -6
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts +0 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +456 -35
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +205 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +942 -59
- package/dist/index.js.map +1 -1
- package/dist/loopback-guard.d.ts +37 -0
- package/dist/loopback-guard.d.ts.map +1 -0
- package/dist/loopback-guard.js +65 -0
- package/dist/loopback-guard.js.map +1 -0
- package/dist/markdown.d.ts +23 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +105 -0
- package/dist/markdown.js.map +1 -1
- package/dist/plan-edits.d.ts +63 -0
- package/dist/plan-edits.d.ts.map +1 -0
- package/dist/plan-edits.js +96 -0
- package/dist/plan-edits.js.map +1 -0
- package/dist/proactive.d.ts +17 -2
- package/dist/proactive.d.ts.map +1 -1
- package/dist/proactive.js +16 -9
- package/dist/proactive.js.map +1 -1
- package/dist/receipt-send.d.ts +44 -0
- package/dist/receipt-send.d.ts.map +1 -0
- package/dist/receipt-send.js +71 -0
- package/dist/receipt-send.js.map +1 -0
- package/dist/serve.d.ts +7 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +22 -1
- package/dist/serve.js.map +1 -1
- package/dist/session-guard.d.ts +210 -0
- package/dist/session-guard.d.ts.map +1 -0
- package/dist/session-guard.js +463 -0
- package/dist/session-guard.js.map +1 -0
- package/dist/task.d.ts +7 -1
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +7 -26
- package/dist/task.js.map +1 -1
- package/dist/waste.d.ts +25 -0
- package/dist/waste.d.ts.map +1 -0
- package/dist/waste.js +39 -0
- package/dist/waste.js.map +1 -0
- package/dist/zone.d.ts +27 -0
- package/dist/zone.d.ts.map +1 -0
- package/dist/zone.js +96 -0
- package/dist/zone.js.map +1 -0
- package/package.json +2 -2
- package/src/base-cost.ts +384 -0
- package/src/bill-range.ts +206 -0
- package/src/command-help.ts +65 -0
- package/src/filter.ts +11 -18
- package/src/gateway-metrics.ts +209 -0
- package/src/gateway-server.ts +43 -6
- package/src/gateway-spend.ts +45 -33
- package/src/git.ts +158 -0
- package/src/i18n/en.ts +424 -6
- package/src/i18n/es.ts +542 -35
- package/src/i18n/types.ts +208 -0
- package/src/index.ts +952 -58
- package/src/loopback-guard.ts +74 -0
- package/src/markdown.ts +117 -0
- package/src/plan-edits.ts +120 -0
- package/src/proactive.ts +22 -13
- package/src/receipt-send.ts +89 -0
- package/src/serve.ts +23 -1
- package/src/session-guard.ts +541 -0
- package/src/task.ts +8 -26
- package/src/waste.ts +42 -0
- package/src/zone.ts +95 -0
package/src/zone.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { parseUsageLine } from '@trazum/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calendar days in a named time zone, for `trazum bill --timezone` (#826).
|
|
5
|
+
*
|
|
6
|
+
* Everything else in the CLI cuts days in UTC, so the same log answers the same
|
|
7
|
+
* way in every office. A person who bills by their own calendar asks for their
|
|
8
|
+
* zone by its IANA name, and this is the whole of what that costs: the platform's
|
|
9
|
+
* `Intl.DateTimeFormat` knows the zone's rules, including the days that are 23 or
|
|
10
|
+
* 25 hours long, so no offset table and no dependency is shipped here.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const formatters = new Map<string, Intl.DateTimeFormat>();
|
|
14
|
+
|
|
15
|
+
function formatterFor(zone: string): Intl.DateTimeFormat {
|
|
16
|
+
const known = formatters.get(zone);
|
|
17
|
+
if (known !== undefined) return known;
|
|
18
|
+
const made = new Intl.DateTimeFormat('en-US', {
|
|
19
|
+
timeZone: zone,
|
|
20
|
+
calendar: 'gregory',
|
|
21
|
+
numberingSystem: 'latn',
|
|
22
|
+
hourCycle: 'h23',
|
|
23
|
+
year: 'numeric',
|
|
24
|
+
month: '2-digit',
|
|
25
|
+
day: '2-digit',
|
|
26
|
+
});
|
|
27
|
+
formatters.set(zone, made);
|
|
28
|
+
return made;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The zone's own spelling of a name the platform accepts (`europe/madrid` is
|
|
33
|
+
* `Europe/Madrid`), or `null` for one it does not. Nothing is guessed: a name
|
|
34
|
+
* the platform refuses is refused here.
|
|
35
|
+
*/
|
|
36
|
+
export function canonicalZone(name: string): string | null {
|
|
37
|
+
if (name.trim() === '') return null;
|
|
38
|
+
try {
|
|
39
|
+
return new Intl.DateTimeFormat('en-US', { timeZone: name }).resolvedOptions().timeZone;
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `YYYY-MM-DD` of an instant on the calendar of `zone`. */
|
|
46
|
+
export function dayInZone(ms: number, zone: string): string {
|
|
47
|
+
const parts = formatterFor(zone).formatToParts(new Date(ms));
|
|
48
|
+
const of = (type: string): string => parts.find((part) => part.type === type)?.value ?? '';
|
|
49
|
+
return `${of('year').padStart(4, '0')}-${of('month')}-${of('day')}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The calendar day after a `YYYY-MM-DD` one. Pure calendar arithmetic: no zone is involved. */
|
|
53
|
+
export function nextDay(day: string): string {
|
|
54
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + 86_400_000).toISOString().slice(0, 10);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The first instant of a `YYYY-MM-DD` day in `zone`.
|
|
59
|
+
*
|
|
60
|
+
* Found by search, not by adding an offset: the offset at midnight is not the
|
|
61
|
+
* offset the day began under when a clock change falls that night, and a day
|
|
62
|
+
* whose midnight does not exist (a zone that skips it) begins at the first
|
|
63
|
+
* instant that is on or after the day. Every zone's offset is within -12h and
|
|
64
|
+
* +14h, so the instant lies within a day and a half of the UTC midnight.
|
|
65
|
+
*/
|
|
66
|
+
export function startOfDayInZone(day: string, zone: string): number {
|
|
67
|
+
const utcMidnight = Date.parse(`${day}T00:00:00Z`);
|
|
68
|
+
let low = utcMidnight - 15 * 3_600_000;
|
|
69
|
+
let high = utcMidnight + 15 * 3_600_000;
|
|
70
|
+
/* Invariant: `low` is on an earlier day than `day`, `high` on `day` or later. */
|
|
71
|
+
while (high - low > 1) {
|
|
72
|
+
const mid = Math.floor((low + high) / 2);
|
|
73
|
+
if (dayInZone(mid, zone) < day) low = mid;
|
|
74
|
+
else high = mid;
|
|
75
|
+
}
|
|
76
|
+
return high;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The usage lines grouped by the day they fall on in `zone`. A line with no
|
|
81
|
+
* clock, or one the profile cannot read, is in no group: the profile accounts
|
|
82
|
+
* for those itself, and the bill's own total still holds them.
|
|
83
|
+
*/
|
|
84
|
+
export function groupByDayInZone(lines: readonly string[], zone: string): Map<string, string[]> {
|
|
85
|
+
const days = new Map<string, string[]>();
|
|
86
|
+
for (const line of lines) {
|
|
87
|
+
const record = parseUsageLine(line);
|
|
88
|
+
if (record === null || record.ts === null) continue;
|
|
89
|
+
const day = dayInZone(record.ts, zone);
|
|
90
|
+
const own = days.get(day);
|
|
91
|
+
if (own === undefined) days.set(day, [line]);
|
|
92
|
+
else own.push(line);
|
|
93
|
+
}
|
|
94
|
+
return days;
|
|
95
|
+
}
|