@aphexcms/cms-core 0.1.0

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 (104) hide show
  1. package/dist/is-mobile.svelte.d.ts +5 -0
  2. package/dist/is-mobile.svelte.d.ts.map +1 -0
  3. package/dist/is-mobile.svelte.js +7 -0
  4. package/dist/utils.d.ts +13 -0
  5. package/dist/utils.d.ts.map +1 -0
  6. package/dist/utils.js +5 -0
  7. package/package.json +99 -0
  8. package/src/api/assets.ts +75 -0
  9. package/src/api/client.ts +150 -0
  10. package/src/api/documents.ts +102 -0
  11. package/src/api/index.ts +7 -0
  12. package/src/api/organizations.ts +154 -0
  13. package/src/api/types.ts +34 -0
  14. package/src/app.d.ts +19 -0
  15. package/src/auth/MULTI_TENANCY_PLAN.md +1183 -0
  16. package/src/auth/auth-errors.ts +23 -0
  17. package/src/auth/auth-hooks.ts +132 -0
  18. package/src/auth/provider.ts +25 -0
  19. package/src/client/index.ts +47 -0
  20. package/src/components/AdminApp.svelte +1078 -0
  21. package/src/components/admin/AdminLayout.svelte +115 -0
  22. package/src/components/admin/DocumentEditor.svelte +795 -0
  23. package/src/components/admin/DocumentTypesList.svelte +97 -0
  24. package/src/components/admin/ObjectModal.svelte +135 -0
  25. package/src/components/admin/SchemaField.svelte +171 -0
  26. package/src/components/admin/fields/ArrayField.svelte +266 -0
  27. package/src/components/admin/fields/BooleanField.svelte +35 -0
  28. package/src/components/admin/fields/ImageField.svelte +284 -0
  29. package/src/components/admin/fields/NumberField.svelte +82 -0
  30. package/src/components/admin/fields/ReferenceField.svelte +260 -0
  31. package/src/components/admin/fields/SlugField.svelte +74 -0
  32. package/src/components/admin/fields/StringField.svelte +40 -0
  33. package/src/components/admin/fields/TextareaField.svelte +40 -0
  34. package/src/components/fields/index.ts +9 -0
  35. package/src/components/index.ts +16 -0
  36. package/src/components/layout/OrganizationSwitcher.svelte +218 -0
  37. package/src/components/layout/Sidebar.svelte +88 -0
  38. package/src/components/layout/sidebar/AppSidebar.svelte +63 -0
  39. package/src/components/layout/sidebar/NavMain.svelte +95 -0
  40. package/src/components/layout/sidebar/NavSecondary.svelte +69 -0
  41. package/src/components/layout/sidebar/NavUser.svelte +85 -0
  42. package/src/config.ts +18 -0
  43. package/src/db/adapters/index.ts +3 -0
  44. package/src/db/index.ts +5 -0
  45. package/src/db/interfaces/asset.ts +61 -0
  46. package/src/db/interfaces/document.ts +53 -0
  47. package/src/db/interfaces/index.ts +98 -0
  48. package/src/db/interfaces/organization.ts +51 -0
  49. package/src/db/interfaces/schema.ts +13 -0
  50. package/src/db/interfaces/user.ts +16 -0
  51. package/src/db/utils/reference-resolver.ts +119 -0
  52. package/src/define.ts +7 -0
  53. package/src/email/index.ts +5 -0
  54. package/src/email/interfaces/email.ts +45 -0
  55. package/src/engine.ts +85 -0
  56. package/src/field-validation/rule.ts +287 -0
  57. package/src/field-validation/utils.ts +91 -0
  58. package/src/hooks.ts +142 -0
  59. package/src/index.ts +5 -0
  60. package/src/lib/is-mobile.svelte.ts +9 -0
  61. package/src/lib/utils.ts +13 -0
  62. package/src/plugins/README.md +154 -0
  63. package/src/routes/assets-by-id.ts +161 -0
  64. package/src/routes/assets-cdn.ts +185 -0
  65. package/src/routes/assets.ts +116 -0
  66. package/src/routes/documents-by-id.ts +188 -0
  67. package/src/routes/documents-publish.ts +211 -0
  68. package/src/routes/documents.ts +172 -0
  69. package/src/routes/index.ts +13 -0
  70. package/src/routes/organizations-by-id.ts +258 -0
  71. package/src/routes/organizations-invitations.ts +183 -0
  72. package/src/routes/organizations-members.ts +301 -0
  73. package/src/routes/organizations-switch.ts +74 -0
  74. package/src/routes/organizations.ts +146 -0
  75. package/src/routes/schemas-by-type.ts +35 -0
  76. package/src/routes/schemas.ts +19 -0
  77. package/src/routes-exports.ts +42 -0
  78. package/src/schema-context.svelte.ts +24 -0
  79. package/src/schema-utils/cleanup.ts +116 -0
  80. package/src/schema-utils/index.ts +4 -0
  81. package/src/schema-utils/utils.ts +47 -0
  82. package/src/schema-utils/validator.ts +58 -0
  83. package/src/server/index.ts +40 -0
  84. package/src/services/asset-service.ts +256 -0
  85. package/src/services/index.ts +6 -0
  86. package/src/storage/adapters/index.ts +2 -0
  87. package/src/storage/adapters/local-storage-adapter.ts +215 -0
  88. package/src/storage/index.ts +8 -0
  89. package/src/storage/interfaces/index.ts +2 -0
  90. package/src/storage/interfaces/storage.ts +114 -0
  91. package/src/storage/providers/storage.ts +83 -0
  92. package/src/types/asset.ts +81 -0
  93. package/src/types/auth.ts +80 -0
  94. package/src/types/config.ts +45 -0
  95. package/src/types/document.ts +38 -0
  96. package/src/types/index.ts +8 -0
  97. package/src/types/organization.ts +119 -0
  98. package/src/types/schemas.ts +151 -0
  99. package/src/types/sidebar.ts +37 -0
  100. package/src/types/user.ts +17 -0
  101. package/src/utils/content-hash.ts +75 -0
  102. package/src/utils/image-url.ts +204 -0
  103. package/src/utils/index.ts +12 -0
  104. package/src/utils/slug.ts +33 -0
@@ -0,0 +1,5 @@
1
+ import { MediaQuery } from 'svelte/reactivity';
2
+ export declare class IsMobile extends MediaQuery {
3
+ constructor(breakpoint?: number);
4
+ }
5
+ //# sourceMappingURL=is-mobile.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-mobile.svelte.d.ts","sourceRoot":"","sources":["../src/lib/is-mobile.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,qBAAa,QAAS,SAAQ,UAAU;gBAC3B,UAAU,GAAE,MAAkC;CAG1D"}
@@ -0,0 +1,7 @@
1
+ import { MediaQuery } from 'svelte/reactivity';
2
+ const DEFAULT_MOBILE_BREAKPOINT = 768;
3
+ export class IsMobile extends MediaQuery {
4
+ constructor(breakpoint = DEFAULT_MOBILE_BREAKPOINT) {
5
+ super(`max-width: ${breakpoint - 1}px`);
6
+ }
7
+ }
@@ -0,0 +1,13 @@
1
+ import { type ClassValue } from 'clsx';
2
+ export declare function cn(...inputs: ClassValue[]): string;
3
+ export type WithoutChild<T> = T extends {
4
+ child?: any;
5
+ } ? Omit<T, 'child'> : T;
6
+ export type WithoutChildren<T> = T extends {
7
+ children?: any;
8
+ } ? Omit<T, 'children'> : T;
9
+ export type WithoutChildrenOrChild<T> = WithoutChildren<WithoutChild<T>>;
10
+ export type WithElementRef<T, U extends HTMLElement = HTMLElement> = T & {
11
+ ref?: U | null;
12
+ };
13
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAGD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,KAAK,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/E,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;AACxF,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC"}
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ import { clsx } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+ export function cn(...inputs) {
4
+ return twMerge(clsx(inputs));
5
+ }
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@aphexcms/cms-core",
3
+ "version": "0.1.0",
4
+ "description": "Aphex CMS Core - A Sanity-style CMS with ports and adapters architecture",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.ts",
11
+ "svelte": "./src/index.ts",
12
+ "default": "./src/index.ts"
13
+ },
14
+ "./server": {
15
+ "types": "./src/server/index.ts",
16
+ "default": "./src/server/index.ts"
17
+ },
18
+ "./client": {
19
+ "types": "./src/client/index.ts",
20
+ "default": "./src/client/index.ts"
21
+ },
22
+ "./app": {
23
+ "types": "./src/app.d.ts"
24
+ }
25
+ },
26
+ "typesVersions": {
27
+ "*": {
28
+ "app": [
29
+ "./src/app.d.ts"
30
+ ]
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "src",
36
+ "package.json",
37
+ "README.md"
38
+ ],
39
+ "svelte": "./src/index.ts",
40
+ "scripts": {
41
+ "build": "svelte-package",
42
+ "check": "svelte-check --tsconfig ./tsconfig.json",
43
+ "format": "prettier --write .",
44
+ "lint": "prettier --check . && eslint .",
45
+ "package": "pnpm build && pnpm pack",
46
+ "prepublishOnly": "pnpm build"
47
+ },
48
+ "keywords": [
49
+ "cms",
50
+ "svelte",
51
+ "sveltekit",
52
+ "content-management",
53
+ "sanity-style",
54
+ "typescript",
55
+ "aphex"
56
+ ],
57
+ "author": "Your Name",
58
+ "license": "MIT",
59
+ "peerDependencies": {
60
+ "@aphexcms/ui": "workspace:*",
61
+ "@lucide/svelte": "^0.544.0",
62
+ "@sveltejs/kit": "^2.22.0",
63
+ "bits-ui": "^2.11.1",
64
+ "clsx": "^2.1.1",
65
+ "lucide-svelte": "^0.544.0",
66
+ "mode-watcher": "^1.1.0",
67
+ "svelte": "^5.0.0",
68
+ "tailwind-merge": "^3.3.1",
69
+ "tailwind-variants": "^3.1.1"
70
+ },
71
+ "dependencies": {
72
+ "s3mini": "^0.5.0",
73
+ "sharp": "^0.34.4"
74
+ },
75
+ "devDependencies": {
76
+ "@eslint/compat": "^1.2.5",
77
+ "@eslint/js": "^9.22.0",
78
+ "@internationalized/date": "^3.9.0",
79
+ "@sveltejs/adapter-auto": "^6.0.0",
80
+ "@sveltejs/kit": "^2.22.0",
81
+ "@sveltejs/package": "^2.5.4",
82
+ "@sveltejs/vite-plugin-svelte": "^6.0.0",
83
+ "@tailwindcss/vite": "^4.0.0",
84
+ "@types/node": "^22",
85
+ "eslint": "^9.22.0",
86
+ "eslint-config-prettier": "^10.0.1",
87
+ "eslint-plugin-svelte": "^3.0.0",
88
+ "globals": "^16.0.0",
89
+ "prettier": "^3.4.2",
90
+ "prettier-plugin-svelte": "^3.3.3",
91
+ "prettier-plugin-tailwindcss": "^0.6.11",
92
+ "svelte": "^5.0.0",
93
+ "svelte-check": "^4.0.0",
94
+ "tailwindcss": "^4.0.0",
95
+ "typescript": "^5.0.0",
96
+ "typescript-eslint": "^8.20.0",
97
+ "vite": "^7.0.4"
98
+ }
99
+ }
@@ -0,0 +1,75 @@
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
+ };
@@ -0,0 +1,150 @@
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();
@@ -0,0 +1,102 @@
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
+ };
@@ -0,0 +1,7 @@
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';
@@ -0,0 +1,154 @@
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
+ };
@@ -0,0 +1,34 @@
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 ADDED
@@ -0,0 +1,19 @@
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 {};