@usebetterdev/plugin 0.5.0 → 0.7.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/dist/config-loader.d.ts +23 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-types.d.ts +2 -0
- package/dist/config-types.d.ts.map +1 -0
- package/dist/config-validation.d.ts +19 -0
- package/dist/config-validation.d.ts.map +1 -0
- package/dist/config.cjs +142 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +110 -0
- package/dist/config.js.map +1 -0
- package/dist/define-config.d.ts +15 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/demo/auth-events.d.ts +34 -0
- package/dist/demo/auth-events.d.ts.map +1 -0
- package/dist/demo/webhook-dispatcher.d.ts +74 -0
- package/dist/demo/webhook-dispatcher.d.ts.map +1 -0
- package/dist/hook-registry.d.ts +68 -0
- package/dist/hook-registry.d.ts.map +1 -0
- package/dist/index.cjs +257 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +242 -0
- package/dist/index.js.map +1 -1
- package/dist/resolve-plugins.d.ts +36 -0
- package/dist/resolve-plugins.d.ts.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/types.d.ts +1 -92
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +11 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +12 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,YAAY,EACtD,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,GAClC,kBAAkB,CAmDpB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
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
|
-
}
|
|
1
|
+
export type { HookContract, HookHandlers, PluginContext, FieldType, PluginFieldDefinition, PluginTableDefinition, PluginSchema, HttpMethod, PluginRequestContext, PluginResponse, PluginEndpointHandler, PluginEndpoint, PluginDefinition, } from "@usebetterdev/contract/plugin-types";
|
|
93
2
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.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,qCAAqC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a value is not `undefined`.
|
|
3
|
+
* Throws with a descriptive error message following the plugin config error pattern.
|
|
4
|
+
*/
|
|
5
|
+
export declare function assertDefined<T>(value: T | undefined, name: string): asserts value is T;
|
|
6
|
+
/**
|
|
7
|
+
* Asserts that a value is one of the allowed values.
|
|
8
|
+
* Throws with a descriptive error message listing the allowed options.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertOneOf<T extends string | number | boolean>(value: T, allowed: T[], name: string): void;
|
|
11
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,KAAK,IAAI,CAAC,CAIpB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAO3G"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usebetterdev/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
|
@@ -17,12 +17,21 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"import": "./dist/index.js",
|
|
19
19
|
"require": "./dist/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./config": {
|
|
22
|
+
"types": "./dist/config.d.ts",
|
|
23
|
+
"import": "./dist/config.js",
|
|
24
|
+
"require": "./dist/config.cjs"
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"files": [
|
|
23
28
|
"dist",
|
|
24
29
|
"README.md"
|
|
25
30
|
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"c12": "^2.0.1",
|
|
33
|
+
"@usebetterdev/contract": "0.6.0"
|
|
34
|
+
},
|
|
26
35
|
"devDependencies": {
|
|
27
36
|
"@types/node": "^22.10.0",
|
|
28
37
|
"tsup": "^8.3.5",
|
|
@@ -33,7 +42,8 @@
|
|
|
33
42
|
"node": ">=22"
|
|
34
43
|
},
|
|
35
44
|
"scripts": {
|
|
36
|
-
"build": "tsup && tsc
|
|
45
|
+
"build": "tsup && tsc --build tsconfig.build.json --force",
|
|
46
|
+
"build:types": "tsc --build tsconfig.build.json",
|
|
37
47
|
"lint": "oxlint",
|
|
38
48
|
"test": "vitest run",
|
|
39
49
|
"typecheck": "tsc --noEmit"
|