-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.ts
More file actions
117 lines (107 loc) · 3.33 KB
/
Copy pathtypes.ts
File metadata and controls
117 lines (107 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @file Shared types for the browser-safe OCI distribution-spec pull client.
* The HTTP surface is an INJECTABLE adapter (`OciHttpAdapter`) so the client
* has no `node:*` dependency at module load. Node callers build the adapter
* from `@socketsecurity/lib/http-request` (`{ json: httpJson, request:
* httpRequest }`); browser callers pass the `http-request/browser`
* equivalents. The `request` leg is needed on top of `json` because the OCI
* flow reads the `WWW-Authenticate` challenge header on the `/v2/` probe, the
* `Docker-Content-Digest` header on a manifest, and the raw bytes of a blob —
* none of which a JSON-only adapter exposes.
*/
/**
* The subset of an HTTP response the OCI client reads. A Node `HttpResponse`
* from `@socketsecurity/lib/http-request` satisfies this shape directly.
*/
export interface OciHttpResponse {
arrayBuffer(): ArrayBuffer
headers: Record<string, string | string[] | undefined>
json<T = unknown>(): T
ok: boolean
status: number
statusText: string
text(): string
}
/**
* Per-request options passed through the adapter. Only headers are needed for
* the anonymous pull flow (bearer token + media-type Accept).
*/
export interface OciRequestOptions {
headers?: Record<string, string> | undefined
}
/**
* Injectable HTTP adapter. `json` parses a JSON endpoint such as a token or
* config blob; `request` returns the full response so the caller can read
* headers and bytes.
*/
export interface OciHttpAdapter {
json<T = unknown>(
url: string,
options?: OciRequestOptions | undefined,
): Promise<T>
request(
url: string,
options?: OciRequestOptions | undefined,
): Promise<OciHttpResponse>
}
/**
* The `{ http }` bag every OCI client function accepts, mirroring the npm
* registry client's `NpmHttpOptions`.
*/
export interface OciHttpOptions {
http: OciHttpAdapter
}
/**
* A parsed `WWW-Authenticate: Bearer realm=...,service=...,scope=...`
* challenge.
*/
export interface AuthChallenge {
realm: string
scope: string | undefined
service: string | undefined
}
/**
* The token endpoint's JSON response. Registries return the bearer under
* `token` (Docker) or `access_token` (OAuth-style); both are accepted.
*/
export interface OciTokenResponse {
access_token?: string | undefined
token?: string | undefined
}
/**
* A platform descriptor on a manifest-index entry.
*/
export interface OciPlatform {
architecture?: string | undefined
os?: string | undefined
variant?: string | undefined
}
/**
* An OCI content descriptor for a config, layer, or index entry.
*/
export interface OciDescriptor {
digest?: string | undefined
mediaType?: string | undefined
platform?: OciPlatform | undefined
size?: number | undefined
}
/**
* A parsed image manifest or manifest index. `config` + `layers` are present on
* a single image manifest; `manifests` is present on a multi-arch index.
*/
export interface OciManifest {
config?: OciDescriptor | undefined
layers?: OciDescriptor[] | undefined
manifests?: OciDescriptor[] | undefined
mediaType?: string | undefined
schemaVersion?: number | undefined
}
/**
* The result of fetching a manifest: the parsed body, its canonical
* `Docker-Content-Digest`, and the served media type.
*/
export interface OciManifestResult {
digest: string
manifest: OciManifest
mediaType: string | undefined
}