@workopilot/pluginapi-sdk 0.1.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/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # @workopilot/pluginapi-sdk
2
+
3
+ Workopilot Plugin API SDK defines the TypeScript contract between the host application and third-party plugins.
4
+
5
+ It provides plugin manifest types, request/handler types, database capability types, logger types, and current user context types. The SDK does not start a server or connect to databases by itself. Runtime capabilities are injected by the host application or by `@workopilot/pluginapi-dev-host` during local development.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @workopilot/pluginapi-sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Create plugin handlers with the `PluginHandler` type:
16
+
17
+ ```ts
18
+ import type { PluginHandler } from '@workopilot/pluginapi-sdk';
19
+
20
+ export const getCurrentUser: PluginHandler = ({ ctx }) => ({
21
+ currentUser: ctx.currentUser
22
+ });
23
+
24
+ export const listItems: PluginHandler = async ({ ctx }) => {
25
+ const rows = await ctx.database.query('SELECT * FROM plugin_demo_items LIMIT ?', [10]);
26
+ return { rows };
27
+ };
28
+ ```
29
+
30
+ Register exported handlers in the plugin manifest:
31
+
32
+ ```json
33
+ {
34
+ "name": "my-plugin",
35
+ "version": "0.1.0",
36
+ "entry": "dist/index.js",
37
+ "routes": [
38
+ {
39
+ "method": "GET",
40
+ "path": "/me",
41
+ "handler": "getCurrentUser"
42
+ }
43
+ ]
44
+ }
45
+ ```
46
+
47
+ ## Provided Types
48
+
49
+ ### Plugin Handler
50
+
51
+ ```ts
52
+ PluginHandler
53
+ PluginHandlerInput
54
+ PluginRequest
55
+ PluginContext
56
+ ```
57
+
58
+ Handlers receive:
59
+
60
+ ```ts
61
+ {
62
+ request,
63
+ ctx
64
+ }
65
+ ```
66
+
67
+ ### Database Capability
68
+
69
+ The host injects database access through `ctx.database`:
70
+
71
+ ```ts
72
+ ctx.database.query(sql, params)
73
+ ctx.database.insert(sql, params)
74
+ ctx.database.update(sql, params)
75
+ ctx.database.delete(sql, params)
76
+ ```
77
+
78
+ Write operations return:
79
+
80
+ ```ts
81
+ {
82
+ affectedRows,
83
+ insertId,
84
+ warningStatus,
85
+ changedRows,
86
+ info
87
+ }
88
+ ```
89
+
90
+ ### Current User
91
+
92
+ The host injects the authenticated user through:
93
+
94
+ ```ts
95
+ ctx.currentUser
96
+ ```
97
+
98
+ Current user shape:
99
+
100
+ ```ts
101
+ {
102
+ tenantId,
103
+ userId,
104
+ clientid,
105
+ userName,
106
+ deptId,
107
+ deptName,
108
+ deptCategory
109
+ }
110
+ ```
111
+
112
+ ### Logger
113
+
114
+ Plugins can write host-managed logs:
115
+
116
+ ```ts
117
+ ctx.logger.info(message, data)
118
+ ctx.logger.error(message, data)
119
+ ```
120
+
121
+ ## Notes
122
+
123
+ Plugin packages should normally use this SDK as a TypeScript type dependency. Database credentials, JWT verification, Redis token checks, and route mounting are handled by the host side.
@@ -0,0 +1,56 @@
1
+ export type PluginRouteMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
2
+ export interface PluginManifest {
3
+ name: string;
4
+ version: string;
5
+ entry: string;
6
+ routes: PluginRoute[];
7
+ }
8
+ export interface PluginRoute {
9
+ method: PluginRouteMethod;
10
+ path: string;
11
+ handler: string;
12
+ }
13
+ export type QueryParam = string | number | boolean | Date | null;
14
+ export interface DatabaseWriteResult {
15
+ affectedRows: number;
16
+ insertId?: number;
17
+ warningStatus?: number;
18
+ changedRows?: number;
19
+ info?: string;
20
+ }
21
+ export interface DatabaseCapability {
22
+ query<T = Record<string, unknown>>(sql: string, params?: QueryParam[]): Promise<T[]>;
23
+ insert(sql: string, params?: QueryParam[]): Promise<DatabaseWriteResult>;
24
+ update(sql: string, params?: QueryParam[]): Promise<DatabaseWriteResult>;
25
+ delete(sql: string, params?: QueryParam[]): Promise<DatabaseWriteResult>;
26
+ }
27
+ export interface PluginLogger {
28
+ info(message: string, data?: unknown): void;
29
+ error(message: string, data?: unknown): void;
30
+ }
31
+ export interface CurrentUser {
32
+ tenantId: string;
33
+ userId: string;
34
+ clientid: string;
35
+ userName: string;
36
+ deptId: string | number | null;
37
+ deptName: string;
38
+ deptCategory: string;
39
+ }
40
+ export interface PluginRequest {
41
+ method: string;
42
+ url: string;
43
+ query: unknown;
44
+ body: unknown;
45
+ headers: Record<string, string | string[] | undefined>;
46
+ }
47
+ export interface PluginContext {
48
+ database: DatabaseCapability;
49
+ logger: PluginLogger;
50
+ currentUser: CurrentUser;
51
+ }
52
+ export interface PluginHandlerInput {
53
+ request: PluginRequest;
54
+ ctx: PluginContext;
55
+ }
56
+ export type PluginHandler = (input: PluginHandlerInput) => Promise<unknown> | unknown;
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@workopilot/pluginapi-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Workopilot plugin API SDK for database-capability plugins",
5
+ "keywords": [
6
+ "wiseai",
7
+ "workopilot",
8
+ "plugin",
9
+ "sdk"
10
+ ],
11
+ "author": "workopilot",
12
+ "license": "MIT",
13
+ "type": "module",
14
+ "main": "dist/index.js",
15
+ "module": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsc -p tsconfig.json"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^5.7.2"
32
+ }
33
+ }