@lonca/trendyol 0.11.0 → 0.11.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.
- package/README.md +18 -33
- package/dist/{client-BZeFAlrp.d.cts → client-CCA1P7sb.d.cts} +4 -16
- package/dist/{client-BZeFAlrp.d.ts → client-CCA1P7sb.d.ts} +4 -16
- package/dist/index.cjs +16 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -108
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +16 -107
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +17 -108
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
package/dist/testing.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as BatchRequestStatus, b3 as TrendyolClient } from './client-
|
|
1
|
+
import { f as BatchRequestStatus, b3 as TrendyolClient } from './client-CCA1P7sb.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, b3 as TrendyolClient } from './client-
|
|
1
|
+
import { f as BatchRequestStatus, b3 as TrendyolClient } from './client-CCA1P7sb.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,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { randomUUID } from 'crypto';
|
|
1
|
+
import { createRequester, LoncaError, ServerError, RateLimitError, NotFoundError, ValidationError, AuthError, TokenBucketRateLimiter, TimeoutError } from '@lonca/core';
|
|
3
2
|
|
|
4
3
|
// src/resources/brands.ts
|
|
5
4
|
var DEFAULT_PAGE_SIZE = 1e3;
|
|
@@ -39,7 +38,7 @@ var BrandsResource = class {
|
|
|
39
38
|
* `createProducts` and don't want to page through the full `list()`
|
|
40
39
|
* (1000 brands per page).
|
|
41
40
|
*
|
|
42
|
-
* **
|
|
41
|
+
* **Wire fact (verified STAGE 2026-05-25):** Trendyol's
|
|
43
42
|
* doc claims this is a case-sensitive *exact* match, but live behaviour
|
|
44
43
|
* is **substring + case-insensitive** — `search('Trendyol')` returns
|
|
45
44
|
* 17 hits including `TRENDYOLMILLA`, `trendyol vavist`, `Trendyol Üyelik`.
|
|
@@ -1257,7 +1256,8 @@ var OrdersResource = class {
|
|
|
1257
1256
|
const items = (data.content ?? []).map(normalizePackage2);
|
|
1258
1257
|
const totalPages = typeof data.totalPages === "number" ? data.totalPages : 0;
|
|
1259
1258
|
const result = { items };
|
|
1260
|
-
|
|
1259
|
+
const nextPageWithinCap = (page + 2) * size <= MAX_OFFSET_RECORDS;
|
|
1260
|
+
if (page + 1 < totalPages && nextPageWithinCap) {
|
|
1261
1261
|
result.nextCursor = String(page + 1);
|
|
1262
1262
|
}
|
|
1263
1263
|
return result;
|
|
@@ -2779,14 +2779,6 @@ function extractErrorsArray(body) {
|
|
|
2779
2779
|
}
|
|
2780
2780
|
return void 0;
|
|
2781
2781
|
}
|
|
2782
|
-
function parseRetryAfter(header) {
|
|
2783
|
-
if (!header) return void 0;
|
|
2784
|
-
const seconds = Number(header);
|
|
2785
|
-
if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
|
|
2786
|
-
const epoch = Date.parse(header);
|
|
2787
|
-
if (!Number.isNaN(epoch)) return Math.max(0, epoch - Date.now());
|
|
2788
|
-
return void 0;
|
|
2789
|
-
}
|
|
2790
2782
|
|
|
2791
2783
|
// src/transport.ts
|
|
2792
2784
|
var BASE_URLS = {
|
|
@@ -2797,95 +2789,26 @@ var TrendyolTransport = class {
|
|
|
2797
2789
|
constructor(config) {
|
|
2798
2790
|
this.config = config;
|
|
2799
2791
|
this.baseUrl = BASE_URLS[config.env];
|
|
2800
|
-
this.
|
|
2801
|
-
|
|
2802
|
-
|
|
2792
|
+
this.requester = createRequester({
|
|
2793
|
+
fetch: config.fetch ?? fetch,
|
|
2794
|
+
logger: config.logger,
|
|
2795
|
+
timeoutMs: config.timeoutMs ?? 3e4,
|
|
2796
|
+
label: "Trendyol",
|
|
2797
|
+
logPrefix: "trendyol",
|
|
2798
|
+
buildUrl: (opts) => this.buildUrl(opts.path, opts.query),
|
|
2799
|
+
buildHeaders: (correlationId) => this.buildHeaders(correlationId),
|
|
2800
|
+
mapHttpError
|
|
2801
|
+
});
|
|
2803
2802
|
}
|
|
2804
2803
|
config;
|
|
2805
2804
|
baseUrl;
|
|
2806
|
-
|
|
2807
|
-
timeoutMs;
|
|
2808
|
-
fetchImpl;
|
|
2805
|
+
requester;
|
|
2809
2806
|
/** Seller ID this transport is configured with. Resources read it for path-building. */
|
|
2810
2807
|
get sellerId() {
|
|
2811
2808
|
return this.config.sellerId;
|
|
2812
2809
|
}
|
|
2813
|
-
|
|
2814
|
-
return
|
|
2815
|
-
async (attempt) => {
|
|
2816
|
-
if (opts.rateLimiter) await opts.rateLimiter.acquire(opts.signal);
|
|
2817
|
-
const url = this.buildUrl(opts.path, opts.query);
|
|
2818
|
-
const correlationId = randomUUID();
|
|
2819
|
-
const headers = { ...this.buildHeaders(correlationId), ...opts.headers };
|
|
2820
|
-
const init = {
|
|
2821
|
-
method: opts.method,
|
|
2822
|
-
headers,
|
|
2823
|
-
signal: this.composeSignal(opts.signal)
|
|
2824
|
-
};
|
|
2825
|
-
if (opts.body !== void 0 && opts.method !== "GET") {
|
|
2826
|
-
if (opts.body instanceof FormData) {
|
|
2827
|
-
init.body = opts.body;
|
|
2828
|
-
delete headers["Content-Type"];
|
|
2829
|
-
} else {
|
|
2830
|
-
init.body = JSON.stringify(opts.body);
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
this.logger.debug("trendyol.request", {
|
|
2834
|
-
method: opts.method,
|
|
2835
|
-
url,
|
|
2836
|
-
correlationId,
|
|
2837
|
-
attempt
|
|
2838
|
-
});
|
|
2839
|
-
let response;
|
|
2840
|
-
try {
|
|
2841
|
-
response = await this.fetchImpl(url, init);
|
|
2842
|
-
} catch (err) {
|
|
2843
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
2844
|
-
throw new TimeoutError({
|
|
2845
|
-
message: `Trendyol request timed out after ${this.timeoutMs}ms`,
|
|
2846
|
-
cause: err
|
|
2847
|
-
});
|
|
2848
|
-
}
|
|
2849
|
-
throw new NetworkError({
|
|
2850
|
-
message: "Trendyol network failure",
|
|
2851
|
-
cause: err
|
|
2852
|
-
});
|
|
2853
|
-
}
|
|
2854
|
-
if (!response.ok) {
|
|
2855
|
-
const body = await safeJson(response);
|
|
2856
|
-
const retryAfterMs = parseRetryAfter(response.headers.get("retry-after"));
|
|
2857
|
-
const error = mapHttpError(response.status, body, retryAfterMs);
|
|
2858
|
-
this.logger.warn("trendyol.error", {
|
|
2859
|
-
method: opts.method,
|
|
2860
|
-
url,
|
|
2861
|
-
correlationId,
|
|
2862
|
-
status: response.status,
|
|
2863
|
-
code: error.code,
|
|
2864
|
-
retryable: error.retryable
|
|
2865
|
-
});
|
|
2866
|
-
throw error;
|
|
2867
|
-
}
|
|
2868
|
-
this.logger.debug("trendyol.response", {
|
|
2869
|
-
correlationId,
|
|
2870
|
-
status: response.status
|
|
2871
|
-
});
|
|
2872
|
-
if (response.status === 204) return void 0;
|
|
2873
|
-
return await safeJson(response);
|
|
2874
|
-
},
|
|
2875
|
-
{
|
|
2876
|
-
signal: opts.signal,
|
|
2877
|
-
onRetry: (err, attempt, delay2) => {
|
|
2878
|
-
if (err instanceof LoncaError) {
|
|
2879
|
-
this.logger.warn("trendyol.retry", {
|
|
2880
|
-
attempt,
|
|
2881
|
-
delayMs: delay2,
|
|
2882
|
-
code: err.code,
|
|
2883
|
-
status: err.status
|
|
2884
|
-
});
|
|
2885
|
-
}
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
|
-
);
|
|
2810
|
+
request(opts) {
|
|
2811
|
+
return this.requester(opts);
|
|
2889
2812
|
}
|
|
2890
2813
|
buildUrl(path, query) {
|
|
2891
2814
|
const url = new URL(path, this.baseUrl);
|
|
@@ -2908,21 +2831,7 @@ var TrendyolTransport = class {
|
|
|
2908
2831
|
Accept: "application/json"
|
|
2909
2832
|
};
|
|
2910
2833
|
}
|
|
2911
|
-
composeSignal(external) {
|
|
2912
|
-
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
2913
|
-
if (!external) return timeoutSignal;
|
|
2914
|
-
return AbortSignal.any([external, timeoutSignal]);
|
|
2915
|
-
}
|
|
2916
2834
|
};
|
|
2917
|
-
async function safeJson(response) {
|
|
2918
|
-
const text = await response.text();
|
|
2919
|
-
if (!text) return void 0;
|
|
2920
|
-
try {
|
|
2921
|
-
return JSON.parse(text);
|
|
2922
|
-
} catch {
|
|
2923
|
-
return text;
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
2835
|
|
|
2927
2836
|
// src/client.ts
|
|
2928
2837
|
function buildClient(transport) {
|