@stigmer/artifact-fetch 0.0.0-stage → 0.1.1
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/LICENSE +194 -0
- package/README.md +19 -2
- package/digest.d.ts +38 -0
- package/digest.d.ts.map +1 -0
- package/digest.js +67 -0
- package/digest.js.map +1 -0
- package/download.d.ts +35 -0
- package/download.d.ts.map +1 -0
- package/download.js +63 -0
- package/download.js.map +1 -0
- package/errors.d.ts +14 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +18 -0
- package/errors.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/package.json +34 -4
- package/retry.d.ts +35 -0
- package/retry.d.ts.map +1 -0
- package/retry.js +74 -0
- package/retry.js.map +1 -0
- package/src/digest.ts +76 -0
- package/src/download.ts +80 -0
- package/src/errors.ts +18 -0
- package/src/index.ts +23 -0
- package/src/retry.ts +88 -0
- package/src/tar.ts +290 -0
- package/src/testing.ts +82 -0
- package/tar.d.ts +79 -0
- package/tar.d.ts.map +1 -0
- package/tar.js +251 -0
- package/tar.js.map +1 -0
- package/testing.d.ts +31 -0
- package/testing.d.ts.map +1 -0
- package/testing.js +65 -0
- package/testing.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Stigmer Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
191
|
+
|
|
192
|
+
Except for the contents of the ee/ directory, which are licensed under the
|
|
193
|
+
Stigmer Enterprise License (see ee/LICENSE), everything in this repository
|
|
194
|
+
is licensed under the Apache License, Version 2.0, above.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stigmer/artifact-fetch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
How a Stigmer process fetches an artifact it did not build and runs it: the CLI installs the Temporal CLI from its GitHub release, and the runner installs the Claude engine from npm the first time a person runs an agent on Claude.
|
|
4
|
+
|
|
5
|
+
- `fetchWithRetry`: the download retry contract. A connection that resets before or during the body, a 5xx or a 429 is tried again with a doubling wait (1 s, 2 s, 4 s; four attempts); any other status is an answer; an abort is never retried.
|
|
6
|
+
- `downloadToFile`: a download streamed to a file while it is hashed, kept only when the whole body matches its expected digest. Memory stays at one chunk whatever the artifact's size.
|
|
7
|
+
- `parseShasum`, `parseIntegrity`, `sha256Digest`: the two forms a publisher states a digest in, a release's `sha256sum` line and npm's Subresource Integrity string, read into one `ExpectedDigest`.
|
|
8
|
+
- `parseTarHeader`, `extractTarEntry`, `readTar`, `extractPackageTarball`: one ustar reader. `extractTarEntry` takes one file by name from an archive in memory; `extractPackageTarball` unpacks a whole npm package as it streams, refusing any entry that is not a regular file under `package/` with a plain relative path, so a package never writes outside its directory.
|
|
9
|
+
|
|
10
|
+
## Why one library
|
|
11
|
+
|
|
12
|
+
The download contract was written for `stigmer up` (`client-apps/cli/src/local/artifact.ts`). The runner then needed the same contract for the Claude engine, a 120 to 140 MB package fetched on a person's machine, and a second copy would have let the two retry, verify and extract differently. So the contract moved here; the CLI keeps its asset naming, its cache and its exit errors, and the runner its engine home.
|
|
13
|
+
|
|
14
|
+
Every failure is an `ArtifactFetchError` whose `message` says what failed and whose `details` carry the facts (the URL, the expected and actual digest, what to do), so each consumer renders its own surface.
|
|
15
|
+
|
|
16
|
+
No runtime dependency: only Node built-ins. Published in lockstep with the other `backend/libs/ts` libraries by `scripts/publish-libs.mjs`; the CLI depends on it, and the runner links it with `file:` and bundles it into its single file.
|
|
17
|
+
|
|
18
|
+
## Verify
|
|
19
|
+
|
|
20
|
+
`npm run typecheck && npm test` here. The consumers' suites: `npm run test -w @stigmer/cli` and `make test-runner`.
|
package/digest.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The digests an artifact is checked against before a byte of it is used.
|
|
3
|
+
*
|
|
4
|
+
* Two publishers, two forms, one comparison: a release's `sha256sum`-format
|
|
5
|
+
* checksum file (Temporal's `checksums.txt`) records lowercase sha256 hex per
|
|
6
|
+
* asset, and npm records a package tarball's Subresource Integrity string
|
|
7
|
+
* (`sha512-<base64>`) in the registry and in every lockfile. Both parse to an
|
|
8
|
+
* {@link ExpectedDigest}, the algorithm and the raw digest bytes, so a
|
|
9
|
+
* download is hashed once while it streams and compared by bytes.
|
|
10
|
+
*/
|
|
11
|
+
/** The hash algorithms an expected digest may name; SHA-1, which old npm lockfiles carry, is refused. */
|
|
12
|
+
export type DigestAlgorithm = "sha256" | "sha384" | "sha512";
|
|
13
|
+
/** What an artifact's bytes must hash to. */
|
|
14
|
+
export interface ExpectedDigest {
|
|
15
|
+
readonly algorithm: DigestAlgorithm;
|
|
16
|
+
readonly digest: Buffer;
|
|
17
|
+
}
|
|
18
|
+
/** Lowercase hex sha256 of `bytes`. */
|
|
19
|
+
export declare function sha256Hex(bytes: Uint8Array): string;
|
|
20
|
+
/**
|
|
21
|
+
* The sha256 a `shasum`/`sha256sum`-format file records for `filename`, lowercase
|
|
22
|
+
* hex, or "" when the file has no entry for it. Each line is "<hex> <filename>";
|
|
23
|
+
* `sha256sum -b` writes the filename with a leading "*" (binary mode), which is
|
|
24
|
+
* not part of the name. A release-wide file lists every asset, so the match is
|
|
25
|
+
* by filename, never by position.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseShasum(content: string, filename: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* The strongest digest an SRI string names (`sha512-<base64>`, possibly several
|
|
30
|
+
* space-separated, as the W3C form allows). Throws when it names none this
|
|
31
|
+
* library accepts: an integrity it cannot check is not a pin.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseIntegrity(sri: string): ExpectedDigest;
|
|
34
|
+
/** The expected digest a sha256 hex string (a checksum file's line) names. */
|
|
35
|
+
export declare function sha256Digest(hex: string): ExpectedDigest;
|
|
36
|
+
/** A digest as its publisher writes it: hex for sha256, SRI for the others. */
|
|
37
|
+
export declare function formatDigest(expected: ExpectedDigest): string;
|
|
38
|
+
//# sourceMappingURL=digest.d.ts.map
|
package/digest.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["src/digest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,yGAAyG;AACzG,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7D,6CAA6C;AAC7C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,uCAAuC;AACvC,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOrE;AAID;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAe1D;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAExD;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAE7D"}
|
package/digest.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The digests an artifact is checked against before a byte of it is used.
|
|
3
|
+
*
|
|
4
|
+
* Two publishers, two forms, one comparison: a release's `sha256sum`-format
|
|
5
|
+
* checksum file (Temporal's `checksums.txt`) records lowercase sha256 hex per
|
|
6
|
+
* asset, and npm records a package tarball's Subresource Integrity string
|
|
7
|
+
* (`sha512-<base64>`) in the registry and in every lockfile. Both parse to an
|
|
8
|
+
* {@link ExpectedDigest}, the algorithm and the raw digest bytes, so a
|
|
9
|
+
* download is hashed once while it streams and compared by bytes.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
/** Lowercase hex sha256 of `bytes`. */
|
|
13
|
+
export function sha256Hex(bytes) {
|
|
14
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The sha256 a `shasum`/`sha256sum`-format file records for `filename`, lowercase
|
|
18
|
+
* hex, or "" when the file has no entry for it. Each line is "<hex> <filename>";
|
|
19
|
+
* `sha256sum -b` writes the filename with a leading "*" (binary mode), which is
|
|
20
|
+
* not part of the name. A release-wide file lists every asset, so the match is
|
|
21
|
+
* by filename, never by position.
|
|
22
|
+
*/
|
|
23
|
+
export function parseShasum(content, filename) {
|
|
24
|
+
for (const line of content.split("\n")) {
|
|
25
|
+
const [hex, name] = line.trim().split(/\s+/, 2);
|
|
26
|
+
if (hex === undefined || name === undefined)
|
|
27
|
+
continue;
|
|
28
|
+
if (name.replace(/^\*/, "") === filename)
|
|
29
|
+
return hex.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
const STRENGTH = { sha256: 1, sha384: 2, sha512: 3 };
|
|
34
|
+
/**
|
|
35
|
+
* The strongest digest an SRI string names (`sha512-<base64>`, possibly several
|
|
36
|
+
* space-separated, as the W3C form allows). Throws when it names none this
|
|
37
|
+
* library accepts: an integrity it cannot check is not a pin.
|
|
38
|
+
*/
|
|
39
|
+
export function parseIntegrity(sri) {
|
|
40
|
+
let best;
|
|
41
|
+
for (const token of sri.trim().split(/\s+/)) {
|
|
42
|
+
const dash = token.indexOf("-");
|
|
43
|
+
if (dash <= 0)
|
|
44
|
+
continue;
|
|
45
|
+
const algorithm = token.slice(0, dash);
|
|
46
|
+
if (!Object.hasOwn(STRENGTH, algorithm))
|
|
47
|
+
continue;
|
|
48
|
+
// An SRI token may carry options after a `?`; the digest ends there.
|
|
49
|
+
const options = token.indexOf("?", dash);
|
|
50
|
+
const digest = Buffer.from(token.slice(dash + 1, options === -1 ? undefined : options), "base64");
|
|
51
|
+
const candidate = { algorithm: algorithm, digest };
|
|
52
|
+
if (digest.length > 0 && (best === undefined || STRENGTH[candidate.algorithm] > STRENGTH[best.algorithm]))
|
|
53
|
+
best = candidate;
|
|
54
|
+
}
|
|
55
|
+
if (best === undefined)
|
|
56
|
+
throw new Error(`integrity "${sri}" names no sha256, sha384 or sha512 digest`);
|
|
57
|
+
return best;
|
|
58
|
+
}
|
|
59
|
+
/** The expected digest a sha256 hex string (a checksum file's line) names. */
|
|
60
|
+
export function sha256Digest(hex) {
|
|
61
|
+
return { algorithm: "sha256", digest: Buffer.from(hex, "hex") };
|
|
62
|
+
}
|
|
63
|
+
/** A digest as its publisher writes it: hex for sha256, SRI for the others. */
|
|
64
|
+
export function formatDigest(expected) {
|
|
65
|
+
return expected.algorithm === "sha256" ? expected.digest.toString("hex") : `${expected.algorithm}-${expected.digest.toString("base64")}`;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=digest.js.map
|
package/digest.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.js","sourceRoot":"","sources":["src/digest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,uCAAuC;AACvC,MAAM,UAAU,SAAS,CAAC,KAAiB;IACzC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,QAAgB;IAC3D,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAChD,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;YAAE,SAAS;QACtD,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK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IAC9H,CAAC;IACD,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,cAAc,GAAG,4CAA4C,CAAC,CAAC;IACvG,OAAO,IAAI,CAAC;AACd,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;AAClE,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,YAAY,CAAC,QAAwB;IACnD,OAAO,QAAQ,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC3I,CAAC"}
|
package/download.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A verified download streamed to a file.
|
|
3
|
+
*
|
|
4
|
+
* The response body is written to `dest` while it is hashed, so an artifact
|
|
5
|
+
* of any size costs one buffer of memory, and the file is only handed back
|
|
6
|
+
* once the whole body matched its expected digest. A mismatch is an answer,
|
|
7
|
+
* not a blip: the file is removed and the download is refused without a
|
|
8
|
+
* retry. Every other failure (the retry contract in `retry.ts` given up, an
|
|
9
|
+
* abort) also removes the file, so `dest` exists afterwards exactly when it
|
|
10
|
+
* holds the verified bytes.
|
|
11
|
+
*/
|
|
12
|
+
import { type ExpectedDigest } from "./digest.js";
|
|
13
|
+
export interface DownloadToFileOptions {
|
|
14
|
+
/** The artifact's URL. */
|
|
15
|
+
readonly url: string;
|
|
16
|
+
/** The file the verified bytes are written to; replaced when it exists. */
|
|
17
|
+
readonly dest: string;
|
|
18
|
+
/** What the whole body must hash to. */
|
|
19
|
+
readonly expected: ExpectedDigest;
|
|
20
|
+
/** The artifact's name in errors ("Claude engine", "Temporal CLI"). */
|
|
21
|
+
readonly label: string;
|
|
22
|
+
/** Stops the download; the file is removed and the signal's reason thrown. */
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
/** Called after every chunk with the bytes received so far in this attempt and the advertised length, when the server sent one. */
|
|
25
|
+
readonly onProgress?: (received: number, total: number | undefined) => void;
|
|
26
|
+
/** Override the fetch implementation (tests). */
|
|
27
|
+
readonly fetchImpl?: typeof fetch;
|
|
28
|
+
/** Override the wait between download attempts (tests). */
|
|
29
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Download `url` to `dest`, verified against `expected`; resolves with the byte count. */
|
|
32
|
+
export declare function downloadToFile(options: DownloadToFileOptions): Promise<{
|
|
33
|
+
readonly bytes: number;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["src/download.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,WAAW,qBAAqB;IACpC,0BAA0B;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,uEAAuE;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,mIAAmI;IACnI,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC5E,iDAAiD;IACjD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAClC,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,2FAA2F;AAC3F,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgBxG"}
|
package/download.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A verified download streamed to a file.
|
|
3
|
+
*
|
|
4
|
+
* The response body is written to `dest` while it is hashed, so an artifact
|
|
5
|
+
* of any size costs one buffer of memory, and the file is only handed back
|
|
6
|
+
* once the whole body matched its expected digest. A mismatch is an answer,
|
|
7
|
+
* not a blip: the file is removed and the download is refused without a
|
|
8
|
+
* retry. Every other failure (the retry contract in `retry.ts` given up, an
|
|
9
|
+
* abort) also removes the file, so `dest` exists afterwards exactly when it
|
|
10
|
+
* holds the verified bytes.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { open, rm } from "node:fs/promises";
|
|
14
|
+
import { ArtifactFetchError } from "./errors.js";
|
|
15
|
+
import { formatDigest } from "./digest.js";
|
|
16
|
+
import { fetchWithRetry, network } from "./retry.js";
|
|
17
|
+
/** Download `url` to `dest`, verified against `expected`; resolves with the byte count. */
|
|
18
|
+
export async function downloadToFile(options) {
|
|
19
|
+
const net = network({ fetchImpl: options.fetchImpl, sleep: options.sleep });
|
|
20
|
+
try {
|
|
21
|
+
const { bytes, actual } = await fetchWithRetry(net, options.url, options.label, (res) => writeBody(res, options), options.signal);
|
|
22
|
+
if (!actual.equals(options.expected.digest)) {
|
|
23
|
+
throw new ArtifactFetchError(`${options.label} checksum mismatch — refusing to use the download`, [
|
|
24
|
+
`expected: ${formatDigest(options.expected)}`,
|
|
25
|
+
`actual: ${formatDigest({ algorithm: options.expected.algorithm, digest: actual })}`,
|
|
26
|
+
`archive: ${options.url}`,
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
return { bytes };
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
await rm(options.dest, { force: true });
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// One attempt's body: truncate the file, then hash and write each chunk in
|
|
37
|
+
// order. A body that ends early throws, and the retry contract decides.
|
|
38
|
+
async function writeBody(res, options) {
|
|
39
|
+
if (res.body === null)
|
|
40
|
+
throw new Error("the response has no body");
|
|
41
|
+
// A length names the bytes on the wire; fetch decodes a content-encoding
|
|
42
|
+
// before the body reaches here, so only an unencoded length counts.
|
|
43
|
+
const advertised = res.headers.get("content-encoding") === null ? Number(res.headers.get("content-length")) : Number.NaN;
|
|
44
|
+
const total = Number.isFinite(advertised) && advertised > 0 ? advertised : undefined;
|
|
45
|
+
const hash = createHash(options.expected.algorithm);
|
|
46
|
+
const file = await open(options.dest, "w", 0o644);
|
|
47
|
+
let bytes = 0;
|
|
48
|
+
try {
|
|
49
|
+
for await (const chunk of res.body) {
|
|
50
|
+
hash.update(chunk);
|
|
51
|
+
await file.write(chunk);
|
|
52
|
+
bytes += chunk.byteLength;
|
|
53
|
+
options.onProgress?.(bytes, total);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await file.close();
|
|
58
|
+
}
|
|
59
|
+
if (total !== undefined && bytes !== total)
|
|
60
|
+
throw new Error(`the body ended after ${bytes} of ${total} bytes`);
|
|
61
|
+
return { bytes, actual: hash.digest() };
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=download.js.map
|
package/download.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["src/download.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO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rB,CAAC;IACD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,OAAO,KAAK,QAAQ,CAAC,CAAC;IAC/G,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;AAC1C,CAAC"}
|
package/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error this library throws for a fetch that did not produce a
|
|
3
|
+
* verified artifact: a persistent network failure, an HTTP status that is an
|
|
4
|
+
* answer, a digest mismatch, or an archive that breaks the extraction rules.
|
|
5
|
+
* `message` says what failed and `details` the facts behind it (the URL, the
|
|
6
|
+
* expected and actual digest, what to do), one line each, so a consumer
|
|
7
|
+
* renders its own surface (the CLI's exit error, the runner's turn failure)
|
|
8
|
+
* without parsing the message.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ArtifactFetchError extends Error {
|
|
11
|
+
readonly details: readonly string[];
|
|
12
|
+
constructor(message: string, details?: readonly string[]);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/errors.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,SAAS,MAAM,EAAO;CAK7D"}
|
package/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error this library throws for a fetch that did not produce a
|
|
3
|
+
* verified artifact: a persistent network failure, an HTTP status that is an
|
|
4
|
+
* answer, a digest mismatch, or an archive that breaks the extraction rules.
|
|
5
|
+
* `message` says what failed and `details` the facts behind it (the URL, the
|
|
6
|
+
* expected and actual digest, what to do), one line each, so a consumer
|
|
7
|
+
* renders its own surface (the CLI's exit error, the runner's turn failure)
|
|
8
|
+
* without parsing the message.
|
|
9
|
+
*/
|
|
10
|
+
export class ArtifactFetchError extends Error {
|
|
11
|
+
details;
|
|
12
|
+
constructor(message, details = []) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "ArtifactFetchError";
|
|
15
|
+
this.details = details;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.js.map
|
package/errors.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,OAAO,CAAoB;IAEpC,YAAY,OAAe,EAAE,UAA6B,EAAE;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ArtifactFetchError } from "./errors.js";
|
|
2
|
+
export { DOWNLOAD_ATTEMPTS, DOWNLOAD_RETRY_BASE_DELAY_MS, describeFailure, fetchWithRetry, network, type Network } from "./retry.js";
|
|
3
|
+
export { formatDigest, parseIntegrity, parseShasum, sha256Digest, sha256Hex, type DigestAlgorithm, type ExpectedDigest, } from "./digest.js";
|
|
4
|
+
export { downloadToFile, type DownloadToFileOptions } from "./download.js";
|
|
5
|
+
export { TAR_BLOCK, extractPackageTarball, extractTarEntry, parseTarHeader, readTar, type ExtractPackageOptions, type TarEntry, type TarEntryKind, type TarHeader, } from "./tar.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AACrI,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EACL,SAAS,EACT,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,OAAO,EACP,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ArtifactFetchError } from "./errors.js";
|
|
2
|
+
export { DOWNLOAD_ATTEMPTS, DOWNLOAD_RETRY_BASE_DELAY_MS, describeFailure, fetchWithRetry, network } from "./retry.js";
|
|
3
|
+
export { formatDigest, parseIntegrity, parseShasum, sha256Digest, sha256Hex, } from "./digest.js";
|
|
4
|
+
export { downloadToFile } from "./download.js";
|
|
5
|
+
export { TAR_BLOCK, extractPackageTarball, extractTarEntry, parseTarHeader, readTar, } from "./tar.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAgB,MAAM,YAAY,CAAC;AACrI,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,GAGV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAA8B,MAAM,eAAe,CAAC;AAC3E,OAAO,EACL,SAAS,EACT,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,OAAO,GAKR,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stigmer/artifact-fetch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "How Stigmer's TypeScript processes fetch a published artifact they did not build: the download retry contract, the digest every download is checked against (a release's sha256 checksum line or npm's SRI integrity) before a byte is extracted, and one ustar reader, over a buffer or a stream, that extracts one entry by name or a whole npm package under strict path rules",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/stigmer/stigmer.git",
|
|
11
|
+
"directory": "backend/libs/ts/artifact-fetch"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^22.13.0 || >=23.4.0"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"stigmer",
|
|
18
|
+
"download",
|
|
19
|
+
"integrity",
|
|
20
|
+
"tar"
|
|
21
|
+
],
|
|
22
|
+
"main": "./index.js",
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./index.d.ts",
|
|
27
|
+
"import": "./index.js",
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
},
|
|
30
|
+
"./testing": {
|
|
31
|
+
"types": "./testing.d.ts",
|
|
32
|
+
"import": "./testing.js",
|
|
33
|
+
"default": "./testing.js"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/retry.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The download retry contract every artifact fetch runs under.
|
|
3
|
+
*
|
|
4
|
+
* A connection that resets before or during the body, a 5xx or a 429 is tried
|
|
5
|
+
* again with a doubling wait, so a network blip does not fail a first
|
|
6
|
+
* `stigmer up`, a CI lane, an image build or a person's first Claude turn. Any
|
|
7
|
+
* other HTTP status is an answer and fails at once. The body is read inside
|
|
8
|
+
* the attempt, so a connection that drops after the headers is as transient as
|
|
9
|
+
* one that never connects. An abort is never retried: the caller asked to
|
|
10
|
+
* stop.
|
|
11
|
+
*/
|
|
12
|
+
/** Attempts per download before a transient failure is reported. */
|
|
13
|
+
export declare const DOWNLOAD_ATTEMPTS = 4;
|
|
14
|
+
/** The wait before the second attempt; it doubles before each later one (1 s, 2 s, 4 s). */
|
|
15
|
+
export declare const DOWNLOAD_RETRY_BASE_DELAY_MS = 1000;
|
|
16
|
+
/** The network a download runs over: the fetch it calls and the wait between attempts. */
|
|
17
|
+
export interface Network {
|
|
18
|
+
readonly fetch: typeof fetch;
|
|
19
|
+
readonly sleep: (ms: number) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/** The process's network, with either half replaced (tests). */
|
|
22
|
+
export declare function network(overrides?: {
|
|
23
|
+
readonly fetchImpl?: typeof fetch;
|
|
24
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
25
|
+
}): Network;
|
|
26
|
+
/**
|
|
27
|
+
* One download of `url`, retried by the contract above, with `read` consuming
|
|
28
|
+
* the response inside each attempt. `label` names the artifact in the error.
|
|
29
|
+
* `signal`, when given, is passed to the fetch; once it aborts, its reason is
|
|
30
|
+
* thrown as is, never retried and never wrapped.
|
|
31
|
+
*/
|
|
32
|
+
export declare function fetchWithRetry<T>(net: Network, url: string, label: string, read: (res: Response) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
33
|
+
/** An error as one line, with Node fetch's socket error behind "fetch failed" appended. */
|
|
34
|
+
export declare function describeFailure(err: unknown): string;
|
|
35
|
+
//# sourceMappingURL=retry.d.ts.map
|
package/retry.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,4FAA4F;AAC5F,eAAO,MAAM,4BAA4B,OAAQ,CAAC;AAElD,0FAA0F;AAC1F,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,SAAS,GAAE;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,GAAG,OAAO,CAEtI;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EACnC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAgCZ;AAOD,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAGpD"}
|