@feedmepos/mf-media 0.0.6 → 0.0.8

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.
@@ -0,0 +1,108 @@
1
+ /** Task status, not asset status. `success` is the only state that carries a URL. */
2
+ export type GenerationStatus = "pending" | "processing" | "success" | "failed";
3
+ export type StudioStyle = "none" | "photo" | "flatlay" | "studio" | "warm" | "illus";
4
+ /**
5
+ * The four ratios the studio presents.
6
+ *
7
+ * The server accepts ten; offering four is a product choice, the same asymmetry
8
+ * RATIO_CHOICES already has in the picker.
9
+ */
10
+ export type StudioRatio = "1x1" | "4x3" | "3x4" | "16x9";
11
+ export declare const STUDIO_STYLES: readonly StudioStyle[];
12
+ export declare const STUDIO_RATIOS: readonly StudioRatio[];
13
+ export declare const STUDIO_COUNTS: readonly number[];
14
+ export interface ComposeRequest {
15
+ prompt: string;
16
+ style?: StudioStyle;
17
+ ratio: StudioRatio;
18
+ count: number;
19
+ /** Mutually exclusive with refTmpToken. */
20
+ refAssetId?: string;
21
+ /** Only with refAssetId; selects a stored variant instead of the original. */
22
+ refRatio?: string;
23
+ /** Mutually exclusive with refAssetId. Comes from createRefUploadIntent. */
24
+ refTmpToken?: string;
25
+ /** 10–90. Anything outside that is replaced server-side by the default, 55. */
26
+ refStrength?: number;
27
+ restaurantId?: string;
28
+ }
29
+ /**
30
+ * One image of a queued batch.
31
+ *
32
+ * There is deliberately no `url` field. Unlike a ratio variant — whose URL serves the
33
+ * original while generation is outstanding — a composed image has no original to fall back
34
+ * on, so a URL before `success` would be a real 404. Render from `status`.
35
+ */
36
+ export interface ComposeItem {
37
+ taskId: string;
38
+ assetId: string;
39
+ imageId: string;
40
+ status: GenerationStatus;
41
+ /** Present when this one image could not be queued; the rest of the batch still was. */
42
+ error?: string;
43
+ }
44
+ export interface ComposeResponse {
45
+ batchId: string;
46
+ prompt: string;
47
+ style: StudioStyle;
48
+ /** Canonicalised server-side, so it may differ from what was sent. */
49
+ ratio: string;
50
+ items: ComposeItem[];
51
+ }
52
+ /** Progress for one image. The last four fields appear only once status is `success`. */
53
+ export interface BatchItem {
54
+ taskId: string;
55
+ assetId: string;
56
+ imageId: string;
57
+ status: GenerationStatus;
58
+ /** Distinguishes "retrying" from "about to give up"; the cap is 3. */
59
+ attempts: number;
60
+ error?: string;
61
+ url?: string;
62
+ width?: number;
63
+ height?: number;
64
+ fileSizeBytes?: number;
65
+ }
66
+ export interface BatchView {
67
+ batchId: string;
68
+ prompt: string;
69
+ ratio: string;
70
+ items: BatchItem[];
71
+ }
72
+ export interface RefUploadIntent {
73
+ /** Send this back as ComposeRequest.refTmpToken. */
74
+ token: string;
75
+ objectKey: string;
76
+ uploadUrl: string;
77
+ method: "PUT";
78
+ expiresAt: string;
79
+ }
80
+ /**
81
+ * Queues one generation task per requested image and returns immediately.
82
+ *
83
+ * Resolves with every item `pending`. Partial success is a real outcome rather than an error:
84
+ * an item that could not be queued comes back `failed` with an `error` while the others are
85
+ * still `pending`, so inspect items rather than treating the call as all-or-nothing.
86
+ */
87
+ export declare function composeImages(businessId: string, req: ComposeRequest): Promise<ComposeResponse>;
88
+ /** Polls one batch. 404 for an unknown batch, and for another business's batch. */
89
+ export declare function fetchBatch(businessId: string, batchId: string): Promise<BatchView>;
90
+ /**
91
+ * Signs a PUT for a reference image.
92
+ *
93
+ * The bytes go straight to R2 and no asset row is created — a reference is an input, not a
94
+ * library item, and the merchant did not ask to store it.
95
+ */
96
+ export declare function createRefUploadIntent(businessId: string, req: {
97
+ contentType: string;
98
+ fileSize: number;
99
+ }): Promise<RefUploadIntent>;
100
+ /**
101
+ * PUTs the reference bytes to the signed URL.
102
+ *
103
+ * Deliberately NOT through mediaClient: this request goes to R2 rather than to
104
+ * media-backend, and sending our Authorization header to a presigned URL makes S3 reject it.
105
+ * Content-Type must be exactly what the intent was requested with, because the signature
106
+ * binds it.
107
+ */
108
+ export declare function uploadRefImage(intent: RefUploadIntent, file: File): Promise<void>;