@jini-ai/registry 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/database-backend.d.ts +46 -0
- package/dist/database-backend.d.ts.map +1 -0
- package/dist/database-backend.js +149 -0
- package/dist/database-backend.js.map +1 -0
- package/dist/github-backend.d.ts +68 -0
- package/dist/github-backend.d.ts.map +1 -0
- package/dist/github-backend.js +157 -0
- package/dist/github-backend.js.map +1 -0
- package/dist/github-client.d.ts +116 -0
- package/dist/github-client.d.ts.map +1 -0
- package/dist/github-client.js +272 -0
- package/dist/github-client.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/static-backend.d.ts +68 -0
- package/dist/static-backend.d.ts.map +1 -0
- package/dist/static-backend.js +281 -0
- package/dist/static-backend.js.map +1 -0
- package/dist/trust.d.ts +94 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +295 -0
- package/dist/trust.js.map +1 -0
- package/dist/versioning.d.ts +47 -0
- package/dist/versioning.d.ts.map +1 -0
- package/dist/versioning.js +205 -0
- package/dist/versioning.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module github-client
|
|
3
|
+
*
|
|
4
|
+
* A concrete `GithubRegistryClient` (the interface `github-backend.ts`
|
|
5
|
+
* defines and takes as an injected dependency) implemented against GitHub's
|
|
6
|
+
* real REST API. Per `source-map.md`'s "2026-07-21 hardening pass": "No
|
|
7
|
+
* concrete `GithubRegistryClient` HTTP implementation exists in this
|
|
8
|
+
* package — `readManifest`/`createPublishPullRequest` are an injected
|
|
9
|
+
* interface with no concrete implementation anywhere in this repo." This
|
|
10
|
+
* file closes that gap.
|
|
11
|
+
*
|
|
12
|
+
* Built directly against GitHub's published REST API docs (Contents API,
|
|
13
|
+
* Git Data API, Pulls API — see each function's doc comment for the exact
|
|
14
|
+
* endpoint/behavior it was verified against), following the same "raw
|
|
15
|
+
* `fetch`, no SDK dependency" convention `@jini-ai/deploy`'s `netlify.ts`/
|
|
16
|
+
* `github-pages.ts` already establish (this package has no `@jini-ai/deploy`
|
|
17
|
+
* dependency and does not gain one — the blob/tree/commit/ref mechanics
|
|
18
|
+
* below are written fresh for this package, not shared cross-package, since
|
|
19
|
+
* there is no existing shared low-level GitHub REST helper package).
|
|
20
|
+
*/
|
|
21
|
+
import type { RegistryManifest } from '@jini-ai/protocol';
|
|
22
|
+
import type { GithubPublishMutation, GithubRegistryClient } from './github-backend.js';
|
|
23
|
+
/** Auth/endpoint config for {@link GithubApiRegistryClient}. */
|
|
24
|
+
export interface GithubApiRegistryClientOptions {
|
|
25
|
+
/**
|
|
26
|
+
* A token with `repo` scope (classic PAT) or fine-grained "Contents" read
|
|
27
|
+
* access — required for `createPublishPullRequest` (which additionally
|
|
28
|
+
* needs "Contents" write + "Pull requests" write), optional for
|
|
29
|
+
* `readManifest` against a public repository (anonymous reads are
|
|
30
|
+
* supported by GitHub's Contents API, subject to its lower unauthenticated
|
|
31
|
+
* rate limit).
|
|
32
|
+
*/
|
|
33
|
+
token?: string;
|
|
34
|
+
/** Override the REST API base URL (e.g. a GitHub Enterprise Server instance's `https://HOST/api/v3`). Defaults to `https://api.github.com`. */
|
|
35
|
+
apiUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `GithubRegistryClient` implementation against GitHub's real REST API:
|
|
39
|
+
* `readManifest` reads a file via the Contents API; `createPublishPullRequest`
|
|
40
|
+
* pushes a new commit via the Git Data API (blobs → tree → commit → branch
|
|
41
|
+
* ref) and opens a pull request via the Pulls API.
|
|
42
|
+
*/
|
|
43
|
+
export declare class GithubApiRegistryClient implements GithubRegistryClient {
|
|
44
|
+
private readonly token;
|
|
45
|
+
private readonly apiUrl;
|
|
46
|
+
constructor(options?: GithubApiRegistryClientOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Reads `path` at `ref` via `GET /repos/{owner}/{repo}/contents/{path}`
|
|
49
|
+
* (GitHub REST "Get repository content") and JSON-parses its base64
|
|
50
|
+
* `content`. Verified against GitHub's own docs: this endpoint returns
|
|
51
|
+
* `content`/`encoding: "base64"` only for files up to 1 MB; a 1-100 MB
|
|
52
|
+
* file instead returns `content: ""`/`encoding: "none"` (requiring the raw
|
|
53
|
+
* media type or Git Trees API instead) and files over 100 MB aren't
|
|
54
|
+
* supported by this endpoint at all. A registry manifest is expected to be
|
|
55
|
+
* well under 1 MB (it is a JSON index of entries, not package content
|
|
56
|
+
* itself), so this implementation reads the standard base64 response and
|
|
57
|
+
* reports a clear, attributable error for the oversized case rather than
|
|
58
|
+
* silently misreading it.
|
|
59
|
+
*
|
|
60
|
+
* @param owner - Repository owner.
|
|
61
|
+
* @param repo - Repository name.
|
|
62
|
+
* @param ref - Branch, tag, or commit sha to read from.
|
|
63
|
+
* @param path - Path to the manifest file within the repository.
|
|
64
|
+
* @returns The parsed manifest JSON (not schema-validated here — downstream
|
|
65
|
+
* readers in `static-backend.ts` already treat an untrusted/malformed
|
|
66
|
+
* manifest defensively; see its `validEntries()`/`doctor()`).
|
|
67
|
+
* @throws If the file does not exist, is a directory, is too large for
|
|
68
|
+
* this endpoint's inline-content response, or is not valid JSON.
|
|
69
|
+
*/
|
|
70
|
+
readManifest(owner: string, repo: string, ref: string, path: string): Promise<RegistryManifest>;
|
|
71
|
+
/**
|
|
72
|
+
* Pushes `request.files` as a new commit on a fresh branch (created off
|
|
73
|
+
* `request.baseRef`) via the Git Data API — create a blob per file, a tree
|
|
74
|
+
* layered on the base commit's tree, a commit, and a branch ref — then
|
|
75
|
+
* opens a pull request via `POST /repos/{owner}/{repo}/pulls`. Mirrors the
|
|
76
|
+
* blob→tree→commit→ref mechanics `@jini-ai/deploy`'s `github-pages.ts` already
|
|
77
|
+
* verified against GitHub's Git Data API docs, extended with an actual
|
|
78
|
+
* Pulls API call (that file force-pushes a branch directly; this one opens
|
|
79
|
+
* a PR against `baseRef` instead, matching `GithubPublishMutation`'s shape).
|
|
80
|
+
*
|
|
81
|
+
* @param request - Owner/repo/baseRef/branchName/title/body/files.
|
|
82
|
+
* @returns The opened (or, if one already existed for the same head/base, the existing) pull request's URL.
|
|
83
|
+
* @throws If no token is configured, `baseRef` does not exist, or any Git Data/Pulls API call fails.
|
|
84
|
+
*/
|
|
85
|
+
createPublishPullRequest(request: GithubPublishMutation): Promise<{
|
|
86
|
+
url: string;
|
|
87
|
+
}>;
|
|
88
|
+
private getRefSha;
|
|
89
|
+
/** `GET /repos/{owner}/{repo}/git/commits/{sha}` (Git Data API) — the tree API's `base_tree` param needs a *tree* sha, not the commit sha `getRefSha` returns. */
|
|
90
|
+
private getCommitTreeSha;
|
|
91
|
+
private createBlob;
|
|
92
|
+
private createTree;
|
|
93
|
+
private createCommit;
|
|
94
|
+
/**
|
|
95
|
+
* Creates `refs/heads/{branch}` pointing at `sha`, or (if it already
|
|
96
|
+
* exists — e.g. a retried publish reusing the same deterministic
|
|
97
|
+
* `vendor-name-version` branch name) force-updates it instead. Verified
|
|
98
|
+
* against GitHub's Git Data Refs API docs: create returns `409 Conflict`
|
|
99
|
+
* when the ref already exists; update accepts `force: true` to bypass the
|
|
100
|
+
* fast-forward-only default — same "last publish wins" reasoning
|
|
101
|
+
* `@jini-ai/deploy`'s `github-pages.ts` already documents for its own ref update.
|
|
102
|
+
*/
|
|
103
|
+
private ensureBranch;
|
|
104
|
+
/**
|
|
105
|
+
* Opens `POST /repos/{owner}/{repo}/pulls`, or — if GitHub rejects it
|
|
106
|
+
* because a pull request for this exact head/base already exists (the
|
|
107
|
+
* documented shape of that failure is a `422` whose `message` says so) —
|
|
108
|
+
* looks up and returns the existing PR's URL instead. Same
|
|
109
|
+
* try-then-recover-on-conflict shape `@jini-ai/deploy`'s `netlify.ts`
|
|
110
|
+
* (`ensureNetlifySite`) already establishes for a different provider's
|
|
111
|
+
* analogous "create-or-find" race.
|
|
112
|
+
*/
|
|
113
|
+
private ensurePullRequest;
|
|
114
|
+
private findOpenPullRequest;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=github-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-client.d.ts","sourceRoot":"","sources":["../src/github-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAQvF,gEAAgE;AAChE,MAAM,WAAW,8BAA8B;IAC7C;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+IAA+I;IAC/I,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,oBAAoB;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,GAAE,8BAAmC;IAKxD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAiCrG;;;;;;;;;;;;;OAaG;IACG,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;YAgB1E,SAAS;IAWvB,kKAAkK;YACpJ,gBAAgB;YAYhB,UAAU;YAaV,UAAU;YAkBV,YAAY;IAa1B;;;;;;;;OAQG;YACW,YAAY;IAoB1B;;;;;;;;OAQG;YACW,iBAAiB;YAoBjB,mBAAmB;CAUlC"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
const GITHUB_API = 'https://api.github.com';
|
|
2
|
+
/** Pinned per GitHub's own recommendation (`X-GitHub-Api-Version` header), matching `@jini-ai/deploy`'s `github-pages.ts` — see that file's doc comment for the sourcing rationale. */
|
|
3
|
+
const GITHUB_API_VERSION = '2026-03-10';
|
|
4
|
+
/**
|
|
5
|
+
* `GithubRegistryClient` implementation against GitHub's real REST API:
|
|
6
|
+
* `readManifest` reads a file via the Contents API; `createPublishPullRequest`
|
|
7
|
+
* pushes a new commit via the Git Data API (blobs → tree → commit → branch
|
|
8
|
+
* ref) and opens a pull request via the Pulls API.
|
|
9
|
+
*/
|
|
10
|
+
export class GithubApiRegistryClient {
|
|
11
|
+
token;
|
|
12
|
+
apiUrl;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.token = options.token;
|
|
15
|
+
this.apiUrl = options.apiUrl ?? GITHUB_API;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads `path` at `ref` via `GET /repos/{owner}/{repo}/contents/{path}`
|
|
19
|
+
* (GitHub REST "Get repository content") and JSON-parses its base64
|
|
20
|
+
* `content`. Verified against GitHub's own docs: this endpoint returns
|
|
21
|
+
* `content`/`encoding: "base64"` only for files up to 1 MB; a 1-100 MB
|
|
22
|
+
* file instead returns `content: ""`/`encoding: "none"` (requiring the raw
|
|
23
|
+
* media type or Git Trees API instead) and files over 100 MB aren't
|
|
24
|
+
* supported by this endpoint at all. A registry manifest is expected to be
|
|
25
|
+
* well under 1 MB (it is a JSON index of entries, not package content
|
|
26
|
+
* itself), so this implementation reads the standard base64 response and
|
|
27
|
+
* reports a clear, attributable error for the oversized case rather than
|
|
28
|
+
* silently misreading it.
|
|
29
|
+
*
|
|
30
|
+
* @param owner - Repository owner.
|
|
31
|
+
* @param repo - Repository name.
|
|
32
|
+
* @param ref - Branch, tag, or commit sha to read from.
|
|
33
|
+
* @param path - Path to the manifest file within the repository.
|
|
34
|
+
* @returns The parsed manifest JSON (not schema-validated here — downstream
|
|
35
|
+
* readers in `static-backend.ts` already treat an untrusted/malformed
|
|
36
|
+
* manifest defensively; see its `validEntries()`/`doctor()`).
|
|
37
|
+
* @throws If the file does not exist, is a directory, is too large for
|
|
38
|
+
* this endpoint's inline-content response, or is not valid JSON.
|
|
39
|
+
*/
|
|
40
|
+
async readManifest(owner, repo, ref, path) {
|
|
41
|
+
const url = `${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/contents/${encPath(path)}?${new URLSearchParams({ ref }).toString()}`;
|
|
42
|
+
const resp = await fetch(url, { headers: githubHeaders(this.token) });
|
|
43
|
+
if (resp.status === 404) {
|
|
44
|
+
throw new Error(`Registry manifest not found: ${owner}/${repo}@${ref}:${path}`);
|
|
45
|
+
}
|
|
46
|
+
const json = await readGithubJson(resp);
|
|
47
|
+
if (!resp.ok) {
|
|
48
|
+
throw githubError(Array.isArray(json) ? {} : json, resp.status, `Failed to read registry manifest ${owner}/${repo}@${ref}:${path}.`);
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(json)) {
|
|
51
|
+
throw new Error(`Registry manifest path is a directory, not a file: ${owner}/${repo}@${ref}:${path}`);
|
|
52
|
+
}
|
|
53
|
+
if (json.type !== 'file') {
|
|
54
|
+
throw new Error(`Registry manifest path is not a file (type: ${String(json.type)}): ${owner}/${repo}@${ref}:${path}`);
|
|
55
|
+
}
|
|
56
|
+
if (json.encoding !== 'base64' || typeof json.content !== 'string') {
|
|
57
|
+
throw new Error(`Registry manifest at ${owner}/${repo}@${ref}:${path} is too large for the Contents API's inline response ` +
|
|
58
|
+
`(size: ${typeof json.size === 'number' ? json.size : 'unknown'} bytes, encoding: ${String(json.encoding)}); ` +
|
|
59
|
+
'split the manifest into a smaller file or fetch it via the Git Trees/raw-media-type API instead.');
|
|
60
|
+
}
|
|
61
|
+
const decoded = Buffer.from(json.content.replace(/\n/g, ''), 'base64').toString('utf8');
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(decoded);
|
|
65
|
+
}
|
|
66
|
+
catch (cause) {
|
|
67
|
+
throw new Error(`Registry manifest at ${owner}/${repo}@${ref}:${path} is not valid JSON.`, { cause });
|
|
68
|
+
}
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Pushes `request.files` as a new commit on a fresh branch (created off
|
|
73
|
+
* `request.baseRef`) via the Git Data API — create a blob per file, a tree
|
|
74
|
+
* layered on the base commit's tree, a commit, and a branch ref — then
|
|
75
|
+
* opens a pull request via `POST /repos/{owner}/{repo}/pulls`. Mirrors the
|
|
76
|
+
* blob→tree→commit→ref mechanics `@jini-ai/deploy`'s `github-pages.ts` already
|
|
77
|
+
* verified against GitHub's Git Data API docs, extended with an actual
|
|
78
|
+
* Pulls API call (that file force-pushes a branch directly; this one opens
|
|
79
|
+
* a PR against `baseRef` instead, matching `GithubPublishMutation`'s shape).
|
|
80
|
+
*
|
|
81
|
+
* @param request - Owner/repo/baseRef/branchName/title/body/files.
|
|
82
|
+
* @returns The opened (or, if one already existed for the same head/base, the existing) pull request's URL.
|
|
83
|
+
* @throws If no token is configured, `baseRef` does not exist, or any Git Data/Pulls API call fails.
|
|
84
|
+
*/
|
|
85
|
+
async createPublishPullRequest(request) {
|
|
86
|
+
if (!this.token) {
|
|
87
|
+
throw new Error('A GitHub token is required to open a registry publish/yank pull request.');
|
|
88
|
+
}
|
|
89
|
+
const { owner, repo } = request;
|
|
90
|
+
const baseSha = await this.getRefSha(owner, repo, request.baseRef);
|
|
91
|
+
if (!baseSha) {
|
|
92
|
+
throw new Error(`GitHub base ref "${request.baseRef}" does not exist in ${owner}/${repo}.`);
|
|
93
|
+
}
|
|
94
|
+
const baseTreeSha = await this.getCommitTreeSha(owner, repo, baseSha);
|
|
95
|
+
const treeSha = await this.createTree(owner, repo, baseTreeSha, request.files);
|
|
96
|
+
const commitSha = await this.createCommit(owner, repo, `${request.title}\n\n${request.body}`.trim(), treeSha, [baseSha]);
|
|
97
|
+
await this.ensureBranch(owner, repo, request.branchName, commitSha);
|
|
98
|
+
return this.ensurePullRequest(owner, repo, request);
|
|
99
|
+
}
|
|
100
|
+
async getRefSha(owner, repo, branch) {
|
|
101
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/ref/heads/${enc(branch)}`, {
|
|
102
|
+
headers: githubHeaders(this.token),
|
|
103
|
+
});
|
|
104
|
+
if (resp.status === 404)
|
|
105
|
+
return undefined;
|
|
106
|
+
const json = await readGithubJson(resp);
|
|
107
|
+
if (!resp.ok)
|
|
108
|
+
throw githubError(json, resp.status, 'GitHub ref lookup failed.');
|
|
109
|
+
const object = json.object;
|
|
110
|
+
return typeof object?.sha === 'string' ? object.sha : undefined;
|
|
111
|
+
}
|
|
112
|
+
/** `GET /repos/{owner}/{repo}/git/commits/{sha}` (Git Data API) — the tree API's `base_tree` param needs a *tree* sha, not the commit sha `getRefSha` returns. */
|
|
113
|
+
async getCommitTreeSha(owner, repo, commitSha) {
|
|
114
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/commits/${enc(commitSha)}`, {
|
|
115
|
+
headers: githubHeaders(this.token),
|
|
116
|
+
});
|
|
117
|
+
const json = await readGithubJson(resp);
|
|
118
|
+
if (!resp.ok)
|
|
119
|
+
throw githubError(json, resp.status, 'GitHub base commit lookup failed.');
|
|
120
|
+
const tree = json.tree;
|
|
121
|
+
const sha = typeof tree?.sha === 'string' ? tree.sha : '';
|
|
122
|
+
if (!sha)
|
|
123
|
+
throw new Error('GitHub base commit response did not include a tree sha.');
|
|
124
|
+
return sha;
|
|
125
|
+
}
|
|
126
|
+
async createBlob(owner, repo, content) {
|
|
127
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/blobs`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
130
|
+
body: JSON.stringify({ content: Buffer.from(content, 'utf8').toString('base64'), encoding: 'base64' }),
|
|
131
|
+
});
|
|
132
|
+
const json = await readGithubJson(resp);
|
|
133
|
+
if (!resp.ok)
|
|
134
|
+
throw githubError(json, resp.status, 'GitHub blob creation failed.');
|
|
135
|
+
const sha = typeof json.sha === 'string' ? json.sha : '';
|
|
136
|
+
if (!sha)
|
|
137
|
+
throw new Error('GitHub blob response did not include a sha.');
|
|
138
|
+
return sha;
|
|
139
|
+
}
|
|
140
|
+
async createTree(owner, repo, baseTreeSha, files) {
|
|
141
|
+
const tree = [];
|
|
142
|
+
for (const file of files) {
|
|
143
|
+
const blobSha = await this.createBlob(owner, repo, file.content);
|
|
144
|
+
tree.push({ path: file.path, mode: '100644', type: 'blob', sha: blobSha });
|
|
145
|
+
}
|
|
146
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/trees`, {
|
|
147
|
+
method: 'POST',
|
|
148
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
149
|
+
body: JSON.stringify({ base_tree: baseTreeSha, tree }),
|
|
150
|
+
});
|
|
151
|
+
const json = await readGithubJson(resp);
|
|
152
|
+
if (!resp.ok)
|
|
153
|
+
throw githubError(json, resp.status, 'GitHub tree creation failed.');
|
|
154
|
+
const sha = typeof json.sha === 'string' ? json.sha : '';
|
|
155
|
+
if (!sha)
|
|
156
|
+
throw new Error('GitHub tree response did not include a sha.');
|
|
157
|
+
return sha;
|
|
158
|
+
}
|
|
159
|
+
async createCommit(owner, repo, message, treeSha, parents) {
|
|
160
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/commits`, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
163
|
+
body: JSON.stringify({ message, tree: treeSha, parents }),
|
|
164
|
+
});
|
|
165
|
+
const json = await readGithubJson(resp);
|
|
166
|
+
if (!resp.ok)
|
|
167
|
+
throw githubError(json, resp.status, 'GitHub commit creation failed.');
|
|
168
|
+
const sha = typeof json.sha === 'string' ? json.sha : '';
|
|
169
|
+
if (!sha)
|
|
170
|
+
throw new Error('GitHub commit response did not include a sha.');
|
|
171
|
+
return sha;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Creates `refs/heads/{branch}` pointing at `sha`, or (if it already
|
|
175
|
+
* exists — e.g. a retried publish reusing the same deterministic
|
|
176
|
+
* `vendor-name-version` branch name) force-updates it instead. Verified
|
|
177
|
+
* against GitHub's Git Data Refs API docs: create returns `409 Conflict`
|
|
178
|
+
* when the ref already exists; update accepts `force: true` to bypass the
|
|
179
|
+
* fast-forward-only default — same "last publish wins" reasoning
|
|
180
|
+
* `@jini-ai/deploy`'s `github-pages.ts` already documents for its own ref update.
|
|
181
|
+
*/
|
|
182
|
+
async ensureBranch(owner, repo, branch, sha) {
|
|
183
|
+
const createResp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/refs`, {
|
|
184
|
+
method: 'POST',
|
|
185
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
186
|
+
body: JSON.stringify({ ref: `refs/heads/${branch}`, sha }),
|
|
187
|
+
});
|
|
188
|
+
if (createResp.ok)
|
|
189
|
+
return;
|
|
190
|
+
if (createResp.status !== 409 && createResp.status !== 422) {
|
|
191
|
+
const json = await readGithubJson(createResp);
|
|
192
|
+
throw githubError(json, createResp.status, 'GitHub branch creation failed.');
|
|
193
|
+
}
|
|
194
|
+
const updateResp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/git/refs/heads/${enc(branch)}`, {
|
|
195
|
+
method: 'PATCH',
|
|
196
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
197
|
+
body: JSON.stringify({ sha, force: true }),
|
|
198
|
+
});
|
|
199
|
+
const json = await readGithubJson(updateResp);
|
|
200
|
+
if (!updateResp.ok)
|
|
201
|
+
throw githubError(json, updateResp.status, 'GitHub branch update failed.');
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Opens `POST /repos/{owner}/{repo}/pulls`, or — if GitHub rejects it
|
|
205
|
+
* because a pull request for this exact head/base already exists (the
|
|
206
|
+
* documented shape of that failure is a `422` whose `message` says so) —
|
|
207
|
+
* looks up and returns the existing PR's URL instead. Same
|
|
208
|
+
* try-then-recover-on-conflict shape `@jini-ai/deploy`'s `netlify.ts`
|
|
209
|
+
* (`ensureNetlifySite`) already establishes for a different provider's
|
|
210
|
+
* analogous "create-or-find" race.
|
|
211
|
+
*/
|
|
212
|
+
async ensurePullRequest(owner, repo, request) {
|
|
213
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/pulls`, {
|
|
214
|
+
method: 'POST',
|
|
215
|
+
headers: githubHeaders(this.token, { 'Content-Type': 'application/json' }),
|
|
216
|
+
body: JSON.stringify({ title: request.title, body: request.body, head: request.branchName, base: request.baseRef }),
|
|
217
|
+
});
|
|
218
|
+
const json = await readGithubJson(resp);
|
|
219
|
+
if (resp.ok) {
|
|
220
|
+
const url = typeof json.html_url === 'string' ? json.html_url : '';
|
|
221
|
+
if (!url)
|
|
222
|
+
throw new Error('GitHub pull request response did not include an html_url.');
|
|
223
|
+
return { url };
|
|
224
|
+
}
|
|
225
|
+
const message = typeof json.message === 'string' ? json.message : '';
|
|
226
|
+
if (resp.status === 422 && /already exists/i.test(message)) {
|
|
227
|
+
const existing = await this.findOpenPullRequest(owner, repo, request.baseRef, request.branchName);
|
|
228
|
+
if (existing)
|
|
229
|
+
return { url: existing };
|
|
230
|
+
}
|
|
231
|
+
throw githubError(json, resp.status, 'GitHub pull request creation failed.');
|
|
232
|
+
}
|
|
233
|
+
async findOpenPullRequest(owner, repo, base, branch) {
|
|
234
|
+
const query = new URLSearchParams({ head: `${owner}:${branch}`, base, state: 'open' });
|
|
235
|
+
const resp = await fetch(`${this.apiUrl}/repos/${enc(owner)}/${enc(repo)}/pulls?${query.toString()}`, {
|
|
236
|
+
headers: githubHeaders(this.token),
|
|
237
|
+
});
|
|
238
|
+
const json = await readGithubJson(resp);
|
|
239
|
+
if (!resp.ok || !Array.isArray(json))
|
|
240
|
+
return undefined;
|
|
241
|
+
const first = json[0];
|
|
242
|
+
return first && typeof first.html_url === 'string' ? first.html_url : undefined;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function enc(value) {
|
|
246
|
+
return encodeURIComponent(value);
|
|
247
|
+
}
|
|
248
|
+
/** URL-encodes each path segment individually so directory separators survive but special characters within a segment don't. */
|
|
249
|
+
function encPath(path) {
|
|
250
|
+
return path.split('/').filter(Boolean).map(encodeURIComponent).join('/');
|
|
251
|
+
}
|
|
252
|
+
function githubHeaders(token, extra = {}) {
|
|
253
|
+
return {
|
|
254
|
+
Accept: 'application/vnd.github+json',
|
|
255
|
+
'X-GitHub-Api-Version': GITHUB_API_VERSION,
|
|
256
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
257
|
+
...extra,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async function readGithubJson(resp) {
|
|
261
|
+
try {
|
|
262
|
+
return (await resp.json());
|
|
263
|
+
}
|
|
264
|
+
catch (cause) {
|
|
265
|
+
throw new Error('GitHub returned a non-JSON response.', { cause });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function githubError(json, status, fallback) {
|
|
269
|
+
const message = typeof json?.message === 'string' && json.message ? json.message : fallback;
|
|
270
|
+
return new Error(`${message} (HTTP ${status})`);
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=github-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-client.js","sourceRoot":"","sources":["../src/github-client.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAC5C,uLAAuL;AACvL,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAmBxC;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IACjB,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AC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB,EAAE,MAAc,EAAE,QAAgB;IACrE,MAAM,OAAO,GAAG,OAAO,IAAI,EAAE,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC5F,OAAO,IAAI,KAAK,CAAC,GAAG,OAAO,UAAU,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @jini-ai/registry
|
|
3
|
+
*
|
|
4
|
+
* Root barrel for pluggable content-registry backend implementations
|
|
5
|
+
* (`static`/`github`/`database`) plus the shared version-resolution helpers
|
|
6
|
+
* they build on. Wire types (`RegistryEntry`, `RegistryManifest`,
|
|
7
|
+
* `RegistryBackend`, ...) live in `@jini-ai/protocol`; this package only adds
|
|
8
|
+
* concrete backend logic, matching `@jini-ai/sqlite`'s split (protocol defines
|
|
9
|
+
* the port, a leaf package implements adapters against it).
|
|
10
|
+
*/
|
|
11
|
+
export type { ParsedRegistrySpecifier, ResolvedRegistryEntryVersion } from './versioning.js';
|
|
12
|
+
export { parseRegistrySpecifier, resolveRegistryEntryVersion } from './versioning.js';
|
|
13
|
+
export type { StaticRegistryBackendOptions } from './static-backend.js';
|
|
14
|
+
export { StaticRegistryBackend } from './static-backend.js';
|
|
15
|
+
export type { GithubPublishMutation, GithubRegistryBackendOptions, GithubRegistryClient } from './github-backend.js';
|
|
16
|
+
export { GithubRegistryBackend } from './github-backend.js';
|
|
17
|
+
export type { DatabaseRegistryBackendOptions } from './database-backend.js';
|
|
18
|
+
export { DatabaseRegistryBackend, ensureRegistryTables, upsertRegistryEntry } from './database-backend.js';
|
|
19
|
+
export type { GithubOidcTrustRoot, RegistryTrustRoot, SignatureVerificationResult } from './trust.js';
|
|
20
|
+
export { GITHUB_ACTIONS_OIDC_ISSUER, canonicalRegistrySigningPayload, verifyRegistryEntrySignatures, verifyRegistrySignature } from './trust.js';
|
|
21
|
+
export type { GithubApiRegistryClientOptions } from './github-client.js';
|
|
22
|
+
export { GithubApiRegistryClient } from './github-client.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,YAAY,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAEtF,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,YAAY,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,YAAY,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE3G,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEjJ,YAAY,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { parseRegistrySpecifier, resolveRegistryEntryVersion } from './versioning.js';
|
|
2
|
+
export { StaticRegistryBackend } from './static-backend.js';
|
|
3
|
+
export { GithubRegistryBackend } from './github-backend.js';
|
|
4
|
+
export { DatabaseRegistryBackend, ensureRegistryTables, upsertRegistryEntry } from './database-backend.js';
|
|
5
|
+
export { GITHUB_ACTIONS_OIDC_ISSUER, canonicalRegistrySigningPayload, verifyRegistryEntrySignatures, verifyRegistrySignature } from './trust.js';
|
|
6
|
+
export { GithubApiRegistryClient } from './github-client.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAGtF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG3G,OAAO,EAAE,0BAA0B,EAAE,+BAA+B,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGjJ,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module static-backend
|
|
3
|
+
*
|
|
4
|
+
* A read-mostly `RegistryBackend` over an in-memory {@link RegistryManifest}:
|
|
5
|
+
* list/search/resolve/doctor computed directly from `manifest.entries`, no
|
|
6
|
+
* publish/yank support. The base class every other backend in this package
|
|
7
|
+
* extends — `github-backend` overrides `getManifest()`'s source and adds
|
|
8
|
+
* publish/yank over a GitHub PR mutation; `database-backend` overrides
|
|
9
|
+
* `getManifest()` to read from sqlite and adds publish/yank as direct writes.
|
|
10
|
+
*/
|
|
11
|
+
import { type RegistryBackend, type RegistryBackendKind, type RegistryDoctorReport, type RegistryEntry, type RegistryListFilter, type RegistryManifest, type RegistryPublishRequest, type RegistrySearchQuery, type RegistrySearchResult, type RegistryTrust, type ResolvedRegistryEntry } from '@jini-ai/protocol';
|
|
12
|
+
import { type RegistryTrustRoot } from './trust.js';
|
|
13
|
+
export interface StaticRegistryBackendOptions {
|
|
14
|
+
id: string;
|
|
15
|
+
kind?: RegistryBackendKind;
|
|
16
|
+
trust: RegistryTrust;
|
|
17
|
+
manifest: RegistryManifest;
|
|
18
|
+
/**
|
|
19
|
+
* Optional per-entry signature trust root (currently `github-oidc` only —
|
|
20
|
+
* see `trust.ts`). Omitting this is the pre-existing, unchanged default:
|
|
21
|
+
* `resolve()` reports `verified: false` for every entry without attempting
|
|
22
|
+
* any verification. Configuring it turns on real cryptographic
|
|
23
|
+
* verification of `entry.signatures[]`, additive alongside `trust` (see
|
|
24
|
+
* `ResolvedRegistryEntrySchema.verified`'s doc comment in `@jini-ai/protocol`).
|
|
25
|
+
*/
|
|
26
|
+
trustRoot?: RegistryTrustRoot | undefined;
|
|
27
|
+
}
|
|
28
|
+
export declare class StaticRegistryBackend implements RegistryBackend {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly kind: RegistryBackendKind;
|
|
31
|
+
readonly trust: RegistryTrust;
|
|
32
|
+
protected readonly manifestData: RegistryManifest;
|
|
33
|
+
protected readonly trustRoot: RegistryTrustRoot | undefined;
|
|
34
|
+
constructor(options: StaticRegistryBackendOptions);
|
|
35
|
+
list(filter?: RegistryListFilter): Promise<RegistryEntry[]>;
|
|
36
|
+
search(input: RegistrySearchQuery): Promise<RegistrySearchResult[]>;
|
|
37
|
+
resolve(name: string, range?: string): Promise<ResolvedRegistryEntry | null>;
|
|
38
|
+
manifest(name: string, version: string): Promise<RegistryEntry | null>;
|
|
39
|
+
doctor(): Promise<RegistryDoctorReport>;
|
|
40
|
+
protected getManifest(): RegistryManifest;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validate a public `publish()` caller's whole request against the
|
|
44
|
+
* `RegistryPublishRequest` wire schema before any backend uses
|
|
45
|
+
* `request.entry`'s fields to build a file path, PR body, or a row that is
|
|
46
|
+
* persisted and later trusted to already be schema-shaped. Without this,
|
|
47
|
+
* `database-backend.ts`'s `publish()` could write a row that permanently
|
|
48
|
+
* breaks every future `list`/`search`/`resolve`/`doctor` call for the
|
|
49
|
+
* backend — those all re-read the table and throw on a row that fails
|
|
50
|
+
* `RegistryEntrySchema` (see `parseStoredEntry`) rather than silently
|
|
51
|
+
* dropping it, on the theory that data *this backend itself wrote* should
|
|
52
|
+
* always be well-formed; `publish()` is the one boundary that must enforce
|
|
53
|
+
* that theory rather than assume it.
|
|
54
|
+
*
|
|
55
|
+
* Shared across backends (not just `DatabaseRegistryBackend`) so
|
|
56
|
+
* `GithubRegistryBackend` also refuses to open a PR publishing a
|
|
57
|
+
* genuinely malformed entry into a shared external manifest. Backend-
|
|
58
|
+
* specific path/branch-name safety checks (`assertSafeEntryName`/
|
|
59
|
+
* `assertSafeVersion` in `github-backend.ts`) still run independently —
|
|
60
|
+
* this schema constrains `name`'s shape but not `version`'s character set,
|
|
61
|
+
* so it is necessary but not sufficient for path safety on its own.
|
|
62
|
+
*
|
|
63
|
+
* @param request - The public `publish()` caller's request object.
|
|
64
|
+
* @returns The schema-parsed (and thus schema-shaped) request.
|
|
65
|
+
* @throws If `request` does not conform to `RegistryPublishRequestSchema`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function assertValidPublishRequest(request: RegistryPublishRequest): RegistryPublishRequest;
|
|
68
|
+
//# sourceMappingURL=static-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-backend.d.ts","sourceRoot":"","sources":["../src/static-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAKL,KAAK,eA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