@beechcms/api 0.6.7 → 0.8.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/assets/dashboard/0auth_mcp.svg +1 -0
- package/assets/dashboard/assets/{chart-D_uST30B.js → chart-CYgKoF6U.js} +6 -6
- package/assets/dashboard/assets/dist-DHabpZqA.js +140 -0
- package/assets/dashboard/assets/index-BZMSpYrl.js +3613 -0
- package/assets/dashboard/assets/index-Dex2YZcC.css +1 -0
- package/assets/dashboard/assets/json-code-editor-DtZpKDXm.js +12 -0
- package/assets/dashboard/assets/pie-chart-recharts-C7WAhcCk.js +1 -0
- package/assets/dashboard/assets/richtext-render-x0TT0116.js +258 -0
- package/assets/dashboard/assets/timeseries-chart-recharts-B9RquiY6.js +1 -0
- package/assets/dashboard/assets/w3c-keyname-BOAvb0qz.js +1 -0
- package/assets/dashboard/index.html +4 -2
- package/dist/auth/auth.app.d.ts +13 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/factory.d.ts +14 -1
- package/dist/features/oauth/authorization-request.d.ts +127 -0
- package/dist/features/oauth/authorize.d.ts +97 -0
- package/dist/features/oauth/consents.d.ts +75 -0
- package/dist/features/oauth/constants.d.ts +48 -0
- package/dist/features/oauth/index.d.ts +31 -0
- package/dist/features/oauth/revoke.d.ts +29 -0
- package/dist/features/oauth/token-issuance.d.ts +49 -0
- package/dist/features/oauth/token.d.ts +38 -0
- package/dist/features/search/constants.d.ts +43 -0
- package/dist/features/search/handlers/embed.d.ts +31 -0
- package/dist/features/search/handlers/full-text-search.d.ts +28 -0
- package/dist/features/search/index.d.ts +20 -0
- package/dist/features/search/jobs/semantic-search.hooks.d.ts +21 -0
- package/dist/features/search/jobs/semantic-search.worker.d.ts +101 -0
- package/dist/features/search/public-search.router.d.ts +15 -0
- package/dist/features/search/search.d.ts +14 -6
- package/dist/features/search/semantic-search.hooks.d.ts +2 -0
- package/dist/features/search/semantic-search.worker.d.ts +21 -0
- package/dist/features/search/types.d.ts +100 -0
- package/dist/features/search/utils/search-utils.d.ts +56 -0
- package/dist/features/seeds/seeds.destructive.d.ts +6 -0
- package/dist/features/seeds/seeds.handler.d.ts +14 -0
- package/dist/features/seeds/seeds.helpers.d.ts +118 -0
- package/dist/features/seeds/seeds.mcp.d.ts +37 -0
- package/dist/features/upload/index.d.ts +2 -2
- package/dist/index.js +3544 -1368
- package/dist/middleware/auth.middleware.d.ts +34 -4
- package/dist/middleware/oauth-scope.middleware.d.ts +60 -0
- package/dist/middleware/rate-limit.middleware.d.ts +4 -2
- package/dist/middleware/repository.middleware.d.ts +9 -1
- package/dist/public/api-key-middleware.d.ts +0 -4
- package/dist/public/public-add.d.ts +1 -1
- package/dist/rate-limit/in-memory-rate-limiter.d.ts +1 -8
- package/dist/shared/db/repositories/content.repository.d1.d.ts +4 -2
- package/dist/shared/db/repositories/d1-oauth-authorization-code.repository.d.ts +9 -0
- package/dist/shared/db/repositories/d1-oauth-client.repository.d.ts +6 -0
- package/dist/shared/db/repositories/d1-oauth-consent.repository.d.ts +10 -0
- package/dist/shared/db/repositories/d1-oauth-token.repository.d.ts +12 -0
- package/dist/shared/db/repositories/d1-search.query.d.ts +54 -0
- package/dist/shared/db/repositories/d1-vector.repository.d.ts +11 -0
- package/dist/shared/db/repositories/in-memory-seed.repository.d.ts +2 -1
- package/dist/shared/db/repositories/seed.repository.d1.d.ts +3 -1
- package/dist/shared/db/repositories/time-trap-token.repository.d1.d.ts +7 -0
- package/dist/shared/storage/factory.d.ts +84 -4
- package/dist/shared/storage/r2-bucket.d.ts +127 -0
- package/dist/shared/storage/s3-bucket.d.ts +104 -10
- package/dist/shared/storage/upload.d.ts +33 -5
- package/dist/shared/utils/dual-key-rate-limiter.d.ts +21 -0
- package/dist/shared/utils/media-utils.d.ts +3 -3
- package/dist/shared/utils/opaque-token.d.ts +13 -0
- package/dist/types.d.ts +49 -1
- package/migrations/0000_v040_base.sql +184 -1
- package/migrations/_archive/0000_schema_init.sql +257 -0
- package/migrations/_archive/0001_init.sql +25 -0
- package/migrations/_archive/0002_seed_admin.sql +10 -0
- package/migrations/_archive/0003_refresh_tokens.sql +17 -0
- package/migrations/_archive/0004_seed_projects.sql +18 -0
- package/migrations/_archive/0005_update_projects.sql +56 -0
- package/migrations/_archive/0006_add_slug_and_unique_index.sql +7 -0
- package/migrations/_archive/0007_cleanup_test_data.sql +4 -0
- package/migrations/_archive/0008_seed_content_entries.sql +104 -0
- package/migrations/_archive/0009_public_idempotency.sql +11 -0
- package/migrations/_archive/0010_seed_real_data.sql +31 -0
- package/migrations/_archive/0010_testsite_data.sql +31 -0
- package/migrations/_archive/0011_analytics.sql +10 -0
- package/migrations/_archive/0012_seed_analytics.sql +17 -0
- package/migrations/_archive/0013_system_stats.sql +8 -0
- package/migrations/_archive/0014_activity_logs.sql +15 -0
- package/migrations/_archive/0015_notifications.sql +12 -0
- package/migrations/_archive/0016_fts5_global_search.sql +81 -0
- package/migrations/_archive/0017_seed_clienti.sql +90 -0
- package/migrations/_archive/0018_draft_data.sql +3 -0
- package/migrations/_archive/0019_drop_fts_triggers.sql +7 -0
- package/migrations/_archive/0020_composite_indexes.sql +15 -0
- package/migrations/_archive/0021_media_objects.sql +15 -0
- package/migrations/_archive/0022_analytics_seed.sql +23 -0
- package/migrations/_archive/0023_user_profile.sql +4 -0
- package/migrations/_archive/0024_activity_user_name.sql +3 -0
- package/migrations/_archive/0025_password_reset_tokens.sql +11 -0
- package/migrations/_archive/0026_remove_dev_admin.sql +4 -0
- package/migrations/_archive/0027_v040_doctype_architecture.sql +51 -0
- package/migrations/_archive/0029_fts_all_text_branches.sql +281 -0
- package/migrations/_archive/0031_site_settings.sql +9 -0
- package/migrations/_archive/0032_seeds.sql +28 -0
- package/migrations/_archive/0033_dashboard_layouts.sql +14 -0
- package/migrations/_archive/0034_kanban_foundation.sql +24 -0
- package/migrations/_archive/0035_setup_lock.sql +10 -0
- package/migrations/_archive/0036_notification_type_success.sql +23 -0
- package/migrations/_archive/0037_time_trap_tokens.sql +13 -0
- package/migrations/_archive/0038_oauth_authorization.sql +95 -0
- package/migrations/_archive/0039_oauth_client_beech_mcp.sql +20 -0
- package/package.json +3 -5
- package/assets/dashboard/assets/index-B58kBLrh.css +0 -1
- package/assets/dashboard/assets/index-DjniT5Z9.js +0 -745
- package/assets/dashboard/assets/pie-chart-recharts-CnVomiSi.js +0 -1
- package/assets/dashboard/assets/timeseries-chart-recharts-CTqi8qnV.js +0 -1
- /package/migrations/{0029_automations.sql → _archive/0029_automations.sql} +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { Branch, Seed } from '@beechcms/core';
|
|
3
|
+
import { SLUG_RE, SEED_SLUG_RE } from '@beechcms/core';
|
|
4
|
+
import type { Env, Variables } from '../../types';
|
|
5
|
+
export type AppContext = Context<{
|
|
6
|
+
Bindings: Env;
|
|
7
|
+
Variables: Variables;
|
|
8
|
+
}>;
|
|
9
|
+
export { SLUG_RE, SEED_SLUG_RE };
|
|
10
|
+
/**
|
|
11
|
+
* Guard ensuring the authenticated caller possesses the `'admin'` role.
|
|
12
|
+
*
|
|
13
|
+
* @param context - The Hono request context with bound JWT payload variables.
|
|
14
|
+
* @returns A 403 Forbidden RFC 7807 Problem Details Response if unauthorized, or `null` if authorized.
|
|
15
|
+
*/
|
|
16
|
+
export declare function requireAdmin(context: AppContext): Response | null;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts audit logging actor metadata from the request's JWT payload.
|
|
19
|
+
*
|
|
20
|
+
* @param context - The Hono request context.
|
|
21
|
+
* @returns The actor representation containing user ID (`sub`), email address, and formatted full name.
|
|
22
|
+
*/
|
|
23
|
+
export declare function actorFromContext(context: AppContext): {
|
|
24
|
+
id: string;
|
|
25
|
+
email: string;
|
|
26
|
+
name: string | null;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Safely parses the incoming HTTP request body as JSON.
|
|
30
|
+
*
|
|
31
|
+
* @param context - The Hono request context.
|
|
32
|
+
* @returns The parsed JSON body payload, or a 400 Bad Request Problem Details Response on syntax failure.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseJsonBody(context: AppContext): Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves an active seed record by slug from the database repository.
|
|
37
|
+
*
|
|
38
|
+
* @param context - The Hono request context.
|
|
39
|
+
* @param slug - The unique slug identifier of the seed.
|
|
40
|
+
* @returns The active seed entity record, or a 404 Not Found Problem Details Response if nonexistent or soft-deleted.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getActiveSeed(context: AppContext, slug: string): Promise<Response | import("@beechcms/core").SeedRecord>;
|
|
43
|
+
/**
|
|
44
|
+
* Validates a candidate seed definition against active system seeds and applies additive schema mutations.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* 1. Checks relational constraints, duplicate aliases, and format validity across all active seeds.
|
|
48
|
+
* 2. Compares definition against physical database columns (`content_<slug>`).
|
|
49
|
+
* 3. Plans and executes DDL via `planCreateSeed` (new table) or `planExtendSeed` (additive columns).
|
|
50
|
+
* 4. Upserts definition into `SeedRepository` with `'runtime'` source and bumps the registry version for OCC.
|
|
51
|
+
* 5. Dispatches an audit event to the activity logger.
|
|
52
|
+
*
|
|
53
|
+
* @param context - The Hono request context.
|
|
54
|
+
* @param slug - The target seed slug.
|
|
55
|
+
* @param candidate - The proposed seed definition.
|
|
56
|
+
* @param action - Action tag for activity logging (`'create'` or `'update'`).
|
|
57
|
+
* @param logDetails - Metadata payload for audit trail recording.
|
|
58
|
+
* @returns `null` upon successful execution, or a 422 Unprocessable Entity Problem Details Response on validation or DDL failure.
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateAndApplySeedDef(context: AppContext, slug: string, candidate: Seed, action: 'create' | 'update', logDetails: any): Promise<Response | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Executes destructive DDL statements and persists the updated seed definition.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Used for operations that cannot be planned additively (e.g. column drops, renames, and type conversions).
|
|
66
|
+
* Runs SQL statements through `schemaMutator.execDestructive`, updates the stored definition,
|
|
67
|
+
* increments the schema registry version, and logs the operation.
|
|
68
|
+
*
|
|
69
|
+
* @param context - The Hono request context.
|
|
70
|
+
* @param slug - The unique slug identifier of the seed.
|
|
71
|
+
* @param updatedDef - The new seed definition reflecting the destructive change.
|
|
72
|
+
* @param stmts - The SQL DDL statements generated for the destructive migration.
|
|
73
|
+
* @param logDetails - Operation details for the audit log.
|
|
74
|
+
* @returns `null` on success, or a 422 Unprocessable Entity Problem Details Response on DDL execution failure.
|
|
75
|
+
*/
|
|
76
|
+
export declare function applyDestructiveSeedDef(context: AppContext, slug: string, updatedDef: Seed, stmts: string[], logDetails: any): Promise<Response | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Typed confirmation guard for destructive operations.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* Validates that the request body contains a string field `confirm` matching `expected`
|
|
82
|
+
* (e.g. `<slug>` for hard drops, or `<slug>.<branchAlias>` for column drops/renames/retypes).
|
|
83
|
+
*
|
|
84
|
+
* @param context - The Hono request context.
|
|
85
|
+
* @param expected - Expected confirmation token string.
|
|
86
|
+
* @param body - Parsed request body object.
|
|
87
|
+
* @returns `null` if confirmation matches, or a 400 Bad Request Problem Details Response on mismatch.
|
|
88
|
+
*/
|
|
89
|
+
export declare function requireConfirm(context: AppContext, expected: string, body: unknown): Response | null;
|
|
90
|
+
/**
|
|
91
|
+
* Validates incoming branches during a definition update (PUT) to reject unconfirmed destructive operations.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Compares incoming branches against stored definitions by ID. If an alias rename or branch type change
|
|
95
|
+
* is detected, rejects the request with a 422 error pointing the caller to dedicated PATCH endpoints.
|
|
96
|
+
* Automatically allocates next sequential branch IDs for any newly appended branches lacking an ID.
|
|
97
|
+
*
|
|
98
|
+
* @param incomingBranches - Branch definitions provided in the update payload.
|
|
99
|
+
* @param storedBranches - Currently persisted branch definitions in the repository.
|
|
100
|
+
* @param slug - The seed slug being updated.
|
|
101
|
+
* @param context - The Hono request context.
|
|
102
|
+
* @returns `null` if valid, or a 422 Unprocessable Entity Problem Details Response on rejected destructive changes.
|
|
103
|
+
*/
|
|
104
|
+
export declare function validateIncomingBranches(incomingBranches: Branch[], storedBranches: Branch[], slug: string, context: AppContext): Response | null;
|
|
105
|
+
/**
|
|
106
|
+
* Scans content records of a seed to extract and delete referenced R2 media objects before table deletion.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Gathers all file branches defined on the seed, selects their column values from `content_<slug>`,
|
|
110
|
+
* extracts storage object keys, and deletes them from Cloudflare R2 storage in batches.
|
|
111
|
+
* Any errors encountered during cleanup are treated as non-fatal warnings to allow table drop to proceed.
|
|
112
|
+
*
|
|
113
|
+
* @param context - The Hono request context.
|
|
114
|
+
* @param slug - The seed slug whose media assets are being purged.
|
|
115
|
+
* @param seed - The seed definition containing branch configurations.
|
|
116
|
+
* @param schemaMutator - Schema mutator instance used to query existing database columns.
|
|
117
|
+
*/
|
|
118
|
+
export declare function deleteSeedMediaObjects(context: AppContext, slug: string, seed: Seed, schemaMutator: any): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import type { Seed } from '@beechcms/core';
|
|
3
|
+
import type { Env, Variables } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes a candidate seed definition for MCP operations:
|
|
6
|
+
* - Preserves existing branch IDs from stored definition by alias matching if omitted.
|
|
7
|
+
* - Auto-assigns sequential branch IDs via `nextBranchId` for new branches that lack one.
|
|
8
|
+
* - Defaults `displayNameAlias` from stored definition or first text branch if omitted.
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeCandidate(candidate: Seed, storedDef: Seed | null): Seed;
|
|
11
|
+
/**
|
|
12
|
+
* Classification of schema migration intent for MCP agents:
|
|
13
|
+
* - `'create'`: Seed does not exist; requires initial table and index creation.
|
|
14
|
+
* - `'additive'`: Additive schema extensions (adding new columns/branches).
|
|
15
|
+
* - `'destructive'`: Involves dropping, renaming, or retyping columns; disallowed in generic MCP apply.
|
|
16
|
+
*/
|
|
17
|
+
export type McpClassification = 'create' | 'additive' | 'destructive';
|
|
18
|
+
/**
|
|
19
|
+
* Diffs a proposed candidate seed against the stored seed definition to detect destructive intent.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Evaluates whether any branches are omitted (drops), have altered aliases (renames),
|
|
23
|
+
* or have changed types. Because `planExtendSeed` is strictly additive and cannot emit destructive DDL,
|
|
24
|
+
* destructive intent must be classified here to reject or require confirmation.
|
|
25
|
+
*
|
|
26
|
+
* @param stored - Stored seed definition from the repository, or `null` if creating.
|
|
27
|
+
* @param candidate - Proposed candidate seed definition.
|
|
28
|
+
* @returns An object with the classification (`create`, `additive`, or `destructive`) and a list of blocking reasons.
|
|
29
|
+
*/
|
|
30
|
+
export declare function classifyCandidate(stored: Seed | null, candidate: Seed): {
|
|
31
|
+
classification: McpClassification;
|
|
32
|
+
blockedReasons: string[];
|
|
33
|
+
};
|
|
34
|
+
export declare const mcpApp: Hono<{
|
|
35
|
+
Bindings: Env;
|
|
36
|
+
Variables: Variables;
|
|
37
|
+
}, import("hono/types").BlankSchema, "/">;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Upload feature — presigned R2 uploads and media serving.
|
|
3
3
|
* The Worker never receives file bytes: it acts as auth gatekeeper and signer only.
|
|
4
4
|
*/
|
|
5
|
-
import { Hono } from 'hono';
|
|
5
|
+
import { Hono, type Context } from 'hono';
|
|
6
6
|
import { AppEnv } from '../../types';
|
|
7
7
|
export declare const uploadRoutes: Hono<AppEnv, import("hono/types").BlankSchema, "/">;
|
|
8
8
|
/** Serve a file from storage (used by the public /api/media/:key route). */
|
|
9
|
-
export declare function serveMediaHandler(c:
|
|
9
|
+
export declare function serveMediaHandler(c: Context<AppEnv>): Promise<Response>;
|