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