@aphexcms/cms-core 0.1.0 → 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,211 +0,0 @@
1
- // Aphex CMS Document Publish API Handlers
2
- import { json } from '@sveltejs/kit';
3
- import type { RequestHandler } from '@sveltejs/kit';
4
- import { validateField } from '../field-validation/utils.js';
5
- import { canWrite } from '../types/auth.js';
6
-
7
- // POST /api/documents/[id]/publish - Publish document
8
- export const POST: RequestHandler = async ({ params, locals }) => {
9
- try {
10
- const { databaseAdapter, cmsEngine } = locals.aphexCMS;
11
- const auth = locals.auth;
12
- const { id } = params;
13
-
14
- if (!auth) {
15
- return json(
16
- {
17
- success: false,
18
- error: 'Unauthorized',
19
- message: 'Authentication required'
20
- },
21
- { status: 401 }
22
- );
23
- }
24
-
25
- // Check write permissions (viewers are read-only)
26
- if (!canWrite(auth)) {
27
- return json(
28
- {
29
- success: false,
30
- error: 'Forbidden',
31
- message: 'You do not have permission to publish documents. Viewers have read-only access.'
32
- },
33
- { status: 403 }
34
- );
35
- }
36
-
37
- if (!id) {
38
- return json(
39
- {
40
- success: false,
41
- error: 'Missing document ID',
42
- message: 'Document ID is required'
43
- },
44
- { status: 400 }
45
- );
46
- }
47
-
48
- // Get document to validate
49
- const document = await databaseAdapter.findByDocId(auth.organizationId, id);
50
- if (!document || !document.draftData) {
51
- return json(
52
- {
53
- success: false,
54
- error: 'Document not found or cannot be published',
55
- message: 'Document may not exist or may not have draft content'
56
- },
57
- { status: 404 }
58
- );
59
- }
60
-
61
- // Get schema for validation (from config to preserve validation functions)
62
- const schema = cmsEngine.getSchemaTypeByName(document.type);
63
- if (!schema) {
64
- return json(
65
- {
66
- success: false,
67
- error: 'Invalid document type',
68
- message: `Schema type '${document.type}' not found`
69
- },
70
- { status: 400 }
71
- );
72
- }
73
-
74
- // VALIDATE before publishing - block if errors exist
75
- const validationErrors: Array<{ field: string; errors: string[] }> = [];
76
-
77
- for (const field of schema.fields) {
78
- const value = document.draftData[field.name];
79
- const result = await validateField(field, value, document.draftData);
80
-
81
- if (!result.isValid) {
82
- const errorMessages = result.errors
83
- .filter((e) => e.level === 'error')
84
- .map((e) => e.message);
85
-
86
- if (errorMessages.length > 0) {
87
- validationErrors.push({
88
- field: field.name,
89
- errors: errorMessages
90
- });
91
- }
92
- }
93
- }
94
-
95
- // Block publishing if validation errors exist
96
- if (validationErrors.length > 0) {
97
- return json(
98
- {
99
- success: false,
100
- error: 'Cannot publish: validation errors',
101
- message: 'Please fix all validation errors before publishing',
102
- validationErrors
103
- },
104
- { status: 400 }
105
- );
106
- }
107
-
108
- // All validation passed - proceed with publish
109
- const publishedDocument = await databaseAdapter.publishDoc(auth.organizationId, id);
110
-
111
- if (!publishedDocument) {
112
- return json(
113
- {
114
- success: false,
115
- error: 'Document not found or cannot be published',
116
- message: 'Document may not exist or may not have draft content'
117
- },
118
- { status: 404 }
119
- );
120
- }
121
-
122
- return json({
123
- success: true,
124
- data: publishedDocument,
125
- message: 'Document published successfully'
126
- });
127
- } catch (error) {
128
- console.error('Failed to publish document:', error);
129
- return json(
130
- {
131
- success: false,
132
- error: 'Failed to publish document',
133
- message: error instanceof Error ? error.message : 'Unknown error'
134
- },
135
- { status: 500 }
136
- );
137
- }
138
- };
139
-
140
- // DELETE /api/documents/[id]/publish - Unpublish document
141
- export const DELETE: RequestHandler = async ({ params, locals }) => {
142
- try {
143
- const { databaseAdapter } = locals.aphexCMS;
144
- const auth = locals.auth;
145
- const { id } = params;
146
-
147
- if (!auth) {
148
- return json(
149
- {
150
- success: false,
151
- error: 'Unauthorized',
152
- message: 'Authentication required'
153
- },
154
- { status: 401 }
155
- );
156
- }
157
-
158
- // Check write permissions (viewers are read-only)
159
- if (!canWrite(auth)) {
160
- return json(
161
- {
162
- success: false,
163
- error: 'Forbidden',
164
- message:
165
- 'You do not have permission to unpublish documents. Viewers have read-only access.'
166
- },
167
- { status: 403 }
168
- );
169
- }
170
-
171
- if (!id) {
172
- return json(
173
- {
174
- success: false,
175
- error: 'Missing document ID',
176
- message: 'Document ID is required'
177
- },
178
- { status: 400 }
179
- );
180
- }
181
-
182
- const unpublishedDocument = await databaseAdapter.unpublishDoc(auth.organizationId, id);
183
-
184
- if (!unpublishedDocument) {
185
- return json(
186
- {
187
- success: false,
188
- error: 'Document not found',
189
- message: `No document found with ID: ${id}`
190
- },
191
- { status: 404 }
192
- );
193
- }
194
-
195
- return json({
196
- success: true,
197
- data: unpublishedDocument,
198
- message: 'Document unpublished successfully'
199
- });
200
- } catch (error) {
201
- console.error('Failed to unpublish document:', error);
202
- return json(
203
- {
204
- success: false,
205
- error: 'Failed to unpublish document',
206
- message: error instanceof Error ? error.message : 'Unknown error'
207
- },
208
- { status: 500 }
209
- );
210
- }
211
- };
@@ -1,172 +0,0 @@
1
- // Aphex CMS Document API Handlers
2
- import { json } from '@sveltejs/kit';
3
- import type { RequestHandler } from '@sveltejs/kit';
4
- import { canWrite } from '../types/auth.js';
5
-
6
- // Default values for API
7
- const DEFAULT_API_LIMIT = 20;
8
- const DEFAULT_API_OFFSET = 0;
9
-
10
- // GET /api/documents - List documents with filtering
11
- export const GET: RequestHandler = async ({ url, locals }) => {
12
- try {
13
- const { databaseAdapter } = locals.aphexCMS;
14
- const auth = locals.auth;
15
-
16
- if (!auth) {
17
- return json(
18
- {
19
- success: false,
20
- error: 'Unauthorized',
21
- message: 'Authentication required'
22
- },
23
- { status: 401 }
24
- );
25
- }
26
-
27
- const docType = url.searchParams.get('docType');
28
- const status = url.searchParams.get('status') || undefined;
29
- const limitParam = url.searchParams.get('limit');
30
- const offsetParam = url.searchParams.get('offset');
31
- const depthParam = url.searchParams.get('depth');
32
- const organizationIdsParam = url.searchParams.get('organizationIds'); // Comma-separated list
33
-
34
- // Parse with defaults
35
- const limit = limitParam ? parseInt(limitParam) : DEFAULT_API_LIMIT;
36
- const offset = offsetParam ? parseInt(offsetParam) : DEFAULT_API_OFFSET;
37
- const depth = depthParam ? parseInt(depthParam) : 0;
38
-
39
- // Parse organizationIds if provided
40
- const filterOrganizationIds = organizationIdsParam
41
- ? organizationIdsParam
42
- .split(',')
43
- .map((id) => id.trim())
44
- .filter(Boolean)
45
- : undefined;
46
-
47
- const filters = {
48
- ...(docType && { type: docType }),
49
- ...(status && { status }),
50
- ...(filterOrganizationIds && { filterOrganizationIds }),
51
- limit: isNaN(limit) ? DEFAULT_API_LIMIT : limit,
52
- offset: isNaN(offset) ? DEFAULT_API_OFFSET : offset,
53
- depth: isNaN(depth) ? 0 : Math.max(0, Math.min(depth, 5)) // Clamp between 0-5 for safety
54
- };
55
- const documents = await databaseAdapter.findManyDoc(auth.organizationId, filters);
56
-
57
- return json({
58
- success: true,
59
- data: documents,
60
- meta: {
61
- count: documents.length,
62
- limit: filters.limit,
63
- offset: filters.offset,
64
- filters: {
65
- docType,
66
- status
67
- }
68
- }
69
- });
70
- } catch (error) {
71
- console.error('Failed to fetch documents:', error);
72
- return json(
73
- {
74
- success: false,
75
- error: 'Failed to fetch documents',
76
- message: error instanceof Error ? error.message : 'Unknown error'
77
- },
78
- { status: 500 }
79
- );
80
- }
81
- };
82
-
83
- // POST /api/documents - Create new document
84
- export const POST: RequestHandler = async ({ request, locals }) => {
85
- try {
86
- const { databaseAdapter } = locals.aphexCMS;
87
- const auth = locals.auth;
88
-
89
- if (!auth) {
90
- return json(
91
- {
92
- success: false,
93
- error: 'Unauthorized',
94
- message: 'Authentication required'
95
- },
96
- { status: 401 }
97
- );
98
- }
99
-
100
- // Check write permissions (viewers are read-only)
101
- if (!canWrite(auth)) {
102
- return json(
103
- {
104
- success: false,
105
- error: 'Forbidden',
106
- message: 'You do not have permission to create documents. Viewers have read-only access.'
107
- },
108
- { status: 403 }
109
- );
110
- }
111
-
112
- const body = await request.json();
113
-
114
- // Validate required fields (support both old and new format)
115
- const documentType = body.type;
116
- const documentData = body.draftData || body.data;
117
-
118
- if (!documentType || !documentData) {
119
- return json(
120
- {
121
- success: false,
122
- error: 'Missing required fields',
123
- message: 'Document type and data are required'
124
- },
125
- { status: 400 }
126
- );
127
- }
128
-
129
- // Validate document type exists
130
- const { cmsEngine } = locals.aphexCMS;
131
- const schema = cmsEngine.getSchemaTypeByName(documentType);
132
- if (!schema) {
133
- return json(
134
- {
135
- success: false,
136
- error: 'Invalid document type',
137
- message: `Schema type '${documentType}' not found`
138
- },
139
- { status: 400 }
140
- );
141
- }
142
-
143
- // NO VALIDATION FOR DRAFTS - Sanity-style: drafts can have any state
144
- // Validation only happens on publish
145
-
146
- // Create document (always starts as draft)
147
- const newDocument = await databaseAdapter.createDocument({
148
- type: documentType,
149
- draftData: documentData,
150
- organizationId: auth.organizationId,
151
- createdBy: auth.type === 'session' ? auth.user.id : undefined
152
- });
153
-
154
- return json(
155
- {
156
- success: true,
157
- data: newDocument
158
- },
159
- { status: 201 }
160
- );
161
- } catch (error) {
162
- console.error('Failed to create document:', error);
163
- return json(
164
- {
165
- success: false,
166
- error: 'Failed to create document',
167
- message: error instanceof Error ? error.message : 'Unknown error'
168
- },
169
- { status: 500 }
170
- );
171
- }
172
- };
@@ -1,13 +0,0 @@
1
- // Aphex CMS API Route Handlers
2
- // These will be imported and re-exported by your app's API routes
3
-
4
- // Document management routes
5
- export * as documents from './documents.js';
6
- export * as documentsById from './documents-by-id.js';
7
-
8
- // Asset management routes
9
- export * as assets from './assets.js';
10
-
11
- // Schema information routes
12
- export * as schemas from './schemas.js';
13
- export * as schemasByType from './schemas-by-type.js';
@@ -1,258 +0,0 @@
1
- // Aphex CMS Organization by ID API Handlers
2
- import { json } from '@sveltejs/kit';
3
- import type { RequestHandler } from '@sveltejs/kit';
4
-
5
- // GET /api/organizations/[id] - Get organization by ID
6
- export const GET: RequestHandler = async ({ params, locals }) => {
7
- try {
8
- const { databaseAdapter } = locals.aphexCMS;
9
- const auth = locals.auth;
10
- const { id } = params;
11
-
12
- if (!auth || auth.type !== 'session') {
13
- return json(
14
- {
15
- success: false,
16
- error: 'Unauthorized',
17
- message: 'Session authentication required'
18
- },
19
- { status: 401 }
20
- );
21
- }
22
-
23
- if (!id) {
24
- return json(
25
- {
26
- success: false,
27
- error: 'Missing required field',
28
- message: 'Organization ID is required'
29
- },
30
- { status: 400 }
31
- );
32
- }
33
-
34
- // Check if user is a member of this organization
35
- const membership = await databaseAdapter.findUserMembership(auth.user.id, id);
36
- if (!membership) {
37
- return json(
38
- {
39
- success: false,
40
- error: 'Forbidden',
41
- message: 'You are not a member of this organization'
42
- },
43
- { status: 403 }
44
- );
45
- }
46
-
47
- const organization = await databaseAdapter.findOrganizationById(id);
48
- if (!organization) {
49
- return json(
50
- {
51
- success: false,
52
- error: 'Organization not found'
53
- },
54
- { status: 404 }
55
- );
56
- }
57
-
58
- return json({
59
- success: true,
60
- data: organization
61
- });
62
- } catch (error) {
63
- console.error('Failed to fetch organization:', error);
64
- return json(
65
- {
66
- success: false,
67
- error: 'Failed to fetch organization',
68
- message: error instanceof Error ? error.message : 'Unknown error'
69
- },
70
- { status: 500 }
71
- );
72
- }
73
- };
74
-
75
- // PATCH /api/organizations/[id] - Update organization
76
- export const PATCH: RequestHandler = async ({ params, request, locals }) => {
77
- try {
78
- const { databaseAdapter } = locals.aphexCMS;
79
- const auth = locals.auth;
80
- const { id } = params;
81
-
82
- if (!auth || auth.type !== 'session') {
83
- return json(
84
- {
85
- success: false,
86
- error: 'Unauthorized',
87
- message: 'Session authentication required'
88
- },
89
- { status: 401 }
90
- );
91
- }
92
-
93
- if (!id) {
94
- return json(
95
- {
96
- success: false,
97
- error: 'Missing required field',
98
- message: 'Organization ID is required'
99
- },
100
- { status: 400 }
101
- );
102
- }
103
-
104
- // Check if user is owner or admin of this organization
105
- const membership = await databaseAdapter.findUserMembership(auth.user.id, id);
106
- if (!membership || (membership.role !== 'owner' && membership.role !== 'admin')) {
107
- return json(
108
- {
109
- success: false,
110
- error: 'Forbidden',
111
- message: 'Only owners and admins can update organization settings'
112
- },
113
- { status: 403 }
114
- );
115
- }
116
-
117
- const body = await request.json();
118
-
119
- // Validate: if slug is being changed, check it's not already taken
120
- if (body.slug) {
121
- const existingOrg = await databaseAdapter.findOrganizationBySlug(body.slug);
122
- if (existingOrg && existingOrg.id !== id) {
123
- return json(
124
- {
125
- success: false,
126
- error: 'Slug already exists',
127
- message: `Organization with slug '${body.slug}' already exists`
128
- },
129
- { status: 409 }
130
- );
131
- }
132
- }
133
-
134
- // Update organization
135
- const updateData: {
136
- name?: string;
137
- slug?: string;
138
- metadata?: any;
139
- } = {};
140
-
141
- if (body.name !== undefined) updateData.name = body.name;
142
- if (body.slug !== undefined) updateData.slug = body.slug;
143
- if (body.metadata !== undefined) updateData.metadata = body.metadata;
144
-
145
- const updatedOrganization = await databaseAdapter.updateOrganization(id, updateData);
146
-
147
- if (!updatedOrganization) {
148
- return json(
149
- {
150
- success: false,
151
- error: 'Organization not found'
152
- },
153
- { status: 404 }
154
- );
155
- }
156
-
157
- return json({
158
- success: true,
159
- data: updatedOrganization
160
- });
161
- } catch (error) {
162
- console.error('Failed to update organization:', error);
163
- return json(
164
- {
165
- success: false,
166
- error: 'Failed to update organization',
167
- message: error instanceof Error ? error.message : 'Unknown error'
168
- },
169
- { status: 500 }
170
- );
171
- }
172
- };
173
-
174
- // DELETE /api/organizations/[id] - Delete an organization
175
- export const DELETE: RequestHandler = async ({ params, locals }) => {
176
- try {
177
- const { databaseAdapter } = locals.aphexCMS;
178
- const auth = locals.auth;
179
- const { id } = params;
180
-
181
- if (!auth || auth.type !== 'session') {
182
- return json(
183
- {
184
- success: false,
185
- error: 'Unauthorized',
186
- message: 'Session authentication required'
187
- },
188
- { status: 401 }
189
- );
190
- }
191
-
192
- if (!id) {
193
- return json(
194
- {
195
- success: false,
196
- error: 'Missing required field',
197
- message: 'Organization ID is required'
198
- },
199
- { status: 400 }
200
- );
201
- }
202
-
203
- // Only owners can delete an organization
204
- const membership = await databaseAdapter.findUserMembership(auth.user.id, id);
205
- if (!membership || membership.role !== 'owner') {
206
- return json(
207
- {
208
- success: false,
209
- error: 'Forbidden',
210
- message: 'Only owners can delete an organization'
211
- },
212
- { status: 403 }
213
- );
214
- }
215
-
216
- // Get all members of the organization
217
- const members = await databaseAdapter.findOrganizationMembers(id);
218
-
219
- // Handle member lifecycle
220
- for (const member of members) {
221
- const userSession = await databaseAdapter.findUserSession(member.userId);
222
- if (userSession?.activeOrganizationId === id) {
223
- const otherOrgs = await databaseAdapter.findUserOrganizations(member.userId);
224
- const remainingOrgs = otherOrgs.filter((org) => org.organization.id !== id);
225
-
226
- if (remainingOrgs.length > 0 && remainingOrgs[0]) {
227
- await databaseAdapter.updateUserSession(member.userId, remainingOrgs[0].organization.id);
228
- } else {
229
- await databaseAdapter.deleteUserSession(member.userId);
230
- }
231
- }
232
- }
233
-
234
- // Delete all members from the organization
235
- await databaseAdapter.removeAllMembers(id);
236
-
237
- // Delete all invitations for the organization
238
- await databaseAdapter.removeAllInvitations(id);
239
-
240
- // Delete the organization
241
- await databaseAdapter.deleteOrganization(id);
242
-
243
- return json({
244
- success: true,
245
- message: 'Organization deleted successfully'
246
- });
247
- } catch (error) {
248
- console.error('Failed to delete organization:', error);
249
- return json(
250
- {
251
- success: false,
252
- error: 'Failed to delete organization',
253
- message: error instanceof Error ? error.message : 'Unknown error'
254
- },
255
- { status: 500 }
256
- );
257
- }
258
- };