@lonca/trendyol 0.12.0 → 0.13.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/README.md +6 -6
- package/dist/{client-BJjLOn4v.d.cts → client-DMndJSb0.d.cts} +33 -3
- package/dist/{client-BJjLOn4v.d.ts → client-DMndJSb0.d.ts} +33 -3
- package/dist/index.cjs +30 -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 +30 -9
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +30 -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 +30 -9
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="left">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/loncadev/
|
|
2
|
+
<img src="https://raw.githubusercontent.com/loncadev/.github/main/brand/logomark.svg" alt="Lonca" height="32">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
# @lonca/trendyol
|
|
@@ -53,13 +53,12 @@ pnpm add @lonca/trendyol @lonca/core
|
|
|
53
53
|
# or npm install / yarn add
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
`@lonca/core` is a peer dependency (
|
|
56
|
+
`@lonca/core` is a peer dependency (error classes, the token-bucket limiter). The `paginate` / `paginateOffset` helpers and the `CursorPage` / `OffsetPage` types are re-exported from `@lonca/trendyol`, so you can import them straight from this package.
|
|
57
57
|
|
|
58
58
|
## Quick start
|
|
59
59
|
|
|
60
60
|
```ts
|
|
61
|
-
import { createTrendyolClient } from '@lonca/trendyol';
|
|
62
|
-
import { paginate } from '@lonca/core';
|
|
61
|
+
import { createTrendyolClient, paginate } from '@lonca/trendyol';
|
|
63
62
|
|
|
64
63
|
const client = createTrendyolClient({
|
|
65
64
|
sellerId: 12345,
|
|
@@ -203,7 +202,8 @@ const start = new Date('2026-05-01');
|
|
|
203
202
|
const end = new Date('2026-05-31');
|
|
204
203
|
|
|
205
204
|
for await (const tx of paginate((p) =>
|
|
206
|
-
|
|
205
|
+
// `transactionType` is required (Trendyol 500s without it); `limit` is clamped to 500/1000.
|
|
206
|
+
client.finance.getSettlements({ ...p, startDate: start, endDate: end, transactionType: 'Sale' }),
|
|
207
207
|
)) {
|
|
208
208
|
// tx is a typed FinancialTransaction — no .raw drill required for documented fields
|
|
209
209
|
if (tx.transactionType === 'Satış' && tx.orderNumber) {
|
|
@@ -349,7 +349,7 @@ await client.invoices.sendLink({ shipmentPackageId: 100, invoiceLink: 'https://x
|
|
|
349
349
|
await client.invoices.deleteLink({ serviceSourceId: 1, channelId: 2, customerId: 3 });
|
|
350
350
|
|
|
351
351
|
// finance — typed FinancialTransaction[]
|
|
352
|
-
await client.finance.getSettlements({ startDate, endDate });
|
|
352
|
+
await client.finance.getSettlements({ startDate, endDate, transactionType: 'Sale' }); // transactionType required
|
|
353
353
|
await client.finance.getOtherFinancials({ transactionType: 'DeductionInvoices' });
|
|
354
354
|
|
|
355
355
|
// labels
|
|
@@ -696,7 +696,17 @@ type OtherFinancialRow = FinancialTransaction;
|
|
|
696
696
|
interface ListFinanceParams extends CursorPaginationParams {
|
|
697
697
|
startDate?: Date;
|
|
698
698
|
endDate?: Date;
|
|
699
|
+
/**
|
|
700
|
+
* **Required** by Trendyol's CHE finance API (it returns 500 without one),
|
|
701
|
+
* e.g. `'Sale'`, `'Return'`, `'Discount'`, `'DeductionInvoices'`. The SDK
|
|
702
|
+
* throws a `ValidationError` if omitted.
|
|
703
|
+
*/
|
|
699
704
|
transactionType?: string;
|
|
705
|
+
/**
|
|
706
|
+
* Page size. Trendyol's finance API only accepts **500 or 1000** — the SDK
|
|
707
|
+
* clamps any value to the nearest of those (default 500).
|
|
708
|
+
*/
|
|
709
|
+
limit?: number;
|
|
700
710
|
}
|
|
701
711
|
interface CreateCommonLabelInput {
|
|
702
712
|
/** Currently the only documented format Trendyol accepts. */
|
|
@@ -743,18 +753,28 @@ interface Country {
|
|
|
743
753
|
raw: Record<string, unknown>;
|
|
744
754
|
}
|
|
745
755
|
interface City {
|
|
756
|
+
/**
|
|
757
|
+
* Trendyol's internal city id — the value the **nested** endpoints expect
|
|
758
|
+
* (`getTurkeyDistricts(city.id)`). Distinct from `code` (the plate-style
|
|
759
|
+
* display code, e.g. `"1"` for Adana); passing `code` there returns 500.
|
|
760
|
+
*/
|
|
761
|
+
id?: string;
|
|
746
762
|
code: string;
|
|
747
763
|
name?: string;
|
|
748
764
|
countryCode?: string;
|
|
749
765
|
raw: Record<string, unknown>;
|
|
750
766
|
}
|
|
751
767
|
interface District {
|
|
768
|
+
/** Trendyol's internal district id — pass to `getTurkeyNeighborhoods(cityId, district.id)`. */
|
|
769
|
+
id?: string;
|
|
752
770
|
code: string;
|
|
753
771
|
name?: string;
|
|
754
772
|
cityCode?: string;
|
|
755
773
|
raw: Record<string, unknown>;
|
|
756
774
|
}
|
|
757
775
|
interface Neighborhood {
|
|
776
|
+
/** Trendyol's internal neighborhood id. */
|
|
777
|
+
id?: string;
|
|
758
778
|
code: string;
|
|
759
779
|
name?: string;
|
|
760
780
|
districtCode?: string;
|
|
@@ -1193,10 +1213,20 @@ declare class LocationsResource {
|
|
|
1193
1213
|
/** List all supported countries (Türkiye + AZ + GULF + CEE). */
|
|
1194
1214
|
getCountries(): Promise<Country[]>;
|
|
1195
1215
|
getTurkeyCities(): Promise<City[]>;
|
|
1196
|
-
|
|
1197
|
-
|
|
1216
|
+
/**
|
|
1217
|
+
* List districts for a Turkish city. **Pass the city `id`** (`City.id`) — the
|
|
1218
|
+
* nested endpoint keys off Trendyol's internal id, not the display `code`, and
|
|
1219
|
+
* returns 500 for the code. Verified live.
|
|
1220
|
+
*/
|
|
1221
|
+
getTurkeyDistricts(cityId: string | number): Promise<District[]>;
|
|
1222
|
+
/**
|
|
1223
|
+
* List neighborhoods for a Turkish district. **Pass the ids** (`City.id`,
|
|
1224
|
+
* `District.id`) — not the display codes (those 500).
|
|
1225
|
+
*/
|
|
1226
|
+
getTurkeyNeighborhoods(cityId: string | number, districtId: string | number): Promise<Neighborhood[]>;
|
|
1198
1227
|
getAzerbaijanCities(): Promise<City[]>;
|
|
1199
|
-
|
|
1228
|
+
/** List districts for an Azerbaijani city. **Pass the city `id`** (`City.id`), not `code`. */
|
|
1229
|
+
getAzerbaijanDistricts(cityId: string | number): Promise<District[]>;
|
|
1200
1230
|
getCitiesByCountry(countryCode: string): Promise<City[]>;
|
|
1201
1231
|
getDistrictsByCity(countryCode: string, cityId: string | number): Promise<District[]>;
|
|
1202
1232
|
private cities;
|
|
@@ -696,7 +696,17 @@ type OtherFinancialRow = FinancialTransaction;
|
|
|
696
696
|
interface ListFinanceParams extends CursorPaginationParams {
|
|
697
697
|
startDate?: Date;
|
|
698
698
|
endDate?: Date;
|
|
699
|
+
/**
|
|
700
|
+
* **Required** by Trendyol's CHE finance API (it returns 500 without one),
|
|
701
|
+
* e.g. `'Sale'`, `'Return'`, `'Discount'`, `'DeductionInvoices'`. The SDK
|
|
702
|
+
* throws a `ValidationError` if omitted.
|
|
703
|
+
*/
|
|
699
704
|
transactionType?: string;
|
|
705
|
+
/**
|
|
706
|
+
* Page size. Trendyol's finance API only accepts **500 or 1000** — the SDK
|
|
707
|
+
* clamps any value to the nearest of those (default 500).
|
|
708
|
+
*/
|
|
709
|
+
limit?: number;
|
|
700
710
|
}
|
|
701
711
|
interface CreateCommonLabelInput {
|
|
702
712
|
/** Currently the only documented format Trendyol accepts. */
|
|
@@ -743,18 +753,28 @@ interface Country {
|
|
|
743
753
|
raw: Record<string, unknown>;
|
|
744
754
|
}
|
|
745
755
|
interface City {
|
|
756
|
+
/**
|
|
757
|
+
* Trendyol's internal city id — the value the **nested** endpoints expect
|
|
758
|
+
* (`getTurkeyDistricts(city.id)`). Distinct from `code` (the plate-style
|
|
759
|
+
* display code, e.g. `"1"` for Adana); passing `code` there returns 500.
|
|
760
|
+
*/
|
|
761
|
+
id?: string;
|
|
746
762
|
code: string;
|
|
747
763
|
name?: string;
|
|
748
764
|
countryCode?: string;
|
|
749
765
|
raw: Record<string, unknown>;
|
|
750
766
|
}
|
|
751
767
|
interface District {
|
|
768
|
+
/** Trendyol's internal district id — pass to `getTurkeyNeighborhoods(cityId, district.id)`. */
|
|
769
|
+
id?: string;
|
|
752
770
|
code: string;
|
|
753
771
|
name?: string;
|
|
754
772
|
cityCode?: string;
|
|
755
773
|
raw: Record<string, unknown>;
|
|
756
774
|
}
|
|
757
775
|
interface Neighborhood {
|
|
776
|
+
/** Trendyol's internal neighborhood id. */
|
|
777
|
+
id?: string;
|
|
758
778
|
code: string;
|
|
759
779
|
name?: string;
|
|
760
780
|
districtCode?: string;
|
|
@@ -1193,10 +1213,20 @@ declare class LocationsResource {
|
|
|
1193
1213
|
/** List all supported countries (Türkiye + AZ + GULF + CEE). */
|
|
1194
1214
|
getCountries(): Promise<Country[]>;
|
|
1195
1215
|
getTurkeyCities(): Promise<City[]>;
|
|
1196
|
-
|
|
1197
|
-
|
|
1216
|
+
/**
|
|
1217
|
+
* List districts for a Turkish city. **Pass the city `id`** (`City.id`) — the
|
|
1218
|
+
* nested endpoint keys off Trendyol's internal id, not the display `code`, and
|
|
1219
|
+
* returns 500 for the code. Verified live.
|
|
1220
|
+
*/
|
|
1221
|
+
getTurkeyDistricts(cityId: string | number): Promise<District[]>;
|
|
1222
|
+
/**
|
|
1223
|
+
* List neighborhoods for a Turkish district. **Pass the ids** (`City.id`,
|
|
1224
|
+
* `District.id`) — not the display codes (those 500).
|
|
1225
|
+
*/
|
|
1226
|
+
getTurkeyNeighborhoods(cityId: string | number, districtId: string | number): Promise<Neighborhood[]>;
|
|
1198
1227
|
getAzerbaijanCities(): Promise<City[]>;
|
|
1199
|
-
|
|
1228
|
+
/** List districts for an Azerbaijani city. **Pass the city `id`** (`City.id`), not `code`. */
|
|
1229
|
+
getAzerbaijanDistricts(cityId: string | number): Promise<District[]>;
|
|
1200
1230
|
getCitiesByCountry(countryCode: string): Promise<City[]>;
|
|
1201
1231
|
getDistrictsByCity(countryCode: string, cityId: string | number): Promise<District[]>;
|
|
1202
1232
|
private cities;
|
package/dist/index.cjs
CHANGED
|
@@ -716,12 +716,20 @@ var FinanceResource = class {
|
|
|
716
716
|
);
|
|
717
717
|
}
|
|
718
718
|
async queryPage(path, params) {
|
|
719
|
-
|
|
719
|
+
if (!params.transactionType) {
|
|
720
|
+
throw new core.ValidationError({
|
|
721
|
+
message: "finance: transactionType is required (Trendyol returns 500 without it) \u2014 pass e.g. { transactionType: 'Sale' }."
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
const size = (params.limit ?? 500) > 500 ? 1e3 : 500;
|
|
720
725
|
const page = params.cursor ? Number.parseInt(params.cursor, 10) : 0;
|
|
721
|
-
const query = {
|
|
726
|
+
const query = {
|
|
727
|
+
page,
|
|
728
|
+
size,
|
|
729
|
+
transactionType: params.transactionType
|
|
730
|
+
};
|
|
722
731
|
if (params.startDate) query.startDate = params.startDate.getTime();
|
|
723
732
|
if (params.endDate) query.endDate = params.endDate.getTime();
|
|
724
|
-
if (params.transactionType) query.transactionType = params.transactionType;
|
|
725
733
|
const data = await this.transport.request({
|
|
726
734
|
method: "GET",
|
|
727
735
|
path,
|
|
@@ -998,22 +1006,32 @@ var LocationsResource = class {
|
|
|
998
1006
|
async getTurkeyCities() {
|
|
999
1007
|
return this.cities(`/integration/member/countries/domestic/TR/cities`);
|
|
1000
1008
|
}
|
|
1001
|
-
|
|
1009
|
+
/**
|
|
1010
|
+
* List districts for a Turkish city. **Pass the city `id`** (`City.id`) — the
|
|
1011
|
+
* nested endpoint keys off Trendyol's internal id, not the display `code`, and
|
|
1012
|
+
* returns 500 for the code. Verified live.
|
|
1013
|
+
*/
|
|
1014
|
+
async getTurkeyDistricts(cityId) {
|
|
1002
1015
|
return this.districts(
|
|
1003
|
-
`/integration/member/countries/domestic/TR/cities/${encodeURIComponent(String(
|
|
1016
|
+
`/integration/member/countries/domestic/TR/cities/${encodeURIComponent(String(cityId))}/districts`
|
|
1004
1017
|
);
|
|
1005
1018
|
}
|
|
1006
|
-
|
|
1019
|
+
/**
|
|
1020
|
+
* List neighborhoods for a Turkish district. **Pass the ids** (`City.id`,
|
|
1021
|
+
* `District.id`) — not the display codes (those 500).
|
|
1022
|
+
*/
|
|
1023
|
+
async getTurkeyNeighborhoods(cityId, districtId) {
|
|
1007
1024
|
return this.neighborhoods(
|
|
1008
|
-
`/integration/member/countries/domestic/TR/cities/${encodeURIComponent(String(
|
|
1025
|
+
`/integration/member/countries/domestic/TR/cities/${encodeURIComponent(String(cityId))}/districts/${encodeURIComponent(String(districtId))}/neighborhoods`
|
|
1009
1026
|
);
|
|
1010
1027
|
}
|
|
1011
1028
|
async getAzerbaijanCities() {
|
|
1012
1029
|
return this.cities(`/integration/member/countries/domestic/AZ/cities`);
|
|
1013
1030
|
}
|
|
1014
|
-
|
|
1031
|
+
/** List districts for an Azerbaijani city. **Pass the city `id`** (`City.id`), not `code`. */
|
|
1032
|
+
async getAzerbaijanDistricts(cityId) {
|
|
1015
1033
|
return this.districts(
|
|
1016
|
-
`/integration/member/countries/domestic/AZ/cities/${encodeURIComponent(String(
|
|
1034
|
+
`/integration/member/countries/domestic/AZ/cities/${encodeURIComponent(String(cityId))}/districts`
|
|
1017
1035
|
);
|
|
1018
1036
|
}
|
|
1019
1037
|
// ─── International (GULF / CEE) ───────────────────────────────────────
|
|
@@ -1033,6 +1051,7 @@ var LocationsResource = class {
|
|
|
1033
1051
|
rateLimiter: this.limiter
|
|
1034
1052
|
});
|
|
1035
1053
|
return n(data, (node) => ({
|
|
1054
|
+
id: node.id !== void 0 ? String(node.id) : void 0,
|
|
1036
1055
|
code: String(node.code ?? node.id ?? ""),
|
|
1037
1056
|
name: node.name,
|
|
1038
1057
|
countryCode: node.countryCode
|
|
@@ -1045,6 +1064,7 @@ var LocationsResource = class {
|
|
|
1045
1064
|
rateLimiter: this.limiter
|
|
1046
1065
|
});
|
|
1047
1066
|
return n(data, (node) => ({
|
|
1067
|
+
id: node.id !== void 0 ? String(node.id) : void 0,
|
|
1048
1068
|
code: String(node.code ?? node.id ?? ""),
|
|
1049
1069
|
name: node.name,
|
|
1050
1070
|
cityCode: node.cityCode !== void 0 ? String(node.cityCode) : void 0
|
|
@@ -1057,6 +1077,7 @@ var LocationsResource = class {
|
|
|
1057
1077
|
rateLimiter: this.limiter
|
|
1058
1078
|
});
|
|
1059
1079
|
return n(data, (node) => ({
|
|
1080
|
+
id: node.id !== void 0 ? String(node.id) : void 0,
|
|
1060
1081
|
code: String(node.code ?? node.id ?? ""),
|
|
1061
1082
|
name: node.name,
|
|
1062
1083
|
districtCode: node.districtCode !== void 0 ? String(node.districtCode) : void 0
|