@gt6/sdk 1.0.19 → 1.0.21

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.
@@ -35,12 +35,14 @@ class GT6Client {
35
35
  try {
36
36
  const controller = new AbortController();
37
37
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
38
+ // 对于FormData,不设置Content-Type,让浏览器自动设置
39
+ const headers = new Headers(options.headers);
40
+ if (!(options.body instanceof FormData)) {
41
+ headers.set('Content-Type', 'application/json');
42
+ }
38
43
  const response = await fetch(url, {
39
44
  ...options,
40
- headers: {
41
- 'Content-Type': 'application/json',
42
- ...options.headers,
43
- },
45
+ headers,
44
46
  signal: controller.signal
45
47
  });
46
48
  clearTimeout(timeoutId);
@@ -1338,9 +1340,10 @@ class UsersAPI {
1338
1340
  }
1339
1341
  /**
1340
1342
  * 获取用户地址列表
1343
+ * @param userType 用户类型,默认为2(普通用户)
1341
1344
  * @returns 地址列表响应
1342
1345
  */
1343
- async getAddresses() {
1346
+ async getAddresses(userType = 2) {
1344
1347
  try {
1345
1348
  // 获取用户token
1346
1349
  const token = this.getToken();
@@ -1350,7 +1353,7 @@ class UsersAPI {
1350
1353
  message: '用户未登录'
1351
1354
  };
1352
1355
  }
1353
- const response = await this.client.request('/web/user/addresses', {
1356
+ const response = await this.client.request(`/web/user/addresses?userType=${userType}`, {
1354
1357
  method: 'GET',
1355
1358
  headers: {
1356
1359
  'Authorization': `Bearer ${token}`,
@@ -1384,19 +1387,21 @@ class UsersAPI {
1384
1387
  }
1385
1388
  /**
1386
1389
  * 获取用户地址列表(简化版本)
1390
+ * @param userType 用户类型,默认为2(普通用户)
1387
1391
  * @returns 地址列表或null
1388
1392
  */
1389
- async getAddressesSimple() {
1390
- const result = await this.getAddresses();
1393
+ async getAddressesSimple(userType = 2) {
1394
+ const result = await this.getAddresses(userType);
1391
1395
  return result.success && result.addresses ? result.addresses : null;
1392
1396
  }
1393
1397
  /**
1394
1398
  * 根据地址ID获取地址信息
1395
1399
  * @param addressId 地址ID
1400
+ * @param userType 用户类型,默认为2(普通用户)
1396
1401
  * @returns 地址信息或null
1397
1402
  */
1398
- async getAddressById(addressId) {
1399
- const addresses = await this.getAddressesSimple();
1403
+ async getAddressById(addressId, userType = 2) {
1404
+ const addresses = await this.getAddressesSimple(userType);
1400
1405
  if (addresses) {
1401
1406
  return addresses.find(addr => addr.addressId === addressId) || null;
1402
1407
  }
@@ -1567,13 +1572,18 @@ class UsersAPI {
1567
1572
  message: '用户未登录'
1568
1573
  };
1569
1574
  }
1575
+ // 确保userType有默认值
1576
+ const requestData = {
1577
+ ...addressData,
1578
+ userType: addressData.userType || 2
1579
+ };
1570
1580
  const response = await this.client.request('/web/user/addresses', {
1571
1581
  method: 'POST',
1572
1582
  headers: {
1573
1583
  'Authorization': `Bearer ${token}`,
1574
1584
  'Content-Type': 'application/json'
1575
1585
  },
1576
- body: JSON.stringify(addressData)
1586
+ body: JSON.stringify(requestData)
1577
1587
  });
1578
1588
  return response;
1579
1589
  }
@@ -1616,13 +1626,18 @@ class UsersAPI {
1616
1626
  message: '用户未登录'
1617
1627
  };
1618
1628
  }
1629
+ // 确保userType有默认值
1630
+ const requestData = {
1631
+ ...addressData,
1632
+ userType: addressData.userType || 2
1633
+ };
1619
1634
  const response = await this.client.request(`/web/user/addresses/${addressId}`, {
1620
1635
  method: 'PUT',
1621
1636
  headers: {
1622
1637
  'Authorization': `Bearer ${token}`,
1623
1638
  'Content-Type': 'application/json'
1624
1639
  },
1625
- body: JSON.stringify(addressData)
1640
+ body: JSON.stringify(requestData)
1626
1641
  });
1627
1642
  return response;
1628
1643
  }
@@ -1652,9 +1667,10 @@ class UsersAPI {
1652
1667
  /**
1653
1668
  * 删除地址
1654
1669
  * @param addressId 地址ID
1670
+ * @param userType 用户类型,默认为2(普通用户)
1655
1671
  * @returns 删除地址响应
1656
1672
  */
1657
- async deleteAddress(addressId) {
1673
+ async deleteAddress(addressId, userType = 2) {
1658
1674
  try {
1659
1675
  // 获取用户token
1660
1676
  const token = this.getToken();
@@ -1664,7 +1680,7 @@ class UsersAPI {
1664
1680
  message: '用户未登录'
1665
1681
  };
1666
1682
  }
1667
- const response = await this.client.request(`/web/user/addresses/${addressId}`, {
1683
+ const response = await this.client.request(`/web/user/addresses/${addressId}?userType=${userType}`, {
1668
1684
  method: 'DELETE',
1669
1685
  headers: {
1670
1686
  'Authorization': `Bearer ${token}`,
@@ -2275,21 +2291,25 @@ class GT6SDK {
2275
2291
  }
2276
2292
  /**
2277
2293
  * 便捷方法:获取用户地址列表
2294
+ * @param userType 用户类型,默认为2(普通用户)
2278
2295
  */
2279
- async getAddresses() {
2280
- return this.users.getAddresses();
2296
+ async getAddresses(userType = 2) {
2297
+ return this.users.getAddresses(userType);
2281
2298
  }
2282
2299
  /**
2283
2300
  * 便捷方法:获取用户地址列表(简化版本)
2301
+ * @param userType 用户类型,默认为2(普通用户)
2284
2302
  */
2285
- async getAddressesSimple() {
2286
- return this.users.getAddressesSimple();
2303
+ async getAddressesSimple(userType = 2) {
2304
+ return this.users.getAddressesSimple(userType);
2287
2305
  }
2288
2306
  /**
2289
2307
  * 便捷方法:根据地址ID获取地址信息
2308
+ * @param addressId 地址ID
2309
+ * @param userType 用户类型,默认为2(普通用户)
2290
2310
  */
2291
- async getAddressById(addressId) {
2292
- return this.users.getAddressById(addressId);
2311
+ async getAddressById(addressId, userType = 2) {
2312
+ return this.users.getAddressById(addressId, userType);
2293
2313
  }
2294
2314
  /**
2295
2315
  * 便捷方法:获取用户资料
@@ -2317,21 +2337,26 @@ class GT6SDK {
2317
2337
  }
2318
2338
  /**
2319
2339
  * 便捷方法:创建地址
2340
+ * @param addressData 地址数据
2320
2341
  */
2321
2342
  async createAddress(addressData) {
2322
2343
  return this.users.createAddress(addressData);
2323
2344
  }
2324
2345
  /**
2325
2346
  * 便捷方法:更新地址
2347
+ * @param addressId 地址ID
2348
+ * @param addressData 地址数据
2326
2349
  */
2327
2350
  async updateAddress(addressId, addressData) {
2328
2351
  return this.users.updateAddress(addressId, addressData);
2329
2352
  }
2330
2353
  /**
2331
2354
  * 便捷方法:删除地址
2355
+ * @param addressId 地址ID
2356
+ * @param userType 用户类型,默认为2(普通用户)
2332
2357
  */
2333
- async deleteAddress(addressId) {
2334
- return this.users.deleteAddress(addressId);
2358
+ async deleteAddress(addressId, userType = 2) {
2359
+ return this.users.deleteAddress(addressId, userType);
2335
2360
  }
2336
2361
  /**
2337
2362
  * 便捷方法:上传文件