@usebetterdev/contract 0.5.0 → 0.6.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 usebetter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,4 +1,4 @@
1
- import type { PluginDefinition } from "@usebetterdev/plugin";
1
+ import type { PluginDefinition } from "./plugin-types.js";
2
2
  /** Retention policy controlling automatic and CLI-driven purge of old audit logs. */
3
3
  export interface RetentionPolicy {
4
4
  /** Purge entries older than this many days. Must be a positive integer. */
@@ -1 +1 @@
1
- {"version":3,"file":"config-types-audit.d.ts","sourceRoot":"","sources":["../src/config-types-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,yHAAyH;IACzH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC9B"}
1
+ {"version":3,"file":"config-types-audit.d.ts","sourceRoot":"","sources":["../src/config-types-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,yHAAyH;IACzH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC9B"}
@@ -1,4 +1,4 @@
1
- import type { PluginDefinition } from "@usebetterdev/plugin";
1
+ import type { PluginDefinition } from "./plugin-types.js";
2
2
  /** Telemetry options. On by default; set enabled: false to opt out. */
3
3
  export interface TelemetryConfig {
4
4
  enabled?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"config-types-tenant.d.ts","sourceRoot":"","sources":["../src/config-types-tenant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,uEAAuE;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,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,yEAAyE;AACzE,MAAM,MAAM,uBAAuB,GAAG,OAAO,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,yDAAyD;AACzD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,6EAA6E;AAC7E,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAAC;IACnC,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC,GAAG,CAAC,EAAE,MAAM,GAAG,uBAAuB,CAAC;CACxC;AAED,qDAAqD;AACrD,MAAM,WAAW,wBAAwB;IACvC,cAAc,CAAC,EAAE,0BAA0B,CAAC;IAC5C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,sIAAsI;IACtI,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B"}
@@ -1,4 +1,4 @@
1
- import { PluginDefinition } from '@usebetterdev/plugin';
1
+ import { PluginDefinition } from './plugin-types.cjs';
2
2
 
3
3
  /** Telemetry options. On by default; set enabled: false to opt out. */
4
4
  interface TelemetryConfig {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/** Permission levels for console access. */\nexport type ConsolePermission = \"read\" | \"write\" | \"admin\";\n\n/** Minimal session info exposed to product handlers. */\nexport interface ConsoleProductSession {\n id: string;\n email: string;\n permissions: ConsolePermission;\n}\n\n/**\n * Request object passed to product endpoint handlers.\n * Constructed by the console after authentication — session is always present.\n */\nexport interface ConsoleProductRequest {\n params: Record<string, string>;\n query: Record<string, string>;\n body: unknown;\n session: ConsoleProductSession;\n}\n\n/** Standardized response from endpoint handlers. */\nexport interface ConsoleResponse {\n status: number;\n body: unknown;\n headers?: Record<string, string>;\n}\n\n/** A single endpoint registered by a product. */\nexport interface ConsoleProductEndpoint {\n method: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\";\n /** Path relative to the product mount, e.g. \"/tenants\" or \"/logs/:id\". */\n path: string;\n handler: (request: ConsoleProductRequest) => Promise<ConsoleResponse>;\n requiredPermission?: ConsolePermission;\n}\n\n/** Product definition registered with the console. */\nexport interface ConsoleProduct {\n /** Short identifier, e.g. \"tenant\", \"audit\". */\n id: string;\n /** Display name, e.g. \"Better Tenant\". */\n name: string;\n endpoints: ConsoleProductEndpoint[];\n}\n\n/** Interface products use to register with the console. */\nexport interface ConsoleRegistration {\n registerProduct(product: ConsoleProduct): void;\n}\n\n// Re-export well-known endpoint types\nexport type {\n HealthResponse,\n CapabilitiesResponse,\n SessionInitRequest,\n SessionInitResponse,\n SessionVerifyRequest,\n SessionVerifyResponse,\n SessionPollRequest,\n SessionPollResponse,\n SessionClaimRequest,\n SessionClaimResponse,\n} from \"./wellknown-types.js\";\n\n// Re-export wire-format types for product endpoints\nexport type {\n ConsoleErrorResponse,\n AuditLogWire,\n AuditLogsResponse,\n AuditLogResponse,\n AuditStatsResponse,\n AuditEnrichmentSummary,\n AuditEnrichmentsResponse,\n AuditPurgeResponse,\n AuditPurgeRequest,\n AuditLogsQuery,\n AuditStatsQuery,\n TenantWire,\n TenantsResponse,\n TenantResponse,\n CreateTenantRequest,\n UpdateTenantRequest,\n TenantStatsResponse,\n TenantsQuery,\n} from \"./product-types.js\";\n\n// Re-export shared config types\nexport type {\n TelemetryConfig,\n PathResolverConfig,\n SubdomainResolverConfig,\n RetentionPolicy,\n StaticJwtResolverConfig,\n StaticTenantResolverConfig,\n BetterTenantStaticConfig,\n BetterAuditStaticConfig,\n StaticMagicLinkConfig,\n StaticConsoleSessionConfig,\n BetterConsoleStaticConfig,\n BetterConfig,\n} from \"./config-types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/** Permission levels for console access. */\nexport type ConsolePermission = \"read\" | \"write\" | \"admin\";\n\n/** Minimal session info exposed to product handlers. */\nexport interface ConsoleProductSession {\n id: string;\n email: string;\n permissions: ConsolePermission;\n}\n\n/**\n * Request object passed to product endpoint handlers.\n * Constructed by the console after authentication — session is always present.\n */\nexport interface ConsoleProductRequest {\n params: Record<string, string>;\n query: Record<string, string>;\n body: unknown;\n session: ConsoleProductSession;\n}\n\n/** Standardized response from endpoint handlers. */\nexport interface ConsoleResponse {\n status: number;\n body: unknown;\n headers?: Record<string, string>;\n}\n\n/** A single endpoint registered by a product. */\nexport interface ConsoleProductEndpoint {\n method: \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\";\n /** Path relative to the product mount, e.g. \"/tenants\" or \"/logs/:id\". */\n path: string;\n handler: (request: ConsoleProductRequest) => Promise<ConsoleResponse>;\n requiredPermission?: ConsolePermission;\n}\n\n/** Product definition registered with the console. */\nexport interface ConsoleProduct {\n /** Short identifier, e.g. \"tenant\", \"audit\". */\n id: string;\n /** Display name, e.g. \"Better Tenant\". */\n name: string;\n endpoints: ConsoleProductEndpoint[];\n}\n\n/** Interface products use to register with the console. */\nexport interface ConsoleRegistration {\n registerProduct(product: ConsoleProduct): void;\n}\n\n// Re-export well-known endpoint types\nexport type {\n HealthResponse,\n CapabilitiesResponse,\n SessionInitRequest,\n SessionInitResponse,\n SessionVerifyRequest,\n SessionVerifyResponse,\n SessionPollRequest,\n SessionPollResponse,\n SessionClaimRequest,\n SessionClaimResponse,\n} from \"./wellknown-types.js\";\n\n// Re-export wire-format types for product endpoints\nexport type {\n ConsoleErrorResponse,\n AuditLogWire,\n AuditLogsResponse,\n AuditLogResponse,\n AuditStatsResponse,\n AuditEnrichmentSummary,\n AuditEnrichmentsResponse,\n AuditPurgeResponse,\n AuditPurgeRequest,\n AuditLogsQuery,\n AuditStatsQuery,\n TenantWire,\n TenantsResponse,\n TenantResponse,\n CreateTenantRequest,\n UpdateTenantRequest,\n TenantStatsResponse,\n TenantsQuery,\n} from \"./product-types.js\";\n\n// Re-export plugin types\nexport type {\n HookContract,\n HookHandlers,\n PluginContext,\n FieldType,\n PluginFieldDefinition,\n PluginTableDefinition,\n PluginSchema,\n HttpMethod,\n PluginRequestContext,\n PluginResponse,\n PluginEndpointHandler,\n PluginEndpoint,\n PluginDefinition,\n} from \"./plugin-types.js\";\n\n// Re-export shared config types\nexport type {\n TelemetryConfig,\n PathResolverConfig,\n SubdomainResolverConfig,\n RetentionPolicy,\n StaticJwtResolverConfig,\n StaticTenantResolverConfig,\n BetterTenantStaticConfig,\n BetterAuditStaticConfig,\n StaticMagicLinkConfig,\n StaticConsoleSessionConfig,\n BetterConsoleStaticConfig,\n BetterConfig,\n} from \"./config-types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { AuditEnrichmentSummary, AuditEnrichmentsResponse, AuditLogResponse, AuditLogWire, AuditLogsQuery, AuditLogsResponse, AuditPurgeRequest, AuditPurgeResponse, AuditStatsQuery, AuditStatsResponse, C as CapabilitiesResponse, ConsoleErrorResponse, ConsolePermission, a as ConsoleProduct, b as ConsoleProductEndpoint, c as ConsoleProductRequest, d as ConsoleProductSession, e as ConsoleRegistration, f as ConsoleResponse, CreateTenantRequest, H as HealthResponse, S as SessionClaimRequest, g as SessionClaimResponse, h as SessionInitRequest, i as SessionInitResponse, j as SessionPollRequest, k as SessionPollResponse, l as SessionVerifyRequest, m as SessionVerifyResponse, TenantResponse, TenantStatsResponse, TenantWire, TenantsQuery, TenantsResponse, UpdateTenantRequest } from './product-types.cjs';
2
+ export { FieldType, HookContract, HookHandlers, HttpMethod, PluginContext, PluginDefinition, PluginEndpoint, PluginEndpointHandler, PluginFieldDefinition, PluginRequestContext, PluginResponse, PluginSchema, PluginTableDefinition } from './plugin-types.cjs';
2
3
  export { BetterAuditStaticConfig, BetterConfig, BetterConsoleStaticConfig, BetterTenantStaticConfig, PathResolverConfig, RetentionPolicy, StaticConsoleSessionConfig, StaticJwtResolverConfig, StaticMagicLinkConfig, StaticTenantResolverConfig, SubdomainResolverConfig, TelemetryConfig } from './config-types.cjs';
3
- import '@usebetterdev/plugin';
package/dist/index.d.ts CHANGED
@@ -44,5 +44,6 @@ export interface ConsoleRegistration {
44
44
  }
45
45
  export type { HealthResponse, CapabilitiesResponse, SessionInitRequest, SessionInitResponse, SessionVerifyRequest, SessionVerifyResponse, SessionPollRequest, SessionPollResponse, SessionClaimRequest, SessionClaimResponse, } from "./wellknown-types.js";
46
46
  export type { ConsoleErrorResponse, AuditLogWire, AuditLogsResponse, AuditLogResponse, AuditStatsResponse, AuditEnrichmentSummary, AuditEnrichmentsResponse, AuditPurgeResponse, AuditPurgeRequest, AuditLogsQuery, AuditStatsQuery, TenantWire, TenantsResponse, TenantResponse, CreateTenantRequest, UpdateTenantRequest, TenantStatsResponse, TenantsQuery, } from "./product-types.js";
47
+ export type { HookContract, HookHandlers, PluginContext, FieldType, PluginFieldDefinition, PluginTableDefinition, PluginSchema, HttpMethod, PluginRequestContext, PluginResponse, PluginEndpointHandler, PluginEndpoint, PluginDefinition, } from "./plugin-types.js";
47
48
  export type { TelemetryConfig, PathResolverConfig, SubdomainResolverConfig, RetentionPolicy, StaticJwtResolverConfig, StaticTenantResolverConfig, BetterTenantStaticConfig, BetterAuditStaticConfig, StaticMagicLinkConfig, StaticConsoleSessionConfig, BetterConsoleStaticConfig, BetterConfig, } from "./config-types.js";
48
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC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AAe,EACf,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,EACzB,YAAY,GACb,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/plugin-types.ts
17
+ var plugin_types_exports = {};
18
+ module.exports = __toCommonJS(plugin_types_exports);
19
+ //# sourceMappingURL=plugin-types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin-types.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Hook system\n// ---------------------------------------------------------------------------\n\n/**\n * A contract mapping hook names to their payload shapes.\n * Products define this to declare what hooks are available.\n *\n * Example:\n * ```ts\n * type MyHooks = {\n * \"tenant:created\": { tenantId: string; name: string };\n * \"tenant:deleted\": { tenantId: string };\n * };\n * ```\n */\nexport type HookContract = Record<string, Record<string, unknown>>;\n\n/**\n * Derives handler function signatures from a HookContract.\n * Each key becomes a handler that receives the corresponding payload.\n */\nexport type HookHandlers<T extends HookContract> = {\n [K in keyof T]: (payload: T[K]) => void | Promise<void>;\n};\n\n// ---------------------------------------------------------------------------\n// Plugin context\n// ---------------------------------------------------------------------------\n\n/**\n * Runtime context passed to plugin init functions.\n * Provides product identity, peer plugin awareness, and configuration.\n */\nexport interface PluginContext {\n productId: string;\n hasPlugin: (id: string) => boolean;\n config: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Schema types (declarative table/field definitions)\n// ---------------------------------------------------------------------------\n\n/** Common database column types that plugins can declare. */\nexport type FieldType = \"string\" | \"number\" | \"boolean\" | \"date\" | \"json\";\n\n/** A single column definition within a plugin table. */\nexport interface PluginFieldDefinition {\n type: FieldType;\n required?: boolean;\n unique?: boolean;\n defaultValue?: string | number | boolean | null | (() => unknown);\n references?: {\n table: string;\n field: string;\n onDelete?: \"cascade\" | \"restrict\" | \"set-null\" | \"no-action\";\n };\n index?: boolean;\n}\n\n/** A single table definition declared by a plugin. Keyed by field name. */\nexport interface PluginTableDefinition {\n fields: Record<string, PluginFieldDefinition>;\n}\n\n/**\n * Schema declaration for a plugin.\n * `tables` declares new tables (keyed by table name).\n * `extend` adds fields to existing product tables (keyed by table name, then field name).\n */\nexport interface PluginSchema {\n tables?: Record<string, PluginTableDefinition>;\n extend?: Record<string, Record<string, PluginFieldDefinition>>;\n}\n\n// ---------------------------------------------------------------------------\n// Endpoint types (declarative HTTP endpoint definitions)\n// ---------------------------------------------------------------------------\n\n/** HTTP methods that plugin endpoints can handle. */\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/** Incoming request context provided to endpoint handlers. */\nexport interface PluginRequestContext {\n request: Request;\n params: Record<string, string>;\n body: unknown;\n hasPlugin: (id: string) => boolean;\n}\n\n/** Response shape returned by endpoint handlers. */\nexport interface PluginResponse {\n status: number;\n body: unknown;\n}\n\n/** Handler function signature for plugin endpoints. */\nexport type PluginEndpointHandler = (\n context: PluginRequestContext,\n) => Promise<PluginResponse>;\n\n/** A single HTTP endpoint declared by a plugin. */\nexport interface PluginEndpoint {\n method: HttpMethod;\n path: string;\n handler: PluginEndpointHandler;\n}\n\n// ---------------------------------------------------------------------------\n// Plugin definition\n// ---------------------------------------------------------------------------\n\n/**\n * Full plugin definition. Generic over the hook contract so plugins\n * get type-safe hook handlers when a product provides its contract.\n */\nexport interface PluginDefinition<\n THooks extends HookContract = HookContract,\n> {\n id: string;\n init?: (context: PluginContext) => void | Promise<void>;\n hooks?: Partial<HookHandlers<THooks>>;\n schema?: PluginSchema;\n endpoints?: PluginEndpoint[];\n /** Type-level brand for inference. Not used at runtime. */\n $Infer?: Record<string, unknown>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * A contract mapping hook names to their payload shapes.
3
+ * Products define this to declare what hooks are available.
4
+ *
5
+ * Example:
6
+ * ```ts
7
+ * type MyHooks = {
8
+ * "tenant:created": { tenantId: string; name: string };
9
+ * "tenant:deleted": { tenantId: string };
10
+ * };
11
+ * ```
12
+ */
13
+ type HookContract = Record<string, Record<string, unknown>>;
14
+ /**
15
+ * Derives handler function signatures from a HookContract.
16
+ * Each key becomes a handler that receives the corresponding payload.
17
+ */
18
+ type HookHandlers<T extends HookContract> = {
19
+ [K in keyof T]: (payload: T[K]) => void | Promise<void>;
20
+ };
21
+ /**
22
+ * Runtime context passed to plugin init functions.
23
+ * Provides product identity, peer plugin awareness, and configuration.
24
+ */
25
+ interface PluginContext {
26
+ productId: string;
27
+ hasPlugin: (id: string) => boolean;
28
+ config: Record<string, unknown>;
29
+ }
30
+ /** Common database column types that plugins can declare. */
31
+ type FieldType = "string" | "number" | "boolean" | "date" | "json";
32
+ /** A single column definition within a plugin table. */
33
+ interface PluginFieldDefinition {
34
+ type: FieldType;
35
+ required?: boolean;
36
+ unique?: boolean;
37
+ defaultValue?: string | number | boolean | null | (() => unknown);
38
+ references?: {
39
+ table: string;
40
+ field: string;
41
+ onDelete?: "cascade" | "restrict" | "set-null" | "no-action";
42
+ };
43
+ index?: boolean;
44
+ }
45
+ /** A single table definition declared by a plugin. Keyed by field name. */
46
+ interface PluginTableDefinition {
47
+ fields: Record<string, PluginFieldDefinition>;
48
+ }
49
+ /**
50
+ * Schema declaration for a plugin.
51
+ * `tables` declares new tables (keyed by table name).
52
+ * `extend` adds fields to existing product tables (keyed by table name, then field name).
53
+ */
54
+ interface PluginSchema {
55
+ tables?: Record<string, PluginTableDefinition>;
56
+ extend?: Record<string, Record<string, PluginFieldDefinition>>;
57
+ }
58
+ /** HTTP methods that plugin endpoints can handle. */
59
+ type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
60
+ /** Incoming request context provided to endpoint handlers. */
61
+ interface PluginRequestContext {
62
+ request: Request;
63
+ params: Record<string, string>;
64
+ body: unknown;
65
+ hasPlugin: (id: string) => boolean;
66
+ }
67
+ /** Response shape returned by endpoint handlers. */
68
+ interface PluginResponse {
69
+ status: number;
70
+ body: unknown;
71
+ }
72
+ /** Handler function signature for plugin endpoints. */
73
+ type PluginEndpointHandler = (context: PluginRequestContext) => Promise<PluginResponse>;
74
+ /** A single HTTP endpoint declared by a plugin. */
75
+ interface PluginEndpoint {
76
+ method: HttpMethod;
77
+ path: string;
78
+ handler: PluginEndpointHandler;
79
+ }
80
+ /**
81
+ * Full plugin definition. Generic over the hook contract so plugins
82
+ * get type-safe hook handlers when a product provides its contract.
83
+ */
84
+ interface PluginDefinition<THooks extends HookContract = HookContract> {
85
+ id: string;
86
+ init?: (context: PluginContext) => void | Promise<void>;
87
+ hooks?: Partial<HookHandlers<THooks>>;
88
+ schema?: PluginSchema;
89
+ endpoints?: PluginEndpoint[];
90
+ /** Type-level brand for inference. Not used at runtime. */
91
+ $Infer?: Record<string, unknown>;
92
+ }
93
+
94
+ export type { FieldType, HookContract, HookHandlers, HttpMethod, PluginContext, PluginDefinition, PluginEndpoint, PluginEndpointHandler, PluginFieldDefinition, PluginRequestContext, PluginResponse, PluginSchema, PluginTableDefinition };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A contract mapping hook names to their payload shapes.
3
+ * Products define this to declare what hooks are available.
4
+ *
5
+ * Example:
6
+ * ```ts
7
+ * type MyHooks = {
8
+ * "tenant:created": { tenantId: string; name: string };
9
+ * "tenant:deleted": { tenantId: string };
10
+ * };
11
+ * ```
12
+ */
13
+ export type HookContract = Record<string, Record<string, unknown>>;
14
+ /**
15
+ * Derives handler function signatures from a HookContract.
16
+ * Each key becomes a handler that receives the corresponding payload.
17
+ */
18
+ export type HookHandlers<T extends HookContract> = {
19
+ [K in keyof T]: (payload: T[K]) => void | Promise<void>;
20
+ };
21
+ /**
22
+ * Runtime context passed to plugin init functions.
23
+ * Provides product identity, peer plugin awareness, and configuration.
24
+ */
25
+ export interface PluginContext {
26
+ productId: string;
27
+ hasPlugin: (id: string) => boolean;
28
+ config: Record<string, unknown>;
29
+ }
30
+ /** Common database column types that plugins can declare. */
31
+ export type FieldType = "string" | "number" | "boolean" | "date" | "json";
32
+ /** A single column definition within a plugin table. */
33
+ export interface PluginFieldDefinition {
34
+ type: FieldType;
35
+ required?: boolean;
36
+ unique?: boolean;
37
+ defaultValue?: string | number | boolean | null | (() => unknown);
38
+ references?: {
39
+ table: string;
40
+ field: string;
41
+ onDelete?: "cascade" | "restrict" | "set-null" | "no-action";
42
+ };
43
+ index?: boolean;
44
+ }
45
+ /** A single table definition declared by a plugin. Keyed by field name. */
46
+ export interface PluginTableDefinition {
47
+ fields: Record<string, PluginFieldDefinition>;
48
+ }
49
+ /**
50
+ * Schema declaration for a plugin.
51
+ * `tables` declares new tables (keyed by table name).
52
+ * `extend` adds fields to existing product tables (keyed by table name, then field name).
53
+ */
54
+ export interface PluginSchema {
55
+ tables?: Record<string, PluginTableDefinition>;
56
+ extend?: Record<string, Record<string, PluginFieldDefinition>>;
57
+ }
58
+ /** HTTP methods that plugin endpoints can handle. */
59
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
60
+ /** Incoming request context provided to endpoint handlers. */
61
+ export interface PluginRequestContext {
62
+ request: Request;
63
+ params: Record<string, string>;
64
+ body: unknown;
65
+ hasPlugin: (id: string) => boolean;
66
+ }
67
+ /** Response shape returned by endpoint handlers. */
68
+ export interface PluginResponse {
69
+ status: number;
70
+ body: unknown;
71
+ }
72
+ /** Handler function signature for plugin endpoints. */
73
+ export type PluginEndpointHandler = (context: PluginRequestContext) => Promise<PluginResponse>;
74
+ /** A single HTTP endpoint declared by a plugin. */
75
+ export interface PluginEndpoint {
76
+ method: HttpMethod;
77
+ path: string;
78
+ handler: PluginEndpointHandler;
79
+ }
80
+ /**
81
+ * Full plugin definition. Generic over the hook contract so plugins
82
+ * get type-safe hook handlers when a product provides its contract.
83
+ */
84
+ export interface PluginDefinition<THooks extends HookContract = HookContract> {
85
+ id: string;
86
+ init?: (context: PluginContext) => void | Promise<void>;
87
+ hooks?: Partial<HookHandlers<THooks>>;
88
+ schema?: PluginSchema;
89
+ endpoints?: PluginEndpoint[];
90
+ /** Type-level brand for inference. Not used at runtime. */
91
+ $Infer?: Record<string, unknown>;
92
+ }
93
+ //# sourceMappingURL=plugin-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-types.d.ts","sourceRoot":"","sources":["../src/plugin-types.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI;KAChD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CACxD,CAAC;AAMF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAMD,6DAA6D;AAC7D,MAAM,MAAM,SAAS,GAA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AE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,uDAAuD;AACvD,MAAM,MAAM,qBAAqB,GAAG,CAClC,OAAO,EAAE,oBAAoB,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAMD;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAC/B,MAAM,SAAS,YAAY,GAAG,YAAY;IAE1C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=plugin-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +1,5 @@
1
+ import './plugin-types.cjs';
1
2
  import './config-types.cjs';
2
- import '@usebetterdev/plugin';
3
3
 
4
4
  /**
5
5
  * Wire-format types for console well-known endpoints.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usebetterdev/contract",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "repository": "github:usebetter-dev/usebetter",
5
5
  "bugs": "https://github.com/usebetter-dev/usebetter/issues",
6
6
  "homepage": "https://github.com/usebetter-dev/usebetter#readme",
@@ -27,25 +27,27 @@
27
27
  "types": "./dist/config-types.d.ts",
28
28
  "import": "./dist/config-types.js",
29
29
  "require": "./dist/config-types.cjs"
30
+ },
31
+ "./plugin-types": {
32
+ "types": "./dist/plugin-types.d.ts",
33
+ "import": "./dist/plugin-types.js",
34
+ "require": "./dist/plugin-types.cjs"
30
35
  }
31
36
  },
32
37
  "files": [
33
38
  "dist",
34
39
  "README.md"
35
40
  ],
36
- "scripts": {
37
- "build": "tsup",
38
- "build:types": "tsc --build tsconfig.build.json",
39
- "typecheck": "tsc --noEmit"
40
- },
41
- "dependencies": {
42
- "@usebetterdev/plugin": "workspace:*"
43
- },
44
41
  "devDependencies": {
45
42
  "tsup": "^8.3.5",
46
43
  "typescript": "~5.7.2"
47
44
  },
48
45
  "engines": {
49
46
  "node": ">=22"
47
+ },
48
+ "scripts": {
49
+ "build": "tsup",
50
+ "build:types": "tsc --build tsconfig.build.json",
51
+ "typecheck": "tsc --noEmit"
50
52
  }
51
- }
53
+ }