@plandesk/api 1.0.0-beta.7 → 1.0.0-beta.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plandesk/api",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -26,7 +26,7 @@
26
26
  "@libsql/kysely-libsql": "^0.4.1",
27
27
  "better-auth": "1.6.23",
28
28
  "hono": "^4.12.23",
29
- "@plandesk/db": "1.0.0-beta.7"
29
+ "@plandesk/db": "1.0.0-beta.8"
30
30
  },
31
31
  "description": "Plan Desk REST + SSE API and service layer (local-first planning workspace).",
32
32
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "tasks"
49
49
  ],
50
50
  "scripts": {
51
- "build": "tsc -p tsconfig.json",
51
+ "build": "rm -rf dist && tsc -p tsconfig.json",
52
52
  "test": "vitest run",
53
53
  "lint": "eslint src"
54
54
  }
package/dist/events.d.ts DELETED
@@ -1,97 +0,0 @@
1
- export type TaskUpdatedEvent = {
2
- type: 'task_updated';
3
- taskId: string;
4
- projectId: string;
5
- };
6
- export type CanvasUpdatedEvent = {
7
- type: 'canvas_updated';
8
- projectId: string;
9
- };
10
- export type DocumentCreatedEvent = {
11
- type: 'document_created';
12
- documentId: string;
13
- projectId: string;
14
- };
15
- export type CommentCreatedEvent = {
16
- type: 'comment_created';
17
- commentId: string;
18
- projectId: string;
19
- target_type: string;
20
- target_id: string;
21
- documentId?: string;
22
- };
23
- export type CommentUpdatedEvent = {
24
- type: 'comment_updated';
25
- commentId: string;
26
- projectId: string;
27
- target_type: string;
28
- target_id: string;
29
- documentId?: string;
30
- };
31
- export type FolderCreatedEvent = {
32
- type: 'folder_created';
33
- folderId: string;
34
- projectId: string;
35
- };
36
- export type FolderUpdatedEvent = {
37
- type: 'folder_updated';
38
- folderId: string;
39
- projectId: string;
40
- };
41
- export type TagUpdatedEvent = {
42
- type: 'tag_updated';
43
- projectId: string;
44
- };
45
- export type NoteCreatedEvent = {
46
- type: 'note_created';
47
- noteId: string;
48
- projectId: string;
49
- };
50
- export type NoteUpdatedEvent = {
51
- type: 'note_updated';
52
- noteId: string;
53
- projectId: string;
54
- };
55
- export type ArtifactCreatedEvent = {
56
- type: 'artifact_created';
57
- artifactId: string;
58
- projectId: string;
59
- };
60
- export type ArtifactUpdatedEvent = {
61
- type: 'artifact_updated';
62
- artifactId: string;
63
- projectId: string;
64
- };
65
- export type AgentRunStartedEvent = {
66
- type: 'agent_run_started';
67
- runId: string;
68
- projectId: string;
69
- };
70
- export type AgentRunProgressEvent = {
71
- type: 'agent_run_progress';
72
- runId: string;
73
- projectId: string;
74
- };
75
- export type AgentRunCompletedEvent = {
76
- type: 'agent_run_completed';
77
- runId: string;
78
- projectId: string;
79
- };
80
- export type SubmissionsPulledEvent = {
81
- type: 'submissions_pulled';
82
- projectId: string;
83
- };
84
- export type GoalUpdatedEvent = {
85
- type: 'goal_updated';
86
- goalId: string;
87
- projectId: string;
88
- };
89
- export type PlankDeskEvent = TaskUpdatedEvent | TagUpdatedEvent | CanvasUpdatedEvent | DocumentCreatedEvent | CommentCreatedEvent | CommentUpdatedEvent | FolderCreatedEvent | FolderUpdatedEvent | NoteCreatedEvent | NoteUpdatedEvent | ArtifactCreatedEvent | ArtifactUpdatedEvent | AgentRunStartedEvent | AgentRunProgressEvent | AgentRunCompletedEvent | SubmissionsPulledEvent | GoalUpdatedEvent;
90
- export type EventListener = (event: PlankDeskEvent) => void;
91
- export type EventBus = {
92
- subscribe(listener: EventListener): () => void;
93
- emit(event: PlankDeskEvent): void;
94
- subscriberCount(): number;
95
- };
96
- export declare function createEventBus(): EventBus;
97
- //# sourceMappingURL=events.d.ts.map
package/dist/events.js DELETED
@@ -1,20 +0,0 @@
1
- export function createEventBus() {
2
- const listeners = new Set();
3
- return {
4
- subscribe(listener) {
5
- listeners.add(listener);
6
- return () => {
7
- listeners.delete(listener);
8
- };
9
- },
10
- emit(event) {
11
- for (const listener of listeners) {
12
- listener(event);
13
- }
14
- },
15
- subscriberCount() {
16
- return listeners.size;
17
- },
18
- };
19
- }
20
- //# sourceMappingURL=events.js.map
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- import type { EventBus } from '../events.js';
3
- export declare function createEventsRouter(eventBus: EventBus): Hono;
4
- //# sourceMappingURL=events.d.ts.map
@@ -1,35 +0,0 @@
1
- import { Hono } from 'hono';
2
- import { streamSSE } from 'hono/streaming';
3
- export function createEventsRouter(eventBus) {
4
- const router = new Hono();
5
- router.get('/events', (c) => {
6
- return streamSSE(c, async (stream) => {
7
- let active = true;
8
- const unsub = eventBus.subscribe((event) => {
9
- void stream.writeSSE({ data: JSON.stringify(event) });
10
- });
11
- const cleanup = () => {
12
- if (!active) {
13
- return;
14
- }
15
- active = false;
16
- unsub();
17
- };
18
- c.req.raw.signal.addEventListener('abort', cleanup, { once: true });
19
- stream.onAbort(cleanup);
20
- await new Promise((resolve) => {
21
- if (c.req.raw.signal.aborted) {
22
- cleanup();
23
- resolve();
24
- return;
25
- }
26
- c.req.raw.signal.addEventListener('abort', () => {
27
- cleanup();
28
- resolve();
29
- }, { once: true });
30
- });
31
- });
32
- });
33
- return router;
34
- }
35
- //# sourceMappingURL=events.js.map
@@ -1,4 +0,0 @@
1
- import { Hono } from 'hono';
2
- import type { TokenService } from '../services/tokens.js';
3
- export declare function createTokensRouter(tokenService: TokenService): Hono;
4
- //# sourceMappingURL=tokens.d.ts.map
@@ -1,22 +0,0 @@
1
- import { Hono } from 'hono';
2
- export function createTokensRouter(tokenService) {
3
- const router = new Hono();
4
- router.post('/mcp-tokens', async (c) => {
5
- const body = await c.req.json();
6
- if (typeof body.name !== 'string' || body.name.trim() === '') {
7
- return c.json({ error: 'invalid_argument' }, 400);
8
- }
9
- const created = await tokenService.create(body.name.trim());
10
- return c.json(created, 201);
11
- });
12
- router.get('/mcp-tokens', async (c) => c.json(await tokenService.list()));
13
- router.delete('/mcp-tokens/:id', async (c) => {
14
- const revoked = await tokenService.revoke(c.req.param('id'));
15
- if (!revoked) {
16
- return c.json({ error: 'not_found' }, 404);
17
- }
18
- return c.body(null, 204);
19
- });
20
- return router;
21
- }
22
- //# sourceMappingURL=tokens.js.map
@@ -1,16 +0,0 @@
1
- import { type Db } from '@plandesk/db';
2
- import { type OrgScopedDeps } from './org-scope.js';
3
- export type TokenServiceDeps = OrgScopedDeps & {
4
- db: Db;
5
- };
6
- export declare function createTokenService(deps: TokenServiceDeps): {
7
- create(name: string): Promise<{
8
- id: string;
9
- name: string;
10
- token: string;
11
- }>;
12
- list(): Promise<import("../serialize.js").SerializedToken[]>;
13
- revoke(id: string): Promise<import("../serialize.js").SerializedToken | undefined>;
14
- };
15
- export type TokenService = ReturnType<typeof createTokenService>;
16
- //# sourceMappingURL=tokens.d.ts.map
@@ -1,33 +0,0 @@
1
- import { createToken as dbCreateToken, listTokens as dbListTokens, revokeToken as dbRevokeToken, } from '@plandesk/db';
2
- import { serializeToken } from '../serialize.js';
3
- import { assertPermission, resolveOrgId } from './org-scope.js';
4
- export function createTokenService(deps) {
5
- const { db } = deps;
6
- return {
7
- async create(name) {
8
- assertPermission(deps, 'apiKey', 'create');
9
- const orgId = resolveOrgId(deps);
10
- const result = await dbCreateToken(db, { name, orgId });
11
- return {
12
- id: result.id,
13
- name: result.name,
14
- token: result.token,
15
- };
16
- },
17
- async list() {
18
- assertPermission(deps, 'apiKey', 'read');
19
- const orgId = resolveOrgId(deps);
20
- return (await dbListTokens(db, orgId)).map(serializeToken);
21
- },
22
- async revoke(id) {
23
- assertPermission(deps, 'apiKey', 'delete');
24
- const orgId = resolveOrgId(deps);
25
- const revoked = await dbRevokeToken(db, id, orgId);
26
- if (!revoked) {
27
- return undefined;
28
- }
29
- return serializeToken(revoked);
30
- },
31
- };
32
- }
33
- //# sourceMappingURL=tokens.js.map
@@ -1,16 +0,0 @@
1
- import type { BetterAuthInstance } from './better-auth.js';
2
- export type BaOrg = {
3
- id: string;
4
- name: string;
5
- slug: string;
6
- createdAt: Date;
7
- };
8
- /** Create a better-auth organization row (test fixture). */
9
- export declare function createBaOrg(auth: BetterAuthInstance, input: {
10
- name: string;
11
- id?: string;
12
- slug?: string;
13
- }): Promise<BaOrg>;
14
- export declare function listBaOrgs(auth: BetterAuthInstance): Promise<BaOrg[]>;
15
- export declare function getBaOrg(auth: BetterAuthInstance, id: string): Promise<BaOrg | undefined>;
16
- //# sourceMappingURL=test-ba-org.d.ts.map
@@ -1,35 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- /** Create a better-auth organization row (test fixture). */
3
- export async function createBaOrg(auth, input) {
4
- const adapter = (await auth.$context).adapter;
5
- const id = input.id ?? randomUUID();
6
- const derivedSlug = input.name
7
- .toLowerCase()
8
- .replace(/[^a-z0-9]+/g, '-')
9
- .replace(/^-|-$/g, '');
10
- const slug = input.slug ?? (derivedSlug.length > 0 ? derivedSlug : `org-${id.slice(0, 8)}`);
11
- const data = {
12
- id,
13
- name: input.name,
14
- slug,
15
- createdAt: new Date(),
16
- };
17
- return adapter.create({
18
- model: 'organization',
19
- data,
20
- forceAllowId: true,
21
- });
22
- }
23
- export async function listBaOrgs(auth) {
24
- const adapter = (await auth.$context).adapter;
25
- return adapter.findMany({ model: 'organization' });
26
- }
27
- export async function getBaOrg(auth, id) {
28
- const adapter = (await auth.$context).adapter;
29
- const org = await adapter.findOne({
30
- model: 'organization',
31
- where: [{ field: 'id', value: id }],
32
- });
33
- return org ?? undefined;
34
- }
35
- //# sourceMappingURL=test-ba-org.js.map