@be-link/ecommerce-backend-bff-service-node-sdk 0.0.16 → 0.0.18

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.
@@ -1,4 +1,4 @@
1
- import { ProductService as Service } from './types';
1
+ import { PandoraProductService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductService {
2
+ export declare namespace PandoraProductService {
3
3
  /**
4
4
  * 核销期限接口
5
5
  */
@@ -202,46 +202,46 @@ export declare namespace ProductService {
202
202
  /**
203
203
  * 商品列表
204
204
  */
205
- list(request: ProductService.Request.list): Promise<StandardResponse<ProductService.Response.list>>;
205
+ list(request: PandoraProductService.Request.list): Promise<StandardResponse<PandoraProductService.Response.list>>;
206
206
  /**
207
207
  * 创建商品
208
208
  */
209
- create(request: ProductService.ProductData): Promise<StandardResponse<ProductService.Response.create>>;
209
+ create(request: PandoraProductService.ProductData): Promise<StandardResponse<PandoraProductService.Response.create>>;
210
210
  /**
211
211
  * 商品详情
212
212
  */
213
- detail(request: ProductService.Request.detail): Promise<StandardResponse<ProductService.ProductData>>;
213
+ detail(request: PandoraProductService.Request.detail): Promise<StandardResponse<PandoraProductService.ProductData>>;
214
214
  /**
215
215
  * 商品更新
216
216
  */
217
- update(request: ProductService.ProductData): Promise<StandardResponse<void>>;
217
+ update(request: PandoraProductService.ProductData): Promise<StandardResponse<void>>;
218
218
  /**
219
219
  * 批量更新
220
220
  */
221
- batchUpdate(request: ProductService.Request.batchUpdate): Promise<StandardResponse<void>>;
221
+ batchUpdate(request: PandoraProductService.Request.batchUpdate): Promise<StandardResponse<void>>;
222
222
  /**
223
223
  * 查询定时任务任务
224
224
  */
225
- queryScheduledTask(request: ProductService.Request.queryScheduledTask): Promise<StandardResponse<ProductService.Response.queryScheduledTask[]>>;
225
+ queryScheduledTask(request: PandoraProductService.Request.queryScheduledTask): Promise<StandardResponse<PandoraProductService.Response.queryScheduledTask[]>>;
226
226
  /**
227
227
  * 校验69码是否重复
228
228
  */
229
- checkSkuCode(request: ProductService.Request.checkSkuCode): Promise<StandardResponse<ProductService.Response.checkSkuCode>>;
229
+ checkSkuCode(request: PandoraProductService.Request.checkSkuCode): Promise<StandardResponse<PandoraProductService.Response.checkSkuCode>>;
230
230
  /**
231
231
  * 商品导出
232
232
  */
233
- export(request: ProductService.Request.list): Promise<StandardResponse<void>>;
233
+ export(request: PandoraProductService.Request.list): Promise<StandardResponse<void>>;
234
234
  /**
235
235
  * 获取商品信息(不含规格信息)
236
236
  */
237
- queryProductList(request: ProductService.Request.queryProductList): Promise<StandardResponse<ProductService.Response.queryProductList>>;
237
+ queryProductList(request: PandoraProductService.Request.queryProductList): Promise<StandardResponse<PandoraProductService.Response.queryProductList>>;
238
238
  /**
239
239
  * 获取商品+规格信息
240
240
  */
241
- queryProductSkuList(request: ProductService.Request.queryProductList): Promise<StandardResponse<ProductService.Response.queryProductSkuList>>;
241
+ queryProductSkuList(request: PandoraProductService.Request.queryProductList): Promise<StandardResponse<PandoraProductService.Response.queryProductSkuList>>;
242
242
  /**
243
243
  * 商品二维码
244
244
  */
245
- productQrCode(request: ProductService.Request.productQrCode): Promise<StandardResponse<ProductService.Response.productQrCode>>;
245
+ productQrCode(request: PandoraProductService.Request.productQrCode): Promise<StandardResponse<PandoraProductService.Response.productQrCode>>;
246
246
  }
247
247
  }
@@ -1,4 +1,4 @@
1
- import { ProductExpService as Service } from './types';
1
+ import { PandoraProductExpService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductExpService {
2
+ export declare namespace PandoraProductExpService {
3
3
  interface ProductCategory {
4
4
  id: string;
5
5
  parentId: string;
@@ -56,26 +56,26 @@ export declare namespace ProductExpService {
56
56
  /**
57
57
  * 获取供应商列表
58
58
  */
59
- getSupplierList(): Promise<StandardResponse<ProductExpService.Response.getSupplierList[]>>;
59
+ getSupplierList(): Promise<StandardResponse<PandoraProductExpService.Response.getSupplierList[]>>;
60
60
  /**
61
61
  * 新增供应商
62
62
  */
63
- addSupplier(request: ProductExpService.Request.addSupplier): Promise<StandardResponse<ProductExpService.Response.addSupplier>>;
63
+ addSupplier(request: PandoraProductExpService.Request.addSupplier): Promise<StandardResponse<PandoraProductExpService.Response.addSupplier>>;
64
64
  /**
65
65
  * 获取直播分组列表
66
66
  */
67
- getLiveGroupList(): Promise<StandardResponse<ProductExpService.Response.getLiveGroupList[]>>;
67
+ getLiveGroupList(): Promise<StandardResponse<PandoraProductExpService.Response.getLiveGroupList[]>>;
68
68
  /**
69
69
  * 新增直播分组
70
70
  */
71
- addLiveGroup(request: ProductExpService.Request.addLiveGroup): Promise<StandardResponse<ProductExpService.Response.addLiveGroup>>;
71
+ addLiveGroup(request: PandoraProductExpService.Request.addLiveGroup): Promise<StandardResponse<PandoraProductExpService.Response.addLiveGroup>>;
72
72
  /**
73
73
  * 商品分类 树结构
74
74
  */
75
- productCategoryTree(): Promise<StandardResponse<ProductExpService.Response.ProductCategoryTree>>;
75
+ productCategoryTree(): Promise<StandardResponse<PandoraProductExpService.Response.ProductCategoryTree>>;
76
76
  /**
77
77
  * 获取产品经理列表
78
78
  */
79
- getProductManagerList(): Promise<StandardResponse<ProductExpService.Response.getProductManagerList>>;
79
+ getProductManagerList(): Promise<StandardResponse<PandoraProductExpService.Response.getProductManagerList>>;
80
80
  }
81
81
  }
@@ -1,4 +1,4 @@
1
- import { ProductLiveService as Service } from './types';
1
+ import { PandoraProductLiveService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductLiveService {
2
+ export declare namespace PandoraProductLiveService {
3
3
  namespace Request {
4
4
  interface list {
5
5
  pageIndex: number;
@@ -30,14 +30,14 @@ export declare namespace ProductLiveService {
30
30
  /**
31
31
  * 商品列表
32
32
  */
33
- list(request: ProductLiveService.Request.list): Promise<StandardResponse<ProductLiveService.Response.list>>;
33
+ list(request: PandoraProductLiveService.Request.list): Promise<StandardResponse<PandoraProductLiveService.Response.list>>;
34
34
  /**
35
35
  * 新增商品
36
36
  */
37
- add(request: ProductLiveService.Request.operate): Promise<StandardResponse<void>>;
37
+ add(request: PandoraProductLiveService.Request.operate): Promise<StandardResponse<void>>;
38
38
  /**
39
39
  * 删除商品
40
40
  */
41
- remove(request: ProductLiveService.Request.operate): Promise<StandardResponse<void>>;
41
+ remove(request: PandoraProductLiveService.Request.operate): Promise<StandardResponse<void>>;
42
42
  }
43
43
  }
@@ -48,7 +48,7 @@ class HttpClient {
48
48
  // 构造标准请求头
49
49
  const standardHeaders = {
50
50
  'Content-Type': 'application/json',
51
- 'X-Request-Id': requestId,
51
+ 'x-request-id': requestId,
52
52
  'x-belink-authorization': token,
53
53
  'x-belink-pandora-userid': userId,
54
54
  'x-belink-pandora-roleid': roleId,
@@ -34,12 +34,12 @@ export declare class WebRequestStrategy extends BaseRequestStrategy {
34
34
  request<T>(path: string, data?: any, headers?: Record<string, string>): Promise<T>;
35
35
  }
36
36
  /**
37
- * 微信小程序请求策略,使用 wx.cloud.callContainer
37
+ * 微信小程序请求策略,使用 wx.request
38
38
  * 为微信小程序环境实现请求策略
39
39
  */
40
40
  export declare class MiniProgramRequestStrategy extends BaseRequestStrategy {
41
41
  /**
42
- * 使用微信云托管容器 API 执行请求
42
+ * 使用 wx.request 执行 HTTP 请求
43
43
  * @param path - API 端点路径
44
44
  * @param data - 请求负载(可选)
45
45
  * @param headers - 要包含在请求中的额外请求头(可选)
@@ -36,7 +36,7 @@ class WebRequestStrategy extends BaseRequestStrategy {
36
36
  * @throws SystemError 如果是 5xx 服务器错误或网络错误
37
37
  */
38
38
  async request(path, data, headers = {}) {
39
- const requestId = headers['X-Request-Id'] || 'unknown';
39
+ const requestId = headers['x-request-id'] || 'unknown';
40
40
  const url = `${(0, env_1.getContainerHost)(this.environment)}${path}`;
41
41
  try {
42
42
  if (console?.info) {
@@ -100,12 +100,12 @@ class WebRequestStrategy extends BaseRequestStrategy {
100
100
  }
101
101
  exports.WebRequestStrategy = WebRequestStrategy;
102
102
  /**
103
- * 微信小程序请求策略,使用 wx.cloud.callContainer
103
+ * 微信小程序请求策略,使用 wx.request
104
104
  * 为微信小程序环境实现请求策略
105
105
  */
106
106
  class MiniProgramRequestStrategy extends BaseRequestStrategy {
107
107
  /**
108
- * 使用微信云托管容器 API 执行请求
108
+ * 使用 wx.request 执行 HTTP 请求
109
109
  * @param path - API 端点路径
110
110
  * @param data - 请求负载(可选)
111
111
  * @param headers - 要包含在请求中的额外请求头(可选)
@@ -114,40 +114,36 @@ class MiniProgramRequestStrategy extends BaseRequestStrategy {
114
114
  * @throws SystemError 如果是 5xx 服务器错误或微信 API 错误
115
115
  */
116
116
  async request(path, data, headers = {}) {
117
- const requestId = headers['X-Request-Id'] || 'unknown';
117
+ const requestId = headers['x-request-id'] || 'unknown';
118
118
  try {
119
119
  // 类型守卫,确保 wx 可用
120
- // 使用 any 类型避免类型定义冲突
121
120
  const wxGlobal = typeof wx !== 'undefined' ? wx : null;
122
- if (!wxGlobal || !wxGlobal.cloud) {
121
+ if (!wxGlobal || !wxGlobal.request) {
123
122
  if (console?.error) {
124
123
  console.error(`[SDK][${requestId}] 微信小程序环境不可用`);
125
124
  }
126
125
  throw new errors_1.SystemError('微信小程序环境不可用', 500);
127
126
  }
128
- // 构造包含微信特定字段的请求头
129
- const requestHeaders = {
130
- ...headers,
131
- 'X-WX-SERVICE': (0, env_1.getContainerService)(this.environment),
132
- };
127
+ // 构造完整的 URL
128
+ const url = `${(0, env_1.getContainerHost)(this.environment)}${path}`;
133
129
  if (console?.info) {
134
- console.info(`[SDK][${requestId}] 发起小程序云调用: ${path}`, `环境: ${(0, env_1.getContainerEnv)(this.environment)}`, data ? `参数: ${JSON.stringify(data)}` : '');
130
+ console.info(`[SDK][${requestId}] 发起小程序请求: ${url}`, data ? `参数: ${JSON.stringify(data)}` : '');
135
131
  }
136
- // 调用微信云托管容器
137
- const response = await wxGlobal.cloud.callContainer({
138
- config: {
139
- env: (0, env_1.getContainerEnv)(this.environment),
140
- },
141
- path,
142
- method: 'POST',
143
- header: requestHeaders,
144
- data,
145
- timeout: 100000, // 100 秒超时
132
+ // 使用 Promise 包装 wx.request
133
+ const response = await new Promise((resolve, reject) => {
134
+ wxGlobal.request({
135
+ url,
136
+ method: 'POST',
137
+ data,
138
+ header: {
139
+ 'content-type': 'application/json',
140
+ ...headers,
141
+ },
142
+ timeout: 60000, // 60 秒超时
143
+ success: (res) => resolve(res),
144
+ fail: (err) => reject(err),
145
+ });
146
146
  });
147
- // 记录微信云调用 ID
148
- if (console?.info && response.callID) {
149
- console.info(`[SDK][${requestId}] 微信云调用 ID: ${response.callID}`);
150
- }
151
147
  // 检查响应状态码是否表示成功
152
148
  if (response.statusCode >= 200 && response.statusCode < 300) {
153
149
  const responseData = response.data;
@@ -158,7 +154,7 @@ class MiniProgramRequestStrategy extends BaseRequestStrategy {
158
154
  // 非 2xx 状态码
159
155
  const errorMessage = response.data?.message || '请求失败';
160
156
  if (console?.error) {
161
- console.error(`[SDK][${requestId}] HTTP 错误: ${errorMessage}`, `状态码: ${response.statusCode}`, `微信云调用 ID: ${response.callID || 'unknown'}`, `响应数据: ${JSON.stringify(response.data)}`);
157
+ console.error(`[SDK][${requestId}] HTTP 错误: ${errorMessage}`, `状态码: ${response.statusCode}`, `响应数据: ${JSON.stringify(response.data)}`);
162
158
  }
163
159
  const ErrorClass = response.statusCode >= 400 && response.statusCode < 500 ? errors_1.BizError : errors_1.SystemError;
164
160
  throw new ErrorClass(errorMessage, response.statusCode);
@@ -186,3 +182,87 @@ class MiniProgramRequestStrategy extends BaseRequestStrategy {
186
182
  }
187
183
  }
188
184
  exports.MiniProgramRequestStrategy = MiniProgramRequestStrategy;
185
+ /* ============================================
186
+ * 旧版本:使用 wx.cloud.callContainer(已废弃)
187
+ * ============================================
188
+ *
189
+ * export class MiniProgramRequestStrategy extends BaseRequestStrategy {
190
+ * async request<T>(path: string, data?: any, headers: Record<string, string> = {}): Promise<T> {
191
+ * const requestId = headers['x-request-id'] || 'unknown'
192
+ *
193
+ * try {
194
+ * const wxGlobal = typeof wx !== 'undefined' ? (wx as any) : null
195
+ * if (!wxGlobal || !wxGlobal.cloud) {
196
+ * if (console?.error) {
197
+ * console.error(`[SDK][${requestId}] 微信小程序环境不可用`)
198
+ * }
199
+ * throw new SystemError('微信小程序环境不可用', 500)
200
+ * }
201
+ *
202
+ * const requestHeaders = {
203
+ * ...headers,
204
+ * 'X-WX-SERVICE': getContainerService(this.environment),
205
+ * }
206
+ *
207
+ * if (console?.info) {
208
+ * console.info(
209
+ * `[SDK][${requestId}] 发起小程序云调用: ${path}`,
210
+ * `环境: ${getContainerEnv(this.environment)}`,
211
+ * data ? `参数: ${JSON.stringify(data)}` : '',
212
+ * )
213
+ * }
214
+ *
215
+ * const response = await wxGlobal.cloud.callContainer({
216
+ * config: {
217
+ * env: getContainerEnv(this.environment),
218
+ * },
219
+ * path,
220
+ * method: 'POST',
221
+ * header: requestHeaders,
222
+ * data,
223
+ * timeout: 100000,
224
+ * })
225
+ *
226
+ * if (console?.info && response.callID) {
227
+ * console.info(`[SDK][${requestId}] 微信云调用 ID: ${response.callID}`)
228
+ * }
229
+ *
230
+ * if (response.statusCode >= 200 && response.statusCode < 300) {
231
+ * const responseData = response.data
232
+ * return responseData as T
233
+ * }
234
+ *
235
+ * const errorMessage = response.data?.message || '请求失败'
236
+ * if (console?.error) {
237
+ * console.error(
238
+ * `[SDK][${requestId}] HTTP 错误: ${errorMessage}`,
239
+ * `状态码: ${response.statusCode}`,
240
+ * `微信云调用 ID: ${response.callID || 'unknown'}`,
241
+ * `响应数据: ${JSON.stringify(response.data)}`,
242
+ * )
243
+ * }
244
+ * const ErrorClass =
245
+ * response.statusCode >= 400 && response.statusCode < 500 ? BizError : SystemError
246
+ * throw new ErrorClass(errorMessage, response.statusCode)
247
+ * } catch (error) {
248
+ * if (error instanceof SdkError) {
249
+ * throw error
250
+ * }
251
+ *
252
+ * if (error && typeof error === 'object' && 'errMsg' in error) {
253
+ * const errorMessage = (error as any).errMsg || '微信 API 调用失败'
254
+ * if (console?.error) {
255
+ * console.error(`[SDK][${requestId}] 微信 API 错误: ${errorMessage}`)
256
+ * }
257
+ * throw new SystemError(errorMessage, 500)
258
+ * }
259
+ *
260
+ * const errorMessage = error instanceof Error ? error.message : '发生未知错误'
261
+ * if (console?.error) {
262
+ * console.error(`[SDK][${requestId}] 未知错误: ${errorMessage}`)
263
+ * }
264
+ * throw new SystemError(errorMessage, 500)
265
+ * }
266
+ * }
267
+ * }
268
+ */
package/cjs/enums.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * 外部 SDK 枚举导出
3
3
  * 集中管理所有第三方服务 SDK 的枚举和常量
4
4
  */
5
- export { PRODUCT_SERVICE_ENUM } from '@be-link/ecommerce-product-service-node-sdk';
5
+ export { ENUM } from '@be-link/ecommerce-product-service-node-sdk/enum';
package/cjs/enums.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * 集中管理所有第三方服务 SDK 的枚举和常量
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.PRODUCT_SERVICE_ENUM = void 0;
7
+ exports.ENUM = void 0;
8
8
  // 商品服务枚举
9
- var ecommerce_product_service_node_sdk_1 = require("@be-link/ecommerce-product-service-node-sdk");
10
- Object.defineProperty(exports, "PRODUCT_SERVICE_ENUM", { enumerable: true, get: function () { return ecommerce_product_service_node_sdk_1.PRODUCT_SERVICE_ENUM; } });
9
+ var enum_1 = require("@be-link/ecommerce-product-service-node-sdk/enum");
10
+ Object.defineProperty(exports, "ENUM", { enumerable: true, get: function () { return enum_1.ENUM; } });
package/cjs/index.d.ts CHANGED
@@ -62,6 +62,6 @@ export { Service as MiniProgramDemoTypes } from './bff/modules/miniprogram/demo/
62
62
  export { Service as PandoraExampleTypes } from './bff/modules/pandora/example/types';
63
63
  export { Service as PandoraStoreTypes } from './bff/modules/pandora/store/types';
64
64
  export { Service as PandoraStoreSelectionTypes } from './bff/modules/pandora/storeSelection/types';
65
- export { ProductService as PandoraProductServiceTypes } from './bff/modules/pandora/product/types';
66
- export { ProductExpService as PandoraProductExpServiceTypes } from './bff/modules/pandora/productExp/types';
67
- export { ProductLiveService as PandoraProductLiveServiceTypes } from './bff/modules/pandora/productLive/types';
65
+ export { PandoraProductService as PandoraProductServiceTypes } from './bff/modules/pandora/product/types';
66
+ export { PandoraProductExpService as PandoraProductExpServiceTypes } from './bff/modules/pandora/productExp/types';
67
+ export { PandoraProductLiveService as PandoraProductLiveServiceTypes } from './bff/modules/pandora/productLive/types';
@@ -31,10 +31,39 @@ function generateUUID() {
31
31
  if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
32
32
  return crypto.randomUUID();
33
33
  }
34
- // 降级方案:使用 Math.random() 生成 UUID v4
35
- // 格式:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
36
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
37
- const r = (Math.random() * 16) | 0;
34
+ // 降级方案 1:使用 crypto.getRandomValues(浏览器和 Node.js)
35
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
36
+ const bytes = new Uint8Array(16);
37
+ crypto.getRandomValues(bytes);
38
+ // 设置 UUID v4 的版本位和变体位
39
+ bytes[6] = (bytes[6] & 0x0f) | 0x40; // 版本 4
40
+ bytes[8] = (bytes[8] & 0x3f) | 0x80; // 变体 10
41
+ // 转换为 UUID 字符串格式
42
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
43
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
44
+ }
45
+ // 降级方案 2:微信小程序环境(尝试使用 wx.getRandomValues)
46
+ if (typeof wx !== 'undefined' && typeof wx.getRandomValues === 'function') {
47
+ try {
48
+ const bytes = new Uint8Array(16);
49
+ wx.getRandomValues(bytes);
50
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
51
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
52
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
53
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
54
+ }
55
+ catch (e) {
56
+ // 如果失败,继续使用最后的降级方案
57
+ }
58
+ }
59
+ // 最后的降级方案:使用增强的 Math.random()
60
+ // 结合时间戳和计数器来减少碰撞概率
61
+ const timestamp = Date.now();
62
+ const counter = generateUUID._counter || 0;
63
+ generateUUID._counter = (counter + 1) % 10000;
64
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c, i) => {
65
+ // 混合时间戳、计数器和随机数
66
+ const r = ((Math.random() * 16) | 0) ^ ((timestamp >> (i * 2)) & 0xf) ^ (counter & 0xf);
38
67
  const v = c === 'x' ? r : (r & 0x3) | 0x8;
39
68
  return v.toString(16);
40
69
  });
@@ -1,4 +1,4 @@
1
- import { ProductService as Service } from './types';
1
+ import { PandoraProductService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductService {
2
+ export declare namespace PandoraProductService {
3
3
  /**
4
4
  * 核销期限接口
5
5
  */
@@ -202,46 +202,46 @@ export declare namespace ProductService {
202
202
  /**
203
203
  * 商品列表
204
204
  */
205
- list(request: ProductService.Request.list): Promise<StandardResponse<ProductService.Response.list>>;
205
+ list(request: PandoraProductService.Request.list): Promise<StandardResponse<PandoraProductService.Response.list>>;
206
206
  /**
207
207
  * 创建商品
208
208
  */
209
- create(request: ProductService.ProductData): Promise<StandardResponse<ProductService.Response.create>>;
209
+ create(request: PandoraProductService.ProductData): Promise<StandardResponse<PandoraProductService.Response.create>>;
210
210
  /**
211
211
  * 商品详情
212
212
  */
213
- detail(request: ProductService.Request.detail): Promise<StandardResponse<ProductService.ProductData>>;
213
+ detail(request: PandoraProductService.Request.detail): Promise<StandardResponse<PandoraProductService.ProductData>>;
214
214
  /**
215
215
  * 商品更新
216
216
  */
217
- update(request: ProductService.ProductData): Promise<StandardResponse<void>>;
217
+ update(request: PandoraProductService.ProductData): Promise<StandardResponse<void>>;
218
218
  /**
219
219
  * 批量更新
220
220
  */
221
- batchUpdate(request: ProductService.Request.batchUpdate): Promise<StandardResponse<void>>;
221
+ batchUpdate(request: PandoraProductService.Request.batchUpdate): Promise<StandardResponse<void>>;
222
222
  /**
223
223
  * 查询定时任务任务
224
224
  */
225
- queryScheduledTask(request: ProductService.Request.queryScheduledTask): Promise<StandardResponse<ProductService.Response.queryScheduledTask[]>>;
225
+ queryScheduledTask(request: PandoraProductService.Request.queryScheduledTask): Promise<StandardResponse<PandoraProductService.Response.queryScheduledTask[]>>;
226
226
  /**
227
227
  * 校验69码是否重复
228
228
  */
229
- checkSkuCode(request: ProductService.Request.checkSkuCode): Promise<StandardResponse<ProductService.Response.checkSkuCode>>;
229
+ checkSkuCode(request: PandoraProductService.Request.checkSkuCode): Promise<StandardResponse<PandoraProductService.Response.checkSkuCode>>;
230
230
  /**
231
231
  * 商品导出
232
232
  */
233
- export(request: ProductService.Request.list): Promise<StandardResponse<void>>;
233
+ export(request: PandoraProductService.Request.list): Promise<StandardResponse<void>>;
234
234
  /**
235
235
  * 获取商品信息(不含规格信息)
236
236
  */
237
- queryProductList(request: ProductService.Request.queryProductList): Promise<StandardResponse<ProductService.Response.queryProductList>>;
237
+ queryProductList(request: PandoraProductService.Request.queryProductList): Promise<StandardResponse<PandoraProductService.Response.queryProductList>>;
238
238
  /**
239
239
  * 获取商品+规格信息
240
240
  */
241
- queryProductSkuList(request: ProductService.Request.queryProductList): Promise<StandardResponse<ProductService.Response.queryProductSkuList>>;
241
+ queryProductSkuList(request: PandoraProductService.Request.queryProductList): Promise<StandardResponse<PandoraProductService.Response.queryProductSkuList>>;
242
242
  /**
243
243
  * 商品二维码
244
244
  */
245
- productQrCode(request: ProductService.Request.productQrCode): Promise<StandardResponse<ProductService.Response.productQrCode>>;
245
+ productQrCode(request: PandoraProductService.Request.productQrCode): Promise<StandardResponse<PandoraProductService.Response.productQrCode>>;
246
246
  }
247
247
  }
@@ -1,4 +1,4 @@
1
- import { ProductExpService as Service } from './types';
1
+ import { PandoraProductExpService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductExpService {
2
+ export declare namespace PandoraProductExpService {
3
3
  interface ProductCategory {
4
4
  id: string;
5
5
  parentId: string;
@@ -56,26 +56,26 @@ export declare namespace ProductExpService {
56
56
  /**
57
57
  * 获取供应商列表
58
58
  */
59
- getSupplierList(): Promise<StandardResponse<ProductExpService.Response.getSupplierList[]>>;
59
+ getSupplierList(): Promise<StandardResponse<PandoraProductExpService.Response.getSupplierList[]>>;
60
60
  /**
61
61
  * 新增供应商
62
62
  */
63
- addSupplier(request: ProductExpService.Request.addSupplier): Promise<StandardResponse<ProductExpService.Response.addSupplier>>;
63
+ addSupplier(request: PandoraProductExpService.Request.addSupplier): Promise<StandardResponse<PandoraProductExpService.Response.addSupplier>>;
64
64
  /**
65
65
  * 获取直播分组列表
66
66
  */
67
- getLiveGroupList(): Promise<StandardResponse<ProductExpService.Response.getLiveGroupList[]>>;
67
+ getLiveGroupList(): Promise<StandardResponse<PandoraProductExpService.Response.getLiveGroupList[]>>;
68
68
  /**
69
69
  * 新增直播分组
70
70
  */
71
- addLiveGroup(request: ProductExpService.Request.addLiveGroup): Promise<StandardResponse<ProductExpService.Response.addLiveGroup>>;
71
+ addLiveGroup(request: PandoraProductExpService.Request.addLiveGroup): Promise<StandardResponse<PandoraProductExpService.Response.addLiveGroup>>;
72
72
  /**
73
73
  * 商品分类 树结构
74
74
  */
75
- productCategoryTree(): Promise<StandardResponse<ProductExpService.Response.ProductCategoryTree>>;
75
+ productCategoryTree(): Promise<StandardResponse<PandoraProductExpService.Response.ProductCategoryTree>>;
76
76
  /**
77
77
  * 获取产品经理列表
78
78
  */
79
- getProductManagerList(): Promise<StandardResponse<ProductExpService.Response.getProductManagerList>>;
79
+ getProductManagerList(): Promise<StandardResponse<PandoraProductExpService.Response.getProductManagerList>>;
80
80
  }
81
81
  }
@@ -1,4 +1,4 @@
1
- import { ProductLiveService as Service } from './types';
1
+ import { PandoraProductLiveService as Service } from './types';
2
2
  import BaseService from '../../BaseService';
3
3
  import type { StandardResponse } from '../../../../types';
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { StandardResponse } from '../../../../types';
2
- export declare namespace ProductLiveService {
2
+ export declare namespace PandoraProductLiveService {
3
3
  namespace Request {
4
4
  interface list {
5
5
  pageIndex: number;
@@ -30,14 +30,14 @@ export declare namespace ProductLiveService {
30
30
  /**
31
31
  * 商品列表
32
32
  */
33
- list(request: ProductLiveService.Request.list): Promise<StandardResponse<ProductLiveService.Response.list>>;
33
+ list(request: PandoraProductLiveService.Request.list): Promise<StandardResponse<PandoraProductLiveService.Response.list>>;
34
34
  /**
35
35
  * 新增商品
36
36
  */
37
- add(request: ProductLiveService.Request.operate): Promise<StandardResponse<void>>;
37
+ add(request: PandoraProductLiveService.Request.operate): Promise<StandardResponse<void>>;
38
38
  /**
39
39
  * 删除商品
40
40
  */
41
- remove(request: ProductLiveService.Request.operate): Promise<StandardResponse<void>>;
41
+ remove(request: PandoraProductLiveService.Request.operate): Promise<StandardResponse<void>>;
42
42
  }
43
43
  }
@@ -45,7 +45,7 @@ export class HttpClient {
45
45
  // 构造标准请求头
46
46
  const standardHeaders = {
47
47
  'Content-Type': 'application/json',
48
- 'X-Request-Id': requestId,
48
+ 'x-request-id': requestId,
49
49
  'x-belink-authorization': token,
50
50
  'x-belink-pandora-userid': userId,
51
51
  'x-belink-pandora-roleid': roleId,
@@ -34,12 +34,12 @@ export declare class WebRequestStrategy extends BaseRequestStrategy {
34
34
  request<T>(path: string, data?: any, headers?: Record<string, string>): Promise<T>;
35
35
  }
36
36
  /**
37
- * 微信小程序请求策略,使用 wx.cloud.callContainer
37
+ * 微信小程序请求策略,使用 wx.request
38
38
  * 为微信小程序环境实现请求策略
39
39
  */
40
40
  export declare class MiniProgramRequestStrategy extends BaseRequestStrategy {
41
41
  /**
42
- * 使用微信云托管容器 API 执行请求
42
+ * 使用 wx.request 执行 HTTP 请求
43
43
  * @param path - API 端点路径
44
44
  * @param data - 请求负载(可选)
45
45
  * @param headers - 要包含在请求中的额外请求头(可选)
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { SdkError, BizError, SystemError } from '../../errors/index.mjs';
3
- import { getContainerHost, getContainerEnv, getContainerService } from '../../utils/env.mjs';
3
+ import { getContainerHost } from '../../utils/env.mjs';
4
4
  /**
5
5
  * 请求策略的抽象基类
6
6
  * 定义所有请求策略的公共契约和共享实现
@@ -29,7 +29,7 @@ export class WebRequestStrategy extends BaseRequestStrategy {
29
29
  * @throws SystemError 如果是 5xx 服务器错误或网络错误
30
30
  */
31
31
  async request(path, data, headers = {}) {
32
- const requestId = headers['X-Request-Id'] || 'unknown';
32
+ const requestId = headers['x-request-id'] || 'unknown';
33
33
  const url = `${getContainerHost(this.environment)}${path}`;
34
34
  try {
35
35
  if (console?.info) {
@@ -92,12 +92,12 @@ export class WebRequestStrategy extends BaseRequestStrategy {
92
92
  }
93
93
  }
94
94
  /**
95
- * 微信小程序请求策略,使用 wx.cloud.callContainer
95
+ * 微信小程序请求策略,使用 wx.request
96
96
  * 为微信小程序环境实现请求策略
97
97
  */
98
98
  export class MiniProgramRequestStrategy extends BaseRequestStrategy {
99
99
  /**
100
- * 使用微信云托管容器 API 执行请求
100
+ * 使用 wx.request 执行 HTTP 请求
101
101
  * @param path - API 端点路径
102
102
  * @param data - 请求负载(可选)
103
103
  * @param headers - 要包含在请求中的额外请求头(可选)
@@ -106,40 +106,36 @@ export class MiniProgramRequestStrategy extends BaseRequestStrategy {
106
106
  * @throws SystemError 如果是 5xx 服务器错误或微信 API 错误
107
107
  */
108
108
  async request(path, data, headers = {}) {
109
- const requestId = headers['X-Request-Id'] || 'unknown';
109
+ const requestId = headers['x-request-id'] || 'unknown';
110
110
  try {
111
111
  // 类型守卫,确保 wx 可用
112
- // 使用 any 类型避免类型定义冲突
113
112
  const wxGlobal = typeof wx !== 'undefined' ? wx : null;
114
- if (!wxGlobal || !wxGlobal.cloud) {
113
+ if (!wxGlobal || !wxGlobal.request) {
115
114
  if (console?.error) {
116
115
  console.error(`[SDK][${requestId}] 微信小程序环境不可用`);
117
116
  }
118
117
  throw new SystemError('微信小程序环境不可用', 500);
119
118
  }
120
- // 构造包含微信特定字段的请求头
121
- const requestHeaders = {
122
- ...headers,
123
- 'X-WX-SERVICE': getContainerService(this.environment),
124
- };
119
+ // 构造完整的 URL
120
+ const url = `${getContainerHost(this.environment)}${path}`;
125
121
  if (console?.info) {
126
- console.info(`[SDK][${requestId}] 发起小程序云调用: ${path}`, `环境: ${getContainerEnv(this.environment)}`, data ? `参数: ${JSON.stringify(data)}` : '');
122
+ console.info(`[SDK][${requestId}] 发起小程序请求: ${url}`, data ? `参数: ${JSON.stringify(data)}` : '');
127
123
  }
128
- // 调用微信云托管容器
129
- const response = await wxGlobal.cloud.callContainer({
130
- config: {
131
- env: getContainerEnv(this.environment),
132
- },
133
- path,
134
- method: 'POST',
135
- header: requestHeaders,
136
- data,
137
- timeout: 100000, // 100 秒超时
124
+ // 使用 Promise 包装 wx.request
125
+ const response = await new Promise((resolve, reject) => {
126
+ wxGlobal.request({
127
+ url,
128
+ method: 'POST',
129
+ data,
130
+ header: {
131
+ 'content-type': 'application/json',
132
+ ...headers,
133
+ },
134
+ timeout: 60000, // 60 秒超时
135
+ success: (res) => resolve(res),
136
+ fail: (err) => reject(err),
137
+ });
138
138
  });
139
- // 记录微信云调用 ID
140
- if (console?.info && response.callID) {
141
- console.info(`[SDK][${requestId}] 微信云调用 ID: ${response.callID}`);
142
- }
143
139
  // 检查响应状态码是否表示成功
144
140
  if (response.statusCode >= 200 && response.statusCode < 300) {
145
141
  const responseData = response.data;
@@ -150,7 +146,7 @@ export class MiniProgramRequestStrategy extends BaseRequestStrategy {
150
146
  // 非 2xx 状态码
151
147
  const errorMessage = response.data?.message || '请求失败';
152
148
  if (console?.error) {
153
- console.error(`[SDK][${requestId}] HTTP 错误: ${errorMessage}`, `状态码: ${response.statusCode}`, `微信云调用 ID: ${response.callID || 'unknown'}`, `响应数据: ${JSON.stringify(response.data)}`);
149
+ console.error(`[SDK][${requestId}] HTTP 错误: ${errorMessage}`, `状态码: ${response.statusCode}`, `响应数据: ${JSON.stringify(response.data)}`);
154
150
  }
155
151
  const ErrorClass = response.statusCode >= 400 && response.statusCode < 500 ? BizError : SystemError;
156
152
  throw new ErrorClass(errorMessage, response.statusCode);
@@ -177,3 +173,87 @@ export class MiniProgramRequestStrategy extends BaseRequestStrategy {
177
173
  }
178
174
  }
179
175
  }
176
+ /* ============================================
177
+ * 旧版本:使用 wx.cloud.callContainer(已废弃)
178
+ * ============================================
179
+ *
180
+ * export class MiniProgramRequestStrategy extends BaseRequestStrategy {
181
+ * async request<T>(path: string, data?: any, headers: Record<string, string> = {}): Promise<T> {
182
+ * const requestId = headers['x-request-id'] || 'unknown'
183
+ *
184
+ * try {
185
+ * const wxGlobal = typeof wx !== 'undefined' ? (wx as any) : null
186
+ * if (!wxGlobal || !wxGlobal.cloud) {
187
+ * if (console?.error) {
188
+ * console.error(`[SDK][${requestId}] 微信小程序环境不可用`)
189
+ * }
190
+ * throw new SystemError('微信小程序环境不可用', 500)
191
+ * }
192
+ *
193
+ * const requestHeaders = {
194
+ * ...headers,
195
+ * 'X-WX-SERVICE': getContainerService(this.environment),
196
+ * }
197
+ *
198
+ * if (console?.info) {
199
+ * console.info(
200
+ * `[SDK][${requestId}] 发起小程序云调用: ${path}`,
201
+ * `环境: ${getContainerEnv(this.environment)}`,
202
+ * data ? `参数: ${JSON.stringify(data)}` : '',
203
+ * )
204
+ * }
205
+ *
206
+ * const response = await wxGlobal.cloud.callContainer({
207
+ * config: {
208
+ * env: getContainerEnv(this.environment),
209
+ * },
210
+ * path,
211
+ * method: 'POST',
212
+ * header: requestHeaders,
213
+ * data,
214
+ * timeout: 100000,
215
+ * })
216
+ *
217
+ * if (console?.info && response.callID) {
218
+ * console.info(`[SDK][${requestId}] 微信云调用 ID: ${response.callID}`)
219
+ * }
220
+ *
221
+ * if (response.statusCode >= 200 && response.statusCode < 300) {
222
+ * const responseData = response.data
223
+ * return responseData as T
224
+ * }
225
+ *
226
+ * const errorMessage = response.data?.message || '请求失败'
227
+ * if (console?.error) {
228
+ * console.error(
229
+ * `[SDK][${requestId}] HTTP 错误: ${errorMessage}`,
230
+ * `状态码: ${response.statusCode}`,
231
+ * `微信云调用 ID: ${response.callID || 'unknown'}`,
232
+ * `响应数据: ${JSON.stringify(response.data)}`,
233
+ * )
234
+ * }
235
+ * const ErrorClass =
236
+ * response.statusCode >= 400 && response.statusCode < 500 ? BizError : SystemError
237
+ * throw new ErrorClass(errorMessage, response.statusCode)
238
+ * } catch (error) {
239
+ * if (error instanceof SdkError) {
240
+ * throw error
241
+ * }
242
+ *
243
+ * if (error && typeof error === 'object' && 'errMsg' in error) {
244
+ * const errorMessage = (error as any).errMsg || '微信 API 调用失败'
245
+ * if (console?.error) {
246
+ * console.error(`[SDK][${requestId}] 微信 API 错误: ${errorMessage}`)
247
+ * }
248
+ * throw new SystemError(errorMessage, 500)
249
+ * }
250
+ *
251
+ * const errorMessage = error instanceof Error ? error.message : '发生未知错误'
252
+ * if (console?.error) {
253
+ * console.error(`[SDK][${requestId}] 未知错误: ${errorMessage}`)
254
+ * }
255
+ * throw new SystemError(errorMessage, 500)
256
+ * }
257
+ * }
258
+ * }
259
+ */
package/esm/enums.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * 外部 SDK 枚举导出
3
3
  * 集中管理所有第三方服务 SDK 的枚举和常量
4
4
  */
5
- export { PRODUCT_SERVICE_ENUM } from '@be-link/ecommerce-product-service-node-sdk';
5
+ export { ENUM } from '@be-link/ecommerce-product-service-node-sdk/enum';
package/esm/enums.mjs CHANGED
@@ -3,4 +3,4 @@
3
3
  * 集中管理所有第三方服务 SDK 的枚举和常量
4
4
  */
5
5
  // 商品服务枚举
6
- export { PRODUCT_SERVICE_ENUM } from '@be-link/ecommerce-product-service-node-sdk';
6
+ export { ENUM } from '@be-link/ecommerce-product-service-node-sdk/enum';
package/esm/index.d.ts CHANGED
@@ -62,6 +62,6 @@ export { Service as MiniProgramDemoTypes } from './bff/modules/miniprogram/demo/
62
62
  export { Service as PandoraExampleTypes } from './bff/modules/pandora/example/types';
63
63
  export { Service as PandoraStoreTypes } from './bff/modules/pandora/store/types';
64
64
  export { Service as PandoraStoreSelectionTypes } from './bff/modules/pandora/storeSelection/types';
65
- export { ProductService as PandoraProductServiceTypes } from './bff/modules/pandora/product/types';
66
- export { ProductExpService as PandoraProductExpServiceTypes } from './bff/modules/pandora/productExp/types';
67
- export { ProductLiveService as PandoraProductLiveServiceTypes } from './bff/modules/pandora/productLive/types';
65
+ export { PandoraProductService as PandoraProductServiceTypes } from './bff/modules/pandora/product/types';
66
+ export { PandoraProductExpService as PandoraProductExpServiceTypes } from './bff/modules/pandora/productExp/types';
67
+ export { PandoraProductLiveService as PandoraProductLiveServiceTypes } from './bff/modules/pandora/productLive/types';
@@ -27,10 +27,39 @@ export function generateUUID() {
27
27
  if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
28
28
  return crypto.randomUUID();
29
29
  }
30
- // 降级方案:使用 Math.random() 生成 UUID v4
31
- // 格式:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
32
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
33
- const r = (Math.random() * 16) | 0;
30
+ // 降级方案 1:使用 crypto.getRandomValues(浏览器和 Node.js)
31
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
32
+ const bytes = new Uint8Array(16);
33
+ crypto.getRandomValues(bytes);
34
+ // 设置 UUID v4 的版本位和变体位
35
+ bytes[6] = (bytes[6] & 0x0f) | 0x40; // 版本 4
36
+ bytes[8] = (bytes[8] & 0x3f) | 0x80; // 变体 10
37
+ // 转换为 UUID 字符串格式
38
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
39
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
40
+ }
41
+ // 降级方案 2:微信小程序环境(尝试使用 wx.getRandomValues)
42
+ if (typeof wx !== 'undefined' && typeof wx.getRandomValues === 'function') {
43
+ try {
44
+ const bytes = new Uint8Array(16);
45
+ wx.getRandomValues(bytes);
46
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
47
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
48
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
49
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
50
+ }
51
+ catch (e) {
52
+ // 如果失败,继续使用最后的降级方案
53
+ }
54
+ }
55
+ // 最后的降级方案:使用增强的 Math.random()
56
+ // 结合时间戳和计数器来减少碰撞概率
57
+ const timestamp = Date.now();
58
+ const counter = generateUUID._counter || 0;
59
+ generateUUID._counter = (counter + 1) % 10000;
60
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c, i) => {
61
+ // 混合时间戳、计数器和随机数
62
+ const r = ((Math.random() * 16) | 0) ^ ((timestamp >> (i * 2)) & 0xf) ^ (counter & 0xf);
34
63
  const v = c === 'x' ? r : (r & 0x3) | 0x8;
35
64
  return v.toString(16);
36
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/ecommerce-backend-bff-service-node-sdk",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "EcommerceBackendBffService Node.js SDK",
5
5
  "type": "commonjs",
6
6
  "main": "./cjs/index.js",
@@ -24,7 +24,8 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "1.13.2"
27
+ "axios": "1.13.2",
28
+ "@be-link/ecommerce-product-service-node-sdk": "^0.0.2"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/node": "^20.0.0",