@teez-sdk/teez-b2c-api 1.0.1 → 2.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/README.md +1 -1
- package/dist/index.cjs +221 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +453 -183
- package/dist/index.d.mts +453 -183
- package/dist/index.mjs +218 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,164 @@ 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
|
+
//#region src/api/auth/schemas.ts
|
|
99
|
+
/**
|
|
100
|
+
* Response schema for login.
|
|
101
|
+
*/
|
|
102
|
+
const AuthApiLoginResponseSchema = zod_mini.void();
|
|
103
|
+
/**
|
|
104
|
+
* Response schema for OTP verification.
|
|
105
|
+
*/
|
|
106
|
+
const AuthApiVerifyResponseSchema = zod_mini.object({
|
|
107
|
+
userId: zod_mini.string(),
|
|
108
|
+
accessToken: zod_mini.string(),
|
|
109
|
+
refreshToken: zod_mini.string(),
|
|
110
|
+
phone: zod_mini.string(),
|
|
111
|
+
pickupPoint: zod_mini.nullish(zod_mini.unknown()),
|
|
112
|
+
address: zod_mini.nullish(zod_mini.unknown()),
|
|
113
|
+
recipient: zod_mini.nullish(zod_mini.unknown()),
|
|
114
|
+
paymentId: zod_mini.nullish(zod_mini.number())
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* Response schema for token validation.
|
|
118
|
+
*/
|
|
119
|
+
const AuthApiCheckTokenResponseSchema = zod_mini.object({
|
|
120
|
+
userId: zod_mini.string(),
|
|
121
|
+
phoneNumber: zod_mini.string(),
|
|
122
|
+
fullName: zod_mini.string(),
|
|
123
|
+
email: zod_mini.string(),
|
|
124
|
+
expiredTokenDate: zod_mini.string(),
|
|
125
|
+
language: zod_mini.enum(["ru", "kk"]),
|
|
126
|
+
hasOrders: zod_mini.boolean(),
|
|
127
|
+
hasAnyOrders: zod_mini.boolean()
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/api/auth/api.ts
|
|
132
|
+
/**
|
|
133
|
+
* API for authentication operations.
|
|
134
|
+
*/
|
|
135
|
+
var AuthApi = class {
|
|
136
|
+
/**
|
|
137
|
+
* Initializes a new instance of the AuthApi.
|
|
138
|
+
*
|
|
139
|
+
* @param http HTTP client instance.
|
|
140
|
+
*/
|
|
141
|
+
constructor(http) {
|
|
142
|
+
this.http = http;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Initiates phone login by sending an OTP code to the specified phone number.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* await client.auth.login({
|
|
149
|
+
* phone: "+77071234567"
|
|
150
|
+
* });
|
|
151
|
+
*/
|
|
152
|
+
async login(params) {
|
|
153
|
+
return parseResponse(AuthApiLoginResponseSchema, await this.http.post({
|
|
154
|
+
path: "/auth/login",
|
|
155
|
+
body: params
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Verifies OTP code and obtains JWT access and refresh tokens.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const response = await client.auth.verify({
|
|
163
|
+
* phone: "+77071234567",
|
|
164
|
+
* otpCode: "2610"
|
|
165
|
+
* });
|
|
166
|
+
*/
|
|
167
|
+
async verify(params) {
|
|
168
|
+
return parseResponse(AuthApiVerifyResponseSchema, await this.http.post({
|
|
169
|
+
path: "/auth/verify",
|
|
170
|
+
body: params
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Validates the current JWT token and retrieves user information.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const response = await client.auth.checkToken();
|
|
178
|
+
*/
|
|
179
|
+
async checkToken(params = {}) {
|
|
180
|
+
return await this.http.get({
|
|
181
|
+
path: "/auth/check-token",
|
|
182
|
+
params,
|
|
183
|
+
schema: AuthApiCheckTokenResponseSchema
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
31
189
|
//#region src/api/banners/schemas.ts
|
|
32
190
|
/**
|
|
33
191
|
* Type literal for banner image resource type
|
|
@@ -442,6 +600,7 @@ var FeatureFlagsApi = class {
|
|
|
442
600
|
* Type union for product sort keys
|
|
443
601
|
*/
|
|
444
602
|
const ProductSortKeySchema = zod_mini.union([
|
|
603
|
+
zod_mini.literal("byRelevance"),
|
|
445
604
|
zod_mini.literal("popularity"),
|
|
446
605
|
zod_mini.literal("highestRated"),
|
|
447
606
|
zod_mini.literal("new"),
|
|
@@ -1067,20 +1226,9 @@ const LANGUAGES = {
|
|
|
1067
1226
|
KZ: "kz"
|
|
1068
1227
|
};
|
|
1069
1228
|
/**
|
|
1070
|
-
* Standard sort options for product and collection searches
|
|
1071
|
-
*/
|
|
1072
|
-
const SORT_OPTIONS = {
|
|
1073
|
-
BY_RELEVANCE: "byRelevance",
|
|
1074
|
-
POPULARITY: "popularity",
|
|
1075
|
-
HIGHEST_RATED: "highestRated",
|
|
1076
|
-
NEW: "new",
|
|
1077
|
-
PRICE: "price",
|
|
1078
|
-
PRICE_DESC: "priceDesc"
|
|
1079
|
-
};
|
|
1080
|
-
/**
|
|
1081
1229
|
* Default application version code.
|
|
1082
1230
|
*/
|
|
1083
|
-
const DEFAULT_APP_VERSION = "
|
|
1231
|
+
const DEFAULT_APP_VERSION = "200";
|
|
1084
1232
|
|
|
1085
1233
|
//#endregion
|
|
1086
1234
|
//#region src/config.ts
|
|
@@ -1100,6 +1248,7 @@ const DEFAULT_CONFIG = {
|
|
|
1100
1248
|
function resolveConfig(config) {
|
|
1101
1249
|
return {
|
|
1102
1250
|
baseUrl: config?.baseUrl ?? DEFAULT_CONFIG.baseUrl,
|
|
1251
|
+
token: config?.token,
|
|
1103
1252
|
appVersion: config?.appVersion ?? DEFAULT_CONFIG.appVersion,
|
|
1104
1253
|
language: config?.language ?? DEFAULT_CONFIG.language,
|
|
1105
1254
|
timeout: config?.timeout ?? DEFAULT_CONFIG.timeout,
|
|
@@ -1119,23 +1268,16 @@ function buildUserAgent(appVersion) {
|
|
|
1119
1268
|
* Builds the headers object for API requests based on configuration.
|
|
1120
1269
|
*/
|
|
1121
1270
|
function buildHeaders(config) {
|
|
1122
|
-
|
|
1271
|
+
const headers = {
|
|
1123
1272
|
"accept-language": config.language,
|
|
1124
1273
|
"user-agent": buildUserAgent(config.appVersion),
|
|
1125
1274
|
"x-app-version": config.appVersion,
|
|
1126
1275
|
...config.headers
|
|
1127
1276
|
};
|
|
1277
|
+
if (config.token !== void 0 && config.token !== null) headers["authorization"] = `Bearer ${config.token}`;
|
|
1278
|
+
return headers;
|
|
1128
1279
|
}
|
|
1129
1280
|
|
|
1130
|
-
//#endregion
|
|
1131
|
-
//#region src/errors/teez-error.ts
|
|
1132
|
-
/**
|
|
1133
|
-
* Base error class for all SDK-related errors.
|
|
1134
|
-
*/
|
|
1135
|
-
var TeezError = class extends Error {
|
|
1136
|
-
name = "TeezError";
|
|
1137
|
-
};
|
|
1138
|
-
|
|
1139
1281
|
//#endregion
|
|
1140
1282
|
//#region src/errors/teez-api-error.ts
|
|
1141
1283
|
/**
|
|
@@ -1225,64 +1367,6 @@ var TeezTimeoutError = class extends TeezError {
|
|
|
1225
1367
|
}
|
|
1226
1368
|
};
|
|
1227
1369
|
|
|
1228
|
-
//#endregion
|
|
1229
|
-
//#region src/errors/teez-validation-error.ts
|
|
1230
|
-
/**
|
|
1231
|
-
* Error thrown when validation fails.
|
|
1232
|
-
*/
|
|
1233
|
-
var TeezValidationError = class extends TeezError {
|
|
1234
|
-
name = "TeezValidationError";
|
|
1235
|
-
/**
|
|
1236
|
-
* List of standardized validation issues.
|
|
1237
|
-
*/
|
|
1238
|
-
issues;
|
|
1239
|
-
/**
|
|
1240
|
-
* The raw data that failed validation.
|
|
1241
|
-
*/
|
|
1242
|
-
data;
|
|
1243
|
-
constructor(message, { issues, data, ...errorOptions }) {
|
|
1244
|
-
super(message, errorOptions);
|
|
1245
|
-
this.issues = issues;
|
|
1246
|
-
this.data = data;
|
|
1247
|
-
}
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
//#endregion
|
|
1251
|
-
//#region src/http/helpers.ts
|
|
1252
|
-
/**
|
|
1253
|
-
* Constructs a full URL with query parameters.
|
|
1254
|
-
*/
|
|
1255
|
-
function buildUrl(path, baseUrl, queryParams) {
|
|
1256
|
-
const url = new URL(path, baseUrl);
|
|
1257
|
-
if (queryParams != void 0) for (const [key, value] of Object.entries(queryParams)) {
|
|
1258
|
-
if (value == void 0) continue;
|
|
1259
|
-
if (Array.isArray(value)) for (const item of value) url.searchParams.append(key, String(item));
|
|
1260
|
-
else url.searchParams.set(key, String(value));
|
|
1261
|
-
}
|
|
1262
|
-
return String(url);
|
|
1263
|
-
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Converts Zod ZodError to abstract ValidationIssue[].
|
|
1266
|
-
*/
|
|
1267
|
-
function toValidationIssues(error) {
|
|
1268
|
-
return error.issues.map((issue) => ({
|
|
1269
|
-
code: issue.code,
|
|
1270
|
-
path: issue.path,
|
|
1271
|
-
message: issue.message
|
|
1272
|
-
}));
|
|
1273
|
-
}
|
|
1274
|
-
/**
|
|
1275
|
-
* Validates and parses the API response data against a schema.
|
|
1276
|
-
*/
|
|
1277
|
-
function parseResponse(schema, data) {
|
|
1278
|
-
const result = zod_mini.safeParse(schema, data);
|
|
1279
|
-
if (!result.success) throw new TeezValidationError("Response validation failed", {
|
|
1280
|
-
issues: toValidationIssues(result.error),
|
|
1281
|
-
data
|
|
1282
|
-
});
|
|
1283
|
-
return result.data;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
1370
|
//#endregion
|
|
1287
1371
|
//#region src/http/client.ts
|
|
1288
1372
|
/**
|
|
@@ -1290,26 +1374,21 @@ function parseResponse(schema, data) {
|
|
|
1290
1374
|
*/
|
|
1291
1375
|
var HttpClient = class {
|
|
1292
1376
|
/**
|
|
1293
|
-
*
|
|
1377
|
+
* Client configuration.
|
|
1294
1378
|
*/
|
|
1295
|
-
|
|
1379
|
+
config;
|
|
1296
1380
|
/**
|
|
1297
1381
|
* Headers to include in all requests.
|
|
1298
1382
|
*/
|
|
1299
1383
|
headers;
|
|
1300
1384
|
/**
|
|
1301
|
-
* Request timeout in milliseconds.
|
|
1302
|
-
*/
|
|
1303
|
-
timeout;
|
|
1304
|
-
/**
|
|
1305
1385
|
* Initializes a new instance of the HttpClient.
|
|
1306
1386
|
*
|
|
1307
1387
|
* @param config Resolved client configuration.
|
|
1308
1388
|
*/
|
|
1309
1389
|
constructor(config) {
|
|
1310
|
-
this.
|
|
1390
|
+
this.config = config;
|
|
1311
1391
|
this.headers = buildHeaders(config);
|
|
1312
|
-
this.timeout = config.timeout;
|
|
1313
1392
|
}
|
|
1314
1393
|
/**
|
|
1315
1394
|
* Performs a low-level HTTP request.
|
|
@@ -1321,7 +1400,7 @@ var HttpClient = class {
|
|
|
1321
1400
|
const controller = new AbortController();
|
|
1322
1401
|
const timeoutId = setTimeout(() => {
|
|
1323
1402
|
controller.abort();
|
|
1324
|
-
}, this.timeout);
|
|
1403
|
+
}, this.config.timeout);
|
|
1325
1404
|
try {
|
|
1326
1405
|
const response = await fetch(url, {
|
|
1327
1406
|
...fetchOptions,
|
|
@@ -1345,12 +1424,13 @@ var HttpClient = class {
|
|
|
1345
1424
|
body
|
|
1346
1425
|
});
|
|
1347
1426
|
}
|
|
1427
|
+
if (response.status === 204) return;
|
|
1348
1428
|
return await response.json();
|
|
1349
1429
|
} catch (error) {
|
|
1350
1430
|
if (error instanceof TeezApiError) throw error;
|
|
1351
|
-
if (error instanceof DOMException && error.name === "AbortError") throw new TeezTimeoutError(`Request timed out after ${this.timeout}ms`, {
|
|
1431
|
+
if (error instanceof DOMException && error.name === "AbortError") throw new TeezTimeoutError(`Request timed out after ${this.config.timeout}ms`, {
|
|
1352
1432
|
url,
|
|
1353
|
-
timeout: this.timeout,
|
|
1433
|
+
timeout: this.config.timeout,
|
|
1354
1434
|
cause: error
|
|
1355
1435
|
});
|
|
1356
1436
|
throw new TeezNetworkError(`Network request failed`, {
|
|
@@ -1366,13 +1446,53 @@ var HttpClient = class {
|
|
|
1366
1446
|
*/
|
|
1367
1447
|
async get(options) {
|
|
1368
1448
|
const { path, params, schema, ...rest } = options;
|
|
1369
|
-
const url = buildUrl(path, this.baseUrl, params);
|
|
1449
|
+
const url = buildUrl(path, this.config.baseUrl, params);
|
|
1370
1450
|
return parseResponse(schema, await this.request({
|
|
1371
1451
|
url,
|
|
1372
1452
|
method: "GET",
|
|
1373
1453
|
...rest
|
|
1374
1454
|
}));
|
|
1375
1455
|
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Performs a POST request.
|
|
1458
|
+
*/
|
|
1459
|
+
post(options) {
|
|
1460
|
+
const { path, params, body, ...rest } = options;
|
|
1461
|
+
const url = buildUrl(path, this.config.baseUrl, params);
|
|
1462
|
+
return this.request({
|
|
1463
|
+
url,
|
|
1464
|
+
method: "POST",
|
|
1465
|
+
headers: { "Content-Type": "application/json" },
|
|
1466
|
+
body: body != void 0 ? JSON.stringify(body) : void 0,
|
|
1467
|
+
...rest
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Performs a PATCH request.
|
|
1472
|
+
*/
|
|
1473
|
+
patch(options) {
|
|
1474
|
+
const { path, params, body, ...rest } = options;
|
|
1475
|
+
const url = buildUrl(path, this.config.baseUrl, params);
|
|
1476
|
+
return this.request({
|
|
1477
|
+
url,
|
|
1478
|
+
method: "PATCH",
|
|
1479
|
+
headers: { "Content-Type": "application/json" },
|
|
1480
|
+
body: body != void 0 ? JSON.stringify(body) : void 0,
|
|
1481
|
+
...rest
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Performs a DELETE request.
|
|
1486
|
+
*/
|
|
1487
|
+
delete(options) {
|
|
1488
|
+
const { path, params, ...rest } = options;
|
|
1489
|
+
const url = buildUrl(path, this.config.baseUrl, params);
|
|
1490
|
+
return this.request({
|
|
1491
|
+
url,
|
|
1492
|
+
method: "DELETE",
|
|
1493
|
+
...rest
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1376
1496
|
};
|
|
1377
1497
|
|
|
1378
1498
|
//#endregion
|
|
@@ -1396,6 +1516,10 @@ var TeezClient = class {
|
|
|
1396
1516
|
*/
|
|
1397
1517
|
http;
|
|
1398
1518
|
/**
|
|
1519
|
+
* API for authentication operations (login, verify OTP, check token).
|
|
1520
|
+
*/
|
|
1521
|
+
auth;
|
|
1522
|
+
/**
|
|
1399
1523
|
* API for retrieving banners.
|
|
1400
1524
|
*/
|
|
1401
1525
|
banners;
|
|
@@ -1435,6 +1559,7 @@ var TeezClient = class {
|
|
|
1435
1559
|
constructor(config) {
|
|
1436
1560
|
this.config = resolveConfig(config);
|
|
1437
1561
|
this.http = new HttpClient(this.config);
|
|
1562
|
+
this.auth = new AuthApi(this.http);
|
|
1438
1563
|
this.banners = new BannersApi(this.http);
|
|
1439
1564
|
this.categories = new CategoriesApi(this.http);
|
|
1440
1565
|
this.collections = new CollectionsApi(this.http);
|
|
@@ -1453,6 +1578,10 @@ var TeezClient = class {
|
|
|
1453
1578
|
};
|
|
1454
1579
|
|
|
1455
1580
|
//#endregion
|
|
1581
|
+
exports.AuthApi = AuthApi;
|
|
1582
|
+
exports.AuthApiCheckTokenResponseSchema = AuthApiCheckTokenResponseSchema;
|
|
1583
|
+
exports.AuthApiLoginResponseSchema = AuthApiLoginResponseSchema;
|
|
1584
|
+
exports.AuthApiVerifyResponseSchema = AuthApiVerifyResponseSchema;
|
|
1456
1585
|
exports.BASE_URL = BASE_URL;
|
|
1457
1586
|
exports.BannerActionTypesSchema = BannerActionTypesSchema;
|
|
1458
1587
|
exports.BannerImageTypeSchema = BannerImageTypeSchema;
|
|
@@ -1496,7 +1625,6 @@ exports.ProductsStockAvailabilityTypeSchema = ProductsStockAvailabilityTypeSchem
|
|
|
1496
1625
|
exports.PromoApi = PromoApi;
|
|
1497
1626
|
exports.PromoApiItemSchema = PromoApiItemSchema;
|
|
1498
1627
|
exports.PromoApiListResponseSchema = PromoApiListResponseSchema;
|
|
1499
|
-
exports.SORT_OPTIONS = SORT_OPTIONS;
|
|
1500
1628
|
exports.ShopsApi = ShopsApi;
|
|
1501
1629
|
exports.ShopsApiContactInfoSchema = ShopsApiContactInfoSchema;
|
|
1502
1630
|
exports.ShopsApiGetMonobrandResponseSchema = ShopsApiGetMonobrandResponseSchema;
|