@sonicjs-cms/core 2.0.0-alpha.2 → 2.0.0-alpha.4
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/dist/chunk-3MNMOLSA.js +133 -0
- package/dist/chunk-3MNMOLSA.js.map +1 -0
- package/dist/chunk-5XKH6PBR.js +7026 -0
- package/dist/chunk-5XKH6PBR.js.map +1 -0
- package/dist/chunk-AGOE25LF.cjs +137 -0
- package/dist/chunk-AGOE25LF.cjs.map +1 -0
- package/dist/chunk-B5DU2UAN.cjs +7035 -0
- package/dist/chunk-B5DU2UAN.cjs.map +1 -0
- package/dist/index.cjs +13 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/routes.cjs +34 -2
- package/dist/routes.js +5 -1
- package/dist/services.cjs +13 -1
- package/dist/services.js +1 -1
- package/migrations/001_initial_schema.sql +198 -0
- package/migrations/002_faq_plugin.sql +86 -0
- package/migrations/003_stage5_enhancements.sql +121 -0
- package/migrations/004_stage6_user_management.sql +183 -0
- package/migrations/005_stage7_workflow_automation.sql +294 -0
- package/migrations/006_plugin_system.sql +155 -0
- package/migrations/007_demo_login_plugin.sql +23 -0
- package/migrations/008_fix_slug_validation.sql +22 -0
- package/migrations/009_system_logging.sql +57 -0
- package/migrations/011_config_managed_collections.sql +14 -0
- package/migrations/012_testimonials_plugin.sql +80 -0
- package/migrations/013_code_examples_plugin.sql +177 -0
- package/migrations/014_fix_plugin_registry.sql +88 -0
- package/migrations/015_add_remaining_plugins.sql +89 -0
- package/migrations/016_remove_duplicate_cache_plugin.sql +17 -0
- package/migrations/017_auth_configurable_fields.sql +49 -0
- package/package.json +1 -1
- package/dist/chunk-4URGXJP7.js +0 -3
- package/dist/chunk-4URGXJP7.js.map +0 -1
- package/dist/chunk-ALTMI5Y2.cjs +0 -4
- package/dist/chunk-ALTMI5Y2.cjs.map +0 -1
- package/dist/chunk-BOLQHE4J.cjs +0 -11
- package/dist/chunk-BOLQHE4J.cjs.map +0 -1
- package/dist/chunk-HD7R6T6I.js +0 -9
- package/dist/chunk-HD7R6T6I.js.map +0 -1
- package/dist/collection-config-FLlGtsh9.d.cts +0 -107
- package/dist/collection-config-FLlGtsh9.d.ts +0 -107
- package/dist/index-BlsY5XNH.d.ts +0 -8333
- package/dist/index-D45jaIlr.d.cts +0 -8333
- package/dist/index.d.cts +0 -136
- package/dist/index.d.ts +0 -136
- package/dist/middleware.d.cts +0 -206
- package/dist/middleware.d.ts +0 -206
- package/dist/plugin-UzmDImQc.d.cts +0 -357
- package/dist/plugin-UzmDImQc.d.ts +0 -357
- package/dist/plugins.d.cts +0 -330
- package/dist/plugins.d.ts +0 -330
- package/dist/routes.d.cts +0 -17
- package/dist/routes.d.ts +0 -17
- package/dist/services.d.cts +0 -5
- package/dist/services.d.ts +0 -5
- package/dist/templates.d.cts +0 -140
- package/dist/templates.d.ts +0 -140
- package/dist/types.d.cts +0 -41
- package/dist/types.d.ts +0 -41
- package/dist/utils.d.cts +0 -184
- package/dist/utils.d.ts +0 -184
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./chunk-
|
|
3
|
+
var chunkB5DU2UAN_cjs = require('./chunk-B5DU2UAN.cjs');
|
|
4
|
+
require('./chunk-AGOE25LF.cjs');
|
|
4
5
|
var chunk24PWAFUT_cjs = require('./chunk-24PWAFUT.cjs');
|
|
5
6
|
var chunkWJ7QYVR2_cjs = require('./chunk-WJ7QYVR2.cjs');
|
|
6
|
-
var chunkBOLQHE4J_cjs = require('./chunk-BOLQHE4J.cjs');
|
|
7
7
|
var chunkBRC3F4CG_cjs = require('./chunk-BRC3F4CG.cjs');
|
|
8
8
|
var chunkL3NXO7Y4_cjs = require('./chunk-L3NXO7Y4.cjs');
|
|
9
9
|
var chunkRGCQSFKC_cjs = require('./chunk-RGCQSFKC.cjs');
|
|
@@ -39,6 +39,12 @@ function createSonicJSApp(config = {}) {
|
|
|
39
39
|
app.use("*", middleware);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
app.route("/api", chunkB5DU2UAN_cjs.api_default);
|
|
43
|
+
app.route("/api/media", chunkB5DU2UAN_cjs.api_media_default);
|
|
44
|
+
app.route("/api/system", chunkB5DU2UAN_cjs.api_system_default);
|
|
45
|
+
app.route("/admin/api", chunkB5DU2UAN_cjs.admin_api_default);
|
|
46
|
+
app.route("/admin/content", chunkB5DU2UAN_cjs.admin_content_default);
|
|
47
|
+
app.route("/auth", chunkB5DU2UAN_cjs.auth_default);
|
|
42
48
|
if (config.routes) {
|
|
43
49
|
for (const route of config.routes) {
|
|
44
50
|
app.route(route.path, route.handler);
|
|
@@ -72,8 +78,12 @@ function createDb(d1$1) {
|
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
// src/index.ts
|
|
75
|
-
var VERSION = "2.0.0-alpha.
|
|
81
|
+
var VERSION = "2.0.0-alpha.3";
|
|
76
82
|
|
|
83
|
+
Object.defineProperty(exports, "ROUTES_INFO", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () { return chunkB5DU2UAN_cjs.ROUTES_INFO; }
|
|
86
|
+
});
|
|
77
87
|
Object.defineProperty(exports, "AuthManager", {
|
|
78
88
|
enumerable: true,
|
|
79
89
|
get: function () { return chunk24PWAFUT_cjs.AuthManager; }
|
|
@@ -370,10 +380,6 @@ Object.defineProperty(exports, "workflowHistory", {
|
|
|
370
380
|
enumerable: true,
|
|
371
381
|
get: function () { return chunkWJ7QYVR2_cjs.workflowHistory; }
|
|
372
382
|
});
|
|
373
|
-
Object.defineProperty(exports, "ROUTES_INFO", {
|
|
374
|
-
enumerable: true,
|
|
375
|
-
get: function () { return chunkBOLQHE4J_cjs.ROUTES_INFO; }
|
|
376
|
-
});
|
|
377
383
|
Object.defineProperty(exports, "getConfirmationDialogScript", {
|
|
378
384
|
enumerable: true,
|
|
379
385
|
get: function () { return chunkBRC3F4CG_cjs.getConfirmationDialogScript; }
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/app.ts","../src/db/index.ts","../src/index.ts"],"names":["Hono","d1","drizzle","schema_exports"],"mappings":";;;;;;;;;;;;;;AAoGO,SAAS,gBAAA,CAAiB,MAAA,GAAwB,EAAC,EAAe;AACvE,EAAA,MAAM,GAAA,GAAM,IAAIA,SAAA,EAAmD;AAGnE,EAAA,MAAM,UAAA,GAAa,OAAO,OAAA,IAAW,OAAA;AACrC,EAAA,MAAM,OAAA,GAAU,OAAO,IAAA,IAAQ,SAAA;AAG/B,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,EAAG,IAAA,KAAS;AAC9B,IAAA,CAAA,CAAE,GAAA,CAAI,cAAc,UAAU,CAAA;AAC9B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAKD,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,EAAA,EAAI,IAAA,KAAS;AAE/B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAGD,EAAA,IAAI,MAAA,CAAO,YAAY,UAAA,EAAY;AACjC,IAAA,KAAA,MAAW,UAAA,IAAc,MAAA,CAAO,UAAA,CAAW,UAAA,EAAY;AACrD,MAAA,GAAA,CAAI,GAAA,CAAI,KAAK,UAAU,CAAA;AAAA,IACzB;AAAA,EACF;AAGA,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,EAAA,EAAI,IAAA,KAAS;AAE/B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAGD,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,EAAA,EAAI,IAAA,KAAS;AAE/B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAGD,EAAA,IAAI,MAAA,CAAO,YAAY,SAAA,EAAW;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gEAAgE,CAAA;AAE/E;ACvMO,SAAS,SAASC,IAAA,EAAgB;AACvC,EAAA,OAAOC,UAAA,CAAQD,IAAA,EAAI,EAAE,MAAA,EAAAE,gCAAA,EAAQ,CAAA;AAC/B;;;ACoRO,IAAM,OAAA,GAAU","file":"index.cjs","sourcesContent":["/**\n * Main Application Factory\n *\n * Creates a configured SonicJS application with all core functionality\n */\n\nimport { Hono } from 'hono'\nimport type { Context } from 'hono'\nimport type { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface Bindings {\n DB: D1Database\n CACHE_KV: KVNamespace\n MEDIA_BUCKET: R2Bucket\n ASSETS: Fetcher\n EMAIL_QUEUE?: Queue\n SENDGRID_API_KEY?: string\n DEFAULT_FROM_EMAIL?: string\n IMAGES_ACCOUNT_ID?: string\n IMAGES_API_TOKEN?: string\n ENVIRONMENT?: string\n}\n\nexport interface Variables {\n user?: {\n userId: string\n email: string\n role: string\n exp: number\n iat: number\n }\n requestId?: string\n startTime?: number\n appVersion?: string\n}\n\nexport interface SonicJSConfig {\n // Collections configuration\n collections?: {\n directory?: string\n autoSync?: boolean\n }\n\n // Plugins configuration\n plugins?: {\n directory?: string\n autoLoad?: boolean\n }\n\n // Custom routes\n routes?: Array<{\n path: string\n handler: Hono\n }>\n\n // Custom middleware\n middleware?: {\n beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n }\n\n // App metadata\n version?: string\n name?: string\n}\n\nexport type SonicJSApp = Hono<{ Bindings: Bindings; Variables: Variables }>\n\n// ============================================================================\n// Application Factory\n// ============================================================================\n\n/**\n * Create a SonicJS application with core functionality\n *\n * @param config - Application configuration\n * @returns Configured Hono application\n *\n * @example\n * ```typescript\n * import { createSonicJSApp } from '@sonicjs/core'\n *\n * const app = createSonicJSApp({\n * collections: {\n * directory: './src/collections',\n * autoSync: true\n * },\n * plugins: {\n * directory: './src/plugins',\n * autoLoad: true\n * }\n * })\n *\n * export default app\n * ```\n */\nexport function createSonicJSApp(config: SonicJSConfig = {}): SonicJSApp {\n const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()\n\n // Set app metadata\n const appVersion = config.version || '1.0.0'\n const appName = config.name || 'SonicJS'\n\n // App version middleware\n app.use('*', async (c, next) => {\n c.set('appVersion', appVersion)\n await next()\n })\n\n // Bootstrap middleware\n // Note: Implementation will be imported from middleware/bootstrap\n // This is a placeholder for the factory pattern\n app.use('*', async (_c, next) => {\n // Bootstrap logic here (migrations, collections, plugins)\n await next()\n })\n\n // Custom middleware - before auth\n if (config.middleware?.beforeAuth) {\n for (const middleware of config.middleware.beforeAuth) {\n app.use('*', middleware)\n }\n }\n\n // Logging middleware\n app.use('*', async (_c, next) => {\n // Logging logic here\n await next()\n })\n\n // Security middleware\n app.use('*', async (_c, next) => {\n // Security headers, CORS, etc.\n await next()\n })\n\n // Custom middleware - after auth\n if (config.middleware?.afterAuth) {\n for (const middleware of config.middleware.afterAuth) {\n app.use('*', middleware)\n }\n }\n\n // Core routes\n // Note: Routes will be imported from routes/*\n // This is a placeholder for the factory pattern\n\n // Custom routes\n if (config.routes) {\n for (const route of config.routes) {\n app.route(route.path, route.handler)\n }\n }\n\n // Health check\n app.get('/health', (c) => {\n return c.json({\n name: appName,\n version: appVersion,\n status: 'running',\n timestamp: new Date().toISOString()\n })\n })\n\n // 404 handler\n app.notFound((c) => {\n return c.json({ error: 'Not Found', status: 404 }, 404)\n })\n\n // Error handler\n app.onError((err, c) => {\n console.error(err)\n return c.json({ error: 'Internal Server Error', status: 500 }, 500)\n })\n\n return app\n}\n\n/**\n * Setup core middleware (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreMiddleware(_app: SonicJSApp): void {\n console.warn('setupCoreMiddleware is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n\n/**\n * Setup core routes (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreRoutes(_app: SonicJSApp): void {\n console.warn('setupCoreRoutes is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n","import { drizzle } from 'drizzle-orm/d1';\nimport * as schema from './schema';\n\nexport function createDb(d1: D1Database) {\n return drizzle(d1, { schema });\n}\n\nexport * from './schema';","/**\n * @sonicjs/core - Main Entry Point\n *\n * Core framework for SonicJS headless CMS\n * Built for Cloudflare's edge platform with TypeScript\n *\n * Phase 2 Migration Status:\n * - Week 1: Types, Utils, Database (COMPLETED ✓)\n * - Week 2: Services, Middleware, Plugins (COMPLETED ✓)\n * - Week 3: Routes, Templates (COMPLETED ✓)\n * - Week 4: Integration & Testing (COMPLETED ✓)\n *\n * Test Coverage:\n * - Utilities: 48 tests (sanitize, query-filter, metrics)\n * - Middleware: 51 tests (auth, logging, security, performance)\n * - Total: 99 tests passing\n */\n\n// ============================================================================\n// Main Application API (Phase 2 Week 1)\n// ============================================================================\n\nexport { createSonicJSApp, setupCoreMiddleware, setupCoreRoutes } from './app'\nexport type { SonicJSConfig, SonicJSApp, Bindings, Variables } from './app'\n\n// ============================================================================\n// Placeholders - To be populated in Phase 2\n// ============================================================================\n\n// Services - Week 2 (COMPLETED)\nexport {\n // Collection Management\n loadCollectionConfigs,\n loadCollectionConfig,\n getAvailableCollectionNames,\n validateCollectionConfig,\n syncCollections,\n syncCollection,\n isCollectionManaged,\n getManagedCollections,\n cleanupRemovedCollections,\n fullCollectionSync,\n // Database Migrations\n MigrationService,\n // Logging\n Logger,\n getLogger,\n initLogger,\n // Plugin Services - Class implementations\n PluginService as PluginServiceClass,\n PluginBootstrapService,\n} from './services'\n\nexport type { Migration, MigrationStatus, LogLevel, LogCategory, LogEntry, LogFilter, CorePlugin } from './services'\n\n// Middleware - Week 2 (COMPLETED)\nexport {\n // Authentication\n AuthManager,\n requireAuth,\n requireRole,\n optionalAuth,\n // Logging\n loggingMiddleware,\n detailedLoggingMiddleware,\n securityLoggingMiddleware,\n performanceLoggingMiddleware,\n // Performance\n cacheHeaders,\n compressionMiddleware,\n securityHeaders,\n // Permissions\n PermissionManager,\n requirePermission,\n requireAnyPermission,\n logActivity,\n // Plugin middleware\n requireActivePlugin,\n requireActivePlugins,\n getActivePlugins,\n isPluginActive,\n // Bootstrap\n bootstrapMiddleware,\n} from './middleware'\n\nexport type { Permission, UserPermissions } from './middleware'\n\n// Plugins - Week 2 (COMPLETED)\nexport {\n // Hook System - Class implementations\n HookSystemImpl,\n ScopedHookSystem as ScopedHookSystemClass,\n HookUtils,\n // Plugin Registry\n PluginRegistryImpl,\n // Plugin Manager - Class implementation\n PluginManager as PluginManagerClass,\n // Plugin Validator - Class implementation\n PluginValidator as PluginValidatorClass,\n} from './plugins'\n\n// Routes - Week 3 (COMPLETED)\nexport { ROUTES_INFO } from './routes'\n\n// Templates - Week 3 (COMPLETED)\nexport {\n // Form templates\n renderForm,\n renderFormField,\n // Table templates\n renderTable,\n // Pagination templates\n renderPagination,\n // Alert templates\n renderAlert,\n // Confirmation dialog templates\n renderConfirmationDialog,\n getConfirmationDialogScript,\n // Filter bar templates\n renderFilterBar,\n} from './templates'\n\nexport type {\n FormField,\n FormData,\n TableColumn,\n TableData,\n PaginationData,\n AlertData,\n ConfirmationDialogOptions,\n FilterBarData,\n Filter,\n FilterOption,\n} from './templates'\n\n// Types - Week 1 (COMPLETED)\nexport type {\n // Collection types\n FieldType,\n FieldConfig,\n CollectionSchema,\n CollectionConfig,\n CollectionConfigModule,\n CollectionSyncResult,\n // Plugin types\n Plugin,\n PluginContext,\n PluginConfig,\n PluginRoutes,\n PluginMiddleware,\n PluginModel,\n PluginService,\n PluginAdminPage,\n PluginComponent,\n PluginMenuItem,\n PluginHook,\n HookHandler,\n HookContext,\n HookSystem,\n ScopedHookSystem,\n PluginRegistry,\n PluginManager,\n PluginStatus,\n AuthService,\n ContentService,\n MediaService,\n PluginLogger,\n PluginBuilderOptions,\n PluginValidator,\n PluginValidationResult,\n HookName,\n // Plugin manifest\n PluginManifest,\n} from './types'\n\nexport { HOOKS } from './types'\n\n// Utils - Week 1 (COMPLETED)\nexport {\n // Sanitization\n escapeHtml,\n sanitizeInput,\n sanitizeObject,\n // Template rendering\n TemplateRenderer,\n templateRenderer,\n renderTemplate,\n // Query filtering\n QueryFilterBuilder,\n buildQuery,\n // Metrics\n metricsTracker,\n} from './utils'\n\nexport type {\n FilterOperator,\n FilterCondition,\n FilterGroup,\n QueryFilter,\n QueryResult,\n} from './utils'\n\n// Database - Week 1 (COMPLETED)\nexport {\n createDb,\n // Schema exports\n users,\n collections,\n content,\n contentVersions,\n media,\n apiTokens,\n workflowHistory,\n plugins,\n pluginHooks,\n pluginRoutes,\n pluginAssets,\n pluginActivityLog,\n systemLogs,\n logConfig,\n // Zod validation schemas\n insertUserSchema,\n selectUserSchema,\n insertCollectionSchema,\n selectCollectionSchema,\n insertContentSchema,\n selectContentSchema,\n insertMediaSchema,\n selectMediaSchema,\n insertWorkflowHistorySchema,\n selectWorkflowHistorySchema,\n insertPluginSchema,\n selectPluginSchema,\n insertPluginHookSchema,\n selectPluginHookSchema,\n insertPluginRouteSchema,\n selectPluginRouteSchema,\n insertPluginAssetSchema,\n selectPluginAssetSchema,\n insertPluginActivityLogSchema,\n selectPluginActivityLogSchema,\n insertSystemLogSchema,\n selectSystemLogSchema,\n insertLogConfigSchema,\n selectLogConfigSchema,\n} from './db'\n\nexport type {\n User,\n NewUser,\n Collection,\n NewCollection,\n Content,\n NewContent,\n Media,\n NewMedia,\n WorkflowHistory,\n NewWorkflowHistory,\n Plugin as DbPlugin,\n NewPlugin,\n PluginHook as DbPluginHook,\n NewPluginHook,\n PluginRoute,\n NewPluginRoute,\n PluginAsset,\n NewPluginAsset,\n PluginActivityLog,\n NewPluginActivityLog,\n SystemLog,\n NewSystemLog,\n LogConfig,\n NewLogConfig,\n} from './db'\n\n// Plugins - Week 2\n// export { PluginBuilder, HookSystem } from './plugins/sdk'\n\n// ============================================================================\n// Version\n// ============================================================================\n\nexport const VERSION = '2.0.0-alpha.2'\n\n// ============================================================================\n// Phase 2 Migration Notes\n// ============================================================================\n\n/**\n * This is a work-in-progress package being extracted from the main SonicJS codebase.\n *\n * Current Phase: 2 (Core Module Migration)\n * Current Week: 1 (Types, Utils, Database)\n *\n * Expected completion: 4 weeks from 2025-01-17\n *\n * DO NOT USE IN PRODUCTION - Alpha release for development only\n */\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/app.ts","../src/db/index.ts","../src/index.ts"],"names":["Hono","api_default","api_media_default","api_system_default","admin_api_default","admin_content_default","auth_default","d1","drizzle","schema_exports"],"mappings":";;;;;;;;;;;;;;AAqGO,SAAS,gBAAA,CAAiB,MAAA,GAAwB,EAAC,EAAe;AACvE,EAAA,MAAM,GAAA,GAAM,IAAIA,SAAA,EAAmD;AAGnE,EAAA,MAAM,UAAA,GAAa,OAAO,OAAA,IAAW,OAAA;AACrC,EAAA,MAAM,OAAA,GAAU,OAAO,IAAA,IAAQ,SAAA;AAG/B,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,EAAG,IAAA,KAAS;AAC9B,IAAA,CAAA,CAAE,GAAA,CAAI,cAAc,UAAU,CAAA;AAC9B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAKD,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,EAAA,EAAI,IAAA,KAAS;AAE/B,IAAA,MAAM,IAAA,EAAK;AAAA,EACb,CAAC,CAAA;AAGD,EAAA,IAAI,MAAA,CAAO,YAAY,UAAA,EAAY;AACjC,IAAA,KAAA,MAAW,UAAA,IAAc,MAAA,CAAO,UAAA,CAAW,UAAA,EAAY;AACrD,MAAA,GAAA,CAAI,GAAA,CAAI,KAAK,UAAU,CAAA;AAAA,IACzB;AAAA,EACF;AAGA,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAA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ACH,CAAC,CAAA;AAGD,EAAA,GAAA,CAAI,QAAA,CAAS,CAAC,CAAA,KAAM;AAClB,IAAA,OAAO,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,aAAa,MAAA,EAAQ,GAAA,IAAO,GAAG,CAAA;AAAA,EACxD,CAAC,CAAA;AAGD,EAAA,GAAA,CAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,CAAA,KAAM;AACtB,IAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACjB,IAAA,OAAO,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,yBAAyB,MAAA,EAAQ,GAAA,IAAO,GAAG,CAAA;AAAA,EACpE,CAAC,CAAA;AAED,EAAA,OAAO,GAAA;AACT;AAQO,SAAS,oBAAoB,IAAA,EAAwB;AAC1D,EAAA,OAAA,CAAQ,KAAK,oEAAoE,CAAA;AAEnF;AAQO,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAA,CAAQ,KAAK,gEAAgE,CAAA;AAE/E;AC9MO,SAAS,SAASC,IAAA,EAAgB;AACvC,EAAA,OAAOC,UAAA,CAAQD,IAAA,EAAI,EAAE,MAAA,EAAAE,gCAAA,EAAQ,CAAA;AAC/B;;;ACoRO,IAAM,OAAA,GAAU","file":"index.cjs","sourcesContent":["/**\n * Main Application Factory\n *\n * Creates a configured SonicJS application with all core functionality\n */\n\nimport { Hono } from 'hono'\nimport type { Context } from 'hono'\nimport type { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types'\nimport { apiRoutes, apiMediaRoutes, apiSystemRoutes, adminApiRoutes, authRoutes, adminContentRoutes } from './routes'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface Bindings {\n DB: D1Database\n CACHE_KV: KVNamespace\n MEDIA_BUCKET: R2Bucket\n ASSETS: Fetcher\n EMAIL_QUEUE?: Queue\n SENDGRID_API_KEY?: string\n DEFAULT_FROM_EMAIL?: string\n IMAGES_ACCOUNT_ID?: string\n IMAGES_API_TOKEN?: string\n ENVIRONMENT?: string\n}\n\nexport interface Variables {\n user?: {\n userId: string\n email: string\n role: string\n exp: number\n iat: number\n }\n requestId?: string\n startTime?: number\n appVersion?: string\n}\n\nexport interface SonicJSConfig {\n // Collections configuration\n collections?: {\n directory?: string\n autoSync?: boolean\n }\n\n // Plugins configuration\n plugins?: {\n directory?: string\n autoLoad?: boolean\n }\n\n // Custom routes\n routes?: Array<{\n path: string\n handler: Hono\n }>\n\n // Custom middleware\n middleware?: {\n beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n }\n\n // App metadata\n version?: string\n name?: string\n}\n\nexport type SonicJSApp = Hono<{ Bindings: Bindings; Variables: Variables }>\n\n// ============================================================================\n// Application Factory\n// ============================================================================\n\n/**\n * Create a SonicJS application with core functionality\n *\n * @param config - Application configuration\n * @returns Configured Hono application\n *\n * @example\n * ```typescript\n * import { createSonicJSApp } from '@sonicjs/core'\n *\n * const app = createSonicJSApp({\n * collections: {\n * directory: './src/collections',\n * autoSync: true\n * },\n * plugins: {\n * directory: './src/plugins',\n * autoLoad: true\n * }\n * })\n *\n * export default app\n * ```\n */\nexport function createSonicJSApp(config: SonicJSConfig = {}): SonicJSApp {\n const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()\n\n // Set app metadata\n const appVersion = config.version || '1.0.0'\n const appName = config.name || 'SonicJS'\n\n // App version middleware\n app.use('*', async (c, next) => {\n c.set('appVersion', appVersion)\n await next()\n })\n\n // Bootstrap middleware\n // Note: Implementation will be imported from middleware/bootstrap\n // This is a placeholder for the factory pattern\n app.use('*', async (_c, next) => {\n // Bootstrap logic here (migrations, collections, plugins)\n await next()\n })\n\n // Custom middleware - before auth\n if (config.middleware?.beforeAuth) {\n for (const middleware of config.middleware.beforeAuth) {\n app.use('*', middleware)\n }\n }\n\n // Logging middleware\n app.use('*', async (_c, next) => {\n // Logging logic here\n await next()\n })\n\n // Security middleware\n app.use('*', async (_c, next) => {\n // Security headers, CORS, etc.\n await next()\n })\n\n // Custom middleware - after auth\n if (config.middleware?.afterAuth) {\n for (const middleware of config.middleware.afterAuth) {\n app.use('*', middleware)\n }\n }\n\n // Core routes\n // Routes are being imported incrementally from routes/*\n // Each route is tested and migrated one-by-one\n app.route('/api', apiRoutes)\n app.route('/api/media', apiMediaRoutes)\n app.route('/api/system', apiSystemRoutes)\n app.route('/admin/api', adminApiRoutes)\n app.route('/admin/content', adminContentRoutes)\n app.route('/auth', authRoutes)\n\n // Custom routes - User-defined routes\n if (config.routes) {\n for (const route of config.routes) {\n app.route(route.path, route.handler)\n }\n }\n\n // Health check\n app.get('/health', (c) => {\n return c.json({\n name: appName,\n version: appVersion,\n status: 'running',\n timestamp: new Date().toISOString()\n })\n })\n\n // 404 handler\n app.notFound((c) => {\n return c.json({ error: 'Not Found', status: 404 }, 404)\n })\n\n // Error handler\n app.onError((err, c) => {\n console.error(err)\n return c.json({ error: 'Internal Server Error', status: 500 }, 500)\n })\n\n return app\n}\n\n/**\n * Setup core middleware (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreMiddleware(_app: SonicJSApp): void {\n console.warn('setupCoreMiddleware is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n\n/**\n * Setup core routes (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreRoutes(_app: SonicJSApp): void {\n console.warn('setupCoreRoutes is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n","import { drizzle } from 'drizzle-orm/d1';\nimport * as schema from './schema';\n\nexport function createDb(d1: D1Database) {\n return drizzle(d1, { schema });\n}\n\nexport * from './schema';","/**\n * @sonicjs/core - Main Entry Point\n *\n * Core framework for SonicJS headless CMS\n * Built for Cloudflare's edge platform with TypeScript\n *\n * Phase 2 Migration Status:\n * - Week 1: Types, Utils, Database (COMPLETED ✓)\n * - Week 2: Services, Middleware, Plugins (COMPLETED ✓)\n * - Week 3: Routes, Templates (COMPLETED ✓)\n * - Week 4: Integration & Testing (COMPLETED ✓)\n *\n * Test Coverage:\n * - Utilities: 48 tests (sanitize, query-filter, metrics)\n * - Middleware: 51 tests (auth, logging, security, performance)\n * - Total: 99 tests passing\n */\n\n// ============================================================================\n// Main Application API (Phase 2 Week 1)\n// ============================================================================\n\nexport { createSonicJSApp, setupCoreMiddleware, setupCoreRoutes } from './app'\nexport type { SonicJSConfig, SonicJSApp, Bindings, Variables } from './app'\n\n// ============================================================================\n// Placeholders - To be populated in Phase 2\n// ============================================================================\n\n// Services - Week 2 (COMPLETED)\nexport {\n // Collection Management\n loadCollectionConfigs,\n loadCollectionConfig,\n getAvailableCollectionNames,\n validateCollectionConfig,\n syncCollections,\n syncCollection,\n isCollectionManaged,\n getManagedCollections,\n cleanupRemovedCollections,\n fullCollectionSync,\n // Database Migrations\n MigrationService,\n // Logging\n Logger,\n getLogger,\n initLogger,\n // Plugin Services - Class implementations\n PluginService as PluginServiceClass,\n PluginBootstrapService,\n} from './services'\n\nexport type { Migration, MigrationStatus, LogLevel, LogCategory, LogEntry, LogFilter, CorePlugin } from './services'\n\n// Middleware - Week 2 (COMPLETED)\nexport {\n // Authentication\n AuthManager,\n requireAuth,\n requireRole,\n optionalAuth,\n // Logging\n loggingMiddleware,\n detailedLoggingMiddleware,\n securityLoggingMiddleware,\n performanceLoggingMiddleware,\n // Performance\n cacheHeaders,\n compressionMiddleware,\n securityHeaders,\n // Permissions\n PermissionManager,\n requirePermission,\n requireAnyPermission,\n logActivity,\n // Plugin middleware\n requireActivePlugin,\n requireActivePlugins,\n getActivePlugins,\n isPluginActive,\n // Bootstrap\n bootstrapMiddleware,\n} from './middleware'\n\nexport type { Permission, UserPermissions } from './middleware'\n\n// Plugins - Week 2 (COMPLETED)\nexport {\n // Hook System - Class implementations\n HookSystemImpl,\n ScopedHookSystem as ScopedHookSystemClass,\n HookUtils,\n // Plugin Registry\n PluginRegistryImpl,\n // Plugin Manager - Class implementation\n PluginManager as PluginManagerClass,\n // Plugin Validator - Class implementation\n PluginValidator as PluginValidatorClass,\n} from './plugins'\n\n// Routes - Week 3 (COMPLETED)\nexport { ROUTES_INFO } from './routes'\n\n// Templates - Week 3 (COMPLETED)\nexport {\n // Form templates\n renderForm,\n renderFormField,\n // Table templates\n renderTable,\n // Pagination templates\n renderPagination,\n // Alert templates\n renderAlert,\n // Confirmation dialog templates\n renderConfirmationDialog,\n getConfirmationDialogScript,\n // Filter bar templates\n renderFilterBar,\n} from './templates'\n\nexport type {\n FormField,\n FormData,\n TableColumn,\n TableData,\n PaginationData,\n AlertData,\n ConfirmationDialogOptions,\n FilterBarData,\n Filter,\n FilterOption,\n} from './templates'\n\n// Types - Week 1 (COMPLETED)\nexport type {\n // Collection types\n FieldType,\n FieldConfig,\n CollectionSchema,\n CollectionConfig,\n CollectionConfigModule,\n CollectionSyncResult,\n // Plugin types\n Plugin,\n PluginContext,\n PluginConfig,\n PluginRoutes,\n PluginMiddleware,\n PluginModel,\n PluginService,\n PluginAdminPage,\n PluginComponent,\n PluginMenuItem,\n PluginHook,\n HookHandler,\n HookContext,\n HookSystem,\n ScopedHookSystem,\n PluginRegistry,\n PluginManager,\n PluginStatus,\n AuthService,\n ContentService,\n MediaService,\n PluginLogger,\n PluginBuilderOptions,\n PluginValidator,\n PluginValidationResult,\n HookName,\n // Plugin manifest\n PluginManifest,\n} from './types'\n\nexport { HOOKS } from './types'\n\n// Utils - Week 1 (COMPLETED)\nexport {\n // Sanitization\n escapeHtml,\n sanitizeInput,\n sanitizeObject,\n // Template rendering\n TemplateRenderer,\n templateRenderer,\n renderTemplate,\n // Query filtering\n QueryFilterBuilder,\n buildQuery,\n // Metrics\n metricsTracker,\n} from './utils'\n\nexport type {\n FilterOperator,\n FilterCondition,\n FilterGroup,\n QueryFilter,\n QueryResult,\n} from './utils'\n\n// Database - Week 1 (COMPLETED)\nexport {\n createDb,\n // Schema exports\n users,\n collections,\n content,\n contentVersions,\n media,\n apiTokens,\n workflowHistory,\n plugins,\n pluginHooks,\n pluginRoutes,\n pluginAssets,\n pluginActivityLog,\n systemLogs,\n logConfig,\n // Zod validation schemas\n insertUserSchema,\n selectUserSchema,\n insertCollectionSchema,\n selectCollectionSchema,\n insertContentSchema,\n selectContentSchema,\n insertMediaSchema,\n selectMediaSchema,\n insertWorkflowHistorySchema,\n selectWorkflowHistorySchema,\n insertPluginSchema,\n selectPluginSchema,\n insertPluginHookSchema,\n selectPluginHookSchema,\n insertPluginRouteSchema,\n selectPluginRouteSchema,\n insertPluginAssetSchema,\n selectPluginAssetSchema,\n insertPluginActivityLogSchema,\n selectPluginActivityLogSchema,\n insertSystemLogSchema,\n selectSystemLogSchema,\n insertLogConfigSchema,\n selectLogConfigSchema,\n} from './db'\n\nexport type {\n User,\n NewUser,\n Collection,\n NewCollection,\n Content,\n NewContent,\n Media,\n NewMedia,\n WorkflowHistory,\n NewWorkflowHistory,\n Plugin as DbPlugin,\n NewPlugin,\n PluginHook as DbPluginHook,\n NewPluginHook,\n PluginRoute,\n NewPluginRoute,\n PluginAsset,\n NewPluginAsset,\n PluginActivityLog,\n NewPluginActivityLog,\n SystemLog,\n NewSystemLog,\n LogConfig,\n NewLogConfig,\n} from './db'\n\n// Plugins - Week 2\n// export { PluginBuilder, HookSystem } from './plugins/sdk'\n\n// ============================================================================\n// Version\n// ============================================================================\n\nexport const VERSION = '2.0.0-alpha.3'\n\n// ============================================================================\n// Phase 2 Migration Notes\n// ============================================================================\n\n/**\n * This is a work-in-progress package being extracted from the main SonicJS codebase.\n *\n * Current Phase: 2 (Core Module Migration)\n * Current Week: 1 (Types, Utils, Database)\n *\n * Expected completion: 4 weeks from 2025-01-17\n *\n * DO NOT USE IN PRODUCTION - Alpha release for development only\n */\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import './chunk-
|
|
1
|
+
import { api_default, api_media_default, api_system_default, admin_api_default, admin_content_default, auth_default } from './chunk-5XKH6PBR.js';
|
|
2
|
+
export { ROUTES_INFO } from './chunk-5XKH6PBR.js';
|
|
3
|
+
import './chunk-3MNMOLSA.js';
|
|
2
4
|
export { AuthManager, PermissionManager, bootstrapMiddleware, cacheHeaders, compressionMiddleware, detailedLoggingMiddleware, getActivePlugins, isPluginActive, logActivity, loggingMiddleware, optionalAuth, performanceLoggingMiddleware, requireActivePlugin, requireActivePlugins, requireAnyPermission, requireAuth, requirePermission, requireRole, securityHeaders, securityLoggingMiddleware } from './chunk-PTQZ5FEI.js';
|
|
3
5
|
import { schema_exports } from './chunk-CXZDAR6S.js';
|
|
4
6
|
export { Logger, MigrationService, PluginBootstrapService, PluginService as PluginServiceClass, apiTokens, cleanupRemovedCollections, collections, content, contentVersions, fullCollectionSync, getAvailableCollectionNames, getLogger, getManagedCollections, initLogger, insertCollectionSchema, insertContentSchema, insertLogConfigSchema, insertMediaSchema, insertPluginActivityLogSchema, insertPluginAssetSchema, insertPluginHookSchema, insertPluginRouteSchema, insertPluginSchema, insertSystemLogSchema, insertUserSchema, insertWorkflowHistorySchema, isCollectionManaged, loadCollectionConfig, loadCollectionConfigs, logConfig, media, pluginActivityLog, pluginAssets, pluginHooks, pluginRoutes, plugins, selectCollectionSchema, selectContentSchema, selectLogConfigSchema, selectMediaSchema, selectPluginActivityLogSchema, selectPluginAssetSchema, selectPluginHookSchema, selectPluginRouteSchema, selectPluginSchema, selectSystemLogSchema, selectUserSchema, selectWorkflowHistorySchema, syncCollection, syncCollections, systemLogs, users, validateCollectionConfig, workflowHistory } from './chunk-CXZDAR6S.js';
|
|
5
|
-
export { ROUTES_INFO } from './chunk-HD7R6T6I.js';
|
|
6
7
|
export { getConfirmationDialogScript, renderAlert, renderConfirmationDialog, renderFilterBar, renderForm, renderFormField, renderPagination, renderTable } from './chunk-KRJMGD4E.js';
|
|
7
8
|
export { HookSystemImpl, HookUtils, PluginManager as PluginManagerClass, PluginRegistryImpl, PluginValidator as PluginValidatorClass, ScopedHookSystem as ScopedHookSystemClass } from './chunk-NRSL6BQI.js';
|
|
8
9
|
export { QueryFilterBuilder, TemplateRenderer, buildQuery, escapeHtml, metricsTracker, renderTemplate, sanitizeInput, sanitizeObject, templateRenderer } from './chunk-JIINOD2W.js';
|
|
@@ -38,6 +39,12 @@ function createSonicJSApp(config = {}) {
|
|
|
38
39
|
app.use("*", middleware);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
42
|
+
app.route("/api", api_default);
|
|
43
|
+
app.route("/api/media", api_media_default);
|
|
44
|
+
app.route("/api/system", api_system_default);
|
|
45
|
+
app.route("/admin/api", admin_api_default);
|
|
46
|
+
app.route("/admin/content", admin_content_default);
|
|
47
|
+
app.route("/auth", auth_default);
|
|
41
48
|
if (config.routes) {
|
|
42
49
|
for (const route of config.routes) {
|
|
43
50
|
app.route(route.path, route.handler);
|
|
@@ -71,7 +78,7 @@ function createDb(d1) {
|
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
// src/index.ts
|
|
74
|
-
var VERSION = "2.0.0-alpha.
|
|
81
|
+
var VERSION = "2.0.0-alpha.3";
|
|
75
82
|
|
|
76
83
|
export { VERSION, createDb, createSonicJSApp, setupCoreMiddleware, setupCoreRoutes };
|
|
77
84
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/app.ts","../src/db/index.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAoGO,SAAS,gBAAA,CAAiB,MAAA,GAAwB,EAAC,EAAe;AACvE,EAAA,MAAM,GAAA,GAAM,IAAI,IAAA,EAAmD;AAGnE,EAAA,MAAM,UAAA,GAAa,OAAO,OAAA,IAAW,OAAA;AACrC,EAAA,MAAM,OAAA,GAAU,OAAO,IAAA,IAAQ,SAAA;AAG/B,EAAA,GAAA,CAAI,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA,EAAG,IAAA,KAAS;AAC9B,I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ACN,OAAA,EAAS,UAAA;AAAA,MACT,MAAA,EAAQ,SAAA;AAAA,MACR,SAAA,EAAA,iBAAW,IAAI,IAAA,EAAK,EAAE,WAAA;AAAY,KACnC,CAAA;AAAA,EACH,CAAC,CAAA;AAGD,EAAA,GAAA,CAAI,QAAA,CAAS,CAAC,CAAA,KAAM;AAClB,IAAA,OAAO,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,aAAa,MAAA,EAAQ,GAAA,IAAO,GAAG,CAAA;AAAA,EACxD,CAAC,CAAA;AAGD,EAAA,GAAA,CAAI,OAAA,CAAQ,CAAC,GAAA,EAAK,CAAA,KAAM;AACtB,IAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACjB,IAAA,OAAO,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,yBAAyB,MAAA,EAAQ,GAAA,IAAO,GAAG,CAAA;AAAA,EACpE,CAAC,CAAA;AAED,EAAA,OAAO,GAAA;AACT;AAQO,SAAS,oBAAoB,IAAA,EAAwB;AAC1D,EAAA,OAAA,CAAQ,KAAK,oEAAoE,CAAA;AAEnF;AAQO,SAAS,gBAAgB,IAAA,EAAwB;AACtD,EAAA,OAAA,CAAQ,KAAK,gEAAgE,CAAA;AAE/E;ACvMO,SAAS,SAAS,EAAA,EAAgB;AACvC,EAAA,OAAO,OAAA,CAAQ,EAAA,EAAI,EAAE,MAAA,EAAA,cAAA,EAAQ,CAAA;AAC/B;;;ACoRO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["/**\n * Main Application Factory\n *\n * Creates a configured SonicJS application with all core functionality\n */\n\nimport { Hono } from 'hono'\nimport type { Context } from 'hono'\nimport type { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface Bindings {\n DB: D1Database\n CACHE_KV: KVNamespace\n MEDIA_BUCKET: R2Bucket\n ASSETS: Fetcher\n EMAIL_QUEUE?: Queue\n SENDGRID_API_KEY?: string\n DEFAULT_FROM_EMAIL?: string\n IMAGES_ACCOUNT_ID?: string\n IMAGES_API_TOKEN?: string\n ENVIRONMENT?: string\n}\n\nexport interface Variables {\n user?: {\n userId: string\n email: string\n role: string\n exp: number\n iat: number\n }\n requestId?: string\n startTime?: number\n appVersion?: string\n}\n\nexport interface SonicJSConfig {\n // Collections configuration\n collections?: {\n directory?: string\n autoSync?: boolean\n }\n\n // Plugins configuration\n plugins?: {\n directory?: string\n autoLoad?: boolean\n }\n\n // Custom routes\n routes?: Array<{\n path: string\n handler: Hono\n }>\n\n // Custom middleware\n middleware?: {\n beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n }\n\n // App metadata\n version?: string\n name?: string\n}\n\nexport type SonicJSApp = Hono<{ Bindings: Bindings; Variables: Variables }>\n\n// ============================================================================\n// Application Factory\n// ============================================================================\n\n/**\n * Create a SonicJS application with core functionality\n *\n * @param config - Application configuration\n * @returns Configured Hono application\n *\n * @example\n * ```typescript\n * import { createSonicJSApp } from '@sonicjs/core'\n *\n * const app = createSonicJSApp({\n * collections: {\n * directory: './src/collections',\n * autoSync: true\n * },\n * plugins: {\n * directory: './src/plugins',\n * autoLoad: true\n * }\n * })\n *\n * export default app\n * ```\n */\nexport function createSonicJSApp(config: SonicJSConfig = {}): SonicJSApp {\n const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()\n\n // Set app metadata\n const appVersion = config.version || '1.0.0'\n const appName = config.name || 'SonicJS'\n\n // App version middleware\n app.use('*', async (c, next) => {\n c.set('appVersion', appVersion)\n await next()\n })\n\n // Bootstrap middleware\n // Note: Implementation will be imported from middleware/bootstrap\n // This is a placeholder for the factory pattern\n app.use('*', async (_c, next) => {\n // Bootstrap logic here (migrations, collections, plugins)\n await next()\n })\n\n // Custom middleware - before auth\n if (config.middleware?.beforeAuth) {\n for (const middleware of config.middleware.beforeAuth) {\n app.use('*', middleware)\n }\n }\n\n // Logging middleware\n app.use('*', async (_c, next) => {\n // Logging logic here\n await next()\n })\n\n // Security middleware\n app.use('*', async (_c, next) => {\n // Security headers, CORS, etc.\n await next()\n })\n\n // Custom middleware - after auth\n if (config.middleware?.afterAuth) {\n for (const middleware of config.middleware.afterAuth) {\n app.use('*', middleware)\n }\n }\n\n // Core routes\n // Note: Routes will be imported from routes/*\n // This is a placeholder for the factory pattern\n\n // Custom routes\n if (config.routes) {\n for (const route of config.routes) {\n app.route(route.path, route.handler)\n }\n }\n\n // Health check\n app.get('/health', (c) => {\n return c.json({\n name: appName,\n version: appVersion,\n status: 'running',\n timestamp: new Date().toISOString()\n })\n })\n\n // 404 handler\n app.notFound((c) => {\n return c.json({ error: 'Not Found', status: 404 }, 404)\n })\n\n // Error handler\n app.onError((err, c) => {\n console.error(err)\n return c.json({ error: 'Internal Server Error', status: 500 }, 500)\n })\n\n return app\n}\n\n/**\n * Setup core middleware (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreMiddleware(_app: SonicJSApp): void {\n console.warn('setupCoreMiddleware is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n\n/**\n * Setup core routes (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreRoutes(_app: SonicJSApp): void {\n console.warn('setupCoreRoutes is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n","import { drizzle } from 'drizzle-orm/d1';\nimport * as schema from './schema';\n\nexport function createDb(d1: D1Database) {\n return drizzle(d1, { schema });\n}\n\nexport * from './schema';","/**\n * @sonicjs/core - Main Entry Point\n *\n * Core framework for SonicJS headless CMS\n * Built for Cloudflare's edge platform with TypeScript\n *\n * Phase 2 Migration Status:\n * - Week 1: Types, Utils, Database (COMPLETED ✓)\n * - Week 2: Services, Middleware, Plugins (COMPLETED ✓)\n * - Week 3: Routes, Templates (COMPLETED ✓)\n * - Week 4: Integration & Testing (COMPLETED ✓)\n *\n * Test Coverage:\n * - Utilities: 48 tests (sanitize, query-filter, metrics)\n * - Middleware: 51 tests (auth, logging, security, performance)\n * - Total: 99 tests passing\n */\n\n// ============================================================================\n// Main Application API (Phase 2 Week 1)\n// ============================================================================\n\nexport { createSonicJSApp, setupCoreMiddleware, setupCoreRoutes } from './app'\nexport type { SonicJSConfig, SonicJSApp, Bindings, Variables } from './app'\n\n// ============================================================================\n// Placeholders - To be populated in Phase 2\n// ============================================================================\n\n// Services - Week 2 (COMPLETED)\nexport {\n // Collection Management\n loadCollectionConfigs,\n loadCollectionConfig,\n getAvailableCollectionNames,\n validateCollectionConfig,\n syncCollections,\n syncCollection,\n isCollectionManaged,\n getManagedCollections,\n cleanupRemovedCollections,\n fullCollectionSync,\n // Database Migrations\n MigrationService,\n // Logging\n Logger,\n getLogger,\n initLogger,\n // Plugin Services - Class implementations\n PluginService as PluginServiceClass,\n PluginBootstrapService,\n} from './services'\n\nexport type { Migration, MigrationStatus, LogLevel, LogCategory, LogEntry, LogFilter, CorePlugin } from './services'\n\n// Middleware - Week 2 (COMPLETED)\nexport {\n // Authentication\n AuthManager,\n requireAuth,\n requireRole,\n optionalAuth,\n // Logging\n loggingMiddleware,\n detailedLoggingMiddleware,\n securityLoggingMiddleware,\n performanceLoggingMiddleware,\n // Performance\n cacheHeaders,\n compressionMiddleware,\n securityHeaders,\n // Permissions\n PermissionManager,\n requirePermission,\n requireAnyPermission,\n logActivity,\n // Plugin middleware\n requireActivePlugin,\n requireActivePlugins,\n getActivePlugins,\n isPluginActive,\n // Bootstrap\n bootstrapMiddleware,\n} from './middleware'\n\nexport type { Permission, UserPermissions } from './middleware'\n\n// Plugins - Week 2 (COMPLETED)\nexport {\n // Hook System - Class implementations\n HookSystemImpl,\n ScopedHookSystem as ScopedHookSystemClass,\n HookUtils,\n // Plugin Registry\n PluginRegistryImpl,\n // Plugin Manager - Class implementation\n PluginManager as PluginManagerClass,\n // Plugin Validator - Class implementation\n PluginValidator as PluginValidatorClass,\n} from './plugins'\n\n// Routes - Week 3 (COMPLETED)\nexport { ROUTES_INFO } from './routes'\n\n// Templates - Week 3 (COMPLETED)\nexport {\n // Form templates\n renderForm,\n renderFormField,\n // Table templates\n renderTable,\n // Pagination templates\n renderPagination,\n // Alert templates\n renderAlert,\n // Confirmation dialog templates\n renderConfirmationDialog,\n getConfirmationDialogScript,\n // Filter bar templates\n renderFilterBar,\n} from './templates'\n\nexport type {\n FormField,\n FormData,\n TableColumn,\n TableData,\n PaginationData,\n AlertData,\n ConfirmationDialogOptions,\n FilterBarData,\n Filter,\n FilterOption,\n} from './templates'\n\n// Types - Week 1 (COMPLETED)\nexport type {\n // Collection types\n FieldType,\n FieldConfig,\n CollectionSchema,\n CollectionConfig,\n CollectionConfigModule,\n CollectionSyncResult,\n // Plugin types\n Plugin,\n PluginContext,\n PluginConfig,\n PluginRoutes,\n PluginMiddleware,\n PluginModel,\n PluginService,\n PluginAdminPage,\n PluginComponent,\n PluginMenuItem,\n PluginHook,\n HookHandler,\n HookContext,\n HookSystem,\n ScopedHookSystem,\n PluginRegistry,\n PluginManager,\n PluginStatus,\n AuthService,\n ContentService,\n MediaService,\n PluginLogger,\n PluginBuilderOptions,\n PluginValidator,\n PluginValidationResult,\n HookName,\n // Plugin manifest\n PluginManifest,\n} from './types'\n\nexport { HOOKS } from './types'\n\n// Utils - Week 1 (COMPLETED)\nexport {\n // Sanitization\n escapeHtml,\n sanitizeInput,\n sanitizeObject,\n // Template rendering\n TemplateRenderer,\n templateRenderer,\n renderTemplate,\n // Query filtering\n QueryFilterBuilder,\n buildQuery,\n // Metrics\n metricsTracker,\n} from './utils'\n\nexport type {\n FilterOperator,\n FilterCondition,\n FilterGroup,\n QueryFilter,\n QueryResult,\n} from './utils'\n\n// Database - Week 1 (COMPLETED)\nexport {\n createDb,\n // Schema exports\n users,\n collections,\n content,\n contentVersions,\n media,\n apiTokens,\n workflowHistory,\n plugins,\n pluginHooks,\n pluginRoutes,\n pluginAssets,\n pluginActivityLog,\n systemLogs,\n logConfig,\n // Zod validation schemas\n insertUserSchema,\n selectUserSchema,\n insertCollectionSchema,\n selectCollectionSchema,\n insertContentSchema,\n selectContentSchema,\n insertMediaSchema,\n selectMediaSchema,\n insertWorkflowHistorySchema,\n selectWorkflowHistorySchema,\n insertPluginSchema,\n selectPluginSchema,\n insertPluginHookSchema,\n selectPluginHookSchema,\n insertPluginRouteSchema,\n selectPluginRouteSchema,\n insertPluginAssetSchema,\n selectPluginAssetSchema,\n insertPluginActivityLogSchema,\n selectPluginActivityLogSchema,\n insertSystemLogSchema,\n selectSystemLogSchema,\n insertLogConfigSchema,\n selectLogConfigSchema,\n} from './db'\n\nexport type {\n User,\n NewUser,\n Collection,\n NewCollection,\n Content,\n NewContent,\n Media,\n NewMedia,\n WorkflowHistory,\n NewWorkflowHistory,\n Plugin as DbPlugin,\n NewPlugin,\n PluginHook as DbPluginHook,\n NewPluginHook,\n PluginRoute,\n NewPluginRoute,\n PluginAsset,\n NewPluginAsset,\n PluginActivityLog,\n NewPluginActivityLog,\n SystemLog,\n NewSystemLog,\n LogConfig,\n NewLogConfig,\n} from './db'\n\n// Plugins - Week 2\n// export { PluginBuilder, HookSystem } from './plugins/sdk'\n\n// ============================================================================\n// Version\n// ============================================================================\n\nexport const VERSION = '2.0.0-alpha.2'\n\n// ============================================================================\n// Phase 2 Migration Notes\n// ============================================================================\n\n/**\n * This is a work-in-progress package being extracted from the main SonicJS codebase.\n *\n * Current Phase: 2 (Core Module Migration)\n * Current Week: 1 (Types, Utils, Database)\n *\n * Expected completion: 4 weeks from 2025-01-17\n *\n * DO NOT USE IN PRODUCTION - Alpha release for development only\n */\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/app.ts","../src/db/index.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqGO,SAAS,gBAAA,CAAiB,MAAA,GAAwB,EAAC,EAAe;AACvE,EAAA,MAAM,GAAA,GAAM,IAAI,IAAA,EAAmD;AAGnE,E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,EAAwB;AACtD,EAAA,OAAA,CAAQ,KAAK,gEAAgE,CAAA;AAE/E;AC9MO,SAAS,SAAS,EAAA,EAAgB;AACvC,EAAA,OAAO,OAAA,CAAQ,EAAA,EAAI,EAAE,MAAA,EAAA,cAAA,EAAQ,CAAA;AAC/B;;;ACoRO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["/**\n * Main Application Factory\n *\n * Creates a configured SonicJS application with all core functionality\n */\n\nimport { Hono } from 'hono'\nimport type { Context } from 'hono'\nimport type { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types'\nimport { apiRoutes, apiMediaRoutes, apiSystemRoutes, adminApiRoutes, authRoutes, adminContentRoutes } from './routes'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\nexport interface Bindings {\n DB: D1Database\n CACHE_KV: KVNamespace\n MEDIA_BUCKET: R2Bucket\n ASSETS: Fetcher\n EMAIL_QUEUE?: Queue\n SENDGRID_API_KEY?: string\n DEFAULT_FROM_EMAIL?: string\n IMAGES_ACCOUNT_ID?: string\n IMAGES_API_TOKEN?: string\n ENVIRONMENT?: string\n}\n\nexport interface Variables {\n user?: {\n userId: string\n email: string\n role: string\n exp: number\n iat: number\n }\n requestId?: string\n startTime?: number\n appVersion?: string\n}\n\nexport interface SonicJSConfig {\n // Collections configuration\n collections?: {\n directory?: string\n autoSync?: boolean\n }\n\n // Plugins configuration\n plugins?: {\n directory?: string\n autoLoad?: boolean\n }\n\n // Custom routes\n routes?: Array<{\n path: string\n handler: Hono\n }>\n\n // Custom middleware\n middleware?: {\n beforeAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n afterAuth?: Array<(c: Context, next: () => Promise<void>) => Promise<void>>\n }\n\n // App metadata\n version?: string\n name?: string\n}\n\nexport type SonicJSApp = Hono<{ Bindings: Bindings; Variables: Variables }>\n\n// ============================================================================\n// Application Factory\n// ============================================================================\n\n/**\n * Create a SonicJS application with core functionality\n *\n * @param config - Application configuration\n * @returns Configured Hono application\n *\n * @example\n * ```typescript\n * import { createSonicJSApp } from '@sonicjs/core'\n *\n * const app = createSonicJSApp({\n * collections: {\n * directory: './src/collections',\n * autoSync: true\n * },\n * plugins: {\n * directory: './src/plugins',\n * autoLoad: true\n * }\n * })\n *\n * export default app\n * ```\n */\nexport function createSonicJSApp(config: SonicJSConfig = {}): SonicJSApp {\n const app = new Hono<{ Bindings: Bindings; Variables: Variables }>()\n\n // Set app metadata\n const appVersion = config.version || '1.0.0'\n const appName = config.name || 'SonicJS'\n\n // App version middleware\n app.use('*', async (c, next) => {\n c.set('appVersion', appVersion)\n await next()\n })\n\n // Bootstrap middleware\n // Note: Implementation will be imported from middleware/bootstrap\n // This is a placeholder for the factory pattern\n app.use('*', async (_c, next) => {\n // Bootstrap logic here (migrations, collections, plugins)\n await next()\n })\n\n // Custom middleware - before auth\n if (config.middleware?.beforeAuth) {\n for (const middleware of config.middleware.beforeAuth) {\n app.use('*', middleware)\n }\n }\n\n // Logging middleware\n app.use('*', async (_c, next) => {\n // Logging logic here\n await next()\n })\n\n // Security middleware\n app.use('*', async (_c, next) => {\n // Security headers, CORS, etc.\n await next()\n })\n\n // Custom middleware - after auth\n if (config.middleware?.afterAuth) {\n for (const middleware of config.middleware.afterAuth) {\n app.use('*', middleware)\n }\n }\n\n // Core routes\n // Routes are being imported incrementally from routes/*\n // Each route is tested and migrated one-by-one\n app.route('/api', apiRoutes)\n app.route('/api/media', apiMediaRoutes)\n app.route('/api/system', apiSystemRoutes)\n app.route('/admin/api', adminApiRoutes)\n app.route('/admin/content', adminContentRoutes)\n app.route('/auth', authRoutes)\n\n // Custom routes - User-defined routes\n if (config.routes) {\n for (const route of config.routes) {\n app.route(route.path, route.handler)\n }\n }\n\n // Health check\n app.get('/health', (c) => {\n return c.json({\n name: appName,\n version: appVersion,\n status: 'running',\n timestamp: new Date().toISOString()\n })\n })\n\n // 404 handler\n app.notFound((c) => {\n return c.json({ error: 'Not Found', status: 404 }, 404)\n })\n\n // Error handler\n app.onError((err, c) => {\n console.error(err)\n return c.json({ error: 'Internal Server Error', status: 500 }, 500)\n })\n\n return app\n}\n\n/**\n * Setup core middleware (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreMiddleware(_app: SonicJSApp): void {\n console.warn('setupCoreMiddleware is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n\n/**\n * Setup core routes (backward compatibility)\n *\n * @param _app - Hono application\n * @deprecated Use createSonicJSApp() instead\n */\nexport function setupCoreRoutes(_app: SonicJSApp): void {\n console.warn('setupCoreRoutes is deprecated. Use createSonicJSApp() instead.')\n // Backward compatibility implementation\n}\n","import { drizzle } from 'drizzle-orm/d1';\nimport * as schema from './schema';\n\nexport function createDb(d1: D1Database) {\n return drizzle(d1, { schema });\n}\n\nexport * from './schema';","/**\n * @sonicjs/core - Main Entry Point\n *\n * Core framework for SonicJS headless CMS\n * Built for Cloudflare's edge platform with TypeScript\n *\n * Phase 2 Migration Status:\n * - Week 1: Types, Utils, Database (COMPLETED ✓)\n * - Week 2: Services, Middleware, Plugins (COMPLETED ✓)\n * - Week 3: Routes, Templates (COMPLETED ✓)\n * - Week 4: Integration & Testing (COMPLETED ✓)\n *\n * Test Coverage:\n * - Utilities: 48 tests (sanitize, query-filter, metrics)\n * - Middleware: 51 tests (auth, logging, security, performance)\n * - Total: 99 tests passing\n */\n\n// ============================================================================\n// Main Application API (Phase 2 Week 1)\n// ============================================================================\n\nexport { createSonicJSApp, setupCoreMiddleware, setupCoreRoutes } from './app'\nexport type { SonicJSConfig, SonicJSApp, Bindings, Variables } from './app'\n\n// ============================================================================\n// Placeholders - To be populated in Phase 2\n// ============================================================================\n\n// Services - Week 2 (COMPLETED)\nexport {\n // Collection Management\n loadCollectionConfigs,\n loadCollectionConfig,\n getAvailableCollectionNames,\n validateCollectionConfig,\n syncCollections,\n syncCollection,\n isCollectionManaged,\n getManagedCollections,\n cleanupRemovedCollections,\n fullCollectionSync,\n // Database Migrations\n MigrationService,\n // Logging\n Logger,\n getLogger,\n initLogger,\n // Plugin Services - Class implementations\n PluginService as PluginServiceClass,\n PluginBootstrapService,\n} from './services'\n\nexport type { Migration, MigrationStatus, LogLevel, LogCategory, LogEntry, LogFilter, CorePlugin } from './services'\n\n// Middleware - Week 2 (COMPLETED)\nexport {\n // Authentication\n AuthManager,\n requireAuth,\n requireRole,\n optionalAuth,\n // Logging\n loggingMiddleware,\n detailedLoggingMiddleware,\n securityLoggingMiddleware,\n performanceLoggingMiddleware,\n // Performance\n cacheHeaders,\n compressionMiddleware,\n securityHeaders,\n // Permissions\n PermissionManager,\n requirePermission,\n requireAnyPermission,\n logActivity,\n // Plugin middleware\n requireActivePlugin,\n requireActivePlugins,\n getActivePlugins,\n isPluginActive,\n // Bootstrap\n bootstrapMiddleware,\n} from './middleware'\n\nexport type { Permission, UserPermissions } from './middleware'\n\n// Plugins - Week 2 (COMPLETED)\nexport {\n // Hook System - Class implementations\n HookSystemImpl,\n ScopedHookSystem as ScopedHookSystemClass,\n HookUtils,\n // Plugin Registry\n PluginRegistryImpl,\n // Plugin Manager - Class implementation\n PluginManager as PluginManagerClass,\n // Plugin Validator - Class implementation\n PluginValidator as PluginValidatorClass,\n} from './plugins'\n\n// Routes - Week 3 (COMPLETED)\nexport { ROUTES_INFO } from './routes'\n\n// Templates - Week 3 (COMPLETED)\nexport {\n // Form templates\n renderForm,\n renderFormField,\n // Table templates\n renderTable,\n // Pagination templates\n renderPagination,\n // Alert templates\n renderAlert,\n // Confirmation dialog templates\n renderConfirmationDialog,\n getConfirmationDialogScript,\n // Filter bar templates\n renderFilterBar,\n} from './templates'\n\nexport type {\n FormField,\n FormData,\n TableColumn,\n TableData,\n PaginationData,\n AlertData,\n ConfirmationDialogOptions,\n FilterBarData,\n Filter,\n FilterOption,\n} from './templates'\n\n// Types - Week 1 (COMPLETED)\nexport type {\n // Collection types\n FieldType,\n FieldConfig,\n CollectionSchema,\n CollectionConfig,\n CollectionConfigModule,\n CollectionSyncResult,\n // Plugin types\n Plugin,\n PluginContext,\n PluginConfig,\n PluginRoutes,\n PluginMiddleware,\n PluginModel,\n PluginService,\n PluginAdminPage,\n PluginComponent,\n PluginMenuItem,\n PluginHook,\n HookHandler,\n HookContext,\n HookSystem,\n ScopedHookSystem,\n PluginRegistry,\n PluginManager,\n PluginStatus,\n AuthService,\n ContentService,\n MediaService,\n PluginLogger,\n PluginBuilderOptions,\n PluginValidator,\n PluginValidationResult,\n HookName,\n // Plugin manifest\n PluginManifest,\n} from './types'\n\nexport { HOOKS } from './types'\n\n// Utils - Week 1 (COMPLETED)\nexport {\n // Sanitization\n escapeHtml,\n sanitizeInput,\n sanitizeObject,\n // Template rendering\n TemplateRenderer,\n templateRenderer,\n renderTemplate,\n // Query filtering\n QueryFilterBuilder,\n buildQuery,\n // Metrics\n metricsTracker,\n} from './utils'\n\nexport type {\n FilterOperator,\n FilterCondition,\n FilterGroup,\n QueryFilter,\n QueryResult,\n} from './utils'\n\n// Database - Week 1 (COMPLETED)\nexport {\n createDb,\n // Schema exports\n users,\n collections,\n content,\n contentVersions,\n media,\n apiTokens,\n workflowHistory,\n plugins,\n pluginHooks,\n pluginRoutes,\n pluginAssets,\n pluginActivityLog,\n systemLogs,\n logConfig,\n // Zod validation schemas\n insertUserSchema,\n selectUserSchema,\n insertCollectionSchema,\n selectCollectionSchema,\n insertContentSchema,\n selectContentSchema,\n insertMediaSchema,\n selectMediaSchema,\n insertWorkflowHistorySchema,\n selectWorkflowHistorySchema,\n insertPluginSchema,\n selectPluginSchema,\n insertPluginHookSchema,\n selectPluginHookSchema,\n insertPluginRouteSchema,\n selectPluginRouteSchema,\n insertPluginAssetSchema,\n selectPluginAssetSchema,\n insertPluginActivityLogSchema,\n selectPluginActivityLogSchema,\n insertSystemLogSchema,\n selectSystemLogSchema,\n insertLogConfigSchema,\n selectLogConfigSchema,\n} from './db'\n\nexport type {\n User,\n NewUser,\n Collection,\n NewCollection,\n Content,\n NewContent,\n Media,\n NewMedia,\n WorkflowHistory,\n NewWorkflowHistory,\n Plugin as DbPlugin,\n NewPlugin,\n PluginHook as DbPluginHook,\n NewPluginHook,\n PluginRoute,\n NewPluginRoute,\n PluginAsset,\n NewPluginAsset,\n PluginActivityLog,\n NewPluginActivityLog,\n SystemLog,\n NewSystemLog,\n LogConfig,\n NewLogConfig,\n} from './db'\n\n// Plugins - Week 2\n// export { PluginBuilder, HookSystem } from './plugins/sdk'\n\n// ============================================================================\n// Version\n// ============================================================================\n\nexport const VERSION = '2.0.0-alpha.3'\n\n// ============================================================================\n// Phase 2 Migration Notes\n// ============================================================================\n\n/**\n * This is a work-in-progress package being extracted from the main SonicJS codebase.\n *\n * Current Phase: 2 (Core Module Migration)\n * Current Week: 1 (Types, Utils, Database)\n *\n * Expected completion: 4 weeks from 2025-01-17\n *\n * DO NOT USE IN PRODUCTION - Alpha release for development only\n */\n"]}
|
package/dist/routes.cjs
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkB5DU2UAN_cjs = require('./chunk-B5DU2UAN.cjs');
|
|
4
|
+
require('./chunk-AGOE25LF.cjs');
|
|
5
|
+
require('./chunk-24PWAFUT.cjs');
|
|
6
|
+
require('./chunk-WJ7QYVR2.cjs');
|
|
7
|
+
require('./chunk-RGCQSFKC.cjs');
|
|
4
8
|
require('./chunk-EMMSS5I5.cjs');
|
|
5
9
|
|
|
6
10
|
|
|
7
11
|
|
|
8
12
|
Object.defineProperty(exports, "ROUTES_INFO", {
|
|
9
13
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkB5DU2UAN_cjs.ROUTES_INFO; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "adminApiRoutes", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkB5DU2UAN_cjs.admin_api_default; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "adminContentRoutes", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkB5DU2UAN_cjs.admin_content_default; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "apiContentCrudRoutes", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkB5DU2UAN_cjs.api_content_crud_default; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "apiMediaRoutes", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkB5DU2UAN_cjs.api_media_default; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "apiRoutes", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkB5DU2UAN_cjs.api_default; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "apiSystemRoutes", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkB5DU2UAN_cjs.api_system_default; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "authRoutes", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkB5DU2UAN_cjs.auth_default; }
|
|
11
43
|
});
|
|
12
44
|
//# sourceMappingURL=routes.cjs.map
|
|
13
45
|
//# sourceMappingURL=routes.cjs.map
|
package/dist/routes.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export { ROUTES_INFO } from './chunk-
|
|
1
|
+
export { ROUTES_INFO, admin_api_default as adminApiRoutes, admin_content_default as adminContentRoutes, api_content_crud_default as apiContentCrudRoutes, api_media_default as apiMediaRoutes, api_default as apiRoutes, api_system_default as apiSystemRoutes, auth_default as authRoutes } from './chunk-5XKH6PBR.js';
|
|
2
|
+
import './chunk-3MNMOLSA.js';
|
|
3
|
+
import './chunk-PTQZ5FEI.js';
|
|
4
|
+
import './chunk-CXZDAR6S.js';
|
|
5
|
+
import './chunk-JIINOD2W.js';
|
|
2
6
|
import './chunk-G3PMV62Z.js';
|
|
3
7
|
//# sourceMappingURL=routes.js.map
|
|
4
8
|
//# sourceMappingURL=routes.js.map
|
package/dist/services.cjs
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('./chunk-
|
|
3
|
+
var chunkAGOE25LF_cjs = require('./chunk-AGOE25LF.cjs');
|
|
4
4
|
var chunkWJ7QYVR2_cjs = require('./chunk-WJ7QYVR2.cjs');
|
|
5
5
|
require('./chunk-EMMSS5I5.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
Object.defineProperty(exports, "CACHE_CONFIGS", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkAGOE25LF_cjs.CACHE_CONFIGS; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "CacheService", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkAGOE25LF_cjs.CacheService; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "getCacheService", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkAGOE25LF_cjs.getCacheService; }
|
|
20
|
+
});
|
|
9
21
|
Object.defineProperty(exports, "Logger", {
|
|
10
22
|
enumerable: true,
|
|
11
23
|
get: function () { return chunkWJ7QYVR2_cjs.Logger; }
|
package/dist/services.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { CACHE_CONFIGS, CacheService, getCacheService } from './chunk-3MNMOLSA.js';
|
|
2
2
|
export { Logger, MigrationService, PluginBootstrapService, PluginService, cleanupRemovedCollections, fullCollectionSync, getAvailableCollectionNames, getLogger, getManagedCollections, initLogger, isCollectionManaged, loadCollectionConfig, loadCollectionConfigs, syncCollection, syncCollections, validateCollectionConfig } from './chunk-CXZDAR6S.js';
|
|
3
3
|
import './chunk-G3PMV62Z.js';
|
|
4
4
|
//# sourceMappingURL=services.js.map
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
-- Initial schema for SonicJS AI
|
|
2
|
+
-- Create users table for authentication
|
|
3
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
4
|
+
id TEXT PRIMARY KEY,
|
|
5
|
+
email TEXT NOT NULL UNIQUE,
|
|
6
|
+
username TEXT NOT NULL UNIQUE,
|
|
7
|
+
first_name TEXT NOT NULL,
|
|
8
|
+
last_name TEXT NOT NULL,
|
|
9
|
+
password_hash TEXT,
|
|
10
|
+
role TEXT NOT NULL DEFAULT 'viewer',
|
|
11
|
+
avatar TEXT,
|
|
12
|
+
is_active INTEGER NOT NULL DEFAULT 1,
|
|
13
|
+
last_login_at INTEGER,
|
|
14
|
+
created_at INTEGER NOT NULL,
|
|
15
|
+
updated_at INTEGER NOT NULL
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- Create collections table for content schema definitions
|
|
19
|
+
CREATE TABLE IF NOT EXISTS collections (
|
|
20
|
+
id TEXT PRIMARY KEY,
|
|
21
|
+
name TEXT NOT NULL UNIQUE,
|
|
22
|
+
display_name TEXT NOT NULL,
|
|
23
|
+
description TEXT,
|
|
24
|
+
schema TEXT NOT NULL, -- JSON schema definition
|
|
25
|
+
is_active INTEGER NOT NULL DEFAULT 1,
|
|
26
|
+
created_at INTEGER NOT NULL,
|
|
27
|
+
updated_at INTEGER NOT NULL
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- Create content table for actual content data
|
|
31
|
+
CREATE TABLE IF NOT EXISTS content (
|
|
32
|
+
id TEXT PRIMARY KEY,
|
|
33
|
+
collection_id TEXT NOT NULL REFERENCES collections(id),
|
|
34
|
+
slug TEXT NOT NULL,
|
|
35
|
+
title TEXT NOT NULL,
|
|
36
|
+
data TEXT NOT NULL, -- JSON content data
|
|
37
|
+
status TEXT NOT NULL DEFAULT 'draft',
|
|
38
|
+
published_at INTEGER,
|
|
39
|
+
author_id TEXT NOT NULL REFERENCES users(id),
|
|
40
|
+
created_at INTEGER NOT NULL,
|
|
41
|
+
updated_at INTEGER NOT NULL
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
-- Create content_versions table for versioning
|
|
45
|
+
CREATE TABLE IF NOT EXISTS content_versions (
|
|
46
|
+
id TEXT PRIMARY KEY,
|
|
47
|
+
content_id TEXT NOT NULL REFERENCES content(id),
|
|
48
|
+
version INTEGER NOT NULL,
|
|
49
|
+
data TEXT NOT NULL, -- JSON data
|
|
50
|
+
author_id TEXT NOT NULL REFERENCES users(id),
|
|
51
|
+
created_at INTEGER NOT NULL
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
-- Create media/files table with comprehensive R2 integration
|
|
55
|
+
CREATE TABLE IF NOT EXISTS media (
|
|
56
|
+
id TEXT PRIMARY KEY,
|
|
57
|
+
filename TEXT NOT NULL,
|
|
58
|
+
original_name TEXT NOT NULL,
|
|
59
|
+
mime_type TEXT NOT NULL,
|
|
60
|
+
size INTEGER NOT NULL,
|
|
61
|
+
width INTEGER,
|
|
62
|
+
height INTEGER,
|
|
63
|
+
folder TEXT NOT NULL DEFAULT 'uploads',
|
|
64
|
+
r2_key TEXT NOT NULL, -- R2 storage key
|
|
65
|
+
public_url TEXT NOT NULL, -- CDN URL
|
|
66
|
+
thumbnail_url TEXT, -- Cloudflare Images URL
|
|
67
|
+
alt TEXT,
|
|
68
|
+
caption TEXT,
|
|
69
|
+
tags TEXT, -- JSON array of tags
|
|
70
|
+
uploaded_by TEXT NOT NULL REFERENCES users(id),
|
|
71
|
+
uploaded_at INTEGER NOT NULL,
|
|
72
|
+
updated_at INTEGER,
|
|
73
|
+
published_at INTEGER,
|
|
74
|
+
scheduled_at INTEGER,
|
|
75
|
+
archived_at INTEGER,
|
|
76
|
+
deleted_at INTEGER
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
-- Create API tokens table for programmatic access
|
|
80
|
+
CREATE TABLE IF NOT EXISTS api_tokens (
|
|
81
|
+
id TEXT PRIMARY KEY,
|
|
82
|
+
name TEXT NOT NULL,
|
|
83
|
+
token TEXT NOT NULL UNIQUE,
|
|
84
|
+
user_id TEXT NOT NULL REFERENCES users(id),
|
|
85
|
+
permissions TEXT NOT NULL, -- JSON array of permissions
|
|
86
|
+
expires_at INTEGER,
|
|
87
|
+
last_used_at INTEGER,
|
|
88
|
+
created_at INTEGER NOT NULL
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
-- Create workflow history table for content workflow tracking
|
|
92
|
+
CREATE TABLE IF NOT EXISTS workflow_history (
|
|
93
|
+
id TEXT PRIMARY KEY,
|
|
94
|
+
content_id TEXT NOT NULL REFERENCES content(id),
|
|
95
|
+
action TEXT NOT NULL,
|
|
96
|
+
from_status TEXT NOT NULL,
|
|
97
|
+
to_status TEXT NOT NULL,
|
|
98
|
+
user_id TEXT NOT NULL REFERENCES users(id),
|
|
99
|
+
comment TEXT,
|
|
100
|
+
created_at INTEGER NOT NULL
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
-- Create indexes for better performance
|
|
104
|
+
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
|
105
|
+
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
|
106
|
+
CREATE INDEX IF NOT EXISTS idx_users_role ON users(role);
|
|
107
|
+
|
|
108
|
+
CREATE INDEX IF NOT EXISTS idx_collections_name ON collections(name);
|
|
109
|
+
CREATE INDEX IF NOT EXISTS idx_collections_active ON collections(is_active);
|
|
110
|
+
|
|
111
|
+
CREATE INDEX IF NOT EXISTS idx_content_collection ON content(collection_id);
|
|
112
|
+
CREATE INDEX IF NOT EXISTS idx_content_author ON content(author_id);
|
|
113
|
+
CREATE INDEX IF NOT EXISTS idx_content_status ON content(status);
|
|
114
|
+
CREATE INDEX IF NOT EXISTS idx_content_published ON content(published_at);
|
|
115
|
+
CREATE INDEX IF NOT EXISTS idx_content_slug ON content(slug);
|
|
116
|
+
|
|
117
|
+
CREATE INDEX IF NOT EXISTS idx_content_versions_content ON content_versions(content_id);
|
|
118
|
+
CREATE INDEX IF NOT EXISTS idx_content_versions_version ON content_versions(version);
|
|
119
|
+
|
|
120
|
+
CREATE INDEX IF NOT EXISTS idx_media_folder ON media(folder);
|
|
121
|
+
CREATE INDEX IF NOT EXISTS idx_media_type ON media(mime_type);
|
|
122
|
+
CREATE INDEX IF NOT EXISTS idx_media_uploaded_by ON media(uploaded_by);
|
|
123
|
+
CREATE INDEX IF NOT EXISTS idx_media_uploaded_at ON media(uploaded_at);
|
|
124
|
+
CREATE INDEX IF NOT EXISTS idx_media_deleted ON media(deleted_at);
|
|
125
|
+
|
|
126
|
+
CREATE INDEX IF NOT EXISTS idx_api_tokens_user ON api_tokens(user_id);
|
|
127
|
+
CREATE INDEX IF NOT EXISTS idx_api_tokens_token ON api_tokens(token);
|
|
128
|
+
|
|
129
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_history_content ON workflow_history(content_id);
|
|
130
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_history_user ON workflow_history(user_id);
|
|
131
|
+
|
|
132
|
+
-- Insert default admin user (password: admin123)
|
|
133
|
+
INSERT OR IGNORE INTO users (
|
|
134
|
+
id, email, username, first_name, last_name, password_hash,
|
|
135
|
+
role, is_active, created_at, updated_at
|
|
136
|
+
) VALUES (
|
|
137
|
+
'admin-user-id',
|
|
138
|
+
'admin@sonicjs.com',
|
|
139
|
+
'admin',
|
|
140
|
+
'Admin',
|
|
141
|
+
'User',
|
|
142
|
+
'd1c379e871838f44e21d5a55841349e50636f06df139bfef11870eec74c381db', -- SHA-256 hash of 'admin123'
|
|
143
|
+
'admin',
|
|
144
|
+
1,
|
|
145
|
+
strftime('%s', 'now') * 1000,
|
|
146
|
+
strftime('%s', 'now') * 1000
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
-- Insert sample collections
|
|
150
|
+
INSERT OR IGNORE INTO collections (
|
|
151
|
+
id, name, display_name, description, schema,
|
|
152
|
+
is_active, created_at, updated_at
|
|
153
|
+
) VALUES (
|
|
154
|
+
'blog-posts-collection',
|
|
155
|
+
'blog_posts',
|
|
156
|
+
'Blog Posts',
|
|
157
|
+
'Blog post content collection',
|
|
158
|
+
'{"type":"object","properties":{"title":{"type":"string","title":"Title","required":true},"content":{"type":"string","title":"Content","format":"richtext"},"excerpt":{"type":"string","title":"Excerpt"},"featured_image":{"type":"string","title":"Featured Image","format":"media"},"tags":{"type":"array","title":"Tags","items":{"type":"string"}},"status":{"type":"string","title":"Status","enum":["draft","published","archived"],"default":"draft"}},"required":["title"]}',
|
|
159
|
+
1,
|
|
160
|
+
strftime('%s', 'now') * 1000,
|
|
161
|
+
strftime('%s', 'now') * 1000
|
|
162
|
+
),
|
|
163
|
+
(
|
|
164
|
+
'pages-collection',
|
|
165
|
+
'pages',
|
|
166
|
+
'Pages',
|
|
167
|
+
'Static page content collection',
|
|
168
|
+
'{"type":"object","properties":{"title":{"type":"string","title":"Title","required":true},"content":{"type":"string","title":"Content","format":"richtext"},"slug":{"type":"string","title":"Slug"},"meta_description":{"type":"string","title":"Meta Description"},"featured_image":{"type":"string","title":"Featured Image","format":"media"}},"required":["title"]}',
|
|
169
|
+
1,
|
|
170
|
+
strftime('%s', 'now') * 1000,
|
|
171
|
+
strftime('%s', 'now') * 1000
|
|
172
|
+
),
|
|
173
|
+
(
|
|
174
|
+
'news-collection',
|
|
175
|
+
'news',
|
|
176
|
+
'News',
|
|
177
|
+
'News article content collection',
|
|
178
|
+
'{"type":"object","properties":{"title":{"type":"string","title":"Title","required":true},"content":{"type":"string","title":"Content","format":"richtext"},"publish_date":{"type":"string","title":"Publish Date","format":"date"},"author":{"type":"string","title":"Author"},"category":{"type":"string","title":"Category","enum":["technology","business","general"]}},"required":["title"]}',
|
|
179
|
+
1,
|
|
180
|
+
strftime('%s', 'now') * 1000,
|
|
181
|
+
strftime('%s', 'now') * 1000
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
-- Insert sample content
|
|
185
|
+
INSERT OR IGNORE INTO content (
|
|
186
|
+
id, collection_id, slug, title, data, status,
|
|
187
|
+
author_id, created_at, updated_at
|
|
188
|
+
) VALUES (
|
|
189
|
+
'welcome-blog-post',
|
|
190
|
+
'blog-posts-collection',
|
|
191
|
+
'welcome-to-sonicjs-ai',
|
|
192
|
+
'Welcome to SonicJS AI',
|
|
193
|
+
'{"title":"Welcome to SonicJS AI","content":"<h1>Welcome to SonicJS AI</h1><p>This is your first blog post created with SonicJS AI, a modern headless CMS built on Cloudflare Workers.</p><h2>Features</h2><ul><li>Cloudflare-native architecture</li><li>TypeScript-first development</li><li>Hono.js framework</li><li>D1 database</li><li>R2 media storage</li><li>Edge computing</li></ul><p>Get started by exploring the admin interface and creating your own content!</p>","excerpt":"Welcome to SonicJS AI, a modern headless CMS built on Cloudflare Workers with TypeScript and Hono.js.","status":"published","tags":["welcome","cms","cloudflare"]}',
|
|
194
|
+
'published',
|
|
195
|
+
'admin-user-id',
|
|
196
|
+
strftime('%s', 'now') * 1000,
|
|
197
|
+
strftime('%s', 'now') * 1000
|
|
198
|
+
);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
-- FAQ Plugin Migration (DEPRECATED - Now managed by third-party plugin)
|
|
2
|
+
-- Creates FAQ table for the FAQ plugin
|
|
3
|
+
-- NOTE: This migration is kept for historical purposes.
|
|
4
|
+
-- The FAQ functionality is now provided by the faq-plugin third-party plugin.
|
|
5
|
+
|
|
6
|
+
CREATE TABLE IF NOT EXISTS faqs (
|
|
7
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
8
|
+
question TEXT NOT NULL,
|
|
9
|
+
answer TEXT NOT NULL,
|
|
10
|
+
category TEXT,
|
|
11
|
+
tags TEXT,
|
|
12
|
+
isPublished INTEGER NOT NULL DEFAULT 1,
|
|
13
|
+
sortOrder INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
15
|
+
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- Create indexes for better performance
|
|
19
|
+
CREATE INDEX IF NOT EXISTS idx_faqs_category ON faqs(category);
|
|
20
|
+
CREATE INDEX IF NOT EXISTS idx_faqs_published ON faqs(isPublished);
|
|
21
|
+
CREATE INDEX IF NOT EXISTS idx_faqs_sort_order ON faqs(sortOrder);
|
|
22
|
+
|
|
23
|
+
-- Create trigger to update updated_at timestamp
|
|
24
|
+
CREATE TRIGGER IF NOT EXISTS faqs_updated_at
|
|
25
|
+
AFTER UPDATE ON faqs
|
|
26
|
+
BEGIN
|
|
27
|
+
UPDATE faqs SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;
|
|
28
|
+
END;
|
|
29
|
+
|
|
30
|
+
-- Insert sample FAQ data
|
|
31
|
+
INSERT OR IGNORE INTO faqs (question, answer, category, tags, isPublished, sortOrder) VALUES
|
|
32
|
+
('What is SonicJS AI?',
|
|
33
|
+
'SonicJS AI is a modern, TypeScript-first headless CMS built for Cloudflare''s edge platform. It provides a complete content management system with admin interface, API endpoints, and plugin architecture.',
|
|
34
|
+
'general',
|
|
35
|
+
'sonicjs, cms, cloudflare',
|
|
36
|
+
1,
|
|
37
|
+
1),
|
|
38
|
+
|
|
39
|
+
('How do I get started with SonicJS AI?',
|
|
40
|
+
'To get started: 1) Clone the repository, 2) Install dependencies with npm install, 3) Set up your Cloudflare account and services, 4) Run the development server with npm run dev, 5) Access the admin interface at /admin.',
|
|
41
|
+
'general',
|
|
42
|
+
'getting-started, setup',
|
|
43
|
+
1,
|
|
44
|
+
2),
|
|
45
|
+
|
|
46
|
+
('What technologies does SonicJS AI use?',
|
|
47
|
+
'SonicJS AI is built with: TypeScript for type safety, Hono.js as the web framework, Cloudflare D1 for the database, Cloudflare R2 for media storage, Cloudflare Workers for serverless execution, and Tailwind CSS for styling.',
|
|
48
|
+
'technical',
|
|
49
|
+
'technology-stack, typescript, cloudflare',
|
|
50
|
+
1,
|
|
51
|
+
3),
|
|
52
|
+
|
|
53
|
+
('How do I create content in SonicJS AI?',
|
|
54
|
+
'Content creation is done through the admin interface. Navigate to /admin, log in with your credentials, go to Content section, select a collection, and click "New Content" to create articles, pages, or other content types.',
|
|
55
|
+
'general',
|
|
56
|
+
'content-creation, admin',
|
|
57
|
+
1,
|
|
58
|
+
4),
|
|
59
|
+
|
|
60
|
+
('Is SonicJS AI free to use?',
|
|
61
|
+
'SonicJS AI is open source and free to use. You only pay for the Cloudflare services you consume (D1 database, R2 storage, Workers execution time). Cloudflare offers generous free tiers for development and small projects.',
|
|
62
|
+
'billing',
|
|
63
|
+
'pricing, open-source, cloudflare',
|
|
64
|
+
1,
|
|
65
|
+
5),
|
|
66
|
+
|
|
67
|
+
('How do I add custom functionality?',
|
|
68
|
+
'SonicJS AI features a plugin system that allows you to extend functionality. You can create plugins using the PluginBuilder API, add custom routes, models, admin pages, and integrate with external services.',
|
|
69
|
+
'technical',
|
|
70
|
+
'plugins, customization, development',
|
|
71
|
+
1,
|
|
72
|
+
6),
|
|
73
|
+
|
|
74
|
+
('Can I customize the admin interface?',
|
|
75
|
+
'Yes! The admin interface is built with TypeScript templates and can be customized. You can modify existing templates, create new components, add custom pages, and integrate your own styling while maintaining the dark theme.',
|
|
76
|
+
'technical',
|
|
77
|
+
'admin-interface, customization, templates',
|
|
78
|
+
1,
|
|
79
|
+
7),
|
|
80
|
+
|
|
81
|
+
('How does authentication work?',
|
|
82
|
+
'SonicJS AI includes a built-in authentication system with JWT tokens, role-based access control (admin, editor, viewer), secure password hashing, and session management. Users can be managed through the admin interface.',
|
|
83
|
+
'technical',
|
|
84
|
+
'authentication, security, users',
|
|
85
|
+
1,
|
|
86
|
+
8);
|