@crewhaus/tool-containers 0.7.0 → 0.8.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 +201 -0
- package/NOTICE +9 -0
- package/dist/index.js +2 -0
- package/dist/lib/http.js +39 -45
- package/package.json +12 -7
- package/dist/fixtures.d.ts +0 -93
- package/dist/fixtures.js +0 -244
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CrewHaus Factory
|
|
2
|
+
Copyright 2026 Max Meier
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Max Meier
|
|
5
|
+
(operating as StudioMax — https://studiomax.io) and contributors.
|
|
6
|
+
|
|
7
|
+
The CrewHaus name and logo are trademarks of Max Meier. See
|
|
8
|
+
https://github.com/crewhaus/factory/blob/main/TRADEMARK.md for the
|
|
9
|
+
use-of-marks policy.
|
package/dist/index.js
CHANGED
|
@@ -115,6 +115,7 @@ async function fetchConfig(client, ref, digest, mediaType) {
|
|
|
115
115
|
}
|
|
116
116
|
export const containerImageInspect = buildTool({
|
|
117
117
|
name: "ContainerImageInspect",
|
|
118
|
+
operativeArgs: [{ field: "image", kind: "recipient" }],
|
|
118
119
|
description: "Resolve a container image tag to the digest it points at right now, over the OCI registry API — no daemon, no pull, no Docker. Returns the manifest digest and media type, the per-platform digest when the tag is a multi-arch index, the layer sizes, and the image config's labels, entrypoint and created time. Use it to pin a deployment to a digest, or to read an image's labels without downloading it. Pass compareTo a digest you recorded earlier and the answer says, as a boolean, whether the tag still points at it. The digest is computed from the response bytes and checked against the registry's own header rather than copied from it, so a registry cannot tell this tool that bytes are something they are not. Anonymous pulls only: a private repository is refused, with an explanation, rather than guessed at.",
|
|
119
120
|
inputSchema: z.object({
|
|
120
121
|
image: z
|
|
@@ -332,6 +333,7 @@ platformMatches = 1) {
|
|
|
332
333
|
}
|
|
333
334
|
export const containerImageTags = buildTool({
|
|
334
335
|
name: "ContainerImageTags",
|
|
336
|
+
operativeArgs: [{ field: "image", kind: "recipient" }],
|
|
335
337
|
description: "List a container repository's tags over the OCI registry API, paged, filtered by glob and sorted newest-first by semver precedence — with tags that are not versions (latest, edge, sha-9f3c1a) kept and listed after them rather than dropped or guessed at. Use it to find the newest release of an image, to check whether a version was ever published, or to see what a repository offers before pinning to one. Set withDigests to resolve each listed tag to its digest, which costs one request per tag and is capped. Anonymous pulls only; a private repository is refused rather than reported as empty.",
|
|
336
338
|
inputSchema: z.object({
|
|
337
339
|
image: z
|
package/dist/lib/http.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* closes, and it closes it at EVERY hop, not just the first.
|
|
17
17
|
*/
|
|
18
18
|
import { assertNotSsrf } from "@crewhaus/tool-fetch";
|
|
19
|
+
import { fetchRaw, readResponseBounded } from "@crewhaus/tool-safety/streams";
|
|
19
20
|
export class RegistryHttpError extends Error {
|
|
20
21
|
name = "RegistryHttpError";
|
|
21
22
|
}
|
|
@@ -32,8 +33,15 @@ function pinnedFetch(req, pinnedIp) {
|
|
|
32
33
|
const original = new URL(req.url);
|
|
33
34
|
const host = original.hostname;
|
|
34
35
|
const unbracketed = host.replace(/^\[/, "").replace(/\]$/, "");
|
|
36
|
+
// Both branches keep the body RAW (`fetchRaw`, Bun's `decompress: false`):
|
|
37
|
+
// otherwise Bun inflates a gzip, deflate, br or zstd body in native code
|
|
38
|
+
// before any reader sees a byte, and a 260 KB gzip of zeros from a
|
|
39
|
+
// registry (or the object store it redirects to) cost about 1 GB of RSS
|
|
40
|
+
// before `maxBytes` fired (C093). `readCapped` decodes it, under the cap,
|
|
41
|
+
// into the same bytes the runtime's decoder gave: a digest is still over
|
|
42
|
+
// the representation the registry sent.
|
|
35
43
|
if (pinnedIp === "" || unbracketed === pinnedIp)
|
|
36
|
-
return
|
|
44
|
+
return fetchRaw(req);
|
|
37
45
|
const pinnedUrl = new URL(original.toString());
|
|
38
46
|
pinnedUrl.hostname = pinnedIp.includes(":") ? `[${pinnedIp}]` : pinnedIp;
|
|
39
47
|
const headers = new Headers(req.headers);
|
|
@@ -45,7 +53,7 @@ function pinnedFetch(req, pinnedIp) {
|
|
|
45
53
|
signal: req.signal,
|
|
46
54
|
tls: { serverName: host },
|
|
47
55
|
};
|
|
48
|
-
return
|
|
56
|
+
return fetchRaw(pinnedUrl.toString(), init);
|
|
49
57
|
}
|
|
50
58
|
let rawFetch = pinnedFetch;
|
|
51
59
|
/** Test seam — `_setFetch(undefined)` restores the production dialer. */
|
|
@@ -102,57 +110,43 @@ export async function httpGet(url, options) {
|
|
|
102
110
|
current = next;
|
|
103
111
|
continue;
|
|
104
112
|
}
|
|
105
|
-
const bytes = await readCapped(res, options.maxBytes);
|
|
113
|
+
const bytes = await readCapped(res, options.maxBytes, options.signal);
|
|
106
114
|
return { status: res.status, headers: res.headers, bytes, url: current.toString() };
|
|
107
115
|
}
|
|
108
116
|
throw new RegistryHttpError(`registry redirected more than ${MAX_REDIRECTS} times`);
|
|
109
117
|
}
|
|
110
118
|
/**
|
|
111
|
-
* Drain a body with a hard
|
|
112
|
-
*
|
|
113
|
-
*
|
|
119
|
+
* Drain a body with a hard cap on its DECODED size, so a hostile or
|
|
120
|
+
* misconfigured registry cannot pin memory: the body arrives raw (see
|
|
121
|
+
* `pinnedFetch`), a gzip, deflate, br or zstd body is decoded here in small
|
|
122
|
+
* steps, and the decoder stops at the cap. The bytes returned are exactly
|
|
123
|
+
* the decoded body; a body past the cap, or one that cannot be decoded, is
|
|
124
|
+
* refused.
|
|
114
125
|
*/
|
|
115
|
-
async function readCapped(res, maxBytes) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (done)
|
|
125
|
-
break;
|
|
126
|
-
if (value === undefined)
|
|
127
|
-
continue;
|
|
128
|
-
total += value.byteLength;
|
|
129
|
-
if (total > maxBytes) {
|
|
130
|
-
try {
|
|
131
|
-
await reader.cancel();
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
// Already aborting.
|
|
135
|
-
}
|
|
136
|
-
throw new RegistryHttpError(`response body exceeded ${maxBytes} bytes — aborted before reading it all`);
|
|
137
|
-
}
|
|
138
|
-
chunks.push(value);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
finally {
|
|
142
|
-
try {
|
|
143
|
-
reader.releaseLock();
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
// The stream may already be released; nothing to do.
|
|
147
|
-
}
|
|
126
|
+
async function readCapped(res, maxBytes, signal) {
|
|
127
|
+
const read = await readResponseBounded(res, {
|
|
128
|
+
maxBytes,
|
|
129
|
+
...(signal !== undefined ? { signal } : {}),
|
|
130
|
+
});
|
|
131
|
+
if (read.ok) {
|
|
132
|
+
if (!read.truncated)
|
|
133
|
+
return read.bytes;
|
|
134
|
+
throw new RegistryHttpError(`response body exceeded ${maxBytes} bytes — aborted before reading it all`);
|
|
148
135
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
136
|
+
switch (read.code) {
|
|
137
|
+
case "aborted":
|
|
138
|
+
case "stalled":
|
|
139
|
+
// As the runtime reports an abort mid-body, so the caller's timeout
|
|
140
|
+
// and cancellation handling sees the same thing it always did.
|
|
141
|
+
throw signal?.reason ?? new RegistryHttpError("the read was aborted before the body ended");
|
|
142
|
+
case "unsupported-encoding":
|
|
143
|
+
throw new RegistryHttpError(`the registry sent a body in a stack of content-encodings this tool cannot decode within its ${maxBytes}-byte cap`);
|
|
144
|
+
case "decode-error":
|
|
145
|
+
case "auto-decompressed":
|
|
146
|
+
throw new RegistryHttpError("the registry sent a body labelled as compressed that could not be decoded");
|
|
147
|
+
default:
|
|
148
|
+
throw new RegistryHttpError("the registry closed the connection before the body ended");
|
|
154
149
|
}
|
|
155
|
-
return merged;
|
|
156
150
|
}
|
|
157
151
|
/**
|
|
158
152
|
* A signal that aborts on the caller's cancellation OR after `timeoutMs`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-containers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deterministic OCI registry reads: resolve an image tag to its digest and list tags, with no daemon and no pull",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "bun test src"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@crewhaus/errors": "0.
|
|
19
|
-
"@crewhaus/tool-builder": "0.
|
|
20
|
-
"@crewhaus/tool-catalog": "0.
|
|
21
|
-
"@crewhaus/tool-fetch": "0.
|
|
19
|
+
"@crewhaus/errors": "0.8.1",
|
|
20
|
+
"@crewhaus/tool-builder": "0.8.1",
|
|
21
|
+
"@crewhaus/tool-catalog": "0.8.1",
|
|
22
|
+
"@crewhaus/tool-fetch": "0.8.1",
|
|
23
|
+
"@crewhaus/tool-safety": "0.8.1",
|
|
22
24
|
"zod": "^3.23.8"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
@@ -42,5 +44,8 @@
|
|
|
42
44
|
"publishConfig": {
|
|
43
45
|
"access": "public"
|
|
44
46
|
},
|
|
45
|
-
"files": ["dist", "README.md", "LICENSE", "NOTICE"]
|
|
47
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.3.14"
|
|
50
|
+
}
|
|
46
51
|
}
|
package/dist/fixtures.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { RegistryFetch } from "./lib/http";
|
|
2
|
-
export declare const bytesOf: (text: string) => Uint8Array;
|
|
3
|
-
export declare const sha256Of: (text: string) => string;
|
|
4
|
-
/**
|
|
5
|
-
* An image config blob. `APP_TOKEN` is here on purpose: it is the shape of the
|
|
6
|
-
* accident this package must not amplify, and the test asserts the value never
|
|
7
|
-
* reaches the output.
|
|
8
|
-
*/
|
|
9
|
-
export declare const CONFIG_JSON = "{\"architecture\":\"amd64\",\"os\":\"linux\",\"created\":\"2026-04-02T10:11:12.13Z\",\n \"config\":{\"User\":\"app\",\"WorkingDir\":\"/srv\",\"Entrypoint\":[\"/bin/app\"],\"Cmd\":[\"--serve\"],\n \"Env\":[\"PATH=/usr/local/bin:/usr/bin\",\"APP_TOKEN=s3cr3t-do-not-echo\"],\n \"ExposedPorts\":{\"8080/tcp\":{}},\n \"Labels\":{\"org.opencontainers.image.title\":\"caf\\u00e9-runner\",\"org.opencontainers.image.version\":\"1.4.2\"}},\n \"rootfs\":{\"type\":\"layers\",\"diff_ids\":[\"sha256:1111111111111111111111111111111111111111111111111111111111111111\",\"sha256:2222222222222222222222222222222222222222222222222222222222222222\"]}}";
|
|
10
|
-
export declare const CONFIG_DIGEST: string;
|
|
11
|
-
/** An OCI image manifest, amd64. Note the indentation and the escaped é. */
|
|
12
|
-
export declare const OCI_AMD64_JSON: string;
|
|
13
|
-
export declare const OCI_AMD64_DIGEST: string;
|
|
14
|
-
/** The same image for arm64/v8, with no annotations. */
|
|
15
|
-
export declare const OCI_ARM64_JSON: string;
|
|
16
|
-
export declare const OCI_ARM64_DIGEST: string;
|
|
17
|
-
/**
|
|
18
|
-
* A multi-arch index with a buildkit attestation entry — the `unknown/unknown`
|
|
19
|
-
* descriptor that a naive "first manifest wins" resolver picks and then reports
|
|
20
|
-
* a provenance document as if it were the image.
|
|
21
|
-
*/
|
|
22
|
-
export declare const OCI_INDEX_JSON: string;
|
|
23
|
-
export declare const OCI_INDEX_DIGEST: string;
|
|
24
|
-
/** Docker's own manifest list + v2 manifest, which Hub still serves for older images. */
|
|
25
|
-
export declare const DOCKER_AMD64_JSON: string;
|
|
26
|
-
export declare const DOCKER_AMD64_DIGEST: string;
|
|
27
|
-
export declare const DOCKER_LIST_JSON: string;
|
|
28
|
-
export declare const DOCKER_LIST_DIGEST: string;
|
|
29
|
-
/** A schema 1 manifest — digest over a signature envelope, which is why it is refused. */
|
|
30
|
-
export declare const SCHEMA1_JSON = "{\"schemaVersion\":1,\"name\":\"library/ancient\",\"tag\":\"1.0\",\"architecture\":\"amd64\",\"fsLayers\":[{\"blobSum\":\"sha256:8888888888888888888888888888888888888888888888888888888888888888\"}],\"signatures\":[{\"header\":{\"alg\":\"ES256\"},\"signature\":\"abc\",\"protected\":\"def\"}]}";
|
|
31
|
-
/** An OCI artifact: image-manifest shaped, but its config is a Helm chart. */
|
|
32
|
-
export declare const HELM_MANIFEST_JSON = "{\"schemaVersion\":2,\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\",\"config\":{\"mediaType\":\"application/vnd.cncf.helm.config.v1+json\",\"size\":141,\"digest\":\"sha256:9999999999999999999999999999999999999999999999999999999999999999\"},\"layers\":[{\"mediaType\":\"application/vnd.cncf.helm.chart.content.v1.tar+gzip\",\"size\":4096,\"digest\":\"sha256:aaaabbbbccccddddeeeeffff0000111122223333444455556666777788889999\"}]}";
|
|
33
|
-
export type RegistryFixture = {
|
|
34
|
-
/** The host the client talks to — Hub's is not `docker.io`. */
|
|
35
|
-
readonly apiHost: string;
|
|
36
|
-
/** Exactly what the registry puts on the 401. */
|
|
37
|
-
readonly challenge: (repository: string) => string;
|
|
38
|
-
readonly tokenUrl: string;
|
|
39
|
-
readonly token: string;
|
|
40
|
-
readonly tokenBody: string;
|
|
41
|
-
};
|
|
42
|
-
export declare const DOCKER_HUB: RegistryFixture;
|
|
43
|
-
export declare const GHCR: RegistryFixture;
|
|
44
|
-
export declare const QUAY: RegistryFixture;
|
|
45
|
-
export type RecordedCall = {
|
|
46
|
-
readonly url: string;
|
|
47
|
-
readonly method: string;
|
|
48
|
-
readonly authorization: string | null;
|
|
49
|
-
readonly accept: string | null;
|
|
50
|
-
readonly pinnedIp: string;
|
|
51
|
-
};
|
|
52
|
-
export type StubRoute = {
|
|
53
|
-
/** Exact URL, or a predicate over the parsed URL. */
|
|
54
|
-
readonly match: string | ((url: URL) => boolean);
|
|
55
|
-
readonly respond: (req: Request, url: URL) => Response;
|
|
56
|
-
};
|
|
57
|
-
export type Stub = {
|
|
58
|
-
readonly fetch: RegistryFetch;
|
|
59
|
-
readonly calls: RecordedCall[];
|
|
60
|
-
};
|
|
61
|
-
/** Build a fetch from an ordered route table. First match wins; no match is a 404. */
|
|
62
|
-
export declare function stubFetch(routes: readonly StubRoute[]): Stub;
|
|
63
|
-
export declare function jsonResponse(status: number, body: string, headers?: Record<string, string>): Response;
|
|
64
|
-
export type Served = {
|
|
65
|
-
readonly body: string;
|
|
66
|
-
readonly mediaType: string;
|
|
67
|
-
/**
|
|
68
|
-
* What to put in `Docker-Content-Digest`. Omitted ⇒ the true digest of the
|
|
69
|
-
* bytes; `null` ⇒ no header at all, which some proxies do.
|
|
70
|
-
*/
|
|
71
|
-
readonly contentDigest?: string | null;
|
|
72
|
-
};
|
|
73
|
-
export type TagPage = {
|
|
74
|
-
readonly body: string;
|
|
75
|
-
readonly nextLast?: string;
|
|
76
|
-
readonly link?: string;
|
|
77
|
-
};
|
|
78
|
-
export type RepoContent = {
|
|
79
|
-
/** Keyed by reference: a tag, or a `sha256:…` digest. */
|
|
80
|
-
readonly manifests?: Record<string, Served>;
|
|
81
|
-
readonly blobs?: Record<string, Served>;
|
|
82
|
-
/** Pages in order; page 0 is the request with no `last` parameter. */
|
|
83
|
-
readonly tagPages?: readonly TagPage[];
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Serve one repository from one registry fixture, including the 401 → token →
|
|
87
|
-
* retry dance. Requests without a bearer token get the registry's own
|
|
88
|
-
* challenge, which is what makes these tests exercise the real flow rather than
|
|
89
|
-
* a happy path with the auth step removed.
|
|
90
|
-
*/
|
|
91
|
-
export declare function registryStub(fixture: RegistryFixture, repository: string, content: RepoContent, extraRoutes?: readonly StubRoute[]): Stub;
|
|
92
|
-
/** The standard multi-arch repository, served by whichever registry is passed. */
|
|
93
|
-
export declare function multiArchContent(): RepoContent;
|
package/dist/fixtures.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recorded registry shapes, and a fetch stub that serves them.
|
|
3
|
-
*
|
|
4
|
-
* These are the three registries this package is meant to work against —
|
|
5
|
-
* Docker Hub, ghcr.io and quay.io — reduced to what actually differs between
|
|
6
|
-
* them: the challenge header, the realm host, whether a service and a scope are
|
|
7
|
-
* echoed, and whether anything else shares the `WWW-Authenticate` line. If the
|
|
8
|
-
* generic challenge-driven flow handles these three it handles the fourth one
|
|
9
|
-
* nobody has tried yet, which is the entire argument for not special-casing
|
|
10
|
-
* Docker Hub.
|
|
11
|
-
*
|
|
12
|
-
* The manifest bytes are deliberately UGLY: three-space indentation, keys in
|
|
13
|
-
* the order a builder emitted them rather than sorted, and a `é` escape
|
|
14
|
-
* instead of a literal é. `JSON.stringify(JSON.parse(bytes))` produces
|
|
15
|
-
* different bytes for every one of them, which is the property the digest tests
|
|
16
|
-
* need — a reserializing implementation passes a fixture whose formatting is
|
|
17
|
-
* already canonical and fails in production.
|
|
18
|
-
*/
|
|
19
|
-
import { createHash } from "node:crypto";
|
|
20
|
-
const encoder = new TextEncoder();
|
|
21
|
-
export const bytesOf = (text) => encoder.encode(text);
|
|
22
|
-
export const sha256Of = (text) => `sha256:${createHash("sha256").update(encoder.encode(text)).digest("hex")}`;
|
|
23
|
-
// ─── documents ──────────────────────────────────────────────────────────────
|
|
24
|
-
/**
|
|
25
|
-
* An image config blob. `APP_TOKEN` is here on purpose: it is the shape of the
|
|
26
|
-
* accident this package must not amplify, and the test asserts the value never
|
|
27
|
-
* reaches the output.
|
|
28
|
-
*/
|
|
29
|
-
export const CONFIG_JSON = `{"architecture":"amd64","os":"linux","created":"2026-04-02T10:11:12.13Z",
|
|
30
|
-
"config":{"User":"app","WorkingDir":"/srv","Entrypoint":["/bin/app"],"Cmd":["--serve"],
|
|
31
|
-
"Env":["PATH=/usr/local/bin:/usr/bin","APP_TOKEN=s3cr3t-do-not-echo"],
|
|
32
|
-
"ExposedPorts":{"8080/tcp":{}},
|
|
33
|
-
"Labels":{"org.opencontainers.image.title":"caf\\u00e9-runner","org.opencontainers.image.version":"1.4.2"}},
|
|
34
|
-
"rootfs":{"type":"layers","diff_ids":["sha256:1111111111111111111111111111111111111111111111111111111111111111","sha256:2222222222222222222222222222222222222222222222222222222222222222"]}}`;
|
|
35
|
-
export const CONFIG_DIGEST = sha256Of(CONFIG_JSON);
|
|
36
|
-
/** An OCI image manifest, amd64. Note the indentation and the escaped é. */
|
|
37
|
-
export const OCI_AMD64_JSON = `{ "schemaVersion": 2,
|
|
38
|
-
"mediaType": "application/vnd.oci.image.manifest.v1+json",
|
|
39
|
-
"config": {
|
|
40
|
-
"mediaType": "application/vnd.oci.image.config.v1+json",
|
|
41
|
-
"size": ${CONFIG_JSON.length},
|
|
42
|
-
"digest": "${CONFIG_DIGEST}"
|
|
43
|
-
},
|
|
44
|
-
"layers": [
|
|
45
|
-
{ "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "size": 3401687,
|
|
46
|
-
"digest": "sha256:3333333333333333333333333333333333333333333333333333333333333333" },
|
|
47
|
-
{ "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "size": 128,
|
|
48
|
-
"digest": "sha256:4444444444444444444444444444444444444444444444444444444444444444" }
|
|
49
|
-
],
|
|
50
|
-
"annotations": { "org.opencontainers.image.title": "caf\\u00e9-runner",
|
|
51
|
-
"org.opencontainers.image.revision": "9f3c1ad" }
|
|
52
|
-
}`;
|
|
53
|
-
export const OCI_AMD64_DIGEST = sha256Of(OCI_AMD64_JSON);
|
|
54
|
-
/** The same image for arm64/v8, with no annotations. */
|
|
55
|
-
export const OCI_ARM64_JSON = `{ "schemaVersion": 2, "mediaType": "application/vnd.oci.image.manifest.v1+json",
|
|
56
|
-
"config": { "mediaType": "application/vnd.oci.image.config.v1+json", "size": ${CONFIG_JSON.length}, "digest": "${CONFIG_DIGEST}" },
|
|
57
|
-
"layers": [ { "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "size": 3211987,
|
|
58
|
-
"digest": "sha256:5555555555555555555555555555555555555555555555555555555555555555" } ]
|
|
59
|
-
}`;
|
|
60
|
-
export const OCI_ARM64_DIGEST = sha256Of(OCI_ARM64_JSON);
|
|
61
|
-
/**
|
|
62
|
-
* A multi-arch index with a buildkit attestation entry — the `unknown/unknown`
|
|
63
|
-
* descriptor that a naive "first manifest wins" resolver picks and then reports
|
|
64
|
-
* a provenance document as if it were the image.
|
|
65
|
-
*/
|
|
66
|
-
export const OCI_INDEX_JSON = `{ "schemaVersion": 2,
|
|
67
|
-
"mediaType": "application/vnd.oci.image.index.v1+json",
|
|
68
|
-
"manifests": [
|
|
69
|
-
{ "mediaType": "application/vnd.oci.image.manifest.v1+json", "size": ${OCI_AMD64_JSON.length},
|
|
70
|
-
"digest": "${OCI_AMD64_DIGEST}",
|
|
71
|
-
"platform": { "architecture": "amd64", "os": "linux" } },
|
|
72
|
-
{ "mediaType": "application/vnd.oci.image.manifest.v1+json", "size": ${OCI_ARM64_JSON.length},
|
|
73
|
-
"digest": "${OCI_ARM64_DIGEST}",
|
|
74
|
-
"platform": { "architecture": "arm64", "os": "linux", "variant": "v8" } },
|
|
75
|
-
{ "mediaType": "application/vnd.oci.image.manifest.v1+json", "size": 566,
|
|
76
|
-
"digest": "sha256:6666666666666666666666666666666666666666666666666666666666666666",
|
|
77
|
-
"platform": { "architecture": "unknown", "os": "unknown" },
|
|
78
|
-
"annotations": { "vnd.docker.reference.type": "attestation-manifest" } }
|
|
79
|
-
]
|
|
80
|
-
}`;
|
|
81
|
-
export const OCI_INDEX_DIGEST = sha256Of(OCI_INDEX_JSON);
|
|
82
|
-
/** Docker's own manifest list + v2 manifest, which Hub still serves for older images. */
|
|
83
|
-
export const DOCKER_AMD64_JSON = `{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.docker.container.image.v1+json","size":${CONFIG_JSON.length},"digest":"${CONFIG_DIGEST}"},"layers":[{"mediaType":"application/vnd.docker.image.rootfs.diff.tar.gzip","size":3401687,"digest":"sha256:7777777777777777777777777777777777777777777777777777777777777777"}]}`;
|
|
84
|
-
export const DOCKER_AMD64_DIGEST = sha256Of(DOCKER_AMD64_JSON);
|
|
85
|
-
export const DOCKER_LIST_JSON = `{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.list.v2+json","manifests":[{"mediaType":"application/vnd.docker.distribution.manifest.v2+json","size":${DOCKER_AMD64_JSON.length},"digest":"${DOCKER_AMD64_DIGEST}","platform":{"architecture":"amd64","os":"linux"}}]}`;
|
|
86
|
-
export const DOCKER_LIST_DIGEST = sha256Of(DOCKER_LIST_JSON);
|
|
87
|
-
/** A schema 1 manifest — digest over a signature envelope, which is why it is refused. */
|
|
88
|
-
export const SCHEMA1_JSON = `{"schemaVersion":1,"name":"library/ancient","tag":"1.0","architecture":"amd64","fsLayers":[{"blobSum":"sha256:8888888888888888888888888888888888888888888888888888888888888888"}],"signatures":[{"header":{"alg":"ES256"},"signature":"abc","protected":"def"}]}`;
|
|
89
|
-
/** An OCI artifact: image-manifest shaped, but its config is a Helm chart. */
|
|
90
|
-
export const HELM_MANIFEST_JSON = `{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.cncf.helm.config.v1+json","size":141,"digest":"sha256:9999999999999999999999999999999999999999999999999999999999999999"},"layers":[{"mediaType":"application/vnd.cncf.helm.chart.content.v1.tar+gzip","size":4096,"digest":"sha256:aaaabbbbccccddddeeeeffff0000111122223333444455556666777788889999"}]}`;
|
|
91
|
-
export const DOCKER_HUB = {
|
|
92
|
-
apiHost: "registry-1.docker.io",
|
|
93
|
-
// Hub omits the scope on the /v2/ probe and includes it on a manifest 401.
|
|
94
|
-
challenge: (repository) => `Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:${repository}:pull"`,
|
|
95
|
-
tokenUrl: "https://auth.docker.io/token",
|
|
96
|
-
token: "hub-token",
|
|
97
|
-
tokenBody: `{"token":"hub-token","access_token":"hub-token","expires_in":300,"issued_at":"2026-09-18T09:00:00.000000000Z"}`,
|
|
98
|
-
};
|
|
99
|
-
export const GHCR = {
|
|
100
|
-
apiHost: "ghcr.io",
|
|
101
|
-
challenge: (repository) => `Bearer realm="https://ghcr.io/token",service="ghcr.io",scope="repository:${repository}:pull"`,
|
|
102
|
-
tokenUrl: "https://ghcr.io/token",
|
|
103
|
-
token: "ghcr-token",
|
|
104
|
-
tokenBody: `{"token":"ghcr-token"}`,
|
|
105
|
-
};
|
|
106
|
-
export const QUAY = {
|
|
107
|
-
apiHost: "quay.io",
|
|
108
|
-
// quay has shipped two challenges on one line; the Bearer one is second.
|
|
109
|
-
challenge: (repository) => `Basic realm="quay.io", Bearer realm="https://quay.io/v2/auth",service="quay.io",scope="repository:${repository}:pull"`,
|
|
110
|
-
tokenUrl: "https://quay.io/v2/auth",
|
|
111
|
-
token: "quay-token",
|
|
112
|
-
tokenBody: `{"token":"quay-token","expires_in":600,"issued_at":"2026-09-18T09:00:00Z"}`,
|
|
113
|
-
};
|
|
114
|
-
/** Build a fetch from an ordered route table. First match wins; no match is a 404. */
|
|
115
|
-
export function stubFetch(routes) {
|
|
116
|
-
const calls = [];
|
|
117
|
-
const fetch = async (req, pinnedIp) => {
|
|
118
|
-
const url = new URL(req.url);
|
|
119
|
-
calls.push({
|
|
120
|
-
url: req.url,
|
|
121
|
-
method: req.method,
|
|
122
|
-
authorization: req.headers.get("authorization"),
|
|
123
|
-
accept: req.headers.get("accept"),
|
|
124
|
-
pinnedIp,
|
|
125
|
-
});
|
|
126
|
-
for (const route of routes) {
|
|
127
|
-
const hit = typeof route.match === "string" ? req.url === route.match : route.match(url);
|
|
128
|
-
if (hit)
|
|
129
|
-
return route.respond(req, url);
|
|
130
|
-
}
|
|
131
|
-
return jsonResponse(404, `{"errors":[{"code":"NOT_FOUND","message":"no stub route for ${url.pathname}"}]}`);
|
|
132
|
-
};
|
|
133
|
-
return { fetch, calls };
|
|
134
|
-
}
|
|
135
|
-
export function jsonResponse(status, body, headers = {}) {
|
|
136
|
-
return new Response(bytesOf(body), {
|
|
137
|
-
status,
|
|
138
|
-
headers: { "content-type": "application/json", ...headers },
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Serve one repository from one registry fixture, including the 401 → token →
|
|
143
|
-
* retry dance. Requests without a bearer token get the registry's own
|
|
144
|
-
* challenge, which is what makes these tests exercise the real flow rather than
|
|
145
|
-
* a happy path with the auth step removed.
|
|
146
|
-
*/
|
|
147
|
-
export function registryStub(fixture, repository, content, extraRoutes = []) {
|
|
148
|
-
const base = `https://${fixture.apiHost}/v2/${repository}`;
|
|
149
|
-
const authorized = (req) => req.headers.get("authorization") === `Bearer ${fixture.token}`;
|
|
150
|
-
const unauthorized = () => jsonResponse(401, `{"errors":[{"code":"UNAUTHORIZED","message":"authentication required"}]}`, {
|
|
151
|
-
"www-authenticate": fixture.challenge(repository),
|
|
152
|
-
});
|
|
153
|
-
const serve = (served) => {
|
|
154
|
-
const headers = { "content-type": served.mediaType };
|
|
155
|
-
const digest = served.contentDigest === undefined ? sha256Of(served.body) : served.contentDigest;
|
|
156
|
-
if (digest !== null)
|
|
157
|
-
headers["docker-content-digest"] = digest;
|
|
158
|
-
return new Response(bytesOf(served.body), { status: 200, headers });
|
|
159
|
-
};
|
|
160
|
-
const routes = [
|
|
161
|
-
// Overrides first: a test that wants one path to redirect or fail says so
|
|
162
|
-
// without having to restate the rest of the registry.
|
|
163
|
-
...extraRoutes,
|
|
164
|
-
{
|
|
165
|
-
match: (url) => `${url.origin}${url.pathname}` === fixture.tokenUrl,
|
|
166
|
-
respond: () => jsonResponse(200, fixture.tokenBody),
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
match: (url) => `${url.origin}${url.pathname}`.startsWith(`${base}/manifests/`),
|
|
170
|
-
respond: (req, url) => {
|
|
171
|
-
if (!authorized(req))
|
|
172
|
-
return unauthorized();
|
|
173
|
-
const reference = decodeURIComponent(url.pathname.split("/manifests/")[1] ?? "");
|
|
174
|
-
const served = content.manifests?.[reference];
|
|
175
|
-
if (served === undefined) {
|
|
176
|
-
return jsonResponse(404, `{"errors":[{"code":"MANIFEST_UNKNOWN","message":"manifest unknown: ${reference}"}]}`);
|
|
177
|
-
}
|
|
178
|
-
return serve(served);
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
match: (url) => `${url.origin}${url.pathname}`.startsWith(`${base}/blobs/`),
|
|
183
|
-
respond: (req, url) => {
|
|
184
|
-
if (!authorized(req))
|
|
185
|
-
return unauthorized();
|
|
186
|
-
const digest = url.pathname.split("/blobs/")[1] ?? "";
|
|
187
|
-
const served = content.blobs?.[digest];
|
|
188
|
-
if (served === undefined) {
|
|
189
|
-
return jsonResponse(404, `{"errors":[{"code":"BLOB_UNKNOWN","message":"blob unknown"}]}`);
|
|
190
|
-
}
|
|
191
|
-
return serve(served);
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
match: (url) => `${url.origin}${url.pathname}` === `${base}/tags/list`,
|
|
196
|
-
respond: (req, url) => {
|
|
197
|
-
if (!authorized(req))
|
|
198
|
-
return unauthorized();
|
|
199
|
-
const pages = content.tagPages ?? [];
|
|
200
|
-
const last = url.searchParams.get("last");
|
|
201
|
-
const index = last === null ? 0 : pages.findIndex((p) => p.nextLast === last) + 1;
|
|
202
|
-
const page = pages[index];
|
|
203
|
-
if (page === undefined)
|
|
204
|
-
return jsonResponse(404, `{"errors":[{"code":"NOT_FOUND"}]}`);
|
|
205
|
-
const headers = {};
|
|
206
|
-
const n = url.searchParams.get("n") ?? "100";
|
|
207
|
-
// Registries send a RELATIVE next link; resolving it against the page
|
|
208
|
-
// URL is part of what the client has to get right.
|
|
209
|
-
const link = page.link ??
|
|
210
|
-
(page.nextLast === undefined
|
|
211
|
-
? undefined
|
|
212
|
-
: `</v2/${repository}/tags/list?n=${n}&last=${page.nextLast}>; rel="next"`);
|
|
213
|
-
if (link !== undefined)
|
|
214
|
-
headers["link"] = link;
|
|
215
|
-
return jsonResponse(200, page.body, headers);
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
];
|
|
219
|
-
return stubFetch(routes);
|
|
220
|
-
}
|
|
221
|
-
/** The standard multi-arch repository, served by whichever registry is passed. */
|
|
222
|
-
export function multiArchContent() {
|
|
223
|
-
return {
|
|
224
|
-
manifests: {
|
|
225
|
-
"1.4.2": { body: OCI_INDEX_JSON, mediaType: "application/vnd.oci.image.index.v1+json" },
|
|
226
|
-
latest: { body: OCI_INDEX_JSON, mediaType: "application/vnd.oci.image.index.v1+json" },
|
|
227
|
-
[OCI_INDEX_DIGEST]: {
|
|
228
|
-
body: OCI_INDEX_JSON,
|
|
229
|
-
mediaType: "application/vnd.oci.image.index.v1+json",
|
|
230
|
-
},
|
|
231
|
-
[OCI_AMD64_DIGEST]: {
|
|
232
|
-
body: OCI_AMD64_JSON,
|
|
233
|
-
mediaType: "application/vnd.oci.image.manifest.v1+json",
|
|
234
|
-
},
|
|
235
|
-
[OCI_ARM64_DIGEST]: {
|
|
236
|
-
body: OCI_ARM64_JSON,
|
|
237
|
-
mediaType: "application/vnd.oci.image.manifest.v1+json",
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
blobs: {
|
|
241
|
-
[CONFIG_DIGEST]: { body: CONFIG_JSON, mediaType: "application/vnd.oci.image.config.v1+json" },
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
}
|