@sonicjs-cms/core 2.4.0 → 2.5.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 (73) hide show
  1. package/dist/{chunk-CPXAVWCU.js → chunk-3YUHXWSG.js} +278 -3
  2. package/dist/chunk-3YUHXWSG.js.map +1 -0
  3. package/dist/chunk-AI2JJIJX.cjs +211 -0
  4. package/dist/chunk-AI2JJIJX.cjs.map +1 -0
  5. package/dist/{chunk-VNCYCH3H.js → chunk-BHNDALCA.js} +56 -4
  6. package/dist/chunk-BHNDALCA.js.map +1 -0
  7. package/dist/{chunk-2MI3LZFH.cjs → chunk-I4V3VZWF.cjs} +46 -2
  8. package/dist/chunk-I4V3VZWF.cjs.map +1 -0
  9. package/dist/{chunk-DTLB6UIH.cjs → chunk-LWG2MWDA.cjs} +280 -2
  10. package/dist/chunk-LWG2MWDA.cjs.map +1 -0
  11. package/dist/{chunk-FT6NBHNX.js → chunk-OJZ45OJD.js} +507 -275
  12. package/dist/chunk-OJZ45OJD.js.map +1 -0
  13. package/dist/chunk-QDBNW7KQ.js +209 -0
  14. package/dist/chunk-QDBNW7KQ.js.map +1 -0
  15. package/dist/{chunk-DXM575E2.js → chunk-TJTWRO4G.js} +5 -5
  16. package/dist/chunk-TJTWRO4G.js.map +1 -0
  17. package/dist/{chunk-A4SVOGG6.cjs → chunk-UAQL2VWX.cjs} +591 -360
  18. package/dist/chunk-UAQL2VWX.cjs.map +1 -0
  19. package/dist/{chunk-D2NLCPO2.js → chunk-VEL7QRYI.js} +46 -2
  20. package/dist/chunk-VEL7QRYI.js.map +1 -0
  21. package/dist/{chunk-7I5INVNR.cjs → chunk-YYV3XQOQ.cjs} +6 -6
  22. package/dist/chunk-YYV3XQOQ.cjs.map +1 -0
  23. package/dist/{chunk-FYEDK7K7.cjs → chunk-ZWV3EBZ7.cjs} +58 -3
  24. package/dist/chunk-ZWV3EBZ7.cjs.map +1 -0
  25. package/dist/{collection-config-FLlGtsh9.d.cts → collection-config-B6gMPunn.d.cts} +9 -1
  26. package/dist/{collection-config-FLlGtsh9.d.ts → collection-config-B6gMPunn.d.ts} +9 -1
  27. package/dist/index.cjs +90 -87
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +4 -4
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +12 -9
  32. package/dist/index.js.map +1 -1
  33. package/dist/middleware.cjs +23 -23
  34. package/dist/middleware.js +2 -2
  35. package/dist/migrations-NIEUFG44.cjs +13 -0
  36. package/dist/{migrations-32QAYLWJ.cjs.map → migrations-NIEUFG44.cjs.map} +1 -1
  37. package/dist/migrations-TGZKJKV4.js +4 -0
  38. package/dist/{migrations-57ZHBQ4X.js.map → migrations-TGZKJKV4.js.map} +1 -1
  39. package/dist/{plugin-bootstrap-C0E3jdz-.d.cts → plugin-bootstrap-SHsdjE6X.d.cts} +1 -1
  40. package/dist/{plugin-bootstrap-CDh0JHtW.d.ts → plugin-bootstrap-dYhD9fQR.d.ts} +1 -1
  41. package/dist/plugin-manager-Baa6xXqB.d.ts +328 -0
  42. package/dist/plugin-manager-vBal9Zip.d.cts +328 -0
  43. package/dist/plugins.cjs +20 -7
  44. package/dist/plugins.d.cts +53 -310
  45. package/dist/plugins.d.ts +53 -310
  46. package/dist/plugins.js +2 -1
  47. package/dist/routes.cjs +25 -24
  48. package/dist/routes.js +5 -4
  49. package/dist/services.cjs +2 -2
  50. package/dist/services.d.cts +2 -2
  51. package/dist/services.d.ts +2 -2
  52. package/dist/services.js +1 -1
  53. package/dist/types.d.cts +1 -1
  54. package/dist/types.d.ts +1 -1
  55. package/dist/utils.cjs +23 -11
  56. package/dist/utils.d.cts +38 -1
  57. package/dist/utils.d.ts +38 -1
  58. package/dist/utils.js +1 -1
  59. package/migrations/027_fix_slug_field_type.sql +18 -0
  60. package/migrations/028_fix_slug_field_type_in_schemas.sql +30 -0
  61. package/package.json +2 -1
  62. package/dist/chunk-2MI3LZFH.cjs.map +0 -1
  63. package/dist/chunk-7I5INVNR.cjs.map +0 -1
  64. package/dist/chunk-A4SVOGG6.cjs.map +0 -1
  65. package/dist/chunk-CPXAVWCU.js.map +0 -1
  66. package/dist/chunk-D2NLCPO2.js.map +0 -1
  67. package/dist/chunk-DTLB6UIH.cjs.map +0 -1
  68. package/dist/chunk-DXM575E2.js.map +0 -1
  69. package/dist/chunk-FT6NBHNX.js.map +0 -1
  70. package/dist/chunk-FYEDK7K7.cjs.map +0 -1
  71. package/dist/chunk-VNCYCH3H.js.map +0 -1
  72. package/dist/migrations-32QAYLWJ.cjs +0 -13
  73. package/dist/migrations-57ZHBQ4X.js +0 -4
@@ -1,330 +1,73 @@
1
- import { l as HookSystem, H as HookHandler, j as PluginHook, s as PluginValidator$1, P as Plugin, t as PluginValidationResult, m as PluginRegistry, b as PluginConfig, o as PluginStatus, n as PluginManager$1, a as PluginContext } from './plugin-zvZpaiP5.cjs';
2
- import { Hono } from 'hono';
1
+ export { H as HookSystemImpl, a as HookUtils, b as PluginManager, P as PluginRegistryImpl, c as PluginValidator, S as ScopedHookSystem } from './plugin-manager-vBal9Zip.cjs';
2
+ import { D1Database } from '@cloudflare/workers-types';
3
+ import * as hono from 'hono';
4
+ import { Context, Next } from 'hono';
5
+ import './plugin-zvZpaiP5.cjs';
3
6
  import 'zod';
4
- import '@cloudflare/workers-types';
5
7
 
6
- /**
7
- * Hook System Implementation
8
- *
9
- * Provides event-driven extensibility for plugins
10
- */
11
-
12
- declare class HookSystemImpl implements HookSystem {
13
- private hooks;
14
- private executing;
15
- /**
16
- * Register a hook handler
17
- */
18
- register(hookName: string, handler: HookHandler, priority?: number): void;
19
- /**
20
- * Execute all handlers for a hook
21
- */
22
- execute(hookName: string, data: any, context?: any): Promise<any>;
23
- /**
24
- * Remove a hook handler
25
- */
26
- unregister(hookName: string, handler: HookHandler): void;
27
- /**
28
- * Get all registered hooks for a name
29
- */
30
- getHooks(hookName: string): PluginHook[];
31
- /**
32
- * Get all registered hook names
33
- */
34
- getHookNames(): string[];
35
- /**
36
- * Get hook statistics
37
- */
38
- getStats(): {
39
- hookName: string;
40
- handlerCount: number;
41
- }[];
42
- /**
43
- * Clear all hooks (useful for testing)
44
- */
45
- clear(): void;
46
- /**
47
- * Create a scoped hook system for a plugin
48
- */
49
- createScope(_pluginName: string): ScopedHookSystem;
50
- }
51
- /**
52
- * Scoped hook system for individual plugins
53
- */
54
- declare class ScopedHookSystem {
55
- private parent;
56
- private registeredHooks;
57
- constructor(parent: HookSystemImpl);
58
- /**
59
- * Register a hook (scoped to this plugin)
60
- */
61
- register(hookName: string, handler: HookHandler, priority?: number): void;
62
- /**
63
- * Execute a hook
64
- */
65
- execute(hookName: string, data: any, context?: any): Promise<any>;
66
- /**
67
- * Unregister a specific hook
68
- */
69
- unregister(hookName: string, handler: HookHandler): void;
70
- /**
71
- * Unregister all hooks for this plugin
72
- */
73
- unregisterAll(): void;
74
- /**
75
- * Get hooks registered by this plugin
76
- */
77
- getRegisteredHooks(): {
78
- hookName: string;
79
- handler: HookHandler;
80
- }[];
8
+ interface TurnstileSettings {
9
+ siteKey: string;
10
+ secretKey: string;
11
+ theme?: 'light' | 'dark' | 'auto';
12
+ size?: 'normal' | 'compact';
13
+ mode?: 'managed' | 'non-interactive' | 'invisible';
14
+ appearance?: 'always' | 'execute' | 'interaction-only';
15
+ preClearance?: boolean;
16
+ preClearanceLevel?: 'interactive' | 'managed' | 'non-interactive';
17
+ enabled: boolean;
81
18
  }
82
- /**
83
- * Hook utilities
84
- */
85
- declare class HookUtils {
86
- /**
87
- * Create a hook name with namespace
88
- */
89
- static createHookName(namespace: string, event: string): string;
19
+ declare class TurnstileService {
20
+ private db;
21
+ private readonly VERIFY_URL;
22
+ constructor(db: D1Database);
90
23
  /**
91
- * Parse a hook name to extract namespace and event
24
+ * Get Turnstile settings from database
92
25
  */
93
- static parseHookName(hookName: string): {
94
- namespace: string;
95
- event: string;
96
- };
26
+ getSettings(): Promise<TurnstileSettings | null>;
97
27
  /**
98
- * Create a middleware that executes hooks
28
+ * Verify a Turnstile token with Cloudflare
99
29
  */
100
- static createHookMiddleware(hookSystem: HookSystem, beforeHook?: string, afterHook?: string): (c: any, next: any) => Promise<void>;
30
+ verifyToken(token: string, remoteIp?: string): Promise<{
31
+ success: boolean;
32
+ error?: string;
33
+ }>;
101
34
  /**
102
- * Create a debounced hook handler
35
+ * Save Turnstile settings to database
103
36
  */
104
- static debounce(handler: HookHandler, delay: number): HookHandler;
37
+ saveSettings(settings: TurnstileSettings): Promise<void>;
105
38
  /**
106
- * Create a throttled hook handler
39
+ * Check if Turnstile is enabled
107
40
  */
108
- static throttle(handler: HookHandler, limit: number): HookHandler;
41
+ isEnabled(): Promise<boolean>;
109
42
  }
110
43
 
111
44
  /**
112
- * Plugin Validator
45
+ * Middleware to verify Turnstile token on form submissions
113
46
  *
114
- * Validates plugin definitions, dependencies, and compatibility
115
- */
116
-
117
- declare class PluginValidator implements PluginValidator$1 {
118
- private static readonly RESERVED_NAMES;
119
- private static readonly RESERVED_PATHS;
120
- /**
121
- * Validate plugin definition
122
- */
123
- validate(plugin: Plugin): PluginValidationResult;
124
- /**
125
- * Validate plugin dependencies
126
- */
127
- validateDependencies(plugin: Plugin, registry: PluginRegistry): PluginValidationResult;
128
- /**
129
- * Validate plugin compatibility with SonicJS version
130
- */
131
- validateCompatibility(plugin: Plugin, sonicVersion: string): PluginValidationResult;
132
- /**
133
- * Check if two version ranges are compatible
134
- */
135
- private isCompatible;
136
- /**
137
- * Validate plugin security constraints
138
- */
139
- validateSecurity(plugin: Plugin): PluginValidationResult;
140
- }
141
-
142
- /**
143
- * Plugin Registry Implementation
47
+ * Usage:
48
+ * ```typescript
49
+ * import { verifyTurnstile } from '@sonicjs-cms/core/plugins'
144
50
  *
145
- * Manages plugin registration, activation, and lifecycle
51
+ * app.post('/api/contact', verifyTurnstile, async (c) => {
52
+ * // Token already verified, process form...
53
+ * })
54
+ * ```
146
55
  */
147
-
148
- declare class PluginRegistryImpl implements PluginRegistry {
149
- private plugins;
150
- private configs;
151
- private statuses;
152
- private validator;
153
- constructor(validator?: PluginValidator);
154
- /**
155
- * Get plugin by name
156
- */
157
- get(name: string): Plugin | undefined;
158
- /**
159
- * Get all registered plugins
160
- */
161
- getAll(): Plugin[];
162
- /**
163
- * Get active plugins
164
- */
165
- getActive(): Plugin[];
166
- /**
167
- * Register a plugin
168
- */
169
- register(plugin: Plugin): Promise<void>;
170
- /**
171
- * Unregister a plugin
172
- */
173
- unregister(name: string): Promise<void>;
174
- /**
175
- * Check if plugin is registered
176
- */
177
- has(name: string): boolean;
178
- /**
179
- * Activate a plugin
180
- */
181
- activate(name: string): Promise<void>;
182
- /**
183
- * Deactivate a plugin
184
- */
185
- deactivate(name: string): Promise<void>;
186
- /**
187
- * Get plugin configuration
188
- */
189
- getConfig(name: string): PluginConfig | undefined;
190
- /**
191
- * Set plugin configuration
192
- */
193
- setConfig(name: string, config: PluginConfig): void;
194
- /**
195
- * Get plugin status
196
- */
197
- getStatus(name: string): PluginStatus | undefined;
198
- /**
199
- * Get all plugin statuses
200
- */
201
- getAllStatuses(): Map<string, PluginStatus>;
202
- /**
203
- * Update plugin status
204
- */
205
- private updateStatus;
206
- /**
207
- * Get plugins that depend on the specified plugin
208
- */
209
- private getDependents;
210
- /**
211
- * Get dependency graph
212
- */
213
- getDependencyGraph(): Map<string, string[]>;
214
- /**
215
- * Resolve plugin load order based on dependencies
216
- */
217
- resolveLoadOrder(): string[];
218
- /**
219
- * Export plugin configuration
220
- */
221
- exportConfig(): {
222
- plugins: PluginConfig[];
223
- };
224
- /**
225
- * Import plugin configuration
226
- */
227
- importConfig(config: {
228
- plugins: PluginConfig[];
229
- }): void;
230
- /**
231
- * Clear all plugins (useful for testing)
232
- */
233
- clear(): void;
234
- /**
235
- * Get registry statistics
236
- */
237
- getStats(): {
238
- total: number;
239
- active: number;
240
- inactive: number;
241
- withErrors: number;
242
- };
243
- }
244
-
56
+ declare function verifyTurnstile(c: Context, next: Next): Promise<void | (Response & hono.TypedResponse<{
57
+ error: string;
58
+ }, 500, "json">) | (Response & hono.TypedResponse<{
59
+ error: string;
60
+ message: string;
61
+ }, 400, "json">) | (Response & hono.TypedResponse<{
62
+ error: string;
63
+ message: string;
64
+ }, 403, "json">)>;
245
65
  /**
246
- * Plugin Manager
247
- *
248
- * Central orchestrator for the plugin system
66
+ * Middleware factory that allows custom error handling
249
67
  */
68
+ declare function createTurnstileMiddleware(options?: {
69
+ onError?: (c: Context, error: string) => Response;
70
+ onMissing?: (c: Context) => Response;
71
+ }): (c: Context, next: Next) => Promise<void | Response>;
250
72
 
251
- declare class PluginManager implements PluginManager$1 {
252
- readonly registry: PluginRegistry;
253
- readonly hooks: HookSystem;
254
- private validator;
255
- private context?;
256
- private scopedHooks;
257
- private pluginRoutes;
258
- constructor();
259
- /**
260
- * Initialize plugin system
261
- */
262
- initialize(context: PluginContext): Promise<void>;
263
- /**
264
- * Load plugins from configuration
265
- */
266
- loadPlugins(configs: PluginConfig[]): Promise<void>;
267
- /**
268
- * Install a plugin
269
- */
270
- install(plugin: Plugin, config?: PluginConfig): Promise<void>;
271
- /**
272
- * Uninstall a plugin
273
- */
274
- uninstall(name: string): Promise<void>;
275
- /**
276
- * Get plugin status
277
- */
278
- getStatus(name: string): PluginStatus;
279
- /**
280
- * Get all plugin statuses
281
- */
282
- getAllStatuses(): PluginStatus[];
283
- /**
284
- * Register plugin extensions (routes, middleware, etc.)
285
- */
286
- private registerPluginExtensions;
287
- /**
288
- * Unregister plugin extensions
289
- */
290
- private unregisterPluginExtensions;
291
- /**
292
- * Update plugin status
293
- */
294
- private updatePluginStatus;
295
- /**
296
- * Create a logger for a plugin
297
- */
298
- private createLogger;
299
- /**
300
- * Get plugin routes for mounting in main app
301
- */
302
- getPluginRoutes(): Map<string, Hono>;
303
- /**
304
- * Get plugin middleware for main app
305
- */
306
- getPluginMiddleware(): Array<{
307
- name: string;
308
- handler: any;
309
- priority: number;
310
- global: boolean;
311
- }>;
312
- /**
313
- * Execute shutdown procedures
314
- */
315
- shutdown(): Promise<void>;
316
- /**
317
- * Get plugin system statistics
318
- */
319
- getStats(): {
320
- registry: ReturnType<PluginRegistryImpl['getStats']>;
321
- hooks: Array<{
322
- hookName: string;
323
- handlerCount: number;
324
- }>;
325
- routes: number;
326
- middleware: number;
327
- };
328
- }
329
-
330
- export { HookSystemImpl, HookUtils, PluginManager, PluginRegistryImpl, PluginValidator, ScopedHookSystem };
73
+ export { TurnstileService, createTurnstileMiddleware, verifyTurnstile };