@sonicjs-cms/core 2.0.0-alpha.1 → 2.0.0-alpha.11

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/dist/chunk-3MNMOLSA.js +133 -0
  2. package/dist/chunk-3MNMOLSA.js.map +1 -0
  3. package/dist/{chunk-BRC3F4CG.cjs → chunk-6BHDKYLU.cjs} +8 -2
  4. package/dist/{chunk-KRJMGD4E.js.map → chunk-6BHDKYLU.cjs.map} +1 -1
  5. package/dist/{chunk-CXZDAR6S.js → chunk-7N3HK7ZK.js} +3 -3
  6. package/dist/{chunk-CXZDAR6S.js.map → chunk-7N3HK7ZK.js.map} +1 -1
  7. package/dist/chunk-AGOE25LF.cjs +137 -0
  8. package/dist/chunk-AGOE25LF.cjs.map +1 -0
  9. package/dist/{chunk-NRSL6BQI.js → chunk-BITQ4MFX.js} +3 -3
  10. package/dist/{chunk-NRSL6BQI.js.map → chunk-BITQ4MFX.js.map} +1 -1
  11. package/dist/{chunk-24PWAFUT.cjs → chunk-BUKT6HP5.cjs} +13 -13
  12. package/dist/{chunk-24PWAFUT.cjs.map → chunk-BUKT6HP5.cjs.map} +1 -1
  13. package/dist/chunk-DG4INX36.cjs +14246 -0
  14. package/dist/chunk-DG4INX36.cjs.map +1 -0
  15. package/dist/chunk-FDUDHGI6.js +14233 -0
  16. package/dist/chunk-FDUDHGI6.js.map +1 -0
  17. package/dist/{chunk-L3NXO7Y4.cjs → chunk-FVMV5DKA.cjs} +49 -49
  18. package/dist/{chunk-L3NXO7Y4.cjs.map → chunk-FVMV5DKA.cjs.map} +1 -1
  19. package/dist/{chunk-KRJMGD4E.js → chunk-FZYF43TN.js} +8 -2
  20. package/dist/chunk-FZYF43TN.js.map +1 -0
  21. package/dist/chunk-G4JGVZAF.js +1337 -0
  22. package/dist/chunk-G4JGVZAF.js.map +1 -0
  23. package/dist/{chunk-EMMSS5I5.cjs → chunk-IGJUBJBW.cjs} +8 -2
  24. package/dist/{chunk-ALTMI5Y2.cjs.map → chunk-IGJUBJBW.cjs.map} +1 -1
  25. package/dist/chunk-LEGKJ5DI.cjs +1344 -0
  26. package/dist/chunk-LEGKJ5DI.cjs.map +1 -0
  27. package/dist/{chunk-WJ7QYVR2.cjs → chunk-RNR4HA23.cjs} +4 -4
  28. package/dist/{chunk-WJ7QYVR2.cjs.map → chunk-RNR4HA23.cjs.map} +1 -1
  29. package/dist/{chunk-G3PMV62Z.js → chunk-V4OQ3NZ2.js} +7 -3
  30. package/dist/{chunk-G3PMV62Z.js.map → chunk-V4OQ3NZ2.js.map} +1 -1
  31. package/dist/{chunk-PTQZ5FEI.js → chunk-WESS2U3K.js} +3 -3
  32. package/dist/{chunk-PTQZ5FEI.js.map → chunk-WESS2U3K.js.map} +1 -1
  33. package/dist/index.cjs +147 -101
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.ts +5 -135
  36. package/dist/index.js +24 -9
  37. package/dist/index.js.map +1 -1
  38. package/dist/middleware.cjs +23 -23
  39. package/dist/middleware.d.ts +2 -206
  40. package/dist/middleware.js +3 -3
  41. package/dist/plugins.cjs +8 -8
  42. package/dist/plugins.d.ts +2 -330
  43. package/dist/plugins.js +2 -2
  44. package/dist/routes.cjs +52 -3
  45. package/dist/routes.d.ts +2 -17
  46. package/dist/routes.js +7 -2
  47. package/dist/services.cjs +31 -19
  48. package/dist/services.d.ts +2 -5
  49. package/dist/services.js +3 -3
  50. package/dist/templates.cjs +23 -10
  51. package/dist/templates.d.ts +2 -140
  52. package/dist/templates.js +3 -2
  53. package/dist/types.cjs +1 -1
  54. package/dist/types.d.ts +2 -41
  55. package/dist/types.js +1 -1
  56. package/dist/utils.cjs +1 -1
  57. package/dist/utils.d.ts +2 -184
  58. package/dist/utils.js +1 -1
  59. package/migrations/001_initial_schema.sql +198 -0
  60. package/migrations/002_faq_plugin.sql +86 -0
  61. package/migrations/003_stage5_enhancements.sql +121 -0
  62. package/migrations/004_stage6_user_management.sql +183 -0
  63. package/migrations/005_stage7_workflow_automation.sql +294 -0
  64. package/migrations/006_plugin_system.sql +155 -0
  65. package/migrations/007_demo_login_plugin.sql +23 -0
  66. package/migrations/008_fix_slug_validation.sql +22 -0
  67. package/migrations/009_system_logging.sql +57 -0
  68. package/migrations/011_config_managed_collections.sql +14 -0
  69. package/migrations/012_testimonials_plugin.sql +80 -0
  70. package/migrations/013_code_examples_plugin.sql +177 -0
  71. package/migrations/014_fix_plugin_registry.sql +88 -0
  72. package/migrations/015_add_remaining_plugins.sql +89 -0
  73. package/migrations/016_remove_duplicate_cache_plugin.sql +17 -0
  74. package/migrations/017_auth_configurable_fields.sql +49 -0
  75. package/package.json +2 -2
  76. package/dist/chunk-4URGXJP7.js +0 -3
  77. package/dist/chunk-4URGXJP7.js.map +0 -1
  78. package/dist/chunk-ALTMI5Y2.cjs +0 -4
  79. package/dist/chunk-BOLQHE4J.cjs +0 -11
  80. package/dist/chunk-BOLQHE4J.cjs.map +0 -1
  81. package/dist/chunk-BRC3F4CG.cjs.map +0 -1
  82. package/dist/chunk-EMMSS5I5.cjs.map +0 -1
  83. package/dist/chunk-HD7R6T6I.js +0 -9
  84. package/dist/chunk-HD7R6T6I.js.map +0 -1
  85. package/dist/collection-config-FLlGtsh9.d.cts +0 -107
  86. package/dist/collection-config-FLlGtsh9.d.ts +0 -107
  87. package/dist/index-BlsY5XNH.d.ts +0 -8333
  88. package/dist/index-D45jaIlr.d.cts +0 -8333
  89. package/dist/index.d.cts +0 -136
  90. package/dist/middleware.d.cts +0 -206
  91. package/dist/plugin-UzmDImQc.d.cts +0 -357
  92. package/dist/plugin-UzmDImQc.d.ts +0 -357
  93. package/dist/plugins.d.cts +0 -330
  94. package/dist/routes.d.cts +0 -17
  95. package/dist/services.d.cts +0 -5
  96. package/dist/templates.d.cts +0 -140
  97. package/dist/types.d.cts +0 -41
  98. package/dist/utils.d.cts +0 -184
package/dist/index.d.cts DELETED
@@ -1,136 +0,0 @@
1
- import { Hono, Context } from 'hono';
2
- import { D1Database as D1Database$1, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
3
- import { s as schema } from './index-D45jaIlr.cjs';
4
- export { aa as Collection, ac as Content, C as CorePlugin, ai as DbPlugin, ak as DbPluginHook, p as LogCategory, au as LogConfig, q as LogEntry, r as LogFilter, o as LogLevel, L as Logger, ae as Media, m as Migration, M as MigrationService, n as MigrationStatus, ab as NewCollection, ad as NewContent, av as NewLogConfig, af as NewMedia, aj as NewPlugin, ar as NewPluginActivityLog, ap as NewPluginAsset, al as NewPluginHook, an as NewPluginRoute, at as NewSystemLog, a9 as NewUser, ah as NewWorkflowHistory, aq as PluginActivityLog, ao as PluginAsset, k as PluginBootstrapService, am as PluginRoute, P as PluginServiceClass, as as SystemLog, a8 as User, ag as WorkflowHistory, z as apiTokens, e as cleanupRemovedCollections, t as collections, w as content, x as contentVersions, f as fullCollectionSync, g as getAvailableCollectionNames, h as getLogger, d as getManagedCollections, j as initLogger, N as insertCollectionSchema, Q as insertContentSchema, a6 as insertLogConfigSchema, S as insertMediaSchema, a2 as insertPluginActivityLogSchema, a0 as insertPluginAssetSchema, Y as insertPluginHookSchema, _ as insertPluginRouteSchema, W as insertPluginSchema, a4 as insertSystemLogSchema, J as insertUserSchema, U as insertWorkflowHistorySchema, i as isCollectionManaged, a as loadCollectionConfig, l as loadCollectionConfigs, I as logConfig, y as media, G as pluginActivityLog, F as pluginAssets, D as pluginHooks, E as pluginRoutes, B as plugins, O as selectCollectionSchema, R as selectContentSchema, a7 as selectLogConfigSchema, T as selectMediaSchema, a3 as selectPluginActivityLogSchema, a1 as selectPluginAssetSchema, Z as selectPluginHookSchema, $ as selectPluginRouteSchema, X as selectPluginSchema, a5 as selectSystemLogSchema, K as selectUserSchema, V as selectWorkflowHistorySchema, c as syncCollection, b as syncCollections, H as systemLogs, u as users, v as validateCollectionConfig, A as workflowHistory } from './index-D45jaIlr.cjs';
5
- export { AuthManager, Permission, PermissionManager, UserPermissions, bootstrapMiddleware, cacheHeaders, compressionMiddleware, detailedLoggingMiddleware, getActivePlugins, isPluginActive, logActivity, loggingMiddleware, optionalAuth, performanceLoggingMiddleware, requireActivePlugin, requireActivePlugins, requireAnyPermission, requireAuth, requirePermission, requireRole, securityHeaders, securityLoggingMiddleware } from './middleware.cjs';
6
- export { HookSystemImpl, HookUtils, PluginManager as PluginManagerClass, PluginRegistryImpl, PluginValidator as PluginValidatorClass, ScopedHookSystem as ScopedHookSystemClass } from './plugins.cjs';
7
- export { ROUTES_INFO } from './routes.cjs';
8
- export { AlertData, ConfirmationDialogOptions, Filter, FilterBarData, FilterOption, FormData, FormField, PaginationData, TableColumn, TableData, getConfirmationDialogScript, renderAlert, renderConfirmationDialog, renderFilterBar, renderForm, renderFormField, renderPagination, renderTable } from './templates.cjs';
9
- export { b as CollectionConfig, c as CollectionConfigModule, C as CollectionSchema, d as CollectionSyncResult, a as FieldConfig, F as FieldType } from './collection-config-FLlGtsh9.cjs';
10
- export { A as AuthService, C as ContentService, u as HOOKS, k as HookContext, H as HookHandler, t as HookName, l as HookSystem, M as MediaService, P as Plugin, g as PluginAdminPage, q as PluginBuilderOptions, h as PluginComponent, b as PluginConfig, a as PluginContext, j as PluginHook, p as PluginLogger, n as PluginManager, i as PluginMenuItem, d as PluginMiddleware, e as PluginModel, m as PluginRegistry, c as PluginRoutes, f as PluginService, o as PluginStatus, s as PluginValidationResult, r as PluginValidator, S as ScopedHookSystem } from './plugin-UzmDImQc.cjs';
11
- export { PluginManifest } from './types.cjs';
12
- export { FilterCondition, FilterGroup, FilterOperator, QueryFilter, QueryFilterBuilder, QueryResult, TemplateRenderer, buildQuery, escapeHtml, metricsTracker, renderTemplate, sanitizeInput, sanitizeObject, templateRenderer } from './utils.cjs';
13
- import * as drizzle_orm_d1 from 'drizzle-orm/d1';
14
- import 'drizzle-zod';
15
- import 'drizzle-orm/sqlite-core';
16
- import 'zod';
17
-
18
- /**
19
- * Main Application Factory
20
- *
21
- * Creates a configured SonicJS application with all core functionality
22
- */
23
-
24
- interface Bindings {
25
- DB: D1Database$1;
26
- CACHE_KV: KVNamespace;
27
- MEDIA_BUCKET: R2Bucket;
28
- ASSETS: Fetcher;
29
- EMAIL_QUEUE?: Queue;
30
- SENDGRID_API_KEY?: string;
31
- DEFAULT_FROM_EMAIL?: string;
32
- IMAGES_ACCOUNT_ID?: string;
33
- IMAGES_API_TOKEN?: string;
34
- ENVIRONMENT?: string;
35
- }
36
- interface Variables {
37
- user?: {
38
- userId: string;
39
- email: string;
40
- role: string;
41
- exp: number;
42
- iat: number;
43
- };
44
- requestId?: string;
45
- startTime?: number;
46
- appVersion?: string;
47
- }
48
- interface SonicJSConfig {
49
- collections?: {
50
- directory?: string;
51
- autoSync?: boolean;
52
- };
53
- plugins?: {
54
- directory?: string;
55
- autoLoad?: boolean;
56
- };
57
- routes?: Array<{
58
- path: string;
59
- handler: Hono;
60
- }>;
61
- middleware?: {
62
- beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
63
- afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>;
64
- };
65
- version?: string;
66
- name?: string;
67
- }
68
- type SonicJSApp = Hono<{
69
- Bindings: Bindings;
70
- Variables: Variables;
71
- }>;
72
- /**
73
- * Create a SonicJS application with core functionality
74
- *
75
- * @param config - Application configuration
76
- * @returns Configured Hono application
77
- *
78
- * @example
79
- * ```typescript
80
- * import { createSonicJSApp } from '@sonicjs/core'
81
- *
82
- * const app = createSonicJSApp({
83
- * collections: {
84
- * directory: './src/collections',
85
- * autoSync: true
86
- * },
87
- * plugins: {
88
- * directory: './src/plugins',
89
- * autoLoad: true
90
- * }
91
- * })
92
- *
93
- * export default app
94
- * ```
95
- */
96
- declare function createSonicJSApp(config?: SonicJSConfig): SonicJSApp;
97
- /**
98
- * Setup core middleware (backward compatibility)
99
- *
100
- * @param _app - Hono application
101
- * @deprecated Use createSonicJSApp() instead
102
- */
103
- declare function setupCoreMiddleware(_app: SonicJSApp): void;
104
- /**
105
- * Setup core routes (backward compatibility)
106
- *
107
- * @param _app - Hono application
108
- * @deprecated Use createSonicJSApp() instead
109
- */
110
- declare function setupCoreRoutes(_app: SonicJSApp): void;
111
-
112
- declare function createDb(d1: D1Database): drizzle_orm_d1.DrizzleD1Database<typeof schema> & {
113
- $client: D1Database;
114
- };
115
-
116
- /**
117
- * @sonicjs/core - Main Entry Point
118
- *
119
- * Core framework for SonicJS headless CMS
120
- * Built for Cloudflare's edge platform with TypeScript
121
- *
122
- * Phase 2 Migration Status:
123
- * - Week 1: Types, Utils, Database (COMPLETED ✓)
124
- * - Week 2: Services, Middleware, Plugins (COMPLETED ✓)
125
- * - Week 3: Routes, Templates (COMPLETED ✓)
126
- * - Week 4: Integration & Testing (COMPLETED ✓)
127
- *
128
- * Test Coverage:
129
- * - Utilities: 48 tests (sanitize, query-filter, metrics)
130
- * - Middleware: 51 tests (auth, logging, security, performance)
131
- * - Total: 99 tests passing
132
- */
133
-
134
- declare const VERSION = "2.0.0-alpha.1";
135
-
136
- export { type Bindings, type SonicJSApp, type SonicJSConfig, VERSION, type Variables, createDb, createSonicJSApp, setupCoreMiddleware, setupCoreRoutes };
@@ -1,206 +0,0 @@
1
- import * as hono from 'hono';
2
- import { Context, Next } from 'hono';
3
- import { D1Database as D1Database$1 } from '@cloudflare/workers-types';
4
-
5
- type JWTPayload = {
6
- userId: string;
7
- email: string;
8
- role: string;
9
- exp: number;
10
- iat: number;
11
- };
12
- declare class AuthManager {
13
- static generateToken(userId: string, email: string, role: string): Promise<string>;
14
- static verifyToken(token: string): Promise<JWTPayload | null>;
15
- static hashPassword(password: string): Promise<string>;
16
- static verifyPassword(password: string, hash: string): Promise<boolean>;
17
- }
18
- declare const requireAuth: () => (c: Context, next: Next) => Promise<void | (Response & hono.TypedResponse<undefined, 302, "redirect">) | (Response & hono.TypedResponse<{
19
- error: string;
20
- }, 401, "json">)>;
21
- declare const requireRole: (requiredRole: string | string[]) => (c: Context, next: Next) => Promise<void | (Response & hono.TypedResponse<undefined, 302, "redirect">) | (Response & hono.TypedResponse<{
22
- error: string;
23
- }, 401, "json">) | (Response & hono.TypedResponse<{
24
- error: string;
25
- }, 403, "json">)>;
26
- declare const optionalAuth: () => (c: Context, next: Next) => Promise<void>;
27
-
28
- type Bindings$2 = {
29
- DB: D1Database;
30
- };
31
- type Variables = {
32
- user?: {
33
- userId: string;
34
- email: string;
35
- role: string;
36
- exp: number;
37
- iat: number;
38
- };
39
- requestId?: string;
40
- startTime?: number;
41
- };
42
- /**
43
- * Logging middleware that captures HTTP requests and responses
44
- */
45
- declare function loggingMiddleware(): (c: Context<{
46
- Bindings: Bindings$2;
47
- Variables: Variables;
48
- }>, next: Next) => Promise<void>;
49
- /**
50
- * Enhanced logging middleware with more detailed request/response logging
51
- */
52
- declare function detailedLoggingMiddleware(): (c: Context<{
53
- Bindings: Bindings$2;
54
- Variables: Variables;
55
- }>, next: Next) => Promise<void>;
56
- /**
57
- * Security logging middleware for sensitive operations
58
- */
59
- declare function securityLoggingMiddleware(): (c: Context<{
60
- Bindings: Bindings$2;
61
- Variables: Variables;
62
- }>, next: Next) => Promise<void>;
63
- /**
64
- * Performance logging middleware for slow requests
65
- */
66
- declare function performanceLoggingMiddleware(slowThreshold?: number): (c: Context<{
67
- Bindings: Bindings$2;
68
- Variables: Variables;
69
- }>, next: Next) => Promise<void>;
70
-
71
- /**
72
- * Add cache headers for static admin pages
73
- * Only caches authenticated pages with short TTL
74
- */
75
- declare const cacheHeaders: (maxAge?: number) => (c: Context, next: Next) => Promise<void>;
76
- /**
77
- * Compression middleware - only compress if client supports it
78
- */
79
- declare const compressionMiddleware: hono.MiddlewareHandler;
80
- /**
81
- * Set security headers
82
- */
83
- declare const securityHeaders: () => (c: Context, next: Next) => Promise<void>;
84
-
85
- interface Permission {
86
- id: string;
87
- name: string;
88
- description: string;
89
- category: string;
90
- }
91
- interface UserPermissions {
92
- userId: string;
93
- role: string;
94
- permissions: string[];
95
- teamPermissions?: Record<string, string[]>;
96
- }
97
- declare class PermissionManager {
98
- private static permissionCache;
99
- private static cacheExpiry;
100
- private static CACHE_TTL;
101
- /**
102
- * Get user permissions from database with caching
103
- */
104
- static getUserPermissions(db: D1Database, userId: string): Promise<UserPermissions>;
105
- /**
106
- * Check if user has a specific permission
107
- */
108
- static hasPermission(db: D1Database, userId: string, permission: string, teamId?: string): Promise<boolean>;
109
- /**
110
- * Clear permission cache for a user
111
- */
112
- static clearUserCache(userId: string): void;
113
- /**
114
- * Clear all permission cache
115
- */
116
- static clearAllCache(): void;
117
- /**
118
- * Clear all permission cache (alias for clearAllCache)
119
- */
120
- static clearCache(): void;
121
- /**
122
- * Check multiple permissions at once
123
- */
124
- static checkMultiplePermissions(db: D1Database, userId: string, permissions: string[], teamId?: string): Promise<Record<string, boolean>>;
125
- /**
126
- * Middleware factory to require specific permissions
127
- */
128
- static requirePermissions(permissions: string[], teamIdParam?: string): (c: Context, next: Next) => Promise<void | (Response & hono.TypedResponse<{
129
- error: string;
130
- }, 401, "json">) | (Response & hono.TypedResponse<{
131
- error: string;
132
- }, 403, "json">) | (Response & hono.TypedResponse<{
133
- error: string;
134
- }, 500, "json">)>;
135
- /**
136
- * Get all available permissions from database
137
- */
138
- static getAllPermissions(db: D1Database): Promise<Permission[]>;
139
- }
140
- /**
141
- * Middleware to require specific permission
142
- */
143
- declare function requirePermission(permission: string, teamIdParam?: string): (c: Context, next: Next) => Promise<void | (Response & hono.TypedResponse<{
144
- error: string;
145
- }, 401, "json">) | (Response & hono.TypedResponse<{
146
- error: string;
147
- }, 403, "json">) | (Response & hono.TypedResponse<{
148
- error: string;
149
- }, 500, "json">)>;
150
- /**
151
- * Middleware to require any of the specified permissions
152
- */
153
- declare function requireAnyPermission(permissions: string[], teamIdParam?: string): (c: Context, next: Next) => Promise<(Response & hono.TypedResponse<{
154
- error: string;
155
- }, 401, "json">) | (Response & hono.TypedResponse<{
156
- error: string;
157
- }, 403, "json">) | (Response & hono.TypedResponse<{
158
- error: string;
159
- }, 500, "json">) | undefined>;
160
- /**
161
- * Helper to log user activity
162
- */
163
- declare function logActivity(db: D1Database, userId: string, action: string, resourceType?: string, resourceId?: string, details?: any, ipAddress?: string, userAgent?: string): Promise<void>;
164
-
165
- type Bindings$1 = {
166
- DB: D1Database$1;
167
- };
168
- /**
169
- * Middleware to check if a plugin is active before allowing access to its routes
170
- */
171
- declare function requireActivePlugin(pluginName: string): (c: Context<{
172
- Bindings: Bindings$1;
173
- }>, next: Next) => Promise<void | Response>;
174
- /**
175
- * Check if multiple plugins are active
176
- */
177
- declare function requireActivePlugins(pluginNames: string[]): (c: Context<{
178
- Bindings: Bindings$1;
179
- }>, next: Next) => Promise<void | Response>;
180
- /**
181
- * Get list of active plugins for menu generation
182
- */
183
- declare function getActivePlugins(db: D1Database$1): Promise<Array<{
184
- name: string;
185
- display_name: string;
186
- icon?: string;
187
- settings?: any;
188
- }>>;
189
- /**
190
- * Check if a specific plugin is active
191
- */
192
- declare function isPluginActive(db: D1Database$1, pluginName: string): Promise<boolean>;
193
-
194
- type Bindings = {
195
- DB: D1Database;
196
- KV: KVNamespace;
197
- };
198
- /**
199
- * Bootstrap middleware that ensures system initialization
200
- * Runs once per worker instance
201
- */
202
- declare function bootstrapMiddleware(): (c: Context<{
203
- Bindings: Bindings;
204
- }>, next: Next) => Promise<void>;
205
-
206
- export { AuthManager, type Permission, PermissionManager, type UserPermissions, bootstrapMiddleware, cacheHeaders, compressionMiddleware, detailedLoggingMiddleware, getActivePlugins, isPluginActive, logActivity, loggingMiddleware, optionalAuth, performanceLoggingMiddleware, requireActivePlugin, requireActivePlugins, requireAnyPermission, requireAuth, requirePermission, requireRole, securityHeaders, securityLoggingMiddleware };
@@ -1,357 +0,0 @@
1
- import { Context, MiddlewareHandler, Hono } from 'hono';
2
- import { z } from 'zod';
3
- import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
4
-
5
- /**
6
- * SonicJS Plugin System Types
7
- *
8
- * Defines the core interfaces and types for the plugin system
9
- */
10
-
11
- interface Plugin {
12
- /** Unique plugin identifier */
13
- name: string;
14
- /** Plugin version (semantic versioning) */
15
- version: string;
16
- /** Human-readable description */
17
- description?: string;
18
- /** Plugin author information */
19
- author?: {
20
- name: string;
21
- email?: string;
22
- url?: string;
23
- };
24
- /** Plugin dependencies (other plugins required) */
25
- dependencies?: string[];
26
- /** SonicJS version compatibility */
27
- compatibility?: string;
28
- /** Plugin license */
29
- license?: string;
30
- routes?: PluginRoutes[];
31
- middleware?: PluginMiddleware[];
32
- models?: PluginModel[];
33
- services?: PluginService[];
34
- adminPages?: PluginAdminPage[];
35
- adminComponents?: PluginComponent[];
36
- menuItems?: PluginMenuItem[];
37
- hooks?: PluginHook[];
38
- install?: (context: PluginContext) => Promise<void>;
39
- uninstall?: (context: PluginContext) => Promise<void>;
40
- activate?: (context: PluginContext) => Promise<void>;
41
- deactivate?: (context: PluginContext) => Promise<void>;
42
- configure?: (config: PluginConfig) => Promise<void>;
43
- }
44
- interface PluginContext {
45
- /** Database instance */
46
- db: D1Database;
47
- /** Key-value storage */
48
- kv: KVNamespace;
49
- /** R2 storage bucket */
50
- r2?: R2Bucket;
51
- /** Plugin configuration */
52
- config: PluginConfig;
53
- /** Core SonicJS services */
54
- services: {
55
- auth: AuthService;
56
- content: ContentService;
57
- media: MediaService;
58
- };
59
- /** Hook system for inter-plugin communication */
60
- hooks: HookSystem | ScopedHookSystem;
61
- /** Logging utilities */
62
- logger: PluginLogger;
63
- }
64
- interface PluginConfig {
65
- /** Plugin-specific configuration */
66
- [key: string]: any;
67
- /** Whether plugin is enabled */
68
- enabled: boolean;
69
- /** Plugin installation timestamp */
70
- installedAt?: number;
71
- /** Plugin last update timestamp */
72
- updatedAt?: number;
73
- }
74
- interface PluginRoutes {
75
- /** Route path prefix */
76
- path: string;
77
- /** Hono route handler */
78
- handler: Hono;
79
- /** Route description */
80
- description?: string;
81
- /** Whether route requires authentication */
82
- requiresAuth?: boolean;
83
- /** Required roles for access */
84
- roles?: string[];
85
- /** Route priority (for ordering) */
86
- priority?: number;
87
- }
88
- interface PluginMiddleware {
89
- /** Middleware name */
90
- name: string;
91
- /** Middleware handler function */
92
- handler: MiddlewareHandler;
93
- /** Middleware description */
94
- description?: string;
95
- /** Middleware priority (lower = earlier) */
96
- priority?: number;
97
- /** Routes to apply middleware to */
98
- routes?: string[];
99
- /** Whether to apply globally */
100
- global?: boolean;
101
- }
102
- interface PluginModel {
103
- /** Model name */
104
- name: string;
105
- /** Database table name */
106
- tableName: string;
107
- /** Zod schema for validation */
108
- schema: z.ZodSchema;
109
- /** Database migrations */
110
- migrations: string[];
111
- /** Model relationships */
112
- relationships?: ModelRelationship[];
113
- /** Whether model extends core content */
114
- extendsContent?: boolean;
115
- }
116
- interface ModelRelationship {
117
- type: 'oneToOne' | 'oneToMany' | 'manyToMany';
118
- target: string;
119
- foreignKey?: string;
120
- joinTable?: string;
121
- }
122
- interface PluginService {
123
- /** Service name */
124
- name: string;
125
- /** Service implementation */
126
- implementation: any;
127
- /** Service description */
128
- description?: string;
129
- /** Service dependencies */
130
- dependencies?: string[];
131
- /** Whether service is singleton */
132
- singleton?: boolean;
133
- }
134
- interface PluginAdminPage {
135
- /** Page path (relative to /admin) */
136
- path: string;
137
- /** Page title */
138
- title: string;
139
- /** Page component/template */
140
- component: string;
141
- /** Page description */
142
- description?: string;
143
- /** Required permissions */
144
- permissions?: string[];
145
- /** Menu item configuration */
146
- menuItem?: PluginMenuItem;
147
- /** Page icon */
148
- icon?: string;
149
- }
150
- interface PluginComponent {
151
- /** Component name */
152
- name: string;
153
- /** Component template function */
154
- template: (props: any) => string;
155
- /** Component description */
156
- description?: string;
157
- /** Component props schema */
158
- propsSchema?: z.ZodSchema;
159
- }
160
- interface PluginMenuItem {
161
- /** Menu item label */
162
- label: string;
163
- /** Menu item path */
164
- path: string;
165
- /** Menu item icon */
166
- icon?: string;
167
- /** Menu item order */
168
- order?: number;
169
- /** Parent menu item */
170
- parent?: string;
171
- /** Required permissions */
172
- permissions?: string[];
173
- /** Whether item is active */
174
- active?: boolean;
175
- }
176
- interface PluginHook {
177
- /** Hook name */
178
- name: string;
179
- /** Hook handler function */
180
- handler: HookHandler;
181
- /** Hook priority */
182
- priority?: number;
183
- /** Hook description */
184
- description?: string;
185
- }
186
- type HookHandler = (data: any, context: HookContext) => Promise<any>;
187
- interface HookContext {
188
- /** Plugin that registered the hook */
189
- plugin: string;
190
- /** Hook execution context */
191
- context: PluginContext;
192
- /** Cancel hook execution */
193
- cancel?: () => void;
194
- }
195
- interface HookSystem {
196
- /** Register a hook handler */
197
- register(hookName: string, handler: HookHandler, priority?: number): void;
198
- /** Execute all handlers for a hook */
199
- execute(hookName: string, data: any, context?: any): Promise<any>;
200
- /** Remove a hook handler */
201
- unregister(hookName: string, handler: HookHandler): void;
202
- /** Get all registered hooks */
203
- getHooks(hookName: string): PluginHook[];
204
- /** Create a scoped hook system (optional) */
205
- createScope?(pluginName: string): ScopedHookSystem;
206
- }
207
- interface ScopedHookSystem {
208
- /** Register a hook handler */
209
- register(hookName: string, handler: HookHandler, priority?: number): void;
210
- /** Execute all handlers for a hook */
211
- execute(hookName: string, data: any, context?: any): Promise<any>;
212
- /** Remove a hook handler */
213
- unregister(hookName: string, handler: HookHandler): void;
214
- /** Remove all hooks for this scope */
215
- unregisterAll(): void;
216
- }
217
- interface PluginRegistry {
218
- /** Get plugin by name */
219
- get(name: string): Plugin | undefined;
220
- /** Get all registered plugins */
221
- getAll(): Plugin[];
222
- /** Get active plugins */
223
- getActive(): Plugin[];
224
- /** Register a plugin */
225
- register(plugin: Plugin): Promise<void>;
226
- /** Unregister a plugin */
227
- unregister(name: string): Promise<void>;
228
- /** Check if plugin is registered */
229
- has(name: string): boolean;
230
- /** Activate a plugin */
231
- activate(name: string): Promise<void>;
232
- /** Deactivate a plugin */
233
- deactivate(name: string): Promise<void>;
234
- /** Get plugin configuration */
235
- getConfig(name: string): PluginConfig | undefined;
236
- /** Set plugin configuration */
237
- setConfig(name: string, config: PluginConfig): void;
238
- /** Get plugin status */
239
- getStatus(name: string): PluginStatus | undefined;
240
- /** Get all plugin statuses */
241
- getAllStatuses(): Map<string, PluginStatus>;
242
- /** Resolve plugin load order based on dependencies */
243
- resolveLoadOrder(): string[];
244
- }
245
- interface PluginManager {
246
- /** Plugin registry */
247
- registry: PluginRegistry;
248
- /** Hook system */
249
- hooks: HookSystem;
250
- /** Initialize plugin system */
251
- initialize(context: PluginContext): Promise<void>;
252
- /** Load plugins from configuration */
253
- loadPlugins(config: PluginConfig[]): Promise<void>;
254
- /** Install a plugin */
255
- install(plugin: Plugin, config?: PluginConfig): Promise<void>;
256
- /** Uninstall a plugin */
257
- uninstall(name: string): Promise<void>;
258
- /** Get plugin status */
259
- getStatus(name: string): PluginStatus;
260
- }
261
- interface PluginStatus {
262
- name: string;
263
- version: string;
264
- active: boolean;
265
- installed: boolean;
266
- hasErrors: boolean;
267
- errors?: string[];
268
- lastError?: string;
269
- }
270
- interface AuthService {
271
- /** Verify user permissions */
272
- hasPermission(userId: string, permission: string): Promise<boolean>;
273
- /** Get current user */
274
- getCurrentUser(context: Context): Promise<any>;
275
- /** Create authentication middleware */
276
- createMiddleware(options?: any): MiddlewareHandler;
277
- }
278
- interface ContentService {
279
- /** Get content by ID */
280
- getById(id: string): Promise<any>;
281
- /** Create new content */
282
- create(data: any): Promise<any>;
283
- /** Update content */
284
- update(id: string, data: any): Promise<any>;
285
- /** Delete content */
286
- delete(id: string): Promise<void>;
287
- /** Search content */
288
- search(query: string, options?: any): Promise<any[]>;
289
- }
290
- interface MediaService {
291
- /** Upload file */
292
- upload(file: File, options?: any): Promise<any>;
293
- /** Get media by ID */
294
- getById(id: string): Promise<any>;
295
- /** Delete media */
296
- delete(id: string): Promise<void>;
297
- /** Transform image */
298
- transform(id: string, options: any): Promise<string>;
299
- }
300
- interface PluginLogger {
301
- debug(message: string, data?: any): void;
302
- info(message: string, data?: any): void;
303
- warn(message: string, data?: any): void;
304
- error(message: string, error?: Error, data?: any): void;
305
- }
306
- interface PluginBuilderOptions {
307
- name: string;
308
- version: string;
309
- description?: string;
310
- author?: Plugin['author'];
311
- dependencies?: string[];
312
- }
313
- interface PluginValidator {
314
- /** Validate plugin definition */
315
- validate(plugin: Plugin): PluginValidationResult;
316
- /** Validate plugin dependencies */
317
- validateDependencies(plugin: Plugin, registry: PluginRegistry): PluginValidationResult;
318
- /** Validate plugin compatibility */
319
- validateCompatibility(plugin: Plugin, version: string): PluginValidationResult;
320
- }
321
- interface PluginValidationResult {
322
- valid: boolean;
323
- errors: string[];
324
- warnings: string[];
325
- }
326
- declare const HOOKS: {
327
- readonly APP_INIT: "app:init";
328
- readonly APP_READY: "app:ready";
329
- readonly APP_SHUTDOWN: "app:shutdown";
330
- readonly REQUEST_START: "request:start";
331
- readonly REQUEST_END: "request:end";
332
- readonly REQUEST_ERROR: "request:error";
333
- readonly AUTH_LOGIN: "auth:login";
334
- readonly AUTH_LOGOUT: "auth:logout";
335
- readonly AUTH_REGISTER: "auth:register";
336
- readonly USER_LOGIN: "user:login";
337
- readonly USER_LOGOUT: "user:logout";
338
- readonly CONTENT_CREATE: "content:create";
339
- readonly CONTENT_UPDATE: "content:update";
340
- readonly CONTENT_DELETE: "content:delete";
341
- readonly CONTENT_PUBLISH: "content:publish";
342
- readonly CONTENT_SAVE: "content:save";
343
- readonly MEDIA_UPLOAD: "media:upload";
344
- readonly MEDIA_DELETE: "media:delete";
345
- readonly MEDIA_TRANSFORM: "media:transform";
346
- readonly PLUGIN_INSTALL: "plugin:install";
347
- readonly PLUGIN_UNINSTALL: "plugin:uninstall";
348
- readonly PLUGIN_ACTIVATE: "plugin:activate";
349
- readonly PLUGIN_DEACTIVATE: "plugin:deactivate";
350
- readonly ADMIN_MENU_RENDER: "admin:menu:render";
351
- readonly ADMIN_PAGE_RENDER: "admin:page:render";
352
- readonly DB_MIGRATE: "db:migrate";
353
- readonly DB_SEED: "db:seed";
354
- };
355
- type HookName = typeof HOOKS[keyof typeof HOOKS];
356
-
357
- export { type AuthService as A, type ContentService as C, type HookHandler as H, type MediaService as M, type Plugin as P, type ScopedHookSystem as S, type PluginContext as a, type PluginConfig as b, type PluginRoutes as c, type PluginMiddleware as d, type PluginModel as e, type PluginService as f, type PluginAdminPage as g, type PluginComponent as h, type PluginMenuItem as i, type PluginHook as j, type HookContext as k, type HookSystem as l, type PluginRegistry as m, type PluginManager as n, type PluginStatus as o, type PluginLogger as p, type PluginBuilderOptions as q, type PluginValidator as r, type PluginValidationResult as s, type HookName as t, HOOKS as u, type ModelRelationship as v };