@forumone/throughline-plugin-contract 0.2.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 +16 -0
- package/dist/auth.d.ts +19 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +2 -0
- package/dist/auth.js.map +1 -0
- package/dist/example-plugin-pattern.d.ts +12 -0
- package/dist/example-plugin-pattern.d.ts.map +1 -0
- package/dist/example-plugin-pattern.js +58 -0
- package/dist/example-plugin-pattern.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +42 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +2 -0
- package/dist/mcp.js.map +1 -0
- package/dist/registry.d.ts +23 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +51 -0
- package/dist/registry.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @forumone/throughline-plugin-contract
|
|
2
|
+
|
|
3
|
+
Shared type contracts every Throughline core plugin satisfies, plus the cross-plugin runtime registry. Core packages import from here so the plugin surface stays consistent across the framework. It is published because every core plugin imports `getPluginRegistry` from it at runtime.
|
|
4
|
+
|
|
5
|
+
## What's in here
|
|
6
|
+
|
|
7
|
+
- `CorePlugin<Options>` — the Payload plugin signature every core package exports
|
|
8
|
+
- `BaseCorePluginOptions` — options every plugin accepts (`enabled`, `routePrefix`, `logger`)
|
|
9
|
+
- `McpToolDefinition`, `McpToolContext`, `McpMeta` — the MCP server surface
|
|
10
|
+
- `McpAuthenticator`, `McpAuthResult`, `AuthenticatedUser` — shared bearer-token auth types
|
|
11
|
+
- `getPluginRegistry` — the runtime registry plugins use to announce themselves and check for sibling plugins
|
|
12
|
+
- `examplePlugin` — a reference implementation showing the exact shape every future plugin follows
|
|
13
|
+
|
|
14
|
+
## Authoring a plugin
|
|
15
|
+
|
|
16
|
+
See `docs/building-plugins.md` at the repo root.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AuthenticatedUser } from './mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates an incoming MCP request and resolves the caller's identity.
|
|
4
|
+
* Plugins accept an optional `authenticator` option; if omitted they fall
|
|
5
|
+
* back to the default Payload bearer-token authenticator.
|
|
6
|
+
*/
|
|
7
|
+
export interface McpAuthenticator {
|
|
8
|
+
/**
|
|
9
|
+
* Inspects the `Authorization` header on the request and returns an
|
|
10
|
+
* {@link McpAuthResult} if the token is valid, or `null` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
authenticate(request: Request): Promise<McpAuthResult | null>;
|
|
13
|
+
}
|
|
14
|
+
export interface McpAuthResult {
|
|
15
|
+
user: AuthenticatedUser;
|
|
16
|
+
apiKeyName: string;
|
|
17
|
+
apiKeyId: string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CAC9D;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB"}
|
package/dist/auth.js
ADDED
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BaseCorePluginOptions, CorePlugin } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* EXAMPLE ONLY — not a real plugin. Reference implementation showing the
|
|
4
|
+
* shape every Throughline core plugin follows. Every future plugin should
|
|
5
|
+
* lift this structure and fill in the feature-specific parts.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExamplePluginOptions extends BaseCorePluginOptions {
|
|
8
|
+
/** A plugin-specific option. */
|
|
9
|
+
greeting?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const examplePlugin: CorePlugin<ExamplePluginOptions>;
|
|
12
|
+
//# sourceMappingURL=example-plugin-pattern.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-plugin-pattern.d.ts","sourceRoot":"","sources":["../src/example-plugin-pattern.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGnE;;;;GAIG;AAEH,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAKD,eAAO,MAAM,aAAa,EAAE,UAAU,CAAC,oBAAoB,CAuD1D,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getPluginRegistry } from './registry.js';
|
|
2
|
+
const EXAMPLE_PLUGIN_ID = '@forumone/throughline-example';
|
|
3
|
+
const EXAMPLE_PLUGIN_VERSION = '0.0.0';
|
|
4
|
+
export const examplePlugin = (options) => {
|
|
5
|
+
return (incomingConfig) => {
|
|
6
|
+
// Step 1 — honour the disabled flag before doing any work.
|
|
7
|
+
if (options.enabled === false)
|
|
8
|
+
return incomingConfig;
|
|
9
|
+
// Step 2 — apply defaults. Note: route prefixes here MUST NOT include
|
|
10
|
+
// `/api` — Payload mounts top-level endpoints under its API base
|
|
11
|
+
// (default `/api`), so the user-facing URL becomes `/api/example/mcp`.
|
|
12
|
+
const greeting = options.greeting ?? 'Hello';
|
|
13
|
+
const routePrefix = options.routePrefix ?? '/example';
|
|
14
|
+
// Step 3 — extend the incoming config by spreading and appending.
|
|
15
|
+
// Never replace existing arrays; always concatenate.
|
|
16
|
+
return {
|
|
17
|
+
...incomingConfig,
|
|
18
|
+
collections: [
|
|
19
|
+
...(incomingConfig.collections ?? []),
|
|
20
|
+
// Plugin's own collections go here.
|
|
21
|
+
],
|
|
22
|
+
endpoints: [
|
|
23
|
+
...(incomingConfig.endpoints ?? []),
|
|
24
|
+
{
|
|
25
|
+
path: `${routePrefix}/mcp`,
|
|
26
|
+
method: 'post',
|
|
27
|
+
handler: async () => {
|
|
28
|
+
// Real plugins delegate this to an MCP server implementation.
|
|
29
|
+
return new Response(JSON.stringify({ greeting }), {
|
|
30
|
+
headers: { 'content-type': 'application/json' },
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
hooks: {
|
|
36
|
+
...(incomingConfig.hooks ?? {}),
|
|
37
|
+
afterError: [
|
|
38
|
+
...(incomingConfig.hooks?.afterError ?? []),
|
|
39
|
+
// Plugin's global error hooks go here.
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
onInit: async (payload) => {
|
|
43
|
+
// Always run any pre-existing onInit first so plugins compose cleanly.
|
|
44
|
+
if (incomingConfig.onInit) {
|
|
45
|
+
await incomingConfig.onInit(payload);
|
|
46
|
+
}
|
|
47
|
+
// Announce presence and assert required capabilities from siblings.
|
|
48
|
+
const registry = getPluginRegistry(payload);
|
|
49
|
+
registry.register({
|
|
50
|
+
id: EXAMPLE_PLUGIN_ID,
|
|
51
|
+
version: EXAMPLE_PLUGIN_VERSION,
|
|
52
|
+
capabilities: ['example'],
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=example-plugin-pattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example-plugin-pattern.js","sourceRoot":"","sources":["../src/example-plugin-pattern.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAajD,MAAM,iBAAiB,GAAG,+BAA+B,CAAA;AACzD,MAAM,sBAAsB,GAAG,OAAO,CAAA;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAqC,CAAC,OAAO,EAAE,EAAE;IACzE,OAAO,CAAC,cAAsB,EAAU,EAAE;QACxC,2DAA2D;QAC3D,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK;YAAE,OAAO,cAAc,CAAA;QAEpD,sEAAsE;QACtE,iEAAiE;QACjE,uEAAuE;QACvE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAA;QAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,UAAU,CAAA;QAErD,kEAAkE;QAClE,8DAA8D;QAC9D,OAAO;YACL,GAAG,cAAc;YACjB,WAAW,EAAE;gBACX,GAAG,CAAC,cAAc,CAAC,WAAW,IAAI,EAAE,CAAC;gBACrC,oCAAoC;aACrC;YACD,SAAS,EAAE;gBACT,GAAG,CAAC,cAAc,CAAC,SAAS,IAAI,EAAE,CAAC;gBACnC;oBACE,IAAI,EAAE,GAAG,WAAW,MAAM;oBAC1B,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,KAAK,IAAI,EAAE;wBAClB,8DAA8D;wBAC9D,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE;4BAChD,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;yBAChD,CAAC,CAAA;oBACJ,CAAC;iBACF;aACF;YACD,KAAK,EAAE;gBACL,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC/B,UAAU,EAAE;oBACV,GAAG,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,IAAI,EAAE,CAAC;oBAC3C,uCAAuC;iBACxC;aACF;YACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBACxB,uEAAuE;gBACvE,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;oBAC1B,MAAM,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;gBACtC,CAAC;gBAED,oEAAoE;gBACpE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAA;gBAC3C,QAAQ,CAAC,QAAQ,CAAC;oBAChB,EAAE,EAAE,iBAAiB;oBACrB,OAAO,EAAE,sBAAsB;oBAC/B,YAAY,EAAE,CAAC,SAAS,CAAC;iBAC1B,CAAC,CAAA;YACJ,CAAC;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Plugin } from 'payload';
|
|
2
|
+
/**
|
|
3
|
+
* Options every Throughline core plugin accepts. Plugin-specific options
|
|
4
|
+
* extend this interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseCorePluginOptions {
|
|
7
|
+
/** Enable or disable the plugin without removing it from the config. Defaults to `true`. */
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Route prefix the plugin mounts its MCP server and API endpoints under.
|
|
11
|
+
* Defaults to a plugin-specific value (e.g. `/api/publishing`). Override
|
|
12
|
+
* to avoid collisions or to expose under a different path.
|
|
13
|
+
*/
|
|
14
|
+
routePrefix?: string;
|
|
15
|
+
/** Logger used for plugin diagnostics. Falls back to a console logger if omitted. */
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
}
|
|
18
|
+
export interface Logger {
|
|
19
|
+
debug: (message: string, context?: Record<string, unknown>) => void;
|
|
20
|
+
info: (message: string, context?: Record<string, unknown>) => void;
|
|
21
|
+
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
22
|
+
error: (message: string, context?: Record<string, unknown>) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The Throughline core plugin signature. A plugin takes its options and
|
|
26
|
+
* returns a standard Payload {@link Plugin}.
|
|
27
|
+
*/
|
|
28
|
+
export type CorePlugin<Options extends BaseCorePluginOptions = BaseCorePluginOptions> = (options: Options) => Plugin;
|
|
29
|
+
export * from './mcp.js';
|
|
30
|
+
export * from './auth.js';
|
|
31
|
+
export * from './registry.js';
|
|
32
|
+
export * from './example-plugin-pattern.js';
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,4FAA4F;IAC5F,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IACnE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAClE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAClE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CACpE;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,IAAI,CACtF,OAAO,EAAE,OAAO,KACb,MAAM,CAAA;AAEX,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,6BAA6B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkCA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,6BAA6B,CAAA"}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Logger } from './index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A single tool exposed by a Throughline MCP server.
|
|
5
|
+
*/
|
|
6
|
+
export interface McpToolDefinition<Input extends z.ZodType = z.ZodType, Output = unknown> {
|
|
7
|
+
/** The tool's name as exposed to the MCP client. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Human-readable description the MCP client uses to decide when to call this tool. */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Zod schema for the input; used for validation and for generating the MCP tool schema. */
|
|
12
|
+
inputSchema: Input;
|
|
13
|
+
/** Handler invoked with validated input plus per-request context. */
|
|
14
|
+
handler: (input: z.infer<Input>, context: McpToolContext) => Promise<Output>;
|
|
15
|
+
}
|
|
16
|
+
export interface McpToolContext {
|
|
17
|
+
/** The user identified by the API key used for this request. */
|
|
18
|
+
user: AuthenticatedUser | null;
|
|
19
|
+
/** The API key's name, for audit logging. */
|
|
20
|
+
apiKeyName: string;
|
|
21
|
+
/** The session ID from the MCP client, if provided. */
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
/** Request-scoped logger. */
|
|
24
|
+
logger: Logger;
|
|
25
|
+
}
|
|
26
|
+
export interface AuthenticatedUser {
|
|
27
|
+
id: string;
|
|
28
|
+
email: string;
|
|
29
|
+
name: string;
|
|
30
|
+
roles: string[];
|
|
31
|
+
groups: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Optional `_meta` parameters clients may pass alongside consequential tool calls.
|
|
35
|
+
* Consumed by the audit system to capture prompt and reasoning context.
|
|
36
|
+
*/
|
|
37
|
+
export interface McpMeta {
|
|
38
|
+
userPrompt?: string;
|
|
39
|
+
reasoning?: string;
|
|
40
|
+
changesSummary?: string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAExC;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IACtF,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAA;IACZ,uFAAuF;IACvF,WAAW,EAAE,MAAM,CAAA;IACnB,4FAA4F;IAC5F,WAAW,EAAE,KAAK,CAAA;IAClB,qEAAqE;IACrE,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC7E;AAED,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAC9B,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAA;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
|
package/dist/mcp.js
ADDED
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lightweight registry plugins use to announce their presence and discover
|
|
3
|
+
* sibling plugins. Attached to the Payload instance via a symbol so it does
|
|
4
|
+
* not pollute the public API surface.
|
|
5
|
+
*/
|
|
6
|
+
export interface PluginRegistryEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
version: string;
|
|
9
|
+
capabilities: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface PluginRegistry {
|
|
12
|
+
register(entry: PluginRegistryEntry): void;
|
|
13
|
+
has(id: string): boolean;
|
|
14
|
+
get(id: string): PluginRegistryEntry | undefined;
|
|
15
|
+
list(): PluginRegistryEntry[];
|
|
16
|
+
requireCapability(capability: string, requiredBy: string): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns the registry attached to the given target (typically the Payload
|
|
20
|
+
* instance passed to `onInit`). Creates and attaches one on first access.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getPluginRegistry(target: object): PluginRegistry;
|
|
23
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAA;IAC1C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAA;IACxB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAAA;IAChD,IAAI,IAAI,mBAAmB,EAAE,CAAA;IAC7B,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAChE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAahE"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lightweight registry plugins use to announce their presence and discover
|
|
3
|
+
* sibling plugins. Attached to the Payload instance via a symbol so it does
|
|
4
|
+
* not pollute the public API surface.
|
|
5
|
+
*/
|
|
6
|
+
const REGISTRY_SYMBOL = Symbol.for('@forumone/throughline/plugin-registry');
|
|
7
|
+
/**
|
|
8
|
+
* Returns the registry attached to the given target (typically the Payload
|
|
9
|
+
* instance passed to `onInit`). Creates and attaches one on first access.
|
|
10
|
+
*/
|
|
11
|
+
export function getPluginRegistry(target) {
|
|
12
|
+
const host = target;
|
|
13
|
+
const existing = host[REGISTRY_SYMBOL];
|
|
14
|
+
if (existing)
|
|
15
|
+
return existing;
|
|
16
|
+
const registry = createRegistry();
|
|
17
|
+
Object.defineProperty(target, REGISTRY_SYMBOL, {
|
|
18
|
+
value: registry,
|
|
19
|
+
enumerable: false,
|
|
20
|
+
writable: false,
|
|
21
|
+
configurable: false,
|
|
22
|
+
});
|
|
23
|
+
return registry;
|
|
24
|
+
}
|
|
25
|
+
function createRegistry() {
|
|
26
|
+
const entries = new Map();
|
|
27
|
+
return {
|
|
28
|
+
register(entry) {
|
|
29
|
+
if (entries.has(entry.id)) {
|
|
30
|
+
throw new Error(`Plugin ${entry.id} is already registered`);
|
|
31
|
+
}
|
|
32
|
+
entries.set(entry.id, entry);
|
|
33
|
+
},
|
|
34
|
+
has(id) {
|
|
35
|
+
return entries.has(id);
|
|
36
|
+
},
|
|
37
|
+
get(id) {
|
|
38
|
+
return entries.get(id);
|
|
39
|
+
},
|
|
40
|
+
list() {
|
|
41
|
+
return Array.from(entries.values());
|
|
42
|
+
},
|
|
43
|
+
requireCapability(capability, requiredBy) {
|
|
44
|
+
const providers = Array.from(entries.values()).filter((entry) => entry.capabilities.includes(capability));
|
|
45
|
+
if (providers.length === 0) {
|
|
46
|
+
throw new Error(`Plugin ${requiredBy} requires capability "${capability}", but no registered plugin provides it.`);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;AAgB3E;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,IAAI,GAAG,MAAoD,CAAA;IACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,CAAA;IACtC,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAA;IACjC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,EAAE;QAC7C,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IACF,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,cAAc;IACrB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA+B,CAAA;IAEtD,OAAO;QACL,QAAQ,CAAC,KAAK;YACZ,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE,wBAAwB,CAAC,CAAA;YAC7D,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;QAC9B,CAAC;QACD,GAAG,CAAC,EAAE;YACJ,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACxB,CAAC;QACD,GAAG,CAAC,EAAE;YACJ,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACxB,CAAC;QACD,IAAI;YACF,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QACrC,CAAC;QACD,iBAAiB,CAAC,UAAU,EAAE,UAAU;YACtC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAC9D,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CACxC,CAAA;YACD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,UAAU,UAAU,yBAAyB,UAAU,0CAA0C,CAClG,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forumone/throughline-plugin-contract",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Shared plugin and MCP contract types and the cross-plugin registry for @forumone/throughline core packages.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/forumone/throughline.git",
|
|
9
|
+
"directory": "packages/plugin-contract"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/forumone/throughline/tree/main/packages/plugin-contract#readme",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -b",
|
|
29
|
+
"dev": "tsc -b -w",
|
|
30
|
+
"clean": "rm -rf dist .turbo *.tsbuildinfo",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint src"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"payload": "^3.0.0",
|
|
36
|
+
"zod": "^3.23.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@forumone/throughline-eslint-config": "workspace:*",
|
|
40
|
+
"@forumone/throughline-tsconfig": "workspace:*",
|
|
41
|
+
"@types/node": "^20.17.0",
|
|
42
|
+
"eslint": "^9.15.0",
|
|
43
|
+
"typescript": "^5.6.0"
|
|
44
|
+
}
|
|
45
|
+
}
|