@ggui-ai/registry-core 0.1.0-rc.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.
Files changed (60) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +76 -0
  3. package/dist/impls/memory-bundle-storage.d.ts +12 -0
  4. package/dist/impls/memory-bundle-storage.d.ts.map +1 -0
  5. package/dist/impls/memory-bundle-storage.js +40 -0
  6. package/dist/impls/memory-registry-storage.d.ts +3 -0
  7. package/dist/impls/memory-registry-storage.d.ts.map +1 -0
  8. package/dist/impls/memory-registry-storage.js +154 -0
  9. package/dist/index.d.ts +26 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +26 -0
  12. package/dist/interfaces/authn.d.ts +51 -0
  13. package/dist/interfaces/authn.d.ts.map +1 -0
  14. package/dist/interfaces/authn.js +1 -0
  15. package/dist/interfaces/bundle-storage.d.ts +79 -0
  16. package/dist/interfaces/bundle-storage.d.ts.map +1 -0
  17. package/dist/interfaces/bundle-storage.js +1 -0
  18. package/dist/interfaces/registry-storage.d.ts +204 -0
  19. package/dist/interfaces/registry-storage.d.ts.map +1 -0
  20. package/dist/interfaces/registry-storage.js +19 -0
  21. package/dist/ops/compile.d.ts +48 -0
  22. package/dist/ops/compile.d.ts.map +1 -0
  23. package/dist/ops/compile.js +163 -0
  24. package/dist/ops/conformance.d.ts +154 -0
  25. package/dist/ops/conformance.d.ts.map +1 -0
  26. package/dist/ops/conformance.js +487 -0
  27. package/dist/ops/list-versions.d.ts +58 -0
  28. package/dist/ops/list-versions.d.ts.map +1 -0
  29. package/dist/ops/list-versions.js +60 -0
  30. package/dist/ops/publish.d.ts +70 -0
  31. package/dist/ops/publish.d.ts.map +1 -0
  32. package/dist/ops/publish.js +417 -0
  33. package/dist/ops/read.d.ts +52 -0
  34. package/dist/ops/read.d.ts.map +1 -0
  35. package/dist/ops/read.js +60 -0
  36. package/dist/ops/register-author-key.d.ts +22 -0
  37. package/dist/ops/register-author-key.d.ts.map +1 -0
  38. package/dist/ops/register-author-key.js +171 -0
  39. package/dist/ops/search.d.ts +50 -0
  40. package/dist/ops/search.d.ts.map +1 -0
  41. package/dist/ops/search.js +106 -0
  42. package/dist/testing/bundle-storage-contract.d.ts +3 -0
  43. package/dist/testing/bundle-storage-contract.d.ts.map +1 -0
  44. package/dist/testing/bundle-storage-contract.js +176 -0
  45. package/dist/testing/index.d.ts +10 -0
  46. package/dist/testing/index.d.ts.map +1 -0
  47. package/dist/testing/index.js +9 -0
  48. package/dist/testing/registry-storage-contract.d.ts +3 -0
  49. package/dist/testing/registry-storage-contract.d.ts.map +1 -0
  50. package/dist/testing/registry-storage-contract.js +392 -0
  51. package/dist/types.d.ts +482 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +110 -0
  54. package/dist/utils/base64.d.ts +15 -0
  55. package/dist/utils/base64.d.ts.map +1 -0
  56. package/dist/utils/base64.js +35 -0
  57. package/dist/utils/semver.d.ts +13 -0
  58. package/dist/utils/semver.d.ts.map +1 -0
  59. package/dist/utils/semver.js +69 -0
  60. package/package.json +85 -0
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 describing the origin of the Work and
141
+ 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 Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
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 2026 Loqu, Inc. (Guuey)
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
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @ggui-ai/registry-core
2
+
3
+ Pure-TypeScript registry operations + storage interfaces for the **ggui marketplace** — the shared business-logic layer behind the hosted ggui registry and the OSS-publishable [`@ggui-ai/registry-server`](https://github.com/ggui-ai/ggui/tree/main/packages/registry-server). No I/O, no HTTP, no cloud SDK — operations take typed inputs + a `{ storage, bundleStorage, authn, clock }` deps bag and return discriminated-union results.
4
+
5
+ ## Why this package exists
6
+
7
+ The registry's business logic — manifest validation, conformance gating, signature verification, version immutability — is identical regardless of where the registry runs. This package extracts that logic so:
8
+
9
+ - The hosted registry's transport layer is a thin shell over these ops.
10
+ - The OSS server is a [hono](https://hono.dev) + filesystem/memory adapter over the same ops.
11
+ - A third-party operator can build their own transport (Express, Fastify, gRPC) by implementing two storage interfaces.
12
+
13
+ ## Architecture
14
+
15
+ ```
16
+ @ggui-ai/registry-core (this package)
17
+ ├── interfaces/
18
+ │ ├── RegistryStorage — rows: artifacts, versions, compiled blobs, author keys
19
+ │ ├── BundleStorage — blobs: bundle, signature, manifest
20
+ │ └── AuthnContext — { subject: string } (vendor-neutral)
21
+ └── ops/
22
+ ├── publishArtifact — full publish flow with conformance + signing
23
+ ├── readArtifact — visibility-aware read + 410 on yanks
24
+ ├── listArtifactVersions — semver-ordered version timeline
25
+ ├── searchArtifacts — filtered scan over metadata rows
26
+ ├── registerAuthorKey — register a publisher Ed25519 public key
27
+ └── checkConformance — static manifest + bundle/source validation gates
28
+ ```
29
+
30
+ An "artifact" is the umbrella noun: the registry stores both **gadgets** (compiled UI components/hooks) and **blueprints** (TSX UI sources), discriminated by `kind`.
31
+
32
+ ## Quick start
33
+
34
+ ```ts
35
+ import {
36
+ publishArtifact,
37
+ inMemoryRegistryStorage,
38
+ inMemoryBundleStorage,
39
+ } from "@ggui-ai/registry-core";
40
+
41
+ const result = await publishArtifact(
42
+ { manifest, bundle: bundleB64, bundleSha384, signature },
43
+ {
44
+ storage: inMemoryRegistryStorage(),
45
+ bundleStorage: inMemoryBundleStorage({ bundleHost: "http://localhost:9001" }),
46
+ authn: { subject: "user-1" },
47
+ clock: () => new Date(),
48
+ registryHostname: "localhost:9001",
49
+ }
50
+ );
51
+
52
+ if (result.ok) {
53
+ console.log(result.body.installCommand);
54
+ } else {
55
+ console.error(result.status, result.body);
56
+ }
57
+ ```
58
+
59
+ ## Contract tests
60
+
61
+ Every storage impl runs the same contract suite, so behavior drift between impls is caught at the contract level:
62
+
63
+ ```ts
64
+ import { registryStorageContract } from "@ggui-ai/registry-core/testing";
65
+ import { inMemoryRegistryStorage } from "@ggui-ai/registry-core";
66
+
67
+ describe("memory impl", () => {
68
+ registryStorageContract(() => inMemoryRegistryStorage());
69
+ });
70
+ ```
71
+
72
+ The OSS filesystem adapter and the hosted adapter both run this suite.
73
+
74
+ ## License
75
+
76
+ Apache-2.0
@@ -0,0 +1,12 @@
1
+ import type { BundleStorage } from '../interfaces/bundle-storage.js';
2
+ export interface InMemoryBundleStorageOptions {
3
+ /**
4
+ * URL prefix for the composed `bundleUrl` / `signatureUrl` /
5
+ * `manifestUrl`. Should not have a trailing slash. Examples:
6
+ * - cloud parity: `https://dev.registry.sandbox.ggui.ai`
7
+ * - e2e (per-test): `http://127.0.0.1:<port>`
8
+ */
9
+ readonly bundleHost?: string;
10
+ }
11
+ export declare function inMemoryBundleStorage(options?: InMemoryBundleStorageOptions): BundleStorage;
12
+ //# sourceMappingURL=memory-bundle-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-bundle-storage.d.ts","sourceRoot":"","sources":["../../src/impls/memory-bundle-storage.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,WAAW,4BAA4B;IAC3C;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,aAAa,CA2Cf"}
@@ -0,0 +1,40 @@
1
+ export function inMemoryBundleStorage(options = {}) {
2
+ const bundleHost = options.bundleHost ?? 'https://example.invalid';
3
+ const bundles = new Map();
4
+ const signatures = new Map();
5
+ const manifests = new Map();
6
+ const key = (scope, name, version) => `${scope}/${name}/${version}`;
7
+ return {
8
+ async putBundle(scope, name, version, bytes) {
9
+ bundles.set(key(scope, name, version), new Uint8Array(bytes));
10
+ return this.bundleUrl(scope, name, version);
11
+ },
12
+ async getBundle(scope, name, version) {
13
+ const bytes = bundles.get(key(scope, name, version));
14
+ return bytes === undefined ? null : new Uint8Array(bytes);
15
+ },
16
+ async putSignature(scope, name, version, signature) {
17
+ signatures.set(key(scope, name, version), signature);
18
+ return this.signatureUrl(scope, name, version);
19
+ },
20
+ async getSignature(scope, name, version) {
21
+ return signatures.get(key(scope, name, version)) ?? null;
22
+ },
23
+ async putManifest(scope, name, version, manifest) {
24
+ manifests.set(key(scope, name, version), manifest);
25
+ return this.manifestUrl(scope, name, version);
26
+ },
27
+ async getManifest(scope, name, version) {
28
+ return manifests.get(key(scope, name, version)) ?? null;
29
+ },
30
+ bundleUrl(scope, name, version) {
31
+ return `${bundleHost}/bundles/${scope}/${name}/${version}/bundle.js`;
32
+ },
33
+ signatureUrl(scope, name, version) {
34
+ return `${bundleHost}/bundles/${scope}/${name}/${version}/bundle.js.sig`;
35
+ },
36
+ manifestUrl(scope, name, version) {
37
+ return `${bundleHost}/bundles/${scope}/${name}/${version}/manifest.json`;
38
+ },
39
+ };
40
+ }
@@ -0,0 +1,3 @@
1
+ import { type RegistryStorage } from '../interfaces/registry-storage.js';
2
+ export declare function inMemoryRegistryStorage(): RegistryStorage;
3
+ //# sourceMappingURL=memory-registry-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-registry-storage.d.ts","sourceRoot":"","sources":["../../src/impls/memory-registry-storage.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,mCAAmC,CAAC;AAK3C,wBAAgB,uBAAuB,IAAI,eAAe,CAwGzD"}
@@ -0,0 +1,154 @@
1
+ import { AuthorKeyAlreadyExistsError, } from '../interfaces/registry-storage.js';
2
+ const DEFAULT_LIMIT = 50;
3
+ const MAX_LIMIT = 200;
4
+ export function inMemoryRegistryStorage() {
5
+ const metadata = new Map();
6
+ const versions = new Map();
7
+ const authorKeys = new Map();
8
+ const compiledBlobs = new Map();
9
+ const versionKey = (artifactId, version) => `${artifactId}@${version}`;
10
+ const authorKey = (subject, keyId) => `${subject}/${keyId}`;
11
+ return {
12
+ async getArtifactMetadata(artifactId) {
13
+ return metadata.get(artifactId) ?? null;
14
+ },
15
+ async putArtifactMetadata(row) {
16
+ metadata.set(row.artifactId, row);
17
+ },
18
+ async scanArtifacts(filter) {
19
+ const rows = Array.from(metadata.values()).filter((row) => rowMatchesFilter(row, filter));
20
+ const limit = clampLimit(filter.limit);
21
+ const offset = parseCursor(filter.cursor);
22
+ const page = rows.slice(offset, offset + limit);
23
+ const nextOffset = offset + page.length;
24
+ const nextCursor = nextOffset < rows.length ? String(nextOffset) : undefined;
25
+ return { rows: page, nextCursor };
26
+ },
27
+ async getArtifactVersion(artifactId, version) {
28
+ return versions.get(versionKey(artifactId, version)) ?? null;
29
+ },
30
+ async listArtifactVersions(artifactId) {
31
+ // Walk the version map and pick the rows whose composite key
32
+ // starts with `<artifactId>@`. The `@` separator is safe because
33
+ // it's reserved in semver (versions never contain `@`) and
34
+ // `artifactId` always contains `/` (never `@`), so the boundary
35
+ // is unambiguous.
36
+ const prefix = `${artifactId}@`;
37
+ const matches = [];
38
+ for (const [key, row] of versions) {
39
+ if (key.startsWith(prefix))
40
+ matches.push(row);
41
+ }
42
+ return matches;
43
+ },
44
+ async putArtifactVersionIfAbsent(row) {
45
+ const key = versionKey(row.artifactId, row.version);
46
+ if (versions.has(key)) {
47
+ return { ok: false, reason: 'version_exists' };
48
+ }
49
+ versions.set(key, row);
50
+ return { ok: true };
51
+ },
52
+ async yankArtifactVersion(artifactId, version) {
53
+ const key = versionKey(artifactId, version);
54
+ const existing = versions.get(key);
55
+ if (existing === undefined)
56
+ return;
57
+ versions.set(key, { ...existing, yanked: true });
58
+ },
59
+ async getCompiledBlob(compiledDigest) {
60
+ return compiledBlobs.get(compiledDigest) ?? null;
61
+ },
62
+ async commitVersionAndBlob(versionRow, blobRow) {
63
+ // Atomic write — the in-memory impl is structurally atomic via
64
+ // the JS event loop. We pre-check both conditions BEFORE
65
+ // mutating either map so a version-row conflict leaves BOTH
66
+ // maps untouched (mirrors the DDB transaction's all-or-nothing
67
+ // semantics from the caller's perspective).
68
+ const vKey = versionKey(versionRow.artifactId, versionRow.version);
69
+ if (versions.has(vKey)) {
70
+ return { ok: false, reason: 'version_exists' };
71
+ }
72
+ const existingBlob = compiledBlobs.get(blobRow.compiledDigest);
73
+ if (existingBlob === undefined) {
74
+ // New-blob path — both rows INSERT.
75
+ versions.set(vKey, versionRow);
76
+ compiledBlobs.set(blobRow.compiledDigest, blobRow);
77
+ return { ok: true, mode: 'new-blob' };
78
+ }
79
+ // Dedup path — version INSERT + refCount bump on existing blob.
80
+ versions.set(vKey, versionRow);
81
+ compiledBlobs.set(blobRow.compiledDigest, {
82
+ ...existingBlob,
83
+ refCount: existingBlob.refCount + 1,
84
+ });
85
+ return { ok: true, mode: 'dedup' };
86
+ },
87
+ async getAuthorKey(subject, keyId) {
88
+ return authorKeys.get(authorKey(subject, keyId)) ?? null;
89
+ },
90
+ async putAuthorKey(row, options) {
91
+ const key = authorKey(row.subject, row.keyId);
92
+ if (options?.ifNotExists === true && authorKeys.has(key)) {
93
+ throw new AuthorKeyAlreadyExistsError(row.subject, row.keyId);
94
+ }
95
+ authorKeys.set(key, row);
96
+ },
97
+ async listAuthorKeys(subject) {
98
+ const prefix = `${subject}/`;
99
+ const matches = [];
100
+ for (const [key, row] of authorKeys) {
101
+ if (key.startsWith(prefix))
102
+ matches.push(row);
103
+ }
104
+ return matches;
105
+ },
106
+ };
107
+ }
108
+ function clampLimit(limit) {
109
+ if (limit === undefined)
110
+ return DEFAULT_LIMIT;
111
+ if (!Number.isInteger(limit))
112
+ return DEFAULT_LIMIT;
113
+ if (limit < 1)
114
+ return 1;
115
+ if (limit > MAX_LIMIT)
116
+ return MAX_LIMIT;
117
+ return limit;
118
+ }
119
+ function parseCursor(cursor) {
120
+ if (cursor === undefined || cursor.length === 0)
121
+ return 0;
122
+ const n = Number.parseInt(cursor, 10);
123
+ if (!Number.isInteger(n) || n < 0)
124
+ return 0;
125
+ return n;
126
+ }
127
+ function rowMatchesFilter(row, q) {
128
+ if (q.kind !== undefined && row.kind !== q.kind)
129
+ return false;
130
+ if (q.hook !== undefined && row.hook !== q.hook)
131
+ return false;
132
+ if (q.tag !== undefined) {
133
+ if (row.tags === undefined || !row.tags.includes(q.tag))
134
+ return false;
135
+ }
136
+ if (q.author !== undefined) {
137
+ const matchesSub = row.publishedBy === q.author;
138
+ const matchesName = row.authorName !== undefined &&
139
+ row.authorName.toLowerCase().includes(q.author.toLowerCase());
140
+ if (!matchesSub && !matchesName)
141
+ return false;
142
+ }
143
+ if (q.q !== undefined) {
144
+ const needle = q.q.toLowerCase();
145
+ const slashIdx = row.artifactId.indexOf('/');
146
+ const namePart = slashIdx >= 0 ? row.artifactId.slice(slashIdx + 1) : row.artifactId;
147
+ const inName = namePart.toLowerCase().includes(needle);
148
+ const inDescription = row.description !== undefined && row.description.toLowerCase().includes(needle);
149
+ const inTags = row.tags !== undefined && row.tags.some((t) => t.toLowerCase().includes(needle));
150
+ if (!inName && !inDescription && !inTags)
151
+ return false;
152
+ }
153
+ return true;
154
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `@ggui-ai/registry-core` — pure-TS registry operations + storage
3
+ * interfaces for the ggui marketplace.
4
+ *
5
+ * The hosted ggui registry and the OSS `@ggui-ai/registry-server` both
6
+ * import from here. The transport layer (a managed API gateway, hono)
7
+ * handles the HTTP envelope + auth verification; registry-core handles
8
+ * row-shape + business logic.
9
+ */
10
+ export type { AuthnContext } from './interfaces/authn.js';
11
+ export type { BundleStorage } from './interfaces/bundle-storage.js';
12
+ export { AuthorKeyAlreadyExistsError, type PutAuthorKeyOptions, type RegistryStorage, } from './interfaces/registry-storage.js';
13
+ export { ARTIFACTS_METADATA_SK, type ArtifactKind, type ArtifactScanFilter, type ArtifactVersionRow, type ArtifactsMetadataRow, type AuthorKeyRow, type CompiledBlobRow, type ErrorBody, LIST_VERSIONS_ERROR_CODES, type ListVersionsErrorBody, type ListVersionsErrorCode, type ListVersionsResponse, PUBLISH_ERROR_CODES, type PublishErrorBody, type PublishErrorCode, type PublishRequestBody, type PublishResponseBody, READ_ERROR_CODES, type ReadErrorBody, type ReadErrorCode, type ReadPkgResponse, REGISTER_AUTHOR_KEY_ERROR_CODES, type RegisterAuthorKeyErrorBody, type RegisterAuthorKeyErrorCode, type RegisterAuthorKeyRequestBody, type RegisterAuthorKeyResponseBody, SEARCH_ERROR_CODES, SEARCH_SORT_OPTIONS, type SearchErrorBody, type SearchErrorCode, type SearchResponse, type SearchResultEntry, type SearchSort, type VersionListEntry, type Visibility, } from './types.js';
14
+ export { BLUEPRINT_EXTERNAL_MODULES, compileBlueprint, compiledDigestHex, type CompileBlueprintErr, type CompileBlueprintOk, type CompileBlueprintResult, } from './ops/compile.js';
15
+ export { checkConformance, MAX_BLUEPRINT_SOURCE_BYTES, type BlueprintProbeRunner, type ConformanceError, type ConformanceErrorCode, type ConformanceFailureCode, type ConformanceRequestPayload, type ConformanceResponseBody, } from './ops/conformance.js';
16
+ export { publishArtifact, MAX_BUNDLE_BYTES, type PublishArtifactDeps, type PublishArtifactInput, type PublishArtifactResult, } from './ops/publish.js';
17
+ export { readArtifact, type ReadArtifactDeps, type ReadArtifactInput, type ReadArtifactResult, } from './ops/read.js';
18
+ export { listArtifactVersions, type ListArtifactVersionsDeps, type ListArtifactVersionsInput, type ListArtifactVersionsResult, } from './ops/list-versions.js';
19
+ export { searchArtifacts, type SearchArtifactsDeps, type SearchArtifactsInput, type SearchArtifactsResult, } from './ops/search.js';
20
+ export { registerAuthorKey, type RegisterAuthorKeyDeps, type RegisterAuthorKeyInput, type RegisterAuthorKeyResult, } from './ops/register-author-key.js';
21
+ export { inMemoryRegistryStorage } from './impls/memory-registry-storage.js';
22
+ export { inMemoryBundleStorage, type InMemoryBundleStorageOptions, } from './impls/memory-bundle-storage.js';
23
+ export { compareSemver } from './utils/semver.js';
24
+ export { base64Encode, safeBase64Decode, sha384Base64 } from './utils/base64.js';
25
+ export type { Ed25519Signature, GadgetSignature } from '@ggui-ai/gadget-signing';
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EACL,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,+BAA+B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,GAChC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,KAAK,4BAA4B,GAClC,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKjF,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `@ggui-ai/registry-core` — pure-TS registry operations + storage
3
+ * interfaces for the ggui marketplace.
4
+ *
5
+ * The hosted ggui registry and the OSS `@ggui-ai/registry-server` both
6
+ * import from here. The transport layer (a managed API gateway, hono)
7
+ * handles the HTTP envelope + auth verification; registry-core handles
8
+ * row-shape + business logic.
9
+ */
10
+ export { AuthorKeyAlreadyExistsError, } from './interfaces/registry-storage.js';
11
+ // Types — rows + wire shapes
12
+ export { ARTIFACTS_METADATA_SK, LIST_VERSIONS_ERROR_CODES, PUBLISH_ERROR_CODES, READ_ERROR_CODES, REGISTER_AUTHOR_KEY_ERROR_CODES, SEARCH_ERROR_CODES, SEARCH_SORT_OPTIONS, } from './types.js';
13
+ // Operations
14
+ export { BLUEPRINT_EXTERNAL_MODULES, compileBlueprint, compiledDigestHex, } from './ops/compile.js';
15
+ export { checkConformance, MAX_BLUEPRINT_SOURCE_BYTES, } from './ops/conformance.js';
16
+ export { publishArtifact, MAX_BUNDLE_BYTES, } from './ops/publish.js';
17
+ export { readArtifact, } from './ops/read.js';
18
+ export { listArtifactVersions, } from './ops/list-versions.js';
19
+ export { searchArtifacts, } from './ops/search.js';
20
+ export { registerAuthorKey, } from './ops/register-author-key.js';
21
+ // In-memory impls
22
+ export { inMemoryRegistryStorage } from './impls/memory-registry-storage.js';
23
+ export { inMemoryBundleStorage, } from './impls/memory-bundle-storage.js';
24
+ // Utils
25
+ export { compareSemver } from './utils/semver.js';
26
+ export { base64Encode, safeBase64Decode, sha384Base64 } from './utils/base64.js';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Post-verification authenticated caller context.
3
+ *
4
+ * Vendor-neutral — registry-core's API never names a specific identity
5
+ * provider (no JWT, no bearer, no cloud-vendor enum). Verification is
6
+ * transport-specific: cloud handlers verify a JWT from the platform's
7
+ * hosted auth surface and produce an `AuthnContext`; the OSS server
8
+ * verifies a bearer token and produces an `AuthnContext`. Once
9
+ * registry-core has the context, it only knows WHO is calling, not
10
+ * HOW they proved it.
11
+ *
12
+ * Authz decisions (org membership, role checks) happen above this
13
+ * layer — registry-core treats the subject as a stable opaque caller
14
+ * identity and uses it as the partition key for AuthorKeys lookups +
15
+ * the `publishedBy` field on rows.
16
+ *
17
+ * ## Protocol & Contract Bar
18
+ *
19
+ * **Parties:** the registry transport (cloud Lambda or OSS hono
20
+ * server) is the producer; registry-core's ops are the consumer.
21
+ *
22
+ * **Obligations:** the producer MUST verify the caller's credentials
23
+ * (JWT signature, bearer-token constant-time compare, …) before
24
+ * constructing this context. Registry-core takes the subject on
25
+ * trust — if the transport constructs an `AuthnContext` without
26
+ * verification, every downstream invariant breaks (the registry would
27
+ * mint rows on behalf of arbitrary callers).
28
+ *
29
+ * **Failure mode:** the transport returns 401/403 BEFORE invoking a
30
+ * registry-core op. Registry-core operations MAY accept an
31
+ * `AuthnContext | undefined` parameter when the operation has a
32
+ * public-readable path (read, search public artifacts); the op then
33
+ * branches internally on the visibility of the requested row.
34
+ *
35
+ * **Observable violation:** if a registry op writes a row with
36
+ * `publishedBy: ctx.subject` and the row is later retrieved + the
37
+ * subject doesn't correspond to a real identity in the transport's
38
+ * verification system, the row is forged — visible to the operator
39
+ * via audit logs that show no matching credential issued for that
40
+ * subject.
41
+ */
42
+ export interface AuthnContext {
43
+ /**
44
+ * Stable, opaque caller identity. Cloud transport: hosted-auth `sub`
45
+ * claim. OSS bearer: a configured user identifier the operator chose
46
+ * to associate with the token (or a hash of the token itself when no
47
+ * identifier is configured).
48
+ */
49
+ readonly subject: string;
50
+ }
51
+ //# sourceMappingURL=authn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authn.d.ts","sourceRoot":"","sources":["../../src/interfaces/authn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1 @@
1
+ export {};