@zhama/tego-plugin-sdk 0.0.0-stage → 1.36.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.
Files changed (98) hide show
  1. package/LICENSE +172 -0
  2. package/README.md +846 -2
  3. package/access-catalog.schema.json +304 -0
  4. package/access-fixtures/resolve.json +1359 -0
  5. package/bin/tego-plugin-pack.mjs +2 -0
  6. package/bin/tego-plugin.mjs +3 -0
  7. package/dist/access-drizzle.cjs +1 -0
  8. package/dist/access-drizzle.d.cts +726 -0
  9. package/dist/access-drizzle.d.ts +726 -0
  10. package/dist/access-drizzle.js +1 -0
  11. package/dist/access-hono.cjs +3 -0
  12. package/dist/access-hono.d.cts +108 -0
  13. package/dist/access-hono.d.ts +108 -0
  14. package/dist/access-hono.js +3 -0
  15. package/dist/access-implications.cjs +1 -0
  16. package/dist/access-implications.d.cts +25 -0
  17. package/dist/access-implications.d.ts +25 -0
  18. package/dist/access-implications.js +1 -0
  19. package/dist/access.cjs +26 -0
  20. package/dist/access.d.cts +884 -0
  21. package/dist/access.d.ts +884 -0
  22. package/dist/access.js +26 -0
  23. package/dist/catalog-CSSbrfEf.d.cts +361 -0
  24. package/dist/catalog-CSSbrfEf.d.ts +361 -0
  25. package/dist/chunk-3KUOBGJN.js +19 -0
  26. package/dist/chunk-3WA3M347.cjs +1 -0
  27. package/dist/chunk-5CU33JVY.js +1 -0
  28. package/dist/chunk-7K37PVGV.js +5 -0
  29. package/dist/chunk-7XHF3YSK.js +1 -0
  30. package/dist/chunk-AJY7ZHXK.cjs +3 -0
  31. package/dist/chunk-BN6TGHSB.cjs +1 -0
  32. package/dist/chunk-BTHXQWHT.js +1 -0
  33. package/dist/chunk-C2OCOPZQ.cjs +1 -0
  34. package/dist/chunk-IMAVYQ4U.cjs +4 -0
  35. package/dist/chunk-OP64Y4IN.cjs +1 -0
  36. package/dist/chunk-QKSPPMVN.js +1 -0
  37. package/dist/chunk-ROFUQLOZ.cjs +1 -0
  38. package/dist/chunk-SNUCO2MK.js +1 -0
  39. package/dist/chunk-THMWRUAT.cjs +19 -0
  40. package/dist/chunk-VMCGDDGP.js +3 -0
  41. package/dist/chunk-W7C357A6.cjs +5 -0
  42. package/dist/chunk-WLTASJF6.js +4 -0
  43. package/dist/egress.cjs +7 -0
  44. package/dist/egress.d.cts +9 -0
  45. package/dist/egress.d.ts +9 -0
  46. package/dist/egress.js +7 -0
  47. package/dist/frontend.cjs +2 -0
  48. package/dist/frontend.d.cts +353 -0
  49. package/dist/frontend.d.ts +353 -0
  50. package/dist/frontend.js +2 -0
  51. package/dist/gateway-signature.cjs +1 -0
  52. package/dist/gateway-signature.d.cts +112 -0
  53. package/dist/gateway-signature.d.ts +112 -0
  54. package/dist/gateway-signature.js +1 -0
  55. package/dist/index.cjs +1 -0
  56. package/dist/index.d.cts +528 -0
  57. package/dist/index.d.ts +528 -0
  58. package/dist/index.js +1 -0
  59. package/dist/manifest-types-DQARCQJt.d.cts +627 -0
  60. package/dist/manifest-types-DQARCQJt.d.ts +627 -0
  61. package/dist/manifest.cjs +1 -0
  62. package/dist/manifest.d.cts +2824 -0
  63. package/dist/manifest.d.ts +2824 -0
  64. package/dist/manifest.js +1 -0
  65. package/dist/mcp-identity.cjs +2 -0
  66. package/dist/mcp-identity.d.cts +106 -0
  67. package/dist/mcp-identity.d.ts +106 -0
  68. package/dist/mcp-identity.js +2 -0
  69. package/dist/pack.cjs +1 -0
  70. package/dist/pack.d.cts +169 -0
  71. package/dist/pack.d.ts +169 -0
  72. package/dist/pack.js +1 -0
  73. package/dist/publish.cjs +1 -0
  74. package/dist/publish.d.cts +96 -0
  75. package/dist/publish.d.ts +96 -0
  76. package/dist/publish.js +1 -0
  77. package/dist/scaffold.cjs +523 -0
  78. package/dist/scaffold.d.cts +182 -0
  79. package/dist/scaffold.d.ts +182 -0
  80. package/dist/scaffold.js +523 -0
  81. package/dist/server-runtime.cjs +1 -0
  82. package/dist/server-runtime.d.cts +63 -0
  83. package/dist/server-runtime.d.ts +63 -0
  84. package/dist/server-runtime.js +1 -0
  85. package/dist/server.cjs +1 -0
  86. package/dist/server.d.cts +1808 -0
  87. package/dist/server.d.ts +1808 -0
  88. package/dist/server.js +1 -0
  89. package/dist/testing.cjs +2 -0
  90. package/dist/testing.d.cts +92 -0
  91. package/dist/testing.d.ts +92 -0
  92. package/dist/testing.js +2 -0
  93. package/dist/vite.cjs +1 -0
  94. package/dist/vite.d.cts +133 -0
  95. package/dist/vite.d.ts +133 -0
  96. package/dist/vite.js +1 -0
  97. package/package.json +160 -4
  98. package/sql/access.sql +73 -0
package/dist/server.js ADDED
@@ -0,0 +1 @@
1
+ export{PLUGIN_COLLECTION_CONTENT_PAGE_MAX,PLUGIN_COLLECTION_IMPORT_MAX,PLUGIN_CONTEXT_HEADERS,accountInvitationSchema,accountInviteSchema,accountPasswordResetSchema,accountProvisionSchema,definePluginBackend,directoryIdentitySchema,directoryListSchema,directoryMatchSchema,directoryPrincipalSchema,directoryValidateSchema,pluginAdminActionSchema,pluginAdminProofSchema,pluginApprovalDigestSchema,pluginApprovedSchema,pluginCollectionAccessSchema,pluginCollectionDeleteSchema,pluginCollectionDocumentContentSchema,pluginCollectionDocumentsStatusSchema,pluginCollectionEnsureSchema,pluginCollectionImportFilesSchema,pluginCollectionImportSchema,pluginCollectionMoveSchema,pluginCollectionPermissionsSchema,pluginCollectionRemoveSchema,pluginCollectionSearchSchema,pluginCollectionStatusSchema,pluginDiagramSchema,pluginDocumentBatchInputSchema,pluginDocumentBatchItemSchema,pluginDocumentContentInputSchema,pluginKnowledgeBaseInputSchema,pluginKnowledgeListInputSchema,pluginKnowledgeReferenceSchema,pluginKnowledgeVerifySchema}from"./chunk-QKSPPMVN.js";
@@ -0,0 +1,2 @@
1
+ "use strict";var A=Object.defineProperty;var a=(s,l)=>A(s,"name",{value:l,configurable:!0});var crypto=require("crypto"),promises=require("fs/promises"),path=require("path"),DEFAULT_DATABASE_URL=process.env.TEST_DATABASE_URL??"postgresql://zhama:zhama123321@localhost:15432/zhama",TEST_TENANT_ID="00000000-0000-4000-8000-00000000a001";async function createTestPluginHost(s){const{Pool:l}=await import("pg"),c=s.databaseUrl??DEFAULT_DATABASE_URL,u=`plugintest_${(s.label??s.pluginId).replace(/[^a-z0-9]+/gi,"_")}_${Math.random().toString(36).slice(2,8)}`,w=new l({connectionString:c});await w.query(`CREATE SCHEMA "${u}"`);const p=await w.connect();try{await p.query(`SET search_path TO "${u}"`);for(const e of await migrationFiles(s.migrationsDir))await p.query(await promises.readFile(e,"utf8"))}finally{p.release()}await w.end();const f=new l({connectionString:c,options:`-c search_path=${u}`}),m=[],b=[],r=new Map,o=new Map;let T=!1,h={...s.config??{}};const E={query:a(async(e,t)=>(await f.query(e,t)).rows,"query"),transaction:a(async e=>{const t=await f.connect();try{await t.query("BEGIN");const n=await e({query:a(async(i,g)=>(await t.query(i,g)).rows,"query")});return await t.query("COMMIT"),n}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}},"transaction")};return{host:{pluginId:s.pluginId,tenantId:s.tenantId??TEST_TENANT_ID,db:E,storage:{put:a(async(e,t,n)=>{r.set(e,t),o.set(e,n??"application/octet-stream")},"put"),copy:a(async(e,t)=>{const n=r.get(e);if(!n)throw new Error("Object not found");r.set(t,n.slice());const i=o.get(e)??"application/octet-stream";return o.set(t,i),{size:n.byteLength,contentType:i}},"copy"),getStream:a(async e=>{const t=r.get(e);return t?new ReadableStream({start(n){n.enqueue(t.slice()),n.close()}}):null},"getStream"),putStream:a(async(e,t,n)=>{const i=t.getReader(),g=[];let d=0;try{for(;;){const y=await i.read();if(y.done)break;if(g.push(y.value),d+=y.value.byteLength,d>n.sizeBytes)throw new Error("Stream exceeds declared size")}}finally{i.releaseLock()}if(d!==n.sizeBytes)throw new Error("Stream size mismatch");const q=new Uint8Array(d);let S=0;for(const y of g)q.set(y,S),S+=y.byteLength;r.set(e,q),o.set(e,n.contentType??"application/octet-stream")},"putStream"),get:a(async(e,t)=>{const n=r.get(e);return n?t?.firstBytes===void 0?n:n.subarray(0,t.firstBytes):null},"get"),head:a(async e=>{const t=r.get(e);return t?{size:t.byteLength,contentType:o.get(e)??null,versionTag:crypto.createHash("sha256").update(t).digest("hex")}:null},"head"),delete:a(async e=>{r.delete(e),o.delete(e)},"delete"),signedUrl:a(async e=>`https://storage.test/${e}`,"signedUrl"),signedPath:a(async e=>`/storage.test/${e}`,"signedPath"),managedPath:a(async e=>`/storage.test/${e}`,"managedPath"),uploadPath:a(async(e,t)=>({path:`/storage.test/upload/${e}`,maxBytes:t?.maxBytes??512*1024*1024,expiresAt:Date.now()+(t?.ttlSeconds??300)*1e3}),"uploadPath")},log:{debug:a(()=>{},"debug"),info:a(()=>{},"info"),warn:a(()=>{},"warn"),error:a((e,t)=>{b.push({message:e,...t?{fields:t}:{}})},"error")},events:{publish:a(async(e,t)=>{if(T)throw new Error("the event bus is down");m.push({topic:e,payload:t})},"publish")},notifications:{send:a(async()=>({id:crypto.randomUUID()}),"send")},config:{current:a(()=>h,"current"),refresh:a(async()=>h,"refresh")}},schema:u,publishedEvents:m,loggedErrors:b,storedObjects:r,failPublish:a((e=!0)=>{T=e},"failPublish"),setConfig:a(e=>{h={...e}},"setConfig"),reset:a(async()=>{const e=await E.query(`select quote_ident(tablename) as name
2
+ from pg_tables where schemaname = $1`,[u]);e.length>0&&await E.query(`truncate table ${e.map(t=>t.name).join(", ")} restart identity cascade`),m.length=0,b.length=0,r.clear(),o.clear(),T=!1,h={...s.config??{}}},"reset"),close:a(async()=>{await f.end();const e=new l({connectionString:c});await e.query(`DROP SCHEMA "${u}" CASCADE`),await e.end()},"close")}}a(createTestPluginHost,"createTestPluginHost");async function migrationFiles(s){return(await promises.readdir(s)).filter(c=>c.endsWith(".sql")).sort().map(c=>path.join(s,c))}a(migrationFiles,"migrationFiles"),exports.TEST_TENANT_ID=TEST_TENANT_ID,exports.createTestPluginHost=createTestPluginHost;
@@ -0,0 +1,92 @@
1
+ import { PluginHostApi } from './server.cjs';
2
+ import 'zod';
3
+ import './frontend.cjs';
4
+
5
+ /**
6
+ * Test helpers for a plugin's backend part.
7
+ *
8
+ * A plugin backend's interesting code is its SQL — multi-table writes in one
9
+ * transaction, `FOR UPDATE SKIP LOCKED`, partial unique indexes — and none of
10
+ * that means anything against a fake. So this stands up the real thing: a
11
+ * throwaway Postgres schema with the plugin's own migrations applied, behind
12
+ * the same `PluginScopedDb` the host hands a running backend, plus recording
13
+ * doubles for the parts of the host API that have no local equivalent.
14
+ *
15
+ * Without it every plugin rewrites the same ~150 lines, and each copy gets the
16
+ * transaction semantics slightly differently — which is exactly the thing that
17
+ * has to match production, because a body whose statements land on pooled
18
+ * connections is not a transaction at all and the test would still pass.
19
+ *
20
+ * Not part of the barrel: it imports `pg` and `node:fs`.
21
+ */
22
+
23
+ interface TestPluginHostOptions {
24
+ pluginId: string;
25
+ /** Absolute path to the part's `migrations` directory. */
26
+ migrationsDir: string;
27
+ /** Defaults to `TEST_DATABASE_URL`, then the monorepo's test Postgres. */
28
+ databaseUrl?: string;
29
+ /**
30
+ * Distinguishes the schemas of suites running against the same database.
31
+ * Defaults to the plugin id.
32
+ */
33
+ label?: string;
34
+ /**
35
+ * What `host.config.current()` answers — the backend section an operator
36
+ * would have filled in. Defaults to empty, which is what a backend that
37
+ * declares no required settings gets.
38
+ */
39
+ config?: Record<string, unknown>;
40
+ /** What `host.tenantId` answers. Defaults to {@link TEST_TENANT_ID}. */
41
+ tenantId?: string;
42
+ }
43
+ /** The tenant a test host belongs to unless the suite names its own. */
44
+ declare const TEST_TENANT_ID = "00000000-0000-4000-8000-00000000a001";
45
+ interface TestPluginHost {
46
+ /** Pass this straight to the backend module's `fetch`. */
47
+ host: PluginHostApi;
48
+ /** The schema this suite owns, for assertions that have to name it. */
49
+ schema: string;
50
+ /** Every `events.publish` the backend made, oldest first. */
51
+ publishedEvents: {
52
+ topic: string;
53
+ payload: unknown;
54
+ }[];
55
+ /** Every `log.error` the backend made. The other levels are dropped. */
56
+ loggedErrors: {
57
+ message: string;
58
+ fields?: Record<string, unknown>;
59
+ }[];
60
+ /** Objects written through `host.storage`, keyed as the backend keyed them. */
61
+ storedObjects: Map<string, Uint8Array>;
62
+ /**
63
+ * Make `events.publish` throw until turned off again.
64
+ *
65
+ * A backend that lets a failed announcement undo a committed write is a real
66
+ * bug, and there is otherwise no way to reach it from a test. Sticky rather
67
+ * than one-shot because a single request may publish more than once, and a
68
+ * one-shot flag would let the second publish succeed and mask the case.
69
+ */
70
+ failPublish(enabled?: boolean): void;
71
+ /** Replace what `host.config` answers, for a test that changes a setting mid-suite. */
72
+ setConfig(values: Record<string, unknown>): void;
73
+ /** Truncate every table and clear the recorders. Cheap enough for `beforeEach`. */
74
+ reset(): Promise<void>;
75
+ /** Drop the schema and close the pools. */
76
+ close(): Promise<void>;
77
+ }
78
+ /**
79
+ * Create the schema, apply the migrations, and return a host API over it.
80
+ *
81
+ * ```ts
82
+ * const harness = await createTestPluginHost({
83
+ * pluginId: 'acme-crm',
84
+ * migrationsDir: new URL('../migrations', import.meta.url).pathname,
85
+ * });
86
+ * afterAll(() => harness.close());
87
+ * beforeEach(() => harness.reset());
88
+ * ```
89
+ */
90
+ declare function createTestPluginHost(options: TestPluginHostOptions): Promise<TestPluginHost>;
91
+
92
+ export { TEST_TENANT_ID, type TestPluginHost, type TestPluginHostOptions, createTestPluginHost };
@@ -0,0 +1,92 @@
1
+ import { PluginHostApi } from './server.js';
2
+ import 'zod';
3
+ import './frontend.js';
4
+
5
+ /**
6
+ * Test helpers for a plugin's backend part.
7
+ *
8
+ * A plugin backend's interesting code is its SQL — multi-table writes in one
9
+ * transaction, `FOR UPDATE SKIP LOCKED`, partial unique indexes — and none of
10
+ * that means anything against a fake. So this stands up the real thing: a
11
+ * throwaway Postgres schema with the plugin's own migrations applied, behind
12
+ * the same `PluginScopedDb` the host hands a running backend, plus recording
13
+ * doubles for the parts of the host API that have no local equivalent.
14
+ *
15
+ * Without it every plugin rewrites the same ~150 lines, and each copy gets the
16
+ * transaction semantics slightly differently — which is exactly the thing that
17
+ * has to match production, because a body whose statements land on pooled
18
+ * connections is not a transaction at all and the test would still pass.
19
+ *
20
+ * Not part of the barrel: it imports `pg` and `node:fs`.
21
+ */
22
+
23
+ interface TestPluginHostOptions {
24
+ pluginId: string;
25
+ /** Absolute path to the part's `migrations` directory. */
26
+ migrationsDir: string;
27
+ /** Defaults to `TEST_DATABASE_URL`, then the monorepo's test Postgres. */
28
+ databaseUrl?: string;
29
+ /**
30
+ * Distinguishes the schemas of suites running against the same database.
31
+ * Defaults to the plugin id.
32
+ */
33
+ label?: string;
34
+ /**
35
+ * What `host.config.current()` answers — the backend section an operator
36
+ * would have filled in. Defaults to empty, which is what a backend that
37
+ * declares no required settings gets.
38
+ */
39
+ config?: Record<string, unknown>;
40
+ /** What `host.tenantId` answers. Defaults to {@link TEST_TENANT_ID}. */
41
+ tenantId?: string;
42
+ }
43
+ /** The tenant a test host belongs to unless the suite names its own. */
44
+ declare const TEST_TENANT_ID = "00000000-0000-4000-8000-00000000a001";
45
+ interface TestPluginHost {
46
+ /** Pass this straight to the backend module's `fetch`. */
47
+ host: PluginHostApi;
48
+ /** The schema this suite owns, for assertions that have to name it. */
49
+ schema: string;
50
+ /** Every `events.publish` the backend made, oldest first. */
51
+ publishedEvents: {
52
+ topic: string;
53
+ payload: unknown;
54
+ }[];
55
+ /** Every `log.error` the backend made. The other levels are dropped. */
56
+ loggedErrors: {
57
+ message: string;
58
+ fields?: Record<string, unknown>;
59
+ }[];
60
+ /** Objects written through `host.storage`, keyed as the backend keyed them. */
61
+ storedObjects: Map<string, Uint8Array>;
62
+ /**
63
+ * Make `events.publish` throw until turned off again.
64
+ *
65
+ * A backend that lets a failed announcement undo a committed write is a real
66
+ * bug, and there is otherwise no way to reach it from a test. Sticky rather
67
+ * than one-shot because a single request may publish more than once, and a
68
+ * one-shot flag would let the second publish succeed and mask the case.
69
+ */
70
+ failPublish(enabled?: boolean): void;
71
+ /** Replace what `host.config` answers, for a test that changes a setting mid-suite. */
72
+ setConfig(values: Record<string, unknown>): void;
73
+ /** Truncate every table and clear the recorders. Cheap enough for `beforeEach`. */
74
+ reset(): Promise<void>;
75
+ /** Drop the schema and close the pools. */
76
+ close(): Promise<void>;
77
+ }
78
+ /**
79
+ * Create the schema, apply the migrations, and return a host API over it.
80
+ *
81
+ * ```ts
82
+ * const harness = await createTestPluginHost({
83
+ * pluginId: 'acme-crm',
84
+ * migrationsDir: new URL('../migrations', import.meta.url).pathname,
85
+ * });
86
+ * afterAll(() => harness.close());
87
+ * beforeEach(() => harness.reset());
88
+ * ```
89
+ */
90
+ declare function createTestPluginHost(options: TestPluginHostOptions): Promise<TestPluginHost>;
91
+
92
+ export { TEST_TENANT_ID, type TestPluginHost, type TestPluginHostOptions, createTestPluginHost };
@@ -0,0 +1,2 @@
1
+ var _=Object.defineProperty;var a=(s,l)=>_(s,"name",{value:l,configurable:!0});import{randomUUID as $,createHash as z}from"crypto";import{readFile as v,readdir as B}from"fs/promises";import{join as L}from"path";var D=process.env.TEST_DATABASE_URL??"postgresql://zhama:zhama123321@localhost:15432/zhama",A="00000000-0000-4000-8000-00000000a001";async function I(s){const{Pool:l}=await import("pg"),c=s.databaseUrl??D,u=`plugintest_${(s.label??s.pluginId).replace(/[^a-z0-9]+/gi,"_")}_${Math.random().toString(36).slice(2,8)}`,w=new l({connectionString:c});await w.query(`CREATE SCHEMA "${u}"`);const m=await w.connect();try{await m.query(`SET search_path TO "${u}"`);for(const e of await U(s.migrationsDir))await m.query(await v(e,"utf8"))}finally{m.release()}await w.end();const f=new l({connectionString:c,options:`-c search_path=${u}`}),p=[],b=[],r=new Map,o=new Map;let E=!1,h={...s.config??{}};const T={query:a(async(e,t)=>(await f.query(e,t)).rows,"query"),transaction:a(async e=>{const t=await f.connect();try{await t.query("BEGIN");const n=await e({query:a(async(i,g)=>(await t.query(i,g)).rows,"query")});return await t.query("COMMIT"),n}catch(n){throw await t.query("ROLLBACK"),n}finally{t.release()}},"transaction")};return{host:{pluginId:s.pluginId,tenantId:s.tenantId??A,db:T,storage:{put:a(async(e,t,n)=>{r.set(e,t),o.set(e,n??"application/octet-stream")},"put"),copy:a(async(e,t)=>{const n=r.get(e);if(!n)throw new Error("Object not found");r.set(t,n.slice());const i=o.get(e)??"application/octet-stream";return o.set(t,i),{size:n.byteLength,contentType:i}},"copy"),getStream:a(async e=>{const t=r.get(e);return t?new ReadableStream({start(n){n.enqueue(t.slice()),n.close()}}):null},"getStream"),putStream:a(async(e,t,n)=>{const i=t.getReader(),g=[];let d=0;try{for(;;){const y=await i.read();if(y.done)break;if(g.push(y.value),d+=y.value.byteLength,d>n.sizeBytes)throw new Error("Stream exceeds declared size")}}finally{i.releaseLock()}if(d!==n.sizeBytes)throw new Error("Stream size mismatch");const S=new Uint8Array(d);let q=0;for(const y of g)S.set(y,q),q+=y.byteLength;r.set(e,S),o.set(e,n.contentType??"application/octet-stream")},"putStream"),get:a(async(e,t)=>{const n=r.get(e);return n?t?.firstBytes===void 0?n:n.subarray(0,t.firstBytes):null},"get"),head:a(async e=>{const t=r.get(e);return t?{size:t.byteLength,contentType:o.get(e)??null,versionTag:z("sha256").update(t).digest("hex")}:null},"head"),delete:a(async e=>{r.delete(e),o.delete(e)},"delete"),signedUrl:a(async e=>`https://storage.test/${e}`,"signedUrl"),signedPath:a(async e=>`/storage.test/${e}`,"signedPath"),managedPath:a(async e=>`/storage.test/${e}`,"managedPath"),uploadPath:a(async(e,t)=>({path:`/storage.test/upload/${e}`,maxBytes:t?.maxBytes??512*1024*1024,expiresAt:Date.now()+(t?.ttlSeconds??300)*1e3}),"uploadPath")},log:{debug:a(()=>{},"debug"),info:a(()=>{},"info"),warn:a(()=>{},"warn"),error:a((e,t)=>{b.push({message:e,...t?{fields:t}:{}})},"error")},events:{publish:a(async(e,t)=>{if(E)throw new Error("the event bus is down");p.push({topic:e,payload:t})},"publish")},notifications:{send:a(async()=>({id:$()}),"send")},config:{current:a(()=>h,"current"),refresh:a(async()=>h,"refresh")}},schema:u,publishedEvents:p,loggedErrors:b,storedObjects:r,failPublish:a((e=!0)=>{E=e},"failPublish"),setConfig:a(e=>{h={...e}},"setConfig"),reset:a(async()=>{const e=await T.query(`select quote_ident(tablename) as name
2
+ from pg_tables where schemaname = $1`,[u]);e.length>0&&await T.query(`truncate table ${e.map(t=>t.name).join(", ")} restart identity cascade`),p.length=0,b.length=0,r.clear(),o.clear(),E=!1,h={...s.config??{}}},"reset"),close:a(async()=>{await f.end();const e=new l({connectionString:c});await e.query(`DROP SCHEMA "${u}" CASCADE`),await e.end()},"close")}}a(I,"createTestPluginHost");async function U(s){return(await B(s)).filter(c=>c.endsWith(".sql")).sort().map(c=>L(s,c))}a(U,"migrationFiles");export{A as TEST_TENANT_ID,I as createTestPluginHost};
package/dist/vite.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var n=Object.defineProperty;var e=(r,t)=>n(r,"name",{value:t,configurable:!0});var chunkW7C357A6_cjs=require("./chunk-W7C357A6.cjs");require("./chunk-C2OCOPZQ.cjs"),Object.defineProperty(exports,"TEGO_PLUGIN_DEV_OVERRIDES",{enumerable:!0,get:e(function(){return chunkW7C357A6_cjs.TEGO_PLUGIN_DEV_OVERRIDES},"get")}),Object.defineProperty(exports,"tegoPluginFrontend",{enumerable:!0,get:e(function(){return chunkW7C357A6_cjs.tegoPluginFrontend},"get")}),Object.defineProperty(exports,"tegoPluginTailwind",{enumerable:!0,get:e(function(){return chunkW7C357A6_cjs.tegoPluginTailwind},"get")});
@@ -0,0 +1,133 @@
1
+ import { UserConfig } from 'vite';
2
+
3
+ /**
4
+ * The Tailwind config a plugin frontend compiles its own utilities with.
5
+ *
6
+ * A plugin's CSS is inlined into its bundle and lands in the shell's document,
7
+ * next to the shell's own stylesheet. Three things make that safe, and each
8
+ * one, left out, produces a plugin that builds fine and then looks wrong
9
+ * inside the shell:
10
+ *
11
+ * - The design tokens come from `@tego/ui`'s preset, the same one the shell
12
+ * compiles with, so `bg-primary` means the same colour on both sides.
13
+ * - Preflight is off: the shell already ships the reset, and a second copy
14
+ * loaded later would restyle the shell's own elements.
15
+ * - Every utility is scoped under `.<pluginId>`, the class the shell puts on
16
+ * the plugin's root, so a plugin's `.hidden` cannot hide shell UI.
17
+ *
18
+ * Content also covers the compiled `@tego/ui` and `@tego/plugin-access-ui`
19
+ * code, because their components carry class names the plugin's bundle must
20
+ * define: the shell does not compile classes for components it never renders
21
+ * itself.
22
+ *
23
+ * Resolution starts from `root` — the plugin's frontend directory — so the
24
+ * same call works inside this repo and in a plugin installed from npm.
25
+ * `tailwindcss` stays the plugin's own dependency; this returns plain config:
26
+ *
27
+ * ```ts
28
+ * import tailwindcss from 'tailwindcss';
29
+ * import { tegoPluginTailwind } from '@tego/plugin-sdk/vite';
30
+ *
31
+ * config.css = {
32
+ * postcss: {
33
+ * plugins: [
34
+ * tailwindcss(
35
+ * tegoPluginTailwind({
36
+ * pluginId: 'acme-crm',
37
+ * root: import.meta.dirname,
38
+ * content: [resolve(import.meta.dirname, 'src/**\/*.{ts,tsx}')],
39
+ * })
40
+ * ),
41
+ * ],
42
+ * },
43
+ * };
44
+ * ```
45
+ */
46
+ interface TegoPluginTailwindOptions {
47
+ /** The plugin id; utilities are scoped under `.<pluginId>`. */
48
+ pluginId: string;
49
+ /** Directory package resolution starts from: the plugin's frontend dir. */
50
+ root: string;
51
+ /** Absolute globs of the plugin's own sources. */
52
+ content: string[];
53
+ }
54
+ /**
55
+ * The subset of a Tailwind v3 config this produces, typed so it passes
56
+ * straight to `tailwindcss(…)` without the SDK depending on tailwindcss.
57
+ * The preset is `@tego/ui`'s CommonJS module, opaque here.
58
+ */
59
+ interface TegoPluginTailwindConfig {
60
+ presets: object[];
61
+ content: string[];
62
+ corePlugins: {
63
+ preflight: false;
64
+ };
65
+ important: string;
66
+ }
67
+ declare function tegoPluginTailwind({ pluginId, root, content, }: TegoPluginTailwindOptions): TegoPluginTailwindConfig;
68
+
69
+ /**
70
+ * The Vite config a plugin's frontend part is built with.
71
+ *
72
+ * Not a convenience wrapper: the shell can only load a bundle that is a
73
+ * SystemJS module whose shared imports were rewritten to the exact ids the
74
+ * shell registered. Both of those are one-line mistakes that produce a plugin
75
+ * which builds cleanly and then fails at load with a message about an unknown
76
+ * scheme, so the settings live here rather than in every plugin's own config.
77
+ *
78
+ * Imported only by a plugin's `vite.config.ts`; `vite` is a peer dependency
79
+ * and nothing else in the SDK reaches this module.
80
+ */
81
+
82
+ interface TegoPluginFrontendOptions {
83
+ /** Entry module whose default export is the `PluginFrontendModule`. */
84
+ entry: string;
85
+ /**
86
+ * The manifest `id`, stamped onto the inlined `<style>` as
87
+ * `data-tego-plugin`. The shell removes styles by this attribute when the
88
+ * plugin page unmounts. Omit it and the attribute is left empty — an older
89
+ * bundle's behaviour, which the shell leaves in place rather than removing.
90
+ */
91
+ pluginId?: string;
92
+ /** Defaults to `dist`, which is what the packaging step expects. */
93
+ outDir?: string;
94
+ /**
95
+ * Build the development form instead of the distributable one.
96
+ *
97
+ * See {@link TEGO_PLUGIN_DEV_OVERRIDES}. `tego-plugin-pack --watch` applies
98
+ * the same overrides without this flag, so a plugin only needs it when it
99
+ * drives Vite itself.
100
+ */
101
+ development?: boolean;
102
+ }
103
+ /**
104
+ * The development form, as a config patch.
105
+ *
106
+ * What it does *not* change is the point: the module format, the externals and
107
+ * the browser target stay exactly as they are in a packed archive, because
108
+ * those are what the shell's loader requires and a bundle that differed there
109
+ * would not be testing the real thing. It changes only the two things that
110
+ * make a watch loop unusable — a minified frame in an anonymous SystemJS
111
+ * module points nowhere, and minifying on every keystroke is the slowest part
112
+ * of the rebuild.
113
+ *
114
+ * Exported so `tego-plugin-pack --watch` and the preset apply one definition
115
+ * rather than two that can drift.
116
+ */
117
+ declare const TEGO_PLUGIN_DEV_OVERRIDES: {
118
+ readonly mode: "development";
119
+ readonly build: {
120
+ readonly minify: false;
121
+ readonly sourcemap: "inline";
122
+ };
123
+ };
124
+ /**
125
+ * @example
126
+ * ```ts
127
+ * import { tegoPluginFrontend } from '@tego/plugin-sdk/vite';
128
+ * export default tegoPluginFrontend({ entry: 'src/index.tsx' });
129
+ * ```
130
+ */
131
+ declare function tegoPluginFrontend(options: TegoPluginFrontendOptions): UserConfig;
132
+
133
+ export { TEGO_PLUGIN_DEV_OVERRIDES, type TegoPluginFrontendOptions, type TegoPluginTailwindConfig, type TegoPluginTailwindOptions, tegoPluginFrontend, tegoPluginTailwind };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,133 @@
1
+ import { UserConfig } from 'vite';
2
+
3
+ /**
4
+ * The Tailwind config a plugin frontend compiles its own utilities with.
5
+ *
6
+ * A plugin's CSS is inlined into its bundle and lands in the shell's document,
7
+ * next to the shell's own stylesheet. Three things make that safe, and each
8
+ * one, left out, produces a plugin that builds fine and then looks wrong
9
+ * inside the shell:
10
+ *
11
+ * - The design tokens come from `@tego/ui`'s preset, the same one the shell
12
+ * compiles with, so `bg-primary` means the same colour on both sides.
13
+ * - Preflight is off: the shell already ships the reset, and a second copy
14
+ * loaded later would restyle the shell's own elements.
15
+ * - Every utility is scoped under `.<pluginId>`, the class the shell puts on
16
+ * the plugin's root, so a plugin's `.hidden` cannot hide shell UI.
17
+ *
18
+ * Content also covers the compiled `@tego/ui` and `@tego/plugin-access-ui`
19
+ * code, because their components carry class names the plugin's bundle must
20
+ * define: the shell does not compile classes for components it never renders
21
+ * itself.
22
+ *
23
+ * Resolution starts from `root` — the plugin's frontend directory — so the
24
+ * same call works inside this repo and in a plugin installed from npm.
25
+ * `tailwindcss` stays the plugin's own dependency; this returns plain config:
26
+ *
27
+ * ```ts
28
+ * import tailwindcss from 'tailwindcss';
29
+ * import { tegoPluginTailwind } from '@tego/plugin-sdk/vite';
30
+ *
31
+ * config.css = {
32
+ * postcss: {
33
+ * plugins: [
34
+ * tailwindcss(
35
+ * tegoPluginTailwind({
36
+ * pluginId: 'acme-crm',
37
+ * root: import.meta.dirname,
38
+ * content: [resolve(import.meta.dirname, 'src/**\/*.{ts,tsx}')],
39
+ * })
40
+ * ),
41
+ * ],
42
+ * },
43
+ * };
44
+ * ```
45
+ */
46
+ interface TegoPluginTailwindOptions {
47
+ /** The plugin id; utilities are scoped under `.<pluginId>`. */
48
+ pluginId: string;
49
+ /** Directory package resolution starts from: the plugin's frontend dir. */
50
+ root: string;
51
+ /** Absolute globs of the plugin's own sources. */
52
+ content: string[];
53
+ }
54
+ /**
55
+ * The subset of a Tailwind v3 config this produces, typed so it passes
56
+ * straight to `tailwindcss(…)` without the SDK depending on tailwindcss.
57
+ * The preset is `@tego/ui`'s CommonJS module, opaque here.
58
+ */
59
+ interface TegoPluginTailwindConfig {
60
+ presets: object[];
61
+ content: string[];
62
+ corePlugins: {
63
+ preflight: false;
64
+ };
65
+ important: string;
66
+ }
67
+ declare function tegoPluginTailwind({ pluginId, root, content, }: TegoPluginTailwindOptions): TegoPluginTailwindConfig;
68
+
69
+ /**
70
+ * The Vite config a plugin's frontend part is built with.
71
+ *
72
+ * Not a convenience wrapper: the shell can only load a bundle that is a
73
+ * SystemJS module whose shared imports were rewritten to the exact ids the
74
+ * shell registered. Both of those are one-line mistakes that produce a plugin
75
+ * which builds cleanly and then fails at load with a message about an unknown
76
+ * scheme, so the settings live here rather than in every plugin's own config.
77
+ *
78
+ * Imported only by a plugin's `vite.config.ts`; `vite` is a peer dependency
79
+ * and nothing else in the SDK reaches this module.
80
+ */
81
+
82
+ interface TegoPluginFrontendOptions {
83
+ /** Entry module whose default export is the `PluginFrontendModule`. */
84
+ entry: string;
85
+ /**
86
+ * The manifest `id`, stamped onto the inlined `<style>` as
87
+ * `data-tego-plugin`. The shell removes styles by this attribute when the
88
+ * plugin page unmounts. Omit it and the attribute is left empty — an older
89
+ * bundle's behaviour, which the shell leaves in place rather than removing.
90
+ */
91
+ pluginId?: string;
92
+ /** Defaults to `dist`, which is what the packaging step expects. */
93
+ outDir?: string;
94
+ /**
95
+ * Build the development form instead of the distributable one.
96
+ *
97
+ * See {@link TEGO_PLUGIN_DEV_OVERRIDES}. `tego-plugin-pack --watch` applies
98
+ * the same overrides without this flag, so a plugin only needs it when it
99
+ * drives Vite itself.
100
+ */
101
+ development?: boolean;
102
+ }
103
+ /**
104
+ * The development form, as a config patch.
105
+ *
106
+ * What it does *not* change is the point: the module format, the externals and
107
+ * the browser target stay exactly as they are in a packed archive, because
108
+ * those are what the shell's loader requires and a bundle that differed there
109
+ * would not be testing the real thing. It changes only the two things that
110
+ * make a watch loop unusable — a minified frame in an anonymous SystemJS
111
+ * module points nowhere, and minifying on every keystroke is the slowest part
112
+ * of the rebuild.
113
+ *
114
+ * Exported so `tego-plugin-pack --watch` and the preset apply one definition
115
+ * rather than two that can drift.
116
+ */
117
+ declare const TEGO_PLUGIN_DEV_OVERRIDES: {
118
+ readonly mode: "development";
119
+ readonly build: {
120
+ readonly minify: false;
121
+ readonly sourcemap: "inline";
122
+ };
123
+ };
124
+ /**
125
+ * @example
126
+ * ```ts
127
+ * import { tegoPluginFrontend } from '@tego/plugin-sdk/vite';
128
+ * export default tegoPluginFrontend({ entry: 'src/index.tsx' });
129
+ * ```
130
+ */
131
+ declare function tegoPluginFrontend(options: TegoPluginFrontendOptions): UserConfig;
132
+
133
+ export { TEGO_PLUGIN_DEV_OVERRIDES, type TegoPluginFrontendOptions, type TegoPluginTailwindConfig, type TegoPluginTailwindOptions, tegoPluginFrontend, tegoPluginTailwind };
package/dist/vite.js ADDED
@@ -0,0 +1 @@
1
+ export{TEGO_PLUGIN_DEV_OVERRIDES,tegoPluginFrontend,tegoPluginTailwind}from"./chunk-7K37PVGV.js";import"./chunk-7XHF3YSK.js";
package/package.json CHANGED
@@ -1,6 +1,162 @@
1
1
  {
2
2
  "name": "@zhama/tego-plugin-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.36.0",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./manifest": {
17
+ "types": "./dist/manifest.d.ts",
18
+ "import": "./dist/manifest.js",
19
+ "require": "./dist/manifest.cjs",
20
+ "default": "./dist/manifest.js"
21
+ },
22
+ "./frontend": {
23
+ "types": "./dist/frontend.d.ts",
24
+ "import": "./dist/frontend.js",
25
+ "require": "./dist/frontend.cjs",
26
+ "default": "./dist/frontend.js"
27
+ },
28
+ "./server": {
29
+ "types": "./dist/server.d.ts",
30
+ "import": "./dist/server.js",
31
+ "require": "./dist/server.cjs",
32
+ "default": "./dist/server.js"
33
+ },
34
+ "./access": {
35
+ "types": "./dist/access.d.ts",
36
+ "import": "./dist/access.js",
37
+ "require": "./dist/access.cjs",
38
+ "default": "./dist/access.js"
39
+ },
40
+ "./access/drizzle": {
41
+ "types": "./dist/access-drizzle.d.ts",
42
+ "import": "./dist/access-drizzle.js",
43
+ "require": "./dist/access-drizzle.cjs",
44
+ "default": "./dist/access-drizzle.js"
45
+ },
46
+ "./access/hono": {
47
+ "types": "./dist/access-hono.d.ts",
48
+ "import": "./dist/access-hono.js",
49
+ "require": "./dist/access-hono.cjs",
50
+ "default": "./dist/access-hono.js"
51
+ },
52
+ "./access/implications": {
53
+ "types": "./dist/access-implications.d.ts",
54
+ "import": "./dist/access-implications.js",
55
+ "require": "./dist/access-implications.cjs",
56
+ "default": "./dist/access-implications.js"
57
+ },
58
+ "./access.sql": "./sql/access.sql",
59
+ "./access-catalog.schema.json": "./access-catalog.schema.json",
60
+ "./vite": {
61
+ "types": "./dist/vite.d.ts",
62
+ "import": "./dist/vite.js",
63
+ "require": "./dist/vite.cjs",
64
+ "default": "./dist/vite.js"
65
+ },
66
+ "./scaffold": {
67
+ "types": "./dist/scaffold.d.ts",
68
+ "import": "./dist/scaffold.js",
69
+ "require": "./dist/scaffold.cjs",
70
+ "default": "./dist/scaffold.js"
71
+ },
72
+ "./server-runtime": {
73
+ "types": "./dist/server-runtime.d.ts",
74
+ "import": "./dist/server-runtime.js",
75
+ "require": "./dist/server-runtime.cjs",
76
+ "default": "./dist/server-runtime.js"
77
+ },
78
+ "./egress": {
79
+ "types": "./dist/egress.d.ts",
80
+ "import": "./dist/egress.js",
81
+ "require": "./dist/egress.cjs",
82
+ "default": "./dist/egress.js"
83
+ },
84
+ "./gateway-signature": {
85
+ "types": "./dist/gateway-signature.d.ts",
86
+ "import": "./dist/gateway-signature.js",
87
+ "require": "./dist/gateway-signature.cjs",
88
+ "default": "./dist/gateway-signature.js"
89
+ },
90
+ "./mcp-identity": {
91
+ "types": "./dist/mcp-identity.d.ts",
92
+ "import": "./dist/mcp-identity.js",
93
+ "require": "./dist/mcp-identity.cjs",
94
+ "default": "./dist/mcp-identity.js"
95
+ },
96
+ "./pack": {
97
+ "types": "./dist/pack.d.ts",
98
+ "import": "./dist/pack.js",
99
+ "default": "./dist/pack.js"
100
+ },
101
+ "./publish": {
102
+ "types": "./dist/publish.d.ts",
103
+ "import": "./dist/publish.js",
104
+ "default": "./dist/publish.js"
105
+ },
106
+ "./testing": {
107
+ "types": "./dist/testing.d.ts",
108
+ "import": "./dist/testing.js",
109
+ "default": "./dist/testing.js"
110
+ }
111
+ },
112
+ "bin": {
113
+ "tego-plugin-pack": "./bin/tego-plugin-pack.mjs",
114
+ "tego-plugin": "./bin/tego-plugin.mjs"
115
+ },
116
+ "files": [
117
+ "dist",
118
+ "bin",
119
+ "sql",
120
+ "access-fixtures",
121
+ "access-catalog.schema.json"
122
+ ],
123
+ "dependencies": {
124
+ "esbuild": "^0.25.12",
125
+ "jszip": "^3.10.1",
126
+ "magic-string": "^0.30.21",
127
+ "zod": "^3.24.1",
128
+ "zod-to-json-schema": "^3.25.2"
129
+ },
130
+ "peerDependencies": {
131
+ "pg": "^8.13.1",
132
+ "vite": "^6.0.0",
133
+ "hono": "^4.10.7",
134
+ "drizzle-orm": "^0.38.3"
135
+ },
136
+ "peerDependenciesMeta": {
137
+ "pg": {
138
+ "optional": true
139
+ },
140
+ "vite": {
141
+ "optional": true
142
+ },
143
+ "hono": {
144
+ "optional": true
145
+ },
146
+ "drizzle-orm": {
147
+ "optional": true
148
+ }
149
+ },
150
+ "description": "Create, build, package and test Tego plugins: tego-plugin create, manifest, frontend/backend APIs, access control and tego-plugin-pack",
151
+ "license": "SEE LICENSE IN LICENSE",
152
+ "repository": {
153
+ "type": "git",
154
+ "url": "git+https://github.com/zhama-ai/tego-os.git",
155
+ "directory": "packages/plugin-sdk"
156
+ },
157
+ "homepage": "https://github.com/zhama-ai/tego-os/tree/main/packages/plugin-sdk#readme",
158
+ "keywords": [
159
+ "tego",
160
+ "tego-plugin"
161
+ ]
162
+ }