@puzzle-ui/media 0.0.0-stage → 0.17.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 (55) hide show
  1. package/README.md +305 -2
  2. package/ai/instructions.md +70 -0
  3. package/ai/manifest.json +10 -0
  4. package/dist/LICENSE +21 -0
  5. package/dist/adapters-Bon320yF.js +481 -0
  6. package/dist/adapters-Bon320yF.js.map +1 -0
  7. package/dist/adapters-C4N2gqSK.d.cts +63 -0
  8. package/dist/adapters-DXycRsjJ.cjs +492 -0
  9. package/dist/adapters-DXycRsjJ.cjs.map +1 -0
  10. package/dist/adapters-DhPviL_C.d.ts +63 -0
  11. package/dist/browser/index.cjs +200 -0
  12. package/dist/browser/index.cjs.map +1 -0
  13. package/dist/browser/index.d.cts +89 -0
  14. package/dist/browser/index.d.ts +89 -0
  15. package/dist/browser/index.js +195 -0
  16. package/dist/browser/index.js.map +1 -0
  17. package/dist/image-processing-B1lRPpsg.cjs +444 -0
  18. package/dist/image-processing-B1lRPpsg.cjs.map +1 -0
  19. package/dist/image-processing-XkoQ8NT7.js +400 -0
  20. package/dist/image-processing-XkoQ8NT7.js.map +1 -0
  21. package/dist/image-worker.cjs +36 -0
  22. package/dist/image-worker.cjs.map +1 -0
  23. package/dist/image-worker.d.cts +1 -0
  24. package/dist/image-worker.d.ts +1 -0
  25. package/dist/image-worker.js +37 -0
  26. package/dist/image-worker.js.map +1 -0
  27. package/dist/index-8Seqy-LJ.d.ts +297 -0
  28. package/dist/index-BP0ikbAS.d.cts +297 -0
  29. package/dist/index.cjs +38 -0
  30. package/dist/index.d.cts +4 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.js +3 -0
  33. package/dist/media-validation-By6karZu.cjs +361 -0
  34. package/dist/media-validation-By6karZu.cjs.map +1 -0
  35. package/dist/media-validation-OyjGVUq3.js +230 -0
  36. package/dist/media-validation-OyjGVUq3.js.map +1 -0
  37. package/dist/media.types-dzfu0Nep.d.cts +127 -0
  38. package/dist/media.types-dzfu0Nep.d.ts +127 -0
  39. package/dist/processing.types-CPaSB88L.d.ts +238 -0
  40. package/dist/processing.types-Dd2XT8Qr.d.cts +238 -0
  41. package/dist/src-8d6s1iWH.js +1286 -0
  42. package/dist/src-8d6s1iWH.js.map +1 -0
  43. package/dist/src-C7WU7ovP.cjs +1363 -0
  44. package/dist/src-C7WU7ovP.cjs.map +1 -0
  45. package/dist/testing/adapters.cjs +4 -0
  46. package/dist/testing/adapters.d.cts +2 -0
  47. package/dist/testing/adapters.d.ts +2 -0
  48. package/dist/testing/adapters.js +1 -0
  49. package/dist/testing/index.cjs +264 -0
  50. package/dist/testing/index.cjs.map +1 -0
  51. package/dist/testing/index.d.cts +14 -0
  52. package/dist/testing/index.d.ts +14 -0
  53. package/dist/testing/index.js +260 -0
  54. package/dist/testing/index.js.map +1 -0
  55. package/package.json +84 -4
@@ -0,0 +1,238 @@
1
+ import { m as MediaVariant, o as MediaChecksum, p as MediaObjectReference, r as MediaAsset } from "./media.types-dzfu0Nep.cjs";
2
+ type MediaUploadMode = "single" | "multipart";
3
+ type MediaUploadState = "pending" | "completed" | "aborted" | "expired";
4
+ type MediaUploadConstraints = {
5
+ readonly tenantId: string;
6
+ readonly fileName: string;
7
+ readonly contentType: string;
8
+ readonly expectedSize?: number;
9
+ readonly expectedChecksum?: MediaChecksum;
10
+ readonly expiresInMs: number;
11
+ readonly objectPrefix?: string;
12
+ };
13
+ type MediaUploadTarget = {
14
+ readonly url: string;
15
+ readonly method: "PUT";
16
+ readonly headers: Readonly<Record<string, string>>;
17
+ readonly expiresAt: Date;
18
+ };
19
+ type MediaMultipartPartTarget = {
20
+ readonly partNumber: number;
21
+ readonly url: string;
22
+ readonly method: "PUT";
23
+ readonly headers: Readonly<Record<string, string>>;
24
+ readonly expiresAt: Date;
25
+ };
26
+ /**
27
+ * An ephemeral upload capability. Never persist or log its URL, headers, or
28
+ * provider upload ID. Object keys remain server-side.
29
+ */
30
+ type MediaUploadSession = {
31
+ readonly id: string;
32
+ readonly tenantId: string;
33
+ readonly mode: MediaUploadMode;
34
+ readonly state: MediaUploadState;
35
+ readonly expectedSize?: number;
36
+ readonly expectedChecksum?: MediaChecksum;
37
+ readonly expiresAt: Date;
38
+ readonly uploadTarget?: MediaUploadTarget;
39
+ readonly partSizeBytes?: number;
40
+ };
41
+ type MediaStoredObject = {
42
+ readonly object: MediaObjectReference;
43
+ readonly tenantId: string;
44
+ readonly mimeType: string;
45
+ readonly size: number;
46
+ readonly checksum?: MediaChecksum;
47
+ readonly createdAt: Date;
48
+ };
49
+ type MediaReadTarget = {
50
+ readonly url: string;
51
+ readonly expiresAt: Date;
52
+ };
53
+ type MediaObjectSummary = {
54
+ readonly object: MediaObjectReference;
55
+ readonly tenantId: string;
56
+ readonly size: number;
57
+ readonly mimeType: string;
58
+ readonly checksum?: MediaChecksum;
59
+ readonly createdAt: Date;
60
+ };
61
+ type MediaObjectPage = {
62
+ readonly items: readonly MediaObjectSummary[];
63
+ readonly nextCursor: string | null;
64
+ };
65
+ type MediaMultipartCompletedPart = {
66
+ readonly partNumber: number;
67
+ readonly etag: string;
68
+ };
69
+ type MediaObjectListInput = {
70
+ readonly cursor?: string;
71
+ readonly first: number;
72
+ readonly olderThan?: Date;
73
+ };
74
+ interface MediaObjectStorageAdapter {
75
+ /** Create a short-lived target bound to the tenant and declared constraints. */
76
+ createUploadIntent(input: MediaUploadConstraints): Promise<MediaUploadSession>;
77
+ /** Create a resumable multipart intent; the provider upload ID stays server-side. */
78
+ createMultipartUpload(input: MediaUploadConstraints & {
79
+ readonly partSizeBytes: number;
80
+ }): Promise<MediaUploadSession>;
81
+ /** Create short-lived targets for validated part numbers in an active session. */
82
+ createMultipartPartTargets(sessionId: string, partNumbers: readonly number[], expiresInMs: number): Promise<readonly MediaMultipartPartTarget[]>;
83
+ /**
84
+ * Verify the completed object's actual size/checksum and finalize idempotently.
85
+ * A repeated completion for the same completed session must return the object.
86
+ */
87
+ completeUpload(sessionId: string, parts?: readonly MediaMultipartCompletedPart[]): Promise<MediaStoredObject>;
88
+ /** Abort an incomplete intent. Repeated aborts should be harmless. */
89
+ abortUpload(sessionId: string): Promise<boolean>;
90
+ getUploadSession(sessionId: string): Promise<MediaUploadSession | null>;
91
+ /** Return metadata for an exact internal object reference, or null if absent. */
92
+ getObjectMetadata(object: MediaObjectReference): Promise<MediaStoredObject | null>;
93
+ /** Issue a short-lived read capability only for an existing object. */
94
+ createReadTarget(object: MediaObjectReference, expiresInMs: number): Promise<MediaReadTarget>;
95
+ /** Delete an exact object reference; deleting an absent object is harmless. */
96
+ deleteObject(object: MediaObjectReference): Promise<boolean>;
97
+ /** List objects using a stable exclusive cursor, optionally older than a cutoff. */
98
+ listObjects(input: MediaObjectListInput): Promise<MediaObjectPage>;
99
+ /** List incomplete sessions whose expiry is at or before `before`. */
100
+ listExpiredUploadSessions(before: Date, first: number): Promise<readonly MediaUploadSession[]>;
101
+ }
102
+ type MediaImageProfile = {
103
+ readonly name: string;
104
+ readonly maxWidth?: number;
105
+ readonly maxHeight?: number;
106
+ readonly format?: "image/jpeg" | "image/png" | "image/webp" | "image/avif";
107
+ readonly quality?: number;
108
+ readonly required?: boolean;
109
+ };
110
+ type MediaVideoRenditionProfile = {
111
+ readonly name: string;
112
+ readonly maxWidth?: number;
113
+ readonly maxHeight?: number;
114
+ readonly videoBitrate?: number;
115
+ readonly audioBitrate?: number;
116
+ readonly container?: string;
117
+ readonly mimeType?: string;
118
+ readonly required?: boolean;
119
+ };
120
+ type MediaProcessingProfile = MediaImageProfile | MediaVideoRenditionProfile;
121
+ type MediaProcessingFailure = {
122
+ readonly message: string;
123
+ readonly code?: string;
124
+ readonly retryable: boolean;
125
+ };
126
+ type MediaProcessingJobStatus = "queued" | "processing" | "retrying" | "succeeded" | "failed" | "dead-letter" | "cancelled";
127
+ type MediaProcessingJobKind = "image" | "video";
128
+ type MediaProcessingJob = {
129
+ readonly id: string;
130
+ readonly tenantId: string;
131
+ readonly assetId: string;
132
+ readonly kind: MediaProcessingJobKind;
133
+ readonly profiles: readonly MediaProcessingProfile[];
134
+ readonly idempotencyKey: string;
135
+ readonly status: MediaProcessingJobStatus;
136
+ readonly attempt: number;
137
+ readonly maxAttempts: number;
138
+ readonly progress: number;
139
+ readonly availableAt: Date;
140
+ readonly workerId?: string | null;
141
+ readonly leaseExpiresAt?: Date | null;
142
+ readonly result?: readonly MediaVariant[];
143
+ readonly failure?: MediaProcessingFailure | null;
144
+ readonly createdAt: Date;
145
+ readonly updatedAt: Date;
146
+ readonly completedAt?: Date | null;
147
+ readonly revision: number;
148
+ };
149
+ type MediaProcessingJobInput = {
150
+ readonly id: string;
151
+ readonly tenantId: string;
152
+ readonly assetId: string;
153
+ readonly kind: MediaProcessingJobKind;
154
+ readonly profiles: readonly MediaProcessingProfile[];
155
+ readonly idempotencyKey: string;
156
+ readonly maxAttempts: number;
157
+ readonly availableAt?: Date;
158
+ readonly createdAt: Date;
159
+ };
160
+ type MediaProcessingQueueClaim = {
161
+ readonly workerId: string;
162
+ readonly leaseDurationMs: number;
163
+ readonly now: Date;
164
+ };
165
+ interface MediaProcessingQueueAdapter {
166
+ /**
167
+ * Idempotency is scoped by tenant/key. Reuse with a different payload must
168
+ * fail instead of silently enqueueing another operation.
169
+ */
170
+ enqueue(input: MediaProcessingJobInput): Promise<MediaProcessingJob>;
171
+ get(id: string): Promise<MediaProcessingJob | null>;
172
+ /** Atomically lease one available job and increment its attempt count. */
173
+ claimNext(input: MediaProcessingQueueClaim): Promise<MediaProcessingJob | null>;
174
+ updateProgress(id: string, workerId: string, progress: number, now: Date): Promise<MediaProcessingJob>;
175
+ /** Only the current lease owner may extend a live lease. */
176
+ renewLease(id: string, workerId: string, leaseDurationMs: number, now: Date): Promise<MediaProcessingJob>;
177
+ /** Completion must be conditional on the current lease owner. */
178
+ complete(id: string, workerId: string, result: readonly MediaVariant[], now: Date): Promise<MediaProcessingJob>;
179
+ /** Failure must be conditional on the current lease owner. `retryAt` schedules a retry. */
180
+ fail(id: string, workerId: string, failure: MediaProcessingFailure, retryAt: Date | null, now: Date): Promise<MediaProcessingJob>;
181
+ cancel(id: string, now: Date): Promise<MediaProcessingJob | null>;
182
+ }
183
+ type MediaProcessingOutputVariant = {
184
+ readonly name: string;
185
+ readonly kind: MediaVariant["kind"];
186
+ readonly object: MediaObjectReference;
187
+ readonly mimeType: string;
188
+ readonly size: number;
189
+ readonly checksum?: MediaChecksum;
190
+ readonly width?: number;
191
+ readonly height?: number;
192
+ readonly duration?: number;
193
+ readonly bitrate?: number;
194
+ };
195
+ type MediaProcessingOutput = {
196
+ readonly variants: readonly MediaProcessingOutputVariant[];
197
+ readonly failures?: readonly {
198
+ readonly profile: string;
199
+ readonly message: string;
200
+ readonly retryable?: boolean;
201
+ }[];
202
+ };
203
+ type MediaProcessorProgress = (progress: number) => void | Promise<void>;
204
+ type MediaProcessorInput = {
205
+ readonly jobId: string;
206
+ readonly idempotencyKey: string;
207
+ readonly asset: MediaAsset;
208
+ readonly profiles: readonly MediaImageProfile[];
209
+ readonly signal?: AbortSignal;
210
+ readonly onProgress: MediaProcessorProgress;
211
+ };
212
+ interface MediaProcessor {
213
+ processImage(input: MediaProcessorInput): Promise<MediaProcessingOutput>;
214
+ }
215
+ type VideoTranscoderInput = {
216
+ readonly jobId: string;
217
+ readonly idempotencyKey: string;
218
+ readonly asset: MediaAsset;
219
+ readonly profiles: readonly MediaVideoRenditionProfile[];
220
+ readonly signal?: AbortSignal;
221
+ readonly onProgress: MediaProcessorProgress;
222
+ };
223
+ interface VideoTranscoder {
224
+ transcode(input: VideoTranscoderInput): Promise<MediaProcessingOutput>;
225
+ }
226
+ type MediaProcessingServiceOptions = {
227
+ readonly storage: import("@puzzle-ui/storage").StorageAdapter;
228
+ readonly objectStorage: MediaObjectStorageAdapter;
229
+ readonly queue: MediaProcessingQueueAdapter;
230
+ readonly processor?: MediaProcessor;
231
+ readonly transcoder?: VideoTranscoder;
232
+ readonly idFactory?: () => string;
233
+ readonly now?: () => Date;
234
+ readonly baseRetryDelayMs?: number;
235
+ readonly maxRetryDelayMs?: number;
236
+ readonly leaseDurationMs?: number;
237
+ };
238
+ export { MediaUploadState as A, MediaObjectStorageAdapter as C, MediaUploadConstraints as D, MediaStoredObject as E, MediaUploadMode as O, MediaObjectPage as S, MediaReadTarget as T, VideoTranscoder as _, MediaProcessingJobKind as a, MediaMultipartPartTarget as b, MediaProcessingOutputVariant as c, MediaProcessingQueueClaim as d, MediaProcessingServiceOptions as f, MediaVideoRenditionProfile as g, MediaProcessorProgress as h, MediaProcessingJobInput as i, MediaUploadTarget as j, MediaUploadSession as k, MediaProcessingProfile as l, MediaProcessorInput as m, MediaProcessingFailure as n, MediaProcessingJobStatus as o, MediaProcessor as p, MediaProcessingJob as r, MediaProcessingOutput as s, MediaImageProfile as t, MediaProcessingQueueAdapter as u, VideoTranscoderInput as v, MediaObjectSummary as w, MediaObjectListInput as x, MediaMultipartCompletedPart as y };