@uploadista/server 0.0.3 → 0.0.4

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 (86) hide show
  1. package/.turbo/turbo-build.log +30 -2
  2. package/dist/auth/index.cjs +1 -0
  3. package/dist/auth/index.d.cts +2 -0
  4. package/dist/auth/index.d.ts +2 -2
  5. package/dist/auth/index.js +1 -1
  6. package/dist/auth-B3XCQncE.cjs +1 -0
  7. package/dist/auth-C77S4vQd.js +2 -0
  8. package/dist/auth-C77S4vQd.js.map +1 -0
  9. package/dist/{auth/get-auth-credentials.js → index-50KlDIjc.d.cts} +41 -16
  10. package/dist/index-50KlDIjc.d.cts.map +1 -0
  11. package/dist/{auth/get-auth-credentials.d.ts → index-CvDNB1lJ.d.ts} +20 -13
  12. package/dist/index-CvDNB1lJ.d.ts.map +1 -0
  13. package/dist/index.cjs +1 -0
  14. package/dist/index.d.cts +620 -0
  15. package/dist/index.d.cts.map +1 -0
  16. package/dist/index.d.ts +619 -8
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -8
  19. package/dist/index.js.map +1 -0
  20. package/package.json +5 -4
  21. package/tsdown.config.ts +12 -0
  22. package/dist/auth/cache.d.ts +0 -87
  23. package/dist/auth/cache.d.ts.map +0 -1
  24. package/dist/auth/cache.js +0 -121
  25. package/dist/auth/cache.test.d.ts +0 -2
  26. package/dist/auth/cache.test.d.ts.map +0 -1
  27. package/dist/auth/cache.test.js +0 -209
  28. package/dist/auth/get-auth-credentials.d.ts.map +0 -1
  29. package/dist/auth/index.d.ts.map +0 -1
  30. package/dist/auth/jwt/index.d.ts +0 -38
  31. package/dist/auth/jwt/index.d.ts.map +0 -1
  32. package/dist/auth/jwt/index.js +0 -36
  33. package/dist/auth/jwt/types.d.ts +0 -77
  34. package/dist/auth/jwt/types.d.ts.map +0 -1
  35. package/dist/auth/jwt/types.js +0 -1
  36. package/dist/auth/jwt/validate.d.ts +0 -58
  37. package/dist/auth/jwt/validate.d.ts.map +0 -1
  38. package/dist/auth/jwt/validate.js +0 -226
  39. package/dist/auth/jwt/validate.test.d.ts +0 -2
  40. package/dist/auth/jwt/validate.test.d.ts.map +0 -1
  41. package/dist/auth/jwt/validate.test.js +0 -492
  42. package/dist/auth/service.d.ts +0 -63
  43. package/dist/auth/service.d.ts.map +0 -1
  44. package/dist/auth/service.js +0 -43
  45. package/dist/auth/service.test.d.ts +0 -2
  46. package/dist/auth/service.test.d.ts.map +0 -1
  47. package/dist/auth/service.test.js +0 -195
  48. package/dist/auth/types.d.ts +0 -38
  49. package/dist/auth/types.d.ts.map +0 -1
  50. package/dist/auth/types.js +0 -1
  51. package/dist/cache.d.ts +0 -87
  52. package/dist/cache.d.ts.map +0 -1
  53. package/dist/cache.js +0 -121
  54. package/dist/cache.test.d.ts +0 -2
  55. package/dist/cache.test.d.ts.map +0 -1
  56. package/dist/cache.test.js +0 -209
  57. package/dist/cloudflare-config.d.ts +0 -72
  58. package/dist/cloudflare-config.d.ts.map +0 -1
  59. package/dist/cloudflare-config.js +0 -67
  60. package/dist/error-types.d.ts +0 -138
  61. package/dist/error-types.d.ts.map +0 -1
  62. package/dist/error-types.js +0 -155
  63. package/dist/hono-adapter.d.ts +0 -48
  64. package/dist/hono-adapter.d.ts.map +0 -1
  65. package/dist/hono-adapter.js +0 -58
  66. package/dist/http-utils.d.ts +0 -148
  67. package/dist/http-utils.d.ts.map +0 -1
  68. package/dist/http-utils.js +0 -233
  69. package/dist/layer-utils.d.ts +0 -121
  70. package/dist/layer-utils.d.ts.map +0 -1
  71. package/dist/layer-utils.js +0 -80
  72. package/dist/metrics/service.d.ts +0 -26
  73. package/dist/metrics/service.d.ts.map +0 -1
  74. package/dist/metrics/service.js +0 -20
  75. package/dist/plugins-typing.d.ts +0 -11
  76. package/dist/plugins-typing.d.ts.map +0 -1
  77. package/dist/plugins-typing.js +0 -1
  78. package/dist/service.d.ts +0 -63
  79. package/dist/service.d.ts.map +0 -1
  80. package/dist/service.js +0 -43
  81. package/dist/service.test.d.ts +0 -2
  82. package/dist/service.test.d.ts.map +0 -1
  83. package/dist/service.test.js +0 -195
  84. package/dist/types.d.ts +0 -38
  85. package/dist/types.d.ts.map +0 -1
  86. package/dist/types.js +0 -1
@@ -0,0 +1,620 @@
1
+ import { n as getAuthCredentials, t as AuthCredentialsResponse } from "./index-50KlDIjc.cjs";
2
+ import { Context, Effect, Layer } from "effect";
3
+ import { UploadistaError } from "@uploadista/core/errors";
4
+ import * as _uploadista_core0 from "@uploadista/core";
5
+ import { Flow, UploadServer } from "@uploadista/core";
6
+ import { FlowProvider } from "@uploadista/core/flow";
7
+ import { BaseEventEmitterService, BaseKvStoreService, UploadFileDataStore, UploadFileDataStores, UploadFileKVStore } from "@uploadista/core/types";
8
+ import { UploadServer as UploadServer$1 } from "@uploadista/core/upload";
9
+ import { GenerateId } from "@uploadista/core/utils";
10
+ import z from "zod";
11
+
12
+ //#region src/types.d.ts
13
+ /**
14
+ * Authentication context containing user identity and authorization metadata.
15
+ * This context is extracted from authentication middleware and made available
16
+ * throughout the upload and flow processing pipeline via Effect Layer.
17
+ */
18
+ type AuthContext = {
19
+ /**
20
+ * Unique identifier for the authenticated user.
21
+ * This is typically extracted from JWT claims (sub), session data, or API key metadata.
22
+ */
23
+ clientId: string;
24
+ /**
25
+ * Optional metadata for authorization and tracking purposes.
26
+ * Can include rate limits, quotas, permissions, or custom application data.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * {
31
+ * permissions: ['upload:create', 'flow:execute'],
32
+ * rateLimit: { requests: 1000, period: 3600 },
33
+ * quota: { storage: 10737418240, used: 5368709120 }
34
+ * }
35
+ * ```
36
+ */
37
+ metadata?: Record<string, unknown>;
38
+ /**
39
+ * Optional list of permissions granted to the user.
40
+ * These can be used for fine-grained access control in the future.
41
+ */
42
+ permissions?: string[];
43
+ };
44
+ /**
45
+ * Result type for authentication middleware.
46
+ * - AuthContext: Successful authentication with user identity
47
+ * - null: Authentication failed or not authenticated
48
+ */
49
+ type AuthResult = AuthContext | null;
50
+ //#endregion
51
+ //#region src/cache.d.ts
52
+ /**
53
+ * Configuration options for the auth cache.
54
+ */
55
+ type AuthCacheConfig = {
56
+ /**
57
+ * Maximum number of entries in the cache.
58
+ * When exceeded, oldest entries are removed (LRU eviction).
59
+ * @default 10000
60
+ */
61
+ maxSize?: number;
62
+ /**
63
+ * Time-to-live for cache entries in milliseconds.
64
+ * Entries older than this will be automatically evicted.
65
+ * @default 3600000 (1 hour)
66
+ */
67
+ ttl?: number;
68
+ };
69
+ declare const AuthCacheService_base: Context.TagClass<AuthCacheService, "AuthCacheService", {
70
+ /**
71
+ * Store an auth context for a job ID.
72
+ */
73
+ readonly set: (jobId: string, authContext: AuthContext) => Effect.Effect<void>;
74
+ /**
75
+ * Retrieve a cached auth context by job ID.
76
+ * Returns null if not found or expired.
77
+ */
78
+ readonly get: (jobId: string) => Effect.Effect<AuthContext | null>;
79
+ /**
80
+ * Delete a cached auth context by job ID.
81
+ */
82
+ readonly delete: (jobId: string) => Effect.Effect<void>;
83
+ /**
84
+ * Clear all cached auth contexts.
85
+ */
86
+ readonly clear: () => Effect.Effect<void>;
87
+ /**
88
+ * Get the current number of cached entries.
89
+ */
90
+ readonly size: () => Effect.Effect<number>;
91
+ }>;
92
+ /**
93
+ * Auth Cache Service
94
+ *
95
+ * Provides caching of authentication contexts for upload and flow jobs.
96
+ * This allows subsequent operations (chunk uploads, flow continuations)
97
+ * to reuse the auth context from the initial request without re-authenticating.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * import { Effect } from "effect";
102
+ * import { AuthCacheService } from "@uploadista/server";
103
+ *
104
+ * const handler = Effect.gen(function* () {
105
+ * const authCache = yield* AuthCacheService;
106
+ * const authContext = { userId: "user-123" };
107
+ *
108
+ * // Cache auth for upload
109
+ * yield* authCache.set("upload-abc", authContext);
110
+ *
111
+ * // Retrieve cached auth later
112
+ * const cached = yield* authCache.get("upload-abc");
113
+ * console.log(cached?.userId); // "user-123"
114
+ *
115
+ * // Clear when done
116
+ * yield* authCache.delete("upload-abc");
117
+ * });
118
+ * ```
119
+ */
120
+ declare class AuthCacheService extends AuthCacheService_base {}
121
+ /**
122
+ * Creates an AuthCacheService Layer with in-memory storage.
123
+ *
124
+ * @param config - Optional configuration for cache behavior
125
+ * @returns Effect Layer providing AuthCacheService
126
+ */
127
+ declare const AuthCacheServiceLive: (config?: AuthCacheConfig) => Layer.Layer<AuthCacheService>;
128
+ /**
129
+ * No-op implementation of AuthCacheService.
130
+ * Does not cache anything - all operations are no-ops.
131
+ * Used when caching is disabled or not needed.
132
+ */
133
+ declare const NoAuthCacheServiceLive: Layer.Layer<AuthCacheService>;
134
+ //#endregion
135
+ //#region src/error-types.d.ts
136
+ /**
137
+ * Base adapter error class for HTTP adapters.
138
+ * All adapter-specific errors should extend this class or one of its subclasses.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * throw new AdapterError("Something went wrong", 500, "INTERNAL_ERROR");
143
+ * ```
144
+ */
145
+ declare class AdapterError extends Error {
146
+ readonly statusCode: number;
147
+ readonly errorCode: string;
148
+ constructor(message: string, statusCode?: number, errorCode?: string);
149
+ }
150
+ /**
151
+ * Validation error - indicates invalid request data or parameters.
152
+ * Returns HTTP 400 Bad Request status.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * if (!isValidUploadId(id)) {
157
+ * throw new ValidationError("Invalid upload ID format");
158
+ * }
159
+ * ```
160
+ */
161
+ declare class ValidationError extends AdapterError {
162
+ constructor(message: string);
163
+ }
164
+ /**
165
+ * Not found error - indicates a requested resource does not exist.
166
+ * Returns HTTP 404 Not Found status.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * if (!upload) {
171
+ * throw new NotFoundError("Upload");
172
+ * }
173
+ * ```
174
+ */
175
+ declare class NotFoundError extends AdapterError {
176
+ constructor(resource: string);
177
+ }
178
+ /**
179
+ * Bad request error - indicates a malformed request.
180
+ * Returns HTTP 400 Bad Request status.
181
+ * Similar to ValidationError but for request structure issues.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * try {
186
+ * const data = JSON.parse(body);
187
+ * } catch {
188
+ * throw new BadRequestError("Invalid JSON body");
189
+ * }
190
+ * ```
191
+ */
192
+ declare class BadRequestError extends AdapterError {
193
+ constructor(message: string);
194
+ }
195
+ /**
196
+ * Creates a standardized error response object for AdapterError.
197
+ * Includes error message, error code, and ISO timestamp.
198
+ *
199
+ * @param error - The AdapterError to format
200
+ * @returns Standardized error response body
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * import { createErrorResponseBody } from "@uploadista/server";
205
+ *
206
+ * try {
207
+ * // ... operation
208
+ * } catch (err) {
209
+ * const errorResponse = createErrorResponseBody(err);
210
+ * res.status(err.statusCode).json(errorResponse);
211
+ * }
212
+ * ```
213
+ */
214
+ declare const createErrorResponseBody: (error: AdapterError) => {
215
+ error: string;
216
+ code: string;
217
+ timestamp: string;
218
+ };
219
+ /**
220
+ * Creates a standardized error response body from UploadistaError.
221
+ * Formats core library errors for HTTP responses with optional details.
222
+ *
223
+ * @param error - The UploadistaError to format
224
+ * @returns Standardized error response body with error, code, timestamp, and optional details
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * import { createUploadistaErrorResponseBody } from "@uploadista/server";
229
+ *
230
+ * try {
231
+ * const result = yield* uploadServer.handleUpload(input);
232
+ * } catch (err) {
233
+ * if (err instanceof UploadistaError) {
234
+ * const errorResponse = createUploadistaErrorResponseBody(err);
235
+ * res.status(400).json(errorResponse);
236
+ * }
237
+ * }
238
+ * ```
239
+ */
240
+ declare const createUploadistaErrorResponseBody: (error: UploadistaError) => {
241
+ error: string;
242
+ code: string;
243
+ timestamp: string;
244
+ details?: unknown;
245
+ };
246
+ /**
247
+ * Creates a generic error response body for unknown/unexpected errors.
248
+ * Used as a fallback when error type cannot be determined.
249
+ *
250
+ * @param message - Error message to include in response (defaults to "Internal server error")
251
+ * @returns Standardized error response body with generic INTERNAL_ERROR code
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * import { createGenericErrorResponseBody } from "@uploadista/server";
256
+ *
257
+ * try {
258
+ * // ... operation
259
+ * } catch (err) {
260
+ * const errorResponse = createGenericErrorResponseBody(
261
+ * err instanceof Error ? err.message : "Unknown error"
262
+ * );
263
+ * res.status(500).json(errorResponse);
264
+ * }
265
+ * ```
266
+ */
267
+ declare const createGenericErrorResponseBody: (message?: string) => {
268
+ error: string;
269
+ code: string;
270
+ timestamp: string;
271
+ };
272
+ //#endregion
273
+ //#region src/http-utils.d.ts
274
+ /**
275
+ * Shared HTTP utilities for server adapters
276
+ *
277
+ * This module provides routing and error handling utilities used across
278
+ * Hono, Express, and Fastify adapters for request parsing and response formatting.
279
+ */
280
+ /**
281
+ * Parses URL segments from a pathname, filtering out empty segments.
282
+ * Useful for extracting route components from request paths.
283
+ *
284
+ * @param pathname - The URL pathname (e.g., "/uploadista/api/upload/abc123")
285
+ * @returns Array of non-empty path segments
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * const segments = parseUrlSegments("/uploadista/api/upload/abc123");
290
+ * // => ["uploadista", "api", "upload", "abc123"]
291
+ * ```
292
+ */
293
+ declare const parseUrlSegments: (pathname: string) => string[];
294
+ /**
295
+ * Extracts the last segment from a URL pathname.
296
+ *
297
+ * @param pathname - The URL pathname to parse
298
+ * @returns The last non-empty segment, or undefined if none exists
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * const id = getLastSegment("/uploadista/api/upload/abc123");
303
+ * // => "abc123"
304
+ * ```
305
+ */
306
+ declare const getLastSegment: (pathname: string) => string | undefined;
307
+ /**
308
+ * Checks if a pathname includes a specific base path and API prefix.
309
+ * Used to determine if a request should be handled by the Uploadista adapter.
310
+ *
311
+ * @param pathname - The request pathname
312
+ * @param basePath - The base path configured for the adapter (e.g., "uploadista")
313
+ * @returns true if the path includes `{basePath}/api/`
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * const isUploadistaPath = hasBasePath("/uploadista/api/upload", "uploadista");
318
+ * // => true
319
+ * ```
320
+ */
321
+ declare const hasBasePath: (pathname: string, basePath: string) => boolean;
322
+ /**
323
+ * Removes the base path prefix and returns clean route segments.
324
+ * Transforms "/uploadista/api/upload/abc123" → ["upload", "abc123"]
325
+ *
326
+ * @param pathname - The full request pathname
327
+ * @param basePath - The base path to remove (e.g., "uploadista")
328
+ * @returns Array of route segments without base path prefix
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * const route = getRouteSegments("/uploadista/api/upload/abc123", "uploadista");
333
+ * // => ["upload", "abc123"]
334
+ * ```
335
+ */
336
+ declare const getRouteSegments: (pathname: string, basePath: string) => string[];
337
+ /**
338
+ * Standard error handler for flow and job operations.
339
+ * Maps application errors to appropriate HTTP status codes and error formats.
340
+ *
341
+ * Supports errors with `code`, `message`, `status`, and `details` properties.
342
+ * Maps error codes to HTTP status codes (e.g., NOT_FOUND → 404, VALIDATION_ERROR → 400).
343
+ *
344
+ * @param error - The error object to handle (can be any type)
345
+ * @returns Standardized error response with status, code, message, and optional details
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * import { handleFlowError } from "@uploadista/server";
350
+ *
351
+ * const response = handleFlowError({
352
+ * code: "FLOW_JOB_NOT_FOUND",
353
+ * message: "Job not found",
354
+ * });
355
+ * // => { status: 404, code: "FLOW_JOB_NOT_FOUND", message: "Job not found" }
356
+ * ```
357
+ */
358
+ declare const handleFlowError: (error: unknown) => {
359
+ status: number;
360
+ code: string;
361
+ message: string;
362
+ details?: unknown;
363
+ };
364
+ /**
365
+ * Extracts job ID from URL segments for job status endpoint.
366
+ * Expected URL format: `/uploadista/api/jobs/:jobId/status`
367
+ *
368
+ * @param urlSegments - Parsed URL segments (without base path)
369
+ * @returns The job ID if found, or undefined
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * const jobId = extractJobIdFromStatus(["jobs", "job-123", "status"]);
374
+ * // => "job-123"
375
+ * ```
376
+ */
377
+ declare const extractJobIdFromStatus: (urlSegments: string[]) => string | undefined;
378
+ /**
379
+ * Extracts job ID and node ID from URL segments for continue flow endpoint.
380
+ * Expected URL format: `/uploadista/api/jobs/:jobId/continue/:nodeId`
381
+ *
382
+ * @param urlSegments - Parsed URL segments (without base path)
383
+ * @returns Object with extracted jobId and nodeId (either can be undefined if not found)
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * const { jobId, nodeId } = extractJobAndNodeId([
388
+ * "jobs",
389
+ * "job-123",
390
+ * "continue",
391
+ * "node-456",
392
+ * ]);
393
+ * // => { jobId: "job-123", nodeId: "node-456" }
394
+ * ```
395
+ */
396
+ declare const extractJobAndNodeId: (urlSegments: string[]) => {
397
+ jobId: string | undefined;
398
+ nodeId: string | undefined;
399
+ };
400
+ /**
401
+ * Extracts flow ID and storage ID from URL segments.
402
+ * Expected URL format: `/uploadista/api/flow/:flowId/:storageId`
403
+ *
404
+ * Mutates the input array (removes last 2 elements).
405
+ *
406
+ * @param urlSegments - Parsed URL segments (will be mutated)
407
+ * @returns Object with extracted flowId and storageId
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * const segments = ["flow", "flow-123", "storage-456"];
412
+ * const { flowId, storageId } = extractFlowAndStorageId(segments);
413
+ * // => { flowId: "flow-123", storageId: "storage-456" }
414
+ * // segments is now ["flow"]
415
+ * ```
416
+ */
417
+ declare const extractFlowAndStorageId: (urlSegments: string[]) => {
418
+ flowId: string | undefined;
419
+ storageId: string | undefined;
420
+ };
421
+ //#endregion
422
+ //#region src/layer-utils.d.ts
423
+ /**
424
+ * Configuration for creating upload server layers.
425
+ * Specifies all dependencies needed by the upload server Effect Layer.
426
+ *
427
+ * @property kvStore - Key-value store for upload metadata
428
+ * @property eventEmitter - Event emitter for upload progress events
429
+ * @property dataStore - File data storage implementation
430
+ * @property bufferedDataStore - Optional buffered storage for performance optimization
431
+ * @property generateId - Optional custom ID generator (uses default if omitted)
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * import { createUploadServerLayer } from "@uploadista/server";
436
+ *
437
+ * const uploadLayerConfig: UploadServerLayerConfig = {
438
+ * kvStore: redisKvStore,
439
+ * eventEmitter: webSocketEventEmitter,
440
+ * dataStore: s3DataStore,
441
+ * };
442
+ * ```
443
+ */
444
+ interface UploadServerLayerConfig {
445
+ kvStore: Layer.Layer<BaseKvStoreService>;
446
+ eventEmitter: Layer.Layer<BaseEventEmitterService>;
447
+ dataStore: Layer.Layer<UploadFileDataStores, never, UploadFileKVStore>;
448
+ bufferedDataStore?: Layer.Layer<UploadFileDataStore, never, UploadFileKVStore>;
449
+ generateId?: Layer.Layer<GenerateId>;
450
+ }
451
+ /**
452
+ * Configuration for creating flow server layers.
453
+ * Specifies all dependencies needed by the flow processing server.
454
+ *
455
+ * @property kvStore - Key-value store for flow job metadata
456
+ * @property eventEmitter - Event emitter for flow progress events
457
+ * @property flowProvider - Factory function for creating flows
458
+ * @property uploadServer - Upload server layer (used by flows for uploads)
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * import { createFlowServerLayer } from "@uploadista/server";
463
+ *
464
+ * const flowLayerConfig: FlowServerLayerConfig = {
465
+ * kvStore: redisKvStore,
466
+ * eventEmitter: webSocketEventEmitter,
467
+ * flowProvider: createFlowsEffect,
468
+ * uploadServer: uploadServerLayer,
469
+ * };
470
+ * ```
471
+ */
472
+ interface FlowServerLayerConfig {
473
+ kvStore: Layer.Layer<BaseKvStoreService>;
474
+ eventEmitter: Layer.Layer<BaseEventEmitterService>;
475
+ flowProvider: Layer.Layer<FlowProvider>;
476
+ uploadServer: Layer.Layer<UploadServer$1>;
477
+ }
478
+ /**
479
+ * Creates the upload server layer with all dependencies composed.
480
+ * This layer handles file uploads with chunked transfer, resumption, and metadata tracking.
481
+ *
482
+ * The created layer includes:
483
+ * - Upload KV store (metadata tracking)
484
+ * - Data store (file storage)
485
+ * - Event emitter (progress notifications)
486
+ * - Optional buffered data store (performance optimization)
487
+ * - Optional custom ID generator
488
+ *
489
+ * @param config - Upload server layer configuration
490
+ * @returns Effect Layer providing UploadServer
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * import { createUploadServerLayer } from "@uploadista/server";
495
+ * import { Layer } from "effect";
496
+ *
497
+ * const uploadServerLayer = createUploadServerLayer({
498
+ * kvStore: redisKvStore,
499
+ * eventEmitter: webSocketEventEmitter,
500
+ * dataStore: s3DataStore,
501
+ * });
502
+ *
503
+ * // Use in application
504
+ * const app = Layer.provide(appLogic, uploadServerLayer);
505
+ * ```
506
+ */
507
+ declare const createUploadServerLayer: ({
508
+ kvStore,
509
+ eventEmitter,
510
+ dataStore,
511
+ bufferedDataStore,
512
+ generateId
513
+ }: UploadServerLayerConfig) => Layer.Layer<UploadServer$1, never, never>;
514
+ /**
515
+ * Creates the flow server layer with all dependencies composed.
516
+ * This layer handles file processing workflows with multi-stage pipelines.
517
+ *
518
+ * The created layer includes:
519
+ * - Flow job KV store (job metadata and state)
520
+ * - Event emitter (progress notifications)
521
+ * - Flow provider (flow definitions)
522
+ * - Upload server (for uploads within flows)
523
+ *
524
+ * @param config - Flow server layer configuration
525
+ * @returns Effect Layer providing FlowServer
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * import { createFlowServerLayer } from "@uploadista/server";
530
+ * import { Layer } from "effect";
531
+ *
532
+ * const flowServerLayer = createFlowServerLayer({
533
+ * kvStore: redisKvStore,
534
+ * eventEmitter: webSocketEventEmitter,
535
+ * flowProvider: createFlowsEffect,
536
+ * uploadServer: uploadServerLayer,
537
+ * });
538
+ *
539
+ * // Use in application
540
+ * const app = Layer.provide(appLogic, flowServerLayer);
541
+ * ```
542
+ */
543
+ declare const createFlowServerLayer: ({
544
+ kvStore,
545
+ eventEmitter,
546
+ flowProvider,
547
+ uploadServer
548
+ }: FlowServerLayerConfig) => Layer.Layer<_uploadista_core0.FlowServer, never, never>;
549
+ //#endregion
550
+ //#region src/plugins-typing.d.ts
551
+ type LayerSuccessUnion<Layers extends readonly Layer.Layer<any, never, never>[]> = Layers[number] extends Layer.Layer<infer Success, never, never> ? Success : never;
552
+ type FlowSuccess<TFlows extends (flowId: string, clientId: string | null) => Effect.Effect<unknown, unknown, unknown>> = ReturnType<TFlows> extends Effect.Effect<infer Success, unknown, unknown> ? Success : never;
553
+ type FlowRequirementsOf<TFlows extends (flowId: string, clientId: string | null) => Effect.Effect<unknown, unknown, unknown>> = FlowSuccess<TFlows> extends Flow<z.ZodSchema<unknown>, z.ZodSchema<unknown>, infer R> ? Exclude<R, UploadServer> : never;
554
+ type RequiredPluginsOf<TFlows extends (flowId: string, clientId: string | null) => Effect.Effect<unknown, unknown, unknown>> = Exclude<FlowRequirementsOf<TFlows>, UploadServer>;
555
+ type PluginAssertion<TFlows extends (flowId: string, clientId: string | null) => Effect.Effect<unknown, unknown, unknown>, TPlugins extends readonly Layer.Layer<any, never, never>[]> = Exclude<RequiredPluginsOf<TFlows>, LayerSuccessUnion<TPlugins>> extends never ? unknown : {
556
+ __missingPlugins: Exclude<RequiredPluginsOf<TFlows>, LayerSuccessUnion<TPlugins>>;
557
+ };
558
+ //#endregion
559
+ //#region src/service.d.ts
560
+ declare const AuthContextService_base: Context.TagClass<AuthContextService, "AuthContextService", {
561
+ /**
562
+ * Get the current client ID from auth context.
563
+ * Returns null if no authentication context is available.
564
+ */
565
+ readonly getClientId: () => Effect.Effect<string | null>;
566
+ /**
567
+ * Get the current auth metadata.
568
+ * Returns empty object if no authentication context or no metadata.
569
+ */
570
+ readonly getMetadata: () => Effect.Effect<Record<string, unknown>>;
571
+ /**
572
+ * Check if the current client has a specific permission.
573
+ * Returns false if no authentication context or permission not found.
574
+ */
575
+ readonly hasPermission: (permission: string) => Effect.Effect<boolean>;
576
+ /**
577
+ * Get the full authentication context if available.
578
+ * Returns null if no authentication context is available.
579
+ */
580
+ readonly getAuthContext: () => Effect.Effect<AuthContext | null>;
581
+ }>;
582
+ /**
583
+ * Authentication Context Service
584
+ *
585
+ * Provides access to the current authentication context throughout
586
+ * the upload and flow processing pipeline. The service is provided
587
+ * via Effect Layer and can be accessed using Effect.service().
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * import { Effect } from "effect";
592
+ * import { AuthContextService } from "@uploadista/server";
593
+ *
594
+ * const uploadHandler = Effect.gen(function* () {
595
+ * const authService = yield* AuthContextService;
596
+ * const clientId = yield* authService.getClientId();
597
+ * if (clientId) {
598
+ * console.log(`Processing upload for client: ${clientId}`);
599
+ * }
600
+ * });
601
+ * ```
602
+ */
603
+ declare class AuthContextService extends AuthContextService_base {}
604
+ /**
605
+ * Creates an AuthContextService Layer from an AuthContext.
606
+ * This is typically called by adapters after successful authentication.
607
+ *
608
+ * @param authContext - The authentication context from middleware
609
+ * @returns Effect Layer providing AuthContextService
610
+ */
611
+ declare const AuthContextServiceLive: (authContext: AuthContext | null) => Layer.Layer<AuthContextService>;
612
+ /**
613
+ * No-auth implementation of AuthContextService.
614
+ * Returns null/empty values for all operations.
615
+ * Used when no authentication middleware is configured (backward compatibility).
616
+ */
617
+ declare const NoAuthContextServiceLive: Layer.Layer<AuthContextService>;
618
+ //#endregion
619
+ export { AdapterError, AuthCacheConfig, AuthCacheService, AuthCacheServiceLive, AuthContext, AuthContextService, AuthContextServiceLive, AuthCredentialsResponse, AuthResult, BadRequestError, FlowRequirementsOf, FlowServerLayerConfig, FlowSuccess, LayerSuccessUnion, NoAuthCacheServiceLive, NoAuthContextServiceLive, NotFoundError, PluginAssertion, RequiredPluginsOf, UploadServerLayerConfig, ValidationError, createErrorResponseBody, createFlowServerLayer, createGenericErrorResponseBody, createUploadServerLayer, createUploadistaErrorResponseBody, extractFlowAndStorageId, extractJobAndNodeId, extractJobIdFromStatus, getAuthCredentials, getLastSegment, getRouteSegments, handleFlowError, hasBasePath, parseUrlSegments };
620
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/cache.ts","../src/error-types.ts","../src/http-utils.ts","../src/layer-utils.ts","../src/plugins-typing.ts","../src/service.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;KAKY,WAAA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