@kyro-cms/core 0.12.15 → 0.12.17

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 (65) hide show
  1. package/README.md +1 -1
  2. package/dist/WebhookService-ByrpAI4d.d.ts +143 -0
  3. package/dist/WebhookService-i-Kl3dvf.d.cts +143 -0
  4. package/dist/api-handler-graphql.cjs +1 -1
  5. package/dist/api-handler-graphql.d.cts +6 -0
  6. package/dist/api-handler-graphql.d.ts +6 -0
  7. package/dist/api-handler-graphql.js +1 -1
  8. package/dist/api-handler-trpc.cjs +1 -1
  9. package/dist/api-handler-trpc.d.cts +5 -0
  10. package/dist/api-handler-trpc.d.ts +5 -0
  11. package/dist/api-handler-trpc.js +1 -1
  12. package/dist/api-handler.cjs +1 -1
  13. package/dist/api-handler.d.cts +7 -0
  14. package/dist/api-handler.d.ts +7 -0
  15. package/dist/api-handler.js +1 -1
  16. package/dist/base-iyJTfH-3.d.cts +74 -0
  17. package/dist/base-oUSURe4_.d.ts +74 -0
  18. package/dist/{chunk-IQYP3DDJ.cjs → chunk-BIJHVTNO.cjs} +2 -2
  19. package/dist/{chunk-NI7S5JMH.js → chunk-CIA3BVH3.js} +5 -5
  20. package/dist/{chunk-ZZIGN5PZ.js → chunk-I4ZACL66.js} +1 -1
  21. package/dist/{chunk-M5JUPA7G.cjs → chunk-LMIBASPC.cjs} +5 -5
  22. package/dist/{chunk-RY3BG3AN.cjs → chunk-RL36RMMG.cjs} +1 -1
  23. package/dist/{chunk-DTSYK7KK.js → chunk-YFRLT77I.js} +2 -2
  24. package/dist/cli/index.cjs +0 -0
  25. package/dist/cli/index.d.cts +1 -0
  26. package/dist/cli/index.d.ts +1 -0
  27. package/dist/client.d.cts +12 -0
  28. package/dist/client.d.ts +12 -0
  29. package/dist/drizzle/index.d.cts +169 -0
  30. package/dist/drizzle/index.d.ts +169 -0
  31. package/dist/fields/index.d.cts +7 -0
  32. package/dist/fields/index.d.ts +7 -0
  33. package/dist/graphql/index.d.cts +57 -0
  34. package/dist/graphql/index.d.ts +57 -0
  35. package/dist/index-Bz9JqRGI.d.cts +86 -0
  36. package/dist/index-Bz9JqRGI.d.ts +86 -0
  37. package/dist/index-DNy8jbA2.d.cts +282 -0
  38. package/dist/index-DVDMEql7.d.ts +282 -0
  39. package/dist/index.cjs +26 -19
  40. package/dist/index.d.cts +1446 -0
  41. package/dist/index.d.ts +1446 -0
  42. package/dist/index.js +26 -19
  43. package/dist/integration.d.cts +14 -0
  44. package/dist/integration.d.ts +14 -0
  45. package/dist/mongodb/index.d.cts +134 -0
  46. package/dist/mongodb/index.d.ts +134 -0
  47. package/dist/rest/index.cjs +1 -1
  48. package/dist/rest/index.d.cts +56 -0
  49. package/dist/rest/index.d.ts +56 -0
  50. package/dist/rest/index.js +1 -1
  51. package/dist/richtext-DrhORshE.d.cts +5 -0
  52. package/dist/richtext-DrhORshE.d.ts +5 -0
  53. package/dist/templates/index.d.cts +107 -0
  54. package/dist/templates/index.d.ts +107 -0
  55. package/dist/trpc/index.d.cts +142 -0
  56. package/dist/trpc/index.d.ts +142 -0
  57. package/dist/types-BcZiluXL.d.cts +569 -0
  58. package/dist/types-CpjuXbe7.d.cts +150 -0
  59. package/dist/types-CpjuXbe7.d.ts +150 -0
  60. package/dist/types-Dc8VAPhF.d.ts +569 -0
  61. package/dist/types-euTszc-1.d.cts +294 -0
  62. package/dist/types-euTszc-1.d.ts +294 -0
  63. package/dist/ws/index.d.cts +88 -0
  64. package/dist/ws/index.d.ts +88 -0
  65. package/package.json +24 -25
@@ -0,0 +1,1446 @@
1
+ import * as hono from 'hono';
2
+ import * as hono_types from 'hono/types';
3
+ import { S as StorageProvider, R as Registry } from './index-DNy8jbA2.cjs';
4
+ export { C as ConfigService, E as EmailConfig, a as StorageConfig, c as createRegistry, g as getRegistry, r as resetRegistry, b as resolveProvider } from './index-DNy8jbA2.cjs';
5
+ import { B as BaseAdapter, P as PluginManager, K as KyroConfig, j as User, R as Request$1, C as CollectionConfig, G as GlobalConfig, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, e as UpdateArgs, D as DeleteArgs, f as FindVersionsArgs, g as VersionRecord, h as CreateVersionArgs } from './types-BcZiluXL.cjs';
6
+ export { k as AccessArgs, l as AccessControl, m as AdapterConfig, A as AdminConfig, n as AnalyticsPlugin, a as AuthConfig, o as CollectionAccess, p as CollectionHooks, q as CommentsPlugin, r as CreateResult, s as FieldAccess, t as FieldHooks, u as GlobalAccess, v as GlobalHooks, H as Hook, w as HookArgs, I as ImageSize, i as KyroPlugin, x as PluginAPI, y as PluginHooks, z as ReviewsPlugin, S as SEOPlugin, U as UploadConfig, V as VersionConfig, W as WhereClause, E as WishlistPlugin, J as evaluateAccess, L as getWhereClause, M as mergeWhereClauses, N as presetPlugins, O as runFieldHooks, Q as runHooks } from './types-BcZiluXL.cjs';
7
+ import { KyroPubSub, KyroWSServer } from './ws/index.cjs';
8
+ export { PubSub, createWSServer } from './ws/index.cjs';
9
+ import { W as WebhookPayload, D as DeliveryResult, a as WebhookDelivery, b as WebhookConfig, c as DeliveryOptions, d as WebhookService } from './WebhookService-i-Kl3dvf.cjs';
10
+ export { A as ALL_WEBHOOK_EVENTS, C as CreateWebhookData, U as UpdateWebhookData, e as WEBHOOK_COLLECTION, f as WEBHOOK_DELIVERY_COLLECTION, g as WEBHOOK_EVENTS, h as WebhookEvent, i as WebhookTriggerResult, j as createWebhookService } from './WebhookService-i-Kl3dvf.cjs';
11
+ import { F as Field } from './types-euTszc-1.cjs';
12
+ export { A as ALL_FIELD_TYPES, a as ArrayField, B as BaseField, b as Block, e as BlocksField, v as COMPLEX_FIELD_TYPES, C as CheckboxField, f as CodeField, g as CollapsibleField, h as ColorField, D as DateField, E as EmailField, j as FieldAdmin, k as FieldType, G as GroupField, l as ImageField, J as JSONField, L as LAYOUT_FIELD_TYPES, M as MarkdownField, N as NumberField, x as PRIMITIVE_FIELD_TYPES, P as PasswordField, y as RELATIONAL_FIELD_TYPES, R as RadioField, m as RelationshipField, n as RichTextBlock, o as RichTextField, p as RowField, q as SelectField, T as TabsField, r as TextField, s as TextareaField, U as UploadField, V as ValidateOptions, O as isArrayField, Q as isBlocksField, W as isGroupField, Y as isImageField, Z as isLayoutField, _ as isNumberField, $ as isRelationshipField, a0 as isRichTextField, a1 as isSelectField, a2 as isTextField, a3 as isUploadField } from './types-euTszc-1.cjs';
13
+ import { ZodTypeAny, z } from 'zod';
14
+ export { z } from 'zod';
15
+ export { n as normalizeRichTextValue, r as renderRichText, a as richTextStyles } from './richtext-DrhORshE.cjs';
16
+ import { A as AbstractBaseAdapter } from './base-iyJTfH-3.cjs';
17
+ import { Dialect } from './drizzle/index.cjs';
18
+ export { DrizzleAdapter, PostgresAuthAdapter, collectionToDrizzleSchema, createDatabase, createDrizzleAdapter, fieldToDrizzleType, runMigrations, seedDefaultRoles } from './drizzle/index.cjs';
19
+ export { MongoDBAdapter, MongoDBAuthAdapter, createMongoDBAdapter } from './mongodb/index.cjs';
20
+ export { createContext, createCountProcedure, createCreateProcedure, createDeleteProcedure, createDynamicRouter, createFindByIDProcedure, createFindProcedure, createKyroServer, createUpdateProcedure } from './trpc/index.cjs';
21
+ export { buildGraphQLSchema, createGraphQLSchema } from './graphql/index.cjs';
22
+ export { createHonoApp, createRESTAPI } from './rest/index.cjs';
23
+ export { A as AdminStylingConfig, C as CSSGenerator, F as FieldStyling, S as StylingConfig, a as StylingMode, T as ThemeBorderRadius, b as ThemeColors, c as ThemeConfig, d as ThemeFonts, e as ThemeShadows, f as ThemeSpacing, g as createAdminStyling, h as defaultDarkTheme, i as defaultFieldStyling, j as defaultLightTheme, k as ecommerce2026Theme, l as generateCSSVariables, m as generateTailwindConfig } from './index-Bz9JqRGI.cjs';
24
+ import { d as AuditLog, e as AuditLogFilter, A as AuthAdapter, U as UserRole, c as AuthUser, S as Session, b as AuthTokenConfig, R as RegisterData, a as AuthResult, L as LoginCredentials, J as JWTPayload } from './types-CpjuXbe7.cjs';
25
+ export { f as AuditAction } from './types-CpjuXbe7.cjs';
26
+ export { TemplateConfig, allSettingsGlobals, blogCollections, blogGlobals, coreSettingsGlobals, createTemplateConfig, ecommerceCollections, ecommerceGlobals, kitchenSinkCollections, mediaCollections, minimalCollections, templateCollections } from './templates/index.cjs';
27
+ export { default as kyro } from './integration.cjs';
28
+ import { Loader } from 'astro/loaders';
29
+ import { Redis } from 'ioredis';
30
+ import 'ws';
31
+ import 'drizzle-orm/postgres-js';
32
+ import 'graphql';
33
+ import 'astro';
34
+
35
+ interface LocalStorageConfig {
36
+ uploadDir: string;
37
+ baseUrl?: string;
38
+ }
39
+ declare function createLocalStorage(config: LocalStorageConfig): StorageProvider;
40
+
41
+ declare function signPayload(payload: string, secret: string): string;
42
+ declare function generateWebhookSecret(): string;
43
+ declare function deliverWebhook(webhook: WebhookConfig, payload: WebhookPayload, options?: DeliveryOptions): Promise<DeliveryResult>;
44
+ declare function deliverWithRetry(webhook: WebhookConfig, payload: WebhookPayload, deliveryId: string, options?: DeliveryOptions): Promise<DeliveryResult>;
45
+ declare function buildDeliveryRecord(deliveryId: string, webhookId: string, event: string, payload: WebhookPayload, attempt: number, result: DeliveryResult): WebhookDelivery;
46
+ declare function createTestPayload(): WebhookPayload;
47
+
48
+ declare class AuditLogger {
49
+ private redis;
50
+ private prefix;
51
+ private retentionDays;
52
+ constructor(redis: Redis, retentionDays?: number, prefix?: string);
53
+ log(data: Omit<AuditLog, "id" | "timestamp">): Promise<string>;
54
+ get(id: string): Promise<AuditLog | null>;
55
+ query(filter?: AuditLogFilter): Promise<{
56
+ logs: AuditLog[];
57
+ total: number;
58
+ }>;
59
+ getRecent(limit?: number): Promise<AuditLog[]>;
60
+ getUserActivity(userId: string, limit?: number): Promise<AuditLog[]>;
61
+ getStats(startDate?: Date, endDate?: Date): Promise<{
62
+ totalEvents: number;
63
+ byAction: Record<string, number>;
64
+ successRate: number;
65
+ failedLogins: number;
66
+ uniqueUsers: Set<string>;
67
+ }>;
68
+ cleanup(): Promise<number>;
69
+ private getKeyForDate;
70
+ private getKeysForDateRange;
71
+ private matchesFilter;
72
+ private serializeLog;
73
+ private deserializeLog;
74
+ }
75
+ declare function createAuditContext(req: Request): {
76
+ ipAddress: string;
77
+ userAgent: string;
78
+ };
79
+
80
+ declare function applyCollectionOverrides(collections: CollectionConfig[], overrides?: Record<string, any>): void;
81
+ declare class Kyro {
82
+ registry: Registry;
83
+ db: BaseAdapter;
84
+ pubsub: KyroPubSub;
85
+ webhookService: WebhookService;
86
+ settings?: Record<string, any>;
87
+ pluginManager: PluginManager;
88
+ private wsServer?;
89
+ private config;
90
+ constructor(config: KyroConfig);
91
+ init(): Promise<void>;
92
+ loadSettings(): Promise<Record<string, any>>;
93
+ loadPluginState(): Promise<void>;
94
+ getREST(options?: {
95
+ user?: User;
96
+ req?: Request$1;
97
+ tenantId?: string;
98
+ }): hono.Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">;
99
+ getGraphQL(options?: {
100
+ user?: User;
101
+ req?: Request$1;
102
+ tenantId?: string;
103
+ }): {
104
+ fetch: (request: any, locals?: any) => Promise<Response>;
105
+ schema: any;
106
+ };
107
+ getTRPC(options?: {
108
+ user?: User;
109
+ req?: Request$1;
110
+ tenantId?: string;
111
+ }): {
112
+ fetch: (request: any, locals?: any) => Promise<Response>;
113
+ router: any;
114
+ };
115
+ getWS(): KyroWSServer | undefined;
116
+ startWebSocket(options?: {
117
+ port?: number;
118
+ requireAuth?: boolean;
119
+ verifyToken?: (token: string) => Promise<any>;
120
+ }): Promise<KyroWSServer | null>;
121
+ shutdown(): Promise<void>;
122
+ }
123
+ declare function createKyro(config: KyroConfig): Kyro;
124
+
125
+ declare class ConfigValidationError extends Error {
126
+ errors: string[];
127
+ constructor(errors: string[]);
128
+ }
129
+ declare function validateCollection(config: CollectionConfig): string[];
130
+ declare function validateGlobal(config: GlobalConfig): string[];
131
+ declare function validateFields(fields: Field[], context: string): string[];
132
+ declare function validateConfig(collections: CollectionConfig[], globals?: GlobalConfig[]): void;
133
+
134
+ declare function fieldToZod(field: Field): ZodTypeAny;
135
+ declare function collectionToZod(collection: CollectionConfig): ZodTypeAny;
136
+ declare function collectionToCreateZod(collection: CollectionConfig): ZodTypeAny;
137
+ declare function collectionToUpdateZod(collection: CollectionConfig): ZodTypeAny;
138
+ declare function collectionToWhereZod(collection: CollectionConfig): ZodTypeAny;
139
+ declare function globalToZod(global: GlobalConfig): ZodTypeAny;
140
+
141
+ type DatabaseType$1 = 'postgres' | 'sqlite' | 'mongodb';
142
+ interface DatabaseConnectionOptions {
143
+ type: DatabaseType$1;
144
+ host?: string;
145
+ port?: number;
146
+ database?: string;
147
+ user?: string;
148
+ password?: string;
149
+ url?: string;
150
+ ssl?: boolean | Record<string, any>;
151
+ maxConnections?: number;
152
+ connectionTimeout?: number;
153
+ }
154
+ interface DrizzleAdapterOptions {
155
+ type?: 'postgres' | 'sqlite';
156
+ client?: any;
157
+ schema?: any;
158
+ connectionString?: string;
159
+ connectionOptions?: DatabaseConnectionOptions;
160
+ }
161
+ interface MongoDBAdapterOptions {
162
+ type: 'mongodb';
163
+ client?: any;
164
+ database?: string;
165
+ connectionString?: string;
166
+ connectionOptions?: DatabaseConnectionOptions;
167
+ }
168
+ type AdapterOptions = DrizzleAdapterOptions | MongoDBAdapterOptions;
169
+
170
+ declare class LocalAdapter extends AbstractBaseAdapter {
171
+ private db;
172
+ private path?;
173
+ private migrations;
174
+ private readonly versionsTableName;
175
+ constructor(options: {
176
+ db?: any;
177
+ path?: string;
178
+ });
179
+ connect(): Promise<void>;
180
+ disconnect(): Promise<void>;
181
+ private ensureTable;
182
+ private ensureVersionsTable;
183
+ private col;
184
+ private fieldToSQL;
185
+ private parseGlobalsSlug;
186
+ find<T>(args: FindArgs): Promise<FindResult<T>>;
187
+ findByID<T>(args: FindByIDArgs): Promise<T | null>;
188
+ create<T>(args: CreateArgs): Promise<T>;
189
+ update<T>(args: UpdateArgs): Promise<T>;
190
+ delete<T>(args: DeleteArgs): Promise<T>;
191
+ count(args: {
192
+ collection: string;
193
+ where?: Record<string, any>;
194
+ tenantId?: string;
195
+ }): Promise<number>;
196
+ findOne(args: {
197
+ collection: string;
198
+ where: Record<string, any>;
199
+ tenantId?: string;
200
+ draft?: boolean;
201
+ }): Promise<any>;
202
+ findVersions(args: FindVersionsArgs): Promise<FindResult<VersionRecord>>;
203
+ findVersionByID(args: {
204
+ collection: string;
205
+ versionId: string;
206
+ tenantId?: string;
207
+ }): Promise<VersionRecord | null>;
208
+ createVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
209
+ updateLatestVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
210
+ deleteVersions(args: {
211
+ collection: string;
212
+ documentId: string;
213
+ keepLatest?: number;
214
+ tenantId?: string;
215
+ }): Promise<void>;
216
+ private rowToVersion;
217
+ protected prepareData(data: Record<string, any>, config: CollectionConfig | GlobalConfig): Record<string, any>;
218
+ private rowToDoc;
219
+ private generateId;
220
+ private getMediaById;
221
+ private getTableNameFor;
222
+ migrate(): Promise<void>;
223
+ rollback(): Promise<void>;
224
+ transaction<T>(fn: (tx: any) => Promise<T>): Promise<T>;
225
+ getDatabase(): any;
226
+ exec(sql: string): void;
227
+ prepare(sql: string): any;
228
+ }
229
+ declare function createLocalAdapter(options?: {
230
+ db?: any;
231
+ path?: string;
232
+ }): LocalAdapter;
233
+
234
+ interface NeonAdapterOptions {
235
+ connectionString: string;
236
+ }
237
+ /**
238
+ * Edge-Native Neon HTTP PostgreSQL Database Adapter for Kyro CMS.
239
+ * Uses Web-standard `fetch` HTTP requests to execute SQL queries on V8 Edge Isolates.
240
+ */
241
+ declare class NeonAdapter extends AbstractBaseAdapter {
242
+ private connectionString;
243
+ constructor(options: NeonAdapterOptions);
244
+ connect(): Promise<void>;
245
+ disconnect(): Promise<void>;
246
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
247
+ find(args: any): Promise<any>;
248
+ findByID(args: any): Promise<any>;
249
+ create(args: any): Promise<any>;
250
+ update(args: any): Promise<any>;
251
+ delete(args: any): Promise<any>;
252
+ count(args: {
253
+ collection: string;
254
+ where?: Record<string, any>;
255
+ tenantId?: string;
256
+ }): Promise<number>;
257
+ findOne(args: {
258
+ collection: string;
259
+ where: Record<string, any>;
260
+ tenantId?: string;
261
+ draft?: boolean;
262
+ }): Promise<any>;
263
+ findVersions(args: any): Promise<any>;
264
+ findVersionByID(args: {
265
+ collection: string;
266
+ versionId: string;
267
+ tenantId?: string;
268
+ }): Promise<any>;
269
+ createVersion<T = Record<string, any>>(args: any): Promise<any>;
270
+ updateLatestVersion<T = Record<string, any>>(args: any): Promise<any>;
271
+ deleteVersions(args: {
272
+ collection: string;
273
+ documentId: string;
274
+ keepLatest?: number;
275
+ tenantId?: string;
276
+ }): Promise<void>;
277
+ }
278
+ declare function createNeonAdapter(options: NeonAdapterOptions): NeonAdapter;
279
+
280
+ interface TursoAdapterOptions {
281
+ url: string;
282
+ authToken?: string;
283
+ }
284
+ /**
285
+ * Edge-Native Turso / libSQL HTTP Database Adapter for Kyro CMS.
286
+ * Executes SQL queries over Web-standard `fetch` HTTP requests on V8 Edge Isolates.
287
+ */
288
+ declare class TursoAdapter extends AbstractBaseAdapter {
289
+ private url;
290
+ private authToken?;
291
+ constructor(options: TursoAdapterOptions);
292
+ connect(): Promise<void>;
293
+ disconnect(): Promise<void>;
294
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
295
+ find(args: any): Promise<any>;
296
+ findByID(args: any): Promise<any>;
297
+ create(args: any): Promise<any>;
298
+ update(args: any): Promise<any>;
299
+ delete(args: any): Promise<any>;
300
+ count(args: {
301
+ collection: string;
302
+ where?: Record<string, any>;
303
+ tenantId?: string;
304
+ }): Promise<number>;
305
+ findOne(args: {
306
+ collection: string;
307
+ where: Record<string, any>;
308
+ tenantId?: string;
309
+ draft?: boolean;
310
+ }): Promise<any>;
311
+ findVersions(args: any): Promise<any>;
312
+ findVersionByID(args: {
313
+ collection: string;
314
+ versionId: string;
315
+ tenantId?: string;
316
+ }): Promise<any>;
317
+ createVersion<T = Record<string, any>>(args: any): Promise<any>;
318
+ updateLatestVersion<T = Record<string, any>>(args: any): Promise<any>;
319
+ deleteVersions(args: {
320
+ collection: string;
321
+ documentId: string;
322
+ keepLatest?: number;
323
+ tenantId?: string;
324
+ }): Promise<void>;
325
+ }
326
+ declare function createTursoAdapter(options: TursoAdapterOptions): TursoAdapter;
327
+
328
+ interface RedisAuthAdapterOptions {
329
+ url?: string;
330
+ host?: string;
331
+ port?: number;
332
+ password?: string;
333
+ db?: number;
334
+ keyPrefix?: string;
335
+ tokenExpiration?: number;
336
+ refreshTokenExpiration?: number;
337
+ tls?: boolean;
338
+ }
339
+ declare class RedisAuthAdapter implements AuthAdapter {
340
+ private _redis;
341
+ private prefix;
342
+ private tokenExpiration;
343
+ private refreshExpiration;
344
+ private options;
345
+ constructor(options?: RedisAuthAdapterOptions);
346
+ private getRedis;
347
+ connect(): Promise<void>;
348
+ disconnect(): Promise<void>;
349
+ private userKey;
350
+ private sessionKey;
351
+ private refreshKey;
352
+ private userByEmailKey;
353
+ private passwordHistoryKey;
354
+ createUser(data: {
355
+ email: string;
356
+ password: string;
357
+ role?: UserRole;
358
+ tenantId?: string;
359
+ }): Promise<AuthUser>;
360
+ findUserByEmail(email: string): Promise<AuthUser | null>;
361
+ findUserById(userId: string): Promise<AuthUser | null>;
362
+ updateUser(userId: string, data: Partial<AuthUser>): Promise<AuthUser | null>;
363
+ deleteUser(userId: string): Promise<boolean>;
364
+ hashPassword(password: string): Promise<string>;
365
+ verifyPassword(email: string, password: string): Promise<AuthUser | null>;
366
+ createSession(userId: string, data?: {
367
+ ipAddress?: string;
368
+ userAgent?: string;
369
+ }): Promise<Session>;
370
+ findSessionByToken(token: string): Promise<Session | null>;
371
+ findSessionByRefreshToken(refreshToken: string): Promise<Session | null>;
372
+ deleteSession(sessionId: string): Promise<boolean>;
373
+ deleteUserSessions(userId: string): Promise<number>;
374
+ addPasswordToHistory(userId: string, passwordHash: string): Promise<void>;
375
+ getPasswordHistory(userId: string, count?: number): Promise<string[]>;
376
+ isPasswordInHistory(password: string, userId: string, historyCount?: number): Promise<boolean>;
377
+ private userToHash;
378
+ private hashToUser;
379
+ private sessionToHash;
380
+ private hashToSession;
381
+ private tokenKey;
382
+ createEmailVerificationToken(userId: string): Promise<{
383
+ token: string;
384
+ expiresAt: Date;
385
+ }>;
386
+ verifyEmailToken(token: string): Promise<{
387
+ success: boolean;
388
+ userId?: string;
389
+ error?: string;
390
+ }>;
391
+ createPasswordResetToken(email: string): Promise<{
392
+ token: string;
393
+ expiresAt: Date;
394
+ error?: string;
395
+ }>;
396
+ resetPasswordWithToken(token: string, newPassword: string): Promise<{
397
+ success: boolean;
398
+ error?: string;
399
+ }>;
400
+ private auditLogKey;
401
+ private auditLogIndexKey;
402
+ findAuditLogs(filter: {
403
+ userId?: string;
404
+ action?: string | string[];
405
+ resource?: string;
406
+ success?: boolean;
407
+ limit?: number;
408
+ offset?: number;
409
+ }): Promise<{
410
+ logs: any[];
411
+ total: number;
412
+ }>;
413
+ createAuditLog(data: any): Promise<any>;
414
+ }
415
+
416
+ interface EmailConfig {
417
+ provider: "smtp" | "resend" | "sendgrid" | "mailgun" | "ses";
418
+ from: string;
419
+ fromName?: string;
420
+ replyTo?: string;
421
+ smtp?: {
422
+ host: string;
423
+ port: number;
424
+ secure: boolean;
425
+ auth: {
426
+ user: string;
427
+ pass: string;
428
+ };
429
+ };
430
+ resend?: {
431
+ apiKey: string;
432
+ };
433
+ sendgrid?: {
434
+ apiKey: string;
435
+ };
436
+ mailgun?: {
437
+ apiKey: string;
438
+ domain: string;
439
+ region?: "us" | "eu";
440
+ };
441
+ ses?: {
442
+ accessKeyId: string;
443
+ secretAccessKey: string;
444
+ region: string;
445
+ };
446
+ }
447
+ interface EmailOptions {
448
+ to: string | string[];
449
+ subject: string;
450
+ html: string;
451
+ text?: string;
452
+ replyTo?: string;
453
+ }
454
+ interface EmailTemplates {
455
+ verifyEmail: (link: string, userName?: string) => {
456
+ subject: string;
457
+ html: string;
458
+ text: string;
459
+ };
460
+ resetPassword: (link: string, userName?: string) => {
461
+ subject: string;
462
+ html: string;
463
+ text: string;
464
+ };
465
+ welcome: (userName?: string) => {
466
+ subject: string;
467
+ html: string;
468
+ text: string;
469
+ };
470
+ accountLocked: (attempts: number, duration: number, userName?: string) => {
471
+ subject: string;
472
+ html: string;
473
+ text: string;
474
+ };
475
+ passwordChanged: (userName?: string) => {
476
+ subject: string;
477
+ html: string;
478
+ text: string;
479
+ };
480
+ newLogin: (location: string, time: string, userName?: string) => {
481
+ subject: string;
482
+ html: string;
483
+ text: string;
484
+ };
485
+ }
486
+ declare class EmailTransport {
487
+ private transporter?;
488
+ private config;
489
+ private templates;
490
+ private transporterInitialized;
491
+ constructor(config: EmailConfig, templates?: Partial<EmailTemplates>);
492
+ private ensureTransporter;
493
+ send(options: EmailOptions): Promise<any>;
494
+ private sendViaResend;
495
+ private sendViaSendGrid;
496
+ private sendViaMailgun;
497
+ getTemplates(): EmailTemplates;
498
+ verifyConnection(): Promise<boolean>;
499
+ static fromConfig(db: any): Promise<EmailTransport | null>;
500
+ static fromEnv(): EmailTransport | null;
501
+ }
502
+
503
+ interface BootstrapConfig {
504
+ authAdapter?: AuthAdapter;
505
+ authDbPath?: string;
506
+ adminEmail: string;
507
+ adminPassword: string;
508
+ adminRole?: string;
509
+ tenantId?: string;
510
+ emailConfig?: EmailConfig;
511
+ sendWelcomeEmail?: boolean;
512
+ }
513
+ interface BootstrapResult {
514
+ success: boolean;
515
+ user?: AuthUser;
516
+ error?: string;
517
+ }
518
+ declare function bootstrapAdmin(config: BootstrapConfig): Promise<BootstrapResult>;
519
+ declare function getBootstrapFromEnv(): BootstrapConfig | null;
520
+ declare function autoBootstrap(authAdapter?: AuthAdapter): Promise<BootstrapResult | null>;
521
+ declare function bootstrapWithRetry(config: BootstrapConfig, maxRetries?: number, retryDelayMs?: number): Promise<BootstrapResult>;
522
+
523
+ interface PasswordPolicyConfig {
524
+ minLength: number;
525
+ requireUppercase: boolean;
526
+ requireLowercase: boolean;
527
+ requireNumbers: boolean;
528
+ requireSpecialChars: boolean;
529
+ preventReuse: number;
530
+ maxLength?: number;
531
+ }
532
+ interface ValidationResult {
533
+ valid: boolean;
534
+ errors: string[];
535
+ }
536
+ declare class PasswordPolicy {
537
+ private config;
538
+ constructor(config?: Partial<PasswordPolicyConfig>);
539
+ validate(password: string): ValidationResult;
540
+ checkReuse(passwordHash: string, history: string[], verifyFn: (password: string, hash: string) => Promise<boolean>): Promise<ValidationResult>;
541
+ isInHistory(password: string, history: string[], verifyFn: (password: string, hash: string) => Promise<boolean>): Promise<boolean>;
542
+ generatePassword(length?: number): string;
543
+ getStrength(password: string): {
544
+ score: number;
545
+ label: string;
546
+ feedback: string[];
547
+ };
548
+ setConfig(config: Partial<PasswordPolicyConfig>): void;
549
+ getConfig(): PasswordPolicyConfig;
550
+ }
551
+
552
+ interface LockoutConfig {
553
+ maxAttempts: number;
554
+ lockDuration: number;
555
+ notifyUser: boolean;
556
+ notifyAdmin: boolean;
557
+ adminNotifyAfter: number;
558
+ }
559
+ interface LockoutStatus {
560
+ locked: boolean;
561
+ attemptsRemaining: number;
562
+ lockedUntil?: Date;
563
+ totalAttempts: number;
564
+ }
565
+ declare class AccountLockout {
566
+ private redis;
567
+ private prefix;
568
+ private config;
569
+ constructor(redis: Redis, config?: Partial<LockoutConfig>, prefix?: string);
570
+ private lockKey;
571
+ private historyKey;
572
+ checkLockout(userId: string): Promise<LockoutStatus>;
573
+ recordFailedAttempt(userId: string): Promise<LockoutStatus>;
574
+ lockAccount(userId: string, duration?: number): Promise<void>;
575
+ unlockAccount(userId: string): Promise<void>;
576
+ resetAttempts(userId: string): Promise<void>;
577
+ getLockoutHistory(userId: string, limit?: number): Promise<Date[]>;
578
+ getLockoutStats(userId: string): Promise<{
579
+ totalFailedAttempts: number;
580
+ lockoutCount: number;
581
+ lastLockout: Date | null;
582
+ averageAttemptsBeforeLockout: number;
583
+ }>;
584
+ shouldNotifyAdmin(currentAttempts: number): boolean;
585
+ getConfig(): LockoutConfig;
586
+ setConfig(config: Partial<LockoutConfig>): void;
587
+ }
588
+
589
+ interface RateLimitConfig {
590
+ window: number;
591
+ max: number;
592
+ }
593
+ interface RateLimitResult {
594
+ allowed: boolean;
595
+ remaining: number;
596
+ resetAt: number;
597
+ retryAfter?: number;
598
+ }
599
+ declare class RateLimiter {
600
+ private redis;
601
+ private prefix;
602
+ private limits;
603
+ private userLimits;
604
+ constructor(redis: Redis, limits?: Record<string, RateLimitConfig>, userLimits?: Record<string, RateLimitConfig>, prefix?: string);
605
+ private getKey;
606
+ check(type: string, identifier: string): Promise<RateLimitResult>;
607
+ checkUser(type: string, userId: string, identifier: string): Promise<RateLimitResult>;
608
+ reset(type: string, identifier: string): Promise<void>;
609
+ resetUser(type: string, userId: string, identifier: string): Promise<void>;
610
+ getStatus(type: string, identifier: string): Promise<{
611
+ count: number;
612
+ limit: number;
613
+ remaining: number;
614
+ resetAt: number;
615
+ }>;
616
+ setLimit(type: string, config: RateLimitConfig): void;
617
+ setUserLimit(type: string, config: RateLimitConfig): void;
618
+ }
619
+
620
+ declare class InMemoryRateLimiter {
621
+ private storage;
622
+ private userStorage;
623
+ private limits;
624
+ private userLimits;
625
+ constructor(limits?: Record<string, RateLimitConfig>, userLimits?: Record<string, RateLimitConfig>);
626
+ private getKey;
627
+ private getUserKey;
628
+ private cleanupOldEntries;
629
+ check(type: string, identifier: string): Promise<RateLimitResult>;
630
+ checkUser(type: string, userId: string, identifier: string): Promise<RateLimitResult>;
631
+ reset(type: string, identifier: string): Promise<void>;
632
+ resetUser(type: string, userId: string, identifier: string): Promise<void>;
633
+ getStatus(type: string, identifier: string): Promise<{
634
+ count: number;
635
+ limit: number;
636
+ remaining: number;
637
+ resetAt: number;
638
+ }>;
639
+ setLimit(type: string, config: RateLimitConfig): void;
640
+ setUserLimit(type: string, config: RateLimitConfig): void;
641
+ }
642
+
643
+ declare class InMemoryAccountLockout {
644
+ private storage;
645
+ private history;
646
+ private config;
647
+ constructor(config?: Partial<LockoutConfig>);
648
+ checkLockout(userId: string): Promise<LockoutStatus>;
649
+ recordFailedAttempt(userId: string): Promise<LockoutStatus>;
650
+ lockAccount(userId: string, duration?: number): Promise<void>;
651
+ unlockAccount(userId: string): Promise<void>;
652
+ resetAttempts(userId: string): Promise<void>;
653
+ getLockoutHistory(userId: string, limit?: number): Promise<Date[]>;
654
+ getLockoutStats(userId: string): Promise<{
655
+ totalFailedAttempts: number;
656
+ lockoutCount: number;
657
+ lastLockout: Date | null;
658
+ averageAttemptsBeforeLockout: number;
659
+ }>;
660
+ shouldNotifyAdmin(currentAttempts: number): boolean;
661
+ getConfig(): LockoutConfig;
662
+ setConfig(config: Partial<LockoutConfig>): void;
663
+ }
664
+
665
+ declare class InMemoryAuditLogger {
666
+ private logs;
667
+ private retentionDays;
668
+ constructor(retentionDays?: number);
669
+ log(data: Omit<AuditLog, "id" | "timestamp">): Promise<string>;
670
+ get(id: string): Promise<AuditLog | null>;
671
+ query(filter?: AuditLogFilter): Promise<{
672
+ logs: AuditLog[];
673
+ total: number;
674
+ }>;
675
+ getRecent(limit?: number): Promise<AuditLog[]>;
676
+ getUserActivity(userId: string, limit?: number): Promise<AuditLog[]>;
677
+ getStats(startDate?: Date, endDate?: Date): Promise<{
678
+ totalEvents: number;
679
+ byAction: Record<string, number>;
680
+ successRate: number;
681
+ failedLogins: number;
682
+ uniqueUsers: Set<string>;
683
+ }>;
684
+ cleanup(): Promise<number>;
685
+ private cleanupOldLogs;
686
+ }
687
+
688
+ interface AuthRoutesConfig {
689
+ redis: AuthAdapter;
690
+ jwtSecret?: string;
691
+ jwtExpiresIn?: string;
692
+ jwtIssuer?: string;
693
+ jwtAudience?: string;
694
+ email?: EmailTransport;
695
+ passwordPolicy?: PasswordPolicy;
696
+ lockout?: InMemoryAccountLockout;
697
+ rateLimiter?: InMemoryRateLimiter;
698
+ auditLogger?: InMemoryAuditLogger;
699
+ baseUrl?: string;
700
+ emailVerificationRequired?: boolean;
701
+ }
702
+ declare class AuthRoutes {
703
+ private authAdapter;
704
+ private email?;
705
+ private passwordPolicy;
706
+ private lockout?;
707
+ private rateLimiter?;
708
+ private auditLogger?;
709
+ private baseUrl;
710
+ private emailVerificationRequired;
711
+ constructor(config: AuthRoutesConfig);
712
+ register(req: Request): Promise<Response>;
713
+ login(req: Request): Promise<Response>;
714
+ logout(req: Request): Promise<Response>;
715
+ refresh(req: Request): Promise<Response>;
716
+ me(req: Request): Promise<Response>;
717
+ changePassword(req: Request): Promise<Response>;
718
+ forgotPassword(req: Request): Promise<Response>;
719
+ verifyEmail(req: Request): Promise<Response>;
720
+ private recordFailedLogin;
721
+ private sanitizeUser;
722
+ private jsonResponse;
723
+ listSessions(req: Request): Promise<Response>;
724
+ revokeSession(req: Request, sessionId: string): Promise<Response>;
725
+ revokeOtherSessions(req: Request): Promise<Response>;
726
+ renameSession(req: Request, sessionId: string): Promise<Response>;
727
+ refreshSession(req: Request): Promise<Response>;
728
+ private errorResponse;
729
+ private rateLimitResponse;
730
+ }
731
+
732
+ type DatabaseType = "sqlite" | "postgres" | "mongodb" | "memory";
733
+ interface KyroAuthConfig {
734
+ authAdapter: AuthAdapter;
735
+ databaseType?: string;
736
+ email?: EmailTransport;
737
+ passwordPolicy: PasswordPolicy;
738
+ lockout?: InMemoryAccountLockout;
739
+ rateLimiter?: InMemoryRateLimiter;
740
+ auditLogger?: InMemoryAuditLogger;
741
+ routes: AuthRoutes;
742
+ }
743
+ declare function createAuthConfig(databaseType?: string, db?: any): Promise<KyroAuthConfig>;
744
+ declare const authConfig: Promise<any>;
745
+
746
+ declare class InMemoryAuthAdapter implements AuthAdapter {
747
+ private users;
748
+ private sessions;
749
+ private refreshTokens;
750
+ private emailToUserId;
751
+ private passwordHistory;
752
+ private emailVerificationTokens;
753
+ private passwordResetTokens;
754
+ private auditLogs;
755
+ private externalDb;
756
+ constructor();
757
+ connect(): Promise<void>;
758
+ disconnect(): Promise<void>;
759
+ createUser(data: {
760
+ email: string;
761
+ password: string;
762
+ role?: UserRole;
763
+ tenantId?: string;
764
+ }): Promise<AuthUser>;
765
+ findUserByEmail(email: string): Promise<AuthUser | null>;
766
+ findUserById(userId: string): Promise<AuthUser | null>;
767
+ updateUser(userId: string, data: Partial<AuthUser>): Promise<AuthUser | null>;
768
+ deleteUser(userId: string): Promise<boolean>;
769
+ hashPassword(password: string): Promise<string>;
770
+ verifyPassword(email: string, password: string): Promise<AuthUser | null>;
771
+ createSession(userId: string, data?: {
772
+ ipAddress?: string;
773
+ userAgent?: string;
774
+ }): Promise<Session>;
775
+ findSessionByToken(token: string): Promise<Session | null>;
776
+ findSessionByRefreshToken(refreshToken: string): Promise<Session | null>;
777
+ deleteSession(sessionId: string): Promise<boolean>;
778
+ deleteUserSessions(userId: string): Promise<number>;
779
+ addPasswordToHistory(userId: string, passwordHash: string): Promise<void>;
780
+ getPasswordHistory(userId: string, count?: number): Promise<string[]>;
781
+ isPasswordInHistory(password: string, userId: string, historyCount?: number): Promise<boolean>;
782
+ createEmailVerificationToken(userId: string): Promise<{
783
+ token: string;
784
+ expiresAt: Date;
785
+ }>;
786
+ verifyEmailToken(token: string): Promise<{
787
+ success: boolean;
788
+ userId?: string;
789
+ error?: string;
790
+ }>;
791
+ createPasswordResetToken(email: string): Promise<{
792
+ token: string;
793
+ expiresAt: Date;
794
+ error?: string;
795
+ }>;
796
+ resetPasswordWithToken(token: string, newPassword: string): Promise<{
797
+ success: boolean;
798
+ error?: string;
799
+ }>;
800
+ hasAnyUsers(): Promise<boolean>;
801
+ findAuditLogs(filter: {
802
+ userId?: string;
803
+ action?: string | string[];
804
+ resource?: string;
805
+ success?: boolean;
806
+ limit?: number;
807
+ offset?: number;
808
+ }): Promise<{
809
+ logs: any[];
810
+ total: number;
811
+ }>;
812
+ createAuditLog(data: any): Promise<any>;
813
+ }
814
+
815
+ declare class Auth {
816
+ private adapter;
817
+ private config;
818
+ constructor(adapter: AuthAdapter, config: AuthTokenConfig);
819
+ register(data: RegisterData): Promise<AuthResult>;
820
+ login(credentials: LoginCredentials): Promise<AuthResult>;
821
+ logout(token: string): Promise<void>;
822
+ refreshToken(refreshToken: string): Promise<AuthResult>;
823
+ verifyToken(token: string): Promise<JWTPayload | null>;
824
+ getUserFromToken(token: string): Promise<AuthUser | null>;
825
+ changePassword(userId: string, currentPassword: string, newPassword: string): Promise<AuthResult>;
826
+ resetPassword(email: string, newPassword: string): Promise<AuthResult>;
827
+ sendEmailVerification(userId: string): Promise<{
828
+ success: boolean;
829
+ error?: string;
830
+ }>;
831
+ verifyEmail(token: string): Promise<{
832
+ success: boolean;
833
+ userId?: string;
834
+ error?: string;
835
+ }>;
836
+ requestPasswordReset(email: string): Promise<{
837
+ success: boolean;
838
+ error?: string;
839
+ }>;
840
+ resetPasswordWithToken(token: string, newPassword: string): Promise<{
841
+ success: boolean;
842
+ error?: string;
843
+ }>;
844
+ deleteAccount(userId: string): Promise<AuthResult>;
845
+ private createSessionForUser;
846
+ private generateToken;
847
+ private hashPassword;
848
+ private parseExpiresIn;
849
+ }
850
+ declare function createAuth(adapter: AuthAdapter, config: AuthTokenConfig): Auth;
851
+
852
+ interface SQLiteAuthAdapterOptions {
853
+ path?: string;
854
+ db?: any;
855
+ saltRounds?: number;
856
+ busyTimeout?: number;
857
+ walAutoCheckpoint?: number;
858
+ cacheSize?: number;
859
+ mmapSize?: number;
860
+ }
861
+ declare class SQLiteAuthAdapter implements AuthAdapter {
862
+ private db;
863
+ private path;
864
+ private saltRounds;
865
+ private externalDb;
866
+ private busyTimeout;
867
+ private walAutoCheckpoint;
868
+ private cacheSize;
869
+ private mmapSize;
870
+ private preparedStatements;
871
+ constructor(options?: SQLiteAuthAdapterOptions);
872
+ connect(): Promise<void>;
873
+ disconnect(): Promise<void>;
874
+ private ensureConnected;
875
+ private ensureTables;
876
+ private prepareStatements;
877
+ private stmt;
878
+ cleanupExpiredSessions(): Promise<number>;
879
+ cleanupOldAuditLogs(retentionDays?: number): Promise<number>;
880
+ getStats(): Promise<{
881
+ userCount: number;
882
+ activeSessionCount: number;
883
+ auditLogCount: number;
884
+ }>;
885
+ createUser(data: {
886
+ email: string;
887
+ password: string;
888
+ name?: string;
889
+ role?: UserRole;
890
+ avatar?: string;
891
+ tenantId?: string;
892
+ }): Promise<AuthUser>;
893
+ findUserByEmail(email: string): Promise<AuthUser | null>;
894
+ findUserById(userId: string): Promise<AuthUser | null>;
895
+ updateUser(userId: string, data: Partial<AuthUser>): Promise<AuthUser | null>;
896
+ deleteUser(userId: string): Promise<boolean>;
897
+ hashPassword(password: string): Promise<string>;
898
+ verifyPassword(email: string, password: string): Promise<AuthUser | null>;
899
+ createSession(userId: string, data?: {
900
+ ipAddress?: string;
901
+ userAgent?: string;
902
+ }): Promise<Session>;
903
+ findSessionByToken(token: string): Promise<Session | null>;
904
+ findSessionByRefreshToken(refreshToken: string): Promise<Session | null>;
905
+ deleteSession(sessionId: string): Promise<boolean>;
906
+ deleteUserSessions(userId: string): Promise<number>;
907
+ hasAnyUsers(): Promise<boolean>;
908
+ findUsers(options?: {
909
+ page?: number;
910
+ limit?: number;
911
+ search?: string;
912
+ }): Promise<{
913
+ users: AuthUser[];
914
+ total: number;
915
+ }>;
916
+ addPasswordToHistory(userId: string, passwordHash: string): Promise<void>;
917
+ getPasswordHistory(userId: string, count?: number): Promise<string[]>;
918
+ isPasswordInHistory(password: string, userId: string, historyCount?: number): Promise<boolean>;
919
+ recordFailedAttempt(userId: string): Promise<void>;
920
+ resetAttempts(userId: string): Promise<void>;
921
+ checkLockout(userId: string): Promise<{
922
+ locked: boolean;
923
+ attemptsRemaining: number;
924
+ lockedUntil?: Date;
925
+ totalAttempts: number;
926
+ }>;
927
+ logAudit(data: {
928
+ action: string;
929
+ userId?: string;
930
+ userEmail?: string;
931
+ role?: string;
932
+ resource: string;
933
+ resourceId?: string;
934
+ ipAddress?: string;
935
+ userAgent?: string;
936
+ success: boolean;
937
+ error?: string;
938
+ metadata?: Record<string, unknown>;
939
+ }): Promise<string>;
940
+ queryAuditLogs(options?: {
941
+ action?: string;
942
+ userId?: string;
943
+ resource?: string;
944
+ success?: boolean;
945
+ startDate?: Date;
946
+ endDate?: Date;
947
+ limit?: number;
948
+ offset?: number;
949
+ }): Promise<{
950
+ logs: Array<{
951
+ id: string;
952
+ timestamp: Date;
953
+ action: string;
954
+ userId?: string;
955
+ userEmail?: string;
956
+ resource: string;
957
+ resourceId?: string;
958
+ ipAddress?: string;
959
+ userAgent?: string;
960
+ success: boolean;
961
+ error?: string;
962
+ metadata?: Record<string, unknown>;
963
+ }>;
964
+ total: number;
965
+ }>;
966
+ private rowToUser;
967
+ private rowToSession;
968
+ findAuditLogs(filter: AuditLogFilter): Promise<{
969
+ logs: AuditLog[];
970
+ total: number;
971
+ }>;
972
+ createAuditLog(data: Omit<AuditLog, "id" | "timestamp">): Promise<AuditLog>;
973
+ createEmailVerificationToken(userId: string): Promise<{
974
+ token: string;
975
+ expiresAt: Date;
976
+ }>;
977
+ verifyEmailToken(token: string): Promise<{
978
+ success: boolean;
979
+ userId?: string;
980
+ error?: string;
981
+ }>;
982
+ createPasswordResetToken(email: string): Promise<{
983
+ token: string;
984
+ expiresAt: Date;
985
+ error?: string;
986
+ }>;
987
+ resetPasswordWithToken(token: string, newPassword: string): Promise<{
988
+ success: boolean;
989
+ error?: string;
990
+ }>;
991
+ }
992
+
993
+ type VersionStatus = 'draft' | 'published' | 'archived';
994
+ interface Version<T = Record<string, unknown>> {
995
+ id: string;
996
+ collection: string;
997
+ documentId: string;
998
+ version: number;
999
+ status: VersionStatus;
1000
+ data: T;
1001
+ createdBy: string;
1002
+ createdAt: Date;
1003
+ publishedAt?: Date;
1004
+ changeDescription?: string;
1005
+ }
1006
+ interface VersionDiff {
1007
+ field: string;
1008
+ oldValue: unknown;
1009
+ newValue: unknown;
1010
+ }
1011
+ interface VersionHistoryOptions {
1012
+ collection: string;
1013
+ documentId: string;
1014
+ limit?: number;
1015
+ offset?: number;
1016
+ }
1017
+ interface CreateVersionOptions<T = Record<string, unknown>> {
1018
+ collection: string;
1019
+ documentId: string;
1020
+ data: T;
1021
+ status?: VersionStatus;
1022
+ createdBy: string;
1023
+ changeDescription?: string;
1024
+ }
1025
+ interface PublishVersionOptions {
1026
+ collection: string;
1027
+ documentId: string;
1028
+ versionId: string;
1029
+ publishedBy: string;
1030
+ }
1031
+ interface CompareVersionsOptions {
1032
+ collection: string;
1033
+ documentId: string;
1034
+ versionA: string | number;
1035
+ versionB: string | number;
1036
+ }
1037
+ interface VersionAdapter {
1038
+ createVersion<T>(options: CreateVersionOptions<T>): Promise<Version<T>>;
1039
+ getVersion<T>(collection: string, versionId: string): Promise<Version<T> | null>;
1040
+ getVersions<T>(options: VersionHistoryOptions): Promise<Version<T>[]>;
1041
+ getLatestVersion<T>(collection: string, documentId: string): Promise<Version<T> | null>;
1042
+ getPublishedVersion<T>(collection: string, documentId: string): Promise<Version<T> | null>;
1043
+ publishVersion(options: PublishVersionOptions): Promise<void>;
1044
+ revertToVersion<T>(options: {
1045
+ collection: string;
1046
+ documentId: string;
1047
+ versionId: string;
1048
+ userId: string;
1049
+ }): Promise<Version<T>>;
1050
+ compareVersions<T>(options: CompareVersionsOptions): Promise<VersionDiff[]>;
1051
+ deleteVersions(collection: string, documentId: string): Promise<void>;
1052
+ }
1053
+ interface DraftPublishConfig {
1054
+ enabled?: boolean;
1055
+ draftsEnabled?: boolean;
1056
+ publishEnabled?: boolean;
1057
+ scheduleEnabled?: boolean;
1058
+ versioningEnabled?: boolean;
1059
+ maxVersionsPerDocument?: number;
1060
+ autoPublish?: boolean;
1061
+ requirePublishPermission?: boolean;
1062
+ }
1063
+ interface VersionPublishSchedule {
1064
+ versionId: string;
1065
+ scheduledFor: Date;
1066
+ status: 'pending' | 'published' | 'cancelled';
1067
+ }
1068
+ declare function getDefaultDraftPublishConfig(): Required<DraftPublishConfig>;
1069
+
1070
+ declare class VersionManager<T = Record<string, unknown>> {
1071
+ private adapter;
1072
+ private config;
1073
+ constructor(adapter: VersionAdapter, config?: DraftPublishConfig);
1074
+ createVersion(options: Omit<CreateVersionOptions<T>, 'version'>): Promise<Version<T>>;
1075
+ publishVersion(options: PublishVersionOptions): Promise<void>;
1076
+ unpublishDocument(collection: string, documentId: string): Promise<void>;
1077
+ revertToVersion(collection: string, documentId: string, versionId: string, userId: string): Promise<Version<T>>;
1078
+ getVersionHistory(collection: string, documentId: string, limit?: number, offset?: number): Promise<Version<T>[]>;
1079
+ compareTwoVersions(collection: string, documentId: string, versionA: string | number, versionB: string | number): Promise<VersionDiff[]>;
1080
+ getLatestDraft(collection: string, documentId: string): Promise<Version<T> | null>;
1081
+ getPublishedVersion(collection: string, documentId: string): Promise<Version<T> | null>;
1082
+ getVersion(collection: string, versionId: string): Promise<Version<T> | null>;
1083
+ schedulePublish(collection: string, documentId: string, versionId: string, scheduledFor: Date): Promise<void>;
1084
+ deleteVersionHistory(collection: string, documentId: string): Promise<void>;
1085
+ private pruneOldVersions;
1086
+ }
1087
+ declare function createVersionManager<T>(adapter: VersionAdapter, config?: DraftPublishConfig): VersionManager<T>;
1088
+ declare function isPublished(status: VersionStatus): boolean;
1089
+ declare function isDraft(status: VersionStatus): boolean;
1090
+ declare function isArchived(status: VersionStatus): boolean;
1091
+
1092
+ type ExtendedDialect = Dialect | "mongodb";
1093
+ interface MediaSearchParams {
1094
+ page?: number;
1095
+ limit?: number;
1096
+ search?: string;
1097
+ type?: string;
1098
+ folder?: string;
1099
+ sortBy?: string;
1100
+ sortDir?: "asc" | "desc";
1101
+ }
1102
+ interface MediaRow {
1103
+ id: string;
1104
+ filename: string;
1105
+ title: string | null;
1106
+ originalName: string;
1107
+ mimeType: string;
1108
+ fileSize: number;
1109
+ width: number | null;
1110
+ height: number | null;
1111
+ url: string;
1112
+ thumbnailUrl: string | null;
1113
+ folder: string | null;
1114
+ provider: string;
1115
+ alt: string | null;
1116
+ caption: string | null;
1117
+ metadata: string | null;
1118
+ createdAt: string;
1119
+ updatedAt: string;
1120
+ }
1121
+ declare class MediaService {
1122
+ private db;
1123
+ private storage;
1124
+ private dialect;
1125
+ private genId;
1126
+ private mediaTable;
1127
+ private foldersTable;
1128
+ constructor(db: any, storage: StorageProvider, options?: {
1129
+ dialect?: ExtendedDialect;
1130
+ genId?: () => string;
1131
+ });
1132
+ static init(db: any, options?: {
1133
+ dialect?: ExtendedDialect;
1134
+ genId?: () => string;
1135
+ storageConfig?: any;
1136
+ }): Promise<MediaService>;
1137
+ private ensureTables;
1138
+ private now;
1139
+ private buildFindConditions;
1140
+ private rowToMedia;
1141
+ static resolveMediaUrl(url: string | null | undefined, origin?: string): string | null;
1142
+ private sqliteRun;
1143
+ private sqliteGet;
1144
+ upload(file: File, folder?: string, origin?: string): Promise<MediaRow>;
1145
+ uploadFromUrl(url: string, folder?: string, origin?: string): Promise<MediaRow>;
1146
+ delete(id: string, origin?: string): Promise<void>;
1147
+ deleteFile(url: string): Promise<void>;
1148
+ rename(id: string, newKey: string, origin?: string): Promise<MediaRow | null>;
1149
+ findById(id: string, origin?: string): Promise<MediaRow | null>;
1150
+ find(params?: MediaSearchParams, origin?: string): Promise<{
1151
+ docs: MediaRow[];
1152
+ totalDocs: number;
1153
+ page: number;
1154
+ limit: number;
1155
+ totalPages: number;
1156
+ }>;
1157
+ update(id: string, data: {
1158
+ title?: string;
1159
+ alt?: string;
1160
+ caption?: string;
1161
+ folder?: string;
1162
+ metadata?: any;
1163
+ originalName?: string;
1164
+ }, origin?: string): Promise<MediaRow | null>;
1165
+ updateMany(ids: string[], data: {
1166
+ folder?: string;
1167
+ }): Promise<void>;
1168
+ listFolders(): Promise<string[]>;
1169
+ createFolder(name: string, parentPath?: string): Promise<void>;
1170
+ deleteFolder(folder: string): Promise<void>;
1171
+ }
1172
+
1173
+ declare function defineConfig(config: {
1174
+ collections?: CollectionConfig[] | Record<string, CollectionConfig>;
1175
+ globals?: GlobalConfig[] | Record<string, GlobalConfig>;
1176
+ adapter: KyroConfig["adapter"];
1177
+ plugins?: KyroConfig["plugins"];
1178
+ auth?: KyroConfig["auth"];
1179
+ cors?: KyroConfig["cors"];
1180
+ admin?: KyroConfig["admin"];
1181
+ upload?: KyroConfig["upload"];
1182
+ graphQL?: KyroConfig["graphQL"];
1183
+ typescript?: KyroConfig["typescript"];
1184
+ localization?: KyroConfig["localization"];
1185
+ rateLimit?: KyroConfig["rateLimit"];
1186
+ debug?: KyroConfig["debug"];
1187
+ }): KyroConfig;
1188
+ declare const defineKyroConfig: typeof defineConfig;
1189
+
1190
+ interface SeoTagsOptions {
1191
+ siteSettings: any;
1192
+ seoSettings?: any;
1193
+ title?: string;
1194
+ description?: string;
1195
+ image?: string;
1196
+ url?: string;
1197
+ }
1198
+ /**
1199
+ * Generates standard SEO meta tags based on global site settings and page overrides.
1200
+ */
1201
+ declare function generateSeoTags(options: SeoTagsOptions): string;
1202
+ /**
1203
+ * Generates analytics script tags based on global site settings.
1204
+ */
1205
+ declare function generateAnalyticsTags(siteSettings: any): string;
1206
+
1207
+ interface SocialLink {
1208
+ platform: string;
1209
+ url: string;
1210
+ label: string;
1211
+ }
1212
+ declare function getSocialLinksFromSettings(socialSettings: any): SocialLink[];
1213
+ declare function getSocialLinks(db: BaseAdapter, options?: {
1214
+ draft?: boolean;
1215
+ }): Promise<SocialLink[]>;
1216
+
1217
+ interface StoreConfig {
1218
+ storeName?: string;
1219
+ storeEmail?: string;
1220
+ storePhone?: string;
1221
+ address?: {
1222
+ street?: string;
1223
+ city?: string;
1224
+ state?: string;
1225
+ postalCode?: string;
1226
+ country?: string;
1227
+ };
1228
+ currency?: {
1229
+ code?: string;
1230
+ symbol?: string;
1231
+ position?: "before" | "after";
1232
+ decimals?: number;
1233
+ };
1234
+ tax?: {
1235
+ enabled?: boolean;
1236
+ rate?: number;
1237
+ includedInPrice?: boolean;
1238
+ taxId?: string;
1239
+ };
1240
+ shipping?: {
1241
+ enableLocalPickup?: boolean;
1242
+ flatRate?: number;
1243
+ freeShippingThreshold?: number;
1244
+ };
1245
+ orders?: {
1246
+ orderNumberPrefix?: string;
1247
+ allowGuestCheckout?: boolean;
1248
+ requirePhone?: boolean;
1249
+ };
1250
+ }
1251
+ declare function getStoreConfigFromSettings(settings: any): StoreConfig;
1252
+ declare function getStoreConfig(db: BaseAdapter, options?: {
1253
+ draft?: boolean;
1254
+ }): Promise<StoreConfig>;
1255
+
1256
+ interface PaymentConfig {
1257
+ testMode?: boolean;
1258
+ provider?: "stripe" | "paypal" | "square" | "manual";
1259
+ stripe?: {
1260
+ enabled?: boolean;
1261
+ publishableKey?: string;
1262
+ secretKey?: string;
1263
+ webhookSecret?: string;
1264
+ };
1265
+ paypal?: {
1266
+ enabled?: boolean;
1267
+ clientId?: string;
1268
+ clientSecret?: string;
1269
+ mode?: "sandbox" | "live";
1270
+ };
1271
+ square?: {
1272
+ enabled?: boolean;
1273
+ applicationId?: string;
1274
+ accessToken?: string;
1275
+ locationId?: string;
1276
+ };
1277
+ methods?: {
1278
+ cod?: boolean;
1279
+ bankTransfer?: boolean;
1280
+ cash?: boolean;
1281
+ check?: boolean;
1282
+ };
1283
+ bankTransfer?: {
1284
+ bankName?: string;
1285
+ accountName?: string;
1286
+ accountNumber?: string;
1287
+ routingNumber?: string;
1288
+ iban?: string;
1289
+ swift?: string;
1290
+ };
1291
+ }
1292
+ declare function getPaymentConfigFromSettings(settings: any): PaymentConfig;
1293
+ declare function getPaymentConfig(db: BaseAdapter, options?: {
1294
+ draft?: boolean;
1295
+ }): Promise<PaymentConfig>;
1296
+
1297
+ type StorageAdapter = 'indexeddb' | 'fs' | 'redis' | 'sqlite' | 'postgres';
1298
+ type Environment = 'browser' | 'node';
1299
+ interface EncryptionConfig {
1300
+ enabled: boolean;
1301
+ algorithm?: 'AES-256-GCM' | 'ChaCha20-Poly1305';
1302
+ }
1303
+ interface StorageConfig {
1304
+ environment: Environment;
1305
+ adapter?: StorageAdapter;
1306
+ connectionString?: string;
1307
+ encryption?: EncryptionConfig;
1308
+ }
1309
+ interface StorageOptions {
1310
+ namespace?: string;
1311
+ ttl?: number;
1312
+ }
1313
+ type CreateStorageResult = {
1314
+ storage: {
1315
+ getItem: (name: string) => string | null | Promise<string | null>;
1316
+ setItem: (name: string, value: string) => void | Promise<void>;
1317
+ removeItem: (name: string) => void | Promise<void>;
1318
+ };
1319
+ cleanup?: () => Promise<void>;
1320
+ };
1321
+
1322
+ declare function createStorage(config: StorageConfig): Promise<CreateStorageResult & {
1323
+ storage: _StateStorage;
1324
+ }>;
1325
+ type _StateStorage = {
1326
+ getItem: (name: string) => string | null | Promise<string | null>;
1327
+ setItem: (name: string, value: string) => void | Promise<void>;
1328
+ removeItem: (name: string) => void | Promise<void>;
1329
+ };
1330
+ declare function createAuthStorage(config: StorageConfig): Promise<CreateStorageResult>;
1331
+
1332
+ declare function setDbAdapter(adapter: any): void;
1333
+ declare function loadSecrets(): Promise<void>;
1334
+ declare function getAppSecret(): string;
1335
+ declare function getEncryptionKey(): string;
1336
+ declare function getSessionConfig(): {
1337
+ maxAge: number;
1338
+ maxSessionsPerUser: number;
1339
+ };
1340
+
1341
+ interface KyroLoaderOptions {
1342
+ collection: string;
1343
+ drafts?: boolean;
1344
+ limit?: number;
1345
+ configPath?: string;
1346
+ }
1347
+ /**
1348
+ * Native Astro 5+ Content Layer Loader for Kyro CMS.
1349
+ * Feeds Kyro CMS collection documents directly into Astro's `getCollection()` store.
1350
+ */
1351
+ declare function kyroLoader(options: KyroLoaderOptions): Loader;
1352
+
1353
+ interface KyroActionOptions<TInput extends z.ZodTypeAny> {
1354
+ collection: string;
1355
+ action: 'create' | 'update' | 'delete' | 'find';
1356
+ schema?: TInput;
1357
+ access?: 'public' | 'authenticated' | 'admin';
1358
+ }
1359
+ /**
1360
+ * Type-safe Astro Actions handler for Kyro CMS collections.
1361
+ * Automatically validates incoming form submissions or RPC inputs against collection schemas.
1362
+ */
1363
+ declare function kyroAction<TInput extends z.ZodTypeAny = z.ZodObject<any>>(options: KyroActionOptions<TInput>): {
1364
+ input: TInput | z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
1365
+ handler: (input: z.infer<TInput>, context: any) => Promise<{
1366
+ success: boolean;
1367
+ collection: string;
1368
+ action: "create" | "update" | "delete" | "find";
1369
+ data: z.TypeOf<TInput>;
1370
+ timestamp: string;
1371
+ error?: undefined;
1372
+ } | {
1373
+ success: boolean;
1374
+ error: any;
1375
+ collection?: undefined;
1376
+ action?: undefined;
1377
+ data?: undefined;
1378
+ timestamp?: undefined;
1379
+ }>;
1380
+ };
1381
+
1382
+ interface KyroAuthMiddlewareOptions {
1383
+ protectedRoutes?: string[];
1384
+ loginPath?: string;
1385
+ cookieName?: string;
1386
+ }
1387
+ /**
1388
+ * Native Astro Middleware for Kyro CMS authentication & session management.
1389
+ * Populates `Astro.locals.kyroUser` and handles protected route authorization.
1390
+ */
1391
+ declare function kyroAuthMiddleware(options?: KyroAuthMiddlewareOptions): (context: any, next: () => Promise<Response>) => Promise<any>;
1392
+
1393
+ /**
1394
+ * Helper to generate TypeScript declarations for Kyro CMS collections.
1395
+ * Can be invoked automatically during `npx astro sync` or dev server startup.
1396
+ */
1397
+ declare function generateKyroAstroTypes(config: Record<string, any>): string;
1398
+
1399
+ interface KyroEnvSchemaOptions {
1400
+ requireDatabase?: boolean;
1401
+ }
1402
+ /**
1403
+ * Type-safe environment variable schema helper for Astro 5 (`astro:env`).
1404
+ */
1405
+ declare function kyroEnvSchema(options?: KyroEnvSchemaOptions): {
1406
+ APP_SECRET: {
1407
+ context: "server";
1408
+ access: "secret";
1409
+ type: "string";
1410
+ optional: boolean;
1411
+ };
1412
+ DATABASE_URL: {
1413
+ context: "server";
1414
+ access: "secret";
1415
+ type: "string";
1416
+ optional: boolean;
1417
+ };
1418
+ PUBLIC_KYRO_URL: {
1419
+ context: "client";
1420
+ access: "public";
1421
+ type: "string";
1422
+ optional: boolean;
1423
+ default: string;
1424
+ };
1425
+ };
1426
+
1427
+ interface KyroDevToolbarOptions {
1428
+ enabled?: boolean;
1429
+ }
1430
+ /**
1431
+ * Astro Integration Hook helper to register the Kyro CMS Dev Toolbar widget.
1432
+ */
1433
+ declare function kyroDevToolbarIntegration(options?: KyroDevToolbarOptions): {
1434
+ name: string;
1435
+ hooks: {
1436
+ 'astro:config:setup': ({ addDevToolbarApp }: any) => void;
1437
+ };
1438
+ };
1439
+
1440
+ /**
1441
+ * Edge Runtime detection utility for Kyro CMS.
1442
+ * Detects V8 Isolate runtimes (Vercel Edge, Cloudflare Workers, Deno Deploy, Netlify Edge).
1443
+ */
1444
+ declare function isEdgeRuntime(): boolean;
1445
+
1446
+ export { AbstractBaseAdapter, AccountLockout, type AdapterOptions, AuditLog, AuditLogFilter, AuditLogger, Auth, AuthAdapter, AuthResult, Session as AuthSession, AuthTokenConfig, AuthUser, BaseAdapter, CollectionConfig, type CompareVersionsOptions, ConfigValidationError, CreateArgs, type CreateStorageResult, type CreateVersionOptions, type DatabaseConnectionOptions, type DatabaseType, type DatabaseType$1 as DbAdapterType, DeleteArgs, DeliveryOptions, DeliveryResult, Dialect, type DraftPublishConfig, type DrizzleAdapterOptions, EmailTransport, type EncryptionConfig, type Environment, Field, FindArgs, FindByIDArgs, FindResult, GlobalConfig, InMemoryAccountLockout, InMemoryAuditLogger, InMemoryAuthAdapter, InMemoryRateLimiter, JWTPayload, Kyro, type KyroActionOptions, type KyroAuthConfig, type KyroAuthMiddlewareOptions, KyroConfig, type KyroDevToolbarOptions, type KyroEnvSchemaOptions, type KyroLoaderOptions, KyroPubSub, KyroWSServer, LocalAdapter, LoginCredentials, MediaService, type MongoDBAdapterOptions, NeonAdapter, type NeonAdapterOptions, PasswordPolicy, type PaymentConfig, PluginManager, type PublishVersionOptions, RateLimiter, RedisAuthAdapter, RegisterData, Registry, Request$1 as Request, SQLiteAuthAdapter, type SeoTagsOptions, Session, type SocialLink, type StorageAdapter, type StorageOptions, type StoreConfig, TursoAdapter, type TursoAdapterOptions, UpdateArgs, User, UserRole, type Version, type VersionAdapter, type VersionDiff, type VersionHistoryOptions, VersionManager, type VersionPublishSchedule, type VersionStatus, WebhookConfig, WebhookDelivery, WebhookPayload, WebhookService, applyCollectionOverrides, authConfig, autoBootstrap, bootstrapAdmin, bootstrapWithRetry, buildDeliveryRecord, collectionToCreateZod, collectionToUpdateZod, collectionToWhereZod, collectionToZod, createAuditContext, createAuth, createAuthConfig, createAuthStorage, createKyro, createLocalAdapter, createLocalStorage, createNeonAdapter, createStorage, createTestPayload, createTursoAdapter, createVersionManager, defineConfig, defineKyroConfig, deliverWebhook, deliverWithRetry, fieldToZod, generateAnalyticsTags, generateKyroAstroTypes, generateSeoTags, generateWebhookSecret, getAppSecret, getBootstrapFromEnv, getDefaultDraftPublishConfig, getEncryptionKey, getPaymentConfig, getPaymentConfigFromSettings, getSessionConfig, getSocialLinks, getSocialLinksFromSettings, getStoreConfig, getStoreConfigFromSettings, globalToZod, isArchived, isDraft, isEdgeRuntime, isPublished, kyroAction, kyroAuthMiddleware, kyroDevToolbarIntegration, kyroEnvSchema, kyroLoader, loadSecrets, setDbAdapter, signPayload, validateCollection, validateConfig, validateFields, validateGlobal };