@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.
- package/package.json +22 -5
- package/src/api/assets.ts +0 -75
- package/src/api/client.ts +0 -150
- package/src/api/documents.ts +0 -102
- package/src/api/index.ts +0 -7
- package/src/api/organizations.ts +0 -154
- package/src/api/types.ts +0 -34
- package/src/app.d.ts +0 -19
- package/src/auth/MULTI_TENANCY_PLAN.md +0 -1183
- package/src/auth/auth-errors.ts +0 -23
- package/src/auth/auth-hooks.ts +0 -132
- package/src/auth/provider.ts +0 -25
- package/src/client/index.ts +0 -47
- package/src/components/AdminApp.svelte +0 -1078
- package/src/components/admin/AdminLayout.svelte +0 -115
- package/src/components/admin/DocumentEditor.svelte +0 -795
- package/src/components/admin/DocumentTypesList.svelte +0 -97
- package/src/components/admin/ObjectModal.svelte +0 -135
- package/src/components/admin/SchemaField.svelte +0 -171
- package/src/components/admin/fields/ArrayField.svelte +0 -266
- package/src/components/admin/fields/BooleanField.svelte +0 -35
- package/src/components/admin/fields/ImageField.svelte +0 -284
- package/src/components/admin/fields/NumberField.svelte +0 -82
- package/src/components/admin/fields/ReferenceField.svelte +0 -260
- package/src/components/admin/fields/SlugField.svelte +0 -74
- package/src/components/admin/fields/StringField.svelte +0 -40
- package/src/components/admin/fields/TextareaField.svelte +0 -40
- package/src/components/fields/index.ts +0 -9
- package/src/components/index.ts +0 -16
- package/src/components/layout/OrganizationSwitcher.svelte +0 -218
- package/src/components/layout/Sidebar.svelte +0 -88
- package/src/components/layout/sidebar/AppSidebar.svelte +0 -63
- package/src/components/layout/sidebar/NavMain.svelte +0 -95
- package/src/components/layout/sidebar/NavSecondary.svelte +0 -69
- package/src/components/layout/sidebar/NavUser.svelte +0 -85
- package/src/config.ts +0 -18
- package/src/db/adapters/index.ts +0 -3
- package/src/db/index.ts +0 -5
- package/src/db/interfaces/asset.ts +0 -61
- package/src/db/interfaces/document.ts +0 -53
- package/src/db/interfaces/index.ts +0 -98
- package/src/db/interfaces/organization.ts +0 -51
- package/src/db/interfaces/schema.ts +0 -13
- package/src/db/interfaces/user.ts +0 -16
- package/src/db/utils/reference-resolver.ts +0 -119
- package/src/define.ts +0 -7
- package/src/email/index.ts +0 -5
- package/src/email/interfaces/email.ts +0 -45
- package/src/engine.ts +0 -85
- package/src/field-validation/rule.ts +0 -287
- package/src/field-validation/utils.ts +0 -91
- package/src/hooks.ts +0 -142
- package/src/index.ts +0 -5
- package/src/lib/is-mobile.svelte.ts +0 -9
- package/src/lib/utils.ts +0 -13
- package/src/plugins/README.md +0 -154
- package/src/routes/assets-by-id.ts +0 -161
- package/src/routes/assets-cdn.ts +0 -185
- package/src/routes/assets.ts +0 -116
- package/src/routes/documents-by-id.ts +0 -188
- package/src/routes/documents-publish.ts +0 -211
- package/src/routes/documents.ts +0 -172
- package/src/routes/index.ts +0 -13
- package/src/routes/organizations-by-id.ts +0 -258
- package/src/routes/organizations-invitations.ts +0 -183
- package/src/routes/organizations-members.ts +0 -301
- package/src/routes/organizations-switch.ts +0 -74
- package/src/routes/organizations.ts +0 -146
- package/src/routes/schemas-by-type.ts +0 -35
- package/src/routes/schemas.ts +0 -19
- package/src/routes-exports.ts +0 -42
- package/src/schema-context.svelte.ts +0 -24
- package/src/schema-utils/cleanup.ts +0 -116
- package/src/schema-utils/index.ts +0 -4
- package/src/schema-utils/utils.ts +0 -47
- package/src/schema-utils/validator.ts +0 -58
- package/src/server/index.ts +0 -40
- package/src/services/asset-service.ts +0 -256
- package/src/services/index.ts +0 -6
- package/src/storage/adapters/index.ts +0 -2
- package/src/storage/adapters/local-storage-adapter.ts +0 -215
- package/src/storage/index.ts +0 -8
- package/src/storage/interfaces/index.ts +0 -2
- package/src/storage/interfaces/storage.ts +0 -114
- package/src/storage/providers/storage.ts +0 -83
- package/src/types/asset.ts +0 -81
- package/src/types/auth.ts +0 -80
- package/src/types/config.ts +0 -45
- package/src/types/document.ts +0 -38
- package/src/types/index.ts +0 -8
- package/src/types/organization.ts +0 -119
- package/src/types/schemas.ts +0 -151
- package/src/types/sidebar.ts +0 -37
- package/src/types/user.ts +0 -17
- package/src/utils/content-hash.ts +0 -75
- package/src/utils/image-url.ts +0 -204
- package/src/utils/index.ts +0 -12
- package/src/utils/slug.ts +0 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aphexcms/cms-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Aphex CMS Core - A Sanity-style CMS with ports and adapters architecture",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -31,11 +31,28 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"src",
|
|
36
|
-
"package.json",
|
|
37
|
-
"README.md"
|
|
34
|
+
"dist"
|
|
38
35
|
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"svelte": "./dist/index.js",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"svelte": "./dist/index.js",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./server": {
|
|
47
|
+
"types": "./dist/server/index.d.ts",
|
|
48
|
+
"default": "./dist/server/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./client": {
|
|
51
|
+
"types": "./dist/client/index.d.ts",
|
|
52
|
+
"default": "./dist/client/index.js"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
39
56
|
"svelte": "./src/index.ts",
|
|
40
57
|
"scripts": {
|
|
41
58
|
"build": "svelte-package",
|
package/src/api/assets.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// Assets API client - manage uploaded files and images
|
|
2
|
-
import { apiClient } from './client.js';
|
|
3
|
-
import type { Asset } from '../types/asset.js';
|
|
4
|
-
import type { ApiResponse } from './types.js';
|
|
5
|
-
|
|
6
|
-
export interface AssetFilters {
|
|
7
|
-
assetType?: 'image' | 'file';
|
|
8
|
-
mimeType?: string;
|
|
9
|
-
search?: string;
|
|
10
|
-
limit?: number;
|
|
11
|
-
offset?: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface UpdateAssetData {
|
|
15
|
-
title?: string;
|
|
16
|
-
description?: string;
|
|
17
|
-
alt?: string;
|
|
18
|
-
creditLine?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class AssetsApi {
|
|
22
|
-
/**
|
|
23
|
-
* List assets with optional filters
|
|
24
|
-
*/
|
|
25
|
-
static async list(filters?: AssetFilters): Promise<ApiResponse<Asset[]>> {
|
|
26
|
-
const params = new URLSearchParams();
|
|
27
|
-
if (filters) {
|
|
28
|
-
Object.entries(filters).forEach(([key, value]) => {
|
|
29
|
-
if (value !== undefined) {
|
|
30
|
-
params.append(key, String(value));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const query = params.toString();
|
|
35
|
-
return apiClient.get<Asset[]>(`/assets${query ? `?${query}` : ''}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get asset by ID
|
|
40
|
-
*/
|
|
41
|
-
static async getById(id: string): Promise<ApiResponse<Asset>> {
|
|
42
|
-
return apiClient.get<Asset>(`/assets/${id}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Upload a new asset (multipart/form-data)
|
|
47
|
-
* Note: Use FormData for file uploads
|
|
48
|
-
*/
|
|
49
|
-
static async upload(formData: FormData): Promise<ApiResponse<Asset>> {
|
|
50
|
-
return apiClient.post<Asset>('/assets', formData);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Update asset metadata
|
|
55
|
-
*/
|
|
56
|
-
static async update(id: string, data: UpdateAssetData): Promise<ApiResponse<Asset>> {
|
|
57
|
-
return apiClient.patch<Asset>(`/assets/${id}`, data);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Delete an asset
|
|
62
|
-
*/
|
|
63
|
-
static async delete(id: string): Promise<ApiResponse<{ success: boolean }>> {
|
|
64
|
-
return apiClient.delete<{ success: boolean }>(`/assets/${id}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Export convenience functions for direct use
|
|
69
|
-
export const assets = {
|
|
70
|
-
list: AssetsApi.list.bind(AssetsApi),
|
|
71
|
-
getById: AssetsApi.getById.bind(AssetsApi),
|
|
72
|
-
upload: AssetsApi.upload.bind(AssetsApi),
|
|
73
|
-
update: AssetsApi.update.bind(AssetsApi),
|
|
74
|
-
delete: AssetsApi.delete.bind(AssetsApi)
|
|
75
|
-
};
|
package/src/api/client.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// Base API client with common functionality
|
|
2
|
-
import type { ApiResponse } from './types.js';
|
|
3
|
-
|
|
4
|
-
// Default configuration
|
|
5
|
-
const DEFAULT_BASE_URL = '/api';
|
|
6
|
-
const DEFAULT_TIMEOUT = 10000; // 10 seconds
|
|
7
|
-
|
|
8
|
-
export class ApiError extends Error {
|
|
9
|
-
constructor(
|
|
10
|
-
public status: number,
|
|
11
|
-
public response: any,
|
|
12
|
-
message?: string
|
|
13
|
-
) {
|
|
14
|
-
super(message || `API Error: ${status}`);
|
|
15
|
-
this.name = 'ApiError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class ApiClient {
|
|
20
|
-
private baseUrl: string;
|
|
21
|
-
private timeout: number;
|
|
22
|
-
|
|
23
|
-
constructor(baseUrl = DEFAULT_BASE_URL, timeout = DEFAULT_TIMEOUT) {
|
|
24
|
-
this.baseUrl = baseUrl;
|
|
25
|
-
this.timeout = timeout;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Make HTTP request with proper error handling
|
|
30
|
-
*/
|
|
31
|
-
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<ApiResponse<T>> {
|
|
32
|
-
const url = `${this.baseUrl}${endpoint}`;
|
|
33
|
-
|
|
34
|
-
// Set up request with defaults
|
|
35
|
-
// Don't set Content-Type for FormData (browser will set it with boundary)
|
|
36
|
-
const headers: Record<string, string> = {};
|
|
37
|
-
if (!(options.body instanceof FormData)) {
|
|
38
|
-
headers['Content-Type'] = 'application/json';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const requestOptions: RequestInit = {
|
|
42
|
-
headers: {
|
|
43
|
-
...headers,
|
|
44
|
-
...options.headers
|
|
45
|
-
},
|
|
46
|
-
...options
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Add timeout
|
|
50
|
-
const controller = new AbortController();
|
|
51
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
52
|
-
requestOptions.signal = controller.signal;
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const response = await fetch(url, requestOptions);
|
|
56
|
-
clearTimeout(timeoutId);
|
|
57
|
-
|
|
58
|
-
const data: ApiResponse<T> = await response.json();
|
|
59
|
-
|
|
60
|
-
// Handle HTTP errors
|
|
61
|
-
if (!response.ok) {
|
|
62
|
-
throw new ApiError(response.status, data, data.message || data.error);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Handle API-level errors
|
|
66
|
-
if (!data.success) {
|
|
67
|
-
throw new ApiError(response.status, data, data.message || data.error);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return data;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
clearTimeout(timeoutId);
|
|
73
|
-
|
|
74
|
-
if (error instanceof ApiError) {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Handle fetch errors (network, timeout, etc.)
|
|
79
|
-
throw new ApiError(0, null, error instanceof Error ? error.message : 'Network error');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* GET request
|
|
85
|
-
*/
|
|
86
|
-
async get<T>(endpoint: string, params?: Record<string, any>): Promise<ApiResponse<T>> {
|
|
87
|
-
let url = endpoint;
|
|
88
|
-
|
|
89
|
-
if (params) {
|
|
90
|
-
const searchParams = new URLSearchParams();
|
|
91
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
92
|
-
if (value !== undefined && value !== null) {
|
|
93
|
-
searchParams.append(key, String(value));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (searchParams.toString()) {
|
|
98
|
-
url += `?${searchParams.toString()}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this.request<T>(url, { method: 'GET' });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* POST request
|
|
107
|
-
*/
|
|
108
|
-
async post<T>(endpoint: string, body?: any): Promise<ApiResponse<T>> {
|
|
109
|
-
return this.request<T>(endpoint, {
|
|
110
|
-
method: 'POST',
|
|
111
|
-
// Don't stringify FormData - pass it directly
|
|
112
|
-
body: body instanceof FormData ? body : body ? JSON.stringify(body) : undefined
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* PUT request
|
|
118
|
-
*/
|
|
119
|
-
async put<T>(endpoint: string, body?: any): Promise<ApiResponse<T>> {
|
|
120
|
-
return this.request<T>(endpoint, {
|
|
121
|
-
method: 'PUT',
|
|
122
|
-
// Don't stringify FormData - pass it directly
|
|
123
|
-
body: body instanceof FormData ? body : body ? JSON.stringify(body) : undefined
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* DELETE request
|
|
129
|
-
*/
|
|
130
|
-
async delete<T>(endpoint: string, body?: any): Promise<ApiResponse<T>> {
|
|
131
|
-
return this.request<T>(endpoint, {
|
|
132
|
-
method: 'DELETE',
|
|
133
|
-
body: body ? JSON.stringify(body) : undefined
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* PATCH request
|
|
139
|
-
*/
|
|
140
|
-
async patch<T>(endpoint: string, body?: any): Promise<ApiResponse<T>> {
|
|
141
|
-
return this.request<T>(endpoint, {
|
|
142
|
-
method: 'PATCH',
|
|
143
|
-
// Don't stringify FormData - pass it directly
|
|
144
|
-
body: body instanceof FormData ? body : body ? JSON.stringify(body) : undefined
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Export singleton instance
|
|
150
|
-
export const apiClient = new ApiClient();
|
package/src/api/documents.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// Documents API client - composable document operations
|
|
2
|
-
import { apiClient } from './client.js';
|
|
3
|
-
import type {
|
|
4
|
-
Document,
|
|
5
|
-
DocumentListParams,
|
|
6
|
-
CreateDocumentData,
|
|
7
|
-
UpdateDocumentData,
|
|
8
|
-
ApiResponse
|
|
9
|
-
} from './types.js';
|
|
10
|
-
|
|
11
|
-
export class DocumentsApi {
|
|
12
|
-
/**
|
|
13
|
-
* List documents with optional filtering
|
|
14
|
-
*/
|
|
15
|
-
static async list(params: DocumentListParams = {}): Promise<ApiResponse<Document[]>> {
|
|
16
|
-
return apiClient.get<Document[]>('/documents', params);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get document by ID
|
|
21
|
-
*/
|
|
22
|
-
static async getById(id: string): Promise<ApiResponse<Document>> {
|
|
23
|
-
return apiClient.get<Document>(`/documents/${id}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Create new document
|
|
28
|
-
*/
|
|
29
|
-
static async create(data: CreateDocumentData): Promise<ApiResponse<Document>> {
|
|
30
|
-
return apiClient.post<Document>('/documents', data);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Update document draft by ID (auto-save)
|
|
35
|
-
*/
|
|
36
|
-
static async updateById(id: string, data: UpdateDocumentData): Promise<ApiResponse<Document>> {
|
|
37
|
-
return apiClient.put<Document>(`/documents/${id}`, data);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Publish document (copy draft -> published)
|
|
42
|
-
*/
|
|
43
|
-
static async publish(id: string): Promise<ApiResponse<Document>> {
|
|
44
|
-
return apiClient.post<Document>(`/documents/${id}/publish`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Unpublish document (revert to draft only)
|
|
49
|
-
*/
|
|
50
|
-
static async unpublish(id: string): Promise<ApiResponse<Document>> {
|
|
51
|
-
return apiClient.delete<Document>(`/documents/${id}/publish`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Delete document by ID
|
|
56
|
-
*/
|
|
57
|
-
static async deleteById(id: string): Promise<ApiResponse<void>> {
|
|
58
|
-
return apiClient.delete<void>(`/documents/${id}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get documents by type (convenience method)
|
|
63
|
-
*/
|
|
64
|
-
static async getByType(
|
|
65
|
-
docType: string,
|
|
66
|
-
params: Omit<DocumentListParams, 'docType'> = {}
|
|
67
|
-
): Promise<ApiResponse<Document[]>> {
|
|
68
|
-
return this.list({ ...params, docType });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get published documents only (convenience method)
|
|
73
|
-
*/
|
|
74
|
-
static async getPublished(
|
|
75
|
-
params: Omit<DocumentListParams, 'status'> = {}
|
|
76
|
-
): Promise<ApiResponse<Document[]>> {
|
|
77
|
-
return this.list({ ...params, status: 'published' });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get draft documents only (convenience method)
|
|
82
|
-
*/
|
|
83
|
-
static async getDrafts(
|
|
84
|
-
params: Omit<DocumentListParams, 'status'> = {}
|
|
85
|
-
): Promise<ApiResponse<Document[]>> {
|
|
86
|
-
return this.list({ ...params, status: 'draft' });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Export convenience functions for direct use
|
|
91
|
-
export const documents = {
|
|
92
|
-
list: DocumentsApi.list.bind(DocumentsApi),
|
|
93
|
-
getById: DocumentsApi.getById.bind(DocumentsApi),
|
|
94
|
-
create: DocumentsApi.create.bind(DocumentsApi),
|
|
95
|
-
updateById: DocumentsApi.updateById.bind(DocumentsApi),
|
|
96
|
-
publish: DocumentsApi.publish.bind(DocumentsApi),
|
|
97
|
-
unpublish: DocumentsApi.unpublish.bind(DocumentsApi),
|
|
98
|
-
deleteById: DocumentsApi.deleteById.bind(DocumentsApi),
|
|
99
|
-
getByType: DocumentsApi.getByType.bind(DocumentsApi),
|
|
100
|
-
getPublished: DocumentsApi.getPublished.bind(DocumentsApi),
|
|
101
|
-
getDrafts: DocumentsApi.getDrafts.bind(DocumentsApi)
|
|
102
|
-
};
|
package/src/api/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// API Client exports
|
|
2
|
-
export { type ApiClient, ApiError, apiClient } from './client.js';
|
|
3
|
-
export { type ApiResponse } from './types.js';
|
|
4
|
-
export { documents } from './documents.js';
|
|
5
|
-
export { organizations } from './organizations.js';
|
|
6
|
-
export { assets } from './assets.js';
|
|
7
|
-
export type * from '../types/index.js';
|
package/src/api/organizations.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// Organizations API client - composable organization operations
|
|
2
|
-
import { apiClient } from './client.js';
|
|
3
|
-
import type { Organization, OrganizationMember, OrganizationRole } from '../types/organization.js';
|
|
4
|
-
import type { ApiResponse } from './types.js';
|
|
5
|
-
|
|
6
|
-
export interface CreateOrganizationData {
|
|
7
|
-
name: string;
|
|
8
|
-
slug: string;
|
|
9
|
-
metadata?: any;
|
|
10
|
-
parentOrganizationId?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface OrganizationListItem extends Organization {
|
|
14
|
-
role: OrganizationRole;
|
|
15
|
-
joinedAt: Date;
|
|
16
|
-
isActive: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface SwitchOrganizationData {
|
|
20
|
-
organizationId: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface InviteMemberData {
|
|
24
|
-
email: string;
|
|
25
|
-
role: OrganizationRole;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface UpdateMemberRoleData {
|
|
29
|
-
userId: string;
|
|
30
|
-
role: OrganizationRole;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RemoveMemberData {
|
|
34
|
-
userId: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface CancelInvitationData {
|
|
38
|
-
invitationId: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface UpdateOrganizationData {
|
|
42
|
-
name?: string;
|
|
43
|
-
slug?: string;
|
|
44
|
-
metadata?: any;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class OrganizationsApi {
|
|
48
|
-
/**
|
|
49
|
-
* List user's organizations
|
|
50
|
-
*/
|
|
51
|
-
static async list(): Promise<ApiResponse<OrganizationListItem[]>> {
|
|
52
|
-
return apiClient.get<OrganizationListItem[]>('/organizations');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create new organization (super_admin only)
|
|
57
|
-
*/
|
|
58
|
-
static async create(data: CreateOrganizationData): Promise<ApiResponse<Organization>> {
|
|
59
|
-
return apiClient.post<Organization>('/organizations', data);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Switch to a different organization
|
|
64
|
-
*/
|
|
65
|
-
static async switch(data: SwitchOrganizationData): Promise<ApiResponse<{ success: boolean }>> {
|
|
66
|
-
return apiClient.post<{ success: boolean }>('/organizations/switch', data);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get organization by ID
|
|
71
|
-
*/
|
|
72
|
-
static async getById(id: string): Promise<ApiResponse<Organization>> {
|
|
73
|
-
return apiClient.get<Organization>(`/organizations/${id}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get active organization
|
|
78
|
-
*/
|
|
79
|
-
static async getActive(): Promise<ApiResponse<Organization>> {
|
|
80
|
-
const result = await this.list();
|
|
81
|
-
const active = result.data?.find((org) => org.isActive);
|
|
82
|
-
if (!active) {
|
|
83
|
-
throw new Error('No active organization found');
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
success: true,
|
|
87
|
-
data: active
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get organization members
|
|
93
|
-
*/
|
|
94
|
-
static async getMembers(): Promise<ApiResponse<OrganizationMember[]>> {
|
|
95
|
-
return apiClient.get<OrganizationMember[]>('/organizations/members');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Invite a member to the organization
|
|
100
|
-
*/
|
|
101
|
-
static async inviteMember(data: InviteMemberData): Promise<ApiResponse<OrganizationMember>> {
|
|
102
|
-
return apiClient.post<OrganizationMember>('/organizations/invitations', data);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Remove a member from the organization
|
|
107
|
-
*/
|
|
108
|
-
static async removeMember(data: RemoveMemberData): Promise<ApiResponse<{ success: boolean }>> {
|
|
109
|
-
return apiClient.delete<{ success: boolean }>('/organizations/members', data);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Update a member's role
|
|
114
|
-
*/
|
|
115
|
-
static async updateMemberRole(
|
|
116
|
-
data: UpdateMemberRoleData
|
|
117
|
-
): Promise<ApiResponse<OrganizationMember>> {
|
|
118
|
-
return apiClient.patch<OrganizationMember>('/organizations/members', data);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Update organization settings
|
|
123
|
-
*/
|
|
124
|
-
static async update(
|
|
125
|
-
id: string,
|
|
126
|
-
data: UpdateOrganizationData
|
|
127
|
-
): Promise<ApiResponse<Organization>> {
|
|
128
|
-
return apiClient.patch<Organization>(`/organizations/${id}`, data);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Cancel a pending invitation
|
|
133
|
-
*/
|
|
134
|
-
static async cancelInvitation(
|
|
135
|
-
data: CancelInvitationData
|
|
136
|
-
): Promise<ApiResponse<{ success: boolean }>> {
|
|
137
|
-
return apiClient.delete<{ success: boolean }>('/organizations/invitations', data);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Export convenience functions for direct use
|
|
142
|
-
export const organizations = {
|
|
143
|
-
list: OrganizationsApi.list.bind(OrganizationsApi),
|
|
144
|
-
create: OrganizationsApi.create.bind(OrganizationsApi),
|
|
145
|
-
switch: OrganizationsApi.switch.bind(OrganizationsApi),
|
|
146
|
-
getById: OrganizationsApi.getById.bind(OrganizationsApi),
|
|
147
|
-
getActive: OrganizationsApi.getActive.bind(OrganizationsApi),
|
|
148
|
-
update: OrganizationsApi.update.bind(OrganizationsApi),
|
|
149
|
-
getMembers: OrganizationsApi.getMembers.bind(OrganizationsApi),
|
|
150
|
-
inviteMember: OrganizationsApi.inviteMember.bind(OrganizationsApi),
|
|
151
|
-
removeMember: OrganizationsApi.removeMember.bind(OrganizationsApi),
|
|
152
|
-
updateMemberRole: OrganizationsApi.updateMemberRole.bind(OrganizationsApi),
|
|
153
|
-
cancelInvitation: OrganizationsApi.cancelInvitation.bind(OrganizationsApi)
|
|
154
|
-
};
|
package/src/api/types.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// API client types
|
|
2
|
-
import type { Document, NewDocument } from '../types/index.js';
|
|
3
|
-
|
|
4
|
-
// API Response wrappers
|
|
5
|
-
export interface ApiResponse<T> {
|
|
6
|
-
success: boolean;
|
|
7
|
-
data?: T;
|
|
8
|
-
error?: string;
|
|
9
|
-
message?: string;
|
|
10
|
-
meta?: {
|
|
11
|
-
count: number;
|
|
12
|
-
limit: number;
|
|
13
|
-
offset: number;
|
|
14
|
-
filters: Record<string, any>;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Document-related types
|
|
19
|
-
export interface DocumentListParams {
|
|
20
|
-
docType?: string;
|
|
21
|
-
status?: string;
|
|
22
|
-
limit?: number;
|
|
23
|
-
offset?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Use database types directly instead of duplicating
|
|
27
|
-
export type CreateDocumentData = Omit<
|
|
28
|
-
NewDocument,
|
|
29
|
-
'id' | 'createdAt' | 'updatedAt' | 'publishedAt'
|
|
30
|
-
>;
|
|
31
|
-
export type UpdateDocumentData = Partial<Pick<Document, 'draftData' | 'status'>>;
|
|
32
|
-
|
|
33
|
-
// Re-export database types for convenience
|
|
34
|
-
export type { Document, NewDocument };
|
package/src/app.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// See https://svelte.dev/docs/kit/types#app.d.ts
|
|
2
|
-
// for information about these interfaces
|
|
3
|
-
//
|
|
4
|
-
import type { CMSInstances } from './hooks.js';
|
|
5
|
-
import type { Auth } from './types/index.js';
|
|
6
|
-
declare global {
|
|
7
|
-
namespace App {
|
|
8
|
-
// interface Error {}
|
|
9
|
-
interface Locals {
|
|
10
|
-
aphexCMS: CMSInstances;
|
|
11
|
-
auth?: Auth; // Available in protected routes
|
|
12
|
-
}
|
|
13
|
-
// interface PageData {}
|
|
14
|
-
// interface PageState {}
|
|
15
|
-
// interface Platform {}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export {};
|