@sonicjs-cms/core 2.0.0-alpha.3 → 2.0.0-alpha.5

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 (47) hide show
  1. package/dist/chunk-3MNMOLSA.js +133 -0
  2. package/dist/chunk-3MNMOLSA.js.map +1 -0
  3. package/dist/chunk-5RDID2QZ.js +7026 -0
  4. package/dist/chunk-5RDID2QZ.js.map +1 -0
  5. package/dist/chunk-AGOE25LF.cjs +137 -0
  6. package/dist/chunk-AGOE25LF.cjs.map +1 -0
  7. package/dist/chunk-KWFUNPSQ.cjs +7035 -0
  8. package/dist/chunk-KWFUNPSQ.cjs.map +1 -0
  9. package/dist/index.cjs +12 -6
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +9 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/routes.cjs +34 -2
  14. package/dist/routes.js +5 -1
  15. package/dist/services.cjs +13 -1
  16. package/dist/services.js +1 -1
  17. package/package.json +1 -1
  18. package/dist/chunk-4URGXJP7.js +0 -3
  19. package/dist/chunk-4URGXJP7.js.map +0 -1
  20. package/dist/chunk-ALTMI5Y2.cjs +0 -4
  21. package/dist/chunk-ALTMI5Y2.cjs.map +0 -1
  22. package/dist/chunk-BOLQHE4J.cjs +0 -11
  23. package/dist/chunk-BOLQHE4J.cjs.map +0 -1
  24. package/dist/chunk-HD7R6T6I.js +0 -9
  25. package/dist/chunk-HD7R6T6I.js.map +0 -1
  26. package/dist/collection-config-FLlGtsh9.d.cts +0 -107
  27. package/dist/collection-config-FLlGtsh9.d.ts +0 -107
  28. package/dist/index-BlsY5XNH.d.ts +0 -8333
  29. package/dist/index-D45jaIlr.d.cts +0 -8333
  30. package/dist/index.d.cts +0 -136
  31. package/dist/index.d.ts +0 -136
  32. package/dist/middleware.d.cts +0 -206
  33. package/dist/middleware.d.ts +0 -206
  34. package/dist/plugin-UzmDImQc.d.cts +0 -357
  35. package/dist/plugin-UzmDImQc.d.ts +0 -357
  36. package/dist/plugins.d.cts +0 -330
  37. package/dist/plugins.d.ts +0 -330
  38. package/dist/routes.d.cts +0 -17
  39. package/dist/routes.d.ts +0 -17
  40. package/dist/services.d.cts +0 -5
  41. package/dist/services.d.ts +0 -5
  42. package/dist/templates.d.cts +0 -140
  43. package/dist/templates.d.ts +0 -140
  44. package/dist/types.d.cts +0 -41
  45. package/dist/types.d.ts +0 -41
  46. package/dist/utils.d.cts +0 -184
  47. package/dist/utils.d.ts +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.3";
135
-
136
- export { type Bindings, type SonicJSApp, type SonicJSConfig, VERSION, type Variables, createDb, createSonicJSApp, setupCoreMiddleware, setupCoreRoutes };
package/dist/index.d.ts 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-BlsY5XNH.js';
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-BlsY5XNH.js';
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.js';
6
- export { HookSystemImpl, HookUtils, PluginManager as PluginManagerClass, PluginRegistryImpl, PluginValidator as PluginValidatorClass, ScopedHookSystem as ScopedHookSystemClass } from './plugins.js';
7
- export { ROUTES_INFO } from './routes.js';
8
- export { AlertData, ConfirmationDialogOptions, Filter, FilterBarData, FilterOption, FormData, FormField, PaginationData, TableColumn, TableData, getConfirmationDialogScript, renderAlert, renderConfirmationDialog, renderFilterBar, renderForm, renderFormField, renderPagination, renderTable } from './templates.js';
9
- export { b as CollectionConfig, c as CollectionConfigModule, C as CollectionSchema, d as CollectionSyncResult, a as FieldConfig, F as FieldType } from './collection-config-FLlGtsh9.js';
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.js';
11
- export { PluginManifest } from './types.js';
12
- export { FilterCondition, FilterGroup, FilterOperator, QueryFilter, QueryFilterBuilder, QueryResult, TemplateRenderer, buildQuery, escapeHtml, metricsTracker, renderTemplate, sanitizeInput, sanitizeObject, templateRenderer } from './utils.js';
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.3";
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,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 };