@lonca/trendyol 1.0.1 → 1.1.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/{client-CnDyop_o.d.cts → client-Bp0jKEU7.d.cts} +26 -0
- package/dist/{client-CnDyop_o.d.ts → client-Bp0jKEU7.d.ts} +26 -0
- package/dist/index.cjs +29 -9
- 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 +29 -9
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +27 -8
- 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 +27 -8
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/testing.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as BatchRequestStatus, ba as TrendyolClient } from './client-
|
|
1
|
+
import { g as BatchRequestStatus, ba as TrendyolClient } from './client-Bp0jKEU7.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 { g as BatchRequestStatus, ba as TrendyolClient } from './client-
|
|
1
|
+
import { g as BatchRequestStatus, ba as TrendyolClient } from './client-Bp0jKEU7.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
|
@@ -2,6 +2,11 @@ import { createRequester, AuthError, LoncaError, ServerError, RateLimitError, No
|
|
|
2
2
|
|
|
3
3
|
// src/resources/brands.ts
|
|
4
4
|
var DEFAULT_PAGE_SIZE = 1e3;
|
|
5
|
+
function toBrand(node) {
|
|
6
|
+
const brand = { id: String(node.id), name: node.name };
|
|
7
|
+
if (typeof node.luxe === "boolean") brand.luxe = node.luxe;
|
|
8
|
+
return brand;
|
|
9
|
+
}
|
|
5
10
|
var BrandsResource = class {
|
|
6
11
|
constructor(transport, limiter) {
|
|
7
12
|
this.transport = transport;
|
|
@@ -12,6 +17,14 @@ var BrandsResource = class {
|
|
|
12
17
|
/**
|
|
13
18
|
* List Trendyol brands, one page at a time.
|
|
14
19
|
*
|
|
20
|
+
* **Next-page heuristic.** Trendyol's brand list carries no page count (neither the docs
|
|
21
|
+
* nor the prod wire have `totalPages` / `totalElements` — the response is just
|
|
22
|
+
* `{ brands: [...] }`). So when `totalPages` is absent, a **full page** (at least `limit`
|
|
23
|
+
* brands — Trendyol may send ~1000 even for a smaller `limit`) means "there may be more"
|
|
24
|
+
* and sets `nextCursor`; a short page is the last one. When the
|
|
25
|
+
* total is an exact multiple of the page size, `paginate()` makes one extra request that
|
|
26
|
+
* comes back empty and stops there. If Trendyol ever sends `totalPages`, it wins.
|
|
27
|
+
*
|
|
15
28
|
* @example
|
|
16
29
|
* ```ts
|
|
17
30
|
* import { paginate } from '@lonca/core';
|
|
@@ -29,8 +42,10 @@ var BrandsResource = class {
|
|
|
29
42
|
query: { page, size },
|
|
30
43
|
rateLimiter: this.limiter
|
|
31
44
|
});
|
|
32
|
-
const
|
|
33
|
-
const
|
|
45
|
+
const brands = data?.brands ?? [];
|
|
46
|
+
const items = brands.map(toBrand);
|
|
47
|
+
const hasMore = typeof data?.totalPages === "number" ? page + 1 < data.totalPages : size > 0 && brands.length >= size;
|
|
48
|
+
const nextCursor = hasMore ? String(page + 1) : void 0;
|
|
34
49
|
return nextCursor !== void 0 ? { items, nextCursor } : { items };
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
@@ -54,7 +69,7 @@ var BrandsResource = class {
|
|
|
54
69
|
query: { name },
|
|
55
70
|
rateLimiter: this.limiter
|
|
56
71
|
});
|
|
57
|
-
return (data ?? []).map(
|
|
72
|
+
return (data ?? []).map(toBrand);
|
|
58
73
|
}
|
|
59
74
|
};
|
|
60
75
|
function normalizeCategory(node) {
|
|
@@ -1019,7 +1034,7 @@ var LocationsResource = class {
|
|
|
1019
1034
|
}
|
|
1020
1035
|
// ─── Domestic (TR / AZ) ───────────────────────────────────────────────
|
|
1021
1036
|
async getTurkeyCities() {
|
|
1022
|
-
return this.cities(`/integration/member/countries/domestic/TR/cities
|
|
1037
|
+
return this.cities(`/integration/member/countries/domestic/TR/cities`, "TR");
|
|
1023
1038
|
}
|
|
1024
1039
|
/**
|
|
1025
1040
|
* List districts for a Turkish city. **Pass the city `id`** (`City.id`) — the
|
|
@@ -1041,7 +1056,7 @@ var LocationsResource = class {
|
|
|
1041
1056
|
);
|
|
1042
1057
|
}
|
|
1043
1058
|
async getAzerbaijanCities() {
|
|
1044
|
-
return this.cities(`/integration/member/countries/domestic/AZ/cities
|
|
1059
|
+
return this.cities(`/integration/member/countries/domestic/AZ/cities`, "AZ");
|
|
1045
1060
|
}
|
|
1046
1061
|
/** List districts for an Azerbaijani city. **Pass the city `id`** (`City.id`), not `code`. */
|
|
1047
1062
|
async getAzerbaijanDistricts(cityId) {
|
|
@@ -1051,7 +1066,10 @@ var LocationsResource = class {
|
|
|
1051
1066
|
}
|
|
1052
1067
|
// ─── International (GULF / CEE) ───────────────────────────────────────
|
|
1053
1068
|
async getCitiesByCountry(countryCode) {
|
|
1054
|
-
return this.cities(
|
|
1069
|
+
return this.cities(
|
|
1070
|
+
`/integration/member/countries/${encodeURIComponent(countryCode)}/cities`,
|
|
1071
|
+
countryCode
|
|
1072
|
+
);
|
|
1055
1073
|
}
|
|
1056
1074
|
async getDistrictsByCity(countryCode, cityId) {
|
|
1057
1075
|
return this.districts(
|
|
@@ -1059,7 +1077,8 @@ var LocationsResource = class {
|
|
|
1059
1077
|
);
|
|
1060
1078
|
}
|
|
1061
1079
|
// ─── Shared paginators ────────────────────────────────────────────────
|
|
1062
|
-
|
|
1080
|
+
/** `countryCode` is the lookup's country — city rows do not carry one on the wire. */
|
|
1081
|
+
async cities(path, countryCode) {
|
|
1063
1082
|
const data = await this.transport.request({
|
|
1064
1083
|
method: "GET",
|
|
1065
1084
|
path,
|
|
@@ -1069,7 +1088,7 @@ var LocationsResource = class {
|
|
|
1069
1088
|
id: node.id !== void 0 ? String(node.id) : void 0,
|
|
1070
1089
|
code: String(node.code ?? node.id ?? ""),
|
|
1071
1090
|
name: node.name,
|
|
1072
|
-
countryCode
|
|
1091
|
+
countryCode
|
|
1073
1092
|
}));
|
|
1074
1093
|
}
|
|
1075
1094
|
async districts(path) {
|