@curless/hotel-storefront 0.69.4 → 0.70.0
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 +11 -0
- package/dist/account/index.d.ts +21 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +63 -4
- package/dist/account/index.js.map +1 -1
- package/dist/config.d.ts +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/huazhu/client.d.ts +3 -1
- package/dist/huazhu/client.d.ts.map +1 -1
- package/dist/huazhu/client.js +26 -0
- package/dist/huazhu/client.js.map +1 -1
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +4 -0
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +3 -2
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +8 -2
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/places.d.ts.map +1 -1
- package/dist/otaless/places.js +16 -2
- package/dist/otaless/places.js.map +1 -1
- package/dist/regions.d.ts.map +1 -1
- package/dist/regions.js +25 -2
- package/dist/regions.js.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +245 -8
- package/dist/server.js.map +1 -1
- package/dist/usage/boot.d.ts +32 -0
- package/dist/usage/boot.d.ts.map +1 -0
- package/dist/usage/boot.js +140 -0
- package/dist/usage/boot.js.map +1 -0
- package/dist/usage/geo.d.ts +48 -0
- package/dist/usage/geo.d.ts.map +1 -0
- package/dist/usage/geo.js +347 -0
- package/dist/usage/geo.js.map +1 -0
- package/dist/usage/maintain.d.ts +26 -0
- package/dist/usage/maintain.d.ts.map +1 -0
- package/dist/usage/maintain.js +177 -0
- package/dist/usage/maintain.js.map +1 -0
- package/dist/usage/platform.d.ts +69 -0
- package/dist/usage/platform.d.ts.map +1 -0
- package/dist/usage/platform.js +124 -0
- package/dist/usage/platform.js.map +1 -0
- package/dist/usage/pseudonym.d.ts +28 -0
- package/dist/usage/pseudonym.d.ts.map +1 -0
- package/dist/usage/pseudonym.js +73 -0
- package/dist/usage/pseudonym.js.map +1 -0
- package/dist/usage/range.d.ts +24 -0
- package/dist/usage/range.d.ts.map +1 -0
- package/dist/usage/range.js +102 -0
- package/dist/usage/range.js.map +1 -0
- package/dist/usage/recorder.d.ts +115 -0
- package/dist/usage/recorder.d.ts.map +1 -0
- package/dist/usage/recorder.js +227 -0
- package/dist/usage/recorder.js.map +1 -0
- package/dist/usage/report.d.ts +207 -0
- package/dist/usage/report.d.ts.map +1 -0
- package/dist/usage/report.js +730 -0
- package/dist/usage/report.js.map +1 -0
- package/dist/usage/shadow-import.d.ts +28 -0
- package/dist/usage/shadow-import.d.ts.map +1 -0
- package/dist/usage/shadow-import.js +107 -0
- package/dist/usage/shadow-import.js.map +1 -0
- package/dist/usage/store.d.ts +215 -0
- package/dist/usage/store.d.ts.map +1 -0
- package/dist/usage/store.js +430 -0
- package/dist/usage/store.js.map +1 -0
- package/dist/usage-cli.d.ts +3 -0
- package/dist/usage-cli.d.ts.map +1 -0
- package/dist/usage-cli.js +152 -0
- package/dist/usage-cli.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// Copied from @curless/shopify-storefront src/usage/geo.ts (0.77.2) - the same
|
|
2
|
+
// files, the same answers; only the address parser is this package's own, and
|
|
3
|
+
// nothing here downloads (the hotel connectors read local files only: Huazhu's
|
|
4
|
+
// production container reaches nothing but Huazhu).
|
|
5
|
+
//
|
|
6
|
+
// Country and network type of an address, from DB-IP's free "Lite" databases
|
|
7
|
+
// (IP to Country Lite, ASN Lite - CC BY 4.0, https://db-ip.com), read from
|
|
8
|
+
// files on this machine. No address is sent anywhere to be looked up.
|
|
9
|
+
//
|
|
10
|
+
// The CSV form, because it needs no parser library and a three-line fixture
|
|
11
|
+
// tests the real loader: `start,end,CC` and `start,end,ASN,Organisation`. Kept
|
|
12
|
+
// in memory as sorted typed arrays (~30 MB for both) and searched by bisection.
|
|
13
|
+
//
|
|
14
|
+
// ⚠️ NETWORK TYPE IS AN ESTIMATE. ASN Lite names the network's owner and nothing
|
|
15
|
+
// else, so "hosting" means the owner is a cloud, hosting, CDN or VPN company we
|
|
16
|
+
// recognise - by number (HOSTING_ASNS) or by name (HOSTING_NAME) - and "isp" means
|
|
17
|
+
// it is not: home broadband and mobile mostly, but an office or a university
|
|
18
|
+
// lands there too.
|
|
19
|
+
import { createReadStream, existsSync, readdirSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { createInterface } from 'node:readline';
|
|
22
|
+
import { createGunzip } from 'node:zlib';
|
|
23
|
+
import { parseAddress } from '../cidr.js';
|
|
24
|
+
/** An address as the tables want it - the package's own parser (cidr.ts), IPv4-mapped IPv6 read as IPv4. */
|
|
25
|
+
export const parseIp = (ip) => {
|
|
26
|
+
const a = parseAddress(ip);
|
|
27
|
+
return a ? { v6: a.v === 6, n: a.n } : null;
|
|
28
|
+
};
|
|
29
|
+
const NOTHING = { cc: null, net: 'unknown' };
|
|
30
|
+
/** Clouds, hosts, CDNs and VPN operators, by AS number. */
|
|
31
|
+
export const HOSTING_ASNS = new Set([
|
|
32
|
+
16509,
|
|
33
|
+
14618,
|
|
34
|
+
8987, // Amazon
|
|
35
|
+
15169,
|
|
36
|
+
396982,
|
|
37
|
+
19527,
|
|
38
|
+
36040, // Google (not Google Fiber, 16591)
|
|
39
|
+
8075,
|
|
40
|
+
8068,
|
|
41
|
+
8069, // Microsoft
|
|
42
|
+
14061, // DigitalOcean
|
|
43
|
+
16276,
|
|
44
|
+
35540, // OVH
|
|
45
|
+
24940,
|
|
46
|
+
213230, // Hetzner
|
|
47
|
+
63949,
|
|
48
|
+
20940,
|
|
49
|
+
16625,
|
|
50
|
+
32787, // Linode / Akamai (and iCloud Private Relay)
|
|
51
|
+
20473, // Vultr / Choopa
|
|
52
|
+
31898, // Oracle
|
|
53
|
+
45102,
|
|
54
|
+
37963, // Alibaba
|
|
55
|
+
132203,
|
|
56
|
+
45090, // Tencent
|
|
57
|
+
13335,
|
|
58
|
+
209242, // Cloudflare (and WARP)
|
|
59
|
+
54113, // Fastly
|
|
60
|
+
9009, // M247
|
|
61
|
+
60068,
|
|
62
|
+
212238, // Datacamp / CDN77
|
|
63
|
+
60781,
|
|
64
|
+
28753, // Leaseweb
|
|
65
|
+
51167, // Contabo
|
|
66
|
+
12876, // Scaleway
|
|
67
|
+
8560, // IONOS
|
|
68
|
+
21859, // Zenlayer
|
|
69
|
+
40676, // Psychz
|
|
70
|
+
8100, // QuadraNet
|
|
71
|
+
46844, // Sharktech
|
|
72
|
+
63023, // GTHost
|
|
73
|
+
62240, // Clouvider
|
|
74
|
+
207137, // PacketHub
|
|
75
|
+
36352, // ColoCrossing
|
|
76
|
+
29802, // HIVELOCITY
|
|
77
|
+
174, // Cogent
|
|
78
|
+
]);
|
|
79
|
+
/** Owners whose name says hosting, cloud or VPN. */
|
|
80
|
+
const HOSTING_NAME = /\b(hosting|hoster|server|servers|cloud|data ?cent(er|re)s?|datacamp|colo|colocation|vps|dedicated|vpn|proxy|cdn|amazon|aws|azure|digitalocean|linode|akamai|ovh|hetzner|vultr|choopa|leaseweb|contabo|scaleway|oracle|alibaba|aliyun|tencent|m247|zenlayer|fastly|cloudflare|hostinger|ionos|godaddy|rackspace|softlayer|equinix|psychz|quadranet|colocrossing|hivelocity|sharktech|gthost|clouvider|packethub|nordvpn|expressvpn|surfshark|mullvad|datapacket|kamatera|upcloud|netcup|hostwinds|interserver|frantech)\b/i;
|
|
81
|
+
/** Named like a host but a consumer network. */
|
|
82
|
+
const NOT_HOSTING = new Set([16591 /* Google Fiber */]);
|
|
83
|
+
export const isHostingOwner = (asn, org) => !NOT_HOSTING.has(asn) && (HOSTING_ASNS.has(asn) || HOSTING_NAME.test(org));
|
|
84
|
+
const MASK64 = (1n << 64n) - 1n;
|
|
85
|
+
class TableBuilder {
|
|
86
|
+
v4 = [];
|
|
87
|
+
v6 = [];
|
|
88
|
+
add(start, end, value) {
|
|
89
|
+
const a = parseIp(start);
|
|
90
|
+
const b = parseIp(end);
|
|
91
|
+
if (!a || !b || a.v6 !== b.v6 || a.n > b.n)
|
|
92
|
+
return;
|
|
93
|
+
if (a.v6)
|
|
94
|
+
this.v6.push([a.n, b.n, value]);
|
|
95
|
+
else
|
|
96
|
+
this.v4.push([Number(a.n), Number(b.n), value]);
|
|
97
|
+
}
|
|
98
|
+
build() {
|
|
99
|
+
this.v4.sort((x, y) => x[0] - y[0]);
|
|
100
|
+
this.v6.sort((x, y) => (x[0] < y[0] ? -1 : x[0] > y[0] ? 1 : 0));
|
|
101
|
+
const t = {
|
|
102
|
+
v4s: Uint32Array.from(this.v4, (r) => r[0]),
|
|
103
|
+
v4e: Uint32Array.from(this.v4, (r) => r[1]),
|
|
104
|
+
v4v: Uint32Array.from(this.v4, (r) => r[2]),
|
|
105
|
+
v6s: BigUint64Array.from(this.v6, (r) => r[0] >> 64n),
|
|
106
|
+
v6sl: BigUint64Array.from(this.v6, (r) => r[0] & MASK64),
|
|
107
|
+
v6e: BigUint64Array.from(this.v6, (r) => r[1] >> 64n),
|
|
108
|
+
v6el: BigUint64Array.from(this.v6, (r) => r[1] & MASK64),
|
|
109
|
+
v6v: Uint32Array.from(this.v6, (r) => r[2]),
|
|
110
|
+
};
|
|
111
|
+
this.v4 = [];
|
|
112
|
+
this.v6 = [];
|
|
113
|
+
return t;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** The value of the range holding `ip`, or -1. */
|
|
117
|
+
const find = (t, ip) => {
|
|
118
|
+
const a = parseIp(ip);
|
|
119
|
+
if (!a)
|
|
120
|
+
return -1;
|
|
121
|
+
let lo = 0;
|
|
122
|
+
let hi = (a.v6 ? t.v6v.length : t.v4v.length) - 1;
|
|
123
|
+
let at = -1;
|
|
124
|
+
if (!a.v6) {
|
|
125
|
+
const n = Number(a.n);
|
|
126
|
+
while (lo <= hi) {
|
|
127
|
+
const mid = (lo + hi) >> 1;
|
|
128
|
+
if (t.v4s[mid] <= n) {
|
|
129
|
+
at = mid;
|
|
130
|
+
lo = mid + 1;
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
hi = mid - 1;
|
|
134
|
+
}
|
|
135
|
+
return at >= 0 && n <= t.v4e[at] ? t.v4v[at] : -1;
|
|
136
|
+
}
|
|
137
|
+
const start = (i) => (t.v6s[i] << 64n) | t.v6sl[i];
|
|
138
|
+
while (lo <= hi) {
|
|
139
|
+
const mid = (lo + hi) >> 1;
|
|
140
|
+
if (start(mid) <= a.n) {
|
|
141
|
+
at = mid;
|
|
142
|
+
lo = mid + 1;
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
hi = mid - 1;
|
|
146
|
+
}
|
|
147
|
+
if (at < 0)
|
|
148
|
+
return -1;
|
|
149
|
+
const end = (t.v6e[at] << 64n) | t.v6el[at];
|
|
150
|
+
return a.n <= end ? t.v6v[at] : -1;
|
|
151
|
+
};
|
|
152
|
+
/** `a,b,"c, d"` → [a, b, 'c, d']. Enough CSV for DB-IP's files. */
|
|
153
|
+
export const csvFields = (line) => {
|
|
154
|
+
const out = [];
|
|
155
|
+
let cur = '';
|
|
156
|
+
let quoted = false;
|
|
157
|
+
for (let i = 0; i < line.length; i++) {
|
|
158
|
+
const ch = line[i];
|
|
159
|
+
if (quoted) {
|
|
160
|
+
if (ch === '"' && line[i + 1] === '"') {
|
|
161
|
+
cur += '"';
|
|
162
|
+
i++;
|
|
163
|
+
}
|
|
164
|
+
else if (ch === '"')
|
|
165
|
+
quoted = false;
|
|
166
|
+
else
|
|
167
|
+
cur += ch;
|
|
168
|
+
}
|
|
169
|
+
else if (ch === '"')
|
|
170
|
+
quoted = true;
|
|
171
|
+
else if (ch === ',') {
|
|
172
|
+
out.push(cur);
|
|
173
|
+
cur = '';
|
|
174
|
+
}
|
|
175
|
+
else
|
|
176
|
+
cur += ch;
|
|
177
|
+
}
|
|
178
|
+
out.push(cur);
|
|
179
|
+
return out;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* A file's lines - and an error at the end if the file could not be read to
|
|
183
|
+
* its end: a gzip cut short throws here, rather than reading as a short file
|
|
184
|
+
* (总线程's review of 0.77.1, P3).
|
|
185
|
+
*/
|
|
186
|
+
export async function* fileLines(file, gzip = file.endsWith('.gz')) {
|
|
187
|
+
const src = createReadStream(file);
|
|
188
|
+
const input = gzip ? src.pipe(createGunzip()) : src;
|
|
189
|
+
const state = { failure: null };
|
|
190
|
+
const rl = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
|
|
191
|
+
const onError = (err) => {
|
|
192
|
+
state.failure = err;
|
|
193
|
+
rl.close();
|
|
194
|
+
};
|
|
195
|
+
src.on('error', onError);
|
|
196
|
+
if (input !== src)
|
|
197
|
+
input.on('error', onError);
|
|
198
|
+
for await (const line of rl) {
|
|
199
|
+
if (state.failure)
|
|
200
|
+
break;
|
|
201
|
+
yield line;
|
|
202
|
+
}
|
|
203
|
+
if (state.failure)
|
|
204
|
+
throw state.failure;
|
|
205
|
+
}
|
|
206
|
+
/** A file is taken only whole, and only if almost every line is a range (1 in 1,000 may not be). */
|
|
207
|
+
const sound = (rows, bad) => rows > 0 && bad <= Math.floor(rows / 1_000);
|
|
208
|
+
/** The month files of `prefix` in `dir`, newest first. */
|
|
209
|
+
export const monthFiles = (dir, prefix) => {
|
|
210
|
+
if (!existsSync(dir))
|
|
211
|
+
return [];
|
|
212
|
+
const re = new RegExp(`^${prefix}-(\\d{4}-\\d{2})\\.csv(\\.gz)?$`);
|
|
213
|
+
return readdirSync(dir)
|
|
214
|
+
.filter((f) => re.test(f))
|
|
215
|
+
.sort()
|
|
216
|
+
.reverse()
|
|
217
|
+
.map((f) => join(dir, f));
|
|
218
|
+
};
|
|
219
|
+
/** The newest `<prefix>-YYYY-MM.csv(.gz)` in `dir`, or null. */
|
|
220
|
+
export const newestFile = (dir, prefix) => {
|
|
221
|
+
if (!existsSync(dir))
|
|
222
|
+
return null;
|
|
223
|
+
const re = new RegExp(`^${prefix}-(\\d{4}-\\d{2})\\.csv(\\.gz)?$`);
|
|
224
|
+
const hits = readdirSync(dir)
|
|
225
|
+
.filter((f) => re.test(f))
|
|
226
|
+
.sort();
|
|
227
|
+
const last = hits.at(-1);
|
|
228
|
+
return last ? join(dir, last) : null;
|
|
229
|
+
};
|
|
230
|
+
export const COUNTRY_PREFIX = 'dbip-country-lite';
|
|
231
|
+
export const ASN_PREFIX = 'dbip-asn-lite';
|
|
232
|
+
export class GeoDb {
|
|
233
|
+
countries;
|
|
234
|
+
codes;
|
|
235
|
+
asns;
|
|
236
|
+
hosting;
|
|
237
|
+
sources;
|
|
238
|
+
constructor(countries, codes, asns, hosting,
|
|
239
|
+
/** Which files answered - for the log line and the report footer. */
|
|
240
|
+
sources) {
|
|
241
|
+
this.countries = countries;
|
|
242
|
+
this.codes = codes;
|
|
243
|
+
this.asns = asns;
|
|
244
|
+
this.hosting = hosting;
|
|
245
|
+
this.sources = sources;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Reads the newest country and ASN files in `dir` that read whole - a file
|
|
249
|
+
* cut short or not of ranges is passed over for the month before it, so a
|
|
250
|
+
* bad download never leaves the connector with no countries (总线程's review
|
|
251
|
+
* of 0.77.1, P3). Either may be missing.
|
|
252
|
+
*/
|
|
253
|
+
static async load(dir) {
|
|
254
|
+
const sources = [];
|
|
255
|
+
let countries = null;
|
|
256
|
+
let codes = [];
|
|
257
|
+
for (const file of monthFiles(dir, COUNTRY_PREFIX)) {
|
|
258
|
+
try {
|
|
259
|
+
const index = new Map();
|
|
260
|
+
const found = [];
|
|
261
|
+
const b = new TableBuilder();
|
|
262
|
+
let rows = 0;
|
|
263
|
+
let bad = 0;
|
|
264
|
+
for await (const line of fileLines(file)) {
|
|
265
|
+
if (!line)
|
|
266
|
+
continue;
|
|
267
|
+
const [s, e, cc] = csvFields(line);
|
|
268
|
+
if (!s || !e || !cc || !/^[A-Z]{2}$/.test(cc)) {
|
|
269
|
+
bad++;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
rows++;
|
|
273
|
+
if (cc === 'ZZ')
|
|
274
|
+
continue;
|
|
275
|
+
let i = index.get(cc);
|
|
276
|
+
if (i === undefined) {
|
|
277
|
+
i = found.length;
|
|
278
|
+
found.push(cc);
|
|
279
|
+
index.set(cc, i);
|
|
280
|
+
}
|
|
281
|
+
b.add(s, e, i);
|
|
282
|
+
}
|
|
283
|
+
if (!sound(rows, bad))
|
|
284
|
+
continue;
|
|
285
|
+
countries = b.build();
|
|
286
|
+
codes = found;
|
|
287
|
+
sources.push(file.split('/').at(-1));
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
// cut short: the month before
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
let asns = null;
|
|
295
|
+
let hosting = new Set();
|
|
296
|
+
for (const file of monthFiles(dir, ASN_PREFIX)) {
|
|
297
|
+
try {
|
|
298
|
+
const b = new TableBuilder();
|
|
299
|
+
const owners = new Set();
|
|
300
|
+
let rows = 0;
|
|
301
|
+
let bad = 0;
|
|
302
|
+
for await (const line of fileLines(file)) {
|
|
303
|
+
if (!line)
|
|
304
|
+
continue;
|
|
305
|
+
const [s, e, asnText, ...org] = csvFields(line);
|
|
306
|
+
const asn = Number(asnText);
|
|
307
|
+
if (!s || !e || !Number.isInteger(asn) || asn <= 0) {
|
|
308
|
+
bad++;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
rows++;
|
|
312
|
+
if (isHostingOwner(asn, org.join(',')))
|
|
313
|
+
owners.add(asn);
|
|
314
|
+
b.add(s, e, asn);
|
|
315
|
+
}
|
|
316
|
+
if (!sound(rows, bad))
|
|
317
|
+
continue;
|
|
318
|
+
asns = b.build();
|
|
319
|
+
hosting = owners;
|
|
320
|
+
sources.push(file.split('/').at(-1));
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// cut short: the month before
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return new GeoDb(countries, codes, asns, hosting, sources);
|
|
328
|
+
}
|
|
329
|
+
/** An empty database: every answer unknown. */
|
|
330
|
+
static none() {
|
|
331
|
+
return new GeoDb(null, [], null, new Set(), []);
|
|
332
|
+
}
|
|
333
|
+
get ready() {
|
|
334
|
+
return this.countries !== null;
|
|
335
|
+
}
|
|
336
|
+
lookup(ip) {
|
|
337
|
+
if (!this.countries && !this.asns)
|
|
338
|
+
return NOTHING;
|
|
339
|
+
const c = this.countries ? find(this.countries, ip) : -1;
|
|
340
|
+
const a = this.asns ? find(this.asns, ip) : -1;
|
|
341
|
+
return {
|
|
342
|
+
cc: c >= 0 ? (this.codes[c] ?? null) : null,
|
|
343
|
+
net: a < 0 ? 'unknown' : this.hosting.has(a) ? 'hosting' : 'isp',
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=geo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../src/usage/geo.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,oDAAoD;AACpD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,mFAAmF;AACnF,6EAA6E;AAC7E,mBAAmB;AACnB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YA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E,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;YAC3C,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK;SACjE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type DailyTotals, type SeenIndex, type Tz } from './report.js';
|
|
2
|
+
import { type UsageStore } from './store.js';
|
|
3
|
+
/**
|
|
4
|
+
* When each user and signed-in shopper pseudonym was first and last seen
|
|
5
|
+
* (local days). Kept like the lines it stands for: an entry not seen for 13
|
|
6
|
+
* months is dropped.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Seen implements SeenIndex {
|
|
9
|
+
readonly users: Map<string, [string, string]>;
|
|
10
|
+
readonly shoppers: Map<string, [string, string]>;
|
|
11
|
+
static file(store: UsageStore): string;
|
|
12
|
+
static load(store: UsageStore): Promise<Seen | null>;
|
|
13
|
+
private static touch;
|
|
14
|
+
touchUser(u: string, day: string): void;
|
|
15
|
+
touchShopper(s: string, day: string): void;
|
|
16
|
+
userFirst(u: string): string | undefined;
|
|
17
|
+
shopperFirst(s: string): string | undefined;
|
|
18
|
+
save(store: UsageStore, firstKept: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const maintain: (store: UsageStore, deployment: string, now?: number, tz?: Tz) => Promise<{
|
|
21
|
+
rolled: string[];
|
|
22
|
+
pruned: string[];
|
|
23
|
+
}>;
|
|
24
|
+
/** The kept totals of `from`..`to`. */
|
|
25
|
+
export declare const readDaily: (store: UsageStore, from: string, to: string) => Promise<DailyTotals[]>;
|
|
26
|
+
//# sourceMappingURL=maintain.d.ts.map
|
|
@@ -0,0 +1 @@
|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@@ -0,0 +1,177 @@
|
|
|
1
|
+
// The daily chores: each finished day's totals into `daily/`, kept for good,
|
|
2
|
+
// then event lines older than 13 months deleted - totals first, always.
|
|
3
|
+
// Totals hold counts and tool names only - no pseudonym - so keeping them
|
|
4
|
+
// forever keeps no one.
|
|
5
|
+
//
|
|
6
|
+
// ⚠️ ONLY THE DAYS THAT NEED IT, A LINE AT A TIME (security review of 0.77.0,
|
|
7
|
+
// P1). The first version read all 13 months into the server process every six
|
|
8
|
+
// hours: a million lines held requests for 2.5 s and took 850 MB, a few million
|
|
9
|
+
// would crash it, and the restart would do it again. Now a day's totals read
|
|
10
|
+
// that day's two files - streamed, twice (report.ts ReportBuilder) - and who is
|
|
11
|
+
// new comes from `seen.json`, the day each pseudonym was first and last seen,
|
|
12
|
+
// instead of from every earlier line. A day's file is capped too (store.ts).
|
|
13
|
+
//
|
|
14
|
+
// ⚠️ A TOTAL'S DAY IS A BEIJING DAY (report.ts), and the event files are UTC
|
|
15
|
+
// days: Beijing day D is UTC files D-1 (from 16:00) and D (to 16:00). A day's
|
|
16
|
+
// totals are rewritten when either file changed after them - an import that
|
|
17
|
+
// rewrote an old day, say - but only while both files are still kept; a day
|
|
18
|
+
// whose lines are partly gone keeps the totals made when they were whole.
|
|
19
|
+
import { promises as fs } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { BEIJING, ReportBuilder, addDays, dailyTotals, dayIn, } from './report.js';
|
|
22
|
+
import { dayOf, firstKeptDay } from './store.js';
|
|
23
|
+
const mtime = async (file) => {
|
|
24
|
+
try {
|
|
25
|
+
return (await fs.stat(file)).mtimeMs;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/** Pseudonyms remembered at most - beyond it the least recently seen go. */
|
|
32
|
+
const MAX_SEEN = 500_000;
|
|
33
|
+
/**
|
|
34
|
+
* When each user and signed-in shopper pseudonym was first and last seen
|
|
35
|
+
* (local days). Kept like the lines it stands for: an entry not seen for 13
|
|
36
|
+
* months is dropped.
|
|
37
|
+
*/
|
|
38
|
+
export class Seen {
|
|
39
|
+
users = new Map();
|
|
40
|
+
shoppers = new Map();
|
|
41
|
+
static file(store) {
|
|
42
|
+
return join(store.dir, 'seen.json');
|
|
43
|
+
}
|
|
44
|
+
static async load(store) {
|
|
45
|
+
try {
|
|
46
|
+
const raw = JSON.parse(await fs.readFile(Seen.file(store), 'utf8'));
|
|
47
|
+
if (raw.v !== 1)
|
|
48
|
+
return null;
|
|
49
|
+
const s = new Seen();
|
|
50
|
+
for (const [k, v] of Object.entries(raw.users ?? {}))
|
|
51
|
+
s.users.set(k, v);
|
|
52
|
+
for (const [k, v] of Object.entries(raw.shoppers ?? {}))
|
|
53
|
+
s.shoppers.set(k, v);
|
|
54
|
+
return s;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static touch(m, id, day) {
|
|
61
|
+
const hit = m.get(id);
|
|
62
|
+
if (!hit)
|
|
63
|
+
m.set(id, [day, day]);
|
|
64
|
+
else {
|
|
65
|
+
if (day < hit[0])
|
|
66
|
+
hit[0] = day;
|
|
67
|
+
if (day > hit[1])
|
|
68
|
+
hit[1] = day;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
touchUser(u, day) {
|
|
72
|
+
Seen.touch(this.users, u, day);
|
|
73
|
+
}
|
|
74
|
+
touchShopper(s, day) {
|
|
75
|
+
Seen.touch(this.shoppers, s, day);
|
|
76
|
+
}
|
|
77
|
+
userFirst(u) {
|
|
78
|
+
return this.users.get(u)?.[0];
|
|
79
|
+
}
|
|
80
|
+
shopperFirst(s) {
|
|
81
|
+
return this.shoppers.get(s)?.[0];
|
|
82
|
+
}
|
|
83
|
+
async save(store, firstKept) {
|
|
84
|
+
const keep = (m) => {
|
|
85
|
+
const live = [...m.entries()].filter(([, [, last]]) => last >= firstKept);
|
|
86
|
+
live.sort(([, a], [, b]) => (a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0));
|
|
87
|
+
return Object.fromEntries(live.slice(0, MAX_SEEN));
|
|
88
|
+
};
|
|
89
|
+
const file = Seen.file(store);
|
|
90
|
+
await fs.mkdir(store.dir, { recursive: true, mode: 0o700 });
|
|
91
|
+
await fs.writeFile(`${file}.tmp`, JSON.stringify({ v: 1, users: keep(this.users), shoppers: keep(this.shoppers) }), { mode: 0o600 });
|
|
92
|
+
await fs.rename(`${file}.tmp`, file);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export const maintain = async (store, deployment, now = store.now(), tz = BEIJING) => {
|
|
96
|
+
const today = dayIn(now, tz);
|
|
97
|
+
const firstKept = firstKeptDay(dayOf(now));
|
|
98
|
+
const files = await store.days();
|
|
99
|
+
const changedAt = new Map();
|
|
100
|
+
for (const { day, files: list } of files) {
|
|
101
|
+
changedAt.set(day, Math.max(...(await Promise.all(list.map(mtime)))));
|
|
102
|
+
}
|
|
103
|
+
// No index yet (the first run, or it was lost): every day still whole is
|
|
104
|
+
// summed again, in order, and the index is built on the way.
|
|
105
|
+
const loaded = await Seen.load(store);
|
|
106
|
+
const seen = loaded ?? new Seen();
|
|
107
|
+
// Every finished local day any kept file touches.
|
|
108
|
+
const candidates = new Set();
|
|
109
|
+
for (const { day } of files) {
|
|
110
|
+
for (const d of [day, addDays(day, 1)])
|
|
111
|
+
if (d < today)
|
|
112
|
+
candidates.add(d);
|
|
113
|
+
}
|
|
114
|
+
const due = [];
|
|
115
|
+
for (const d of [...candidates].sort()) {
|
|
116
|
+
const written = await mtime(join(store.dailyDir, `${d}.json`));
|
|
117
|
+
const whole = addDays(d, -1) >= firstKept;
|
|
118
|
+
const changed = Math.max(changedAt.get(addDays(d, -1)) ?? 0, changedAt.get(d) ?? 0);
|
|
119
|
+
if (!written || (whole && (!loaded || changed > written)))
|
|
120
|
+
due.push(d);
|
|
121
|
+
}
|
|
122
|
+
const rolled = [];
|
|
123
|
+
for (const day of due) {
|
|
124
|
+
const b = new ReportBuilder(day, day, deployment, tz, seen);
|
|
125
|
+
for await (const e of store.read(addDays(day, -1), day))
|
|
126
|
+
b.place(e);
|
|
127
|
+
for await (const e of store.read(addDays(day, -1), day)) {
|
|
128
|
+
b.add(e);
|
|
129
|
+
if (e.d !== deployment)
|
|
130
|
+
continue;
|
|
131
|
+
const d = dayIn(e.t, tz);
|
|
132
|
+
if (d > day)
|
|
133
|
+
continue;
|
|
134
|
+
if (e.u)
|
|
135
|
+
seen.touchUser(e.u, d);
|
|
136
|
+
if (e.s && (e.step === 'ok' || e.step === 'orders'))
|
|
137
|
+
seen.touchShopper(e.s, d);
|
|
138
|
+
}
|
|
139
|
+
const totals = dailyTotals(b.build(), day);
|
|
140
|
+
if (!totals)
|
|
141
|
+
continue;
|
|
142
|
+
await fs.mkdir(store.dailyDir, { recursive: true, mode: 0o700 });
|
|
143
|
+
const file = join(store.dailyDir, `${day}.json`);
|
|
144
|
+
await fs.writeFile(`${file}.tmp`, `${JSON.stringify(totals)}\n`, { mode: 0o600 });
|
|
145
|
+
await fs.rename(`${file}.tmp`, file);
|
|
146
|
+
rolled.push(day);
|
|
147
|
+
}
|
|
148
|
+
if (due.length || !loaded)
|
|
149
|
+
await seen.save(store, firstKept);
|
|
150
|
+
const pruned = await store.prune(dayOf(now));
|
|
151
|
+
await store.measure();
|
|
152
|
+
return { rolled, pruned };
|
|
153
|
+
};
|
|
154
|
+
/** The kept totals of `from`..`to`. */
|
|
155
|
+
export const readDaily = async (store, from, to) => {
|
|
156
|
+
let names;
|
|
157
|
+
try {
|
|
158
|
+
names = await fs.readdir(store.dailyDir);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
const out = [];
|
|
164
|
+
for (const name of names.sort()) {
|
|
165
|
+
const day = name.slice(0, 10);
|
|
166
|
+
if (!/^\d{4}-\d{2}-\d{2}\.json$/.test(name) || day < from || day > to)
|
|
167
|
+
continue;
|
|
168
|
+
try {
|
|
169
|
+
out.push(JSON.parse(await fs.readFile(join(store.dailyDir, name), 'utf8')));
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// unreadable: skip
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=maintain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maintain.js","sourceRoot":"","sources":["../../src/usage/maintain.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,0EAA0E;AAC1E,wBAAwB;AACxB,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,OAAO,EAEP,aAAa,EAGb,OAAO,EACP,WAAW,EACX,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAmB,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,KAAK,GAAG,KAAK,EAAE,IAAY,EAAmB,EAAE;IACpD,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB;;;;GAIG;AACH,MAAM,OAAO,IAAI;IACN,KAAK,GAAG,IAAI,GA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AC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;YAAE,SAAS;QAChF,IAAI,CAAC;YACH,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAgB,CAAC,CAAC;QAC7F,CAAC;QAAC,MAAM,CAAC;YACP,mBAAmB;QACrB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type PlatformId } from '../source-ranges.js';
|
|
2
|
+
import type { GeoDb, NetKind } from './geo.js';
|
|
3
|
+
export type Platform = 'chatgpt' | 'claude' | 'manus' | 'muse' | 'other';
|
|
4
|
+
export declare const PLATFORMS: readonly Platform[];
|
|
5
|
+
/** A set of ranges, asked one address at a time. */
|
|
6
|
+
export declare class Ranges {
|
|
7
|
+
private readonly cidrs;
|
|
8
|
+
constructor(list: readonly string[]);
|
|
9
|
+
has(ip: string | undefined): boolean;
|
|
10
|
+
}
|
|
11
|
+
/** A platform's published outbound ranges - the allowlist's own list. */
|
|
12
|
+
export declare const rangesOf: (id: PlatformId) => Ranges;
|
|
13
|
+
/** OpenAI's published ChatGPT connector ranges: the only source a guest's address is taken from. */
|
|
14
|
+
export declare const OPENAI: Ranges;
|
|
15
|
+
export type PlatformSignals = {
|
|
16
|
+
/** What the client called itself at `initialize` (sessions.ts keeps it per session). */
|
|
17
|
+
client?: string | undefined;
|
|
18
|
+
userAgent?: string | undefined;
|
|
19
|
+
/** Whether the request carried `X-OpenAI-Session`. */
|
|
20
|
+
openaiSession?: boolean;
|
|
21
|
+
/** The address our proxy saw (server.ts `sourceOf`). */
|
|
22
|
+
peer?: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* By the marks the connector already goes by (sessions.ts CARD_HOSTS): ChatGPT's
|
|
26
|
+
* `openai-mcp` agent and its session header; claude.ai by its client name or
|
|
27
|
+
* Anthropic's ranges; Manus and Muse by name only - neither publishes an address
|
|
28
|
+
* (docs/mcp-source-allowlist.md). Self-reported, which is fine for a count.
|
|
29
|
+
* Claude Code counts as Claude; Codex is `other`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const platformOf: (s: PlatformSignals) => Platform;
|
|
32
|
+
/** A routable public address, as sent - or null. */
|
|
33
|
+
export declare const publicIp: (raw: unknown) => string | null;
|
|
34
|
+
export type Origin =
|
|
35
|
+
/** The guest's own address, for the country lookup only - never stored. */
|
|
36
|
+
{
|
|
37
|
+
kind: 'user';
|
|
38
|
+
ip: string;
|
|
39
|
+
}
|
|
40
|
+
/** A platform's data centre: its address says nothing of where the person is. */
|
|
41
|
+
| {
|
|
42
|
+
kind: 'platform';
|
|
43
|
+
}
|
|
44
|
+
/** ChatGPT, but no usable address came with it. */
|
|
45
|
+
| {
|
|
46
|
+
kind: 'unknown';
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Whose address this request carries.
|
|
50
|
+
*
|
|
51
|
+
* ⚠️ ONLY CHATGPT, AND ONLY FROM OPENAI'S OWN ADDRESSES. ChatGPT puts the person's
|
|
52
|
+
* address in the `X-Forwarded-For` it sends (first entry); every other host calls
|
|
53
|
+
* from its own machines, so its address is the platform's, not the person's -
|
|
54
|
+
* recorded as such, never as where they are (robin, 2026-11-12). A request that
|
|
55
|
+
* merely CLAIMS to be ChatGPT, from anywhere else, is `unknown`: the header is
|
|
56
|
+
* the caller's to write.
|
|
57
|
+
*
|
|
58
|
+
* `forwarded` is the X-Forwarded-For exactly as the caller sent it - the copy
|
|
59
|
+
* Caddy is asked to make (`X-Caller-Forwarded-For`, recorder.ts), because Caddy
|
|
60
|
+
* itself rewrites X-Forwarded-For to the peer it saw.
|
|
61
|
+
*/
|
|
62
|
+
export declare const originOf: (platform: Platform, peer: string | undefined, forwarded: string | undefined, openai: Pick<Ranges, "has">) => Origin;
|
|
63
|
+
export type GeoFields = {
|
|
64
|
+
g: string;
|
|
65
|
+
n?: NetKind;
|
|
66
|
+
};
|
|
67
|
+
/** The country (and network type) an event carries - looked up here, the address dropped here. */
|
|
68
|
+
export declare const geoFields: (platform: Platform, peer: string | undefined, forwarded: string | undefined, openai: Pick<Ranges, "has">, geo: Pick<GeoDb, "lookup">) => GeoFields;
|
|
69
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/usage/platform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AACzE,eAAO,MAAM,SAAS,EAAE,SAAS,QAAQ,EAAoD,CAAC;AAE9F,oDAAoD;AACpD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,IAAI,EAAE,SAAS,MAAM,EAAE;IAQnC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO;CAIrC;AAED,yEAAyE;AACzE,eAAO,MAAM,QAAQ,GAAI,IAAI,UAAU,KAAG,MACqD,CAAC;AAEhG,oGAAoG;AACpG,eAAO,MAAM,MAAM,QAAqB,CAAC;AAIzC,MAAM,MAAM,eAAe,GAAG;IAC5B,wFAAwF;IACxF,MA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