@commercengine/storefront-sdk 0.14.5 → 0.15.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.
@@ -999,6 +999,17 @@ var CE_SDK = (function(exports) {
999
999
  };
1000
1000
  }
1001
1001
  /**
1002
+ * Resolve the current customer ID from explicit parameters or the active session.
1003
+ *
1004
+ * @param explicitCustomerId - Optional customer ID supplied by the caller
1005
+ * @returns The resolved customer ID
1006
+ * @throws When the user is anonymous or no session can be established
1007
+ */
1008
+ async resolveCurrentCustomerId(explicitCustomerId) {
1009
+ if (explicitCustomerId) return explicitCustomerId;
1010
+ return this.config.sessionManager.ensureCustomerId();
1011
+ }
1012
+ /**
1002
1013
  * Resolve path parameters that require `customer_id`.
1003
1014
  *
1004
1015
  * @param pathParams - Path parameters with an optional `customer_id`
@@ -1008,7 +1019,7 @@ var CE_SDK = (function(exports) {
1008
1019
  async resolveCustomerPathParams(pathParams) {
1009
1020
  return {
1010
1021
  ...pathParams,
1011
- customer_id: pathParams.customer_id ?? await this.config.sessionManager.ensureCustomerId()
1022
+ customer_id: await this.resolveCurrentCustomerId(pathParams.customer_id)
1012
1023
  };
1013
1024
  }
1014
1025
  };
@@ -1620,6 +1631,35 @@ var CE_SDK = (function(exports) {
1620
1631
  }
1621
1632
  };
1622
1633
  //#endregion
1634
+ //#region src/lib/shared/form-data-utils.ts
1635
+ /**
1636
+ * Multipart form-data helpers for the Storefront SDK
1637
+ */
1638
+ /**
1639
+ * Serialize a request body object into a `FormData` instance.
1640
+ *
1641
+ * Binary fields are generated as `string` (OpenAPI `format: binary`), so callers pass
1642
+ * `File`/`Blob` values. Array fields are appended once per entry under the same key,
1643
+ * which is what the API expects for repeated uploads such as `images` and `videos`.
1644
+ * Everything else is coerced with `String()`.
1645
+ *
1646
+ * @param body - Request body object to serialize
1647
+ * @returns A `FormData` instance ready to be sent as `multipart/form-data`
1648
+ */
1649
+ function toFormData(body) {
1650
+ const formData = new FormData();
1651
+ if (body === void 0 || body === null) return formData;
1652
+ for (const [key, value] of Object.entries(body)) {
1653
+ if (value === void 0 || value === null) continue;
1654
+ const entries = Array.isArray(value) ? value : [value];
1655
+ for (const entry of entries) {
1656
+ if (entry === void 0 || entry === null) continue;
1657
+ formData.append(key, entry instanceof Blob ? entry : String(entry));
1658
+ }
1659
+ }
1660
+ return formData;
1661
+ }
1662
+ //#endregion
1623
1663
  //#region src/lib/catalog.ts
1624
1664
  /**
1625
1665
  * Client for interacting with catalog endpoints
@@ -1664,12 +1704,7 @@ var CE_SDK = (function(exports) {
1664
1704
  return this.executeRequest(() => this.client.POST("/catalog/products/{product_id}/reviews", {
1665
1705
  params: { path: pathParams },
1666
1706
  body: formData,
1667
- bodySerializer: (body) => {
1668
- const fd = new FormData();
1669
- for (const [key, value] of Object.entries(body)) if (value !== void 0 && value !== null) if (value instanceof File || value instanceof Blob) fd.append(key, value);
1670
- else fd.append(key, String(value));
1671
- return fd;
1672
- }
1707
+ bodySerializer: (body) => toFormData(body)
1673
1708
  }));
1674
1709
  }
1675
1710
  };
@@ -2851,11 +2886,7 @@ var CE_SDK = (function(exports) {
2851
2886
  return this.executeRequest(() => this.client.POST("/auth/user/{id}/profile-image", {
2852
2887
  params: { path: pathParams },
2853
2888
  body: formData,
2854
- bodySerializer: (body) => {
2855
- const fd = new FormData();
2856
- for (const [key, value] of Object.entries(body)) if (value !== void 0 && value !== null) fd.append(key, value);
2857
- return fd;
2858
- }
2889
+ bodySerializer: (body) => toFormData(body)
2859
2890
  }));
2860
2891
  }
2861
2892
  /**
@@ -2885,11 +2916,7 @@ var CE_SDK = (function(exports) {
2885
2916
  return this.executeRequest(() => this.client.PUT("/auth/user/{id}/profile-image", {
2886
2917
  params: { path: pathParams },
2887
2918
  body: formData,
2888
- bodySerializer: (body) => {
2889
- const fd = new FormData();
2890
- for (const [key, value] of Object.entries(body)) if (value !== void 0 && value !== null) fd.append(key, value);
2891
- return fd;
2892
- }
2919
+ bodySerializer: (body) => toFormData(body)
2893
2920
  }));
2894
2921
  }
2895
2922
  /**
@@ -3155,6 +3182,44 @@ var CE_SDK = (function(exports) {
3155
3182
  return this.executeRequest(() => this.client.GET("/orders", { params: { query: resolvedQueryParams } }));
3156
3183
  }
3157
3184
  /**
3185
+ * List previously purchased items for the authenticated user
3186
+ *
3187
+ * @description Lists items previously purchased across paid orders (orders with a `payment_status`
3188
+ * of `pending` or `failed` are excluded). Results are deduplicated by `product_id`, returning the
3189
+ * most recent purchase for each product. Use this to power a "Buy it again" carousel.
3190
+ *
3191
+ * @param queryParams - Optional query parameters for pagination and seller filtering
3192
+ * @returns Promise with previously purchased items
3193
+ * @example
3194
+ * ```typescript
3195
+ * // Basic usage
3196
+ * const { data, error } = await sdk.order.listBuyItAgainItems();
3197
+ *
3198
+ * // With pagination and marketplace seller filtering
3199
+ * const { data, error } = await sdk.order.listBuyItAgainItems({
3200
+ * page: 1,
3201
+ * limit: 20,
3202
+ * seller_id: "seller_a,seller_b"
3203
+ * });
3204
+ *
3205
+ * if (error) {
3206
+ * console.error("Failed to list buy-it-again items:", error.message);
3207
+ * } else {
3208
+ * console.log("Items found:", data.items.length);
3209
+ * console.log("Pagination:", data.pagination);
3210
+ *
3211
+ * data.items.forEach(item => {
3212
+ * console.log(`${item.product_name} (${item.product_id})`);
3213
+ * console.log("Variant:", item.variant_name);
3214
+ * console.log("Selling price:", item.selling_price);
3215
+ * });
3216
+ * }
3217
+ * ```
3218
+ */
3219
+ async listBuyItAgainItems(queryParams) {
3220
+ return this.executeRequest(() => this.client.GET("/orders/buy-it-again", { params: { query: queryParams } }));
3221
+ }
3222
+ /**
3158
3223
  * Get payment status for an order
3159
3224
  *
3160
3225
  * @param orderNumber - Order number
@@ -3376,6 +3441,184 @@ var CE_SDK = (function(exports) {
3376
3441
  body
3377
3442
  }));
3378
3443
  }
3444
+ /**
3445
+ * List all return requests for an order
3446
+ *
3447
+ * @param pathParams - Order number path parameters
3448
+ * @returns Promise with return requests
3449
+ * @example
3450
+ * ```typescript
3451
+ * const { data, error } = await sdk.order.listOrderReturns({
3452
+ * order_number: "ORD-2024-001"
3453
+ * });
3454
+ *
3455
+ * if (error) {
3456
+ * console.error("Failed to list order returns:", error.message);
3457
+ * } else {
3458
+ * console.log("Returns found:", data.returns?.length || 0);
3459
+ *
3460
+ * data.returns?.forEach(orderReturn => {
3461
+ * console.log(`Return ${orderReturn.request_number}: ${orderReturn.status}`);
3462
+ * console.log("Created at:", orderReturn.created_at);
3463
+ * console.log("Items:", orderReturn.items?.length || 0);
3464
+ * });
3465
+ * }
3466
+ * ```
3467
+ */
3468
+ async listOrderReturns(pathParams) {
3469
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/returns", { params: { path: pathParams } }));
3470
+ }
3471
+ /**
3472
+ * Create a return request for delivered items in an order
3473
+ *
3474
+ * @description Specify how the return should be settled via `requested_settlement` and list the
3475
+ * delivered line items to return. Each item is keyed by its shipment (`shipment_number`) and
3476
+ * product. Only shipments with `is_return_allowed` set to `true` can be returned.
3477
+ *
3478
+ * @param pathParams - Order number path parameters
3479
+ * @param body - Return request body
3480
+ * @returns Promise with the created return request
3481
+ * @example
3482
+ * ```typescript
3483
+ * const { data, error } = await sdk.order.createOrderReturn(
3484
+ * { order_number: "ORD-2024-001" },
3485
+ * {
3486
+ * requested_settlement: "refund",
3487
+ * items: [
3488
+ * {
3489
+ * shipment_number: "SHIP-2024-001",
3490
+ * product_id: "prod_01H9XYZ12345",
3491
+ * variant_id: "var_01H9XYZ12345",
3492
+ * quantity: 1,
3493
+ * return_reason: "Product arrived damaged"
3494
+ * }
3495
+ * ]
3496
+ * }
3497
+ * );
3498
+ *
3499
+ * // Request a replacement instead of a refund
3500
+ * const { data: replacement } = await sdk.order.createOrderReturn(
3501
+ * { order_number: "ORD-2024-001" },
3502
+ * {
3503
+ * requested_settlement: "replacement",
3504
+ * items: [
3505
+ * {
3506
+ * shipment_number: "SHIP-2024-001",
3507
+ * product_id: "prod_01H9XYZ12345",
3508
+ * variant_id: null,
3509
+ * quantity: 2,
3510
+ * return_reason: "Wrong size delivered"
3511
+ * }
3512
+ * ]
3513
+ * }
3514
+ * );
3515
+ *
3516
+ * if (error) {
3517
+ * console.error("Failed to create return:", error.message);
3518
+ * } else {
3519
+ * console.log("Return created:", data.order_return?.request_number);
3520
+ * console.log("Return status:", data.order_return?.status);
3521
+ * }
3522
+ * ```
3523
+ */
3524
+ async createOrderReturn(pathParams, body) {
3525
+ return this.executeRequest(() => this.client.POST("/orders/{order_number}/returns", {
3526
+ params: { path: pathParams },
3527
+ body
3528
+ }));
3529
+ }
3530
+ /**
3531
+ * Get the full detail of a return request
3532
+ *
3533
+ * @description Returns the return request along with its linked return order, replacement order,
3534
+ * refunds, and signed URLs for any uploaded attachments.
3535
+ *
3536
+ * @param pathParams - Order number and return number path parameters
3537
+ * @returns Promise with return request details
3538
+ * @example
3539
+ * ```typescript
3540
+ * const { data, error } = await sdk.order.getOrderReturnDetails({
3541
+ * order_number: "ORD-2024-001",
3542
+ * return_number: "RET-2024-001"
3543
+ * });
3544
+ *
3545
+ * if (error) {
3546
+ * console.error("Failed to get return details:", error.message);
3547
+ * } else {
3548
+ * const orderReturn = data.order_return;
3549
+ * console.log("Return status:", orderReturn?.status);
3550
+ * console.log("Return order:", orderReturn?.return_order?.order_number);
3551
+ * console.log("Replacement order:", orderReturn?.replacement_order?.order_number);
3552
+ * console.log("Refunds:", orderReturn?.refund?.length || 0);
3553
+ * console.log("Attachment images:", orderReturn?.attachments?.images);
3554
+ * }
3555
+ * ```
3556
+ */
3557
+ async getOrderReturnDetails(pathParams) {
3558
+ return this.executeRequest(() => this.client.GET("/orders/{order_number}/returns/{return_number}", { params: { path: pathParams } }));
3559
+ }
3560
+ /**
3561
+ * Upload supporting attachments for a return request
3562
+ *
3563
+ * @description Uploads images and videos that evidence the condition of the returned items.
3564
+ *
3565
+ * @param pathParams - Order number and return number path parameters
3566
+ * @param formData - Form data containing image and video files
3567
+ * @returns Promise with upload confirmation
3568
+ * @example
3569
+ * ```typescript
3570
+ * const imageFiles = Array.from(document.getElementById('image-input').files);
3571
+ *
3572
+ * const { data, error } = await sdk.order.uploadOrderReturnAttachments(
3573
+ * { order_number: "ORD-2024-001", return_number: "RET-2024-001" },
3574
+ * {
3575
+ * images: imageFiles,
3576
+ * videos: [new File(["video data"], "damage.mp4", { type: "video/mp4" })]
3577
+ * }
3578
+ * );
3579
+ *
3580
+ * if (error) {
3581
+ * console.error("Failed to upload attachments:", error.message);
3582
+ * } else {
3583
+ * console.log("Attachments uploaded:", data.success);
3584
+ * console.log("Message:", data.message);
3585
+ * }
3586
+ * ```
3587
+ */
3588
+ async uploadOrderReturnAttachments(pathParams, formData) {
3589
+ return this.executeRequest(() => this.client.POST("/orders/{order_number}/returns/{return_number}/attachments", {
3590
+ params: { path: pathParams },
3591
+ body: formData,
3592
+ bodySerializer: (body) => toFormData(body)
3593
+ }));
3594
+ }
3595
+ /**
3596
+ * Cancel a return request
3597
+ *
3598
+ * @param pathParams - Order number and return number path parameters
3599
+ * @param body - Cancellation request body
3600
+ * @returns Promise with the updated return request
3601
+ * @example
3602
+ * ```typescript
3603
+ * const { data, error } = await sdk.order.cancelOrderReturn(
3604
+ * { order_number: "ORD-2024-001", return_number: "RET-2024-001" },
3605
+ * { reason: "Decided to keep the product" }
3606
+ * );
3607
+ *
3608
+ * if (error) {
3609
+ * console.error("Failed to cancel return:", error.message);
3610
+ * } else {
3611
+ * console.log("Return cancelled");
3612
+ * console.log("Updated status:", data.order_return?.status);
3613
+ * }
3614
+ * ```
3615
+ */
3616
+ async cancelOrderReturn(pathParams, body) {
3617
+ return this.executeRequest(() => this.client.POST("/orders/{order_number}/returns/{return_number}/cancel", {
3618
+ params: { path: pathParams },
3619
+ body
3620
+ }));
3621
+ }
3379
3622
  };
3380
3623
  //#endregion
3381
3624
  //#region src/lib/payments.ts
@@ -3848,6 +4091,16 @@ var CE_SDK = (function(exports) {
3848
4091
  query: resolvedQueryParams
3849
4092
  } }));
3850
4093
  }
4094
+ async listAuthorizedSellers(pathParamsOrQuery, queryParams) {
4095
+ const hasPathParams = queryParams !== void 0 || !!pathParamsOrQuery && typeof pathParamsOrQuery === "object" && "id" in pathParamsOrQuery;
4096
+ const pathParams = hasPathParams ? pathParamsOrQuery : {};
4097
+ const resolvedPathParams = { id: await this.resolveCurrentCustomerId(pathParams.id) };
4098
+ const resolvedQueryParams = hasPathParams ? queryParams : pathParamsOrQuery;
4099
+ return this.executeRequest(() => this.client.GET("/customers/{id}/authorized-sellers", { params: {
4100
+ path: resolvedPathParams,
4101
+ query: resolvedQueryParams
4102
+ } }));
4103
+ }
3851
4104
  };
3852
4105
  //#endregion
3853
4106
  //#region src/lib/shared/store-config.ts