@teez-sdk/teez-b2c-api 1.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/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # @teez-sdk/teez-b2c-api
2
+
3
+ [← Back to root](../../README.md)
4
+
5
+ A typed TypeScript client for the Teez B2C API.
6
+
7
+ ## Features
8
+
9
+ - **Fully Typed:** Written in TypeScript with complete type definitions.
10
+ - **Runtime Validation:** Uses [Zod](https://zod.dev) to validate API responses.
11
+ - **Modular:** API endpoints are organized into logical modules (Products, Banners, etc.).
12
+ - **Error Handling:** Custom error classes for fine-grained control over API, network, and validation errors.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @teez-sdk/teez-b2c-api
18
+ # or
19
+ yarn add @teez-sdk/teez-b2c-api
20
+ # or
21
+ pnpm add @teez-sdk/teez-b2c-api
22
+
23
+ ```
24
+
25
+ ## Getting Started
26
+
27
+ Initialize the client and make your first request:
28
+
29
+ ```typescript
30
+ import { TeezClient } from "@teez-sdk/teez-b2c-api";
31
+
32
+ // Initialize with default configuration
33
+ const client = new TeezClient();
34
+
35
+ // Or with custom configuration
36
+ const customClient = new TeezClient({
37
+ timeout: 5000,
38
+ language: "kk", // Request responses in Kazakh
39
+ });
40
+
41
+ try {
42
+ // Fetch products
43
+ const products = await client.products.list({
44
+ pageSize: 10,
45
+ pageNumber: 1,
46
+ });
47
+
48
+ console.log(products);
49
+ } catch (error) {
50
+ console.error("Failed to fetch products:", error);
51
+ }
52
+ ```
53
+
54
+ ## Configuration
55
+
56
+ The `TeezClient` accepts an optional configuration object:
57
+
58
+ ```typescript
59
+ interface TeezClientConfig {
60
+ /** Base URL for the API. Default: "[https://b2c-api.teez.kz](https://b2c-api.teez.kz)" */
61
+ baseUrl?: string;
62
+
63
+ /** Application version. Default: "193" */
64
+ appVersion?: string;
65
+
66
+ /** Language for API responses. Default: "ru" */
67
+ language?: "ru" | "kk" | "uz";
68
+
69
+ /** Request timeout in milliseconds. Default: 30000 */
70
+ timeout?: number;
71
+
72
+ /** Custom headers to include in all requests. */
73
+ headers?: Record<string, string>;
74
+ }
75
+ ```
76
+
77
+ ### Examples
78
+
79
+ **Set a custom app version:**
80
+
81
+ ```typescript
82
+ const client = new TeezClient({
83
+ appVersion: "200", // User-agent will be "android;kz.teez.customer;200"
84
+ });
85
+ ```
86
+
87
+ **Use a custom user-agent:**
88
+
89
+ ```typescript
90
+ const client = new TeezClient({
91
+ headers: {
92
+ "user-agent": "my-custom-client/1.0",
93
+ },
94
+ });
95
+ ```
96
+
97
+ ## Usage Examples
98
+
99
+ ### Categories
100
+
101
+ ```typescript
102
+ import { TeezClient } from "@teez-sdk/teez-b2c-api";
103
+
104
+ const client = new TeezClient();
105
+
106
+ // Get all categories
107
+ const categories = await client.categories.list();
108
+
109
+ console.log(`Found ${categories.length} categories`);
110
+
111
+ // Get a specific category
112
+ const electronics = await client.categories.get({
113
+ categoryId: 3472,
114
+ });
115
+
116
+ console.log(`Category: ${electronics.name} (level ${electronics.level})`);
117
+
118
+ // Get parent hierarchies for multiple categories
119
+ const parents = await client.categories.getParents({
120
+ categoryId: [3472, 7665, 3431],
121
+ level: 1, // Optional: filter by hierarchy level
122
+ });
123
+
124
+ console.log(`Found ${parents.length} parent hierarchies`);
125
+ ```
126
+
127
+ ### Products
128
+
129
+ ```typescript
130
+ // List products with pagination
131
+ const products = await client.products.list({
132
+ pageSize: 20,
133
+ pageNumber: 1,
134
+ });
135
+
136
+ // Get product reviews
137
+ const reviews = await client.products.getReviews({
138
+ productId: 12345,
139
+ pageSize: 10,
140
+ });
141
+
142
+ // Get similar products
143
+ const similar = await client.sku.getSimilar({
144
+ skuId: 12345,
145
+ pageSize: 5,
146
+ });
147
+ ```
148
+
149
+ ## Available APIs
150
+
151
+ The client exposes the following API modules:
152
+
153
+ - `client.banners` - Retrieve banners.
154
+ - `client.categories` - Browse product categories.
155
+ - `client.collections` - access curated collections.
156
+ - `client.featureFlags` - Check feature availability.
157
+ - `client.products` - Search and filter products, get reviews.
158
+ - `client.promo` - Access promotions.
159
+ - `client.shops` - Information about shops.
160
+ - `client.sku` - Detailed SKU information.
161
+
162
+ ## Error Handling
163
+
164
+ The SDK throws specific error types to help you handle failures gracefully:
165
+
166
+ - `TeezApiError`: The server returned a non-2xx status code. Contains status, status text, and response body.
167
+ - `TeezNetworkError`: Network failure (e.g., DNS resolution, offline).
168
+ - `TeezTimeoutError`: The request exceeded the configured timeout.
169
+ - `TeezValidationError`: The API response did not match the expected schema (Zod validation failed).
170
+
171
+ ```typescript
172
+ import { TeezApiError, TeezTimeoutError } from "@teez-sdk/teez-b2c-api";
173
+
174
+ try {
175
+ await client.products.list();
176
+ } catch (error) {
177
+ if (error instanceof TeezTimeoutError) {
178
+ console.error("Request timed out");
179
+ } else if (error instanceof TeezApiError) {
180
+ console.error(`API Error: ${error.status} - ${error.message}`);
181
+ } else {
182
+ console.error("Unknown error:", error);
183
+ }
184
+ }
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT