brainerce 1.30.0 → 1.32.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/dist/index.d.mts CHANGED
@@ -2736,6 +2736,37 @@ interface VariantInventoryResponse {
2736
2736
  canPurchase: boolean;
2737
2737
  lastInventorySyncAt?: string | null;
2738
2738
  }
2739
+ /**
2740
+ * A media-library asset returned by the admin media endpoints
2741
+ * (`/v1/media/*`). The CDN `url` is what you store in `images[].url` on a
2742
+ * product. Requires an admin API key with `media:read` / `media:write`.
2743
+ */
2744
+ interface MediaAsset {
2745
+ id: string;
2746
+ url: string;
2747
+ key: string;
2748
+ thumbnailUrl: string | null;
2749
+ mimeType: string;
2750
+ width: number | null;
2751
+ height: number | null;
2752
+ size: number;
2753
+ /** Display name / title in the media library. */
2754
+ name: string;
2755
+ /** Accessibility alt text. */
2756
+ alt: string | null;
2757
+ createdAt: string;
2758
+ }
2759
+ /** Query params for `listMedia`. */
2760
+ interface ListMediaParams {
2761
+ page?: number;
2762
+ limit?: number;
2763
+ search?: string;
2764
+ }
2765
+ /** Body for `updateMediaAsset` — default metadata. */
2766
+ interface UpdateMediaAssetInput {
2767
+ alt?: string;
2768
+ name?: string;
2769
+ }
2739
2770
  type RefundType = 'full' | 'partial';
2740
2771
  interface RefundLineItem {
2741
2772
  lineItemId: string;
@@ -5582,6 +5613,50 @@ declare class BrainerceClient {
5582
5613
  * ```
5583
5614
  */
5584
5615
  updateVariantInventory(productId: string, variantId: string, data: UpdateVariantInventoryDto): Promise<VariantInventoryResponse>;
5616
+ /**
5617
+ * Upload a file, or ingest a remote image URL, into the store's media
5618
+ * library. Requires an admin API key with the `media:write` scope. Returns
5619
+ * the created asset — store `asset.url` in `images[].url` on a product.
5620
+ *
5621
+ * @example
5622
+ * ```typescript
5623
+ * // Upload a File/Blob:
5624
+ * const asset = await client.uploadMedia(fileInput.files[0]);
5625
+ * // …or ingest by URL (fetched server-side via the SSRF-safe downloader):
5626
+ * const asset = await client.uploadMedia({ sourceUrl: 'https://example.com/photo.jpg' });
5627
+ * await client.updateProduct('prod_123', {
5628
+ * images: [{ url: asset.url, position: 0, isMain: true }],
5629
+ * });
5630
+ * ```
5631
+ */
5632
+ uploadMedia(input: File | Blob | {
5633
+ sourceUrl: string;
5634
+ }): Promise<MediaAsset>;
5635
+ /**
5636
+ * List media-library assets (paginated). Requires `media:read`.
5637
+ *
5638
+ * @example
5639
+ * ```typescript
5640
+ * const { data, meta } = await client.listMedia({ page: 1, limit: 50, search: 'hero' });
5641
+ * ```
5642
+ */
5643
+ listMedia(params?: ListMediaParams): Promise<PaginatedResponse<MediaAsset>>;
5644
+ /**
5645
+ * Get a single media asset by ID. Requires `media:read`.
5646
+ */
5647
+ getMedia(id: string): Promise<MediaAsset>;
5648
+ /**
5649
+ * Update an asset's default metadata (`alt` / `name`). Requires `media:write`.
5650
+ */
5651
+ updateMediaAsset(id: string, data: UpdateMediaAssetInput): Promise<MediaAsset>;
5652
+ /**
5653
+ * Delete a media asset — soft-deletes it and removes its key from every
5654
+ * product/variant/category/brand/store/modifier that referenced it.
5655
+ * Requires `media:write`.
5656
+ */
5657
+ deleteMedia(id: string): Promise<{
5658
+ success: boolean;
5659
+ }>;
5585
5660
  /**
5586
5661
  * Get a list of orders with pagination
5587
5662
  */
package/dist/index.d.ts CHANGED
@@ -2736,6 +2736,37 @@ interface VariantInventoryResponse {
2736
2736
  canPurchase: boolean;
2737
2737
  lastInventorySyncAt?: string | null;
2738
2738
  }
2739
+ /**
2740
+ * A media-library asset returned by the admin media endpoints
2741
+ * (`/v1/media/*`). The CDN `url` is what you store in `images[].url` on a
2742
+ * product. Requires an admin API key with `media:read` / `media:write`.
2743
+ */
2744
+ interface MediaAsset {
2745
+ id: string;
2746
+ url: string;
2747
+ key: string;
2748
+ thumbnailUrl: string | null;
2749
+ mimeType: string;
2750
+ width: number | null;
2751
+ height: number | null;
2752
+ size: number;
2753
+ /** Display name / title in the media library. */
2754
+ name: string;
2755
+ /** Accessibility alt text. */
2756
+ alt: string | null;
2757
+ createdAt: string;
2758
+ }
2759
+ /** Query params for `listMedia`. */
2760
+ interface ListMediaParams {
2761
+ page?: number;
2762
+ limit?: number;
2763
+ search?: string;
2764
+ }
2765
+ /** Body for `updateMediaAsset` — default metadata. */
2766
+ interface UpdateMediaAssetInput {
2767
+ alt?: string;
2768
+ name?: string;
2769
+ }
2739
2770
  type RefundType = 'full' | 'partial';
2740
2771
  interface RefundLineItem {
2741
2772
  lineItemId: string;
@@ -5582,6 +5613,50 @@ declare class BrainerceClient {
5582
5613
  * ```
5583
5614
  */
5584
5615
  updateVariantInventory(productId: string, variantId: string, data: UpdateVariantInventoryDto): Promise<VariantInventoryResponse>;
5616
+ /**
5617
+ * Upload a file, or ingest a remote image URL, into the store's media
5618
+ * library. Requires an admin API key with the `media:write` scope. Returns
5619
+ * the created asset — store `asset.url` in `images[].url` on a product.
5620
+ *
5621
+ * @example
5622
+ * ```typescript
5623
+ * // Upload a File/Blob:
5624
+ * const asset = await client.uploadMedia(fileInput.files[0]);
5625
+ * // …or ingest by URL (fetched server-side via the SSRF-safe downloader):
5626
+ * const asset = await client.uploadMedia({ sourceUrl: 'https://example.com/photo.jpg' });
5627
+ * await client.updateProduct('prod_123', {
5628
+ * images: [{ url: asset.url, position: 0, isMain: true }],
5629
+ * });
5630
+ * ```
5631
+ */
5632
+ uploadMedia(input: File | Blob | {
5633
+ sourceUrl: string;
5634
+ }): Promise<MediaAsset>;
5635
+ /**
5636
+ * List media-library assets (paginated). Requires `media:read`.
5637
+ *
5638
+ * @example
5639
+ * ```typescript
5640
+ * const { data, meta } = await client.listMedia({ page: 1, limit: 50, search: 'hero' });
5641
+ * ```
5642
+ */
5643
+ listMedia(params?: ListMediaParams): Promise<PaginatedResponse<MediaAsset>>;
5644
+ /**
5645
+ * Get a single media asset by ID. Requires `media:read`.
5646
+ */
5647
+ getMedia(id: string): Promise<MediaAsset>;
5648
+ /**
5649
+ * Update an asset's default metadata (`alt` / `name`). Requires `media:write`.
5650
+ */
5651
+ updateMediaAsset(id: string, data: UpdateMediaAssetInput): Promise<MediaAsset>;
5652
+ /**
5653
+ * Delete a media asset — soft-deletes it and removes its key from every
5654
+ * product/variant/category/brand/store/modifier that referenced it.
5655
+ * Requires `media:write`.
5656
+ */
5657
+ deleteMedia(id: string): Promise<{
5658
+ success: boolean;
5659
+ }>;
5585
5660
  /**
5586
5661
  * Get a list of orders with pagination
5587
5662
  */
package/dist/index.js CHANGED
@@ -1404,6 +1404,70 @@ var BrainerceClient = class {
1404
1404
  data
1405
1405
  );
1406
1406
  }
1407
+ // -------------------- Media Library (Admin) --------------------
1408
+ /**
1409
+ * Upload a file, or ingest a remote image URL, into the store's media
1410
+ * library. Requires an admin API key with the `media:write` scope. Returns
1411
+ * the created asset — store `asset.url` in `images[].url` on a product.
1412
+ *
1413
+ * @example
1414
+ * ```typescript
1415
+ * // Upload a File/Blob:
1416
+ * const asset = await client.uploadMedia(fileInput.files[0]);
1417
+ * // …or ingest by URL (fetched server-side via the SSRF-safe downloader):
1418
+ * const asset = await client.uploadMedia({ sourceUrl: 'https://example.com/photo.jpg' });
1419
+ * await client.updateProduct('prod_123', {
1420
+ * images: [{ url: asset.url, position: 0, isMain: true }],
1421
+ * });
1422
+ * ```
1423
+ */
1424
+ async uploadMedia(input) {
1425
+ const formData = new FormData();
1426
+ if (typeof input === "object" && "sourceUrl" in input) {
1427
+ formData.append("sourceUrl", input.sourceUrl);
1428
+ } else {
1429
+ formData.append("file", input);
1430
+ }
1431
+ return this.adminRequest("POST", "/api/v1/media", formData);
1432
+ }
1433
+ /**
1434
+ * List media-library assets (paginated). Requires `media:read`.
1435
+ *
1436
+ * @example
1437
+ * ```typescript
1438
+ * const { data, meta } = await client.listMedia({ page: 1, limit: 50, search: 'hero' });
1439
+ * ```
1440
+ */
1441
+ async listMedia(params) {
1442
+ return this.adminRequest("GET", "/api/v1/media", void 0, {
1443
+ page: params?.page,
1444
+ limit: params?.limit,
1445
+ search: params?.search
1446
+ });
1447
+ }
1448
+ /**
1449
+ * Get a single media asset by ID. Requires `media:read`.
1450
+ */
1451
+ async getMedia(id) {
1452
+ return this.adminRequest("GET", `/api/v1/media/${encodePathSegment(id)}`);
1453
+ }
1454
+ /**
1455
+ * Update an asset's default metadata (`alt` / `name`). Requires `media:write`.
1456
+ */
1457
+ async updateMediaAsset(id, data) {
1458
+ return this.adminRequest("PATCH", `/api/v1/media/${encodePathSegment(id)}`, data);
1459
+ }
1460
+ /**
1461
+ * Delete a media asset — soft-deletes it and removes its key from every
1462
+ * product/variant/category/brand/store/modifier that referenced it.
1463
+ * Requires `media:write`.
1464
+ */
1465
+ async deleteMedia(id) {
1466
+ return this.adminRequest(
1467
+ "DELETE",
1468
+ `/api/v1/media/${encodePathSegment(id)}`
1469
+ );
1470
+ }
1407
1471
  // -------------------- Orders --------------------
1408
1472
  /**
1409
1473
  * Get a list of orders with pagination
package/dist/index.mjs CHANGED
@@ -1334,6 +1334,70 @@ var BrainerceClient = class {
1334
1334
  data
1335
1335
  );
1336
1336
  }
1337
+ // -------------------- Media Library (Admin) --------------------
1338
+ /**
1339
+ * Upload a file, or ingest a remote image URL, into the store's media
1340
+ * library. Requires an admin API key with the `media:write` scope. Returns
1341
+ * the created asset — store `asset.url` in `images[].url` on a product.
1342
+ *
1343
+ * @example
1344
+ * ```typescript
1345
+ * // Upload a File/Blob:
1346
+ * const asset = await client.uploadMedia(fileInput.files[0]);
1347
+ * // …or ingest by URL (fetched server-side via the SSRF-safe downloader):
1348
+ * const asset = await client.uploadMedia({ sourceUrl: 'https://example.com/photo.jpg' });
1349
+ * await client.updateProduct('prod_123', {
1350
+ * images: [{ url: asset.url, position: 0, isMain: true }],
1351
+ * });
1352
+ * ```
1353
+ */
1354
+ async uploadMedia(input) {
1355
+ const formData = new FormData();
1356
+ if (typeof input === "object" && "sourceUrl" in input) {
1357
+ formData.append("sourceUrl", input.sourceUrl);
1358
+ } else {
1359
+ formData.append("file", input);
1360
+ }
1361
+ return this.adminRequest("POST", "/api/v1/media", formData);
1362
+ }
1363
+ /**
1364
+ * List media-library assets (paginated). Requires `media:read`.
1365
+ *
1366
+ * @example
1367
+ * ```typescript
1368
+ * const { data, meta } = await client.listMedia({ page: 1, limit: 50, search: 'hero' });
1369
+ * ```
1370
+ */
1371
+ async listMedia(params) {
1372
+ return this.adminRequest("GET", "/api/v1/media", void 0, {
1373
+ page: params?.page,
1374
+ limit: params?.limit,
1375
+ search: params?.search
1376
+ });
1377
+ }
1378
+ /**
1379
+ * Get a single media asset by ID. Requires `media:read`.
1380
+ */
1381
+ async getMedia(id) {
1382
+ return this.adminRequest("GET", `/api/v1/media/${encodePathSegment(id)}`);
1383
+ }
1384
+ /**
1385
+ * Update an asset's default metadata (`alt` / `name`). Requires `media:write`.
1386
+ */
1387
+ async updateMediaAsset(id, data) {
1388
+ return this.adminRequest("PATCH", `/api/v1/media/${encodePathSegment(id)}`, data);
1389
+ }
1390
+ /**
1391
+ * Delete a media asset — soft-deletes it and removes its key from every
1392
+ * product/variant/category/brand/store/modifier that referenced it.
1393
+ * Requires `media:write`.
1394
+ */
1395
+ async deleteMedia(id) {
1396
+ return this.adminRequest(
1397
+ "DELETE",
1398
+ `/api/v1/media/${encodePathSegment(id)}`
1399
+ );
1400
+ }
1337
1401
  // -------------------- Orders --------------------
1338
1402
  /**
1339
1403
  * Get a list of orders with pagination
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brainerce",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Official SDK for building e-commerce storefronts with Brainerce Platform. Perfect for vibe-coded sites, AI-built stores (Cursor, Lovable, v0), and custom storefronts.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",