@structcms/api 0.1.0 → 0.1.1

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/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
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.cjs';
2
- export { m as ALLOWED_MIME_TYPES, n as AllowedMimeType } from './types-Zi0Iyow1.cjs';
1
+ import { S as StorageAdapter, P as Page, C as CreatePageInput$1, U as UpdatePageInput$1, a as PageFilter, N as Navigation, b as CreateNavigationInput$1, c as UpdateNavigationInput$1, 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-Cdui_Ets.cjs';
2
+ export { m as ALLOWED_DOCUMENT_MIME_TYPES, n as ALLOWED_MIME_TYPES, o as ALL_ALLOWED_MIME_TYPES, p as AllowedDocumentMimeType, q as AllowedMimeType, r as MAX_FILE_SIZE, s as MediaCategory } from './types-Cdui_Ets.cjs';
3
3
  import { SupabaseClient } from '@supabase/supabase-js';
4
+ import { z } from 'zod';
4
5
  export { SupabaseAdapterFactoryConfig, SupabaseAdapterFactoryStorageConfig, SupabaseAdapters, createSupabaseAdapters } from './supabase/index.cjs';
5
6
 
6
7
  /**
@@ -25,14 +26,14 @@ declare class SupabaseStorageAdapter implements StorageAdapter {
25
26
  constructor(config: SupabaseStorageAdapterConfig);
26
27
  getPage(slug: string): Promise<Page | null>;
27
28
  getPageById(id: string): Promise<Page | null>;
28
- createPage(input: CreatePageInput): Promise<Page>;
29
- updatePage(input: UpdatePageInput): Promise<Page>;
29
+ createPage(input: CreatePageInput$1): Promise<Page>;
30
+ updatePage(input: UpdatePageInput$1): Promise<Page>;
30
31
  deletePage(id: string): Promise<void>;
31
32
  listPages(filter?: PageFilter): Promise<Page[]>;
32
33
  getNavigation(name: string): Promise<Navigation | null>;
33
34
  getNavigationById(id: string): Promise<Navigation | null>;
34
- createNavigation(input: CreateNavigationInput): Promise<Navigation>;
35
- updateNavigation(input: UpdateNavigationInput): Promise<Navigation>;
35
+ createNavigation(input: CreateNavigationInput$1): Promise<Navigation>;
36
+ updateNavigation(input: UpdateNavigationInput$1): Promise<Navigation>;
36
37
  deleteNavigation(id: string): Promise<void>;
37
38
  listNavigations(): Promise<Navigation[]>;
38
39
  }
@@ -52,11 +53,11 @@ declare class StorageValidationError extends Error {
52
53
  * Handler for creating a new page
53
54
  * Generates a slug from the title if not provided and ensures uniqueness
54
55
  */
55
- declare function handleCreatePage(adapter: StorageAdapter, input: CreatePageInput): Promise<Page>;
56
+ declare function handleCreatePage(adapter: StorageAdapter, input: CreatePageInput$1): Promise<Page>;
56
57
  /**
57
58
  * Handler for updating an existing page
58
59
  */
59
- declare function handleUpdatePage(adapter: StorageAdapter, input: UpdatePageInput): Promise<Page>;
60
+ declare function handleUpdatePage(adapter: StorageAdapter, input: UpdatePageInput$1): Promise<Page>;
60
61
  /**
61
62
  * Handler for deleting a page by ID
62
63
  */
@@ -65,11 +66,11 @@ declare function handleDeletePage(adapter: StorageAdapter, id: string): Promise<
65
66
  * Handler for creating a new navigation
66
67
  * Validates that the name is non-empty and unique
67
68
  */
68
- declare function handleCreateNavigation(adapter: StorageAdapter, input: CreateNavigationInput): Promise<Navigation>;
69
+ declare function handleCreateNavigation(adapter: StorageAdapter, input: CreateNavigationInput$1): Promise<Navigation>;
69
70
  /**
70
71
  * Handler for updating an existing navigation
71
72
  */
72
- declare function handleUpdateNavigation(adapter: StorageAdapter, input: UpdateNavigationInput): Promise<Navigation>;
73
+ declare function handleUpdateNavigation(adapter: StorageAdapter, input: UpdateNavigationInput$1): Promise<Navigation>;
73
74
  /**
74
75
  * Handler for deleting a navigation by ID
75
76
  */
@@ -101,6 +102,157 @@ declare function generateSlug(title: string): string;
101
102
  */
102
103
  declare function ensureUniqueSlug(slug: string, existingSlugs: string[]): string;
103
104
 
105
+ /**
106
+ * Strip all HTML tags from a string (for plain text fields like titles, names)
107
+ */
108
+ declare function stripTags(value: string): string;
109
+
110
+ /**
111
+ * Schema for creating a new page
112
+ */
113
+ declare const CreatePageSchema: z.ZodObject<{
114
+ title: z.ZodString;
115
+ pageType: z.ZodString;
116
+ slug: z.ZodOptional<z.ZodString>;
117
+ sections: z.ZodOptional<z.ZodArray<z.ZodObject<{
118
+ id: z.ZodOptional<z.ZodString>;
119
+ type: z.ZodString;
120
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ type: string;
123
+ data: Record<string, unknown>;
124
+ id?: string | undefined;
125
+ }, {
126
+ type: string;
127
+ data: Record<string, unknown>;
128
+ id?: string | undefined;
129
+ }>, "many">>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ title: string;
132
+ pageType: string;
133
+ slug?: string | undefined;
134
+ sections?: {
135
+ type: string;
136
+ data: Record<string, unknown>;
137
+ id?: string | undefined;
138
+ }[] | undefined;
139
+ }, {
140
+ title: string;
141
+ pageType: string;
142
+ slug?: string | undefined;
143
+ sections?: {
144
+ type: string;
145
+ data: Record<string, unknown>;
146
+ id?: string | undefined;
147
+ }[] | undefined;
148
+ }>;
149
+ /**
150
+ * Schema for updating an existing page
151
+ */
152
+ declare const UpdatePageSchema: z.ZodObject<{
153
+ title: z.ZodOptional<z.ZodString>;
154
+ pageType: z.ZodOptional<z.ZodString>;
155
+ slug: z.ZodOptional<z.ZodOptional<z.ZodString>>;
156
+ sections: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
157
+ id: z.ZodOptional<z.ZodString>;
158
+ type: z.ZodString;
159
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
160
+ }, "strip", z.ZodTypeAny, {
161
+ type: string;
162
+ data: Record<string, unknown>;
163
+ id?: string | undefined;
164
+ }, {
165
+ type: string;
166
+ data: Record<string, unknown>;
167
+ id?: string | undefined;
168
+ }>, "many">>>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ slug?: string | undefined;
171
+ title?: string | undefined;
172
+ sections?: {
173
+ type: string;
174
+ data: Record<string, unknown>;
175
+ id?: string | undefined;
176
+ }[] | undefined;
177
+ pageType?: string | undefined;
178
+ }, {
179
+ slug?: string | undefined;
180
+ title?: string | undefined;
181
+ sections?: {
182
+ type: string;
183
+ data: Record<string, unknown>;
184
+ id?: string | undefined;
185
+ }[] | undefined;
186
+ pageType?: string | undefined;
187
+ }>;
188
+ /**
189
+ * Schema for creating a new navigation
190
+ */
191
+ declare const CreateNavigationSchema: z.ZodObject<{
192
+ name: z.ZodString;
193
+ items: z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">;
194
+ }, "strip", z.ZodTypeAny, {
195
+ name: string;
196
+ items: any[];
197
+ }, {
198
+ name: string;
199
+ items: any[];
200
+ }>;
201
+ /**
202
+ * Schema for updating an existing navigation
203
+ */
204
+ declare const UpdateNavigationSchema: z.ZodObject<{
205
+ name: z.ZodOptional<z.ZodString>;
206
+ items: z.ZodOptional<z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">>;
207
+ }, "strip", z.ZodTypeAny, {
208
+ name?: string | undefined;
209
+ items?: any[] | undefined;
210
+ }, {
211
+ name?: string | undefined;
212
+ items?: any[] | undefined;
213
+ }>;
214
+ /**
215
+ * Schema for sign in
216
+ */
217
+ declare const SignInSchema: z.ZodObject<{
218
+ email: z.ZodString;
219
+ password: z.ZodString;
220
+ }, "strip", z.ZodTypeAny, {
221
+ email: string;
222
+ password: string;
223
+ }, {
224
+ email: string;
225
+ password: string;
226
+ }>;
227
+ /**
228
+ * Schema for media upload
229
+ */
230
+ declare const MediaUploadSchema: z.ZodObject<{
231
+ filename: z.ZodString;
232
+ mimeType: z.ZodString;
233
+ size: z.ZodNumber;
234
+ data: z.ZodType<ArrayBuffer, z.ZodTypeDef, ArrayBuffer>;
235
+ }, "strip", z.ZodTypeAny, {
236
+ data: ArrayBuffer;
237
+ filename: string;
238
+ mimeType: string;
239
+ size: number;
240
+ }, {
241
+ data: ArrayBuffer;
242
+ filename: string;
243
+ mimeType: string;
244
+ size: number;
245
+ }>;
246
+ /**
247
+ * Type exports for TypeScript
248
+ */
249
+ type CreatePageInput = z.infer<typeof CreatePageSchema>;
250
+ type UpdatePageInput = z.infer<typeof UpdatePageSchema>;
251
+ type CreateNavigationInput = z.infer<typeof CreateNavigationSchema>;
252
+ type UpdateNavigationInput = z.infer<typeof UpdateNavigationSchema>;
253
+ type SignInInput = z.infer<typeof SignInSchema>;
254
+ type MediaUploadInput = z.infer<typeof MediaUploadSchema>;
255
+
104
256
  /**
105
257
  * Page response for delivery API
106
258
  * Dates are serialized as ISO strings for JSON transport
@@ -205,7 +357,7 @@ declare class MediaValidationError extends Error {
205
357
  }
206
358
  /**
207
359
  * Handler for uploading a media file
208
- * Validates the file type and delegates to the adapter
360
+ * Validates the file type, size, and delegates to the adapter
209
361
  */
210
362
  declare function handleUploadMedia(adapter: MediaAdapter, input: UploadMediaInput): Promise<MediaFile>;
211
363
  /**
@@ -273,6 +425,62 @@ interface AuthMiddlewareConfig {
273
425
  }
274
426
  declare function createAuthMiddleware(config: AuthMiddlewareConfig): (headers: Record<string, string | undefined>) => Promise<AuthenticatedRequest>;
275
427
 
428
+ /**
429
+ * Generates a cryptographically secure random CSRF token
430
+ * @returns A hex-encoded random token (32 bytes = 64 hex characters)
431
+ */
432
+ declare function generateCsrfToken(): string;
433
+ /**
434
+ * Validates CSRF tokens using double-submit cookie pattern
435
+ * Compares the token from the cookie with the token from the request header
436
+ *
437
+ * @param cookieToken - Token from the cookie
438
+ * @param headerToken - Token from the X-CSRF-Token header
439
+ * @returns true if tokens match and are valid, false otherwise
440
+ */
441
+ declare function validateCsrfToken(cookieToken: string | undefined, headerToken: string | undefined): boolean;
442
+
443
+ /**
444
+ * Configuration for rate limiter
445
+ */
446
+ interface RateLimiterConfig {
447
+ /** Time window in milliseconds */
448
+ windowMs: number;
449
+ /** Maximum number of requests allowed in the time window */
450
+ maxRequests: number;
451
+ }
452
+ /**
453
+ * Result of rate limit check
454
+ */
455
+ interface RateLimitResult {
456
+ /** Whether the request is allowed */
457
+ allowed: boolean;
458
+ /** Number of seconds to wait before retrying (only set if not allowed) */
459
+ retryAfter?: number;
460
+ }
461
+ /**
462
+ * Rate limiter using sliding window algorithm with in-memory storage
463
+ */
464
+ interface RateLimiter {
465
+ /**
466
+ * Check if a request from the given key is allowed
467
+ * @param key - Unique identifier for the requester (e.g., IP address, user ID)
468
+ * @returns Result indicating if request is allowed and retry time if not
469
+ */
470
+ check(key: string): RateLimitResult;
471
+ /**
472
+ * Reset the rate limit for a specific key
473
+ * @param key - The key to reset
474
+ */
475
+ reset(key: string): void;
476
+ }
477
+ /**
478
+ * Creates a new rate limiter instance
479
+ * @param config - Configuration for the rate limiter
480
+ * @returns A new RateLimiter instance
481
+ */
482
+ declare function createRateLimiter(config: RateLimiterConfig): RateLimiter;
483
+
276
484
  /**
277
485
  * Export response for a single page with resolved media URLs
278
486
  */
@@ -362,4 +570,25 @@ declare function handleExportSite(storageAdapter: StorageAdapter, mediaAdapter:
362
570
  contentDisposition: string;
363
571
  }>;
364
572
 
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 };
573
+ interface AuditEntry {
574
+ action: string;
575
+ entity: string;
576
+ entityId: string;
577
+ userId?: string;
578
+ timestamp: Date;
579
+ metadata?: Record<string, unknown>;
580
+ }
581
+ type AuditSink = (entry: AuditEntry) => void | Promise<void>;
582
+ declare function createAuditLogger(sink?: AuditSink): {
583
+ log: (entry: Omit<AuditEntry, "timestamp">) => Promise<void>;
584
+ };
585
+ interface WithAuditLogOptions {
586
+ action: string;
587
+ entity: string;
588
+ extractEntityId: (args: unknown[]) => string;
589
+ extractUserId?: (args: unknown[]) => string | undefined;
590
+ metadata?: (args: unknown[]) => Record<string, unknown> | undefined;
591
+ }
592
+ declare function withAuditLog<T extends (...args: any[]) => any>(handler: T, options: WithAuditLogOptions, sink?: AuditSink): T;
593
+
594
+ export { type AllNavigationsExportResponse, type AllPagesExportResponse, type AuditEntry, AuthAdapter, AuthError, type AuthMiddlewareConfig, AuthSession, AuthUser, AuthValidationError, type AuthenticatedRequest, CreateNavigationInput$1 as CreateNavigationInput, CreateNavigationSchema, type CreateNavigationInput as CreateNavigationSchemaType, CreatePageInput$1 as CreatePageInput, CreatePageSchema, type CreatePageInput as CreatePageSchemaType, type ListPagesOptions, MediaAdapter, MediaError, type MediaExportEntry, MediaFile, MediaFilter, MediaUploadSchema, type MediaUploadInput as MediaUploadSchemaType, MediaValidationError, Navigation, type NavigationExportResponse, NavigationItem, type NavigationResponse, OAuthResponse, Page, type PageExportResponse, PageFilter, type PageResponse, PageSection, type RateLimitResult, type RateLimiter, type RateLimiterConfig, type SignInInput, SignInSchema, SignInWithOAuthInput, SignInWithPasswordInput, type SiteExportResponse, StorageAdapter, StorageError, StorageValidationError, SupabaseAuthAdapter, type SupabaseAuthAdapterConfig, SupabaseMediaAdapter, type SupabaseMediaAdapterConfig, SupabaseStorageAdapter, type SupabaseStorageAdapterConfig, UpdateNavigationInput$1 as UpdateNavigationInput, UpdateNavigationSchema, type UpdateNavigationInput as UpdateNavigationSchemaType, UpdatePageInput$1 as UpdatePageInput, UpdatePageSchema, type UpdatePageInput as UpdatePageSchemaType, UploadMediaInput, VerifySessionInput, createAuditLogger, createAuthAdapter, createAuthMiddleware, createMediaAdapter, createRateLimiter, createStorageAdapter, ensureUniqueSlug, generateCsrfToken, 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, stripTags, validateCsrfToken, withAuditLog };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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';
1
+ import { S as StorageAdapter, P as Page, C as CreatePageInput$1, U as UpdatePageInput$1, a as PageFilter, N as Navigation, b as CreateNavigationInput$1, c as UpdateNavigationInput$1, 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-Cdui_Ets.js';
2
+ export { m as ALLOWED_DOCUMENT_MIME_TYPES, n as ALLOWED_MIME_TYPES, o as ALL_ALLOWED_MIME_TYPES, p as AllowedDocumentMimeType, q as AllowedMimeType, r as MAX_FILE_SIZE, s as MediaCategory } from './types-Cdui_Ets.js';
3
3
  import { SupabaseClient } from '@supabase/supabase-js';
4
+ import { z } from 'zod';
4
5
  export { SupabaseAdapterFactoryConfig, SupabaseAdapterFactoryStorageConfig, SupabaseAdapters, createSupabaseAdapters } from './supabase/index.js';
5
6
 
6
7
  /**
@@ -25,14 +26,14 @@ declare class SupabaseStorageAdapter implements StorageAdapter {
25
26
  constructor(config: SupabaseStorageAdapterConfig);
26
27
  getPage(slug: string): Promise<Page | null>;
27
28
  getPageById(id: string): Promise<Page | null>;
28
- createPage(input: CreatePageInput): Promise<Page>;
29
- updatePage(input: UpdatePageInput): Promise<Page>;
29
+ createPage(input: CreatePageInput$1): Promise<Page>;
30
+ updatePage(input: UpdatePageInput$1): Promise<Page>;
30
31
  deletePage(id: string): Promise<void>;
31
32
  listPages(filter?: PageFilter): Promise<Page[]>;
32
33
  getNavigation(name: string): Promise<Navigation | null>;
33
34
  getNavigationById(id: string): Promise<Navigation | null>;
34
- createNavigation(input: CreateNavigationInput): Promise<Navigation>;
35
- updateNavigation(input: UpdateNavigationInput): Promise<Navigation>;
35
+ createNavigation(input: CreateNavigationInput$1): Promise<Navigation>;
36
+ updateNavigation(input: UpdateNavigationInput$1): Promise<Navigation>;
36
37
  deleteNavigation(id: string): Promise<void>;
37
38
  listNavigations(): Promise<Navigation[]>;
38
39
  }
@@ -52,11 +53,11 @@ declare class StorageValidationError extends Error {
52
53
  * Handler for creating a new page
53
54
  * Generates a slug from the title if not provided and ensures uniqueness
54
55
  */
55
- declare function handleCreatePage(adapter: StorageAdapter, input: CreatePageInput): Promise<Page>;
56
+ declare function handleCreatePage(adapter: StorageAdapter, input: CreatePageInput$1): Promise<Page>;
56
57
  /**
57
58
  * Handler for updating an existing page
58
59
  */
59
- declare function handleUpdatePage(adapter: StorageAdapter, input: UpdatePageInput): Promise<Page>;
60
+ declare function handleUpdatePage(adapter: StorageAdapter, input: UpdatePageInput$1): Promise<Page>;
60
61
  /**
61
62
  * Handler for deleting a page by ID
62
63
  */
@@ -65,11 +66,11 @@ declare function handleDeletePage(adapter: StorageAdapter, id: string): Promise<
65
66
  * Handler for creating a new navigation
66
67
  * Validates that the name is non-empty and unique
67
68
  */
68
- declare function handleCreateNavigation(adapter: StorageAdapter, input: CreateNavigationInput): Promise<Navigation>;
69
+ declare function handleCreateNavigation(adapter: StorageAdapter, input: CreateNavigationInput$1): Promise<Navigation>;
69
70
  /**
70
71
  * Handler for updating an existing navigation
71
72
  */
72
- declare function handleUpdateNavigation(adapter: StorageAdapter, input: UpdateNavigationInput): Promise<Navigation>;
73
+ declare function handleUpdateNavigation(adapter: StorageAdapter, input: UpdateNavigationInput$1): Promise<Navigation>;
73
74
  /**
74
75
  * Handler for deleting a navigation by ID
75
76
  */
@@ -101,6 +102,157 @@ declare function generateSlug(title: string): string;
101
102
  */
102
103
  declare function ensureUniqueSlug(slug: string, existingSlugs: string[]): string;
103
104
 
105
+ /**
106
+ * Strip all HTML tags from a string (for plain text fields like titles, names)
107
+ */
108
+ declare function stripTags(value: string): string;
109
+
110
+ /**
111
+ * Schema for creating a new page
112
+ */
113
+ declare const CreatePageSchema: z.ZodObject<{
114
+ title: z.ZodString;
115
+ pageType: z.ZodString;
116
+ slug: z.ZodOptional<z.ZodString>;
117
+ sections: z.ZodOptional<z.ZodArray<z.ZodObject<{
118
+ id: z.ZodOptional<z.ZodString>;
119
+ type: z.ZodString;
120
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ type: string;
123
+ data: Record<string, unknown>;
124
+ id?: string | undefined;
125
+ }, {
126
+ type: string;
127
+ data: Record<string, unknown>;
128
+ id?: string | undefined;
129
+ }>, "many">>;
130
+ }, "strip", z.ZodTypeAny, {
131
+ title: string;
132
+ pageType: string;
133
+ slug?: string | undefined;
134
+ sections?: {
135
+ type: string;
136
+ data: Record<string, unknown>;
137
+ id?: string | undefined;
138
+ }[] | undefined;
139
+ }, {
140
+ title: string;
141
+ pageType: string;
142
+ slug?: string | undefined;
143
+ sections?: {
144
+ type: string;
145
+ data: Record<string, unknown>;
146
+ id?: string | undefined;
147
+ }[] | undefined;
148
+ }>;
149
+ /**
150
+ * Schema for updating an existing page
151
+ */
152
+ declare const UpdatePageSchema: z.ZodObject<{
153
+ title: z.ZodOptional<z.ZodString>;
154
+ pageType: z.ZodOptional<z.ZodString>;
155
+ slug: z.ZodOptional<z.ZodOptional<z.ZodString>>;
156
+ sections: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
157
+ id: z.ZodOptional<z.ZodString>;
158
+ type: z.ZodString;
159
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
160
+ }, "strip", z.ZodTypeAny, {
161
+ type: string;
162
+ data: Record<string, unknown>;
163
+ id?: string | undefined;
164
+ }, {
165
+ type: string;
166
+ data: Record<string, unknown>;
167
+ id?: string | undefined;
168
+ }>, "many">>>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ slug?: string | undefined;
171
+ title?: string | undefined;
172
+ sections?: {
173
+ type: string;
174
+ data: Record<string, unknown>;
175
+ id?: string | undefined;
176
+ }[] | undefined;
177
+ pageType?: string | undefined;
178
+ }, {
179
+ slug?: string | undefined;
180
+ title?: string | undefined;
181
+ sections?: {
182
+ type: string;
183
+ data: Record<string, unknown>;
184
+ id?: string | undefined;
185
+ }[] | undefined;
186
+ pageType?: string | undefined;
187
+ }>;
188
+ /**
189
+ * Schema for creating a new navigation
190
+ */
191
+ declare const CreateNavigationSchema: z.ZodObject<{
192
+ name: z.ZodString;
193
+ items: z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">;
194
+ }, "strip", z.ZodTypeAny, {
195
+ name: string;
196
+ items: any[];
197
+ }, {
198
+ name: string;
199
+ items: any[];
200
+ }>;
201
+ /**
202
+ * Schema for updating an existing navigation
203
+ */
204
+ declare const UpdateNavigationSchema: z.ZodObject<{
205
+ name: z.ZodOptional<z.ZodString>;
206
+ items: z.ZodOptional<z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">>;
207
+ }, "strip", z.ZodTypeAny, {
208
+ name?: string | undefined;
209
+ items?: any[] | undefined;
210
+ }, {
211
+ name?: string | undefined;
212
+ items?: any[] | undefined;
213
+ }>;
214
+ /**
215
+ * Schema for sign in
216
+ */
217
+ declare const SignInSchema: z.ZodObject<{
218
+ email: z.ZodString;
219
+ password: z.ZodString;
220
+ }, "strip", z.ZodTypeAny, {
221
+ email: string;
222
+ password: string;
223
+ }, {
224
+ email: string;
225
+ password: string;
226
+ }>;
227
+ /**
228
+ * Schema for media upload
229
+ */
230
+ declare const MediaUploadSchema: z.ZodObject<{
231
+ filename: z.ZodString;
232
+ mimeType: z.ZodString;
233
+ size: z.ZodNumber;
234
+ data: z.ZodType<ArrayBuffer, z.ZodTypeDef, ArrayBuffer>;
235
+ }, "strip", z.ZodTypeAny, {
236
+ data: ArrayBuffer;
237
+ filename: string;
238
+ mimeType: string;
239
+ size: number;
240
+ }, {
241
+ data: ArrayBuffer;
242
+ filename: string;
243
+ mimeType: string;
244
+ size: number;
245
+ }>;
246
+ /**
247
+ * Type exports for TypeScript
248
+ */
249
+ type CreatePageInput = z.infer<typeof CreatePageSchema>;
250
+ type UpdatePageInput = z.infer<typeof UpdatePageSchema>;
251
+ type CreateNavigationInput = z.infer<typeof CreateNavigationSchema>;
252
+ type UpdateNavigationInput = z.infer<typeof UpdateNavigationSchema>;
253
+ type SignInInput = z.infer<typeof SignInSchema>;
254
+ type MediaUploadInput = z.infer<typeof MediaUploadSchema>;
255
+
104
256
  /**
105
257
  * Page response for delivery API
106
258
  * Dates are serialized as ISO strings for JSON transport
@@ -205,7 +357,7 @@ declare class MediaValidationError extends Error {
205
357
  }
206
358
  /**
207
359
  * Handler for uploading a media file
208
- * Validates the file type and delegates to the adapter
360
+ * Validates the file type, size, and delegates to the adapter
209
361
  */
210
362
  declare function handleUploadMedia(adapter: MediaAdapter, input: UploadMediaInput): Promise<MediaFile>;
211
363
  /**
@@ -273,6 +425,62 @@ interface AuthMiddlewareConfig {
273
425
  }
274
426
  declare function createAuthMiddleware(config: AuthMiddlewareConfig): (headers: Record<string, string | undefined>) => Promise<AuthenticatedRequest>;
275
427
 
428
+ /**
429
+ * Generates a cryptographically secure random CSRF token
430
+ * @returns A hex-encoded random token (32 bytes = 64 hex characters)
431
+ */
432
+ declare function generateCsrfToken(): string;
433
+ /**
434
+ * Validates CSRF tokens using double-submit cookie pattern
435
+ * Compares the token from the cookie with the token from the request header
436
+ *
437
+ * @param cookieToken - Token from the cookie
438
+ * @param headerToken - Token from the X-CSRF-Token header
439
+ * @returns true if tokens match and are valid, false otherwise
440
+ */
441
+ declare function validateCsrfToken(cookieToken: string | undefined, headerToken: string | undefined): boolean;
442
+
443
+ /**
444
+ * Configuration for rate limiter
445
+ */
446
+ interface RateLimiterConfig {
447
+ /** Time window in milliseconds */
448
+ windowMs: number;
449
+ /** Maximum number of requests allowed in the time window */
450
+ maxRequests: number;
451
+ }
452
+ /**
453
+ * Result of rate limit check
454
+ */
455
+ interface RateLimitResult {
456
+ /** Whether the request is allowed */
457
+ allowed: boolean;
458
+ /** Number of seconds to wait before retrying (only set if not allowed) */
459
+ retryAfter?: number;
460
+ }
461
+ /**
462
+ * Rate limiter using sliding window algorithm with in-memory storage
463
+ */
464
+ interface RateLimiter {
465
+ /**
466
+ * Check if a request from the given key is allowed
467
+ * @param key - Unique identifier for the requester (e.g., IP address, user ID)
468
+ * @returns Result indicating if request is allowed and retry time if not
469
+ */
470
+ check(key: string): RateLimitResult;
471
+ /**
472
+ * Reset the rate limit for a specific key
473
+ * @param key - The key to reset
474
+ */
475
+ reset(key: string): void;
476
+ }
477
+ /**
478
+ * Creates a new rate limiter instance
479
+ * @param config - Configuration for the rate limiter
480
+ * @returns A new RateLimiter instance
481
+ */
482
+ declare function createRateLimiter(config: RateLimiterConfig): RateLimiter;
483
+
276
484
  /**
277
485
  * Export response for a single page with resolved media URLs
278
486
  */
@@ -362,4 +570,25 @@ declare function handleExportSite(storageAdapter: StorageAdapter, mediaAdapter:
362
570
  contentDisposition: string;
363
571
  }>;
364
572
 
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 };
573
+ interface AuditEntry {
574
+ action: string;
575
+ entity: string;
576
+ entityId: string;
577
+ userId?: string;
578
+ timestamp: Date;
579
+ metadata?: Record<string, unknown>;
580
+ }
581
+ type AuditSink = (entry: AuditEntry) => void | Promise<void>;
582
+ declare function createAuditLogger(sink?: AuditSink): {
583
+ log: (entry: Omit<AuditEntry, "timestamp">) => Promise<void>;
584
+ };
585
+ interface WithAuditLogOptions {
586
+ action: string;
587
+ entity: string;
588
+ extractEntityId: (args: unknown[]) => string;
589
+ extractUserId?: (args: unknown[]) => string | undefined;
590
+ metadata?: (args: unknown[]) => Record<string, unknown> | undefined;
591
+ }
592
+ declare function withAuditLog<T extends (...args: any[]) => any>(handler: T, options: WithAuditLogOptions, sink?: AuditSink): T;
593
+
594
+ export { type AllNavigationsExportResponse, type AllPagesExportResponse, type AuditEntry, AuthAdapter, AuthError, type AuthMiddlewareConfig, AuthSession, AuthUser, AuthValidationError, type AuthenticatedRequest, CreateNavigationInput$1 as CreateNavigationInput, CreateNavigationSchema, type CreateNavigationInput as CreateNavigationSchemaType, CreatePageInput$1 as CreatePageInput, CreatePageSchema, type CreatePageInput as CreatePageSchemaType, type ListPagesOptions, MediaAdapter, MediaError, type MediaExportEntry, MediaFile, MediaFilter, MediaUploadSchema, type MediaUploadInput as MediaUploadSchemaType, MediaValidationError, Navigation, type NavigationExportResponse, NavigationItem, type NavigationResponse, OAuthResponse, Page, type PageExportResponse, PageFilter, type PageResponse, PageSection, type RateLimitResult, type RateLimiter, type RateLimiterConfig, type SignInInput, SignInSchema, SignInWithOAuthInput, SignInWithPasswordInput, type SiteExportResponse, StorageAdapter, StorageError, StorageValidationError, SupabaseAuthAdapter, type SupabaseAuthAdapterConfig, SupabaseMediaAdapter, type SupabaseMediaAdapterConfig, SupabaseStorageAdapter, type SupabaseStorageAdapterConfig, UpdateNavigationInput$1 as UpdateNavigationInput, UpdateNavigationSchema, type UpdateNavigationInput as UpdateNavigationSchemaType, UpdatePageInput$1 as UpdatePageInput, UpdatePageSchema, type UpdatePageInput as UpdatePageSchemaType, UploadMediaInput, VerifySessionInput, createAuditLogger, createAuthAdapter, createAuthMiddleware, createMediaAdapter, createRateLimiter, createStorageAdapter, ensureUniqueSlug, generateCsrfToken, 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, stripTags, validateCsrfToken, withAuditLog };