@structcms/api 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.
@@ -0,0 +1,365 @@
1
+ import { S as StorageAdapter, P as Page, C as CreatePageInput, U as UpdatePageInput, a as PageFilter, N as Navigation, b as CreateNavigationInput, c as UpdateNavigationInput, d as NavigationItem, e as PageSection, M as MediaAdapter, f as UploadMediaInput, g as MediaFile, h as MediaFilter, A as AuthAdapter, i as SignInWithOAuthInput, O as OAuthResponse, j as SignInWithPasswordInput, k as AuthSession, V as VerifySessionInput, l as AuthUser } from './types-Zi0Iyow1.js';
2
+ export { m as ALLOWED_MIME_TYPES, n as AllowedMimeType } from './types-Zi0Iyow1.js';
3
+ import { SupabaseClient } from '@supabase/supabase-js';
4
+ export { SupabaseAdapterFactoryConfig, SupabaseAdapterFactoryStorageConfig, SupabaseAdapters, createSupabaseAdapters } from './supabase/index.js';
5
+
6
+ /**
7
+ * Storage adapter error with additional context
8
+ */
9
+ declare class StorageError extends Error {
10
+ readonly code?: string | undefined;
11
+ readonly details?: string | undefined;
12
+ constructor(message: string, code?: string | undefined, details?: string | undefined);
13
+ }
14
+ /**
15
+ * Configuration for creating a Supabase storage adapter
16
+ */
17
+ interface SupabaseStorageAdapterConfig {
18
+ client: SupabaseClient;
19
+ }
20
+ /**
21
+ * Supabase implementation of the StorageAdapter interface
22
+ */
23
+ declare class SupabaseStorageAdapter implements StorageAdapter {
24
+ private client;
25
+ constructor(config: SupabaseStorageAdapterConfig);
26
+ getPage(slug: string): Promise<Page | null>;
27
+ getPageById(id: string): Promise<Page | null>;
28
+ createPage(input: CreatePageInput): Promise<Page>;
29
+ updatePage(input: UpdatePageInput): Promise<Page>;
30
+ deletePage(id: string): Promise<void>;
31
+ listPages(filter?: PageFilter): Promise<Page[]>;
32
+ getNavigation(name: string): Promise<Navigation | null>;
33
+ getNavigationById(id: string): Promise<Navigation | null>;
34
+ createNavigation(input: CreateNavigationInput): Promise<Navigation>;
35
+ updateNavigation(input: UpdateNavigationInput): Promise<Navigation>;
36
+ deleteNavigation(id: string): Promise<void>;
37
+ listNavigations(): Promise<Navigation[]>;
38
+ }
39
+ /**
40
+ * Creates a storage adapter using Supabase
41
+ */
42
+ declare function createStorageAdapter(config: SupabaseStorageAdapterConfig): StorageAdapter;
43
+
44
+ /**
45
+ * Error thrown when storage validation fails
46
+ */
47
+ declare class StorageValidationError extends Error {
48
+ readonly code: string;
49
+ constructor(message: string, code: string);
50
+ }
51
+ /**
52
+ * Handler for creating a new page
53
+ * Generates a slug from the title if not provided and ensures uniqueness
54
+ */
55
+ declare function handleCreatePage(adapter: StorageAdapter, input: CreatePageInput): Promise<Page>;
56
+ /**
57
+ * Handler for updating an existing page
58
+ */
59
+ declare function handleUpdatePage(adapter: StorageAdapter, input: UpdatePageInput): Promise<Page>;
60
+ /**
61
+ * Handler for deleting a page by ID
62
+ */
63
+ declare function handleDeletePage(adapter: StorageAdapter, id: string): Promise<void>;
64
+ /**
65
+ * Handler for creating a new navigation
66
+ * Validates that the name is non-empty and unique
67
+ */
68
+ declare function handleCreateNavigation(adapter: StorageAdapter, input: CreateNavigationInput): Promise<Navigation>;
69
+ /**
70
+ * Handler for updating an existing navigation
71
+ */
72
+ declare function handleUpdateNavigation(adapter: StorageAdapter, input: UpdateNavigationInput): Promise<Navigation>;
73
+ /**
74
+ * Handler for deleting a navigation by ID
75
+ */
76
+ declare function handleDeleteNavigation(adapter: StorageAdapter, id: string): Promise<void>;
77
+
78
+ /**
79
+ * Generates a URL-safe slug from a title string.
80
+ *
81
+ * @param title - The title to convert to a slug
82
+ * @returns A URL-safe slug
83
+ *
84
+ * @example
85
+ * generateSlug('Hello World') // 'hello-world'
86
+ * generateSlug('Über uns') // 'ueber-uns'
87
+ * generateSlug(' Multiple Spaces ') // 'multiple-spaces'
88
+ */
89
+ declare function generateSlug(title: string): string;
90
+ /**
91
+ * Ensures a slug is unique by appending a numeric suffix if needed.
92
+ *
93
+ * @param slug - The base slug to make unique
94
+ * @param existingSlugs - Array of existing slugs to check against
95
+ * @returns A unique slug
96
+ *
97
+ * @example
98
+ * ensureUniqueSlug('hello', ['hello', 'world']) // 'hello-1'
99
+ * ensureUniqueSlug('hello', ['hello', 'hello-1']) // 'hello-2'
100
+ * ensureUniqueSlug('new', ['hello', 'world']) // 'new'
101
+ */
102
+ declare function ensureUniqueSlug(slug: string, existingSlugs: string[]): string;
103
+
104
+ /**
105
+ * Page response for delivery API
106
+ * Dates are serialized as ISO strings for JSON transport
107
+ */
108
+ interface PageResponse {
109
+ id: string;
110
+ slug: string;
111
+ pageType: string;
112
+ title: string;
113
+ sections: PageSection[];
114
+ meta: {
115
+ createdAt: string;
116
+ updatedAt: string;
117
+ };
118
+ }
119
+ /**
120
+ * Navigation response for delivery API
121
+ */
122
+ interface NavigationResponse {
123
+ id: string;
124
+ name: string;
125
+ items: NavigationItem[];
126
+ meta: {
127
+ updatedAt: string;
128
+ };
129
+ }
130
+ /**
131
+ * Filter options for listing pages via delivery API
132
+ */
133
+ interface ListPagesOptions {
134
+ pageType?: string;
135
+ limit?: number;
136
+ offset?: number;
137
+ }
138
+
139
+ /**
140
+ * Handler for GET /api/cms/pages
141
+ * Returns all pages with resolved media references, optionally filtered by pageType
142
+ */
143
+ declare function handleListPages(adapter: StorageAdapter, mediaAdapter: MediaAdapter, options?: ListPagesOptions): Promise<PageResponse[]>;
144
+ /**
145
+ * Handler for GET /api/cms/pages/:slug
146
+ * Returns a single page by slug with resolved media references, or null if not found
147
+ */
148
+ declare function handleGetPageBySlug(adapter: StorageAdapter, mediaAdapter: MediaAdapter, slug: string): Promise<PageResponse | null>;
149
+ /**
150
+ * Handler for GET /api/cms/navigation/:name
151
+ * Returns a navigation by name, or null if not found
152
+ */
153
+ declare function handleGetNavigation(adapter: StorageAdapter, name: string): Promise<NavigationResponse | null>;
154
+
155
+ /**
156
+ * Media adapter error with additional context
157
+ */
158
+ declare class MediaError extends Error {
159
+ readonly code?: string | undefined;
160
+ readonly details?: string | undefined;
161
+ constructor(message: string, code?: string | undefined, details?: string | undefined);
162
+ }
163
+ /**
164
+ * Configuration for creating a Supabase media adapter
165
+ */
166
+ interface SupabaseMediaAdapterConfig {
167
+ client: SupabaseClient;
168
+ bucketName?: string;
169
+ }
170
+ /**
171
+ * Supabase implementation of the MediaAdapter interface
172
+ */
173
+ declare class SupabaseMediaAdapter implements MediaAdapter {
174
+ private client;
175
+ private bucketName;
176
+ constructor(config: SupabaseMediaAdapterConfig);
177
+ /**
178
+ * Generates a unique storage path for a file
179
+ */
180
+ private generateStoragePath;
181
+ /**
182
+ * Constructs the public URL for a stored file
183
+ */
184
+ private getPublicUrl;
185
+ /**
186
+ * Maps a database row to MediaFile
187
+ */
188
+ private mapRowToMediaFile;
189
+ upload(input: UploadMediaInput): Promise<MediaFile>;
190
+ getMedia(id: string): Promise<MediaFile | null>;
191
+ listMedia(filter?: MediaFilter): Promise<MediaFile[]>;
192
+ deleteMedia(id: string): Promise<void>;
193
+ }
194
+ /**
195
+ * Creates a media adapter using Supabase
196
+ */
197
+ declare function createMediaAdapter(config: SupabaseMediaAdapterConfig): MediaAdapter;
198
+
199
+ /**
200
+ * Error thrown when media validation fails
201
+ */
202
+ declare class MediaValidationError extends Error {
203
+ readonly code: string;
204
+ constructor(message: string, code: string);
205
+ }
206
+ /**
207
+ * Handler for uploading a media file
208
+ * Validates the file type and delegates to the adapter
209
+ */
210
+ declare function handleUploadMedia(adapter: MediaAdapter, input: UploadMediaInput): Promise<MediaFile>;
211
+ /**
212
+ * Handler for retrieving a media file by ID
213
+ */
214
+ declare function handleGetMedia(adapter: MediaAdapter, id: string): Promise<MediaFile | null>;
215
+ /**
216
+ * Handler for listing media files with optional filtering
217
+ */
218
+ declare function handleListMedia(adapter: MediaAdapter, filter?: MediaFilter): Promise<MediaFile[]>;
219
+ /**
220
+ * Handler for deleting a media file
221
+ */
222
+ declare function handleDeleteMedia(adapter: MediaAdapter, id: string): Promise<void>;
223
+
224
+ /**
225
+ * Resolves media references in page sections.
226
+ * Walks section data fields and replaces media IDs (UUIDs) with public URLs.
227
+ *
228
+ * Convention: Fields named "image", "media", "photo", "thumbnail", "avatar", "icon"
229
+ * or ending with "_image", "_media", etc. are treated as media references.
230
+ *
231
+ * Missing media is resolved to null.
232
+ */
233
+ declare function resolveMediaReferences(sections: PageSection[], adapter: MediaAdapter): Promise<PageSection[]>;
234
+
235
+ declare class AuthError extends Error {
236
+ readonly code?: string | undefined;
237
+ readonly details?: string | undefined;
238
+ constructor(message: string, code?: string | undefined, details?: string | undefined);
239
+ }
240
+ interface SupabaseAuthAdapterConfig {
241
+ client: SupabaseClient;
242
+ }
243
+ declare class SupabaseAuthAdapter implements AuthAdapter {
244
+ private client;
245
+ constructor(config: SupabaseAuthAdapterConfig);
246
+ private mapSupabaseUser;
247
+ signInWithOAuth(input: SignInWithOAuthInput): Promise<OAuthResponse>;
248
+ signInWithPassword(input: SignInWithPasswordInput): Promise<AuthSession>;
249
+ signOut(_accessToken: string): Promise<void>;
250
+ verifySession(input: VerifySessionInput): Promise<AuthUser | null>;
251
+ refreshSession(refreshToken: string): Promise<AuthSession>;
252
+ getCurrentUser(accessToken: string): Promise<AuthUser | null>;
253
+ }
254
+ declare function createAuthAdapter(config: SupabaseAuthAdapterConfig): AuthAdapter;
255
+
256
+ declare class AuthValidationError extends Error {
257
+ constructor(message: string);
258
+ }
259
+ declare function handleSignInWithOAuth(adapter: AuthAdapter, input: SignInWithOAuthInput): Promise<OAuthResponse>;
260
+ declare function handleSignInWithPassword(adapter: AuthAdapter, input: SignInWithPasswordInput): Promise<AuthSession>;
261
+ declare function handleSignOut(adapter: AuthAdapter, accessToken: string): Promise<void>;
262
+ declare function handleVerifySession(adapter: AuthAdapter, input: VerifySessionInput): Promise<AuthUser>;
263
+ declare function handleRefreshSession(adapter: AuthAdapter, refreshToken: string): Promise<AuthSession>;
264
+ declare function handleGetCurrentUser(adapter: AuthAdapter, accessToken: string): Promise<AuthUser | null>;
265
+
266
+ interface AuthenticatedRequest {
267
+ user: AuthUser;
268
+ accessToken: string;
269
+ }
270
+ interface AuthMiddlewareConfig {
271
+ adapter: AuthAdapter;
272
+ extractToken?: (headers: Record<string, string | undefined>) => string | null;
273
+ }
274
+ declare function createAuthMiddleware(config: AuthMiddlewareConfig): (headers: Record<string, string | undefined>) => Promise<AuthenticatedRequest>;
275
+
276
+ /**
277
+ * Export response for a single page with resolved media URLs
278
+ */
279
+ interface PageExportResponse {
280
+ id: string;
281
+ slug: string;
282
+ pageType: string;
283
+ title: string;
284
+ sections: PageSection[];
285
+ createdAt: string;
286
+ updatedAt: string;
287
+ }
288
+ /**
289
+ * Export response for all pages
290
+ */
291
+ interface AllPagesExportResponse {
292
+ pages: PageExportResponse[];
293
+ exportedAt: string;
294
+ }
295
+ /**
296
+ * Export response for navigation structures
297
+ */
298
+ interface NavigationExportResponse {
299
+ id: string;
300
+ name: string;
301
+ items: NavigationItem[];
302
+ updatedAt: string;
303
+ }
304
+ /**
305
+ * Export response for all navigations
306
+ */
307
+ interface AllNavigationsExportResponse {
308
+ navigations: NavigationExportResponse[];
309
+ exportedAt: string;
310
+ }
311
+ /**
312
+ * Full site export response
313
+ */
314
+ interface SiteExportResponse {
315
+ pages: PageExportResponse[];
316
+ navigations: NavigationExportResponse[];
317
+ media: MediaExportEntry[];
318
+ exportedAt: string;
319
+ }
320
+ /**
321
+ * Media entry in site export
322
+ */
323
+ interface MediaExportEntry {
324
+ id: string;
325
+ filename: string;
326
+ url: string;
327
+ mimeType: string;
328
+ size: number;
329
+ createdAt: string;
330
+ }
331
+
332
+ /**
333
+ * Handler for GET /api/cms/export/pages/:slug
334
+ * Returns complete page JSON with resolved media URLs
335
+ */
336
+ declare function handleExportPage(storageAdapter: StorageAdapter, mediaAdapter: MediaAdapter, slug: string): Promise<{
337
+ data: PageExportResponse;
338
+ contentDisposition: string;
339
+ } | null>;
340
+ /**
341
+ * Handler for GET /api/cms/export/pages
342
+ * Returns all pages as JSON array with resolved media URLs
343
+ */
344
+ declare function handleExportAllPages(storageAdapter: StorageAdapter, mediaAdapter: MediaAdapter): Promise<{
345
+ data: AllPagesExportResponse;
346
+ contentDisposition: string;
347
+ }>;
348
+ /**
349
+ * Handler for GET /api/cms/export/navigation
350
+ * Returns all navigation structures as JSON
351
+ */
352
+ declare function handleExportNavigations(storageAdapter: StorageAdapter): Promise<{
353
+ data: AllNavigationsExportResponse;
354
+ contentDisposition: string;
355
+ }>;
356
+ /**
357
+ * Handler for GET /api/cms/export
358
+ * Returns complete site content (pages, navigation, media metadata) as JSON
359
+ */
360
+ declare function handleExportSite(storageAdapter: StorageAdapter, mediaAdapter: MediaAdapter): Promise<{
361
+ data: SiteExportResponse;
362
+ contentDisposition: string;
363
+ }>;
364
+
365
+ export { type AllNavigationsExportResponse, type AllPagesExportResponse, AuthAdapter, AuthError, type AuthMiddlewareConfig, AuthSession, AuthUser, AuthValidationError, type AuthenticatedRequest, CreateNavigationInput, CreatePageInput, type ListPagesOptions, MediaAdapter, MediaError, type MediaExportEntry, MediaFile, MediaFilter, MediaValidationError, Navigation, type NavigationExportResponse, NavigationItem, type NavigationResponse, OAuthResponse, Page, type PageExportResponse, PageFilter, type PageResponse, PageSection, SignInWithOAuthInput, SignInWithPasswordInput, type SiteExportResponse, StorageAdapter, StorageError, StorageValidationError, SupabaseAuthAdapter, type SupabaseAuthAdapterConfig, SupabaseMediaAdapter, type SupabaseMediaAdapterConfig, SupabaseStorageAdapter, type SupabaseStorageAdapterConfig, UpdateNavigationInput, UpdatePageInput, UploadMediaInput, VerifySessionInput, createAuthAdapter, createAuthMiddleware, createMediaAdapter, createStorageAdapter, ensureUniqueSlug, generateSlug, handleCreateNavigation, handleCreatePage, handleDeleteMedia, handleDeleteNavigation, handleDeletePage, handleExportAllPages, handleExportNavigations, handleExportPage, handleExportSite, handleGetCurrentUser, handleGetMedia, handleGetNavigation, handleGetPageBySlug, handleListMedia, handleListPages, handleRefreshSession, handleSignInWithOAuth, handleSignInWithPassword, handleSignOut, handleUpdateNavigation, handleUpdatePage, handleUploadMedia, handleVerifySession, resolveMediaReferences };