@curless/hotel-storefront 0.89.0 → 0.91.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/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/usage/bookings-import.d.ts.map +1 -1
- package/dist/usage/bookings-import.js +1 -2
- package/dist/usage/bookings-import.js.map +1 -1
- package/dist/usage/boot.d.ts +1 -1
- package/dist/usage/boot.d.ts.map +1 -1
- package/dist/usage/boot.js +17 -68
- package/dist/usage/boot.js.map +1 -1
- package/dist/usage/platform.d.ts +1 -1
- package/dist/usage/platform.d.ts.map +1 -1
- package/dist/usage/platform.js.map +1 -1
- package/dist/usage/recorder.d.ts +1 -3
- package/dist/usage/recorder.d.ts.map +1 -1
- package/dist/usage/recorder.js.map +1 -1
- package/dist/usage/shadow-import.d.ts +1 -1
- package/dist/usage/shadow-import.d.ts.map +1 -1
- package/dist/usage/shadow-import.js +1 -1
- package/dist/usage/shadow-import.js.map +1 -1
- package/dist/usage-cli.js +7 -8
- package/dist/usage-cli.js.map +1 -1
- package/package.json +7 -5
- package/dist/usage/geo.d.ts +0 -88
- package/dist/usage/geo.d.ts.map +0 -1
- package/dist/usage/geo.js +0 -396
- package/dist/usage/geo.js.map +0 -1
- package/dist/usage/maintain.d.ts +0 -26
- package/dist/usage/maintain.d.ts.map +0 -1
- package/dist/usage/maintain.js +0 -177
- package/dist/usage/maintain.js.map +0 -1
- package/dist/usage/pseudonym.d.ts +0 -28
- package/dist/usage/pseudonym.d.ts.map +0 -1
- package/dist/usage/pseudonym.js +0 -73
- package/dist/usage/pseudonym.js.map +0 -1
- package/dist/usage/range.d.ts +0 -18
- package/dist/usage/range.d.ts.map +0 -1
- package/dist/usage/range.js +0 -97
- package/dist/usage/range.js.map +0 -1
- package/dist/usage/report.d.ts +0 -258
- package/dist/usage/report.d.ts.map +0 -1
- package/dist/usage/report.js +0 -862
- package/dist/usage/report.js.map +0 -1
- package/dist/usage/store.d.ts +0 -258
- package/dist/usage/store.d.ts.map +0 -1
- package/dist/usage/store.js +0 -475
- package/dist/usage/store.js.map +0 -1
package/dist/usage/geo.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Readable } from 'node:stream';
|
|
2
|
-
/** An address as the tables want it - the package's own parser (cidr.ts), IPv4-mapped IPv6 read as IPv4. */
|
|
3
|
-
export declare const parseIp: (ip: string) => {
|
|
4
|
-
v6: boolean;
|
|
5
|
-
n: bigint;
|
|
6
|
-
} | null;
|
|
7
|
-
export type NetKind = 'isp' | 'hosting' | 'unknown';
|
|
8
|
-
export type GeoAnswer = {
|
|
9
|
-
cc: string | null;
|
|
10
|
-
net: NetKind;
|
|
11
|
-
};
|
|
12
|
-
/** Clouds, hosts, CDNs and VPN operators, by AS number. */
|
|
13
|
-
export declare const HOSTING_ASNS: ReadonlySet<number>;
|
|
14
|
-
export declare const isHostingOwner: (asn: number, org: string) => boolean;
|
|
15
|
-
/** An address range: both ends addresses, of one family, in order. */
|
|
16
|
-
export type IpRange = {
|
|
17
|
-
v6: boolean;
|
|
18
|
-
a: bigint;
|
|
19
|
-
b: bigint;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* ⚠️ A ROW IS A RANGE ONLY IF BOTH ENDS ARE ADDRESSES (总线程 11-13, shopify
|
|
23
|
-
* 0.77.3 P3-6 carried over): of one family (v4 or v6), start not after end.
|
|
24
|
-
* Anything else is a bad line, not a row - or a file of `a,b,US` would pass
|
|
25
|
-
* for whole and hide last month's.
|
|
26
|
-
*/
|
|
27
|
-
export declare const rangeOf: (start: string | undefined, end: string | undefined) => IpRange | null;
|
|
28
|
-
/** `a,b,"c, d"` → [a, b, 'c, d']. Enough CSV for DB-IP's files. */
|
|
29
|
-
export declare const csvFields: (line: string) => string[];
|
|
30
|
-
/**
|
|
31
|
-
* What a country or ASN file may unzip to. DB-IP's own are about 40 MB and a
|
|
32
|
-
* million lines, the longest line under 200 bytes; past these a file is not
|
|
33
|
-
* one of them - a gzip that unzips to a gigabyte, or to one line that never
|
|
34
|
-
* ends, would otherwise be read into the connector whole (总线程 11-13, shopify
|
|
35
|
-
* 0.77.3 P3-4 carried over).
|
|
36
|
-
*
|
|
37
|
-
* ⚠️ LINES, NOT BYTES, ARE WHAT A LOAD COSTS (shopify 0.77.4, P3): 5 million
|
|
38
|
-
* IPv6 ranges that passed every check (212 MB unzipped) took the heap to about
|
|
39
|
-
* 750 MB for 16 s, once a day. Twice the real file's lines is the most it takes.
|
|
40
|
-
*/
|
|
41
|
-
export declare const FILE_LIMITS: {
|
|
42
|
-
bytes: number;
|
|
43
|
-
line: number;
|
|
44
|
-
lines: number;
|
|
45
|
-
};
|
|
46
|
-
export type FileLimits = typeof FILE_LIMITS;
|
|
47
|
-
/**
|
|
48
|
-
* A file's lines - and an error at the end if the file could not be read to
|
|
49
|
-
* its end: a gzip cut short throws here, rather than reading as a short file
|
|
50
|
-
* (总线程's review of 0.77.1, P3); so does one past FILE_LIMITS.
|
|
51
|
-
*
|
|
52
|
-
* ⚠️ THE FILE IS CLOSED HOWEVER IT ENDS (总线程 11-13, shopify 0.77.3 P3-5
|
|
53
|
-
* carried over): a gzip that fails midway left its file open - one descriptor
|
|
54
|
-
* a day, from the daily check, for as long as the bad file stayed.
|
|
55
|
-
*/
|
|
56
|
-
export declare function fileLines(file: string, opts?: {
|
|
57
|
-
gzip?: boolean;
|
|
58
|
-
limits?: Partial<FileLimits>;
|
|
59
|
-
/** Tests: the stream the file is read from. */
|
|
60
|
-
open?: (file: string) => Readable;
|
|
61
|
-
}): AsyncGenerator<string>;
|
|
62
|
-
/** The month files of `prefix` in `dir`, newest first. */
|
|
63
|
-
export declare const monthFiles: (dir: string, prefix: string) => string[];
|
|
64
|
-
/** The newest `<prefix>-YYYY-MM.csv(.gz)` in `dir`, or null. */
|
|
65
|
-
export declare const newestFile: (dir: string, prefix: string) => string | null;
|
|
66
|
-
export declare const COUNTRY_PREFIX = "dbip-country-lite";
|
|
67
|
-
export declare const ASN_PREFIX = "dbip-asn-lite";
|
|
68
|
-
export declare class GeoDb {
|
|
69
|
-
private readonly countries;
|
|
70
|
-
private readonly codes;
|
|
71
|
-
private readonly asns;
|
|
72
|
-
private readonly hosting;
|
|
73
|
-
/** Which files answered - for the log line and the report footer. */
|
|
74
|
-
readonly sources: string[];
|
|
75
|
-
private constructor();
|
|
76
|
-
/**
|
|
77
|
-
* Reads the newest country and ASN files in `dir` that read whole - a file
|
|
78
|
-
* cut short or not of ranges is passed over for the month before it, so a
|
|
79
|
-
* bad download never leaves the connector with no countries (总线程's review
|
|
80
|
-
* of 0.77.1, P3). Either may be missing.
|
|
81
|
-
*/
|
|
82
|
-
static load(dir: string): Promise<GeoDb>;
|
|
83
|
-
/** An empty database: every answer unknown. */
|
|
84
|
-
static none(): GeoDb;
|
|
85
|
-
get ready(): boolean;
|
|
86
|
-
lookup(ip: string): GeoAnswer;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=geo.d.ts.map
|
package/dist/usage/geo.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../../src/usage/geo.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,4GAA4G;AAC5G,eAAO,MAAM,OAAO,GAAI,IAAI,MAAM,KAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAGjE,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,CAAC;AACpD,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC;AAI5D,2DAA2D;AAC3D,eAAO,MAAM,YAAY,EAAE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;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE;IAN5B,OAAO;IASP;;;;;OAKG;WACU,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAuE9C,+CAA+C;IAC/C,MAAM,CAAC,IAAI,IAAI,KAAK;IAIpB,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS;CAS9B"}
|
package/dist/usage/geo.js
DELETED
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
// Copied from @curless/shopify-storefront src/usage/geo.ts (0.77.2; file reading and
|
|
2
|
-
// row checks 0.77.3 / 0.77.4) - the same
|
|
3
|
-
// files, the same answers; only the address parser is this package's own, and
|
|
4
|
-
// nothing here downloads (the hotel connectors read local files only: Huazhu's
|
|
5
|
-
// production container reaches nothing but Huazhu).
|
|
6
|
-
//
|
|
7
|
-
// Country and network type of an address, from DB-IP's free "Lite" databases
|
|
8
|
-
// (IP to Country Lite, ASN Lite - CC BY 4.0, https://db-ip.com), read from
|
|
9
|
-
// files on this machine. No address is sent anywhere to be looked up.
|
|
10
|
-
//
|
|
11
|
-
// The CSV form, because it needs no parser library and a three-line fixture
|
|
12
|
-
// tests the real loader: `start,end,CC` and `start,end,ASN,Organisation`. Kept
|
|
13
|
-
// in memory as sorted typed arrays (~30 MB for both) and searched by bisection.
|
|
14
|
-
//
|
|
15
|
-
// ⚠️ NETWORK TYPE IS AN ESTIMATE. ASN Lite names the network's owner and nothing
|
|
16
|
-
// else, so "hosting" means the owner is a cloud, hosting, CDN or VPN company we
|
|
17
|
-
// recognise - by number (HOSTING_ASNS) or by name (HOSTING_NAME) - and "isp" means
|
|
18
|
-
// it is not: home broadband and mobile mostly, but an office or a university
|
|
19
|
-
// lands there too.
|
|
20
|
-
import { createReadStream, existsSync, readdirSync } from 'node:fs';
|
|
21
|
-
import { join } from 'node:path';
|
|
22
|
-
import { StringDecoder } from 'node:string_decoder';
|
|
23
|
-
import { createGunzip } from 'node:zlib';
|
|
24
|
-
import { parseAddress } from '../cidr.js';
|
|
25
|
-
/** An address as the tables want it - the package's own parser (cidr.ts), IPv4-mapped IPv6 read as IPv4. */
|
|
26
|
-
export const parseIp = (ip) => {
|
|
27
|
-
const a = parseAddress(ip);
|
|
28
|
-
return a ? { v6: a.v === 6, n: a.n } : null;
|
|
29
|
-
};
|
|
30
|
-
const NOTHING = { cc: null, net: 'unknown' };
|
|
31
|
-
/** Clouds, hosts, CDNs and VPN operators, by AS number. */
|
|
32
|
-
export const HOSTING_ASNS = new Set([
|
|
33
|
-
16509,
|
|
34
|
-
14618,
|
|
35
|
-
8987, // Amazon
|
|
36
|
-
15169,
|
|
37
|
-
396982,
|
|
38
|
-
19527,
|
|
39
|
-
36040, // Google (not Google Fiber, 16591)
|
|
40
|
-
8075,
|
|
41
|
-
8068,
|
|
42
|
-
8069, // Microsoft
|
|
43
|
-
14061, // DigitalOcean
|
|
44
|
-
16276,
|
|
45
|
-
35540, // OVH
|
|
46
|
-
24940,
|
|
47
|
-
213230, // Hetzner
|
|
48
|
-
63949,
|
|
49
|
-
20940,
|
|
50
|
-
16625,
|
|
51
|
-
32787, // Linode / Akamai (and iCloud Private Relay)
|
|
52
|
-
20473, // Vultr / Choopa
|
|
53
|
-
31898, // Oracle
|
|
54
|
-
45102,
|
|
55
|
-
37963, // Alibaba
|
|
56
|
-
132203,
|
|
57
|
-
45090, // Tencent
|
|
58
|
-
13335,
|
|
59
|
-
209242, // Cloudflare (and WARP)
|
|
60
|
-
54113, // Fastly
|
|
61
|
-
9009, // M247
|
|
62
|
-
60068,
|
|
63
|
-
212238, // Datacamp / CDN77
|
|
64
|
-
60781,
|
|
65
|
-
28753, // Leaseweb
|
|
66
|
-
51167, // Contabo
|
|
67
|
-
12876, // Scaleway
|
|
68
|
-
8560, // IONOS
|
|
69
|
-
21859, // Zenlayer
|
|
70
|
-
40676, // Psychz
|
|
71
|
-
8100, // QuadraNet
|
|
72
|
-
46844, // Sharktech
|
|
73
|
-
63023, // GTHost
|
|
74
|
-
62240, // Clouvider
|
|
75
|
-
207137, // PacketHub
|
|
76
|
-
36352, // ColoCrossing
|
|
77
|
-
29802, // HIVELOCITY
|
|
78
|
-
174, // Cogent
|
|
79
|
-
]);
|
|
80
|
-
/** Owners whose name says hosting, cloud or VPN. */
|
|
81
|
-
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;
|
|
82
|
-
/** Named like a host but a consumer network. */
|
|
83
|
-
const NOT_HOSTING = new Set([16591 /* Google Fiber */]);
|
|
84
|
-
export const isHostingOwner = (asn, org) => !NOT_HOSTING.has(asn) && (HOSTING_ASNS.has(asn) || HOSTING_NAME.test(org));
|
|
85
|
-
const MASK64 = (1n << 64n) - 1n;
|
|
86
|
-
/**
|
|
87
|
-
* ⚠️ A ROW IS A RANGE ONLY IF BOTH ENDS ARE ADDRESSES (总线程 11-13, shopify
|
|
88
|
-
* 0.77.3 P3-6 carried over): of one family (v4 or v6), start not after end.
|
|
89
|
-
* Anything else is a bad line, not a row - or a file of `a,b,US` would pass
|
|
90
|
-
* for whole and hide last month's.
|
|
91
|
-
*/
|
|
92
|
-
export const rangeOf = (start, end) => {
|
|
93
|
-
const a = start ? parseIp(start) : null;
|
|
94
|
-
const b = end ? parseIp(end) : null;
|
|
95
|
-
if (!a || !b || a.v6 !== b.v6 || a.n > b.n)
|
|
96
|
-
return null;
|
|
97
|
-
return { v6: a.v6, a: a.n, b: b.n };
|
|
98
|
-
};
|
|
99
|
-
class TableBuilder {
|
|
100
|
-
v4 = [];
|
|
101
|
-
v6 = [];
|
|
102
|
-
add(r, value) {
|
|
103
|
-
if (r.v6)
|
|
104
|
-
this.v6.push([r.a, r.b, value]);
|
|
105
|
-
else
|
|
106
|
-
this.v4.push([Number(r.a), Number(r.b), value]);
|
|
107
|
-
}
|
|
108
|
-
build() {
|
|
109
|
-
this.v4.sort((x, y) => x[0] - y[0]);
|
|
110
|
-
this.v6.sort((x, y) => (x[0] < y[0] ? -1 : x[0] > y[0] ? 1 : 0));
|
|
111
|
-
const t = {
|
|
112
|
-
v4s: Uint32Array.from(this.v4, (r) => r[0]),
|
|
113
|
-
v4e: Uint32Array.from(this.v4, (r) => r[1]),
|
|
114
|
-
v4v: Uint32Array.from(this.v4, (r) => r[2]),
|
|
115
|
-
v6s: BigUint64Array.from(this.v6, (r) => r[0] >> 64n),
|
|
116
|
-
v6sl: BigUint64Array.from(this.v6, (r) => r[0] & MASK64),
|
|
117
|
-
v6e: BigUint64Array.from(this.v6, (r) => r[1] >> 64n),
|
|
118
|
-
v6el: BigUint64Array.from(this.v6, (r) => r[1] & MASK64),
|
|
119
|
-
v6v: Uint32Array.from(this.v6, (r) => r[2]),
|
|
120
|
-
};
|
|
121
|
-
this.v4 = [];
|
|
122
|
-
this.v6 = [];
|
|
123
|
-
return t;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/** The value of the range holding `ip`, or -1. */
|
|
127
|
-
const find = (t, ip) => {
|
|
128
|
-
const a = parseIp(ip);
|
|
129
|
-
if (!a)
|
|
130
|
-
return -1;
|
|
131
|
-
let lo = 0;
|
|
132
|
-
let hi = (a.v6 ? t.v6v.length : t.v4v.length) - 1;
|
|
133
|
-
let at = -1;
|
|
134
|
-
if (!a.v6) {
|
|
135
|
-
const n = Number(a.n);
|
|
136
|
-
while (lo <= hi) {
|
|
137
|
-
const mid = (lo + hi) >> 1;
|
|
138
|
-
if (t.v4s[mid] <= n) {
|
|
139
|
-
at = mid;
|
|
140
|
-
lo = mid + 1;
|
|
141
|
-
}
|
|
142
|
-
else
|
|
143
|
-
hi = mid - 1;
|
|
144
|
-
}
|
|
145
|
-
return at >= 0 && n <= t.v4e[at] ? t.v4v[at] : -1;
|
|
146
|
-
}
|
|
147
|
-
const start = (i) => (t.v6s[i] << 64n) | t.v6sl[i];
|
|
148
|
-
while (lo <= hi) {
|
|
149
|
-
const mid = (lo + hi) >> 1;
|
|
150
|
-
if (start(mid) <= a.n) {
|
|
151
|
-
at = mid;
|
|
152
|
-
lo = mid + 1;
|
|
153
|
-
}
|
|
154
|
-
else
|
|
155
|
-
hi = mid - 1;
|
|
156
|
-
}
|
|
157
|
-
if (at < 0)
|
|
158
|
-
return -1;
|
|
159
|
-
const end = (t.v6e[at] << 64n) | t.v6el[at];
|
|
160
|
-
return a.n <= end ? t.v6v[at] : -1;
|
|
161
|
-
};
|
|
162
|
-
/** `a,b,"c, d"` → [a, b, 'c, d']. Enough CSV for DB-IP's files. */
|
|
163
|
-
export const csvFields = (line) => {
|
|
164
|
-
const out = [];
|
|
165
|
-
let cur = '';
|
|
166
|
-
let quoted = false;
|
|
167
|
-
for (let i = 0; i < line.length; i++) {
|
|
168
|
-
const ch = line[i];
|
|
169
|
-
if (quoted) {
|
|
170
|
-
if (ch === '"' && line[i + 1] === '"') {
|
|
171
|
-
cur += '"';
|
|
172
|
-
i++;
|
|
173
|
-
}
|
|
174
|
-
else if (ch === '"')
|
|
175
|
-
quoted = false;
|
|
176
|
-
else
|
|
177
|
-
cur += ch;
|
|
178
|
-
}
|
|
179
|
-
else if (ch === '"')
|
|
180
|
-
quoted = true;
|
|
181
|
-
else if (ch === ',') {
|
|
182
|
-
out.push(cur);
|
|
183
|
-
cur = '';
|
|
184
|
-
}
|
|
185
|
-
else
|
|
186
|
-
cur += ch;
|
|
187
|
-
}
|
|
188
|
-
out.push(cur);
|
|
189
|
-
return out;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* What a country or ASN file may unzip to. DB-IP's own are about 40 MB and a
|
|
193
|
-
* million lines, the longest line under 200 bytes; past these a file is not
|
|
194
|
-
* one of them - a gzip that unzips to a gigabyte, or to one line that never
|
|
195
|
-
* ends, would otherwise be read into the connector whole (总线程 11-13, shopify
|
|
196
|
-
* 0.77.3 P3-4 carried over).
|
|
197
|
-
*
|
|
198
|
-
* ⚠️ LINES, NOT BYTES, ARE WHAT A LOAD COSTS (shopify 0.77.4, P3): 5 million
|
|
199
|
-
* IPv6 ranges that passed every check (212 MB unzipped) took the heap to about
|
|
200
|
-
* 750 MB for 16 s, once a day. Twice the real file's lines is the most it takes.
|
|
201
|
-
*/
|
|
202
|
-
export const FILE_LIMITS = { bytes: 1024 * 1024 * 1024, line: 4_096, lines: 2_000_000 };
|
|
203
|
-
/**
|
|
204
|
-
* A file's lines - and an error at the end if the file could not be read to
|
|
205
|
-
* its end: a gzip cut short throws here, rather than reading as a short file
|
|
206
|
-
* (总线程's review of 0.77.1, P3); so does one past FILE_LIMITS.
|
|
207
|
-
*
|
|
208
|
-
* ⚠️ THE FILE IS CLOSED HOWEVER IT ENDS (总线程 11-13, shopify 0.77.3 P3-5
|
|
209
|
-
* carried over): a gzip that fails midway left its file open - one descriptor
|
|
210
|
-
* a day, from the daily check, for as long as the bad file stayed.
|
|
211
|
-
*/
|
|
212
|
-
export async function* fileLines(file, opts = {}) {
|
|
213
|
-
const lim = { ...FILE_LIMITS, ...opts.limits };
|
|
214
|
-
const src = (opts.open ?? createReadStream)(file);
|
|
215
|
-
const gunzip = (opts.gzip ?? file.endsWith('.gz')) ? createGunzip() : null;
|
|
216
|
-
const input = gunzip ? src.pipe(gunzip) : src;
|
|
217
|
-
// A read error reaches the loop below through the gunzip, which `pipe` would not do.
|
|
218
|
-
if (gunzip)
|
|
219
|
-
src.on('error', (err) => gunzip.destroy(err));
|
|
220
|
-
const text = new StringDecoder('utf8');
|
|
221
|
-
let bytes = 0;
|
|
222
|
-
let lines = 0;
|
|
223
|
-
let rest = '';
|
|
224
|
-
const line = (s) => {
|
|
225
|
-
if (++lines > lim.lines)
|
|
226
|
-
throw new Error(`more than ${lim.lines} lines`);
|
|
227
|
-
return s.endsWith('\r') ? s.slice(0, -1) : s;
|
|
228
|
-
};
|
|
229
|
-
try {
|
|
230
|
-
for await (const chunk of input) {
|
|
231
|
-
bytes += chunk.length;
|
|
232
|
-
if (bytes > lim.bytes)
|
|
233
|
-
throw new Error(`more than ${lim.bytes} bytes`);
|
|
234
|
-
const parts = (rest + text.write(chunk)).split('\n');
|
|
235
|
-
rest = parts.pop() ?? '';
|
|
236
|
-
if (rest.length > lim.line)
|
|
237
|
-
throw new Error(`a line longer than ${lim.line}`);
|
|
238
|
-
for (const p of parts) {
|
|
239
|
-
if (p.length > lim.line)
|
|
240
|
-
throw new Error(`a line longer than ${lim.line}`);
|
|
241
|
-
yield line(p);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
rest += text.end();
|
|
245
|
-
if (rest)
|
|
246
|
-
yield line(rest);
|
|
247
|
-
}
|
|
248
|
-
finally {
|
|
249
|
-
src.destroy();
|
|
250
|
-
gunzip?.destroy();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/** A file is taken only whole, and only if almost every line is a range (1 in 1,000 may not be). */
|
|
254
|
-
const sound = (rows, bad) => rows > 0 && bad <= Math.floor(rows / 1_000);
|
|
255
|
-
/** The month files of `prefix` in `dir`, newest first. */
|
|
256
|
-
export const monthFiles = (dir, prefix) => {
|
|
257
|
-
if (!existsSync(dir))
|
|
258
|
-
return [];
|
|
259
|
-
const re = new RegExp(`^${prefix}-(\\d{4}-\\d{2})\\.csv(\\.gz)?$`);
|
|
260
|
-
return readdirSync(dir)
|
|
261
|
-
.filter((f) => re.test(f))
|
|
262
|
-
.sort()
|
|
263
|
-
.reverse()
|
|
264
|
-
.map((f) => join(dir, f));
|
|
265
|
-
};
|
|
266
|
-
/** The newest `<prefix>-YYYY-MM.csv(.gz)` in `dir`, or null. */
|
|
267
|
-
export const newestFile = (dir, prefix) => {
|
|
268
|
-
if (!existsSync(dir))
|
|
269
|
-
return null;
|
|
270
|
-
const re = new RegExp(`^${prefix}-(\\d{4}-\\d{2})\\.csv(\\.gz)?$`);
|
|
271
|
-
const hits = readdirSync(dir)
|
|
272
|
-
.filter((f) => re.test(f))
|
|
273
|
-
.sort();
|
|
274
|
-
const last = hits.at(-1);
|
|
275
|
-
return last ? join(dir, last) : null;
|
|
276
|
-
};
|
|
277
|
-
export const COUNTRY_PREFIX = 'dbip-country-lite';
|
|
278
|
-
export const ASN_PREFIX = 'dbip-asn-lite';
|
|
279
|
-
export class GeoDb {
|
|
280
|
-
countries;
|
|
281
|
-
codes;
|
|
282
|
-
asns;
|
|
283
|
-
hosting;
|
|
284
|
-
sources;
|
|
285
|
-
constructor(countries, codes, asns, hosting,
|
|
286
|
-
/** Which files answered - for the log line and the report footer. */
|
|
287
|
-
sources) {
|
|
288
|
-
this.countries = countries;
|
|
289
|
-
this.codes = codes;
|
|
290
|
-
this.asns = asns;
|
|
291
|
-
this.hosting = hosting;
|
|
292
|
-
this.sources = sources;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Reads the newest country and ASN files in `dir` that read whole - a file
|
|
296
|
-
* cut short or not of ranges is passed over for the month before it, so a
|
|
297
|
-
* bad download never leaves the connector with no countries (总线程's review
|
|
298
|
-
* of 0.77.1, P3). Either may be missing.
|
|
299
|
-
*/
|
|
300
|
-
static async load(dir) {
|
|
301
|
-
const sources = [];
|
|
302
|
-
let countries = null;
|
|
303
|
-
let codes = [];
|
|
304
|
-
for (const file of monthFiles(dir, COUNTRY_PREFIX)) {
|
|
305
|
-
try {
|
|
306
|
-
const index = new Map();
|
|
307
|
-
const found = [];
|
|
308
|
-
const b = new TableBuilder();
|
|
309
|
-
let rows = 0;
|
|
310
|
-
let bad = 0;
|
|
311
|
-
for await (const line of fileLines(file)) {
|
|
312
|
-
if (!line)
|
|
313
|
-
continue;
|
|
314
|
-
const [s, e, cc] = csvFields(line);
|
|
315
|
-
const r = rangeOf(s, e);
|
|
316
|
-
if (!r || !cc || !/^[A-Z]{2}$/.test(cc)) {
|
|
317
|
-
bad++;
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
rows++;
|
|
321
|
-
if (cc === 'ZZ')
|
|
322
|
-
continue;
|
|
323
|
-
let i = index.get(cc);
|
|
324
|
-
if (i === undefined) {
|
|
325
|
-
i = found.length;
|
|
326
|
-
found.push(cc);
|
|
327
|
-
index.set(cc, i);
|
|
328
|
-
}
|
|
329
|
-
b.add(r, i);
|
|
330
|
-
}
|
|
331
|
-
if (!sound(rows, bad))
|
|
332
|
-
continue;
|
|
333
|
-
countries = b.build();
|
|
334
|
-
codes = found;
|
|
335
|
-
sources.push(file.split('/').at(-1));
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
catch {
|
|
339
|
-
// cut short: the month before
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
let asns = null;
|
|
343
|
-
let hosting = new Set();
|
|
344
|
-
for (const file of monthFiles(dir, ASN_PREFIX)) {
|
|
345
|
-
try {
|
|
346
|
-
const b = new TableBuilder();
|
|
347
|
-
const owners = new Set();
|
|
348
|
-
let rows = 0;
|
|
349
|
-
let bad = 0;
|
|
350
|
-
for await (const line of fileLines(file)) {
|
|
351
|
-
if (!line)
|
|
352
|
-
continue;
|
|
353
|
-
const [s, e, asnText, ...org] = csvFields(line);
|
|
354
|
-
const asn = Number(asnText);
|
|
355
|
-
const r = rangeOf(s, e);
|
|
356
|
-
if (!r || !Number.isInteger(asn) || asn <= 0) {
|
|
357
|
-
bad++;
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
rows++;
|
|
361
|
-
if (isHostingOwner(asn, org.join(',')))
|
|
362
|
-
owners.add(asn);
|
|
363
|
-
b.add(r, asn);
|
|
364
|
-
}
|
|
365
|
-
if (!sound(rows, bad))
|
|
366
|
-
continue;
|
|
367
|
-
asns = b.build();
|
|
368
|
-
hosting = owners;
|
|
369
|
-
sources.push(file.split('/').at(-1));
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
catch {
|
|
373
|
-
// cut short: the month before
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return new GeoDb(countries, codes, asns, hosting, sources);
|
|
377
|
-
}
|
|
378
|
-
/** An empty database: every answer unknown. */
|
|
379
|
-
static none() {
|
|
380
|
-
return new GeoDb(null, [], null, new Set(), []);
|
|
381
|
-
}
|
|
382
|
-
get ready() {
|
|
383
|
-
return this.countries !== null;
|
|
384
|
-
}
|
|
385
|
-
lookup(ip) {
|
|
386
|
-
if (!this.countries && !this.asns)
|
|
387
|
-
return NOTHING;
|
|
388
|
-
const c = this.countries ? find(this.countries, ip) : -1;
|
|
389
|
-
const a = this.asns ? find(this.asns, ip) : -1;
|
|
390
|
-
return {
|
|
391
|
-
cc: c >= 0 ? (this.codes[c] ?? null) : null,
|
|
392
|
-
net: a < 0 ? 'unknown' : this.hosting.has(a) ? 'hosting' : 'isp',
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
//# sourceMappingURL=geo.js.map
|
package/dist/usage/geo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../src/usage/geo.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,yCAAyC;AACzC,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,mFAAm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26 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"maintain.d.ts","sourceRoot":"","sources":["../../src/usage/maintain.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,SAAS,EACd,KAAK,EAAE,EAIR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,UAAU,EAAuB,MAAM,YAAY,CAAC;AAalE;;;;GAIG;AACH,qBAAa,IAAK,YAAW,SAAS;IACpC,QAAQ,CAAC,KAAK,gCAAuC;IACrD,QAAQ,CAAC,QAAQ,gCAAu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