@teez-sdk/teez-b2c-api 2.2.0 → 3.0.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/index.mjs CHANGED
@@ -1,72 +1,6 @@
1
1
  import * as z from "zod/mini";
2
+ import { safeParse } from "zod/mini";
2
3
 
3
- //#region src/errors/teez-error.ts
4
- /**
5
- * Base error class for all SDK-related errors.
6
- */
7
- var TeezError = class extends Error {
8
- name = "TeezError";
9
- };
10
-
11
- //#endregion
12
- //#region src/errors/teez-validation-error.ts
13
- /**
14
- * Error thrown when validation fails.
15
- */
16
- var TeezValidationError = class extends TeezError {
17
- name = "TeezValidationError";
18
- /**
19
- * List of standardized validation issues.
20
- */
21
- issues;
22
- /**
23
- * The raw data that failed validation.
24
- */
25
- data;
26
- constructor(message, { issues, data, ...errorOptions }) {
27
- super(message, errorOptions);
28
- this.issues = issues;
29
- this.data = data;
30
- }
31
- };
32
-
33
- //#endregion
34
- //#region src/http/helpers.ts
35
- /**
36
- * Constructs a full URL with query parameters.
37
- */
38
- function buildUrl(path, baseUrl, queryParams) {
39
- const url = new URL(path, baseUrl);
40
- if (queryParams != void 0) for (const [key, value] of Object.entries(queryParams)) {
41
- if (value == void 0) continue;
42
- if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
43
- else url.searchParams.set(key, String(value));
44
- }
45
- return String(url);
46
- }
47
- /**
48
- * Converts Zod ZodError to abstract ValidationIssue[].
49
- */
50
- function toValidationIssues(error) {
51
- return error.issues.map((issue) => ({
52
- code: issue.code,
53
- path: issue.path,
54
- message: issue.message
55
- }));
56
- }
57
- /**
58
- * Validates and parses the API response data against a schema.
59
- */
60
- function parseResponse(schema, data) {
61
- const result = z.safeParse(schema, data);
62
- if (!result.success) throw new TeezValidationError("Response validation failed", {
63
- issues: toValidationIssues(result.error),
64
- data
65
- });
66
- return result.data;
67
- }
68
-
69
- //#endregion
70
4
  //#region src/api/auth/schemas.ts
71
5
  /**
72
6
  * Response schema for initiating phone login.
@@ -121,11 +55,11 @@ var AuthApi = class {
121
55
  * phone: "+77071234567"
122
56
  * });
123
57
  */
124
- async login(params) {
125
- return parseResponse(AuthApiLoginResponseSchema, await this.http.post({
58
+ login(params) {
59
+ return this.http.post({
126
60
  path: "/auth/login",
127
61
  body: params
128
- }));
62
+ }, AuthApiLoginResponseSchema);
129
63
  }
130
64
  /**
131
65
  * Verifies OTP code and obtains JWT access and refresh tokens.
@@ -136,11 +70,11 @@ var AuthApi = class {
136
70
  * otpCode: "2610"
137
71
  * });
138
72
  */
139
- async verify(params) {
140
- return parseResponse(AuthApiVerifyResponseSchema, await this.http.post({
73
+ verify(params) {
74
+ return this.http.post({
141
75
  path: "/auth/verify",
142
76
  body: params
143
- }));
77
+ }, AuthApiVerifyResponseSchema);
144
78
  }
145
79
  /**
146
80
  * Validates the current JWT token and retrieves user information.
@@ -148,12 +82,11 @@ var AuthApi = class {
148
82
  * @example
149
83
  * const response = await client.auth.checkToken();
150
84
  */
151
- async checkToken(params = {}) {
152
- return await this.http.get({
85
+ checkToken(params = {}) {
86
+ return this.http.get({
153
87
  path: "/auth/check-token",
154
- params,
155
- schema: AuthApiCheckTokenResponseSchema
156
- });
88
+ params
89
+ }, AuthApiCheckTokenResponseSchema);
157
90
  }
158
91
  };
159
92
 
@@ -221,9 +154,8 @@ var BannersApi = class {
221
154
  list(params = {}) {
222
155
  return this.http.get({
223
156
  path: "/api/v3/banners",
224
- params,
225
- schema: BannersApiListResponseSchema
226
- });
157
+ params
158
+ }, BannersApiListResponseSchema);
227
159
  }
228
160
  };
229
161
 
@@ -298,9 +230,8 @@ var CategoriesApi = class {
298
230
  list(params = {}) {
299
231
  return this.http.get({
300
232
  path: "/categories",
301
- params,
302
- schema: CategoriesApiListResponseSchema
303
- });
233
+ params
234
+ }, CategoriesApiListResponseSchema);
304
235
  }
305
236
  /**
306
237
  * Retrieves detailed information about a specific category by its ID.
@@ -313,9 +244,8 @@ var CategoriesApi = class {
313
244
  get(params) {
314
245
  return this.http.get({
315
246
  path: `/categories/${params.categoryId}`,
316
- params,
317
- schema: CategoriesApiGetResponseSchema
318
- });
247
+ params
248
+ }, CategoriesApiGetResponseSchema);
319
249
  }
320
250
  /**
321
251
  * Retrieves parent categories for specific category IDs.
@@ -328,9 +258,8 @@ var CategoriesApi = class {
328
258
  getParents(params) {
329
259
  return this.http.get({
330
260
  path: "/api/v1/categories/parents",
331
- params,
332
- schema: CategoriesApiGetParentsResponseSchema
333
- });
261
+ params
262
+ }, CategoriesApiGetParentsResponseSchema);
334
263
  }
335
264
  };
336
265
 
@@ -489,9 +418,8 @@ var CollectionsApi = class {
489
418
  getSkus(params) {
490
419
  return this.http.get({
491
420
  path: "/api/v2/collections/skus",
492
- params,
493
- schema: CollectionsApiGetSkusResponseSchema
494
- });
421
+ params
422
+ }, CollectionsApiGetSkusResponseSchema);
495
423
  }
496
424
  /**
497
425
  * Retrieves a list of all collections.
@@ -502,9 +430,8 @@ var CollectionsApi = class {
502
430
  list(params = {}) {
503
431
  return this.http.get({
504
432
  path: "/collections",
505
- params,
506
- schema: CollectionsApiListResponseSchema
507
- });
433
+ params
434
+ }, CollectionsApiListResponseSchema);
508
435
  }
509
436
  /**
510
437
  * Retrieves detailed information about a specific collection by its ID.
@@ -517,9 +444,139 @@ var CollectionsApi = class {
517
444
  get(params) {
518
445
  return this.http.get({
519
446
  path: `/collections/${params.collectionId}`,
520
- params,
521
- schema: CollectionsApiGetResponseSchema
522
- });
447
+ params
448
+ }, CollectionsApiGetResponseSchema);
449
+ }
450
+ };
451
+
452
+ //#endregion
453
+ //#region src/api/favorites/schemas.ts
454
+ /**
455
+ * Schema for a product badge.
456
+ */
457
+ const FavoritesApiBadgeSchema = z.object({
458
+ label: z.string(),
459
+ backgroundColor: z.nullish(z.number()),
460
+ textColor: z.number()
461
+ });
462
+ /**
463
+ * Type literal for stock availability type
464
+ */
465
+ const FavoritesStockAvailabilityTypeSchema = z.literal("stock");
466
+ /**
467
+ * Schema for stock availability information.
468
+ */
469
+ const FavoritesApiStockAvailabilitySchema = z.object({
470
+ type: FavoritesStockAvailabilityTypeSchema,
471
+ svg: z.nullish(z.string()),
472
+ text: z.string(),
473
+ maxQty: z.number(),
474
+ maxQtyReason: z.string()
475
+ });
476
+ /**
477
+ * Schema for a favorited item (SKU).
478
+ */
479
+ const FavoritesApiItemSchema = z.object({
480
+ productId: z.number(),
481
+ skuId: z.number(),
482
+ imageUrl: z.string(),
483
+ name: z.string(),
484
+ shortDescription: z.string(),
485
+ thumbnailUrl: z.string(),
486
+ originalPrice: z.number(),
487
+ price: z.number(),
488
+ qty: z.number(),
489
+ stockAvailability: z.nullish(FavoritesApiStockAvailabilitySchema),
490
+ isPromo: z.boolean(),
491
+ promoName: z.nullish(z.string()),
492
+ promocodes: z.array(z.string()),
493
+ qtyPurchasedInfo: z.nullish(z.string()),
494
+ rating: z.nullish(z.number()),
495
+ scoreQuantity: z.nullish(z.number()),
496
+ badge: z.nullish(FavoritesApiBadgeSchema),
497
+ moderationStatus: z.number()
498
+ });
499
+ /**
500
+ * Response schema for the favorites list.
501
+ */
502
+ const FavoritesApiListResponseSchema = z.object({ items: z.array(FavoritesApiItemSchema) });
503
+ /**
504
+ * Response schema for retrieving favorite SKU IDs.
505
+ */
506
+ const FavoritesApiGetIdsResponseSchema = z.object({ skuIds: z.array(z.number()) });
507
+ /**
508
+ * Response schema for adding a SKU to favorites.
509
+ */
510
+ const FavoritesApiAddResponseSchema = z.nullish(z.null());
511
+ /**
512
+ * Response schema for removing a SKU from favorites.
513
+ */
514
+ const FavoritesApiRemoveResponseSchema = z.nullish(z.null());
515
+
516
+ //#endregion
517
+ //#region src/api/favorites/api.ts
518
+ /**
519
+ * API for managing user favorites.
520
+ */
521
+ var FavoritesApi = class {
522
+ /**
523
+ * Initializes a new instance of the FavoritesApi.
524
+ *
525
+ * @param http HTTP client instance.
526
+ */
527
+ constructor(http) {
528
+ this.http = http;
529
+ }
530
+ /**
531
+ * Retrieves a paginated list of favorited items.
532
+ *
533
+ * @example
534
+ * const favorites = await client.favorites.list({
535
+ * pageNumber: 1,
536
+ * pageSize: 20
537
+ * });
538
+ */
539
+ list(params = {}) {
540
+ return this.http.get({
541
+ path: "/api/v1/favorites",
542
+ params
543
+ }, FavoritesApiListResponseSchema);
544
+ }
545
+ /**
546
+ * Retrieves the list of IDs of favorited SKUs.
547
+ *
548
+ * @example
549
+ * const { skuIds } = await client.favorites.getIds();
550
+ */
551
+ getIds(params = {}) {
552
+ return this.http.get({
553
+ path: "/api/v1/favorites/ids",
554
+ params
555
+ }, FavoritesApiGetIdsResponseSchema);
556
+ }
557
+ /**
558
+ * Adds SKUs to favorites.
559
+ *
560
+ * @example
561
+ * await client.favorites.add({ skuIds: [12345, 67890] });
562
+ */
563
+ add(params) {
564
+ return this.http.post({
565
+ path: "/api/v1/favorites",
566
+ body: params.skuIds
567
+ }, FavoritesApiAddResponseSchema);
568
+ }
569
+ /**
570
+ * Removes SKUs from favorites.
571
+ *
572
+ * @example
573
+ * await client.favorites.remove({ skuIds: [12345, 67890] });
574
+ */
575
+ remove(params) {
576
+ return this.http.delete({
577
+ path: "/api/v1/favorites",
578
+ body: params.skuIds
579
+ }, FavoritesApiRemoveResponseSchema);
523
580
  }
524
581
  };
525
582
 
@@ -560,9 +617,8 @@ var FeatureFlagsApi = class {
560
617
  list(params = {}) {
561
618
  return this.http.get({
562
619
  path: "/api/v1/feature-flags",
563
- params,
564
- schema: FeatureFlagsApiListResponseSchema
565
- });
620
+ params
621
+ }, FeatureFlagsApiListResponseSchema);
566
622
  }
567
623
  };
568
624
 
@@ -615,9 +671,9 @@ const ProductsApiGetReviewsResponseSchema = z.object({
615
671
  * Schema for a product badge.
616
672
  */
617
673
  const ProductsApiBadgeSchema = z.object({
618
- backgroundColor: z.number(),
619
674
  label: z.string(),
620
- textColor: z.number()
675
+ textColor: z.number(),
676
+ backgroundColor: z.nullish(z.number())
621
677
  });
622
678
  /**
623
679
  * Type literal for products stock availability type
@@ -648,12 +704,12 @@ const ProductsApiProductItemSchema = z.object({
648
704
  qty: z.number(),
649
705
  stockAvailability: z.nullish(ProductsApiStockAvailabilitySchema),
650
706
  isPromo: z.boolean(),
651
- promoName: z.string(),
707
+ promoName: z.nullish(z.string()),
652
708
  promocodes: z.array(z.string()),
653
709
  qtyPurchasedInfo: z.nullish(z.string()),
654
710
  rating: z.nullish(z.number()),
655
711
  scoreQuantity: z.nullish(z.number()),
656
- badge: ProductsApiBadgeSchema,
712
+ badge: z.nullish(ProductsApiBadgeSchema),
657
713
  moderationStatus: z.number()
658
714
  });
659
715
  /**
@@ -692,9 +748,8 @@ var ProductsApi = class {
692
748
  getSortOptions(params = {}) {
693
749
  return this.http.get({
694
750
  path: "/api/product/sort-options",
695
- params,
696
- schema: ProductsApiGetSortOptionsResponseSchema
697
- });
751
+ params
752
+ }, ProductsApiGetSortOptionsResponseSchema);
698
753
  }
699
754
  /**
700
755
  * Retrieves a list of products with optional filtering and pagination.
@@ -708,9 +763,8 @@ var ProductsApi = class {
708
763
  list(params = {}) {
709
764
  return this.http.get({
710
765
  path: "/api/v2/product",
711
- params,
712
- schema: ProductsApiListResponseSchema
713
- });
766
+ params
767
+ }, ProductsApiListResponseSchema);
714
768
  }
715
769
  /**
716
770
  * Retrieves reviews for a specific product.
@@ -723,9 +777,8 @@ var ProductsApi = class {
723
777
  getReviews(params) {
724
778
  return this.http.get({
725
779
  path: `/api/v1/product/${params.productId}/review`,
726
- params,
727
- schema: ProductsApiGetReviewsResponseSchema
728
- });
780
+ params
781
+ }, ProductsApiGetReviewsResponseSchema);
729
782
  }
730
783
  };
731
784
 
@@ -770,9 +823,8 @@ var PromoApi = class {
770
823
  list(params = {}) {
771
824
  return this.http.get({
772
825
  path: "/api/promo",
773
- params,
774
- schema: PromoApiListResponseSchema
775
- });
826
+ params
827
+ }, PromoApiListResponseSchema);
776
828
  }
777
829
  };
778
830
 
@@ -904,9 +956,8 @@ var ShopsApi = class {
904
956
  get(params) {
905
957
  return this.http.get({
906
958
  path: `/api/v1/shops/${params.shopId}`,
907
- params,
908
- schema: ShopsApiGetResponseSchema
909
- });
959
+ params
960
+ }, ShopsApiGetResponseSchema);
910
961
  }
911
962
  /**
912
963
  * Retrieves monobrand shop details.
@@ -917,9 +968,8 @@ var ShopsApi = class {
917
968
  getMonobrand(params = {}) {
918
969
  return this.http.get({
919
970
  path: "/api/v1/shops/monobrand",
920
- params,
921
- schema: ShopsApiGetMonobrandResponseSchema
922
- });
971
+ params
972
+ }, ShopsApiGetMonobrandResponseSchema);
923
973
  }
924
974
  /**
925
975
  * Retrieves products for a specific shop.
@@ -933,9 +983,8 @@ var ShopsApi = class {
933
983
  getProducts(params) {
934
984
  return this.http.get({
935
985
  path: `/api/v2/shops/${params.shopId}/products`,
936
- params,
937
- schema: ShopsApiGetProductsResponseSchema
938
- });
986
+ params
987
+ }, ShopsApiGetProductsResponseSchema);
939
988
  }
940
989
  };
941
990
 
@@ -1133,9 +1182,8 @@ var SkuApi = class {
1133
1182
  get(params) {
1134
1183
  return this.http.get({
1135
1184
  path: `/api/v2/sku/${params.skuId}`,
1136
- params,
1137
- schema: SkuApiGetResponseSchema
1138
- });
1185
+ params
1186
+ }, SkuApiGetResponseSchema);
1139
1187
  }
1140
1188
  /**
1141
1189
  * Retrieves similar SKUs.
@@ -1148,9 +1196,8 @@ var SkuApi = class {
1148
1196
  getSimilar(params) {
1149
1197
  return this.http.get({
1150
1198
  path: "/api/v2/sku/similar-skus",
1151
- params,
1152
- schema: SkuApiGetSimilarResponseSchema
1153
- });
1199
+ params
1200
+ }, SkuApiGetSimilarResponseSchema);
1154
1201
  }
1155
1202
  /**
1156
1203
  * Retrieves collections associated with a SKU.
@@ -1163,9 +1210,8 @@ var SkuApi = class {
1163
1210
  getCollections(params) {
1164
1211
  return this.http.get({
1165
1212
  path: `/sku/${params.skuId}/collections`,
1166
- params,
1167
- schema: SkuApiGetCollectionsResponseSchema
1168
- });
1213
+ params
1214
+ }, SkuApiGetCollectionsResponseSchema);
1169
1215
  }
1170
1216
  /**
1171
1217
  * Checks if a review is available for a SKU.
@@ -1178,9 +1224,8 @@ var SkuApi = class {
1178
1224
  getReviewAvailable(params) {
1179
1225
  return this.http.get({
1180
1226
  path: `/sku/${params.skuId}/review-available`,
1181
- params,
1182
- schema: SkuApiGetReviewAvailableResponseSchema
1183
- });
1227
+ params
1228
+ }, SkuApiGetReviewAvailableResponseSchema);
1184
1229
  }
1185
1230
  };
1186
1231
 
@@ -1225,11 +1270,11 @@ var UsersApi = class {
1225
1270
  * language: "ru"
1226
1271
  * });
1227
1272
  */
1228
- async updateLanguage(params) {
1229
- return parseResponse(UsersApiUpdateLanguageResponseSchema, await this.http.patch({
1273
+ updateLanguage(params) {
1274
+ return this.http.patch({
1230
1275
  path: "/api/v1/users/me/language",
1231
1276
  body: params
1232
- }));
1277
+ }, UsersApiUpdateLanguageResponseSchema);
1233
1278
  }
1234
1279
  /**
1235
1280
  * Registers device identity for analytics tracking.
@@ -1246,11 +1291,11 @@ var UsersApi = class {
1246
1291
  * }
1247
1292
  * });
1248
1293
  */
1249
- async registerDevice(params) {
1250
- return parseResponse(UsersApiRegisterDeviceResponseSchema, await this.http.post({
1294
+ registerDevice(params) {
1295
+ return this.http.post({
1251
1296
  path: "/api/v1/device-identities",
1252
1297
  body: params
1253
- }));
1298
+ }, UsersApiRegisterDeviceResponseSchema);
1254
1299
  }
1255
1300
  };
1256
1301
 
@@ -1272,6 +1317,20 @@ const LANGUAGES = {
1272
1317
  */
1273
1318
  const DEFAULT_APP_VERSION = "200";
1274
1319
 
1320
+ //#endregion
1321
+ //#region src/utils/merge-headers.ts
1322
+ /**
1323
+ * Merges base headers with new ones (overrides).
1324
+ * Returns a new Headers instance without mutating the original source.
1325
+ */
1326
+ function mergeHeaders(base, overrides) {
1327
+ const result = new Headers(base);
1328
+ if (overrides != void 0) new Headers(overrides).forEach((value, key) => {
1329
+ result.set(key, value);
1330
+ });
1331
+ return result;
1332
+ }
1333
+
1275
1334
  //#endregion
1276
1335
  //#region src/config.ts
1277
1336
  /**
@@ -1282,22 +1341,20 @@ const DEFAULT_CONFIG = {
1282
1341
  appVersion: DEFAULT_APP_VERSION,
1283
1342
  language: "ru",
1284
1343
  timeout: 3e4,
1285
- headers: {}
1344
+ headers: new Headers()
1286
1345
  };
1287
1346
  /**
1288
1347
  * Merges user configuration with defaults.
1289
1348
  */
1290
1349
  function resolveConfig(config) {
1350
+ const headers = mergeHeaders(DEFAULT_CONFIG.headers, config?.headers);
1291
1351
  return {
1292
1352
  baseUrl: config?.baseUrl ?? DEFAULT_CONFIG.baseUrl,
1293
1353
  token: config?.token,
1294
1354
  appVersion: config?.appVersion ?? DEFAULT_CONFIG.appVersion,
1295
1355
  language: config?.language ?? DEFAULT_CONFIG.language,
1296
1356
  timeout: config?.timeout ?? DEFAULT_CONFIG.timeout,
1297
- headers: {
1298
- ...DEFAULT_CONFIG.headers,
1299
- ...config?.headers
1300
- }
1357
+ headers
1301
1358
  };
1302
1359
  }
1303
1360
  /**
@@ -1310,16 +1367,23 @@ function buildUserAgent(appVersion) {
1310
1367
  * Builds the headers object for API requests based on configuration.
1311
1368
  */
1312
1369
  function buildHeaders(config) {
1313
- const headers = {
1314
- "accept-language": config.language,
1315
- "user-agent": buildUserAgent(config.appVersion),
1316
- "x-app-version": config.appVersion,
1317
- ...config.headers
1318
- };
1319
- if (config.token !== void 0 && config.token !== null) headers["authorization"] = `Bearer ${config.token}`;
1370
+ const headers = new Headers(config.headers);
1371
+ headers.set("Accept-Language", config.language);
1372
+ headers.set("User-Agent", buildUserAgent(config.appVersion));
1373
+ headers.set("X-App-Version", config.appVersion);
1374
+ if (config.token != void 0) headers.set("Authorization", `Bearer ${config.token}`);
1320
1375
  return headers;
1321
1376
  }
1322
1377
 
1378
+ //#endregion
1379
+ //#region src/errors/teez-error.ts
1380
+ /**
1381
+ * Base error class for all SDK-related errors.
1382
+ */
1383
+ var TeezError = class extends Error {
1384
+ name = "TeezError";
1385
+ };
1386
+
1323
1387
  //#endregion
1324
1388
  //#region src/errors/teez-api-error.ts
1325
1389
  /**
@@ -1328,6 +1392,10 @@ function buildHeaders(config) {
1328
1392
  var TeezApiError = class extends TeezError {
1329
1393
  name = "TeezApiError";
1330
1394
  /**
1395
+ * URL of the request that failed.
1396
+ */
1397
+ url;
1398
+ /**
1331
1399
  * HTTP status code.
1332
1400
  */
1333
1401
  status;
@@ -1336,18 +1404,14 @@ var TeezApiError = class extends TeezError {
1336
1404
  */
1337
1405
  statusText;
1338
1406
  /**
1339
- * URL of the request that failed.
1340
- */
1341
- url;
1342
- /**
1343
1407
  * Response body, if available.
1344
1408
  */
1345
1409
  body;
1346
1410
  constructor(message, { url, status, statusText, body, ...errorOptions }) {
1347
1411
  super(message, errorOptions);
1412
+ this.url = url;
1348
1413
  this.status = status;
1349
1414
  this.statusText = statusText;
1350
- this.url = url;
1351
1415
  this.body = body;
1352
1416
  }
1353
1417
  /**
@@ -1409,6 +1473,64 @@ var TeezTimeoutError = class extends TeezError {
1409
1473
  }
1410
1474
  };
1411
1475
 
1476
+ //#endregion
1477
+ //#region src/errors/teez-validation-error.ts
1478
+ /**
1479
+ * Error thrown when validation fails.
1480
+ */
1481
+ var TeezValidationError = class extends TeezError {
1482
+ name = "TeezValidationError";
1483
+ /**
1484
+ * List of standardized validation issues.
1485
+ */
1486
+ issues;
1487
+ /**
1488
+ * The raw data that failed validation.
1489
+ */
1490
+ data;
1491
+ constructor(message, { issues, data, ...errorOptions }) {
1492
+ super(message, errorOptions);
1493
+ this.issues = issues;
1494
+ this.data = data;
1495
+ }
1496
+ };
1497
+
1498
+ //#endregion
1499
+ //#region src/http/helpers.ts
1500
+ /**
1501
+ * Constructs a full URL with query parameters.
1502
+ */
1503
+ function buildUrl(path, baseUrl, queryParams) {
1504
+ const url = new URL(path, baseUrl);
1505
+ if (queryParams != void 0) for (const [key, value] of Object.entries(queryParams)) {
1506
+ if (value == void 0) continue;
1507
+ if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
1508
+ else url.searchParams.set(key, String(value));
1509
+ }
1510
+ return url;
1511
+ }
1512
+ /**
1513
+ * Converts Zod ZodError to abstract ValidationIssue[].
1514
+ */
1515
+ function toValidationIssues(error) {
1516
+ return error.issues.map((issue) => ({
1517
+ code: issue.code,
1518
+ path: issue.path,
1519
+ message: issue.message
1520
+ }));
1521
+ }
1522
+ /**
1523
+ * Validates and parses the API response data against a schema.
1524
+ */
1525
+ function parseResponse(schema, data) {
1526
+ const result = safeParse(schema, data);
1527
+ if (!result.success) throw new TeezValidationError("Response validation failed", {
1528
+ issues: toValidationIssues(result.error),
1529
+ data
1530
+ });
1531
+ return result.data;
1532
+ }
1533
+
1412
1534
  //#endregion
1413
1535
  //#region src/http/client.ts
1414
1536
  /**
@@ -1425,51 +1547,52 @@ var HttpClient = class {
1425
1547
  headers;
1426
1548
  /**
1427
1549
  * Initializes a new instance of the HttpClient.
1428
- *
1429
- * @param config Resolved client configuration.
1430
1550
  */
1431
1551
  constructor(config) {
1432
1552
  this.config = config;
1433
1553
  this.headers = buildHeaders(config);
1434
1554
  }
1435
1555
  /**
1436
- * Performs a low-level HTTP request.
1437
- *
1438
- * @param options Request options.
1556
+ * Implementation of request method.
1439
1557
  */
1440
- async request(options) {
1441
- const { url, headers, ...fetchOptions } = options;
1558
+ async request({ path, params, headers: headersRaw, body: bodyRaw, ...options }, schema) {
1559
+ const url = buildUrl(path, this.config.baseUrl, params);
1560
+ const headers = mergeHeaders(this.headers, headersRaw);
1561
+ let body;
1562
+ if (bodyRaw !== void 0) {
1563
+ body = JSON.stringify(bodyRaw);
1564
+ if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
1565
+ }
1442
1566
  const controller = new AbortController();
1443
1567
  const timeoutId = setTimeout(() => {
1444
1568
  controller.abort();
1445
1569
  }, this.config.timeout);
1446
1570
  try {
1447
1571
  const response = await fetch(url, {
1448
- ...fetchOptions,
1449
- headers: {
1450
- ...this.headers,
1451
- ...headers
1452
- },
1572
+ ...options,
1573
+ headers,
1574
+ body,
1453
1575
  signal: controller.signal
1454
1576
  });
1455
1577
  if (!response.ok) {
1456
- let body;
1578
+ let errorBody;
1457
1579
  try {
1458
- body = await response.json();
1580
+ errorBody = await response.json();
1459
1581
  } catch {
1460
- body = await response.text().catch(() => void 0);
1582
+ errorBody = await response.text().catch(() => void 0);
1461
1583
  }
1462
1584
  throw new TeezApiError(`API request failed: ${response.status} ${response.statusText}`, {
1463
1585
  url,
1464
1586
  status: response.status,
1465
1587
  statusText: response.statusText,
1466
- body
1588
+ body: errorBody
1467
1589
  });
1468
1590
  }
1469
1591
  if (response.status === 204) return;
1470
- return await response.json();
1592
+ const data = await response.json();
1593
+ return schema != void 0 ? parseResponse(schema, data) : data;
1471
1594
  } catch (error) {
1472
- if (error instanceof TeezApiError) throw error;
1595
+ if (error instanceof TeezError) throw error;
1473
1596
  if (error instanceof DOMException && error.name === "AbortError") throw new TeezTimeoutError(`Request timed out after ${this.config.timeout}ms`, {
1474
1597
  url,
1475
1598
  timeout: this.config.timeout,
@@ -1484,55 +1607,51 @@ var HttpClient = class {
1484
1607
  }
1485
1608
  }
1486
1609
  /**
1487
- * Performs a GET request and validates the response.
1610
+ * Implementation of GET method.
1488
1611
  */
1489
- async get(options) {
1490
- const { path, params, schema, ...rest } = options;
1491
- const url = buildUrl(path, this.config.baseUrl, params);
1492
- return parseResponse(schema, await this.request({
1493
- url,
1494
- method: "GET",
1495
- ...rest
1496
- }));
1612
+ get(options, schema) {
1613
+ return schema != void 0 ? this.request({
1614
+ ...options,
1615
+ method: "GET"
1616
+ }, schema) : this.request({
1617
+ ...options,
1618
+ method: "GET"
1619
+ });
1497
1620
  }
1498
1621
  /**
1499
- * Performs a POST request.
1622
+ * Implementation of POST method.
1500
1623
  */
1501
- post(options) {
1502
- const { path, params, body, ...rest } = options;
1503
- const url = buildUrl(path, this.config.baseUrl, params);
1504
- return this.request({
1505
- url,
1506
- method: "POST",
1507
- headers: { "Content-Type": "application/json" },
1508
- body: body != void 0 ? JSON.stringify(body) : void 0,
1509
- ...rest
1624
+ post(options, schema) {
1625
+ return schema != void 0 ? this.request({
1626
+ ...options,
1627
+ method: "POST"
1628
+ }, schema) : this.request({
1629
+ ...options,
1630
+ method: "POST"
1510
1631
  });
1511
1632
  }
1512
1633
  /**
1513
- * Performs a PATCH request.
1634
+ * Implementation of PATCH method.
1514
1635
  */
1515
- patch(options) {
1516
- const { path, params, body, ...rest } = options;
1517
- const url = buildUrl(path, this.config.baseUrl, params);
1518
- return this.request({
1519
- url,
1520
- method: "PATCH",
1521
- headers: { "Content-Type": "application/json" },
1522
- body: body != void 0 ? JSON.stringify(body) : void 0,
1523
- ...rest
1636
+ patch(options, schema) {
1637
+ return schema != void 0 ? this.request({
1638
+ ...options,
1639
+ method: "PATCH"
1640
+ }, schema) : this.request({
1641
+ ...options,
1642
+ method: "PATCH"
1524
1643
  });
1525
1644
  }
1526
1645
  /**
1527
- * Performs a DELETE request.
1646
+ * Implementation of DELETE method.
1528
1647
  */
1529
- delete(options) {
1530
- const { path, params, ...rest } = options;
1531
- const url = buildUrl(path, this.config.baseUrl, params);
1532
- return this.request({
1533
- url,
1534
- method: "DELETE",
1535
- ...rest
1648
+ delete(options, schema) {
1649
+ return schema != void 0 ? this.request({
1650
+ ...options,
1651
+ method: "DELETE"
1652
+ }, schema) : this.request({
1653
+ ...options,
1654
+ method: "DELETE"
1536
1655
  });
1537
1656
  }
1538
1657
  };
@@ -1574,6 +1693,10 @@ var TeezClient = class {
1574
1693
  */
1575
1694
  collections;
1576
1695
  /**
1696
+ * API for managing user favorites.
1697
+ */
1698
+ favorites;
1699
+ /**
1577
1700
  * API for retrieving feature flags.
1578
1701
  */
1579
1702
  featureFlags;
@@ -1609,6 +1732,7 @@ var TeezClient = class {
1609
1732
  this.banners = new BannersApi(this.http);
1610
1733
  this.categories = new CategoriesApi(this.http);
1611
1734
  this.collections = new CollectionsApi(this.http);
1735
+ this.favorites = new FavoritesApi(this.http);
1612
1736
  this.featureFlags = new FeatureFlagsApi(this.http);
1613
1737
  this.products = new ProductsApi(this.http);
1614
1738
  this.promo = new PromoApi(this.http);
@@ -1625,5 +1749,5 @@ var TeezClient = class {
1625
1749
  };
1626
1750
 
1627
1751
  //#endregion
1628
- export { AuthApi, AuthApiCheckTokenResponseSchema, AuthApiLoginResponseSchema, AuthApiVerifyResponseSchema, BASE_URL, BannerActionTypesSchema, BannerImageTypeSchema, BannersApi, BannersApiActionSchema, BannersApiBannerItemSchema, BannersApiImageSchema, BannersApiListResponseSchema, CategoriesApi, CategoriesApiGetParentsResponseItemSchema, CategoriesApiGetParentsResponseSchema, CategoriesApiGetResponseSchema, CategoriesApiListResponseItemSchema, CategoriesApiListResponseSchema, CollectionTypeSchema, CollectionsApi, CollectionsApiGetResponseSchema, CollectionsApiGetSkusResponseSchema, CollectionsApiListItemSchema, CollectionsApiListResponseSchema, CollectionsApiSkuItemSchema, CollectionsApiStockAvailabilitySchema, CollectionsStockAvailabilityTypeSchema, DEFAULT_APP_VERSION, DEFAULT_CONFIG, FeatureFlagsApi, FeatureFlagsApiItemSchema, FeatureFlagsApiListResponseSchema, LANGUAGES, ProductSortKeySchema, ProductsApi, ProductsApiBadgeSchema, ProductsApiGetReviewsResponseSchema, ProductsApiGetSortOptionsResponseSchema, ProductsApiListResponseSchema, ProductsApiProductItemSchema, ProductsApiReviewItemSchema, ProductsApiSortOptionSchema, ProductsApiStockAvailabilitySchema, ProductsStockAvailabilityTypeSchema, PromoApi, PromoApiItemSchema, PromoApiListResponseSchema, ShopsApi, ShopsApiContactInfoSchema, ShopsApiGetMonobrandResponseSchema, ShopsApiGetProductsResponseSchema, ShopsApiGetResponseSchema, ShopsApiProductItemSchema, ShopsApiShopItemSchema, ShopsApiStockAvailabilitySchema, ShopsApiTagSchema, ShopsStockAvailabilityTypeSchema, SkuApi, SkuApiAttributePropertySchema, SkuApiAttributePropertyValueSchema, SkuApiAttributeSchema, SkuApiBrandSchema, SkuApiCategorySchema, SkuApiCollectionItemSchema, SkuApiGetCollectionsResponseSchema, SkuApiGetResponseSchema, SkuApiGetReviewAvailableResponseSchema, SkuApiGetSimilarResponseSchema, SkuApiInstallmentSchema, SkuApiShopSchema, SkuApiSimilarItemSchema, SkuApiStockAvailabilitySchema, SkuApiTagSchema, SkuStockAvailabilityTypeSchema, TeezApiError, TeezClient, TeezError, TeezNetworkError, TeezTimeoutError, TeezValidationError, UsersApi, UsersApiLanguageEnumSchema, UsersApiRegisterDeviceResponseSchema, UsersApiUpdateLanguageResponseSchema, buildHeaders, buildUserAgent, resolveConfig };
1752
+ export { AuthApi, AuthApiCheckTokenResponseSchema, AuthApiLoginResponseSchema, AuthApiVerifyResponseSchema, BASE_URL, BannerActionTypesSchema, BannerImageTypeSchema, BannersApi, BannersApiActionSchema, BannersApiBannerItemSchema, BannersApiImageSchema, BannersApiListResponseSchema, CategoriesApi, CategoriesApiGetParentsResponseItemSchema, CategoriesApiGetParentsResponseSchema, CategoriesApiGetResponseSchema, CategoriesApiListResponseItemSchema, CategoriesApiListResponseSchema, CollectionTypeSchema, CollectionsApi, CollectionsApiGetResponseSchema, CollectionsApiGetSkusResponseSchema, CollectionsApiListItemSchema, CollectionsApiListResponseSchema, CollectionsApiSkuItemSchema, CollectionsApiStockAvailabilitySchema, CollectionsStockAvailabilityTypeSchema, DEFAULT_APP_VERSION, DEFAULT_CONFIG, FavoritesApi, FavoritesApiAddResponseSchema, FavoritesApiBadgeSchema, FavoritesApiGetIdsResponseSchema, FavoritesApiItemSchema, FavoritesApiListResponseSchema, FavoritesApiRemoveResponseSchema, FavoritesApiStockAvailabilitySchema, FavoritesStockAvailabilityTypeSchema, FeatureFlagsApi, FeatureFlagsApiItemSchema, FeatureFlagsApiListResponseSchema, LANGUAGES, ProductSortKeySchema, ProductsApi, ProductsApiBadgeSchema, ProductsApiGetReviewsResponseSchema, ProductsApiGetSortOptionsResponseSchema, ProductsApiListResponseSchema, ProductsApiProductItemSchema, ProductsApiReviewItemSchema, ProductsApiSortOptionSchema, ProductsApiStockAvailabilitySchema, ProductsStockAvailabilityTypeSchema, PromoApi, PromoApiItemSchema, PromoApiListResponseSchema, ShopsApi, ShopsApiContactInfoSchema, ShopsApiGetMonobrandResponseSchema, ShopsApiGetProductsResponseSchema, ShopsApiGetResponseSchema, ShopsApiProductItemSchema, ShopsApiShopItemSchema, ShopsApiStockAvailabilitySchema, ShopsApiTagSchema, ShopsStockAvailabilityTypeSchema, SkuApi, SkuApiAttributePropertySchema, SkuApiAttributePropertyValueSchema, SkuApiAttributeSchema, SkuApiBrandSchema, SkuApiCategorySchema, SkuApiCollectionItemSchema, SkuApiGetCollectionsResponseSchema, SkuApiGetResponseSchema, SkuApiGetReviewAvailableResponseSchema, SkuApiGetSimilarResponseSchema, SkuApiInstallmentSchema, SkuApiShopSchema, SkuApiSimilarItemSchema, SkuApiStockAvailabilitySchema, SkuApiTagSchema, SkuStockAvailabilityTypeSchema, TeezApiError, TeezClient, TeezError, TeezNetworkError, TeezTimeoutError, TeezValidationError, UsersApi, UsersApiLanguageEnumSchema, UsersApiRegisterDeviceResponseSchema, UsersApiUpdateLanguageResponseSchema, buildHeaders, buildUserAgent, resolveConfig };
1629
1753
  //# sourceMappingURL=index.mjs.map