@iskra-bun/web-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +31 -0
  3. package/dist/chunk-POXNRNTC.js +51 -0
  4. package/dist/chunk-POXNRNTC.js.map +1 -0
  5. package/dist/index.d.ts +966 -0
  6. package/dist/index.js +2824 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/mailgun-Z46GZJNI.js +83 -0
  9. package/dist/mailgun-Z46GZJNI.js.map +1 -0
  10. package/dist/s3-7IG4ESFW.js +171 -0
  11. package/dist/s3-7IG4ESFW.js.map +1 -0
  12. package/dist/sendgrid-UK2GSBEF.js +43 -0
  13. package/dist/sendgrid-UK2GSBEF.js.map +1 -0
  14. package/dist/smtp-WJDLYKD5.js +50 -0
  15. package/dist/smtp-WJDLYKD5.js.map +1 -0
  16. package/package.json +74 -0
  17. package/src/driver.ts +55 -0
  18. package/src/errors.ts +66 -0
  19. package/src/features/api-key.ts +243 -0
  20. package/src/features/auth/better-auth-config.ts +160 -0
  21. package/src/features/auth/index.ts +229 -0
  22. package/src/features/auth/schema.ts +174 -0
  23. package/src/features/auth/types.ts +114 -0
  24. package/src/features/cache.ts +144 -0
  25. package/src/features/cors.ts +33 -0
  26. package/src/features/csrf.ts +94 -0
  27. package/src/features/db.ts +90 -0
  28. package/src/features/email/index.ts +103 -0
  29. package/src/features/email/providers/mailgun.ts +99 -0
  30. package/src/features/email/providers/sendgrid.ts +42 -0
  31. package/src/features/email/providers/smtp.ts +51 -0
  32. package/src/features/error-handler.ts +147 -0
  33. package/src/features/health.ts +94 -0
  34. package/src/features/json-schema-validation.ts +186 -0
  35. package/src/features/logger.ts +70 -0
  36. package/src/features/openapi.ts +107 -0
  37. package/src/features/permissions.ts +128 -0
  38. package/src/features/rate-limit.ts +173 -0
  39. package/src/features/request-id.ts +45 -0
  40. package/src/features/session.ts +322 -0
  41. package/src/features/storage/adapters/local.ts +133 -0
  42. package/src/features/storage/adapters/s3.ts +193 -0
  43. package/src/features/storage/base.ts +112 -0
  44. package/src/features/storage/index.ts +53 -0
  45. package/src/features/tracing.ts +49 -0
  46. package/src/features/upload/helper.ts +85 -0
  47. package/src/features/upload/index.ts +140 -0
  48. package/src/features/validation.ts +105 -0
  49. package/src/index.ts +29 -0
  50. package/src/kernel.ts +257 -0
  51. package/src/responses.ts +37 -0
  52. package/src/router.ts +31 -0
  53. package/src/server.ts +135 -0
  54. package/src/types.ts +272 -0
package/src/types.ts ADDED
@@ -0,0 +1,272 @@
1
+ import type { Kernel } from "./kernel";
2
+
3
+ export type { Kernel };
4
+
5
+ // Simplified Logger Sink interface to avoid dependency on logtape for now
6
+ export interface Sink {
7
+ (record: Record<string, unknown>): void;
8
+ }
9
+
10
+ export interface KernelConfig {
11
+ port?: number;
12
+ hostname?: string;
13
+ environment?: "development" | "production" | "test";
14
+ securityHeaders?: SecurityHeadersConfig; // Always applied, non-pluggable
15
+ }
16
+
17
+ export interface SecurityHeadersConfig {
18
+ contentSecurityPolicy?:
19
+ | string
20
+ | {
21
+ directives?: Record<string, string | string[]>;
22
+ };
23
+ xFrameOptions?: "DENY" | "SAMEORIGIN" | string;
24
+ xContentTypeOptions?: boolean;
25
+ strictTransportSecurity?: {
26
+ maxAge?: number;
27
+ includeSubDomains?: boolean;
28
+ preload?: boolean;
29
+ };
30
+ xXssProtection?: boolean;
31
+ referrerPolicy?:
32
+ | "no-referrer"
33
+ | "no-referrer-when-downgrade"
34
+ | "origin"
35
+ | "origin-when-cross-origin"
36
+ | "same-origin"
37
+ | "strict-origin"
38
+ | "strict-origin-when-cross-origin"
39
+ | "unsafe-url";
40
+ permissionsPolicy?: Record<string, string[]>;
41
+ }
42
+
43
+ export interface ApiKeyValidationResult {
44
+ isValid: boolean;
45
+ key?: ApiKeyMetadata;
46
+ error?: string;
47
+ }
48
+
49
+ export interface ApiKeyMetadata {
50
+ id: string;
51
+ key: string;
52
+ name?: string;
53
+ scopes?: string[];
54
+ rateLimit?: {
55
+ max: number;
56
+ windowMs: number;
57
+ };
58
+ expiresAt?: Date;
59
+ createdAt: Date;
60
+ lastUsedAt?: Date;
61
+ metadata?: Record<string, any>;
62
+ }
63
+
64
+ export interface ApiKeyConfig {
65
+ staticKeys?: Array<Partial<ApiKeyMetadata> & { key: string }>;
66
+ headerName?: string;
67
+ queryParamName?: string;
68
+ extractStrategies?: ("header" | "bearer" | "query" | "custom")[];
69
+ vaultService?: any; // Placeholder for now
70
+ customExtractor?: (c: any) => string | null;
71
+ enableCache?: boolean;
72
+ cacheTtl?: number;
73
+ requireScopes?: boolean;
74
+ skipPaths?: string[];
75
+ onError?: (error: string, c: any) => Response | Promise<Response>;
76
+ onValidated?: (key: ApiKeyMetadata, c: any) => void | Promise<void>;
77
+ }
78
+
79
+ export interface CsrfConfig {
80
+ secret: string;
81
+ cookieName?: string;
82
+ headerName?: string;
83
+ ignoreMethods?: string[];
84
+ cookieOptions?: {
85
+ httpOnly?: boolean;
86
+ secure?: boolean;
87
+ sameSite?: "Strict" | "Lax" | "None";
88
+ maxAge?: number;
89
+ };
90
+ }
91
+
92
+ // Feature Interface
93
+ export interface Feature {
94
+ name: string;
95
+ dependencies?: string[]; // Required features
96
+ peerDependencies?: string[]; // Required npm packages
97
+ initialize(kernel: Kernel): Promise<void>;
98
+ routes?: (app: any) => void;
99
+ shutdown?(): Promise<void>;
100
+ }
101
+
102
+ // Configs for Standard Features
103
+
104
+ export interface CorsConfig {
105
+ origin?: string | string[] | ((origin: string) => boolean);
106
+ credentials?: boolean;
107
+ allowMethods?: string[];
108
+ allowHeaders?: string[];
109
+ exposeHeaders?: string[];
110
+ maxAge?: number;
111
+ }
112
+
113
+ export interface RateLimitConfig {
114
+ windowMs?: number;
115
+ max?: number;
116
+ keyGenerator?: (c: any) => string;
117
+ skip?: (c: any) => boolean;
118
+ handler?: (c: any) => Response;
119
+ standardHeaders?: boolean;
120
+ store?: "memory" | "cache";
121
+ }
122
+
123
+ export interface HealthCheckConfig {
124
+ path?: string;
125
+ readinessPath?: string;
126
+ livenessPath?: string;
127
+ includeDetails?: boolean;
128
+ checks?: {
129
+ [key: string]: (context?: any) => Promise<{
130
+ status: "ok" | "error";
131
+ message?: string;
132
+ details?: any;
133
+ }>;
134
+ };
135
+ }
136
+
137
+ export interface RequestIdConfig {
138
+ headerName?: string;
139
+ generator?: () => string;
140
+ }
141
+
142
+ export interface ErrorHandlerConfig {
143
+ includeStack?: boolean;
144
+ customHandlers?: {
145
+ [key: number]: (error: Error, c: any) => Response;
146
+ };
147
+ logger?: (error: Error, c: any) => void;
148
+ }
149
+
150
+ export interface LoggerConfig {
151
+ level?: "debug" | "info" | "error" | "trace" | "warning" | "fatal" | null | undefined;
152
+ format?: "json" | "pretty";
153
+ sinks?: Array<
154
+ {
155
+ type: "console" | "file";
156
+ path?: string;
157
+ level?: "debug" | "info" | "warn" | "error";
158
+ } | Sink
159
+ >;
160
+ logRequests?: boolean;
161
+ logResponses?: boolean;
162
+ }
163
+
164
+ export interface AuthConfig {
165
+ secret: string;
166
+ basePath?: string; // Default: "/api/sso"
167
+ baseURL?: string; // For better-auth
168
+ trustedOrigins?: string[]; // For better-auth CORS
169
+ disableCSRFCheck?: boolean; // Disable CSRF protection (for testing)
170
+ authMode?: "oidc" | "email"; // Authentication mode
171
+ enableSelfRegistration?: boolean; // Enable user self-registration for email/password mode
172
+
173
+ // deno-lint-ignore no-explicit-any
174
+ socialProviders?: Record<string, any>; // Allow other providers
175
+
176
+ // OIDC Configuration for Keycloak and other OIDC providers
177
+ oidcConfig?: {
178
+ clientId: string;
179
+ clientSecret: string;
180
+ issuer: string;
181
+ providerId?: string;
182
+ authorizationEndpoint?: string;
183
+ tokenEndpoint?: string;
184
+ userinfoEndpoint?: string;
185
+ jwksEndpoint?: string;
186
+ discoveryEndpoint?: string;
187
+ scopes?: string[];
188
+ pkce?: boolean;
189
+ mapping?: {
190
+ id?: string;
191
+ email?: string;
192
+ emailVerified?: string;
193
+ name?: string;
194
+ image?: string;
195
+ extraFields?: Record<string, string>;
196
+ };
197
+ };
198
+ }
199
+
200
+ export interface SessionConfig {
201
+ store: "db" | "cache" | "memory";
202
+ secret: string;
203
+ ttl?: number;
204
+ cookieName?: string;
205
+ cookieOptions?: {
206
+ secure?: boolean;
207
+ sameSite?: "Strict" | "Lax" | "None";
208
+ domain?: string;
209
+ path?: string;
210
+ };
211
+ }
212
+
213
+ export interface DbConfig {
214
+ adapter: "postgres" | "mysql" | "sqlite";
215
+ connection?: {
216
+ host?: string;
217
+ port?: number;
218
+ database?: string;
219
+ user?: string;
220
+ password?: string;
221
+ connectionString?: string;
222
+ };
223
+ }
224
+
225
+ export interface CacheConfig {
226
+ adapter: "redis" | "memory";
227
+ connection?: {
228
+ host?: string;
229
+ port?: number;
230
+ password?: string;
231
+ db?: number;
232
+ };
233
+ secret?: string;
234
+ // ... (CacheConfig end)
235
+ ttl?: number;
236
+ }
237
+
238
+ export interface PermissionsConfig {
239
+ loadPermissions?: (userId: string) => Promise<string[]>;
240
+ loadRoles?: (userId: string) => Promise<string[]>;
241
+ anonymousPermissions?: string[];
242
+ enableRBAC?: boolean;
243
+ cachePermissions?: boolean;
244
+ cacheTTL?: number;
245
+ }
246
+
247
+ export interface Role {
248
+ name: string;
249
+ permissions: string[];
250
+ description?: string;
251
+ }
252
+
253
+ export interface OpenAPIConfig {
254
+ title: string;
255
+ version: string;
256
+ description?: string;
257
+ servers?: Array<{ url: string; description?: string }>;
258
+ tags?: Array<{ name: string; description?: string }>;
259
+ contact?: { name?: string; email?: string; url?: string };
260
+ license?: { name: string; url?: string };
261
+ externalDocs?: { description: string; url: string };
262
+ security?: Array<Record<string, string[]>>;
263
+ securitySchemes?: Record<string, any>;
264
+ }
265
+
266
+ export interface UploadConfig {
267
+ projectName: string;
268
+ maxFileSize?: number;
269
+ allowedExtensions?: string[];
270
+ exposeRoutes?: boolean;
271
+ routePrefix?: string;
272
+ }