@bigbucket-ai/sdk 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +227 -2
- package/dist/index.d.mts +353 -0
- package/dist/index.d.ts +353 -0
- package/dist/index.js +556 -0
- package/dist/index.mjs +516 -0
- package/package.json +52 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
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 TransformFit = "cover" | "contain" | "scale";
|
|
29
|
+
type TransformFormat = "auto" | "webp" | "jpeg" | "png";
|
|
30
|
+
interface TransformOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Target width in pixels (1 to 4096).
|
|
33
|
+
*/
|
|
34
|
+
width?: number | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Alias for width.
|
|
37
|
+
*/
|
|
38
|
+
w?: number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Target height in pixels (1 to 4096).
|
|
41
|
+
*/
|
|
42
|
+
height?: number | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Alias for height.
|
|
45
|
+
*/
|
|
46
|
+
h?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Fit mode for resizing:
|
|
49
|
+
* - 'cover': Smart crop preserving aspect ratio to exact dimensions without distortion.
|
|
50
|
+
* - 'contain': Shrink to fit inside bounding box maintaining aspect ratio.
|
|
51
|
+
* - 'scale': Direct scale to width and height.
|
|
52
|
+
*/
|
|
53
|
+
fit?: TransformFit | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Compression quality from 1 to 100 (default: 85).
|
|
56
|
+
*/
|
|
57
|
+
quality?: number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Alias for quality.
|
|
60
|
+
*/
|
|
61
|
+
q?: number | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Target output format:
|
|
64
|
+
* - 'auto': Automatically negotiates next-gen WebP for supported browsers.
|
|
65
|
+
* - 'webp': Convert to WebP.
|
|
66
|
+
* - 'jpeg': Convert to JPEG.
|
|
67
|
+
* - 'png': Convert to PNG.
|
|
68
|
+
*/
|
|
69
|
+
format?: TransformFormat | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Alias for format.
|
|
72
|
+
*/
|
|
73
|
+
fmt?: TransformFormat | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Transformation shorthand string.
|
|
76
|
+
* Example: 'w-1280,ar-1200-1200,f-auto,q-80'
|
|
77
|
+
*/
|
|
78
|
+
tr?: string | undefined;
|
|
79
|
+
}
|
|
80
|
+
type ImageStatus = "pending" | "processing" | "ready" | "failed" | "deleted";
|
|
81
|
+
interface BigBucketOptions {
|
|
82
|
+
/**
|
|
83
|
+
* Secret project API key (e.g. bb_live_...).
|
|
84
|
+
* Must only be used in trusted server-side environments.
|
|
85
|
+
*/
|
|
86
|
+
apiKey: string;
|
|
87
|
+
/**
|
|
88
|
+
* Base URL of the BigBucket API. Defaults to http://localhost:8000/api/v1 in local dev.
|
|
89
|
+
*/
|
|
90
|
+
baseUrl?: string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Request timeout in milliseconds. Defaults to 30,000 (30 seconds).
|
|
93
|
+
*/
|
|
94
|
+
timeout?: number | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Optional custom fetch implementation (useful in testing or specialized runtimes).
|
|
97
|
+
*/
|
|
98
|
+
fetch?: typeof fetch | undefined;
|
|
99
|
+
}
|
|
100
|
+
type FileInput = Uint8Array | ArrayBuffer | Blob | {
|
|
101
|
+
buffer: ArrayBuffer;
|
|
102
|
+
} | string;
|
|
103
|
+
interface UploadOptions {
|
|
104
|
+
/**
|
|
105
|
+
* Original file name (e.g. product.webp).
|
|
106
|
+
*/
|
|
107
|
+
filename: string;
|
|
108
|
+
/**
|
|
109
|
+
* MIME content type (e.g. image/webp, image/jpeg, image/png, image/gif).
|
|
110
|
+
*/
|
|
111
|
+
contentType: string;
|
|
112
|
+
/**
|
|
113
|
+
* File size in bytes (optional, computed automatically when possible).
|
|
114
|
+
*/
|
|
115
|
+
fileSize?: number | undefined;
|
|
116
|
+
}
|
|
117
|
+
interface ImageVariant {
|
|
118
|
+
variantName: string;
|
|
119
|
+
url: string;
|
|
120
|
+
mimeType: string;
|
|
121
|
+
fileSize: number;
|
|
122
|
+
width: number;
|
|
123
|
+
height: number;
|
|
124
|
+
format: string;
|
|
125
|
+
}
|
|
126
|
+
interface ImageAsset {
|
|
127
|
+
id: string;
|
|
128
|
+
projectId: string;
|
|
129
|
+
url: string;
|
|
130
|
+
originalFilename: string;
|
|
131
|
+
mimeType: string;
|
|
132
|
+
fileSize: number;
|
|
133
|
+
width: number;
|
|
134
|
+
height: number;
|
|
135
|
+
format: ImageFormat;
|
|
136
|
+
status: ImageStatus;
|
|
137
|
+
createdAt: string;
|
|
138
|
+
updatedAt: string;
|
|
139
|
+
variants: ImageVariant[];
|
|
140
|
+
}
|
|
141
|
+
interface ImageListOptions {
|
|
142
|
+
page?: number | undefined;
|
|
143
|
+
pageSize?: number | undefined;
|
|
144
|
+
status?: ImageStatus | undefined;
|
|
145
|
+
format?: string | undefined;
|
|
146
|
+
}
|
|
147
|
+
interface Pagination {
|
|
148
|
+
total: number;
|
|
149
|
+
page: number;
|
|
150
|
+
pageSize: number;
|
|
151
|
+
hasNext: boolean;
|
|
152
|
+
}
|
|
153
|
+
interface PaginatedImages {
|
|
154
|
+
data: ImageAsset[];
|
|
155
|
+
pagination: Pagination;
|
|
156
|
+
}
|
|
157
|
+
interface PresignedDetails {
|
|
158
|
+
url: string;
|
|
159
|
+
method: string;
|
|
160
|
+
headers: Record<string, string>;
|
|
161
|
+
}
|
|
162
|
+
interface UploadSession {
|
|
163
|
+
uploadId: string;
|
|
164
|
+
objectKey: string;
|
|
165
|
+
presigned: PresignedDetails;
|
|
166
|
+
expiresAt: string;
|
|
167
|
+
}
|
|
168
|
+
interface UploadStatus {
|
|
169
|
+
id: string;
|
|
170
|
+
projectId: string;
|
|
171
|
+
objectKey: string;
|
|
172
|
+
expectedFileSize: number;
|
|
173
|
+
expectedMimeType: string;
|
|
174
|
+
status: string;
|
|
175
|
+
expiresAt: string;
|
|
176
|
+
createdAt: string;
|
|
177
|
+
completedAt: string | null;
|
|
178
|
+
assetId: string | null;
|
|
179
|
+
}
|
|
180
|
+
interface UsageSummary {
|
|
181
|
+
totalStoredBytes: number;
|
|
182
|
+
totalReadyImages: number;
|
|
183
|
+
successfulUploads: number;
|
|
184
|
+
deletedImages: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Images resource for listing, inspecting, and deleting media assets.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
declare class ImagesResource {
|
|
192
|
+
private readonly transport;
|
|
193
|
+
constructor(transport: HttpTransport);
|
|
194
|
+
private mapAsset;
|
|
195
|
+
/**
|
|
196
|
+
* Retrieve metadata and stable delivery URL for an image.
|
|
197
|
+
*/
|
|
198
|
+
get(imageId: string): Promise<ImageAsset>;
|
|
199
|
+
/**
|
|
200
|
+
* List and paginate media assets belonging to the authenticated project.
|
|
201
|
+
*/
|
|
202
|
+
list(options?: ImageListOptions): Promise<PaginatedImages>;
|
|
203
|
+
/**
|
|
204
|
+
* Delete an image from storage and mark it deleted in BigBucket.
|
|
205
|
+
*/
|
|
206
|
+
delete(imageId: string): Promise<{
|
|
207
|
+
success: boolean;
|
|
208
|
+
id: string;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Uploads resource for managing upload sessions and finalization.
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
declare class UploadsResource {
|
|
217
|
+
private readonly transport;
|
|
218
|
+
constructor(transport: HttpTransport);
|
|
219
|
+
/**
|
|
220
|
+
* Request permission and generate a presigned upload URL.
|
|
221
|
+
*/
|
|
222
|
+
create(options: {
|
|
223
|
+
filename: string;
|
|
224
|
+
contentType: string;
|
|
225
|
+
fileSize: number;
|
|
226
|
+
}): Promise<UploadSession>;
|
|
227
|
+
/**
|
|
228
|
+
* Finalize an upload session once the client has uploaded bytes to the presigned URL.
|
|
229
|
+
*/
|
|
230
|
+
complete(uploadId: string): Promise<ImageAsset>;
|
|
231
|
+
/**
|
|
232
|
+
* Check the status of an ongoing or completed upload session.
|
|
233
|
+
*/
|
|
234
|
+
get(uploadId: string): Promise<UploadStatus>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Usage resource for inspecting stored bytes, ready images, and upload metrics.
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
declare class UsageResource {
|
|
242
|
+
private readonly transport;
|
|
243
|
+
constructor(transport: HttpTransport);
|
|
244
|
+
/**
|
|
245
|
+
* Retrieve usage metrics for a project or the account.
|
|
246
|
+
*/
|
|
247
|
+
get(projectId?: string): Promise<UsageSummary>;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
declare class BigBucket {
|
|
251
|
+
private readonly transport;
|
|
252
|
+
readonly images: ImagesResource;
|
|
253
|
+
readonly uploads: UploadsResource;
|
|
254
|
+
readonly usage: UsageResource;
|
|
255
|
+
constructor(options: BigBucketOptions);
|
|
256
|
+
/**
|
|
257
|
+
* Helper method to normalize arbitrary input types (Buffer, Uint8Array, Blob, etc.)
|
|
258
|
+
* and resolve byte length.
|
|
259
|
+
*/
|
|
260
|
+
private resolveFileData;
|
|
261
|
+
/**
|
|
262
|
+
* Complete end-to-end image upload workflow:
|
|
263
|
+
* 1. Requests an upload session and receives presigned storage URL.
|
|
264
|
+
* 2. Uploads binary data directly to the storage provider (Cloudflare R2).
|
|
265
|
+
* 3. Finalizes the upload with server verification and content inspection.
|
|
266
|
+
* 4. Returns verified ImageAsset with delivery URL.
|
|
267
|
+
*/
|
|
268
|
+
upload(file: FileInput, options: UploadOptions): Promise<ImageAsset>;
|
|
269
|
+
/**
|
|
270
|
+
* Helper method to generate an optimized, transformed image delivery URL.
|
|
271
|
+
*
|
|
272
|
+
* @param baseUrl The original delivery URL of the image asset.
|
|
273
|
+
* @param options Dynamic transformation parameters (width, height, quality, format, or Zepto shorthand).
|
|
274
|
+
*/
|
|
275
|
+
transformUrl(baseUrl: string, options?: TransformOptions): string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Image transformation utilities for BigBucket.
|
|
280
|
+
* Supports URL construction for on-the-fly resizing, cropping, compression,
|
|
281
|
+
* format conversion, and shorthand transforms.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Build an optimized, transformed image delivery URL.
|
|
286
|
+
*
|
|
287
|
+
* @param baseUrl The stable public delivery URL of the image asset.
|
|
288
|
+
* @param options Transformation parameters (width, height, fit, quality, format, or 'tr' shorthand).
|
|
289
|
+
* @returns Fully formatted URL with query parameters.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* import { buildTransformUrl } from "@bigbucket-ai/sdk";
|
|
294
|
+
*
|
|
295
|
+
* // Resize to 400px width with 80% WebP compression
|
|
296
|
+
* const thumbUrl = buildTransformUrl(image.url, {
|
|
297
|
+
* width: 400,
|
|
298
|
+
* quality: 80,
|
|
299
|
+
* format: "webp",
|
|
300
|
+
* });
|
|
301
|
+
* // -> "https://.../asset.png?w=400&q=80&fmt=webp"
|
|
302
|
+
*
|
|
303
|
+
* // 1:1 aspect ratio square crop
|
|
304
|
+
* const squareUrl = buildTransformUrl(image.url, {
|
|
305
|
+
* tr: "w-1280,ar-1200-1200,f-auto,q-80",
|
|
306
|
+
* });
|
|
307
|
+
* // -> "https://.../asset.png?tr=w-1280,ar-1200-1200,f-auto,q-80"
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function buildTransformUrl(baseUrl: string, options?: TransformOptions): string;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Typed Error hierarchy for BigBucket SDK.
|
|
314
|
+
*/
|
|
315
|
+
interface BigBucketErrorOptions {
|
|
316
|
+
message: string;
|
|
317
|
+
statusCode?: number | undefined;
|
|
318
|
+
code?: string | undefined;
|
|
319
|
+
requestId?: string | undefined;
|
|
320
|
+
details?: unknown;
|
|
321
|
+
cause?: unknown;
|
|
322
|
+
}
|
|
323
|
+
declare class BigBucketError extends Error {
|
|
324
|
+
readonly statusCode: number;
|
|
325
|
+
readonly code: string;
|
|
326
|
+
readonly requestId: string | undefined;
|
|
327
|
+
readonly details: unknown;
|
|
328
|
+
readonly isRetryable: boolean;
|
|
329
|
+
constructor(options: BigBucketErrorOptions);
|
|
330
|
+
}
|
|
331
|
+
declare class AuthenticationError extends BigBucketError {
|
|
332
|
+
constructor(options: BigBucketErrorOptions);
|
|
333
|
+
}
|
|
334
|
+
declare class NotFoundError extends BigBucketError {
|
|
335
|
+
constructor(options: BigBucketErrorOptions);
|
|
336
|
+
}
|
|
337
|
+
declare class PayloadTooLargeError extends BigBucketError {
|
|
338
|
+
constructor(options: BigBucketErrorOptions);
|
|
339
|
+
}
|
|
340
|
+
declare class UnsupportedFormatError extends BigBucketError {
|
|
341
|
+
constructor(options: BigBucketErrorOptions);
|
|
342
|
+
}
|
|
343
|
+
declare class RateLimitError extends BigBucketError {
|
|
344
|
+
constructor(options: BigBucketErrorOptions);
|
|
345
|
+
}
|
|
346
|
+
declare class StorageUploadError extends BigBucketError {
|
|
347
|
+
constructor(message: string, cause?: unknown);
|
|
348
|
+
}
|
|
349
|
+
declare class TimeoutError extends BigBucketError {
|
|
350
|
+
constructor(message?: string);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
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 TransformFit, type TransformFormat, type TransformOptions, type TransportConfig, UnsupportedFormatError, type UploadOptions, type UploadSession, type UploadStatus, UploadsResource, UsageResource, type UsageSummary, buildTransformUrl };
|