@lonca/trendyol 0.14.0 → 0.15.1

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.
@@ -1,4 +1,4 @@
1
- import { f as BatchRequestStatus, b4 as TrendyolClient } from './client-CtygosAW.cjs';
1
+ import { g as BatchRequestStatus, ba as TrendyolClient } from './client-Dnfjvwah.cjs';
2
2
  import '@lonca/core';
3
3
 
4
4
  /** A request the fake client received, normalized for matching in a `handler`. */
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as BatchRequestStatus, b4 as TrendyolClient } from './client-CtygosAW.js';
1
+ import { g as BatchRequestStatus, ba as TrendyolClient } from './client-Dnfjvwah.js';
2
2
  import '@lonca/core';
3
3
 
4
4
  /** A request the fake client received, normalized for matching in a `handler`. */
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createRequester, LoncaError, ServerError, RateLimitError, NotFoundError, ValidationError, AuthError, TokenBucketRateLimiter, normalizeIssueEntries, TimeoutError } from '@lonca/core';
1
+ import { createRequester, AuthError, LoncaError, ServerError, RateLimitError, NotFoundError, ValidationError, TokenBucketRateLimiter, normalizeIssueEntries, TimeoutError } from '@lonca/core';
2
2
 
3
3
  // src/resources/brands.ts
4
4
  var DEFAULT_PAGE_SIZE = 1e3;
@@ -952,18 +952,23 @@ var LabelsResource = class {
952
952
  * returns, call `getCommon()` with the same `cargoTrackingNumber` to
953
953
  * retrieve the generated label.
954
954
  *
955
+ * Trendyol documents this endpoint (`createCommonLabel`) as a bare
956
+ * `200 OK` with no response body, so the SDK returns a `MutationResult`
957
+ * whose `raw` is whatever the gateway sent (normally `undefined`).
958
+ *
955
959
  * @throws {ValidationError} when `format` is missing.
956
960
  */
957
961
  async createCommon(cargoTrackingNumber, input) {
958
962
  if (!input?.format) {
959
963
  throw new ValidationError({ message: "labels.createCommon: format is required" });
960
964
  }
961
- return this.transport.request({
965
+ const raw = await this.transport.request({
962
966
  method: "POST",
963
967
  path: `/integration/sellers/${this.transport.sellerId}/common-label/${encodeURIComponent(String(cargoTrackingNumber))}`,
964
968
  body: input,
965
969
  rateLimiter: this.limiter
966
970
  });
971
+ return { raw };
967
972
  }
968
973
  /**
969
974
  * Retrieve the previously-created common label. Trendyol returns
@@ -2410,6 +2415,9 @@ var QuestionsResource = class {
2410
2415
  * Reply to a question. Trendyol enforces 10–2000 characters on the
2411
2416
  * answer text; the SDK pre-validates client-side.
2412
2417
  *
2418
+ * Trendyol documents the response as `{ answerId: number }`; the SDK
2419
+ * surfaces it as `answerId` and keeps the untouched body on `raw`.
2420
+ *
2413
2421
  * @throws {ValidationError} when `text` is outside the 10–2000 char range.
2414
2422
  */
2415
2423
  async answer(questionId, text) {
@@ -2423,12 +2431,15 @@ var QuestionsResource = class {
2423
2431
  message: `questions.answer: text must be at most 2000 chars (got ${text.length})`
2424
2432
  });
2425
2433
  }
2426
- return this.transport.request({
2434
+ const raw = await this.transport.request({
2427
2435
  method: "POST",
2428
2436
  path: `/integration/qna/sellers/${this.transport.sellerId}/questions/${encodeURIComponent(String(questionId))}/answers`,
2429
2437
  body: { text },
2430
2438
  rateLimiter: this.limiter
2431
2439
  });
2440
+ const out = { raw };
2441
+ if (typeof raw?.answerId === "number") out.answerId = raw.answerId;
2442
+ return out;
2432
2443
  }
2433
2444
  };
2434
2445
  var VALID_TYPES = /* @__PURE__ */ new Set([
@@ -2521,6 +2532,9 @@ var TestOrdersResource = class {
2521
2532
  * SDK forwards the typed payload verbatim — drill into Trendyol's
2522
2533
  * `createTestOrder` doc for inner field rules.
2523
2534
  *
2535
+ * Trendyol documents the response as `{ orderNumber: string }`; the SDK
2536
+ * surfaces it as `orderNumber` and keeps the untouched body on `raw`.
2537
+ *
2524
2538
  * @throws {ValidationError} when required top-level fields are missing.
2525
2539
  */
2526
2540
  async create(input) {
@@ -2529,29 +2543,52 @@ var TestOrdersResource = class {
2529
2543
  throw new ValidationError({ message: `testOrders.create: ${k} is required` });
2530
2544
  }
2531
2545
  }
2532
- return this.transport.request({
2546
+ const raw = await this.transport.request({
2533
2547
  method: "POST",
2534
2548
  path: `/integration/test/order/orders/core`,
2535
2549
  body: input,
2536
2550
  rateLimiter: this.limiter
2537
2551
  });
2552
+ const out = { raw };
2553
+ if (typeof raw?.orderNumber === "string") out.orderNumber = raw.orderNumber;
2554
+ else if (typeof raw?.orderNumber === "number") out.orderNumber = String(raw.orderNumber);
2555
+ return out;
2538
2556
  }
2539
- /** Push a test shipment package to the given status. */
2540
- async updateStatus(packageId, status) {
2541
- return this.transport.request({
2557
+ /**
2558
+ * Push a test shipment package to the given status. Trendyol's
2559
+ * `status-updates-on-test-orders` doc shows a `{ lines, params, status }`
2560
+ * body — pass `options` to send the documented `lines` / `params`;
2561
+ * omitted, the body stays `{ status }` alone as before. Documented
2562
+ * response is a bare `200 OK` (no body), hence `MutationResult`.
2563
+ */
2564
+ async updateStatus(packageId, status, options = {}) {
2565
+ const raw = await this.transport.request({
2542
2566
  method: "PUT",
2543
2567
  path: `/integration/test/order/sellers/${this.transport.sellerId}/shipment-packages/${encodeURIComponent(String(packageId))}/status`,
2544
- body: { status },
2568
+ body: {
2569
+ ...options.lines !== void 0 ? { lines: options.lines } : {},
2570
+ ...options.params !== void 0 ? { params: options.params } : {},
2571
+ status
2572
+ },
2545
2573
  rateLimiter: this.limiter
2546
2574
  });
2575
+ return { raw };
2547
2576
  }
2548
- /** Move test claims to the `WaitingInAction` state. */
2549
- async setClaimsWaitingInAction() {
2550
- return this.transport.request({
2577
+ /**
2578
+ * Move test claims to the `WaitingInAction` state. Trendyol's
2579
+ * `updateTestOrderStatus` doc shows a `{ shipmentPackageId }` body (the
2580
+ * `orderShipmentPackageId` from `claims.list`); pass `input` to send it —
2581
+ * omitted, the request goes out body-less as before. Documented response
2582
+ * is a bare `200 OK` (no body), hence `MutationResult`.
2583
+ */
2584
+ async setClaimsWaitingInAction(input) {
2585
+ const raw = await this.transport.request({
2551
2586
  method: "PUT",
2552
2587
  path: `/integration/test/order/sellers/${this.transport.sellerId}/claims/waiting-in-action`,
2588
+ ...input ? { body: input } : {},
2553
2589
  rateLimiter: this.limiter
2554
2590
  });
2591
+ return { raw };
2555
2592
  }
2556
2593
  };
2557
2594
  var VideosResource = class {
@@ -2567,18 +2604,25 @@ var VideosResource = class {
2567
2604
  * Queue a video for upload. Trendyol downloads from the URL in the
2568
2605
  * body asynchronously; poll `list()` (filtered by id) for status.
2569
2606
  *
2607
+ * Trendyol documents the response as `{ videoId: string }`; the SDK
2608
+ * surfaces it as `videoId` (pass it to `list({ id })`) and keeps the
2609
+ * untouched body on `raw`.
2610
+ *
2570
2611
  * @throws {ValidationError} when `input` is empty / not an object.
2571
2612
  */
2572
2613
  async create(input) {
2573
2614
  if (!input || typeof input !== "object") {
2574
2615
  throw new ValidationError({ message: "videos.create: input is required" });
2575
2616
  }
2576
- return this.transport.request({
2617
+ const raw = await this.transport.request({
2577
2618
  method: "POST",
2578
2619
  path: `/integration/video/sellers/${this.transport.sellerId}/videos`,
2579
2620
  body: input,
2580
2621
  rateLimiter: this.createLimiter
2581
2622
  });
2623
+ const out = { raw };
2624
+ if (typeof raw?.videoId === "string") out.videoId = raw.videoId;
2625
+ return out;
2582
2626
  }
2583
2627
  /** List the seller's integration videos (optionally filtered by id / status). */
2584
2628
  async list(params = {}) {
@@ -2630,16 +2674,24 @@ var WebhooksResource = class {
2630
2674
  * per seller — the SDK does NOT pre-check (you'd need to call `list()`
2631
2675
  * first), but Trendyol returns 400 when the cap is exceeded.
2632
2676
  *
2677
+ * Trendyol documents the response as `{ id: string }` — the webhook ID
2678
+ * you need for `update` / `delete` / `activate` / `deactivate`. The SDK
2679
+ * surfaces it as `id` and keeps the untouched body on `raw`.
2680
+ *
2633
2681
  * @throws {ValidationError} when `url` or `authenticationType` is missing.
2634
2682
  */
2635
2683
  async create(input) {
2636
2684
  this.validateInput(input, "create");
2637
- return this.transport.request({
2685
+ const raw = await this.transport.request({
2638
2686
  method: "POST",
2639
2687
  path: `/integration/sellers/${this.transport.sellerId}/webhooks`,
2640
2688
  body: input,
2641
2689
  rateLimiter: this.limiter
2642
2690
  });
2691
+ const out = { raw };
2692
+ if (typeof raw?.id === "string") out.id = raw.id;
2693
+ else if (typeof raw?.id === "number") out.id = String(raw.id);
2694
+ return out;
2643
2695
  }
2644
2696
  /** List all registered webhook subscriptions. */
2645
2697
  async list() {
@@ -2654,43 +2706,57 @@ var WebhooksResource = class {
2654
2706
  /**
2655
2707
  * Update a webhook subscription. Same input shape as `create`; replaces
2656
2708
  * the whole subscription (Trendyol does NOT partially update).
2709
+ *
2710
+ * Documented response is a bare `200 OK` (no body), hence `MutationResult`.
2657
2711
  */
2658
2712
  async update(webhookId, input) {
2659
2713
  this.validateInput(input, "update");
2660
- return this.transport.request({
2714
+ const raw = await this.transport.request({
2661
2715
  method: "PUT",
2662
2716
  path: this.webhookPath(webhookId),
2663
2717
  body: input,
2664
2718
  rateLimiter: this.limiter
2665
2719
  });
2720
+ return { raw };
2666
2721
  }
2667
- /** Permanently delete a webhook subscription. */
2722
+ /**
2723
+ * Permanently delete a webhook subscription. Documented response is a
2724
+ * bare `200 OK` (no body), hence `MutationResult`.
2725
+ */
2668
2726
  async delete(webhookId) {
2669
- return this.transport.request({
2727
+ const raw = await this.transport.request({
2670
2728
  method: "DELETE",
2671
2729
  path: this.webhookPath(webhookId),
2672
2730
  rateLimiter: this.limiter
2673
2731
  });
2732
+ return { raw };
2674
2733
  }
2675
- /** Re-activate a previously-deactivated webhook subscription. */
2734
+ /**
2735
+ * Re-activate a previously-deactivated webhook subscription. Documented
2736
+ * response is a bare `200 OK` (no body), hence `MutationResult`.
2737
+ */
2676
2738
  async activate(webhookId) {
2677
- return this.transport.request({
2739
+ const raw = await this.transport.request({
2678
2740
  method: "PUT",
2679
2741
  path: `${this.webhookPath(webhookId)}/activate`,
2680
2742
  rateLimiter: this.limiter
2681
2743
  });
2744
+ return { raw };
2682
2745
  }
2683
2746
  /**
2684
2747
  * Deactivate a webhook subscription. Trendyol automatically deactivates
2685
2748
  * a subscription after persistent delivery failures (and sends 2 emails);
2686
2749
  * use `activate()` to bring it back online once your endpoint is healthy.
2750
+ *
2751
+ * Documented response is a bare `200 OK` (no body), hence `MutationResult`.
2687
2752
  */
2688
2753
  async deactivate(webhookId) {
2689
- return this.transport.request({
2754
+ const raw = await this.transport.request({
2690
2755
  method: "PUT",
2691
2756
  path: `${this.webhookPath(webhookId)}/deactivate`,
2692
2757
  rateLimiter: this.limiter
2693
2758
  });
2759
+ return { raw };
2694
2760
  }
2695
2761
  validateInput(input, method) {
2696
2762
  if (!input?.url || typeof input.url !== "string") {
@@ -2738,6 +2804,13 @@ function buildUserAgent(sellerId, integratorName) {
2738
2804
  return `${sellerId} - ${integratorName}`;
2739
2805
  }
2740
2806
  function mapHttpError(status, body, retryAfterMs) {
2807
+ if ((status === 401 || status === 403) && typeof body === "string") {
2808
+ return new AuthError({
2809
+ message: `Trendyol rejected the request before it reached the API (HTTP ${status}, non-JSON body) \u2014 check IP allowlisting / credentials / User-Agent`,
2810
+ status,
2811
+ data: { bodyKind: /^\s*</.test(body) ? "html" : "text", bodyLength: body.length }
2812
+ });
2813
+ }
2741
2814
  const data = { body };
2742
2815
  const issues = normalizeErrorIssues(body);
2743
2816
  switch (status) {