@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.cjs +349 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +739 -224
- package/dist/index.d.mts +739 -224
- package/dist/index.mjs +342 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -28,73 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
let zod_mini = require("zod/mini");
|
|
29
29
|
zod_mini = __toESM(zod_mini);
|
|
30
30
|
|
|
31
|
-
//#region src/errors/teez-error.ts
|
|
32
|
-
/**
|
|
33
|
-
* Base error class for all SDK-related errors.
|
|
34
|
-
*/
|
|
35
|
-
var TeezError = class extends Error {
|
|
36
|
-
name = "TeezError";
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/errors/teez-validation-error.ts
|
|
41
|
-
/**
|
|
42
|
-
* Error thrown when validation fails.
|
|
43
|
-
*/
|
|
44
|
-
var TeezValidationError = class extends TeezError {
|
|
45
|
-
name = "TeezValidationError";
|
|
46
|
-
/**
|
|
47
|
-
* List of standardized validation issues.
|
|
48
|
-
*/
|
|
49
|
-
issues;
|
|
50
|
-
/**
|
|
51
|
-
* The raw data that failed validation.
|
|
52
|
-
*/
|
|
53
|
-
data;
|
|
54
|
-
constructor(message, { issues, data, ...errorOptions }) {
|
|
55
|
-
super(message, errorOptions);
|
|
56
|
-
this.issues = issues;
|
|
57
|
-
this.data = data;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/http/helpers.ts
|
|
63
|
-
/**
|
|
64
|
-
* Constructs a full URL with query parameters.
|
|
65
|
-
*/
|
|
66
|
-
function buildUrl(path, baseUrl, queryParams) {
|
|
67
|
-
const url = new URL(path, baseUrl);
|
|
68
|
-
if (queryParams != void 0) for (const [key, value] of Object.entries(queryParams)) {
|
|
69
|
-
if (value == void 0) continue;
|
|
70
|
-
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
71
|
-
else url.searchParams.set(key, String(value));
|
|
72
|
-
}
|
|
73
|
-
return String(url);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Converts Zod ZodError to abstract ValidationIssue[].
|
|
77
|
-
*/
|
|
78
|
-
function toValidationIssues(error) {
|
|
79
|
-
return error.issues.map((issue) => ({
|
|
80
|
-
code: issue.code,
|
|
81
|
-
path: issue.path,
|
|
82
|
-
message: issue.message
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Validates and parses the API response data against a schema.
|
|
87
|
-
*/
|
|
88
|
-
function parseResponse(schema, data) {
|
|
89
|
-
const result = zod_mini.safeParse(schema, data);
|
|
90
|
-
if (!result.success) throw new TeezValidationError("Response validation failed", {
|
|
91
|
-
issues: toValidationIssues(result.error),
|
|
92
|
-
data
|
|
93
|
-
});
|
|
94
|
-
return result.data;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//#endregion
|
|
98
31
|
//#region src/api/auth/schemas.ts
|
|
99
32
|
/**
|
|
100
33
|
* Response schema for initiating phone login.
|
|
@@ -149,11 +82,11 @@ var AuthApi = class {
|
|
|
149
82
|
* phone: "+77071234567"
|
|
150
83
|
* });
|
|
151
84
|
*/
|
|
152
|
-
|
|
153
|
-
return
|
|
85
|
+
login(params) {
|
|
86
|
+
return this.http.post({
|
|
154
87
|
path: "/auth/login",
|
|
155
88
|
body: params
|
|
156
|
-
})
|
|
89
|
+
}, AuthApiLoginResponseSchema);
|
|
157
90
|
}
|
|
158
91
|
/**
|
|
159
92
|
* Verifies OTP code and obtains JWT access and refresh tokens.
|
|
@@ -164,11 +97,11 @@ var AuthApi = class {
|
|
|
164
97
|
* otpCode: "2610"
|
|
165
98
|
* });
|
|
166
99
|
*/
|
|
167
|
-
|
|
168
|
-
return
|
|
100
|
+
verify(params) {
|
|
101
|
+
return this.http.post({
|
|
169
102
|
path: "/auth/verify",
|
|
170
103
|
body: params
|
|
171
|
-
})
|
|
104
|
+
}, AuthApiVerifyResponseSchema);
|
|
172
105
|
}
|
|
173
106
|
/**
|
|
174
107
|
* Validates the current JWT token and retrieves user information.
|
|
@@ -176,12 +109,11 @@ var AuthApi = class {
|
|
|
176
109
|
* @example
|
|
177
110
|
* const response = await client.auth.checkToken();
|
|
178
111
|
*/
|
|
179
|
-
|
|
180
|
-
return
|
|
112
|
+
checkToken(params = {}) {
|
|
113
|
+
return this.http.get({
|
|
181
114
|
path: "/auth/check-token",
|
|
182
|
-
params
|
|
183
|
-
|
|
184
|
-
});
|
|
115
|
+
params
|
|
116
|
+
}, AuthApiCheckTokenResponseSchema);
|
|
185
117
|
}
|
|
186
118
|
};
|
|
187
119
|
|
|
@@ -249,9 +181,8 @@ var BannersApi = class {
|
|
|
249
181
|
list(params = {}) {
|
|
250
182
|
return this.http.get({
|
|
251
183
|
path: "/api/v3/banners",
|
|
252
|
-
params
|
|
253
|
-
|
|
254
|
-
});
|
|
184
|
+
params
|
|
185
|
+
}, BannersApiListResponseSchema);
|
|
255
186
|
}
|
|
256
187
|
};
|
|
257
188
|
|
|
@@ -326,9 +257,8 @@ var CategoriesApi = class {
|
|
|
326
257
|
list(params = {}) {
|
|
327
258
|
return this.http.get({
|
|
328
259
|
path: "/categories",
|
|
329
|
-
params
|
|
330
|
-
|
|
331
|
-
});
|
|
260
|
+
params
|
|
261
|
+
}, CategoriesApiListResponseSchema);
|
|
332
262
|
}
|
|
333
263
|
/**
|
|
334
264
|
* Retrieves detailed information about a specific category by its ID.
|
|
@@ -341,9 +271,8 @@ var CategoriesApi = class {
|
|
|
341
271
|
get(params) {
|
|
342
272
|
return this.http.get({
|
|
343
273
|
path: `/categories/${params.categoryId}`,
|
|
344
|
-
params
|
|
345
|
-
|
|
346
|
-
});
|
|
274
|
+
params
|
|
275
|
+
}, CategoriesApiGetResponseSchema);
|
|
347
276
|
}
|
|
348
277
|
/**
|
|
349
278
|
* Retrieves parent categories for specific category IDs.
|
|
@@ -356,9 +285,8 @@ var CategoriesApi = class {
|
|
|
356
285
|
getParents(params) {
|
|
357
286
|
return this.http.get({
|
|
358
287
|
path: "/api/v1/categories/parents",
|
|
359
|
-
params
|
|
360
|
-
|
|
361
|
-
});
|
|
288
|
+
params
|
|
289
|
+
}, CategoriesApiGetParentsResponseSchema);
|
|
362
290
|
}
|
|
363
291
|
};
|
|
364
292
|
|
|
@@ -517,9 +445,8 @@ var CollectionsApi = class {
|
|
|
517
445
|
getSkus(params) {
|
|
518
446
|
return this.http.get({
|
|
519
447
|
path: "/api/v2/collections/skus",
|
|
520
|
-
params
|
|
521
|
-
|
|
522
|
-
});
|
|
448
|
+
params
|
|
449
|
+
}, CollectionsApiGetSkusResponseSchema);
|
|
523
450
|
}
|
|
524
451
|
/**
|
|
525
452
|
* Retrieves a list of all collections.
|
|
@@ -530,9 +457,8 @@ var CollectionsApi = class {
|
|
|
530
457
|
list(params = {}) {
|
|
531
458
|
return this.http.get({
|
|
532
459
|
path: "/collections",
|
|
533
|
-
params
|
|
534
|
-
|
|
535
|
-
});
|
|
460
|
+
params
|
|
461
|
+
}, CollectionsApiListResponseSchema);
|
|
536
462
|
}
|
|
537
463
|
/**
|
|
538
464
|
* Retrieves detailed information about a specific collection by its ID.
|
|
@@ -545,9 +471,139 @@ var CollectionsApi = class {
|
|
|
545
471
|
get(params) {
|
|
546
472
|
return this.http.get({
|
|
547
473
|
path: `/collections/${params.collectionId}`,
|
|
548
|
-
params
|
|
549
|
-
|
|
550
|
-
|
|
474
|
+
params
|
|
475
|
+
}, CollectionsApiGetResponseSchema);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/api/favorites/schemas.ts
|
|
481
|
+
/**
|
|
482
|
+
* Schema for a product badge.
|
|
483
|
+
*/
|
|
484
|
+
const FavoritesApiBadgeSchema = zod_mini.object({
|
|
485
|
+
label: zod_mini.string(),
|
|
486
|
+
backgroundColor: zod_mini.nullish(zod_mini.number()),
|
|
487
|
+
textColor: zod_mini.number()
|
|
488
|
+
});
|
|
489
|
+
/**
|
|
490
|
+
* Type literal for stock availability type
|
|
491
|
+
*/
|
|
492
|
+
const FavoritesStockAvailabilityTypeSchema = zod_mini.literal("stock");
|
|
493
|
+
/**
|
|
494
|
+
* Schema for stock availability information.
|
|
495
|
+
*/
|
|
496
|
+
const FavoritesApiStockAvailabilitySchema = zod_mini.object({
|
|
497
|
+
type: FavoritesStockAvailabilityTypeSchema,
|
|
498
|
+
svg: zod_mini.nullish(zod_mini.string()),
|
|
499
|
+
text: zod_mini.string(),
|
|
500
|
+
maxQty: zod_mini.number(),
|
|
501
|
+
maxQtyReason: zod_mini.string()
|
|
502
|
+
});
|
|
503
|
+
/**
|
|
504
|
+
* Schema for a favorited item (SKU).
|
|
505
|
+
*/
|
|
506
|
+
const FavoritesApiItemSchema = zod_mini.object({
|
|
507
|
+
productId: zod_mini.number(),
|
|
508
|
+
skuId: zod_mini.number(),
|
|
509
|
+
imageUrl: zod_mini.string(),
|
|
510
|
+
name: zod_mini.string(),
|
|
511
|
+
shortDescription: zod_mini.string(),
|
|
512
|
+
thumbnailUrl: zod_mini.string(),
|
|
513
|
+
originalPrice: zod_mini.number(),
|
|
514
|
+
price: zod_mini.number(),
|
|
515
|
+
qty: zod_mini.number(),
|
|
516
|
+
stockAvailability: zod_mini.nullish(FavoritesApiStockAvailabilitySchema),
|
|
517
|
+
isPromo: zod_mini.boolean(),
|
|
518
|
+
promoName: zod_mini.nullish(zod_mini.string()),
|
|
519
|
+
promocodes: zod_mini.array(zod_mini.string()),
|
|
520
|
+
qtyPurchasedInfo: zod_mini.nullish(zod_mini.string()),
|
|
521
|
+
rating: zod_mini.nullish(zod_mini.number()),
|
|
522
|
+
scoreQuantity: zod_mini.nullish(zod_mini.number()),
|
|
523
|
+
badge: zod_mini.nullish(FavoritesApiBadgeSchema),
|
|
524
|
+
moderationStatus: zod_mini.number()
|
|
525
|
+
});
|
|
526
|
+
/**
|
|
527
|
+
* Response schema for the favorites list.
|
|
528
|
+
*/
|
|
529
|
+
const FavoritesApiListResponseSchema = zod_mini.object({ items: zod_mini.array(FavoritesApiItemSchema) });
|
|
530
|
+
/**
|
|
531
|
+
* Response schema for retrieving favorite SKU IDs.
|
|
532
|
+
*/
|
|
533
|
+
const FavoritesApiGetIdsResponseSchema = zod_mini.object({ skuIds: zod_mini.array(zod_mini.number()) });
|
|
534
|
+
/**
|
|
535
|
+
* Response schema for adding a SKU to favorites.
|
|
536
|
+
*/
|
|
537
|
+
const FavoritesApiAddResponseSchema = zod_mini.nullish(zod_mini.null());
|
|
538
|
+
/**
|
|
539
|
+
* Response schema for removing a SKU from favorites.
|
|
540
|
+
*/
|
|
541
|
+
const FavoritesApiRemoveResponseSchema = zod_mini.nullish(zod_mini.null());
|
|
542
|
+
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/api/favorites/api.ts
|
|
545
|
+
/**
|
|
546
|
+
* API for managing user favorites.
|
|
547
|
+
*/
|
|
548
|
+
var FavoritesApi = class {
|
|
549
|
+
/**
|
|
550
|
+
* Initializes a new instance of the FavoritesApi.
|
|
551
|
+
*
|
|
552
|
+
* @param http HTTP client instance.
|
|
553
|
+
*/
|
|
554
|
+
constructor(http) {
|
|
555
|
+
this.http = http;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Retrieves a paginated list of favorited items.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* const favorites = await client.favorites.list({
|
|
562
|
+
* pageNumber: 1,
|
|
563
|
+
* pageSize: 20
|
|
564
|
+
* });
|
|
565
|
+
*/
|
|
566
|
+
list(params = {}) {
|
|
567
|
+
return this.http.get({
|
|
568
|
+
path: "/api/v1/favorites",
|
|
569
|
+
params
|
|
570
|
+
}, FavoritesApiListResponseSchema);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Retrieves the list of IDs of favorited SKUs.
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* const { skuIds } = await client.favorites.getIds();
|
|
577
|
+
*/
|
|
578
|
+
getIds(params = {}) {
|
|
579
|
+
return this.http.get({
|
|
580
|
+
path: "/api/v1/favorites/ids",
|
|
581
|
+
params
|
|
582
|
+
}, FavoritesApiGetIdsResponseSchema);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Adds SKUs to favorites.
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* await client.favorites.add({ skuIds: [12345, 67890] });
|
|
589
|
+
*/
|
|
590
|
+
add(params) {
|
|
591
|
+
return this.http.post({
|
|
592
|
+
path: "/api/v1/favorites",
|
|
593
|
+
body: params.skuIds
|
|
594
|
+
}, FavoritesApiAddResponseSchema);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Removes SKUs from favorites.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* await client.favorites.remove({ skuIds: [12345, 67890] });
|
|
601
|
+
*/
|
|
602
|
+
remove(params) {
|
|
603
|
+
return this.http.delete({
|
|
604
|
+
path: "/api/v1/favorites",
|
|
605
|
+
body: params.skuIds
|
|
606
|
+
}, FavoritesApiRemoveResponseSchema);
|
|
551
607
|
}
|
|
552
608
|
};
|
|
553
609
|
|
|
@@ -588,9 +644,8 @@ var FeatureFlagsApi = class {
|
|
|
588
644
|
list(params = {}) {
|
|
589
645
|
return this.http.get({
|
|
590
646
|
path: "/api/v1/feature-flags",
|
|
591
|
-
params
|
|
592
|
-
|
|
593
|
-
});
|
|
647
|
+
params
|
|
648
|
+
}, FeatureFlagsApiListResponseSchema);
|
|
594
649
|
}
|
|
595
650
|
};
|
|
596
651
|
|
|
@@ -643,9 +698,9 @@ const ProductsApiGetReviewsResponseSchema = zod_mini.object({
|
|
|
643
698
|
* Schema for a product badge.
|
|
644
699
|
*/
|
|
645
700
|
const ProductsApiBadgeSchema = zod_mini.object({
|
|
646
|
-
backgroundColor: zod_mini.number(),
|
|
647
701
|
label: zod_mini.string(),
|
|
648
|
-
textColor: zod_mini.number()
|
|
702
|
+
textColor: zod_mini.number(),
|
|
703
|
+
backgroundColor: zod_mini.nullish(zod_mini.number())
|
|
649
704
|
});
|
|
650
705
|
/**
|
|
651
706
|
* Type literal for products stock availability type
|
|
@@ -676,12 +731,12 @@ const ProductsApiProductItemSchema = zod_mini.object({
|
|
|
676
731
|
qty: zod_mini.number(),
|
|
677
732
|
stockAvailability: zod_mini.nullish(ProductsApiStockAvailabilitySchema),
|
|
678
733
|
isPromo: zod_mini.boolean(),
|
|
679
|
-
promoName: zod_mini.string(),
|
|
734
|
+
promoName: zod_mini.nullish(zod_mini.string()),
|
|
680
735
|
promocodes: zod_mini.array(zod_mini.string()),
|
|
681
736
|
qtyPurchasedInfo: zod_mini.nullish(zod_mini.string()),
|
|
682
737
|
rating: zod_mini.nullish(zod_mini.number()),
|
|
683
738
|
scoreQuantity: zod_mini.nullish(zod_mini.number()),
|
|
684
|
-
badge: ProductsApiBadgeSchema,
|
|
739
|
+
badge: zod_mini.nullish(ProductsApiBadgeSchema),
|
|
685
740
|
moderationStatus: zod_mini.number()
|
|
686
741
|
});
|
|
687
742
|
/**
|
|
@@ -720,9 +775,8 @@ var ProductsApi = class {
|
|
|
720
775
|
getSortOptions(params = {}) {
|
|
721
776
|
return this.http.get({
|
|
722
777
|
path: "/api/product/sort-options",
|
|
723
|
-
params
|
|
724
|
-
|
|
725
|
-
});
|
|
778
|
+
params
|
|
779
|
+
}, ProductsApiGetSortOptionsResponseSchema);
|
|
726
780
|
}
|
|
727
781
|
/**
|
|
728
782
|
* Retrieves a list of products with optional filtering and pagination.
|
|
@@ -736,9 +790,8 @@ var ProductsApi = class {
|
|
|
736
790
|
list(params = {}) {
|
|
737
791
|
return this.http.get({
|
|
738
792
|
path: "/api/v2/product",
|
|
739
|
-
params
|
|
740
|
-
|
|
741
|
-
});
|
|
793
|
+
params
|
|
794
|
+
}, ProductsApiListResponseSchema);
|
|
742
795
|
}
|
|
743
796
|
/**
|
|
744
797
|
* Retrieves reviews for a specific product.
|
|
@@ -751,9 +804,8 @@ var ProductsApi = class {
|
|
|
751
804
|
getReviews(params) {
|
|
752
805
|
return this.http.get({
|
|
753
806
|
path: `/api/v1/product/${params.productId}/review`,
|
|
754
|
-
params
|
|
755
|
-
|
|
756
|
-
});
|
|
807
|
+
params
|
|
808
|
+
}, ProductsApiGetReviewsResponseSchema);
|
|
757
809
|
}
|
|
758
810
|
};
|
|
759
811
|
|
|
@@ -798,9 +850,8 @@ var PromoApi = class {
|
|
|
798
850
|
list(params = {}) {
|
|
799
851
|
return this.http.get({
|
|
800
852
|
path: "/api/promo",
|
|
801
|
-
params
|
|
802
|
-
|
|
803
|
-
});
|
|
853
|
+
params
|
|
854
|
+
}, PromoApiListResponseSchema);
|
|
804
855
|
}
|
|
805
856
|
};
|
|
806
857
|
|
|
@@ -932,9 +983,8 @@ var ShopsApi = class {
|
|
|
932
983
|
get(params) {
|
|
933
984
|
return this.http.get({
|
|
934
985
|
path: `/api/v1/shops/${params.shopId}`,
|
|
935
|
-
params
|
|
936
|
-
|
|
937
|
-
});
|
|
986
|
+
params
|
|
987
|
+
}, ShopsApiGetResponseSchema);
|
|
938
988
|
}
|
|
939
989
|
/**
|
|
940
990
|
* Retrieves monobrand shop details.
|
|
@@ -945,9 +995,8 @@ var ShopsApi = class {
|
|
|
945
995
|
getMonobrand(params = {}) {
|
|
946
996
|
return this.http.get({
|
|
947
997
|
path: "/api/v1/shops/monobrand",
|
|
948
|
-
params
|
|
949
|
-
|
|
950
|
-
});
|
|
998
|
+
params
|
|
999
|
+
}, ShopsApiGetMonobrandResponseSchema);
|
|
951
1000
|
}
|
|
952
1001
|
/**
|
|
953
1002
|
* Retrieves products for a specific shop.
|
|
@@ -961,9 +1010,8 @@ var ShopsApi = class {
|
|
|
961
1010
|
getProducts(params) {
|
|
962
1011
|
return this.http.get({
|
|
963
1012
|
path: `/api/v2/shops/${params.shopId}/products`,
|
|
964
|
-
params
|
|
965
|
-
|
|
966
|
-
});
|
|
1013
|
+
params
|
|
1014
|
+
}, ShopsApiGetProductsResponseSchema);
|
|
967
1015
|
}
|
|
968
1016
|
};
|
|
969
1017
|
|
|
@@ -1161,9 +1209,8 @@ var SkuApi = class {
|
|
|
1161
1209
|
get(params) {
|
|
1162
1210
|
return this.http.get({
|
|
1163
1211
|
path: `/api/v2/sku/${params.skuId}`,
|
|
1164
|
-
params
|
|
1165
|
-
|
|
1166
|
-
});
|
|
1212
|
+
params
|
|
1213
|
+
}, SkuApiGetResponseSchema);
|
|
1167
1214
|
}
|
|
1168
1215
|
/**
|
|
1169
1216
|
* Retrieves similar SKUs.
|
|
@@ -1176,9 +1223,8 @@ var SkuApi = class {
|
|
|
1176
1223
|
getSimilar(params) {
|
|
1177
1224
|
return this.http.get({
|
|
1178
1225
|
path: "/api/v2/sku/similar-skus",
|
|
1179
|
-
params
|
|
1180
|
-
|
|
1181
|
-
});
|
|
1226
|
+
params
|
|
1227
|
+
}, SkuApiGetSimilarResponseSchema);
|
|
1182
1228
|
}
|
|
1183
1229
|
/**
|
|
1184
1230
|
* Retrieves collections associated with a SKU.
|
|
@@ -1191,9 +1237,8 @@ var SkuApi = class {
|
|
|
1191
1237
|
getCollections(params) {
|
|
1192
1238
|
return this.http.get({
|
|
1193
1239
|
path: `/sku/${params.skuId}/collections`,
|
|
1194
|
-
params
|
|
1195
|
-
|
|
1196
|
-
});
|
|
1240
|
+
params
|
|
1241
|
+
}, SkuApiGetCollectionsResponseSchema);
|
|
1197
1242
|
}
|
|
1198
1243
|
/**
|
|
1199
1244
|
* Checks if a review is available for a SKU.
|
|
@@ -1206,9 +1251,8 @@ var SkuApi = class {
|
|
|
1206
1251
|
getReviewAvailable(params) {
|
|
1207
1252
|
return this.http.get({
|
|
1208
1253
|
path: `/sku/${params.skuId}/review-available`,
|
|
1209
|
-
params
|
|
1210
|
-
|
|
1211
|
-
});
|
|
1254
|
+
params
|
|
1255
|
+
}, SkuApiGetReviewAvailableResponseSchema);
|
|
1212
1256
|
}
|
|
1213
1257
|
};
|
|
1214
1258
|
|
|
@@ -1253,11 +1297,11 @@ var UsersApi = class {
|
|
|
1253
1297
|
* language: "ru"
|
|
1254
1298
|
* });
|
|
1255
1299
|
*/
|
|
1256
|
-
|
|
1257
|
-
return
|
|
1300
|
+
updateLanguage(params) {
|
|
1301
|
+
return this.http.patch({
|
|
1258
1302
|
path: "/api/v1/users/me/language",
|
|
1259
1303
|
body: params
|
|
1260
|
-
})
|
|
1304
|
+
}, UsersApiUpdateLanguageResponseSchema);
|
|
1261
1305
|
}
|
|
1262
1306
|
/**
|
|
1263
1307
|
* Registers device identity for analytics tracking.
|
|
@@ -1274,11 +1318,11 @@ var UsersApi = class {
|
|
|
1274
1318
|
* }
|
|
1275
1319
|
* });
|
|
1276
1320
|
*/
|
|
1277
|
-
|
|
1278
|
-
return
|
|
1321
|
+
registerDevice(params) {
|
|
1322
|
+
return this.http.post({
|
|
1279
1323
|
path: "/api/v1/device-identities",
|
|
1280
1324
|
body: params
|
|
1281
|
-
})
|
|
1325
|
+
}, UsersApiRegisterDeviceResponseSchema);
|
|
1282
1326
|
}
|
|
1283
1327
|
};
|
|
1284
1328
|
|
|
@@ -1300,6 +1344,20 @@ const LANGUAGES = {
|
|
|
1300
1344
|
*/
|
|
1301
1345
|
const DEFAULT_APP_VERSION = "200";
|
|
1302
1346
|
|
|
1347
|
+
//#endregion
|
|
1348
|
+
//#region src/utils/merge-headers.ts
|
|
1349
|
+
/**
|
|
1350
|
+
* Merges base headers with new ones (overrides).
|
|
1351
|
+
* Returns a new Headers instance without mutating the original source.
|
|
1352
|
+
*/
|
|
1353
|
+
function mergeHeaders(base, overrides) {
|
|
1354
|
+
const result = new Headers(base);
|
|
1355
|
+
if (overrides != void 0) new Headers(overrides).forEach((value, key) => {
|
|
1356
|
+
result.set(key, value);
|
|
1357
|
+
});
|
|
1358
|
+
return result;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1303
1361
|
//#endregion
|
|
1304
1362
|
//#region src/config.ts
|
|
1305
1363
|
/**
|
|
@@ -1310,22 +1368,20 @@ const DEFAULT_CONFIG = {
|
|
|
1310
1368
|
appVersion: DEFAULT_APP_VERSION,
|
|
1311
1369
|
language: "ru",
|
|
1312
1370
|
timeout: 3e4,
|
|
1313
|
-
headers:
|
|
1371
|
+
headers: new Headers()
|
|
1314
1372
|
};
|
|
1315
1373
|
/**
|
|
1316
1374
|
* Merges user configuration with defaults.
|
|
1317
1375
|
*/
|
|
1318
1376
|
function resolveConfig(config) {
|
|
1377
|
+
const headers = mergeHeaders(DEFAULT_CONFIG.headers, config?.headers);
|
|
1319
1378
|
return {
|
|
1320
1379
|
baseUrl: config?.baseUrl ?? DEFAULT_CONFIG.baseUrl,
|
|
1321
1380
|
token: config?.token,
|
|
1322
1381
|
appVersion: config?.appVersion ?? DEFAULT_CONFIG.appVersion,
|
|
1323
1382
|
language: config?.language ?? DEFAULT_CONFIG.language,
|
|
1324
1383
|
timeout: config?.timeout ?? DEFAULT_CONFIG.timeout,
|
|
1325
|
-
headers
|
|
1326
|
-
...DEFAULT_CONFIG.headers,
|
|
1327
|
-
...config?.headers
|
|
1328
|
-
}
|
|
1384
|
+
headers
|
|
1329
1385
|
};
|
|
1330
1386
|
}
|
|
1331
1387
|
/**
|
|
@@ -1338,16 +1394,23 @@ function buildUserAgent(appVersion) {
|
|
|
1338
1394
|
* Builds the headers object for API requests based on configuration.
|
|
1339
1395
|
*/
|
|
1340
1396
|
function buildHeaders(config) {
|
|
1341
|
-
const headers =
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
};
|
|
1347
|
-
if (config.token !== void 0 && config.token !== null) headers["authorization"] = `Bearer ${config.token}`;
|
|
1397
|
+
const headers = new Headers(config.headers);
|
|
1398
|
+
headers.set("Accept-Language", config.language);
|
|
1399
|
+
headers.set("User-Agent", buildUserAgent(config.appVersion));
|
|
1400
|
+
headers.set("X-App-Version", config.appVersion);
|
|
1401
|
+
if (config.token != void 0) headers.set("Authorization", `Bearer ${config.token}`);
|
|
1348
1402
|
return headers;
|
|
1349
1403
|
}
|
|
1350
1404
|
|
|
1405
|
+
//#endregion
|
|
1406
|
+
//#region src/errors/teez-error.ts
|
|
1407
|
+
/**
|
|
1408
|
+
* Base error class for all SDK-related errors.
|
|
1409
|
+
*/
|
|
1410
|
+
var TeezError = class extends Error {
|
|
1411
|
+
name = "TeezError";
|
|
1412
|
+
};
|
|
1413
|
+
|
|
1351
1414
|
//#endregion
|
|
1352
1415
|
//#region src/errors/teez-api-error.ts
|
|
1353
1416
|
/**
|
|
@@ -1356,6 +1419,10 @@ function buildHeaders(config) {
|
|
|
1356
1419
|
var TeezApiError = class extends TeezError {
|
|
1357
1420
|
name = "TeezApiError";
|
|
1358
1421
|
/**
|
|
1422
|
+
* URL of the request that failed.
|
|
1423
|
+
*/
|
|
1424
|
+
url;
|
|
1425
|
+
/**
|
|
1359
1426
|
* HTTP status code.
|
|
1360
1427
|
*/
|
|
1361
1428
|
status;
|
|
@@ -1364,18 +1431,14 @@ var TeezApiError = class extends TeezError {
|
|
|
1364
1431
|
*/
|
|
1365
1432
|
statusText;
|
|
1366
1433
|
/**
|
|
1367
|
-
* URL of the request that failed.
|
|
1368
|
-
*/
|
|
1369
|
-
url;
|
|
1370
|
-
/**
|
|
1371
1434
|
* Response body, if available.
|
|
1372
1435
|
*/
|
|
1373
1436
|
body;
|
|
1374
1437
|
constructor(message, { url, status, statusText, body, ...errorOptions }) {
|
|
1375
1438
|
super(message, errorOptions);
|
|
1439
|
+
this.url = url;
|
|
1376
1440
|
this.status = status;
|
|
1377
1441
|
this.statusText = statusText;
|
|
1378
|
-
this.url = url;
|
|
1379
1442
|
this.body = body;
|
|
1380
1443
|
}
|
|
1381
1444
|
/**
|
|
@@ -1437,6 +1500,64 @@ var TeezTimeoutError = class extends TeezError {
|
|
|
1437
1500
|
}
|
|
1438
1501
|
};
|
|
1439
1502
|
|
|
1503
|
+
//#endregion
|
|
1504
|
+
//#region src/errors/teez-validation-error.ts
|
|
1505
|
+
/**
|
|
1506
|
+
* Error thrown when validation fails.
|
|
1507
|
+
*/
|
|
1508
|
+
var TeezValidationError = class extends TeezError {
|
|
1509
|
+
name = "TeezValidationError";
|
|
1510
|
+
/**
|
|
1511
|
+
* List of standardized validation issues.
|
|
1512
|
+
*/
|
|
1513
|
+
issues;
|
|
1514
|
+
/**
|
|
1515
|
+
* The raw data that failed validation.
|
|
1516
|
+
*/
|
|
1517
|
+
data;
|
|
1518
|
+
constructor(message, { issues, data, ...errorOptions }) {
|
|
1519
|
+
super(message, errorOptions);
|
|
1520
|
+
this.issues = issues;
|
|
1521
|
+
this.data = data;
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
//#endregion
|
|
1526
|
+
//#region src/http/helpers.ts
|
|
1527
|
+
/**
|
|
1528
|
+
* Constructs a full URL with query parameters.
|
|
1529
|
+
*/
|
|
1530
|
+
function buildUrl(path, baseUrl, queryParams) {
|
|
1531
|
+
const url = new URL(path, baseUrl);
|
|
1532
|
+
if (queryParams != void 0) for (const [key, value] of Object.entries(queryParams)) {
|
|
1533
|
+
if (value == void 0) continue;
|
|
1534
|
+
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
1535
|
+
else url.searchParams.set(key, String(value));
|
|
1536
|
+
}
|
|
1537
|
+
return url;
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Converts Zod ZodError to abstract ValidationIssue[].
|
|
1541
|
+
*/
|
|
1542
|
+
function toValidationIssues(error) {
|
|
1543
|
+
return error.issues.map((issue) => ({
|
|
1544
|
+
code: issue.code,
|
|
1545
|
+
path: issue.path,
|
|
1546
|
+
message: issue.message
|
|
1547
|
+
}));
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Validates and parses the API response data against a schema.
|
|
1551
|
+
*/
|
|
1552
|
+
function parseResponse(schema, data) {
|
|
1553
|
+
const result = (0, zod_mini.safeParse)(schema, data);
|
|
1554
|
+
if (!result.success) throw new TeezValidationError("Response validation failed", {
|
|
1555
|
+
issues: toValidationIssues(result.error),
|
|
1556
|
+
data
|
|
1557
|
+
});
|
|
1558
|
+
return result.data;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1440
1561
|
//#endregion
|
|
1441
1562
|
//#region src/http/client.ts
|
|
1442
1563
|
/**
|
|
@@ -1453,51 +1574,52 @@ var HttpClient = class {
|
|
|
1453
1574
|
headers;
|
|
1454
1575
|
/**
|
|
1455
1576
|
* Initializes a new instance of the HttpClient.
|
|
1456
|
-
*
|
|
1457
|
-
* @param config Resolved client configuration.
|
|
1458
1577
|
*/
|
|
1459
1578
|
constructor(config) {
|
|
1460
1579
|
this.config = config;
|
|
1461
1580
|
this.headers = buildHeaders(config);
|
|
1462
1581
|
}
|
|
1463
1582
|
/**
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
* @param options Request options.
|
|
1583
|
+
* Implementation of request method.
|
|
1467
1584
|
*/
|
|
1468
|
-
async request(options) {
|
|
1469
|
-
const
|
|
1585
|
+
async request({ path, params, headers: headersRaw, body: bodyRaw, ...options }, schema) {
|
|
1586
|
+
const url = buildUrl(path, this.config.baseUrl, params);
|
|
1587
|
+
const headers = mergeHeaders(this.headers, headersRaw);
|
|
1588
|
+
let body;
|
|
1589
|
+
if (bodyRaw !== void 0) {
|
|
1590
|
+
body = JSON.stringify(bodyRaw);
|
|
1591
|
+
if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
1592
|
+
}
|
|
1470
1593
|
const controller = new AbortController();
|
|
1471
1594
|
const timeoutId = setTimeout(() => {
|
|
1472
1595
|
controller.abort();
|
|
1473
1596
|
}, this.config.timeout);
|
|
1474
1597
|
try {
|
|
1475
1598
|
const response = await fetch(url, {
|
|
1476
|
-
...
|
|
1477
|
-
headers
|
|
1478
|
-
|
|
1479
|
-
...headers
|
|
1480
|
-
},
|
|
1599
|
+
...options,
|
|
1600
|
+
headers,
|
|
1601
|
+
body,
|
|
1481
1602
|
signal: controller.signal
|
|
1482
1603
|
});
|
|
1483
1604
|
if (!response.ok) {
|
|
1484
|
-
let
|
|
1605
|
+
let errorBody;
|
|
1485
1606
|
try {
|
|
1486
|
-
|
|
1607
|
+
errorBody = await response.json();
|
|
1487
1608
|
} catch {
|
|
1488
|
-
|
|
1609
|
+
errorBody = await response.text().catch(() => void 0);
|
|
1489
1610
|
}
|
|
1490
1611
|
throw new TeezApiError(`API request failed: ${response.status} ${response.statusText}`, {
|
|
1491
1612
|
url,
|
|
1492
1613
|
status: response.status,
|
|
1493
1614
|
statusText: response.statusText,
|
|
1494
|
-
body
|
|
1615
|
+
body: errorBody
|
|
1495
1616
|
});
|
|
1496
1617
|
}
|
|
1497
1618
|
if (response.status === 204) return;
|
|
1498
|
-
|
|
1619
|
+
const data = await response.json();
|
|
1620
|
+
return schema != void 0 ? parseResponse(schema, data) : data;
|
|
1499
1621
|
} catch (error) {
|
|
1500
|
-
if (error instanceof
|
|
1622
|
+
if (error instanceof TeezError) throw error;
|
|
1501
1623
|
if (error instanceof DOMException && error.name === "AbortError") throw new TeezTimeoutError(`Request timed out after ${this.config.timeout}ms`, {
|
|
1502
1624
|
url,
|
|
1503
1625
|
timeout: this.config.timeout,
|
|
@@ -1512,55 +1634,51 @@ var HttpClient = class {
|
|
|
1512
1634
|
}
|
|
1513
1635
|
}
|
|
1514
1636
|
/**
|
|
1515
|
-
*
|
|
1637
|
+
* Implementation of GET method.
|
|
1516
1638
|
*/
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
})
|
|
1639
|
+
get(options, schema) {
|
|
1640
|
+
return schema != void 0 ? this.request({
|
|
1641
|
+
...options,
|
|
1642
|
+
method: "GET"
|
|
1643
|
+
}, schema) : this.request({
|
|
1644
|
+
...options,
|
|
1645
|
+
method: "GET"
|
|
1646
|
+
});
|
|
1525
1647
|
}
|
|
1526
1648
|
/**
|
|
1527
|
-
*
|
|
1649
|
+
* Implementation of POST method.
|
|
1528
1650
|
*/
|
|
1529
|
-
post(options) {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
body: body != void 0 ? JSON.stringify(body) : void 0,
|
|
1537
|
-
...rest
|
|
1651
|
+
post(options, schema) {
|
|
1652
|
+
return schema != void 0 ? this.request({
|
|
1653
|
+
...options,
|
|
1654
|
+
method: "POST"
|
|
1655
|
+
}, schema) : this.request({
|
|
1656
|
+
...options,
|
|
1657
|
+
method: "POST"
|
|
1538
1658
|
});
|
|
1539
1659
|
}
|
|
1540
1660
|
/**
|
|
1541
|
-
*
|
|
1661
|
+
* Implementation of PATCH method.
|
|
1542
1662
|
*/
|
|
1543
|
-
patch(options) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
body: body != void 0 ? JSON.stringify(body) : void 0,
|
|
1551
|
-
...rest
|
|
1663
|
+
patch(options, schema) {
|
|
1664
|
+
return schema != void 0 ? this.request({
|
|
1665
|
+
...options,
|
|
1666
|
+
method: "PATCH"
|
|
1667
|
+
}, schema) : this.request({
|
|
1668
|
+
...options,
|
|
1669
|
+
method: "PATCH"
|
|
1552
1670
|
});
|
|
1553
1671
|
}
|
|
1554
1672
|
/**
|
|
1555
|
-
*
|
|
1673
|
+
* Implementation of DELETE method.
|
|
1556
1674
|
*/
|
|
1557
|
-
delete(options) {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1675
|
+
delete(options, schema) {
|
|
1676
|
+
return schema != void 0 ? this.request({
|
|
1677
|
+
...options,
|
|
1678
|
+
method: "DELETE"
|
|
1679
|
+
}, schema) : this.request({
|
|
1680
|
+
...options,
|
|
1681
|
+
method: "DELETE"
|
|
1564
1682
|
});
|
|
1565
1683
|
}
|
|
1566
1684
|
};
|
|
@@ -1602,6 +1720,10 @@ var TeezClient = class {
|
|
|
1602
1720
|
*/
|
|
1603
1721
|
collections;
|
|
1604
1722
|
/**
|
|
1723
|
+
* API for managing user favorites.
|
|
1724
|
+
*/
|
|
1725
|
+
favorites;
|
|
1726
|
+
/**
|
|
1605
1727
|
* API for retrieving feature flags.
|
|
1606
1728
|
*/
|
|
1607
1729
|
featureFlags;
|
|
@@ -1637,6 +1759,7 @@ var TeezClient = class {
|
|
|
1637
1759
|
this.banners = new BannersApi(this.http);
|
|
1638
1760
|
this.categories = new CategoriesApi(this.http);
|
|
1639
1761
|
this.collections = new CollectionsApi(this.http);
|
|
1762
|
+
this.favorites = new FavoritesApi(this.http);
|
|
1640
1763
|
this.featureFlags = new FeatureFlagsApi(this.http);
|
|
1641
1764
|
this.products = new ProductsApi(this.http);
|
|
1642
1765
|
this.promo = new PromoApi(this.http);
|
|
@@ -1682,6 +1805,15 @@ exports.CollectionsApiStockAvailabilitySchema = CollectionsApiStockAvailabilityS
|
|
|
1682
1805
|
exports.CollectionsStockAvailabilityTypeSchema = CollectionsStockAvailabilityTypeSchema;
|
|
1683
1806
|
exports.DEFAULT_APP_VERSION = DEFAULT_APP_VERSION;
|
|
1684
1807
|
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
1808
|
+
exports.FavoritesApi = FavoritesApi;
|
|
1809
|
+
exports.FavoritesApiAddResponseSchema = FavoritesApiAddResponseSchema;
|
|
1810
|
+
exports.FavoritesApiBadgeSchema = FavoritesApiBadgeSchema;
|
|
1811
|
+
exports.FavoritesApiGetIdsResponseSchema = FavoritesApiGetIdsResponseSchema;
|
|
1812
|
+
exports.FavoritesApiItemSchema = FavoritesApiItemSchema;
|
|
1813
|
+
exports.FavoritesApiListResponseSchema = FavoritesApiListResponseSchema;
|
|
1814
|
+
exports.FavoritesApiRemoveResponseSchema = FavoritesApiRemoveResponseSchema;
|
|
1815
|
+
exports.FavoritesApiStockAvailabilitySchema = FavoritesApiStockAvailabilitySchema;
|
|
1816
|
+
exports.FavoritesStockAvailabilityTypeSchema = FavoritesStockAvailabilityTypeSchema;
|
|
1685
1817
|
exports.FeatureFlagsApi = FeatureFlagsApi;
|
|
1686
1818
|
exports.FeatureFlagsApiItemSchema = FeatureFlagsApiItemSchema;
|
|
1687
1819
|
exports.FeatureFlagsApiListResponseSchema = FeatureFlagsApiListResponseSchema;
|