@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.
@@ -0,0 +1,281 @@
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 { RegistryEntrySchema, RegistryListFilterSchema, RegistryPublishRequestSchema, RegistrySearchQuerySchema, } from '@jini-ai/protocol';
12
+ import { parseRegistrySpecifier, resolveRegistryEntryVersion } from './versioning.js';
13
+ import { verifyRegistryEntrySignatures } from './trust.js';
14
+ export class StaticRegistryBackend {
15
+ id;
16
+ kind;
17
+ trust;
18
+ manifestData;
19
+ trustRoot;
20
+ constructor(options) {
21
+ this.id = options.id;
22
+ this.kind = options.kind ?? 'http';
23
+ this.trust = options.trust;
24
+ this.manifestData = options.manifest;
25
+ this.trustRoot = options.trustRoot;
26
+ }
27
+ async list(filter) {
28
+ const parsedFilter = RegistryListFilterSchema.parse(filter);
29
+ let entries = validEntries(this.getManifest());
30
+ if (!parsedFilter?.includeYanked) {
31
+ entries = entries.filter((entry) => !entry.yanked);
32
+ }
33
+ if (parsedFilter?.publisher) {
34
+ const publisher = parsedFilter.publisher.toLowerCase();
35
+ entries = entries.filter((entry) => entry.publisher?.id?.toLowerCase() === publisher || entry.publisher?.github?.toLowerCase() === publisher);
36
+ }
37
+ if (parsedFilter?.tags && parsedFilter.tags.length > 0) {
38
+ const tags = parsedFilter.tags.map((tag) => tag.toLowerCase());
39
+ entries = entries.filter((entry) => {
40
+ const entryTags = new Set((entry.tags ?? []).map((tag) => tag.toLowerCase()));
41
+ return tags.every((tag) => entryTags.has(tag));
42
+ });
43
+ }
44
+ if (parsedFilter?.query) {
45
+ const terms = parsedFilter.query.toLowerCase().split(/\s+/g).filter(Boolean);
46
+ if (terms.length > 0) {
47
+ entries = entries.filter((entry) => terms.some((term) => searchHaystack(entry).includes(term)));
48
+ }
49
+ }
50
+ return entries;
51
+ }
52
+ async search(input) {
53
+ const query = RegistrySearchQuerySchema.parse(input);
54
+ const terms = query.query.toLowerCase().split(/\s+/g).filter(Boolean);
55
+ const tags = new Set((query.tags ?? []).map((tag) => tag.toLowerCase()));
56
+ // Pass `includeYanked` through to `list` so search honors the same
57
+ // filter contract instead of unconditionally dropping yanked entries.
58
+ const entries = await this.list({ includeYanked: query.includeYanked });
59
+ const results = [];
60
+ for (const entry of entries) {
61
+ if (tags.size > 0) {
62
+ const entryTags = new Set((entry.tags ?? []).map((tag) => tag.toLowerCase()));
63
+ if (![...tags].every((tag) => entryTags.has(tag)))
64
+ continue;
65
+ }
66
+ const haystack = searchHaystack(entry);
67
+ const matched = terms.filter((term) => haystack.includes(term));
68
+ if (terms.length > 0 && matched.length === 0)
69
+ continue;
70
+ results.push({
71
+ entry,
72
+ score: terms.length === 0 ? 0 : matched.length / terms.length,
73
+ matched,
74
+ });
75
+ }
76
+ return results
77
+ .sort((left, right) => right.score - left.score || left.entry.name.localeCompare(right.entry.name))
78
+ .slice(0, query.limit ?? 100);
79
+ }
80
+ async resolve(name, range) {
81
+ const parsed = parseRegistrySpecifier(range ? `${name}@${range}` : name);
82
+ const entry = validEntries(this.getManifest()).find((candidate) => candidate.name.toLowerCase() === parsed.name.toLowerCase());
83
+ if (!entry)
84
+ return null;
85
+ const resolvedVersion = resolveRegistryEntryVersion(entry, parsed.range);
86
+ if (!resolvedVersion)
87
+ return null;
88
+ // Additive alongside `trust`: never replaces or narrows the
89
+ // backend-configured trust level above, which is still stamped exactly
90
+ // as before. A backend with no `trustRoot` configured (the unchanged
91
+ // default) always resolves `verified: false` here without attempting
92
+ // any cryptographic work — see `trust.ts`'s `verifyRegistryEntrySignatures`.
93
+ const verification = verifyRegistryEntrySignatures(entry, this.trustRoot);
94
+ return {
95
+ backendId: this.id,
96
+ backendKind: this.kind,
97
+ trust: this.trust,
98
+ verified: verification.verified,
99
+ ...(verification.verified && verification.issuer ? { verifiedIssuer: verification.issuer } : {}),
100
+ ...(verification.verified && verification.subject ? { verifiedSubject: verification.subject } : {}),
101
+ entry,
102
+ version: {
103
+ version: resolvedVersion.version,
104
+ source: resolvedVersion.source,
105
+ ref: resolvedVersion.ref,
106
+ integrity: resolvedVersion.archiveIntegrity,
107
+ manifestDigest: resolvedVersion.manifestDigest,
108
+ deprecated: resolvedVersion.deprecated,
109
+ },
110
+ source: resolvedVersion.source,
111
+ ref: resolvedVersion.ref,
112
+ integrity: resolvedVersion.archiveIntegrity,
113
+ manifestDigest: resolvedVersion.manifestDigest,
114
+ };
115
+ }
116
+ async manifest(name, version) {
117
+ const resolved = await this.resolve(name, version);
118
+ return resolved?.entry ?? null;
119
+ }
120
+ async doctor() {
121
+ const issues = [];
122
+ // Deliberately audits the RAW manifest entries (not the `validEntries()`
123
+ // schema-filtered set `list`/`search`/`resolve` use) — doctor's whole
124
+ // purpose is to surface malformed data, so silently dropping a bad entry
125
+ // before doctor sees it would hide exactly the issue it exists to report.
126
+ // Because these are RAW/unvalidated entries (a caller can hand a
127
+ // manifest object that never went through `RegistryManifestSchema`),
128
+ // every field is guarded before it is dereferenced — a value that isn't
129
+ // even a plausible object (null/array/primitive) is reported as
130
+ // malformed instead of throwing out of `doctor()` itself.
131
+ //
132
+ // The manifest *envelope* itself gets the same treatment: a backend can
133
+ // hand this class a manifest whose `entries` isn't even an array at all
134
+ // (e.g. `GithubRegistryBackend` reads a JSON file from a remote, less-
135
+ // trusted source through an injected client with no schema guarantee).
136
+ // Report that as one explicit issue instead of letting `for...of` throw
137
+ // a bare `TypeError` out of a caller-facing diagnostic method.
138
+ const rawEntries = manifestEntriesRaw(this.getManifest());
139
+ if (!Array.isArray(rawEntries)) {
140
+ issues.push({
141
+ severity: 'error',
142
+ code: 'malformed-manifest',
143
+ message: 'Registry manifest "entries" is missing or not an array; no entries could be checked.',
144
+ });
145
+ }
146
+ const entries = Array.isArray(rawEntries) ? rawEntries : [];
147
+ for (const raw of entries) {
148
+ const value = raw;
149
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
150
+ issues.push({
151
+ severity: 'error',
152
+ code: 'malformed-entry',
153
+ message: 'Registry entry is not a valid object and could not be checked.',
154
+ });
155
+ continue;
156
+ }
157
+ const candidate = value;
158
+ const name = typeof candidate.name === 'string' ? candidate.name : undefined;
159
+ if (!name || !/^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*$/.test(name)) {
160
+ issues.push({
161
+ severity: 'error',
162
+ code: 'invalid-name',
163
+ message: 'Registry entry name must be vendor/name.',
164
+ pluginName: name,
165
+ });
166
+ }
167
+ const dist = candidate.dist && typeof candidate.dist === 'object' ? candidate.dist : undefined;
168
+ if (!candidate.source && !dist?.archive) {
169
+ issues.push({
170
+ severity: 'error',
171
+ code: 'missing-source',
172
+ message: 'Registry entry must provide source or dist.archive.',
173
+ pluginName: name,
174
+ });
175
+ }
176
+ if (!candidate.license) {
177
+ issues.push({
178
+ severity: 'warning',
179
+ code: 'missing-license',
180
+ message: 'Registry entry should declare a license.',
181
+ pluginName: name,
182
+ });
183
+ }
184
+ const capabilitiesSummary = Array.isArray(candidate.capabilitiesSummary) ? candidate.capabilitiesSummary : undefined;
185
+ if (!capabilitiesSummary || capabilitiesSummary.length === 0) {
186
+ issues.push({
187
+ severity: 'warning',
188
+ code: 'missing-capabilities',
189
+ message: 'Registry entry should summarize its capabilities.',
190
+ pluginName: name,
191
+ });
192
+ }
193
+ if (candidate.yanked && !candidate.yankReason) {
194
+ issues.push({
195
+ severity: 'error',
196
+ code: 'missing-yank-reason',
197
+ message: 'Yanked entries must keep a human-readable reason.',
198
+ pluginName: name,
199
+ });
200
+ }
201
+ }
202
+ return {
203
+ ok: !issues.some((issue) => issue.severity === 'error'),
204
+ backendId: this.id,
205
+ checkedAt: Date.now(),
206
+ entriesChecked: entries.length,
207
+ issues,
208
+ };
209
+ }
210
+ getManifest() {
211
+ return this.manifestData;
212
+ }
213
+ }
214
+ /**
215
+ * @internal Extract a manifest's raw `entries` value without assuming it is
216
+ * an array. `RegistryManifestSchema` guarantees that shape for anything that
217
+ * went through it, but a backend may hand this class a manifest that never
218
+ * did (a raw JSON file read from a remote/less-trusted source, a host-
219
+ * constructed object typed but not runtime-checked). Returns whatever the
220
+ * value actually is so callers can decide how to report "not an array."
221
+ */
222
+ function manifestEntriesRaw(manifest) {
223
+ return manifest?.entries;
224
+ }
225
+ /** @internal Drop any manifest entry that fails the wire schema rather than let a malformed entry propagate. Also
226
+ * tolerates a manifest whose `entries` isn't an array at all — treated as no entries rather than a crash. */
227
+ function validEntries(manifest) {
228
+ const rawEntries = manifestEntriesRaw(manifest);
229
+ const entries = Array.isArray(rawEntries) ? rawEntries : [];
230
+ return entries.flatMap((entry) => {
231
+ const parsed = RegistryEntrySchema.safeParse(entry);
232
+ return parsed.success ? [parsed.data] : [];
233
+ });
234
+ }
235
+ /**
236
+ * Validate a public `publish()` caller's whole request against the
237
+ * `RegistryPublishRequest` wire schema before any backend uses
238
+ * `request.entry`'s fields to build a file path, PR body, or a row that is
239
+ * persisted and later trusted to already be schema-shaped. Without this,
240
+ * `database-backend.ts`'s `publish()` could write a row that permanently
241
+ * breaks every future `list`/`search`/`resolve`/`doctor` call for the
242
+ * backend — those all re-read the table and throw on a row that fails
243
+ * `RegistryEntrySchema` (see `parseStoredEntry`) rather than silently
244
+ * dropping it, on the theory that data *this backend itself wrote* should
245
+ * always be well-formed; `publish()` is the one boundary that must enforce
246
+ * that theory rather than assume it.
247
+ *
248
+ * Shared across backends (not just `DatabaseRegistryBackend`) so
249
+ * `GithubRegistryBackend` also refuses to open a PR publishing a
250
+ * genuinely malformed entry into a shared external manifest. Backend-
251
+ * specific path/branch-name safety checks (`assertSafeEntryName`/
252
+ * `assertSafeVersion` in `github-backend.ts`) still run independently —
253
+ * this schema constrains `name`'s shape but not `version`'s character set,
254
+ * so it is necessary but not sufficient for path safety on its own.
255
+ *
256
+ * @param request - The public `publish()` caller's request object.
257
+ * @returns The schema-parsed (and thus schema-shaped) request.
258
+ * @throws If `request` does not conform to `RegistryPublishRequestSchema`.
259
+ */
260
+ export function assertValidPublishRequest(request) {
261
+ const parsed = RegistryPublishRequestSchema.safeParse(request);
262
+ if (!parsed.success) {
263
+ throw new Error(`Invalid registry publish request: ${parsed.error.message}`);
264
+ }
265
+ return parsed.data;
266
+ }
267
+ /** @internal The lowercase, space-joined text `list`/`search` match query terms against. */
268
+ function searchHaystack(entry) {
269
+ return [
270
+ entry.name,
271
+ entry.title ?? '',
272
+ entry.description ?? '',
273
+ ...(entry.tags ?? []),
274
+ ...(entry.capabilitiesSummary ?? []),
275
+ entry.publisher?.id ?? '',
276
+ entry.publisher?.github ?? '',
277
+ ]
278
+ .join(' ')
279
+ .toLowerCase();
280
+ }
281
+ //# sourceMappingURL=static-backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-backend.js","sourceRoot":"","sources":["../src/static-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,GAY1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,6BAA6B,EAA0B,MAAM,YAAY,CAAC;AAkBnF,MAAM,OAAO,qBAAqB;IACvB,EAAE,CAAS;IACX,IAAI,CAAsB;IAC1B,KAAK,CAAgB;IAEX,YAAY,CAAmB;IAC/B,SAAS,CAAgC;IAE5D,YAAY,OAAqC;QAC/C,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAA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AK,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE;QACzB,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE;KAC9B;SACE,IAAI,CAAC,GAAG,CAAC;SACT,WAAW,EAAE,CAAC;AACnB,CAAC"}
@@ -0,0 +1,94 @@
1
+ import type { RegistryEntry, RegistrySignature } from '@jini-ai/protocol';
2
+ /** GitHub Actions' own OIDC token issuer — the default {@link GithubOidcTrustRoot.allowedIssuers} entry. */
3
+ export declare const GITHUB_ACTIONS_OIDC_ISSUER = "https://token.actions.githubusercontent.com";
4
+ /**
5
+ * Host-supplied trust anchor for `kind: 'github-oidc'` signatures. Modeled
6
+ * as a constructor option on each backend (`StaticRegistryBackendOptions.trustRoot`,
7
+ * `GithubRegistryBackendOptions.trustRoot`, `DatabaseRegistryBackendOptions.trustRoot`)
8
+ * — matching how `trust` itself is already a constructor option, per this
9
+ * task's sign-off decision 3.
10
+ */
11
+ export interface GithubOidcTrustRoot {
12
+ /**
13
+ * PEM-encoded CA certificate(s) a signing certificate must chain to.
14
+ * Required — without at least one, `github-oidc` signatures cannot be
15
+ * cryptographically verified and are always reported `verified: false`
16
+ * (never silently trusted). May be Sigstore's public Fulcio root, a
17
+ * private/enterprise equivalent, or any other CA the host chooses.
18
+ */
19
+ caCertificates: string[];
20
+ /**
21
+ * Allowlisted OIDC issuer URL(s) checked against the signature's own
22
+ * `issuer` field. Defaults to `[GITHUB_ACTIONS_OIDC_ISSUER]` when omitted.
23
+ * This is a declarative check on self-reported metadata, not a
24
+ * cryptographic one — see the module doc comment.
25
+ */
26
+ allowedIssuers?: string[];
27
+ /**
28
+ * Allowlisted signer identities, matched against the *certificate's own*
29
+ * `subjectAltName` URI entries (e.g.
30
+ * `https://github.com/OWNER/REPO/.github/workflows/WORKFLOW.yml@REF`,
31
+ * the shape GitHub Artifact Attestations certificates use) — a
32
+ * cryptographically real, cert-bound value, not the signature's
33
+ * self-reported `subject` field. A plain string must match exactly; a
34
+ * `RegExp` is tested against each SAN URI. When omitted, any identity
35
+ * whose certificate chains to a configured CA is accepted (the CA chain
36
+ * alone is the trust boundary).
37
+ */
38
+ allowedIdentities?: Array<string | RegExp>;
39
+ }
40
+ /** Per-kind trust roots. Only `githubOidc` is implemented in v1 (see the module doc comment). */
41
+ export interface RegistryTrustRoot {
42
+ githubOidc?: GithubOidcTrustRoot;
43
+ }
44
+ /** Outcome of verifying one {@link RegistrySignature} against a {@link RegistryTrustRoot}. Never thrown — always returned. */
45
+ export interface SignatureVerificationResult {
46
+ verified: boolean;
47
+ /** The signature kind this result is about. Omitted only when an entry has no signatures to report on at all. */
48
+ kind?: RegistrySignature['kind'];
49
+ /** Present when `verified` is `false` — a human-readable, non-throwing reason. */
50
+ reason?: string;
51
+ /** Present when `verified` is `true` — the signature's self-reported `issuer` field. */
52
+ issuer?: string;
53
+ /** Present when `verified` is `true` — the signature's self-reported `subject` field, falling back to the certificate's own first SAN identity when the signature didn't declare one. */
54
+ subject?: string;
55
+ }
56
+ /**
57
+ * The exact string a `github-oidc` signature's `signature` bytes must cover.
58
+ * `@jini-ai/protocol`'s `RegistrySignatureSchema` does not itself define a
59
+ * canonical signing payload (it only models the wire shape of a signature),
60
+ * so this is this package's own convention: `name@version:digest`, where
61
+ * `digest` is whichever integrity/manifest-digest field the entry declares.
62
+ * Exported so a future signing tool can compute the exact same string this
63
+ * verifier checks against, rather than the two drifting independently.
64
+ *
65
+ * @param entry - The registry entry the signature is claimed to cover.
66
+ * @returns The canonical UTF-8 string the signature must be a valid signature over.
67
+ */
68
+ export declare function canonicalRegistrySigningPayload(entry: RegistryEntry): string;
69
+ /**
70
+ * Verify one {@link RegistrySignature} against a host-configured
71
+ * {@link RegistryTrustRoot}. Never throws — a malformed certificate,
72
+ * unparseable signature, or missing trust root all resolve to
73
+ * `verified: false` with a `reason`, matching this package's existing
74
+ * "never crash a caller-facing read on untrusted input" convention (see
75
+ * `static-backend.ts`'s `validEntries()`/`doctor()`).
76
+ *
77
+ * @param entry - The entry the signature is claimed to cover (used to derive {@link canonicalRegistrySigningPayload}).
78
+ * @param signature - One entry of `entry.signatures`.
79
+ * @param trustRoot - The backend's configured trust root, if any.
80
+ * @returns The verification outcome; check `.verified` before trusting `.issuer`/`.subject`.
81
+ */
82
+ export declare function verifyRegistrySignature(entry: RegistryEntry, signature: RegistrySignature, trustRoot: RegistryTrustRoot | undefined): SignatureVerificationResult;
83
+ /**
84
+ * Verify every signature on `entry` against `trustRoot`, returning the first
85
+ * result that verifies, or (if none do) the last failure — so a caller gets
86
+ * a meaningful `reason` even when an entry declares multiple signatures and
87
+ * all fail.
88
+ *
89
+ * @param entry - The entry to verify.
90
+ * @param trustRoot - The backend's configured trust root, if any.
91
+ * @returns The first verifying result, or the last failing one.
92
+ */
93
+ export declare function verifyRegistryEntrySignatures(entry: RegistryEntry, trustRoot: RegistryTrustRoot | undefined): SignatureVerificationResult;
94
+ //# sourceMappingURL=trust.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust.d.ts","sourceRoot":"","sources":["../src/trust.ts"],"names":[],"mappings":"AA+EA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,4GAA4G;AAC5G,eAAO,MAAM,0BAA0B,gDAAgD,CAAC;AAExF;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CAC5C;AAED,iGAAiG;AACjG,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAED,8HAA8H;AAC9H,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,iHAAiH;IACjH,IAAI,CAA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