@usebetterdev/plugin 0.5.0-beta.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/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +36 -0
package/dist/index.cjs
ADDED
|
@@ -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/index.ts
|
|
17
|
+
var index_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(index_exports);
|
|
19
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export 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 \"./types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type { HookContract, HookHandlers, PluginContext, FieldType, PluginFieldDefinition, PluginTableDefinition, PluginSchema, HttpMethod, PluginRequestContext, PluginResponse, PluginEndpointHandler, PluginEndpoint, PluginDefinition, } from "./types.js";
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/types.d.ts
ADDED
|
@@ -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=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/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,CAA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/usebetter",
|
|
5
|
+
"bugs": "https://github.com/usebetter-dev/usebetter/issues",
|
|
6
|
+
"homepage": "https://github.com/usebetter-dev/usebetter#readme",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": ["dist", "README.md"],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
25
|
+
"lint": "oxlint",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.10.0",
|
|
31
|
+
"tsup": "^8.3.5",
|
|
32
|
+
"typescript": "~5.7.2",
|
|
33
|
+
"vitest": "^2.1.6"
|
|
34
|
+
},
|
|
35
|
+
"engines": { "node": ">=22" }
|
|
36
|
+
}
|