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