@bigbucket-ai/sdk 0.1.0 → 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/README.md CHANGED
@@ -97,7 +97,32 @@ console.log("Total images:", response.pagination.total);
97
97
  console.log("Has next page:", response.pagination.hasNext);
98
98
  ```
99
99
 
100
- ### 4. Deleting an Image
100
+ ### 4. On-the-Fly Dynamic Image Transformations
101
+
102
+ Generate optimized, responsive image delivery URLs without storing multiple sizes:
103
+
104
+ ```typescript
105
+ import { buildTransformUrl } from "@bigbucket-ai/sdk";
106
+
107
+ // 1. Resize width to 400px with 80% WebP compression
108
+ const mobileUrl = buildTransformUrl(image.url, {
109
+ width: 400,
110
+ quality: 80,
111
+ format: "webp",
112
+ });
113
+ // -> "https://.../asset.png?w=400&q=80&fmt=webp"
114
+
115
+ // 2. 1:1 aspect ratio square product crop
116
+ const productCardUrl = buildTransformUrl(image.url, {
117
+ tr: "w-1280,ar-1200-1200,f-auto,q-80",
118
+ });
119
+ // -> "https://.../asset.png?tr=w-1280,ar-1200-1200,f-auto,q-80"
120
+
121
+ // 3. Or use the method directly on your client instance:
122
+ const thumbUrl = bigbucket.transformUrl(image.url, { w: 250, h: 250, fit: "cover" });
123
+ ```
124
+
125
+ ### 5. Deleting an Image
101
126
  Deletes the object from storage (Cloudflare R2) and frees project usage accounting atomically:
102
127
 
103
128
  ```typescript
package/dist/index.d.mts CHANGED
@@ -25,6 +25,58 @@ declare class HttpTransport {
25
25
  * TypeScript types for @bigbucket-ai/sdk matching the BigBucket API.
26
26
  */
27
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
+ }
28
80
  type ImageStatus = "pending" | "processing" | "ready" | "failed" | "deleted";
29
81
  interface BigBucketOptions {
30
82
  /**
@@ -214,8 +266,49 @@ declare class BigBucket {
214
266
  * 4. Returns verified ImageAsset with delivery URL.
215
267
  */
216
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;
217
276
  }
218
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
+
219
312
  /**
220
313
  * Typed Error hierarchy for BigBucket SDK.
221
314
  */
@@ -257,4 +350,4 @@ declare class TimeoutError extends BigBucketError {
257
350
  constructor(message?: string);
258
351
  }
259
352
 
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 };
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 };
package/dist/index.d.ts CHANGED
@@ -25,6 +25,58 @@ declare class HttpTransport {
25
25
  * TypeScript types for @bigbucket-ai/sdk matching the BigBucket API.
26
26
  */
27
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
+ }
28
80
  type ImageStatus = "pending" | "processing" | "ready" | "failed" | "deleted";
29
81
  interface BigBucketOptions {
30
82
  /**
@@ -214,8 +266,49 @@ declare class BigBucket {
214
266
  * 4. Returns verified ImageAsset with delivery URL.
215
267
  */
216
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;
217
276
  }
218
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
+
219
312
  /**
220
313
  * Typed Error hierarchy for BigBucket SDK.
221
314
  */
@@ -257,4 +350,4 @@ declare class TimeoutError extends BigBucketError {
257
350
  constructor(message?: string);
258
351
  }
259
352
 
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 };
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 };
package/dist/index.js CHANGED
@@ -32,7 +32,8 @@ __export(index_exports, {
32
32
  TimeoutError: () => TimeoutError,
33
33
  UnsupportedFormatError: () => UnsupportedFormatError,
34
34
  UploadsResource: () => UploadsResource,
35
- UsageResource: () => UsageResource
35
+ UsageResource: () => UsageResource,
36
+ buildTransformUrl: () => buildTransformUrl
36
37
  });
37
38
  module.exports = __toCommonJS(index_exports);
38
39
 
@@ -428,6 +429,36 @@ var UsageResource = class {
428
429
  }
429
430
  };
430
431
 
432
+ // src/transform.ts
433
+ function buildTransformUrl(baseUrl, options) {
434
+ if (!baseUrl) return "";
435
+ if (!options || Object.keys(options).length === 0) return baseUrl;
436
+ const url = new URL(baseUrl);
437
+ if (options.tr) {
438
+ url.searchParams.set("tr", options.tr);
439
+ }
440
+ const w = options.width ?? options.w;
441
+ if (w !== void 0) {
442
+ url.searchParams.set("w", String(w));
443
+ }
444
+ const h = options.height ?? options.h;
445
+ if (h !== void 0) {
446
+ url.searchParams.set("h", String(h));
447
+ }
448
+ if (options.fit) {
449
+ url.searchParams.set("fit", options.fit);
450
+ }
451
+ const q = options.quality ?? options.q;
452
+ if (q !== void 0) {
453
+ url.searchParams.set("q", String(q));
454
+ }
455
+ const fmt = options.format ?? options.fmt;
456
+ if (fmt) {
457
+ url.searchParams.set("fmt", fmt);
458
+ }
459
+ return url.toString();
460
+ }
461
+
431
462
  // src/client.ts
432
463
  var BigBucket = class {
433
464
  transport;
@@ -496,6 +527,15 @@ var BigBucket = class {
496
527
  );
497
528
  return await this.uploads.complete(session.uploadId);
498
529
  }
530
+ /**
531
+ * Helper method to generate an optimized, transformed image delivery URL.
532
+ *
533
+ * @param baseUrl The original delivery URL of the image asset.
534
+ * @param options Dynamic transformation parameters (width, height, quality, format, or Zepto shorthand).
535
+ */
536
+ transformUrl(baseUrl, options) {
537
+ return buildTransformUrl(baseUrl, options);
538
+ }
499
539
  };
500
540
  // Annotate the CommonJS export names for ESM import in node:
501
541
  0 && (module.exports = {
@@ -511,5 +551,6 @@ var BigBucket = class {
511
551
  TimeoutError,
512
552
  UnsupportedFormatError,
513
553
  UploadsResource,
514
- UsageResource
554
+ UsageResource,
555
+ buildTransformUrl
515
556
  });
package/dist/index.mjs CHANGED
@@ -390,6 +390,36 @@ var UsageResource = class {
390
390
  }
391
391
  };
392
392
 
393
+ // src/transform.ts
394
+ function buildTransformUrl(baseUrl, options) {
395
+ if (!baseUrl) return "";
396
+ if (!options || Object.keys(options).length === 0) return baseUrl;
397
+ const url = new URL(baseUrl);
398
+ if (options.tr) {
399
+ url.searchParams.set("tr", options.tr);
400
+ }
401
+ const w = options.width ?? options.w;
402
+ if (w !== void 0) {
403
+ url.searchParams.set("w", String(w));
404
+ }
405
+ const h = options.height ?? options.h;
406
+ if (h !== void 0) {
407
+ url.searchParams.set("h", String(h));
408
+ }
409
+ if (options.fit) {
410
+ url.searchParams.set("fit", options.fit);
411
+ }
412
+ const q = options.quality ?? options.q;
413
+ if (q !== void 0) {
414
+ url.searchParams.set("q", String(q));
415
+ }
416
+ const fmt = options.format ?? options.fmt;
417
+ if (fmt) {
418
+ url.searchParams.set("fmt", fmt);
419
+ }
420
+ return url.toString();
421
+ }
422
+
393
423
  // src/client.ts
394
424
  var BigBucket = class {
395
425
  transport;
@@ -458,6 +488,15 @@ var BigBucket = class {
458
488
  );
459
489
  return await this.uploads.complete(session.uploadId);
460
490
  }
491
+ /**
492
+ * Helper method to generate an optimized, transformed image delivery URL.
493
+ *
494
+ * @param baseUrl The original delivery URL of the image asset.
495
+ * @param options Dynamic transformation parameters (width, height, quality, format, or Zepto shorthand).
496
+ */
497
+ transformUrl(baseUrl, options) {
498
+ return buildTransformUrl(baseUrl, options);
499
+ }
461
500
  };
462
501
  export {
463
502
  AuthenticationError,
@@ -472,5 +511,6 @@ export {
472
511
  TimeoutError,
473
512
  UnsupportedFormatError,
474
513
  UploadsResource,
475
- UsageResource
514
+ UsageResource,
515
+ buildTransformUrl
476
516
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbucket-ai/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Official TypeScript/JavaScript SDK for the BigBucket Image Storage and Management Platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",