@mailwoman/core 8.4.0 → 8.5.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.
Files changed (52) hide show
  1. package/api/APIClient.ts +207 -42
  2. package/api/clock.ts +43 -0
  3. package/api/disk-storage.ts +239 -0
  4. package/api/index.ts +7 -0
  5. package/api/pacer.ts +98 -0
  6. package/api/responses.ts +227 -44
  7. package/api/retry.ts +227 -0
  8. package/api/test-clocks.ts +234 -0
  9. package/env/schema.ts +3 -0
  10. package/out/api/APIClient.d.ts +60 -8
  11. package/out/api/APIClient.d.ts.map +1 -1
  12. package/out/api/APIClient.js +149 -35
  13. package/out/api/APIClient.js.map +1 -1
  14. package/out/api/clock.d.ts +36 -0
  15. package/out/api/clock.d.ts.map +1 -0
  16. package/out/api/clock.js +27 -0
  17. package/out/api/clock.js.map +1 -0
  18. package/out/api/disk-storage.d.ts +64 -0
  19. package/out/api/disk-storage.d.ts.map +1 -0
  20. package/out/api/disk-storage.js +185 -0
  21. package/out/api/disk-storage.js.map +1 -0
  22. package/out/api/index.d.ts +3 -0
  23. package/out/api/index.d.ts.map +1 -1
  24. package/out/api/index.js +6 -0
  25. package/out/api/index.js.map +1 -1
  26. package/out/api/pacer.d.ts +68 -0
  27. package/out/api/pacer.d.ts.map +1 -0
  28. package/out/api/pacer.js +88 -0
  29. package/out/api/pacer.js.map +1 -0
  30. package/out/api/responses.d.ts +71 -2
  31. package/out/api/responses.d.ts.map +1 -1
  32. package/out/api/responses.js +160 -34
  33. package/out/api/responses.js.map +1 -1
  34. package/out/api/retry.d.ts +119 -0
  35. package/out/api/retry.d.ts.map +1 -0
  36. package/out/api/retry.js +158 -0
  37. package/out/api/retry.js.map +1 -0
  38. package/out/api/test-clocks.d.ts +87 -0
  39. package/out/api/test-clocks.d.ts.map +1 -0
  40. package/out/api/test-clocks.js +175 -0
  41. package/out/api/test-clocks.js.map +1 -0
  42. package/out/env/index.d.ts +1 -0
  43. package/out/env/index.d.ts.map +1 -1
  44. package/out/env/schema.d.ts +1 -0
  45. package/out/env/schema.d.ts.map +1 -1
  46. package/out/env/schema.js +2 -0
  47. package/out/env/schema.js.map +1 -1
  48. package/out/vitest.config.d.ts.map +1 -1
  49. package/out/vitest.config.js +2 -0
  50. package/out/vitest.config.js.map +1 -1
  51. package/package.json +18 -2
  52. package/vitest.config.ts +2 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The injectable time source every timing-sensitive part of {@linkcode APIClient} reads through.
6
+ *
7
+ * Lifted from `filer/sdk/sec-client.ts` (3b task 5) when the SEC client's bespoke pacing/retry
8
+ * machinery moved down into `@mailwoman/core/api`. Keeping the seam is the whole reason the pacing
9
+ * and backoff suites are deterministic and finish in milliseconds instead of sleeping on the wall
10
+ * clock — a rate-limit test that actually waits 100ms per grant costs 4s for a 40-call fan-out and
11
+ * is flaky under CI load; the same test against an injected clock is exact and instant.
12
+ *
13
+ * Deliberately NOT `node:timers/promises`: `core/api` reaches a browser bundle (`docs`'s
14
+ * `DashboardMap` imports `@mailwoman/cartographer`, which barrels `tiles/api.ts`, which imports
15
+ * `@mailwoman/core/api`), and webpack 5 refuses to resolve a `node:`-prefixed specifier for the
16
+ * web target. The global `setTimeout` is available on every runtime this package ships to.
17
+ */
18
+ /**
19
+ * The real-time {@linkcode ClockLike}, used whenever a caller doesn't inject one.
20
+ */
21
+ export const systemClock = {
22
+ now: () => Date.now(),
23
+ sleep: (ms) => new Promise((resolve) => {
24
+ setTimeout(resolve, ms);
25
+ }),
26
+ };
27
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../api/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAiBH;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAc;IACrC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CACb,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACxB,CAAC,CAAC;CACH,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file An on-disk `axios-cache-interceptor` storage adapter, so a client gets a durable HTTP cache by
6
+ * CONFIGURATION rather than by hand-rolling one (3b task 5).
7
+ *
8
+ * NODE ONLY, and deliberately NOT re-exported from `./index.ts`: `core/api` reaches a browser bundle
9
+ * (`docs`'s `DashboardMap` → `@mailwoman/cartographer` → `tiles/api.ts` → `@mailwoman/core/api`),
10
+ * and webpack refuses to resolve `node:fs/promises` for the web target. Import this through its own
11
+ * `@mailwoman/core/api/disk-storage` subpath.
12
+ *
13
+ * Two rules here are load-bearing, both carried over from the bespoke cache this replaces
14
+ * (`98c4dda1:filer/sdk/sec-client.ts`), both learned the hard way:
15
+ *
16
+ * 1. VALIDATE BEFORE WRITING. A response that can't be read back — an unparseable body, a
17
+ * non-finite TTL — must never reach disk. A permanently-cached entry has no self-healing path
18
+ * short of hand-deleting a hash-named file.
19
+ * 2. ATOMIC WRITE, UNIQUE TEMP NAME. Write-then-rename, with a temp name unique per write. A
20
+ * DETERMINISTIC temp name (`${final}.building`) made two clients writing one URL collide: the
21
+ * first `rename()` moved the shared temp file away and the second got a raw `ENOENT` for a
22
+ * response that had already succeeded (reproduced 6/6), and at multi-MB bodies the two writers'
23
+ * bytes interleaved into a corrupt-but-parseable entry.
24
+ */
25
+ import { type AxiosStorage, type NotEmptyStorageValue } from "axios-cache-interceptor";
26
+ import { type IRuntimeLogger } from "../logging/index.ts";
27
+ /**
28
+ * Options for {@linkcode buildDiskStorage}.
29
+ */
30
+ export interface DiskStorageOptions {
31
+ /**
32
+ * The directory cache entries live in. Created on first write (recursively).
33
+ */
34
+ directory: string;
35
+ /**
36
+ * An additional, domain-specific gate run against every entry BEFORE it is written. Return `false` (or throw) to drop
37
+ * the write; the entry is removed rather than persisted, so the next request re-fetches.
38
+ *
39
+ * This is the seam for "a 200 whose body isn't what this API is supposed to return". Some upstreams (SEC EDGAR among
40
+ * them) serve an HTML error page with a 200 status; persisting one under a permanent TTL poisons that URL forever.
41
+ * The structural checks below (serializable, finite `createdAt`/`ttl`) always run regardless.
42
+ */
43
+ validate?: (value: NotEmptyStorageValue) => boolean;
44
+ /**
45
+ * Where rejected writes and unreadable entries are reported. Defaults to a `disk-storage`-prefixed console logger.
46
+ */
47
+ logger?: IRuntimeLogger;
48
+ }
49
+ /**
50
+ * Create an on-disk {@linkcode AxiosStorage}, keyed by the SHA-256 of the interceptor's cache key (which already folds
51
+ * in method, URL, params and body), so a filename is always a fixed-length, filesystem-safe hex digest.
52
+ *
53
+ * An in-process overlay Map sits in front of the files, and it is load-bearing for two reasons:
54
+ *
55
+ * 1. `loading` markers live there INSTEAD of on disk. That keeps the interceptor's stampede guard working (a concurrent
56
+ * second request for the same key sees `loading` and waits on the first) without a file write per request, and
57
+ * without an interrupted process leaving a `loading` marker on disk forever.
58
+ * 2. A value being WRITTEN stays there until its `rename` lands. Without that, `set()` clearing the `loading` marker
59
+ * before the file exists opens a window where the key is in neither place, and a concurrent reader gets `empty` for
60
+ * a response that is already in hand — measured as 3 dispatches for 3 concurrent requests to one URL, i.e. the
61
+ * stampede guard fully defeated.
62
+ */
63
+ export declare function buildDiskStorage(options: DiskStorageOptions): AxiosStorage;
64
+ //# sourceMappingURL=disk-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disk-storage.d.ts","sourceRoot":"","sources":["../../api/disk-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,EAAE,KAAK,YAAY,EAAgB,KAAK,oBAAoB,EAAqB,MAAM,yBAAyB,CAAA;AAEvH,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGxE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,OAAO,CAAA;IACnD;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;CACvB;AA0BD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,YAAY,CA+I1E"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file An on-disk `axios-cache-interceptor` storage adapter, so a client gets a durable HTTP cache by
6
+ * CONFIGURATION rather than by hand-rolling one (3b task 5).
7
+ *
8
+ * NODE ONLY, and deliberately NOT re-exported from `./index.ts`: `core/api` reaches a browser bundle
9
+ * (`docs`'s `DashboardMap` → `@mailwoman/cartographer` → `tiles/api.ts` → `@mailwoman/core/api`),
10
+ * and webpack refuses to resolve `node:fs/promises` for the web target. Import this through its own
11
+ * `@mailwoman/core/api/disk-storage` subpath.
12
+ *
13
+ * Two rules here are load-bearing, both carried over from the bespoke cache this replaces
14
+ * (`98c4dda1:filer/sdk/sec-client.ts`), both learned the hard way:
15
+ *
16
+ * 1. VALIDATE BEFORE WRITING. A response that can't be read back — an unparseable body, a
17
+ * non-finite TTL — must never reach disk. A permanently-cached entry has no self-healing path
18
+ * short of hand-deleting a hash-named file.
19
+ * 2. ATOMIC WRITE, UNIQUE TEMP NAME. Write-then-rename, with a temp name unique per write. A
20
+ * DETERMINISTIC temp name (`${final}.building`) made two clients writing one URL collide: the
21
+ * first `rename()` moved the shared temp file away and the second got a raw `ENOENT` for a
22
+ * response that had already succeeded (reproduced 6/6), and at multi-MB bodies the two writers'
23
+ * bytes interleaved into a corrupt-but-parseable entry.
24
+ */
25
+ import { randomUUID } from "node:crypto";
26
+ import { mkdir, readFile, rename, rm, unlink, writeFile } from "node:fs/promises";
27
+ import { join } from "node:path";
28
+ import { buildStorage } from "axios-cache-interceptor";
29
+ import { ConsoleLogger } from "../logging/index.js";
30
+ import { sha256Hex } from "../utils/hash.js";
31
+ /**
32
+ * Whether a storage value is one worth persisting. `loading` is an in-flight marker with no reusable body — it belongs
33
+ * in memory (see {@linkcode buildDiskStorage}'s in-process overlay), not in a file that would outlive the process that
34
+ * wrote it and block every later request for that key.
35
+ */
36
+ function isPersistableState(value) {
37
+ return value.state !== "loading";
38
+ }
39
+ /**
40
+ * The structural half of the validate-before-write rule: an entry must survive a JSON round trip WITH ITS MEANING
41
+ * INTACT.
42
+ *
43
+ * `createdAt` and `ttl` get an explicit finite check because `JSON.stringify(Infinity)` is the string `null`, and
44
+ * `null` reads back as `0` in the interceptor's `createdAt + ttl < Date.now()` expiry test. An `Infinity` TTL — the
45
+ * obvious way to spell "cache this immutable document forever" — would therefore round-trip into an entry that is
46
+ * expired the instant it is read. Rejecting it loudly beats silently caching nothing.
47
+ */
48
+ function hasFiniteTiming(value) {
49
+ if (value.createdAt !== undefined && !Number.isFinite(value.createdAt))
50
+ return false;
51
+ return value.ttl === undefined || Number.isFinite(value.ttl);
52
+ }
53
+ /**
54
+ * Create an on-disk {@linkcode AxiosStorage}, keyed by the SHA-256 of the interceptor's cache key (which already folds
55
+ * in method, URL, params and body), so a filename is always a fixed-length, filesystem-safe hex digest.
56
+ *
57
+ * An in-process overlay Map sits in front of the files, and it is load-bearing for two reasons:
58
+ *
59
+ * 1. `loading` markers live there INSTEAD of on disk. That keeps the interceptor's stampede guard working (a concurrent
60
+ * second request for the same key sees `loading` and waits on the first) without a file write per request, and
61
+ * without an interrupted process leaving a `loading` marker on disk forever.
62
+ * 2. A value being WRITTEN stays there until its `rename` lands. Without that, `set()` clearing the `loading` marker
63
+ * before the file exists opens a window where the key is in neither place, and a concurrent reader gets `empty` for
64
+ * a response that is already in hand — measured as 3 dispatches for 3 concurrent requests to one URL, i.e. the
65
+ * stampede guard fully defeated.
66
+ */
67
+ export function buildDiskStorage(options) {
68
+ const { directory, validate } = options;
69
+ const logger = options.logger ?? ConsoleLogger.prefix("disk-storage");
70
+ /**
71
+ * Values visible to this process ahead of (or instead of) the files: `loading` markers, which are never persisted,
72
+ * and entries mid-write, which are dropped once their `rename` lands. See the function docstring.
73
+ */
74
+ const overlay = new Map();
75
+ function entryPath(key) {
76
+ return join(directory, `${sha256Hex(key)}.json`);
77
+ }
78
+ async function removeEntry(key) {
79
+ overlay.delete(key);
80
+ try {
81
+ await unlink(entryPath(key));
82
+ }
83
+ catch {
84
+ // A miss is the expected case for a key that was never persisted (or was already evicted).
85
+ }
86
+ }
87
+ /**
88
+ * Serialize `value`, or return `null` when it must not reach disk. Every rejection path is logged with the key so a
89
+ * maintainer seeing a cache that never fills has something to grep for.
90
+ */
91
+ function serializeIfValid(key, value) {
92
+ if (!hasFiniteTiming(value)) {
93
+ logger.warn(`Refusing to cache ${key}: createdAt/ttl must be finite (received ttl=${String(value.ttl)}).`);
94
+ return null;
95
+ }
96
+ try {
97
+ if (validate && !validate(value)) {
98
+ logger.warn(`Refusing to cache ${key}: rejected by the configured validate() predicate.`);
99
+ return null;
100
+ }
101
+ return JSON.stringify(value);
102
+ }
103
+ catch (error) {
104
+ logger.warn(`Refusing to cache ${key}: ${error instanceof Error ? error.message : String(error)}`);
105
+ return null;
106
+ }
107
+ }
108
+ return buildStorage({
109
+ find: async (key) => {
110
+ const pending = overlay.get(key);
111
+ if (pending)
112
+ return pending;
113
+ let raw;
114
+ try {
115
+ raw = await readFile(entryPath(key), "utf8");
116
+ }
117
+ catch {
118
+ return undefined;
119
+ }
120
+ try {
121
+ return JSON.parse(raw);
122
+ }
123
+ catch {
124
+ // A truncated or hand-edited entry is a miss, not a crash — re-fetching is always safe.
125
+ logger.warn(`Discarding an unreadable cache entry for ${key}.`);
126
+ await removeEntry(key);
127
+ return undefined;
128
+ }
129
+ },
130
+ set: async (key, value) => {
131
+ if (!isPersistableState(value)) {
132
+ overlay.set(key, value);
133
+ return;
134
+ }
135
+ const serialized = serializeIfValid(key, value);
136
+ if (serialized === null) {
137
+ // Drop any older entry too: the interceptor is telling us this key's content just changed,
138
+ // and keeping a superseded body would be worse than a miss.
139
+ await removeEntry(key);
140
+ return;
141
+ }
142
+ // Publish to the overlay BEFORE the write and clear it only once the rename has landed, so the
143
+ // key is continuously visible: the `loading` marker is replaced by the real value in the same
144
+ // synchronous step, never by a gap.
145
+ overlay.set(key, value);
146
+ const finalPath = entryPath(key);
147
+ // Unique per write — `process.pid` separates processes, `randomUUID()` separates concurrent
148
+ // writes inside one. A deterministic name here is the ENOENT/interleaving bug in the file header.
149
+ const buildingPath = `${finalPath}.${process.pid}.${randomUUID()}.building`;
150
+ try {
151
+ await mkdir(directory, { recursive: true });
152
+ await writeFile(buildingPath, serialized);
153
+ await rename(buildingPath, finalPath);
154
+ }
155
+ catch (error) {
156
+ // A CACHE WRITE IS A SIDE EFFECT OF A SUCCESSFUL REQUEST, AND A FAILED SIDE EFFECT MUST NOT
157
+ // FAIL THE REQUEST.
158
+ //
159
+ // `axios-cache-interceptor` awaits `set()` inside its response `onFulfilled`, so throwing
160
+ // from here rejects a request whose HTTP response ALREADY SUCCEEDED — the body is discarded.
161
+ // Worse, it escapes as a bare `Error`: no `status`, so `isTransientResourceError` reads it as
162
+ // FALSE and a caller following the documented contract is told never to retry. ANY
163
+ // filesystem failure does this: `EACCES` on a directory whose mode changed (reproduced with
164
+ // a `0o500` parent, which also showed three concurrent gets yielding one rejection and two
165
+ // successes for the SAME response), `EMFILE` under a concurrent crawl, a rename race, a
166
+ // transient I/O error. Not being able to cache is a cache miss.
167
+ logger.warn(`Could not persist ${key} (continuing as a cache miss): ${error instanceof Error ? error.message : String(error)}`);
168
+ // Best-effort cleanup of the temp file, if the failure came after it was created.
169
+ await unlink(buildingPath).catch(() => undefined);
170
+ }
171
+ finally {
172
+ overlay.delete(key);
173
+ }
174
+ },
175
+ remove: removeEntry,
176
+ clear: async () => {
177
+ overlay.clear();
178
+ // Recreated rather than left absent: "the cache is empty" and "the cache directory vanished"
179
+ // are different states to anything inspecting the data root, and only the first is intended.
180
+ await rm(directory, { recursive: true, force: true });
181
+ await mkdir(directory, { recursive: true });
182
+ },
183
+ });
184
+ }
185
+ //# sourceMappingURL=disk-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disk-storage.js","sourceRoot":"","sources":["../../api/disk-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAqB,YAAY,EAAgD,MAAM,yBAAyB,CAAA;AAEvH,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAyB5C;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,KAA2B;IACtD,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAA;AACjC,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,KAA2B;IACnD,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpF,OAAO,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAA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E,IAAI,EAAE,CAAC,CAAA;YACrD,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC5C,CAAC;KACD,CAAC,CAAA;AACH,CAAC"}
@@ -6,6 +6,9 @@
6
6
  * Core API utilities.
7
7
  */
8
8
  export * from "./APIClient.ts";
9
+ export * from "./clock.ts";
9
10
  export * from "./headless.ts";
11
+ export * from "./pacer.ts";
10
12
  export * from "./responses.ts";
13
+ export * from "./retry.ts";
11
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
package/out/api/index.js CHANGED
@@ -6,6 +6,12 @@
6
6
  * Core API utilities.
7
7
  */
8
8
  export * from "./APIClient.js";
9
+ export * from "./clock.js";
9
10
  export * from "./headless.js";
11
+ export * from "./pacer.js";
10
12
  export * from "./responses.js";
13
+ export * from "./retry.js";
14
+ // NOT `./disk-storage.ts` — it imports `node:fs/promises`, and this barrel reaches a browser bundle
15
+ // (docs' DashboardMap → @mailwoman/cartographer → tiles/api.ts → @mailwoman/core/api). Import it from
16
+ // its own `@mailwoman/core/api/disk-storage` subpath.
11
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAE1B,oGAAoG;AACpG,sGAAsG;AACtG,sDAAsD"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Strict minimum-interval request pacing for {@linkcode APIClient}.
6
+ *
7
+ * Lifted verbatim (modulo the SEC-specific rate clamp, which now lives at the SEC client's own call
8
+ * site) from `98c4dda1:filer/sdk/sec-client.ts`, where the design was settled over two review rounds
9
+ * and verified across eight arrival shapes — fan-out, interleaved, serial-plus-fanout, multi-burst,
10
+ * mid-refill, idle-then-burst, and a 60-call run at 50/s — under an injected clock.
11
+ */
12
+ import { type ClockLike } from "./clock.ts";
13
+ /**
14
+ * A strict-interval request pacer: grants are spaced AT LEAST `intervalMs` apart, with NO burst allowance beyond the
15
+ * very first grant. {@linkcode RequestPacer.acquire} resolves immediately for the first call after construction (or
16
+ * after any idle gap), and every call within one interval of the previous grant waits out the remainder of it.
17
+ *
18
+ * WHY NOT A TOKEN BUCKET: a token bucket with capacity C admits up to `C + rate * 1s` requests within any sliding
19
+ * one-second window — there is NO non-zero capacity that honors a FLAT rate cap, only an average one. The bucket this
20
+ * replaced started full (a one-time startup burst, by design) but ALSO refilled to full after any idle gap, so a fresh
21
+ * burst recurred every time a crawl paused and resumed — measured at 20 grants inside one 1000ms window against a 10/s
22
+ * ceiling (2x). Upstreams that publish a flat rate (SEC EDGAR's 10 req/s, verified enforced) and actively police it
23
+ * need the FLAT guarantee, at the cost of the first-call-of-a-burst latency a bucket would have avoided.
24
+ *
25
+ * FAIRNESS (deliberately not addressed): under concurrent contention (N callers racing `acquire()` in the same
26
+ * synchronous turn), grants are issued in whatever order the synchronous reservation happens to run in. This never
27
+ * affects the RATE — every grant is still exactly `intervalMs` after the last — only which specific caller waits how
28
+ * long under backlog. A caller needing FIFO fairness would need a real queue on top of this.
29
+ */
30
+ export declare class RequestPacer {
31
+ #private;
32
+ /**
33
+ * @param intervalMs Minimum milliseconds between two grants. Values `<= 0` are rejected — a zero-interval pacer would
34
+ * never actually pace, and silently accepting one would make a misconfigured caller look throttled when it isn't.
35
+ * @param clock Time source. Defaults to {@linkcode systemClock}.
36
+ */
37
+ constructor(intervalMs: number, clock?: ClockLike);
38
+ /**
39
+ * The configured minimum spacing between grants, in milliseconds.
40
+ */
41
+ get intervalMs(): number;
42
+ /**
43
+ * Resolve once this call's turn comes up: immediately for the first call (or after any idle gap), or exactly
44
+ * `intervalMs` after the previous grant otherwise.
45
+ *
46
+ * The grant time is reserved SYNCHRONOUSLY, before any `await` — `#nextGrantAt` is read AND bumped in the same
47
+ * synchronous step that computes this call's own wait. This is load-bearing, not cosmetic: moving the `#nextGrantAt`
48
+ * update to after the `await` (i.e. "compute the wait, sleep, then update state") reopens the concurrency bug this
49
+ * pacer exists to close — N callers invoked in the same synchronous turn would all read the SAME stale `#nextGrantAt`
50
+ * before any of them updates it, compute the SAME wait, and all be released together instead of one interval apart.
51
+ *
52
+ * `Math.max(#nextGrantAt, now)` is equally load-bearing: without it, a long idle gap leaves `#nextGrantAt` stuck in
53
+ * the past, and every call after the idle would compute a negative/zero wait forever (the increment-by-one-interval
54
+ * never catches up to a `now` that's run far ahead) — pacing would silently stop working after any idle period.
55
+ *
56
+ * Both are mutation-proved in `pacer.test.ts`.
57
+ *
58
+ * REAL-CLOCK CAVEAT, measured rather than assumed: the guarantee is on the CLOCK's timeline. Grant instants are
59
+ * scheduled exactly `intervalMs` apart, but the continuation that actually issues the request runs whenever the event
60
+ * loop gets to it, which on real timers is 0-2ms after the deadline. A grant that lands 1ms late shifts toward the
61
+ * following window, so a sliding-second count over the OBSERVED dispatch times reads 11 rather than 10 at a 100ms
62
+ * interval (measured 3/3 runs of a 40-call fan-out; the preceding second correspondingly holds 9, and the long-run
63
+ * rate is exactly at the cap). A caller that needs a hard sliding-window ceiling with no jitter headroom should pace
64
+ * fractionally under the published rate rather than exactly at it.
65
+ */
66
+ acquire(): Promise<void>;
67
+ }
68
+ //# sourceMappingURL=pacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.d.ts","sourceRoot":"","sources":["../../api/pacer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,YAAY,CAAA;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAY;;IAKxB;;;;OAIG;gBACS,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,SAAuB;IAa9D;;OAEG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAYrC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Strict minimum-interval request pacing for {@linkcode APIClient}.
6
+ *
7
+ * Lifted verbatim (modulo the SEC-specific rate clamp, which now lives at the SEC client's own call
8
+ * site) from `98c4dda1:filer/sdk/sec-client.ts`, where the design was settled over two review rounds
9
+ * and verified across eight arrival shapes — fan-out, interleaved, serial-plus-fanout, multi-burst,
10
+ * mid-refill, idle-then-burst, and a 60-call run at 50/s — under an injected clock.
11
+ */
12
+ import { systemClock } from "./clock.js";
13
+ /**
14
+ * A strict-interval request pacer: grants are spaced AT LEAST `intervalMs` apart, with NO burst allowance beyond the
15
+ * very first grant. {@linkcode RequestPacer.acquire} resolves immediately for the first call after construction (or
16
+ * after any idle gap), and every call within one interval of the previous grant waits out the remainder of it.
17
+ *
18
+ * WHY NOT A TOKEN BUCKET: a token bucket with capacity C admits up to `C + rate * 1s` requests within any sliding
19
+ * one-second window — there is NO non-zero capacity that honors a FLAT rate cap, only an average one. The bucket this
20
+ * replaced started full (a one-time startup burst, by design) but ALSO refilled to full after any idle gap, so a fresh
21
+ * burst recurred every time a crawl paused and resumed — measured at 20 grants inside one 1000ms window against a 10/s
22
+ * ceiling (2x). Upstreams that publish a flat rate (SEC EDGAR's 10 req/s, verified enforced) and actively police it
23
+ * need the FLAT guarantee, at the cost of the first-call-of-a-burst latency a bucket would have avoided.
24
+ *
25
+ * FAIRNESS (deliberately not addressed): under concurrent contention (N callers racing `acquire()` in the same
26
+ * synchronous turn), grants are issued in whatever order the synchronous reservation happens to run in. This never
27
+ * affects the RATE — every grant is still exactly `intervalMs` after the last — only which specific caller waits how
28
+ * long under backlog. A caller needing FIFO fairness would need a real queue on top of this.
29
+ */
30
+ export class RequestPacer {
31
+ #intervalMs;
32
+ #clock;
33
+ #nextGrantAt;
34
+ /**
35
+ * @param intervalMs Minimum milliseconds between two grants. Values `<= 0` are rejected — a zero-interval pacer would
36
+ * never actually pace, and silently accepting one would make a misconfigured caller look throttled when it isn't.
37
+ * @param clock Time source. Defaults to {@linkcode systemClock}.
38
+ */
39
+ constructor(intervalMs, clock = systemClock) {
40
+ if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
41
+ throw new RangeError(`RequestPacer: intervalMs must be a finite number greater than 0 (received ${intervalMs}). A pacer with a ` +
42
+ "zero or non-finite interval cannot enforce a rate; construct one only when you actually want pacing.");
43
+ }
44
+ this.#intervalMs = intervalMs;
45
+ this.#clock = clock;
46
+ this.#nextGrantAt = clock.now();
47
+ }
48
+ /**
49
+ * The configured minimum spacing between grants, in milliseconds.
50
+ */
51
+ get intervalMs() {
52
+ return this.#intervalMs;
53
+ }
54
+ /**
55
+ * Resolve once this call's turn comes up: immediately for the first call (or after any idle gap), or exactly
56
+ * `intervalMs` after the previous grant otherwise.
57
+ *
58
+ * The grant time is reserved SYNCHRONOUSLY, before any `await` — `#nextGrantAt` is read AND bumped in the same
59
+ * synchronous step that computes this call's own wait. This is load-bearing, not cosmetic: moving the `#nextGrantAt`
60
+ * update to after the `await` (i.e. "compute the wait, sleep, then update state") reopens the concurrency bug this
61
+ * pacer exists to close — N callers invoked in the same synchronous turn would all read the SAME stale `#nextGrantAt`
62
+ * before any of them updates it, compute the SAME wait, and all be released together instead of one interval apart.
63
+ *
64
+ * `Math.max(#nextGrantAt, now)` is equally load-bearing: without it, a long idle gap leaves `#nextGrantAt` stuck in
65
+ * the past, and every call after the idle would compute a negative/zero wait forever (the increment-by-one-interval
66
+ * never catches up to a `now` that's run far ahead) — pacing would silently stop working after any idle period.
67
+ *
68
+ * Both are mutation-proved in `pacer.test.ts`.
69
+ *
70
+ * REAL-CLOCK CAVEAT, measured rather than assumed: the guarantee is on the CLOCK's timeline. Grant instants are
71
+ * scheduled exactly `intervalMs` apart, but the continuation that actually issues the request runs whenever the event
72
+ * loop gets to it, which on real timers is 0-2ms after the deadline. A grant that lands 1ms late shifts toward the
73
+ * following window, so a sliding-second count over the OBSERVED dispatch times reads 11 rather than 10 at a 100ms
74
+ * interval (measured 3/3 runs of a 40-call fan-out; the preceding second correspondingly holds 9, and the long-run
75
+ * rate is exactly at the cap). A caller that needs a hard sliding-window ceiling with no jitter headroom should pace
76
+ * fractionally under the published rate rather than exactly at it.
77
+ */
78
+ async acquire() {
79
+ const now = this.#clock.now();
80
+ const grantAt = Math.max(this.#nextGrantAt, now);
81
+ this.#nextGrantAt = grantAt + this.#intervalMs;
82
+ const waitMs = grantAt - now;
83
+ if (waitMs > 0) {
84
+ await this.#clock.sleep(Math.ceil(waitMs));
85
+ }
86
+ }
87
+ }
88
+ //# sourceMappingURL=pacer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pacer.js","sourceRoot":"","sources":["../../api/pacer.ts"],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internal
39
39
  */
40
40
  export declare function pluckResponseData<Body>(responseContainer: ResponseContainer<Body>): ExtractResponseBodyData<Body>;
41
- export declare function checkConnectivity(connectivityURL?: URL | string): Promise<boolean>;
41
+ /**
42
+ * The `kind` component of a {@linkcode ResourceError}'s `(source, kind, reason)` URN, as produced by
43
+ * {@linkcode delegateAxiosError}. This is the axis {@linkcode isTransientResourceError} branches on, so a caller never
44
+ * has to pattern-match an error message.
45
+ */
46
+ export declare const ResourceErrorKind: {
47
+ /**
48
+ * The request never reached an HTTP response: a connect failure, a DNS failure, a timeout, or a body read that died
49
+ * mid-transfer.
50
+ */
51
+ readonly Network: "network";
52
+ /**
53
+ * An HTTP response came back and carried a failing status.
54
+ */
55
+ readonly Response: "response";
56
+ /**
57
+ * The request was rejected before (or independently of) the network — a caller-initiated cancel, a malformed config.
58
+ * Never transient: re-issuing the identical request can only fail identically.
59
+ */
60
+ readonly Request: "request";
61
+ /**
62
+ * A response arrived with a SUCCESS status, but its body could not be decoded into the requested type — the classic
63
+ * case being an upstream that serves an HTML error page under a 200.
64
+ *
65
+ * Never transient, deliberately: retrying an unchanged bad body cannot help, and a client that treated this as
66
+ * retryable would spend its whole attempt budget re-downloading the same broken payload.
67
+ */
68
+ readonly Payload: "payload";
69
+ };
70
+ /**
71
+ * The `kind` component of a {@linkcode ResourceError}'s URN.
72
+ */
73
+ export type ResourceErrorKind = (typeof ResourceErrorKind)[keyof typeof ResourceErrorKind];
74
+ /**
75
+ * The `kind` component of `error`'s URN, or `null` when it isn't a {@linkcode ResourceError} carrying one.
76
+ *
77
+ * Exposed so a caller can assert on the taxonomy directly (`kind === ResourceErrorKind.Network`) instead of splitting
78
+ * the URN — or, worse, matching on `message` prose — at the call site.
79
+ */
80
+ export declare function resourceErrorKind(error: unknown): ResourceErrorKind | null;
81
+ /**
82
+ * Whether `error` is the kind of failure a caller should REQUEUE rather than give up on — every network-class failure
83
+ * (connect, DNS, timeout, mid-transfer drop) and every transient HTTP status (408/429/5xx).
84
+ *
85
+ * This stays `true` even after a client exhausted its OWN bounded attempts: the client's ceiling is a statement about
86
+ * one call, while a caller's requeue is a new, separate attempt budget minutes or hours later. Callers branch on this
87
+ * plus {@linkcode ResourceError.status} — 404 to skip, 403 to abort — and never on message text.
88
+ */
89
+ export declare function isTransientResourceError(error: unknown): boolean;
42
90
  /**
43
91
  * Delegate Axios errors to an appropriate error handler.
44
92
  *
93
+ * ALWAYS throws — every failure past this point is a {@linkcode ResourceError} carrying a numeric `status`, a `(source,
94
+ * kind, reason)` URN on `name`, and the originating `AxiosError` on `cause`. A non-Axios error is rethrown untouched.
95
+ *
96
+ * WHAT CHANGED, measured rather than recalled — a differential against `98c4dda1` across 18 failure shapes in the exact
97
+ * `TileAPI` configuration found **16 of them changed**, not the two originally claimed:
98
+ *
99
+ * - Every RESPONSELESS failure (`ERR_NETWORK`, `ECONNREFUSED`, `ECONNRESET`, `ECONNABORTED`, `ETIMEDOUT`, `ERR_CANCELED`)
100
+ * used to collapse into a uniform 500; they now split into 503 / 504 / 400 by cause, and `ERR_CANCELED` flips from
101
+ * transient to terminal, which is the point — a caller who cancelled should not requeue.
102
+ * - Every non-401 HTTP status used to rethrow the raw `AxiosError`, so `status`-based branching (404 → skip, 403 → abort)
103
+ * had to reach into `error.response`. 401's own message and URN changed too.
104
+ *
105
+ * The earlier claim that `ECONNABORTED`/`ETIMEDOUT`/`ERR_CANCELED` RESOLVED the chain with `undefined` was wrong FOR
106
+ * EVERY SHAPE AXIOS ACTUALLY PRODUCES: the old `if (!response) throw` ran BEFORE that `switch`, and axios never
107
+ * attaches a `response` to a timeout or a cancellation, so a real one threw `axios:response:missing` 500 — a
108
+ * misclassified 500, not a `TypeError` at the caller. Note the `return` arms were not unreachable in general, only
109
+ * unreachable via axios: reaching the `switch` required a response to be PRESENT, and an error carrying both a
110
+ * `response` and `ECONNABORTED` did resolve with `undefined`. Stock adapters never pair those, but this repo's own
111
+ * `axiosLikeError(message, code, config, response)` helper builds that shape in one argument. No regression follows
112
+ * from any of this — the sole call site has no `.catch`, and every shape that rejects now also rejected before.
113
+ *
45
114
  * @internal
46
115
  */
47
- export declare function delegateAxiosError(error: unknown): Promise<unknown>;
116
+ export declare function delegateAxiosError(error: unknown): Promise<never>;
48
117
  //# sourceMappingURL=responses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../api/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACtC,IAAI,EAAE,IAAI,CAAA;CACV;AAED,MAAM,MAAM,YAAY,CAAC,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE/D;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,iBAAiB,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,CAAA;AAqBvF;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,CAAC,IAAI,IAAI,IAAI,SAAS;IACxD,IAAI,EAAE,MAAM,IAAI,CAAA;CAChB,GACE,uBAAuB,CAAC,IAAI,CAAC,GAC7B,IAAI,CAAA;AAEP;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;AAUlH,wBAAgB,iBAAiB,CAChC,eAAe,GAAE,GAAG,GAAG,MAA6D,GAClF,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA0CzE"}
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../api/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,IAAI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