@aphexcms/cms-core 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/package.json +22 -5
  2. package/src/api/assets.ts +0 -75
  3. package/src/api/client.ts +0 -150
  4. package/src/api/documents.ts +0 -102
  5. package/src/api/index.ts +0 -7
  6. package/src/api/organizations.ts +0 -154
  7. package/src/api/types.ts +0 -34
  8. package/src/app.d.ts +0 -19
  9. package/src/auth/MULTI_TENANCY_PLAN.md +0 -1183
  10. package/src/auth/auth-errors.ts +0 -23
  11. package/src/auth/auth-hooks.ts +0 -132
  12. package/src/auth/provider.ts +0 -25
  13. package/src/client/index.ts +0 -47
  14. package/src/components/AdminApp.svelte +0 -1078
  15. package/src/components/admin/AdminLayout.svelte +0 -115
  16. package/src/components/admin/DocumentEditor.svelte +0 -795
  17. package/src/components/admin/DocumentTypesList.svelte +0 -97
  18. package/src/components/admin/ObjectModal.svelte +0 -135
  19. package/src/components/admin/SchemaField.svelte +0 -171
  20. package/src/components/admin/fields/ArrayField.svelte +0 -266
  21. package/src/components/admin/fields/BooleanField.svelte +0 -35
  22. package/src/components/admin/fields/ImageField.svelte +0 -284
  23. package/src/components/admin/fields/NumberField.svelte +0 -82
  24. package/src/components/admin/fields/ReferenceField.svelte +0 -260
  25. package/src/components/admin/fields/SlugField.svelte +0 -74
  26. package/src/components/admin/fields/StringField.svelte +0 -40
  27. package/src/components/admin/fields/TextareaField.svelte +0 -40
  28. package/src/components/fields/index.ts +0 -9
  29. package/src/components/index.ts +0 -16
  30. package/src/components/layout/OrganizationSwitcher.svelte +0 -218
  31. package/src/components/layout/Sidebar.svelte +0 -88
  32. package/src/components/layout/sidebar/AppSidebar.svelte +0 -63
  33. package/src/components/layout/sidebar/NavMain.svelte +0 -95
  34. package/src/components/layout/sidebar/NavSecondary.svelte +0 -69
  35. package/src/components/layout/sidebar/NavUser.svelte +0 -85
  36. package/src/config.ts +0 -18
  37. package/src/db/adapters/index.ts +0 -3
  38. package/src/db/index.ts +0 -5
  39. package/src/db/interfaces/asset.ts +0 -61
  40. package/src/db/interfaces/document.ts +0 -53
  41. package/src/db/interfaces/index.ts +0 -98
  42. package/src/db/interfaces/organization.ts +0 -51
  43. package/src/db/interfaces/schema.ts +0 -13
  44. package/src/db/interfaces/user.ts +0 -16
  45. package/src/db/utils/reference-resolver.ts +0 -119
  46. package/src/define.ts +0 -7
  47. package/src/email/index.ts +0 -5
  48. package/src/email/interfaces/email.ts +0 -45
  49. package/src/engine.ts +0 -85
  50. package/src/field-validation/rule.ts +0 -287
  51. package/src/field-validation/utils.ts +0 -91
  52. package/src/hooks.ts +0 -142
  53. package/src/index.ts +0 -5
  54. package/src/lib/is-mobile.svelte.ts +0 -9
  55. package/src/lib/utils.ts +0 -13
  56. package/src/plugins/README.md +0 -154
  57. package/src/routes/assets-by-id.ts +0 -161
  58. package/src/routes/assets-cdn.ts +0 -185
  59. package/src/routes/assets.ts +0 -116
  60. package/src/routes/documents-by-id.ts +0 -188
  61. package/src/routes/documents-publish.ts +0 -211
  62. package/src/routes/documents.ts +0 -172
  63. package/src/routes/index.ts +0 -13
  64. package/src/routes/organizations-by-id.ts +0 -258
  65. package/src/routes/organizations-invitations.ts +0 -183
  66. package/src/routes/organizations-members.ts +0 -301
  67. package/src/routes/organizations-switch.ts +0 -74
  68. package/src/routes/organizations.ts +0 -146
  69. package/src/routes/schemas-by-type.ts +0 -35
  70. package/src/routes/schemas.ts +0 -19
  71. package/src/routes-exports.ts +0 -42
  72. package/src/schema-context.svelte.ts +0 -24
  73. package/src/schema-utils/cleanup.ts +0 -116
  74. package/src/schema-utils/index.ts +0 -4
  75. package/src/schema-utils/utils.ts +0 -47
  76. package/src/schema-utils/validator.ts +0 -58
  77. package/src/server/index.ts +0 -40
  78. package/src/services/asset-service.ts +0 -256
  79. package/src/services/index.ts +0 -6
  80. package/src/storage/adapters/index.ts +0 -2
  81. package/src/storage/adapters/local-storage-adapter.ts +0 -215
  82. package/src/storage/index.ts +0 -8
  83. package/src/storage/interfaces/index.ts +0 -2
  84. package/src/storage/interfaces/storage.ts +0 -114
  85. package/src/storage/providers/storage.ts +0 -83
  86. package/src/types/asset.ts +0 -81
  87. package/src/types/auth.ts +0 -80
  88. package/src/types/config.ts +0 -45
  89. package/src/types/document.ts +0 -38
  90. package/src/types/index.ts +0 -8
  91. package/src/types/organization.ts +0 -119
  92. package/src/types/schemas.ts +0 -151
  93. package/src/types/sidebar.ts +0 -37
  94. package/src/types/user.ts +0 -17
  95. package/src/utils/content-hash.ts +0 -75
  96. package/src/utils/image-url.ts +0 -204
  97. package/src/utils/index.ts +0 -12
  98. package/src/utils/slug.ts +0 -33
@@ -1,85 +0,0 @@
1
- <script lang="ts">
2
- import { goto } from '$app/navigation';
3
- import {
4
- SidebarMenu,
5
- SidebarMenuItem,
6
- SidebarMenuButton,
7
- useSidebar
8
- } from '@aphexcms/ui/shadcn/sidebar';
9
- import {
10
- DropdownMenu,
11
- DropdownMenuContent,
12
- DropdownMenuItem,
13
- DropdownMenuSeparator,
14
- DropdownMenuTrigger
15
- } from '@aphexcms/ui/shadcn/dropdown-menu';
16
- import { ChevronsUpDown, Settings, LogOut } from 'lucide-svelte';
17
- import type { AuthUser } from '../../../types/user.js';
18
-
19
- type Props = {
20
- user: AuthUser;
21
- onSignOut?: () => void | Promise<void>;
22
- };
23
-
24
- let { user, onSignOut }: Props = $props();
25
-
26
- const sidebar = useSidebar();
27
-
28
- async function handleSignOut() {
29
- if (onSignOut) {
30
- await onSignOut();
31
- }
32
- }
33
- </script>
34
-
35
- <SidebarMenu>
36
- <SidebarMenuItem>
37
- <DropdownMenu>
38
- <DropdownMenuTrigger>
39
- {#snippet child({ props })}
40
- <SidebarMenuButton
41
- {...props}
42
- size="lg"
43
- class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
44
- >
45
- {#if user.image}
46
- <img src={user.image} alt={user.name || user.email} class="h-8 w-8 rounded-lg" />
47
- {:else}
48
- <div
49
- class="bg-sidebar-primary text-sidebar-primary-foreground flex h-8 w-8 items-center justify-center rounded-lg text-sm font-semibold"
50
- >
51
- {user.name?.[0]?.toUpperCase() || user.email[0].toUpperCase()}
52
- </div>
53
- {/if}
54
- <div class="grid flex-1 text-left text-sm leading-tight">
55
- <span class="truncate font-medium">{user.name || user.email}</span>
56
- <span class="text-muted-foreground truncate text-xs">{user.email}</span>
57
- </div>
58
- <ChevronsUpDown class="ml-auto size-4" />
59
- </SidebarMenuButton>
60
- {/snippet}
61
- </DropdownMenuTrigger>
62
- <DropdownMenuContent
63
- class="w-[--bits-dropdown-menu-anchor-width] min-w-56 rounded-lg"
64
- side={sidebar.isMobile ? 'bottom' : 'right'}
65
- align="end"
66
- sideOffset={4}
67
- >
68
- <div class="px-2 py-1.5 text-sm">
69
- <p class="font-medium">{user.name || 'User'}</p>
70
- <p class="text-muted-foreground text-xs">{user.email}</p>
71
- </div>
72
- <DropdownMenuSeparator />
73
- <DropdownMenuItem onclick={() => goto('/admin/settings')}>
74
- <Settings class="mr-2 h-4 w-4" />
75
- <span>Account Settings</span>
76
- </DropdownMenuItem>
77
- <DropdownMenuSeparator />
78
- <DropdownMenuItem class="text-destructive" onclick={handleSignOut}>
79
- <LogOut class="mr-2 h-4 w-4" />
80
- <span>Sign Out</span>
81
- </DropdownMenuItem>
82
- </DropdownMenuContent>
83
- </DropdownMenu>
84
- </SidebarMenuItem>
85
- </SidebarMenu>
package/src/config.ts DELETED
@@ -1,18 +0,0 @@
1
- // Aphex CMS Configuration System
2
- import type { CMSConfig } from './types/index.js';
3
-
4
- export function createCMSConfig(config: CMSConfig): CMSConfig {
5
- return {
6
- // Start with the user's config and apply defaults for missing properties
7
- ...config,
8
- storage: config.storage ?? null, // Default to null if not provided
9
- customization: {
10
- branding: {
11
- title: 'Aphex CMS',
12
- ...config.customization?.branding
13
- },
14
- ...config.customization
15
- },
16
- plugins: config.plugins ?? []
17
- };
18
- }
@@ -1,3 +0,0 @@
1
- // Database adapters are now in separate packages
2
- // e.g., @aphexcms/postgresql-adapter, @aphexcms/mongodb-adapter
3
- // This file is kept for backwards compatibility but exports nothing - and potentially default adapters or something. maybe sqlite?
package/src/db/index.ts DELETED
@@ -1,5 +0,0 @@
1
- // Aphex CMS Database Layer
2
- // Ports and adapters for database operations
3
-
4
- // Interfaces
5
- export * from './interfaces/index.js';
@@ -1,61 +0,0 @@
1
- // Asset interface for asset operations
2
- import type { Asset } from '../../types/index.js';
3
-
4
- export interface AssetFilters {
5
- organizationId: string; // Required for multi-tenancy (user's current org for RLS context)
6
- assetType?: 'image' | 'file';
7
- mimeType?: string;
8
- search?: string;
9
- limit?: number;
10
- offset?: number;
11
- filterOrganizationIds?: string[]; // Optional: Filter to specific org(s). RLS still enforces access.
12
- }
13
-
14
- export interface CreateAssetData {
15
- organizationId: string; // Required for multi-tenancy
16
- assetType: 'image' | 'file';
17
- filename: string;
18
- originalFilename: string;
19
- mimeType: string;
20
- size: number;
21
- url: string;
22
- path: string;
23
- storageAdapter: string; // Which storage adapter was used
24
- width?: number;
25
- height?: number;
26
- metadata?: any;
27
- title?: string;
28
- description?: string;
29
- alt?: string;
30
- creditLine?: string;
31
- createdBy?: string; // User ID (optional for backward compatibility)
32
- }
33
-
34
- export interface UpdateAssetData {
35
- url?: string; // Allow updating URL (for local storage after asset creation)
36
- title?: string;
37
- description?: string;
38
- alt?: string;
39
- creditLine?: string;
40
- updatedBy?: string; // User ID (optional for backward compatibility)
41
- }
42
-
43
- /**
44
- * Asset adapter interface for asset-specific operations
45
- */
46
- export interface AssetAdapter {
47
- // Asset CRUD operations
48
- createAsset(data: CreateAssetData): Promise<Asset>;
49
- findAssetById(organizationId: string, id: string): Promise<Asset | null>;
50
- findAssets(
51
- organizationId: string,
52
- filters?: Omit<AssetFilters, 'organizationId'>
53
- ): Promise<Asset[]>;
54
- updateAsset(organizationId: string, id: string, data: UpdateAssetData): Promise<Asset | null>;
55
- deleteAsset(organizationId: string, id: string): Promise<boolean>;
56
-
57
- // Asset analytics
58
- countAssets(organizationId: string): Promise<number>;
59
- countAssetsByType(organizationId: string): Promise<Record<string, number>>;
60
- getTotalAssetsSize(organizationId: string): Promise<number>;
61
- }
@@ -1,53 +0,0 @@
1
- // Document interface for document operations
2
- import type { Document } from '../../types/index.js';
3
-
4
- export interface DocumentFilters {
5
- organizationId: string; // Required for multi-tenancy (user's current org for RLS context)
6
- type?: string;
7
- status?: string;
8
- limit?: number;
9
- offset?: number;
10
- depth?: number; // How deep to resolve nested references (0 = no resolution, default = 0)
11
- filterOrganizationIds?: string[]; // Optional: Filter to specific org(s). RLS still enforces access.
12
- }
13
-
14
- export interface CreateDocumentData {
15
- organizationId: string; // Required for multi-tenancy
16
- type: string;
17
- draftData: any;
18
- createdBy?: string; // User ID (optional for backward compatibility)
19
- }
20
-
21
- export interface UpdateDocumentData {
22
- draftData?: any;
23
- status?: string;
24
- updatedBy?: string; // User ID (optional for backward compatibility)
25
- }
26
-
27
- /**
28
- * Document adapter interface for document-specific operations
29
- */
30
- export interface DocumentAdapter {
31
- // Document CRUD operations
32
- findManyDoc(
33
- organizationId: string,
34
- filters?: Omit<DocumentFilters, 'organizationId'>
35
- ): Promise<Document[]>;
36
- findByDocId(organizationId: string, id: string, depth?: number): Promise<Document | null>;
37
- createDocument(data: CreateDocumentData): Promise<Document>;
38
- updateDocDraft(
39
- organizationId: string,
40
- id: string,
41
- data: any,
42
- updatedBy?: string
43
- ): Promise<Document | null>;
44
- deleteDocById(organizationId: string, id: string): Promise<boolean>;
45
-
46
- // Publishing operations
47
- publishDoc(organizationId: string, id: string): Promise<Document | null>;
48
- unpublishDoc(organizationId: string, id: string): Promise<Document | null>;
49
-
50
- // Analytics/counts
51
- countDocsByType(organizationId: string, type: string): Promise<number>;
52
- getDocCountsByType(organizationId: string): Promise<Record<string, number>>;
53
- }
@@ -1,98 +0,0 @@
1
- // Combined database interface
2
- import type { DocumentAdapter } from './document.js';
3
- import type { AssetAdapter } from './asset.js';
4
- import type { UserProfileAdapter } from './user.js';
5
- import type { SchemaAdapter } from './schema.js';
6
- import type { OrganizationAdapter } from './organization.js';
7
-
8
- // Re-export individual interfaces
9
- export type {
10
- DocumentAdapter,
11
- DocumentFilters,
12
- CreateDocumentData,
13
- UpdateDocumentData
14
- } from './document.js';
15
- export type { AssetAdapter, CreateAssetData, UpdateAssetData } from './asset.js';
16
- export type { UserProfileAdapter, NewUserProfileData } from './user.js';
17
- export type { SchemaAdapter } from './schema.js';
18
- export type { OrganizationAdapter } from './organization.js';
19
-
20
- /**
21
- * Combined database adapter interface
22
- * Extends all entity-specific adapters for full database functionality
23
- */
24
- export interface DatabaseAdapter
25
- extends DocumentAdapter,
26
- AssetAdapter,
27
- UserProfileAdapter,
28
- SchemaAdapter,
29
- OrganizationAdapter {
30
- // Connection management
31
- connect?(): Promise<void>;
32
- disconnect?(): Promise<void>;
33
-
34
- // Health check
35
- isHealthy(): Promise<boolean>;
36
-
37
- // Multi-tenancy RLS methods (optional - only for adapters that support RLS)
38
- /**
39
- * Initialize RLS (enable/disable) on tables - call after migrations
40
- */
41
- initializeRLS?(): Promise<void>;
42
-
43
- /**
44
- * Execute a function within a transaction with organization context set for RLS
45
- * Ensures proper isolation with connection pooling
46
- */
47
- withOrgContext?<T>(organizationId: string, fn: () => Promise<T>): Promise<T>;
48
-
49
- /**
50
- * Get all child organizations for a parent (for hierarchy support)
51
- */
52
- getChildOrganizations?(parentOrganizationId: string): Promise<string[]>;
53
-
54
- /**
55
- * Check if any user profiles exist in the system (for first-user detection)
56
- */
57
- hasAnyUserProfiles?(): Promise<boolean>;
58
- }
59
-
60
- /**
61
- * Database provider factory interface
62
- * Providers are pre-configured and create adapters on demand
63
- */
64
- export interface DatabaseProvider {
65
- name: string;
66
- createAdapter(): DatabaseAdapter;
67
- }
68
-
69
- /**
70
- * Generic database configuration
71
- */
72
- export interface DatabaseConfig {
73
- connectionString?: string; // Optional if client is provided
74
- client?: any; // Pre-initialized database client (recommended for database agnosticism)
75
- options?: {
76
- maxConnections?: number;
77
- timeout?: number;
78
- ssl?: boolean;
79
- [key: string]: any;
80
- };
81
- }
82
-
83
- /**
84
- * Database transaction interface (optional for advanced providers)
85
- */
86
- export interface DatabaseTransaction {
87
- commit(): Promise<void>;
88
- rollback(): Promise<void>;
89
- isActive(): boolean;
90
- }
91
-
92
- /**
93
- * Extended database adapter with transaction support
94
- */
95
- export interface TransactionalDatabaseAdapter extends DatabaseAdapter {
96
- beginTransaction(): Promise<DatabaseTransaction>;
97
- withTransaction<T>(fn: (adapter: DatabaseAdapter) => Promise<T>): Promise<T>;
98
- }
@@ -1,51 +0,0 @@
1
- // Organization adapter interface for multi-tenancy operations
2
- import type {
3
- Organization,
4
- NewOrganization,
5
- OrganizationMember,
6
- NewOrganizationMember,
7
- Invitation,
8
- NewInvitation,
9
- UserSession,
10
- OrganizationMembership
11
- } from '../../types/organization.js';
12
-
13
- export interface OrganizationAdapter {
14
- // Organization CRUD
15
- createOrganization(data: NewOrganization): Promise<Organization>;
16
- findOrganizationById(id: string): Promise<Organization | null>;
17
- findOrganizationBySlug(slug: string): Promise<Organization | null>;
18
- updateOrganization(
19
- id: string,
20
- data: Partial<Omit<Organization, 'id' | 'createdAt' | 'createdBy'>>
21
- ): Promise<Organization | null>;
22
- deleteOrganization(id: string): Promise<boolean>;
23
-
24
- // Member management
25
- addMember(data: NewOrganizationMember): Promise<OrganizationMember>;
26
- removeMember(organizationId: string, userId: string): Promise<boolean>;
27
- removeAllMembers(organizationId: string): Promise<boolean>;
28
- updateMemberRole(
29
- organizationId: string,
30
- userId: string,
31
- role: 'owner' | 'admin' | 'editor' | 'viewer'
32
- ): Promise<OrganizationMember | null>;
33
- findUserMembership(userId: string, organizationId: string): Promise<OrganizationMember | null>;
34
- findUserOrganizations(userId: string): Promise<OrganizationMembership[]>;
35
- findOrganizationMembers(organizationId: string): Promise<OrganizationMember[]>;
36
-
37
- // Invitation management
38
- createInvitation(data: NewInvitation): Promise<Invitation>;
39
- findInvitationByToken(token: string): Promise<Invitation | null>;
40
- findOrganizationInvitations(organizationId: string): Promise<Invitation[]>;
41
- findInvitationsByEmail(email: string): Promise<Invitation[]>;
42
- acceptInvitation(token: string, userId: string): Promise<OrganizationMember>;
43
- deleteInvitation(id: string): Promise<boolean>;
44
- removeAllInvitations(organizationId: string): Promise<boolean>;
45
- cleanupExpiredInvitations(): Promise<number>;
46
-
47
- // User session management
48
- updateUserSession(userId: string, organizationId: string): Promise<void>;
49
- findUserSession(userId: string): Promise<UserSession | null>;
50
- deleteUserSession(userId: string): Promise<boolean>;
51
- }
@@ -1,13 +0,0 @@
1
- import type { SchemaType } from '../../types/index.js';
2
-
3
- /**
4
- * Defines database operations for managing schemas.
5
- */
6
- export interface SchemaAdapter {
7
- registerSchemaType(schemaType: SchemaType): Promise<void>;
8
- getSchemaType(name: string): Promise<SchemaType | null>;
9
- listSchemas(): Promise<SchemaType[]>;
10
- listDocumentTypes(): Promise<Array<{ name: string; title: string; description?: string }>>;
11
- listObjectTypes(): Promise<Array<{ name: string; title: string; description?: string }>>;
12
- deleteSchemaType(name: string): Promise<void>;
13
- }
@@ -1,16 +0,0 @@
1
- import type { UserProfile } from '../../types/index.js';
2
-
3
- export interface NewUserProfileData {
4
- userId: string;
5
- role?: 'super_admin' | 'admin' | 'editor' | 'viewer';
6
- preferences?: Record<string, any>;
7
- }
8
-
9
- /**
10
- * Defines database operations for managing user profiles.
11
- */
12
- export interface UserProfileAdapter {
13
- createUserProfile(data: NewUserProfileData): Promise<UserProfile>;
14
- findUserProfileById(userId: string): Promise<UserProfile | null>;
15
- deleteUserProfile(userId: string): Promise<boolean>;
16
- }
@@ -1,119 +0,0 @@
1
- // Reference resolution utility for resolving nested document references
2
- import type { Document } from '../../types/index.js';
3
- import type { DocumentAdapter } from '../interfaces/document.js';
4
-
5
- interface ResolveOptions {
6
- depth: number;
7
- currentDepth?: number;
8
- visited?: Set<string>; // Track visited documents to prevent circular references
9
- }
10
-
11
- /**
12
- * Recursively resolves reference fields in a document
13
- * @param document - The document to resolve references for
14
- * @param adapter - Document adapter for fetching referenced documents
15
- * @param organizationId - Organization ID for filtering referenced documents
16
- * @param options - Resolution options (depth, tracking)
17
- * @returns Document with resolved references
18
- */
19
- export async function resolveReferences(
20
- document: Document,
21
- adapter: DocumentAdapter,
22
- organizationId: string,
23
- options: ResolveOptions
24
- ): Promise<Document> {
25
- const { depth, currentDepth = 0, visited = new Set() } = options;
26
-
27
- // Base case: no more depth to resolve or already visited (circular reference)
28
- if (currentDepth >= depth || visited.has(document.id)) {
29
- return document;
30
- }
31
-
32
- // Mark as visited
33
- visited.add(document.id);
34
-
35
- // Clone the document to avoid mutations
36
- const resolvedDocument = { ...document };
37
-
38
- // Resolve references in draftData
39
- if (document.draftData) {
40
- resolvedDocument.draftData = await resolveDataReferences(
41
- document.draftData,
42
- adapter,
43
- organizationId,
44
- {
45
- depth,
46
- currentDepth: currentDepth + 1,
47
- visited
48
- }
49
- );
50
- }
51
-
52
- // Resolve references in publishedData
53
- if (document.publishedData) {
54
- resolvedDocument.publishedData = await resolveDataReferences(
55
- document.publishedData,
56
- adapter,
57
- organizationId,
58
- {
59
- depth,
60
- currentDepth: currentDepth + 1,
61
- visited
62
- }
63
- );
64
- }
65
-
66
- return resolvedDocument;
67
- }
68
-
69
- /**
70
- * Resolves references within document data (recursive)
71
- */
72
- async function resolveDataReferences(
73
- data: any,
74
- adapter: DocumentAdapter,
75
- organizationId: string,
76
- options: ResolveOptions
77
- ): Promise<any> {
78
- if (!data || typeof data !== 'object') {
79
- return data;
80
- }
81
-
82
- // Handle arrays
83
- if (Array.isArray(data)) {
84
- return Promise.all(
85
- data.map((item) => resolveDataReferences(item, adapter, organizationId, options))
86
- );
87
- }
88
-
89
- // Clone object
90
- const resolved: any = {};
91
-
92
- for (const [key, value] of Object.entries(data)) {
93
- // Check if this looks like a reference field (string ID)
94
- if (typeof value === 'string' && key !== '_type' && key !== '_key') {
95
- // Try to fetch the referenced document
96
- try {
97
- const referencedDoc = await adapter.findByDocId(organizationId, value);
98
- if (referencedDoc) {
99
- // Recursively resolve nested references
100
- resolved[key] = await resolveReferences(referencedDoc, adapter, organizationId, options);
101
- } else {
102
- // Reference not found, keep the ID
103
- resolved[key] = value;
104
- }
105
- } catch (error) {
106
- // On error, keep the original value
107
- resolved[key] = value;
108
- }
109
- } else if (value && typeof value === 'object') {
110
- // Recursively resolve nested objects/arrays
111
- resolved[key] = await resolveDataReferences(value, adapter, organizationId, options);
112
- } else {
113
- // Primitive value, keep as is
114
- resolved[key] = value;
115
- }
116
- }
117
-
118
- return resolved;
119
- }
package/src/define.ts DELETED
@@ -1,7 +0,0 @@
1
- // CMS configuration helper
2
- import type { CMSConfig } from './types/index.js';
3
-
4
- // CMS config helper
5
- export function defineCMSConfig(config: CMSConfig): CMSConfig {
6
- return config;
7
- }
@@ -1,5 +0,0 @@
1
- // Aphex CMS Email Layer
2
- // Ports and adapters for email sending operations
3
-
4
- // Interfaces
5
- export * from './interfaces/email.js';
@@ -1,45 +0,0 @@
1
- export interface EmailAddress {
2
- email: string;
3
- name?: string;
4
- }
5
-
6
- export interface SendEmailOptions {
7
- from: string;
8
- to: string | string[];
9
- subject: string;
10
- html?: string;
11
- text?: string;
12
- cc?: string | string[];
13
- bcc?: string | string[];
14
- replyTo?: string;
15
- tags?: Array<{ name: string; value: string }>;
16
- attachments?: Array<{
17
- filename: string;
18
- content: Buffer | string;
19
- }>;
20
- }
21
-
22
- export interface SendEmailResult {
23
- id: string;
24
- error?: string;
25
- }
26
-
27
- export interface EmailAdapter {
28
- readonly name: string;
29
-
30
- send(options: SendEmailOptions): Promise<SendEmailResult>;
31
-
32
- sendBatch?(emails: SendEmailOptions[]): Promise<SendEmailResult[]>;
33
- }
34
-
35
- export interface EmailProvider {
36
- name: string;
37
- createAdapter(config: EmailConfig): EmailAdapter;
38
- }
39
-
40
- export interface EmailConfig {
41
- apiKey?: string;
42
- options?: {
43
- [key: string]: any;
44
- };
45
- }
package/src/engine.ts DELETED
@@ -1,85 +0,0 @@
1
- import type { CMSConfig } from './types/config.js';
2
- import type { SchemaType } from './types/schemas.js';
3
- import type { DatabaseAdapter } from './db/interfaces/index.js';
4
-
5
- export class CMSEngine {
6
- private db: DatabaseAdapter;
7
- public config: CMSConfig;
8
-
9
- constructor(config: CMSConfig, dbAdapter: DatabaseAdapter) {
10
- this.config = config;
11
- this.db = dbAdapter;
12
- }
13
-
14
- // Update config dynamically (for schema hot-reloading)
15
- updateConfig(newConfig: CMSConfig): void {
16
- this.config = newConfig;
17
- console.log('🔄 CMS config updated:', {
18
- schemaTypes: newConfig.schemaTypes.length,
19
- documents: newConfig.schemaTypes.filter((t) => t.type === 'document').length,
20
- objects: newConfig.schemaTypes.filter((t) => t.type === 'object').length
21
- });
22
- }
23
-
24
- // Initialize CMS - register schema types in database
25
- async initialize(): Promise<void> {
26
- console.log('🚀 Initializing CMS...');
27
-
28
- // Get existing schemas from database
29
- const existingSchemas = await this.db.listSchemas();
30
- const existingNames = new Set(existingSchemas.map((s) => s.name));
31
- const currentNames = new Set(this.config.schemaTypes.map((s) => s.name));
32
-
33
- // Delete schemas that are no longer in config
34
- for (const existingName of existingNames) {
35
- if (!currentNames.has(existingName)) {
36
- await this.db.deleteSchemaType(existingName);
37
- }
38
- }
39
-
40
- // Register all schema types (updates if exists, creates if new)
41
- for (const schemaType of this.config.schemaTypes) {
42
- await this.db.registerSchemaType(schemaType);
43
- }
44
-
45
- console.log('✅ CMS initialized successfully');
46
- }
47
-
48
- // Schema Type utility methods
49
- async getSchemaType(name: string): Promise<SchemaType | null> {
50
- return this.db.getSchemaType(name);
51
- }
52
-
53
- async listSchemas(): Promise<SchemaType[]> {
54
- return this.db.listSchemas();
55
- }
56
-
57
- getSchemaTypeByName(name: string): SchemaType | null {
58
- return this.config.schemaTypes.find((s) => s.name === name) || null;
59
- }
60
-
61
- async listDocumentTypes(): Promise<Array<{ name: string; title: string; description?: string }>> {
62
- return this.db.listDocumentTypes();
63
- }
64
-
65
- async listObjectTypes(): Promise<Array<{ name: string; title: string; description?: string }>> {
66
- return this.db.listObjectTypes();
67
- }
68
- }
69
-
70
- // Global CMS instance
71
- let cmsInstance: CMSEngine | null = null;
72
-
73
- export function createCMS(config: CMSConfig, dbAdapter: DatabaseAdapter): CMSEngine {
74
- if (!cmsInstance) {
75
- cmsInstance = new CMSEngine(config, dbAdapter);
76
- }
77
- return cmsInstance;
78
- }
79
-
80
- export function getCMS(): CMSEngine {
81
- if (!cmsInstance) {
82
- throw new Error('CMS not initialized. Call createCMS() first.');
83
- }
84
- return cmsInstance;
85
- }