@bigbucket-ai/sdk 0.0.0-stage → 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.
@@ -0,0 +1,260 @@
1
+ interface TransportConfig {
2
+ apiKey: string;
3
+ baseUrl?: string | undefined;
4
+ timeout?: number | undefined;
5
+ fetch?: typeof fetch | undefined;
6
+ }
7
+ declare class HttpTransport {
8
+ private readonly apiKey;
9
+ private readonly baseUrl;
10
+ private readonly timeout;
11
+ private readonly customFetch;
12
+ constructor(config: TransportConfig);
13
+ /**
14
+ * Execute an authenticated request against the BigBucket API.
15
+ */
16
+ request<T>(path: string, options?: RequestInit): Promise<T>;
17
+ /**
18
+ * Upload binary data directly to the storage provider (Cloudflare R2 or Local Storage).
19
+ * Note: Permanent BigBucket credentials MUST NOT be forwarded to the storage provider.
20
+ */
21
+ uploadToPresignedUrl(uploadUrl: string, method: string, signedHeaders: Record<string, string>, body: BodyInit): Promise<void>;
22
+ }
23
+
24
+ /**
25
+ * TypeScript types for @bigbucket-ai/sdk matching the BigBucket API.
26
+ */
27
+ type ImageFormat = "jpeg" | "png" | "webp" | "gif";
28
+ type ImageStatus = "pending" | "processing" | "ready" | "failed" | "deleted";
29
+ interface BigBucketOptions {
30
+ /**
31
+ * Secret project API key (e.g. bb_live_...).
32
+ * Must only be used in trusted server-side environments.
33
+ */
34
+ apiKey: string;
35
+ /**
36
+ * Base URL of the BigBucket API. Defaults to http://localhost:8000/api/v1 in local dev.
37
+ */
38
+ baseUrl?: string | undefined;
39
+ /**
40
+ * Request timeout in milliseconds. Defaults to 30,000 (30 seconds).
41
+ */
42
+ timeout?: number | undefined;
43
+ /**
44
+ * Optional custom fetch implementation (useful in testing or specialized runtimes).
45
+ */
46
+ fetch?: typeof fetch | undefined;
47
+ }
48
+ type FileInput = Uint8Array | ArrayBuffer | Blob | {
49
+ buffer: ArrayBuffer;
50
+ } | string;
51
+ interface UploadOptions {
52
+ /**
53
+ * Original file name (e.g. product.webp).
54
+ */
55
+ filename: string;
56
+ /**
57
+ * MIME content type (e.g. image/webp, image/jpeg, image/png, image/gif).
58
+ */
59
+ contentType: string;
60
+ /**
61
+ * File size in bytes (optional, computed automatically when possible).
62
+ */
63
+ fileSize?: number | undefined;
64
+ }
65
+ interface ImageVariant {
66
+ variantName: string;
67
+ url: string;
68
+ mimeType: string;
69
+ fileSize: number;
70
+ width: number;
71
+ height: number;
72
+ format: string;
73
+ }
74
+ interface ImageAsset {
75
+ id: string;
76
+ projectId: string;
77
+ url: string;
78
+ originalFilename: string;
79
+ mimeType: string;
80
+ fileSize: number;
81
+ width: number;
82
+ height: number;
83
+ format: ImageFormat;
84
+ status: ImageStatus;
85
+ createdAt: string;
86
+ updatedAt: string;
87
+ variants: ImageVariant[];
88
+ }
89
+ interface ImageListOptions {
90
+ page?: number | undefined;
91
+ pageSize?: number | undefined;
92
+ status?: ImageStatus | undefined;
93
+ format?: string | undefined;
94
+ }
95
+ interface Pagination {
96
+ total: number;
97
+ page: number;
98
+ pageSize: number;
99
+ hasNext: boolean;
100
+ }
101
+ interface PaginatedImages {
102
+ data: ImageAsset[];
103
+ pagination: Pagination;
104
+ }
105
+ interface PresignedDetails {
106
+ url: string;
107
+ method: string;
108
+ headers: Record<string, string>;
109
+ }
110
+ interface UploadSession {
111
+ uploadId: string;
112
+ objectKey: string;
113
+ presigned: PresignedDetails;
114
+ expiresAt: string;
115
+ }
116
+ interface UploadStatus {
117
+ id: string;
118
+ projectId: string;
119
+ objectKey: string;
120
+ expectedFileSize: number;
121
+ expectedMimeType: string;
122
+ status: string;
123
+ expiresAt: string;
124
+ createdAt: string;
125
+ completedAt: string | null;
126
+ assetId: string | null;
127
+ }
128
+ interface UsageSummary {
129
+ totalStoredBytes: number;
130
+ totalReadyImages: number;
131
+ successfulUploads: number;
132
+ deletedImages: number;
133
+ }
134
+
135
+ /**
136
+ * Images resource for listing, inspecting, and deleting media assets.
137
+ */
138
+
139
+ declare class ImagesResource {
140
+ private readonly transport;
141
+ constructor(transport: HttpTransport);
142
+ private mapAsset;
143
+ /**
144
+ * Retrieve metadata and stable delivery URL for an image.
145
+ */
146
+ get(imageId: string): Promise<ImageAsset>;
147
+ /**
148
+ * List and paginate media assets belonging to the authenticated project.
149
+ */
150
+ list(options?: ImageListOptions): Promise<PaginatedImages>;
151
+ /**
152
+ * Delete an image from storage and mark it deleted in BigBucket.
153
+ */
154
+ delete(imageId: string): Promise<{
155
+ success: boolean;
156
+ id: string;
157
+ }>;
158
+ }
159
+
160
+ /**
161
+ * Uploads resource for managing upload sessions and finalization.
162
+ */
163
+
164
+ declare class UploadsResource {
165
+ private readonly transport;
166
+ constructor(transport: HttpTransport);
167
+ /**
168
+ * Request permission and generate a presigned upload URL.
169
+ */
170
+ create(options: {
171
+ filename: string;
172
+ contentType: string;
173
+ fileSize: number;
174
+ }): Promise<UploadSession>;
175
+ /**
176
+ * Finalize an upload session once the client has uploaded bytes to the presigned URL.
177
+ */
178
+ complete(uploadId: string): Promise<ImageAsset>;
179
+ /**
180
+ * Check the status of an ongoing or completed upload session.
181
+ */
182
+ get(uploadId: string): Promise<UploadStatus>;
183
+ }
184
+
185
+ /**
186
+ * Usage resource for inspecting stored bytes, ready images, and upload metrics.
187
+ */
188
+
189
+ declare class UsageResource {
190
+ private readonly transport;
191
+ constructor(transport: HttpTransport);
192
+ /**
193
+ * Retrieve usage metrics for a project or the account.
194
+ */
195
+ get(projectId?: string): Promise<UsageSummary>;
196
+ }
197
+
198
+ declare class BigBucket {
199
+ private readonly transport;
200
+ readonly images: ImagesResource;
201
+ readonly uploads: UploadsResource;
202
+ readonly usage: UsageResource;
203
+ constructor(options: BigBucketOptions);
204
+ /**
205
+ * Helper method to normalize arbitrary input types (Buffer, Uint8Array, Blob, etc.)
206
+ * and resolve byte length.
207
+ */
208
+ private resolveFileData;
209
+ /**
210
+ * Complete end-to-end image upload workflow:
211
+ * 1. Requests an upload session and receives presigned storage URL.
212
+ * 2. Uploads binary data directly to the storage provider (Cloudflare R2).
213
+ * 3. Finalizes the upload with server verification and content inspection.
214
+ * 4. Returns verified ImageAsset with delivery URL.
215
+ */
216
+ upload(file: FileInput, options: UploadOptions): Promise<ImageAsset>;
217
+ }
218
+
219
+ /**
220
+ * Typed Error hierarchy for BigBucket SDK.
221
+ */
222
+ interface BigBucketErrorOptions {
223
+ message: string;
224
+ statusCode?: number | undefined;
225
+ code?: string | undefined;
226
+ requestId?: string | undefined;
227
+ details?: unknown;
228
+ cause?: unknown;
229
+ }
230
+ declare class BigBucketError extends Error {
231
+ readonly statusCode: number;
232
+ readonly code: string;
233
+ readonly requestId: string | undefined;
234
+ readonly details: unknown;
235
+ readonly isRetryable: boolean;
236
+ constructor(options: BigBucketErrorOptions);
237
+ }
238
+ declare class AuthenticationError extends BigBucketError {
239
+ constructor(options: BigBucketErrorOptions);
240
+ }
241
+ declare class NotFoundError extends BigBucketError {
242
+ constructor(options: BigBucketErrorOptions);
243
+ }
244
+ declare class PayloadTooLargeError extends BigBucketError {
245
+ constructor(options: BigBucketErrorOptions);
246
+ }
247
+ declare class UnsupportedFormatError extends BigBucketError {
248
+ constructor(options: BigBucketErrorOptions);
249
+ }
250
+ declare class RateLimitError extends BigBucketError {
251
+ constructor(options: BigBucketErrorOptions);
252
+ }
253
+ declare class StorageUploadError extends BigBucketError {
254
+ constructor(message: string, cause?: unknown);
255
+ }
256
+ declare class TimeoutError extends BigBucketError {
257
+ constructor(message?: string);
258
+ }
259
+
260
+ export { AuthenticationError, BigBucket, BigBucketError, type BigBucketErrorOptions, type BigBucketOptions, type FileInput, HttpTransport, type ImageAsset, type ImageFormat, type ImageListOptions, type ImageStatus, type ImageVariant, ImagesResource, NotFoundError, type PaginatedImages, type Pagination, PayloadTooLargeError, type PresignedDetails, RateLimitError, StorageUploadError, TimeoutError, type TransportConfig, UnsupportedFormatError, type UploadOptions, type UploadSession, type UploadStatus, UploadsResource, UsageResource, type UsageSummary };