@kb-labs/marketplace-contracts 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @product-name/package-name
2
+
3
+ Baseline library package inside KB Labs Product Template.
4
+
5
+ ## Vision & Purpose
6
+
7
+ **@product-name/package-name** is a minimal example library shipped with `kb-labs-product-template`.
8
+ It shows how a typical package is structured (source, tests, types) and is intended to be **renamed or removed** when creating a real product.
9
+
10
+ ### Core Goals
11
+
12
+ - Demonstrate the standard KB Labs package layout (src/types/tests/build tooling)
13
+ - Provide a simple, testable function (`hello`) as a starting point
14
+ - Act as a safe playground for verifying DevKit configs (tsup, Vitest, ESLint)
15
+
16
+ ## Package Status
17
+
18
+ - **Version**: 0.1.0
19
+ - **Stage**: Template / Example
20
+ - **Status**: Not for Production ⚠️
21
+
22
+ ## Architecture
23
+
24
+ ### Structure
25
+
26
+ ```
27
+ packages/package-name/
28
+ ├── src/
29
+ │ ├── index.ts # Public entrypoint
30
+ │ └── types/ # Shared types and re-exports
31
+ │ ├── types.ts
32
+ │ └── index.ts
33
+ ├── index.test.ts # Vitest example
34
+ └── tsup.config.ts # Build configuration
35
+ ```
36
+
37
+ The default implementation is intentionally tiny:
38
+
39
+ ```ts
40
+ export const hello = (name = 'KB Labs') => `Hello, ${name}!`;
41
+ ```
42
+
43
+ ## Dependencies
44
+
45
+ ### Runtime
46
+
47
+ None by default — this is a pure TypeScript example.
48
+
49
+ ### Development
50
+
51
+ - `@kb-labs/devkit`: shared TS/ESLint/Vitest/TSUP presets
52
+ - `tsup`, `vitest`, `tsx`, `typescript`
53
+
54
+ ## Scripts
55
+
56
+ From the `kb-labs-product-template` root:
57
+
58
+ ```bash
59
+ pnpm --filter @product-name/package-name build
60
+ pnpm --filter @product-name/package-name test
61
+ pnpm --filter @product-name/package-name lint
62
+ ```
63
+
64
+ ## How to Adapt for a Real Package
65
+
66
+ When using the product template for your own project:
67
+
68
+ 1. Rename the package in `package.json` (e.g. `@kb-labs/my-product-core`).
69
+ 2. Replace the `hello` function with your actual public API.
70
+ 3. Update tests in `index.test.ts` to cover real behaviour.
71
+ 4. Adjust `types/` to expose the correct public types.
72
+
73
+ This package is meant as a scaffold only; don’t ship it as-is to production.
74
+
75
+
@@ -0,0 +1,198 @@
1
+ import { ManifestV3 } from '@kb-labs/plugin-contracts';
2
+ import { EntitySignature, EntityKind, MarketplaceEntry } from '@kb-labs/core-discovery';
3
+
4
+ /**
5
+ * @module @kb-labs/marketplace-contracts/types
6
+ * Shared types for the KB Labs marketplace ecosystem.
7
+ */
8
+
9
+ /**
10
+ * A resolved package ready to be installed.
11
+ */
12
+ interface ResolvedPackage {
13
+ /** Package identifier (@scope/name) */
14
+ id: string;
15
+ /** Resolved version (semver) */
16
+ version: string;
17
+ /** SRI integrity hash (sha256-...) */
18
+ integrity: string;
19
+ /** Platform-issued signature (from registry) */
20
+ signature?: EntitySignature;
21
+ /** How this package was sourced */
22
+ source: 'marketplace' | 'local';
23
+ /** Download URL (for registry-based sources) */
24
+ downloadUrl?: string;
25
+ }
26
+ /**
27
+ * Metadata about a successfully installed package.
28
+ */
29
+ interface InstalledPackage {
30
+ /** Package identifier */
31
+ id: string;
32
+ /** Installed version */
33
+ version: string;
34
+ /** Absolute path to the installed package root */
35
+ packageRoot: string;
36
+ /** Computed integrity hash */
37
+ integrity: string;
38
+ }
39
+ /**
40
+ * Brief listing entry for search results.
41
+ */
42
+ interface PackageListing {
43
+ id: string;
44
+ version: string;
45
+ description?: string;
46
+ primaryKind: EntityKind;
47
+ provides: EntityKind[];
48
+ signature?: EntitySignature;
49
+ }
50
+ /**
51
+ * Metadata required when publishing a package.
52
+ */
53
+ interface PublishMetadata {
54
+ id: string;
55
+ version: string;
56
+ description?: string;
57
+ primaryKind: EntityKind;
58
+ provides: EntityKind[];
59
+ }
60
+ /**
61
+ * Result of a publish operation.
62
+ */
63
+ interface PublishResult {
64
+ id: string;
65
+ version: string;
66
+ signature?: EntitySignature;
67
+ publishedAt: string;
68
+ }
69
+ /**
70
+ * Abstraction over the source of packages.
71
+ *
72
+ * Currently: NpmPackageSource (pnpm add/remove).
73
+ * Future: RegistryPackageSource (KB Labs marketplace registry API).
74
+ *
75
+ * MarketplaceService works through this interface — it never calls
76
+ * pnpm or any other package manager directly.
77
+ */
78
+ interface PackageSource {
79
+ /** Resolve a package spec (e.g., "@scope/pkg@^1.0.0") to installable metadata */
80
+ resolve(spec: string): Promise<ResolvedPackage>;
81
+ /** Install a resolved package into the workspace */
82
+ install(pkg: ResolvedPackage, root: string, opts?: {
83
+ dev?: boolean;
84
+ }): Promise<InstalledPackage>;
85
+ /** Remove a package from the workspace */
86
+ remove(packageId: string, root: string): Promise<void>;
87
+ /** Search available packages (optional — not all sources support it) */
88
+ search?(query: string, filter?: {
89
+ kind?: EntityKind;
90
+ }): Promise<PackageListing[]>;
91
+ /** Publish a package (optional — only registry source supports it) */
92
+ publish?(tarball: Buffer, metadata: PublishMetadata): Promise<PublishResult>;
93
+ }
94
+ /**
95
+ * Public read-only API of MarketplaceService exposed to strategies.
96
+ * Strategies must not depend on the full implementation.
97
+ */
98
+ /** Marketplace entry with its package ID (key from lock record). */
99
+ type MarketplaceEntryWithId = MarketplaceEntry & {
100
+ id: string;
101
+ };
102
+ interface MarketplaceServiceAPI {
103
+ /** List installed entries, optionally filtered by kind */
104
+ list(filter?: {
105
+ kind?: EntityKind;
106
+ }): Promise<MarketplaceEntryWithId[]>;
107
+ /** Get a single entry by package ID */
108
+ getEntry(packageId: string): Promise<MarketplaceEntry | null>;
109
+ }
110
+ /**
111
+ * Strategy for handling a specific entity kind in the marketplace.
112
+ *
113
+ * Each entity type (plugin, adapter, workflow, etc.) can have custom
114
+ * detection, extraction, and lifecycle hooks. Adding a new entity type
115
+ * means implementing this interface — zero changes to core.
116
+ */
117
+ interface EntityKindStrategy {
118
+ /** Which primary kind this strategy handles */
119
+ kind: EntityKind;
120
+ /**
121
+ * Detect whether a package at the given root is of this entity kind.
122
+ * Returns the kind if detected, null otherwise.
123
+ */
124
+ detectKind(packageRoot: string): Promise<EntityKind | null>;
125
+ /**
126
+ * Extract all entity kinds this package provides.
127
+ * Called after detectKind succeeds.
128
+ */
129
+ extractProvides(packageRoot: string): Promise<EntityKind[]>;
130
+ /**
131
+ * Post-install hook. Called after the package is installed and written to lock.
132
+ * Example: adapter strategy validates that required adapter dependencies are installed.
133
+ */
134
+ afterInstall?(packageId: string, packageRoot: string, service: MarketplaceServiceAPI): Promise<void>;
135
+ /**
136
+ * Pre-uninstall hook. Called before the package is removed.
137
+ * Example: adapter strategy checks if other adapters depend on this one.
138
+ */
139
+ beforeUninstall?(packageId: string, service: MarketplaceServiceAPI): Promise<void>;
140
+ }
141
+ /**
142
+ * Cached manifest entry. Stored in .kb/marketplace.manifests.json.
143
+ * Different entity types have different manifest shapes (ManifestV3, AdapterManifest).
144
+ * Caching avoids dynamic import on every discovery cycle.
145
+ */
146
+ interface ManifestCacheEntry {
147
+ /** Which manifest type is stored */
148
+ manifestType: 'plugin' | 'adapter';
149
+ /** The manifest data. Type depends on manifestType. */
150
+ manifest: ManifestV3 | Record<string, unknown>;
151
+ /** ISO timestamp of when this entry was cached */
152
+ cachedAt: string;
153
+ /** Integrity hash of the source package when cached. Stale if different from lock. */
154
+ integrity: string;
155
+ }
156
+ /**
157
+ * Full manifest cache file schema.
158
+ */
159
+ interface ManifestCache {
160
+ schema: 'kb.marketplace.manifests/1';
161
+ entries: Record<string, ManifestCacheEntry>;
162
+ }
163
+ interface InstallResultEntry {
164
+ id: string;
165
+ version: string;
166
+ primaryKind: EntityKind;
167
+ provides: EntityKind[];
168
+ packageRoot: string;
169
+ }
170
+ interface InstallResult {
171
+ installed: InstallResultEntry[];
172
+ warnings: string[];
173
+ }
174
+ interface SyncResult {
175
+ added: Array<{
176
+ id: string;
177
+ primaryKind: EntityKind;
178
+ version: string;
179
+ }>;
180
+ skipped: Array<{
181
+ id: string;
182
+ reason: string;
183
+ }>;
184
+ total: number;
185
+ }
186
+ interface DoctorIssue {
187
+ severity: 'error' | 'warning' | 'info';
188
+ packageId: string;
189
+ message: string;
190
+ remediation?: string;
191
+ }
192
+ interface DoctorReport {
193
+ ok: boolean;
194
+ total: number;
195
+ issues: DoctorIssue[];
196
+ }
197
+
198
+ export type { DoctorIssue, DoctorReport, EntityKindStrategy, InstallResult, InstallResultEntry, InstalledPackage, ManifestCache, ManifestCacheEntry, MarketplaceEntryWithId, MarketplaceServiceAPI, PackageListing, PackageSource, PublishMetadata, PublishResult, ResolvedPackage, SyncResult };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@kb-labs/marketplace-contracts",
3
+ "version": "0.1.1",
4
+ "description": "Shared types and interfaces for KB Labs marketplace",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": false,
20
+ "scripts": {
21
+ "clean": "rimraf dist",
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "type-check": "tsc --noEmit",
25
+ "lint": "eslint .",
26
+ "lint:fix": "eslint . --fix",
27
+ "test": "vitest run --passWithNoTests -c ../../vitest.config.ts",
28
+ "test:watch": "vitest -c ../../vitest.config.ts"
29
+ },
30
+ "dependencies": {
31
+ "@kb-labs/core-discovery": "^1.5.0",
32
+ "@kb-labs/plugin-contracts": "^1.3.0",
33
+ "@kb-labs/core-platform": "^1.5.0"
34
+ },
35
+ "devDependencies": {
36
+ "tsup": "^8.5.0",
37
+ "vitest": "^3.2.4",
38
+ "@kb-labs/devkit": "link:../../../../infra/kb-labs-devkit"
39
+ }
40
+ }