@be-link/ecommerce-backend-bff-service-node-sdk 0.0.10 → 0.0.12

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.
Files changed (31) hide show
  1. package/README.md +79 -2
  2. package/cjs/bff/modules/BaseService.d.ts +1 -1
  3. package/cjs/bff/modules/miniprogram/demo/service.d.ts +16 -0
  4. package/cjs/bff/modules/{demo → miniprogram/demo}/service.js +6 -10
  5. package/cjs/bff/modules/pandora/example/service.d.ts +29 -0
  6. package/cjs/bff/modules/pandora/example/service.js +43 -0
  7. package/cjs/index.d.ts +29 -38
  8. package/cjs/index.js +33 -42
  9. package/esm/bff/modules/BaseService.d.ts +1 -1
  10. package/esm/bff/modules/miniprogram/demo/service.d.ts +16 -0
  11. package/esm/bff/modules/miniprogram/demo/service.mjs +19 -0
  12. package/esm/bff/modules/pandora/example/service.d.ts +29 -0
  13. package/esm/bff/modules/pandora/example/service.mjs +36 -0
  14. package/esm/index.d.ts +29 -38
  15. package/esm/index.mjs +28 -35
  16. package/package.json +2 -1
  17. package/cjs/bff/modules/demo/service.d.ts +0 -22
  18. package/cjs/bff/modules/example/service.d.ts +0 -46
  19. package/cjs/bff/modules/example/service.js +0 -60
  20. package/esm/bff/modules/demo/service.d.ts +0 -22
  21. package/esm/bff/modules/demo/service.mjs +0 -25
  22. package/esm/bff/modules/example/service.d.ts +0 -46
  23. package/esm/bff/modules/example/service.mjs +0 -53
  24. /package/cjs/bff/modules/{demo → miniprogram/demo}/types.d.ts +0 -0
  25. /package/cjs/bff/modules/{demo → miniprogram/demo}/types.js +0 -0
  26. /package/cjs/bff/modules/{example → pandora/example}/types.d.ts +0 -0
  27. /package/cjs/bff/modules/{example → pandora/example}/types.js +0 -0
  28. /package/esm/bff/modules/{demo → miniprogram/demo}/types.d.ts +0 -0
  29. /package/esm/bff/modules/{demo → miniprogram/demo}/types.mjs +0 -0
  30. /package/esm/bff/modules/{example → pandora/example}/types.d.ts +0 -0
  31. /package/esm/bff/modules/{example → pandora/example}/types.mjs +0 -0
package/README.md CHANGED
@@ -1,11 +1,33 @@
1
+ ## 开发
2
+
3
+ ### 添加新服务
4
+
5
+ 1. **创建 types.ts 文件**
6
+ ```bash
7
+ # 在对应平台和模块目录下创建 types.ts
8
+ # 例如:src/bff/modules/miniprogram/product/types.ts
9
+ ```
10
+
11
+ 2. **生成服务代码**
12
+ ```bash
13
+ # ⚠️ 必须在 packages/sdk 目录下运行
14
+ cd packages/sdk
15
+ npm run generate miniprogram/product
16
+ ```
17
+
18
+
19
+
1
20
  # EcommerceBackendBffService SDK
2
21
 
3
- EcommerceBackendBffService Node.js SDK - 统一平台 SDK,支持 Web/H5 和微信小程序
22
+ EcommerceBackendBffService Node.js SDK - 按平台分离的 SDK,支持 Pandora 管理后台和微信小程序
4
23
 
5
24
  ## 特性
6
25
 
26
+ - ✅ **平台分离架构**:PandoraSDK 和 MiniProgramSDK 独立,避免命名冲突
7
27
  - ✅ **统一命名空间结构**:与后端 SDK 保持一致的类型定义
8
28
  - ✅ **自动生成 Swagger 文档**:使用 tsoa 自动生成 OpenAPI 3.0 文档
29
+ - ✅ **双模块格式支持**:同时支持 ESM 和 CommonJS,兼容 Vite、Webpack 等现代构建工具
30
+ - ✅ **编译时装饰器移除**:使用 TypeScript transformer 在编译时移除 tsoa 装饰器,前端零依赖
9
31
  - ✅ **多平台支持**:自动检测并适配 Web/H5 和微信小程序环境
10
32
  - ✅ **类型安全**:完整的 TypeScript 类型定义
11
33
  - ✅ **标准响应格式**:统一的 `StandardResponse<T>` 响应结构
@@ -18,11 +40,46 @@ npm install @be-link/ecommerce-backend-bff-service-node-sdk
18
40
 
19
41
  ## 使用
20
42
 
21
- ### Web/H5 环境
43
+ > 💡 **重要变更**:SDK 现在按平台分离,请使用 `PandoraSDK` 或 `MiniProgramSDK`。详见 [平台 SDK 指南](./PLATFORM_SDK_GUIDE.md)
44
+
45
+ ### Pandora 管理后台
46
+
47
+ ```typescript
48
+ import { PandoraSDK } from '@be-link/ecommerce-backend-bff-service-node-sdk'
49
+
50
+ const sdk = new PandoraSDK({
51
+ getToken: async () => localStorage.getItem('token') || '',
52
+ getUserId: async () => localStorage.getItem('userId') || '',
53
+ getRoleId: async () => localStorage.getItem('roleId') || '',
54
+ environment: 'production'
55
+ })
56
+
57
+ // 使用 Pandora 服务
58
+ const result = await sdk.example.getExampleData({ id: '123' })
59
+ ```
60
+
61
+ ### 微信小程序
62
+
63
+ ```typescript
64
+ import { MiniProgramSDK } from '@be-link/ecommerce-backend-bff-service-node-sdk'
65
+
66
+ const sdk = new MiniProgramSDK({
67
+ getToken: async () => wx.getStorageSync('token') || '',
68
+ getUserId: async () => wx.getStorageSync('userId') || '',
69
+ getRoleId: async () => wx.getStorageSync('roleId') || '',
70
+ environment: 'production'
71
+ })
72
+
73
+ // 使用小程序服务
74
+ const result = await sdk.demo.getDemoData({ page: 1 })
75
+ ```
76
+
77
+ ### 旧版本兼容(不推荐)
22
78
 
23
79
  ```typescript
24
80
  import { EcommerceBackendBffSDK } from '@be-link/ecommerce-backend-bff-service-node-sdk'
25
81
 
82
+ // ⚠️ 已废弃,请迁移到 PandoraSDK 或 MiniProgramSDK
26
83
  const sdk = new EcommerceBackendBffSDK({
27
84
  getToken: async () => localStorage.getItem('token') || '',
28
85
  getUserId: async () => localStorage.getItem('userId') || '',
@@ -71,6 +128,23 @@ type UserProfile = ExampleServiceTypes.Response.getUserProfile
71
128
 
72
129
  ## 开发
73
130
 
131
+ ### 添加新服务
132
+
133
+ 1. **创建 types.ts 文件**
134
+ ```bash
135
+ # 在对应平台和模块目录下创建 types.ts
136
+ # 例如:src/bff/modules/miniprogram/product/types.ts
137
+ ```
138
+
139
+ 2. **生成服务代码**
140
+ ```bash
141
+ # ⚠️ 必须在 packages/sdk 目录下运行
142
+ cd packages/sdk
143
+ npm run generate miniprogram/product
144
+ ```
145
+
146
+ ### 其他命令
147
+
74
148
  ```bash
75
149
  # 构建
76
150
  npm run build
@@ -85,6 +159,8 @@ npm run build:swagger
85
159
  npm test
86
160
  ```
87
161
 
162
+ 详细的生成器使用说明请查看:[Generator README](./scripts/generator/README.md)
163
+
88
164
  ## 文档
89
165
 
90
166
  - [目录结构说明](./DIRECTORY_STRUCTURE.md) - 项目目录结构和组织方式
@@ -92,6 +168,7 @@ npm test
92
168
  - [Swagger 文档](./SWAGGER.md) - API 文档生成和使用指南
93
169
  - [类型兼容性](./TYPES_COMPATIBILITY.md) - 类型定义和兼容性说明
94
170
  - [SDK vs Server](./SDK_VS_SERVER.md) - SDK 和 Server 的区别
171
+ - [TSOA Transformer](./TSOA_TRANSFORMER.md) - TypeScript 装饰器移除机制说明
95
172
 
96
173
  ## API 文档
97
174
 
@@ -6,7 +6,7 @@ import { HttpClient } from '../request/client';
6
6
  */
7
7
  export default abstract class BaseService {
8
8
  /**
9
- * 服务的 URL 前缀路径(例如 '/api/v1/user')
9
+ * 服务的 URL 前缀路径(例如 '/miniprogram/user' 或 '/pandora/user')
10
10
  * 必须由子类定义
11
11
  */
12
12
  protected abstract prefixUrl: string;
@@ -0,0 +1,16 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../../BaseService';
3
+ import type { StandardResponse } from '../../../../types';
4
+ /**
5
+ * DemoService - Demo 服务模块
6
+ * 提供 Demo 相关的 API 方法
7
+ */
8
+ export declare class MiniProgramDemoService extends BaseService {
9
+ protected prefixUrl: string;
10
+ /**
11
+ * 示例接口
12
+ * @param request - 请求参数
13
+ * @returns Promise,解析为标准响应格式
14
+ */
15
+ demoFunc(request: Service.Request.demoFunc): Promise<StandardResponse<Service.Response.demoFunc>>;
16
+ }
@@ -3,28 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const BaseService_1 = __importDefault(require("../BaseService"));
6
+ exports.MiniProgramDemoService = void 0;
7
+ const BaseService_1 = __importDefault(require("../../BaseService"));
7
8
  /**
8
9
  * DemoService - Demo 服务模块
9
10
  * 提供 Demo 相关的 API 方法
10
11
  */
11
- class DemoService extends BaseService_1.default {
12
+ class MiniProgramDemoService extends BaseService_1.default {
12
13
  constructor() {
13
14
  super(...arguments);
14
- this.prefixUrl = '/demo';
15
+ this.prefixUrl = '/miniprogram/demo';
15
16
  }
16
17
  /**
17
- * Demo 方法
18
+ * 示例接口
18
19
  * @param request - 请求参数
19
20
  * @returns Promise,解析为标准响应格式
20
- * @example
21
- * const result = await sdk.demo.demoFunc({ demoParam: 'test' })
22
- * console.log(result.data) // 业务数据
23
- * console.log(result.message) // 响应消息
24
- * console.log(result.requestId) // 请求 ID
25
21
  */
26
22
  demoFunc(request) {
27
23
  return this.request(this.demoFunc, request);
28
24
  }
29
25
  }
30
- exports.default = DemoService;
26
+ exports.MiniProgramDemoService = MiniProgramDemoService;
@@ -0,0 +1,29 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../../BaseService';
3
+ import type { StandardResponse } from '../../../../types';
4
+ /**
5
+ * PandoraExampleService - Pandora Example 服务模块
6
+ * 提供 Pandora Example 相关的 API 方法
7
+ * 平台: pandora
8
+ */
9
+ export declare class PandoraExampleService extends BaseService {
10
+ protected prefixUrl: string;
11
+ /**
12
+ * 获取用户资料
13
+ * @param request - 请求参数
14
+ * @returns Promise,解析为标准响应格式
15
+ */
16
+ getUserProfile(request: Service.Request.getUserProfile): Promise<StandardResponse<Service.Response.getUserProfile>>;
17
+ /**
18
+ * 更新用户资料
19
+ * @param request - 请求参数
20
+ * @returns Promise,解析为标准响应格式
21
+ */
22
+ updateProfile(request: Service.Request.updateProfile): Promise<StandardResponse<Service.Response.updateProfile>>;
23
+ /**
24
+ * 获取订单列表
25
+ * @param request - 请求参数
26
+ * @returns Promise,解析为标准响应格式
27
+ */
28
+ getOrderList(request: Service.Request.getOrderList): Promise<StandardResponse<Service.Response.getOrderList>>;
29
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PandoraExampleService = void 0;
7
+ const BaseService_1 = __importDefault(require("../../BaseService"));
8
+ /**
9
+ * PandoraExampleService - Pandora Example 服务模块
10
+ * 提供 Pandora Example 相关的 API 方法
11
+ * 平台: pandora
12
+ */
13
+ class PandoraExampleService extends BaseService_1.default {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.prefixUrl = '/pandora/example';
17
+ }
18
+ /**
19
+ * 获取用户资料
20
+ * @param request - 请求参数
21
+ * @returns Promise,解析为标准响应格式
22
+ */
23
+ getUserProfile(request) {
24
+ return this.request(this.getUserProfile, request);
25
+ }
26
+ /**
27
+ * 更新用户资料
28
+ * @param request - 请求参数
29
+ * @returns Promise,解析为标准响应格式
30
+ */
31
+ updateProfile(request) {
32
+ return this.request(this.updateProfile, request);
33
+ }
34
+ /**
35
+ * 获取订单列表
36
+ * @param request - 请求参数
37
+ * @returns Promise,解析为标准响应格式
38
+ */
39
+ getOrderList(request) {
40
+ return this.request(this.getOrderList, request);
41
+ }
42
+ }
43
+ exports.PandoraExampleService = PandoraExampleService;
package/cjs/index.d.ts CHANGED
@@ -1,56 +1,47 @@
1
- import { ExampleService } from './bff/modules/example/service';
2
- import DemoService from './bff/modules/demo/service';
1
+ import { PandoraExampleService } from './bff/modules/pandora/example/service';
2
+ import { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service';
3
3
  import type { SdkOptions } from './types';
4
4
  /**
5
- * EcommerceBackendBffSDK - 统一平台 SDK 的主入口
6
- * 支持 Web/H5 和微信小程序环境
7
- *
8
- * @example
9
- * ```typescript
10
- * // Web/H5 环境 - 生产环境
11
- * const sdk = new EcommerceBackendBffSDK({
12
- * getToken: async () => localStorage.getItem('token') || '',
13
- * getUserId: async () => localStorage.getItem('userId') || '',
14
- * getRoleId: async () => localStorage.getItem('roleId') || '',
15
- * environment: 'production'
16
- * })
17
- *
18
- * // 小程序环境 - 测试环境
19
- * const sdk = new EcommerceBackendBffSDK({
20
- * getToken: async () => wx.getStorageSync('token') || '',
21
- * getUserId: async () => wx.getStorageSync('userId') || '',
22
- * getRoleId: async () => wx.getStorageSync('roleId') || '',
23
- * environment: 'test'
24
- * })
25
- *
26
- * // 使用服务模块
27
- * const profile = await sdk.example.getUserProfile('user123')
28
- * const demoResult = await sdk.demo.demoFunc({ demoParam: 'test' })
29
- * ```
5
+ * Pandora 平台 SDK(管理后台)
6
+ * 包含所有 Pandora 平台相关的服务
30
7
  */
31
- export declare class EcommerceBackendBffSDK {
8
+ export declare class PandoraSDK {
32
9
  /**
33
10
  * HttpClient 实例,管理平台特定的请求策略
34
11
  */
35
12
  private http;
36
13
  /**
37
- * 示例服务模块,演示 SDK 使用模式
14
+ * Pandora 示例服务模块
38
15
  */
39
- example: ExampleService;
16
+ example: PandoraExampleService;
40
17
  /**
41
- * Demo 服务模块(从旧版 config 服务迁移而来)
18
+ * 使用配置选项初始化 Pandora SDK
19
+ * @param options - SDK 配置,包含凭证回调函数
20
+ */
21
+ constructor(options: SdkOptions);
22
+ }
23
+ /**
24
+ * 小程序平台 SDK
25
+ * 包含所有小程序平台相关的服务
26
+ */
27
+ export declare class MiniProgramSDK {
28
+ /**
29
+ * HttpClient 实例,管理平台特定的请求策略
30
+ */
31
+ private http;
32
+ /**
33
+ * 小程序 Demo 服务模块
42
34
  */
43
- demo: DemoService;
35
+ demo: MiniProgramDemoService;
44
36
  /**
45
- * 使用配置选项初始化 SDK
37
+ * 使用配置选项初始化小程序 SDK
46
38
  * @param options - SDK 配置,包含凭证回调函数
47
39
  */
48
40
  constructor(options: SdkOptions);
49
41
  }
50
- export { default as DemoService } from './bff/modules/demo/service';
51
- export { ExampleService } from './bff/modules/example/service';
52
- export type { Service as DemoControllerTypes } from './bff/modules/demo/types';
53
- export type { Service as EcommerceBackendBffServiceControllerTypes } from './bff/modules/demo/types';
54
- export type { Service as ExampleServiceTypes } from './bff/modules/example/types';
55
42
  export { SdkError, BizError, SystemError } from './errors';
56
43
  export type { SdkOptions, IRequestStrategy, StandardResponse } from './types';
44
+ export { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service';
45
+ export { PandoraExampleService } from './bff/modules/pandora/example/service';
46
+ export type { Service as MiniProgramDemoTypes } from './bff/modules/miniprogram/demo/types';
47
+ export type { Service as PandoraExampleTypes } from './bff/modules/pandora/example/types';
package/cjs/index.js CHANGED
@@ -1,60 +1,51 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SystemError = exports.BizError = exports.SdkError = exports.ExampleService = exports.DemoService = exports.EcommerceBackendBffSDK = void 0;
3
+ exports.PandoraExampleService = exports.MiniProgramDemoService = exports.SystemError = exports.BizError = exports.SdkError = exports.MiniProgramSDK = exports.PandoraSDK = void 0;
7
4
  const client_1 = require("./bff/request/client");
8
- const service_1 = require("./bff/modules/example/service");
9
- const service_2 = __importDefault(require("./bff/modules/demo/service"));
5
+ const service_1 = require("./bff/modules/pandora/example/service");
6
+ const service_2 = require("./bff/modules/miniprogram/demo/service");
10
7
  /**
11
- * EcommerceBackendBffSDK - 统一平台 SDK 的主入口
12
- * 支持 Web/H5 和微信小程序环境
13
- *
14
- * @example
15
- * ```typescript
16
- * // Web/H5 环境 - 生产环境
17
- * const sdk = new EcommerceBackendBffSDK({
18
- * getToken: async () => localStorage.getItem('token') || '',
19
- * getUserId: async () => localStorage.getItem('userId') || '',
20
- * getRoleId: async () => localStorage.getItem('roleId') || '',
21
- * environment: 'production'
22
- * })
23
- *
24
- * // 小程序环境 - 测试环境
25
- * const sdk = new EcommerceBackendBffSDK({
26
- * getToken: async () => wx.getStorageSync('token') || '',
27
- * getUserId: async () => wx.getStorageSync('userId') || '',
28
- * getRoleId: async () => wx.getStorageSync('roleId') || '',
29
- * environment: 'test'
30
- * })
31
- *
32
- * // 使用服务模块
33
- * const profile = await sdk.example.getUserProfile('user123')
34
- * const demoResult = await sdk.demo.demoFunc({ demoParam: 'test' })
35
- * ```
8
+ * Pandora 平台 SDK(管理后台)
9
+ * 包含所有 Pandora 平台相关的服务
36
10
  */
37
- class EcommerceBackendBffSDK {
11
+ class PandoraSDK {
38
12
  /**
39
- * 使用配置选项初始化 SDK
13
+ * 使用配置选项初始化 Pandora SDK
40
14
  * @param options - SDK 配置,包含凭证回调函数
41
15
  */
42
16
  constructor(options) {
43
17
  // 使用提供的选项初始化 HttpClient
44
18
  this.http = new client_1.HttpClient(options);
45
- // 使用 HttpClient 实例化所有服务模块
46
- this.example = new service_1.ExampleService(this.http);
47
- this.demo = new service_2.default(this.http);
19
+ // 使用 HttpClient 实例化所有 Pandora 服务模块
20
+ this.example = new service_1.PandoraExampleService(this.http);
48
21
  }
49
22
  }
50
- exports.EcommerceBackendBffSDK = EcommerceBackendBffSDK;
51
- // 导出服务类以便直接实例化(如需要)
52
- var service_3 = require("./bff/modules/demo/service");
53
- Object.defineProperty(exports, "DemoService", { enumerable: true, get: function () { return __importDefault(service_3).default; } });
54
- var service_4 = require("./bff/modules/example/service");
55
- Object.defineProperty(exports, "ExampleService", { enumerable: true, get: function () { return service_4.ExampleService; } });
23
+ exports.PandoraSDK = PandoraSDK;
24
+ /**
25
+ * 小程序平台 SDK
26
+ * 包含所有小程序平台相关的服务
27
+ */
28
+ class MiniProgramSDK {
29
+ /**
30
+ * 使用配置选项初始化小程序 SDK
31
+ * @param options - SDK 配置,包含凭证回调函数
32
+ */
33
+ constructor(options) {
34
+ // 使用提供的选项初始化 HttpClient
35
+ this.http = new client_1.HttpClient(options);
36
+ // 使用 HttpClient 实例化所有小程序服务模块
37
+ this.demo = new service_2.MiniProgramDemoService(this.http);
38
+ }
39
+ }
40
+ exports.MiniProgramSDK = MiniProgramSDK;
41
+ // ==================== 导出 ====================
56
42
  // 错误类
57
43
  var errors_1 = require("./errors");
58
44
  Object.defineProperty(exports, "SdkError", { enumerable: true, get: function () { return errors_1.SdkError; } });
59
45
  Object.defineProperty(exports, "BizError", { enumerable: true, get: function () { return errors_1.BizError; } });
60
46
  Object.defineProperty(exports, "SystemError", { enumerable: true, get: function () { return errors_1.SystemError; } });
47
+ // 服务类(按平台分组)
48
+ var service_3 = require("./bff/modules/miniprogram/demo/service");
49
+ Object.defineProperty(exports, "MiniProgramDemoService", { enumerable: true, get: function () { return service_3.MiniProgramDemoService; } });
50
+ var service_4 = require("./bff/modules/pandora/example/service");
51
+ Object.defineProperty(exports, "PandoraExampleService", { enumerable: true, get: function () { return service_4.PandoraExampleService; } });
@@ -6,7 +6,7 @@ import { HttpClient } from '../request/client';
6
6
  */
7
7
  export default abstract class BaseService {
8
8
  /**
9
- * 服务的 URL 前缀路径(例如 '/api/v1/user')
9
+ * 服务的 URL 前缀路径(例如 '/miniprogram/user' 或 '/pandora/user')
10
10
  * 必须由子类定义
11
11
  */
12
12
  protected abstract prefixUrl: string;
@@ -0,0 +1,16 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../../BaseService';
3
+ import type { StandardResponse } from '../../../../types';
4
+ /**
5
+ * DemoService - Demo 服务模块
6
+ * 提供 Demo 相关的 API 方法
7
+ */
8
+ export declare class MiniProgramDemoService extends BaseService {
9
+ protected prefixUrl: string;
10
+ /**
11
+ * 示例接口
12
+ * @param request - 请求参数
13
+ * @returns Promise,解析为标准响应格式
14
+ */
15
+ demoFunc(request: Service.Request.demoFunc): Promise<StandardResponse<Service.Response.demoFunc>>;
16
+ }
@@ -0,0 +1,19 @@
1
+ import BaseService from '../../BaseService.mjs';
2
+ /**
3
+ * DemoService - Demo 服务模块
4
+ * 提供 Demo 相关的 API 方法
5
+ */
6
+ export class MiniProgramDemoService extends BaseService {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.prefixUrl = '/miniprogram/demo';
10
+ }
11
+ /**
12
+ * 示例接口
13
+ * @param request - 请求参数
14
+ * @returns Promise,解析为标准响应格式
15
+ */
16
+ demoFunc(request) {
17
+ return this.request(this.demoFunc, request);
18
+ }
19
+ }
@@ -0,0 +1,29 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../../BaseService';
3
+ import type { StandardResponse } from '../../../../types';
4
+ /**
5
+ * PandoraExampleService - Pandora Example 服务模块
6
+ * 提供 Pandora Example 相关的 API 方法
7
+ * 平台: pandora
8
+ */
9
+ export declare class PandoraExampleService extends BaseService {
10
+ protected prefixUrl: string;
11
+ /**
12
+ * 获取用户资料
13
+ * @param request - 请求参数
14
+ * @returns Promise,解析为标准响应格式
15
+ */
16
+ getUserProfile(request: Service.Request.getUserProfile): Promise<StandardResponse<Service.Response.getUserProfile>>;
17
+ /**
18
+ * 更新用户资料
19
+ * @param request - 请求参数
20
+ * @returns Promise,解析为标准响应格式
21
+ */
22
+ updateProfile(request: Service.Request.updateProfile): Promise<StandardResponse<Service.Response.updateProfile>>;
23
+ /**
24
+ * 获取订单列表
25
+ * @param request - 请求参数
26
+ * @returns Promise,解析为标准响应格式
27
+ */
28
+ getOrderList(request: Service.Request.getOrderList): Promise<StandardResponse<Service.Response.getOrderList>>;
29
+ }
@@ -0,0 +1,36 @@
1
+ import BaseService from '../../BaseService.mjs';
2
+ /**
3
+ * PandoraExampleService - Pandora Example 服务模块
4
+ * 提供 Pandora Example 相关的 API 方法
5
+ * 平台: pandora
6
+ */
7
+ export class PandoraExampleService extends BaseService {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.prefixUrl = '/pandora/example';
11
+ }
12
+ /**
13
+ * 获取用户资料
14
+ * @param request - 请求参数
15
+ * @returns Promise,解析为标准响应格式
16
+ */
17
+ getUserProfile(request) {
18
+ return this.request(this.getUserProfile, request);
19
+ }
20
+ /**
21
+ * 更新用户资料
22
+ * @param request - 请求参数
23
+ * @returns Promise,解析为标准响应格式
24
+ */
25
+ updateProfile(request) {
26
+ return this.request(this.updateProfile, request);
27
+ }
28
+ /**
29
+ * 获取订单列表
30
+ * @param request - 请求参数
31
+ * @returns Promise,解析为标准响应格式
32
+ */
33
+ getOrderList(request) {
34
+ return this.request(this.getOrderList, request);
35
+ }
36
+ }
package/esm/index.d.ts CHANGED
@@ -1,56 +1,47 @@
1
- import { ExampleService } from './bff/modules/example/service';
2
- import DemoService from './bff/modules/demo/service';
1
+ import { PandoraExampleService } from './bff/modules/pandora/example/service';
2
+ import { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service';
3
3
  import type { SdkOptions } from './types';
4
4
  /**
5
- * EcommerceBackendBffSDK - 统一平台 SDK 的主入口
6
- * 支持 Web/H5 和微信小程序环境
7
- *
8
- * @example
9
- * ```typescript
10
- * // Web/H5 环境 - 生产环境
11
- * const sdk = new EcommerceBackendBffSDK({
12
- * getToken: async () => localStorage.getItem('token') || '',
13
- * getUserId: async () => localStorage.getItem('userId') || '',
14
- * getRoleId: async () => localStorage.getItem('roleId') || '',
15
- * environment: 'production'
16
- * })
17
- *
18
- * // 小程序环境 - 测试环境
19
- * const sdk = new EcommerceBackendBffSDK({
20
- * getToken: async () => wx.getStorageSync('token') || '',
21
- * getUserId: async () => wx.getStorageSync('userId') || '',
22
- * getRoleId: async () => wx.getStorageSync('roleId') || '',
23
- * environment: 'test'
24
- * })
25
- *
26
- * // 使用服务模块
27
- * const profile = await sdk.example.getUserProfile('user123')
28
- * const demoResult = await sdk.demo.demoFunc({ demoParam: 'test' })
29
- * ```
5
+ * Pandora 平台 SDK(管理后台)
6
+ * 包含所有 Pandora 平台相关的服务
30
7
  */
31
- export declare class EcommerceBackendBffSDK {
8
+ export declare class PandoraSDK {
32
9
  /**
33
10
  * HttpClient 实例,管理平台特定的请求策略
34
11
  */
35
12
  private http;
36
13
  /**
37
- * 示例服务模块,演示 SDK 使用模式
14
+ * Pandora 示例服务模块
38
15
  */
39
- example: ExampleService;
16
+ example: PandoraExampleService;
40
17
  /**
41
- * Demo 服务模块(从旧版 config 服务迁移而来)
18
+ * 使用配置选项初始化 Pandora SDK
19
+ * @param options - SDK 配置,包含凭证回调函数
20
+ */
21
+ constructor(options: SdkOptions);
22
+ }
23
+ /**
24
+ * 小程序平台 SDK
25
+ * 包含所有小程序平台相关的服务
26
+ */
27
+ export declare class MiniProgramSDK {
28
+ /**
29
+ * HttpClient 实例,管理平台特定的请求策略
30
+ */
31
+ private http;
32
+ /**
33
+ * 小程序 Demo 服务模块
42
34
  */
43
- demo: DemoService;
35
+ demo: MiniProgramDemoService;
44
36
  /**
45
- * 使用配置选项初始化 SDK
37
+ * 使用配置选项初始化小程序 SDK
46
38
  * @param options - SDK 配置,包含凭证回调函数
47
39
  */
48
40
  constructor(options: SdkOptions);
49
41
  }
50
- export { default as DemoService } from './bff/modules/demo/service';
51
- export { ExampleService } from './bff/modules/example/service';
52
- export type { Service as DemoControllerTypes } from './bff/modules/demo/types';
53
- export type { Service as EcommerceBackendBffServiceControllerTypes } from './bff/modules/demo/types';
54
- export type { Service as ExampleServiceTypes } from './bff/modules/example/types';
55
42
  export { SdkError, BizError, SystemError } from './errors';
56
43
  export type { SdkOptions, IRequestStrategy, StandardResponse } from './types';
44
+ export { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service';
45
+ export { PandoraExampleService } from './bff/modules/pandora/example/service';
46
+ export type { Service as MiniProgramDemoTypes } from './bff/modules/miniprogram/demo/types';
47
+ export type { Service as PandoraExampleTypes } from './bff/modules/pandora/example/types';
package/esm/index.mjs CHANGED
@@ -1,48 +1,41 @@
1
1
  import { HttpClient } from './bff/request/client.mjs';
2
- import { ExampleService } from './bff/modules/example/service.mjs';
3
- import DemoService from './bff/modules/demo/service.mjs';
2
+ import { PandoraExampleService } from './bff/modules/pandora/example/service.mjs';
3
+ import { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service.mjs';
4
4
  /**
5
- * EcommerceBackendBffSDK - 统一平台 SDK 的主入口
6
- * 支持 Web/H5 和微信小程序环境
7
- *
8
- * @example
9
- * ```typescript
10
- * // Web/H5 环境 - 生产环境
11
- * const sdk = new EcommerceBackendBffSDK({
12
- * getToken: async () => localStorage.getItem('token') || '',
13
- * getUserId: async () => localStorage.getItem('userId') || '',
14
- * getRoleId: async () => localStorage.getItem('roleId') || '',
15
- * environment: 'production'
16
- * })
17
- *
18
- * // 小程序环境 - 测试环境
19
- * const sdk = new EcommerceBackendBffSDK({
20
- * getToken: async () => wx.getStorageSync('token') || '',
21
- * getUserId: async () => wx.getStorageSync('userId') || '',
22
- * getRoleId: async () => wx.getStorageSync('roleId') || '',
23
- * environment: 'test'
24
- * })
25
- *
26
- * // 使用服务模块
27
- * const profile = await sdk.example.getUserProfile('user123')
28
- * const demoResult = await sdk.demo.demoFunc({ demoParam: 'test' })
29
- * ```
5
+ * Pandora 平台 SDK(管理后台)
6
+ * 包含所有 Pandora 平台相关的服务
30
7
  */
31
- export class EcommerceBackendBffSDK {
8
+ export class PandoraSDK {
32
9
  /**
33
- * 使用配置选项初始化 SDK
10
+ * 使用配置选项初始化 Pandora SDK
34
11
  * @param options - SDK 配置,包含凭证回调函数
35
12
  */
36
13
  constructor(options) {
37
14
  // 使用提供的选项初始化 HttpClient
38
15
  this.http = new HttpClient(options);
39
- // 使用 HttpClient 实例化所有服务模块
40
- this.example = new ExampleService(this.http);
41
- this.demo = new DemoService(this.http);
16
+ // 使用 HttpClient 实例化所有 Pandora 服务模块
17
+ this.example = new PandoraExampleService(this.http);
42
18
  }
43
19
  }
44
- // 导出服务类以便直接实例化(如需要)
45
- export { default as DemoService } from './bff/modules/demo/service.mjs';
46
- export { ExampleService } from './bff/modules/example/service.mjs';
20
+ /**
21
+ * 小程序平台 SDK
22
+ * 包含所有小程序平台相关的服务
23
+ */
24
+ export class MiniProgramSDK {
25
+ /**
26
+ * 使用配置选项初始化小程序 SDK
27
+ * @param options - SDK 配置,包含凭证回调函数
28
+ */
29
+ constructor(options) {
30
+ // 使用提供的选项初始化 HttpClient
31
+ this.http = new HttpClient(options);
32
+ // 使用 HttpClient 实例化所有小程序服务模块
33
+ this.demo = new MiniProgramDemoService(this.http);
34
+ }
35
+ }
36
+ // ==================== 导出 ====================
47
37
  // 错误类
48
38
  export { SdkError, BizError, SystemError } from './errors/index.mjs';
39
+ // 服务类(按平台分组)
40
+ export { MiniProgramDemoService } from './bff/modules/miniprogram/demo/service.mjs';
41
+ export { PandoraExampleService } from './bff/modules/pandora/example/service.mjs';
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.10",
3
+ "version": "0.0.12",
4
4
  "description": "EcommerceBackendBffService Node.js SDK",
5
5
  "type": "commonjs",
6
6
  "main": "./cjs/index.js",
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^20.0.0",
31
+ "tsoa": "^6.4.0",
31
32
  "typescript": "^5.0.0"
32
33
  }
33
34
  }
@@ -1,22 +0,0 @@
1
- import { Service } from './types';
2
- import BaseService from '../BaseService';
3
- import type { StandardResponse } from '../../../types';
4
- /**
5
- * DemoService - Demo 服务模块
6
- * 提供 Demo 相关的 API 方法
7
- */
8
- declare class DemoService extends BaseService {
9
- protected prefixUrl: string;
10
- /**
11
- * Demo 方法
12
- * @param request - 请求参数
13
- * @returns Promise,解析为标准响应格式
14
- * @example
15
- * const result = await sdk.demo.demoFunc({ demoParam: 'test' })
16
- * console.log(result.data) // 业务数据
17
- * console.log(result.message) // 响应消息
18
- * console.log(result.requestId) // 请求 ID
19
- */
20
- demoFunc(request: Service.Request.demoFunc): Promise<StandardResponse<Service.Response.demoFunc>>;
21
- }
22
- export default DemoService;
@@ -1,46 +0,0 @@
1
- import BaseService from '../BaseService';
2
- import type { StandardResponse } from '../../../types';
3
- import { Service } from './types';
4
- /**
5
- * ExampleService - 演示如何创建服务模块
6
- * 此服务提供用户资料和订单管理的示例方法
7
- */
8
- export declare class ExampleService extends BaseService {
9
- /**
10
- * 此服务的 API 路径前缀
11
- * 此服务中的所有方法都将使用此前缀
12
- */
13
- protected prefixUrl: string;
14
- /**
15
- * 根据 ID 获取用户资料
16
- * @param request - 请求参数
17
- * @returns Promise,解析为标准响应格式,包含用户资料数据
18
- * @example
19
- * const result = await exampleService.getUserProfile({ id: 'user123' })
20
- * console.log(result.data) // 用户资料数据
21
- * console.log(result.message) // 响应消息
22
- * console.log(result.requestId) // 请求 ID
23
- */
24
- getUserProfile(request: Service.Request.getUserProfile): Promise<StandardResponse<Service.Response.getUserProfile>>;
25
- /**
26
- * 更新用户资料
27
- * @param request - 请求参数
28
- * @returns Promise,解析为标准响应格式
29
- * @example
30
- * const result = await exampleService.updateProfile({ name: 'John Doe', email: 'john@example.com' })
31
- * console.log(result.message) // 'success'
32
- * console.log(result.success) // true
33
- */
34
- updateProfile(request: Service.Request.updateProfile): Promise<StandardResponse<Service.Response.updateProfile>>;
35
- /**
36
- * 获取分页订单列表
37
- * @param request - 请求参数
38
- * @returns Promise,解析为标准响应格式,包含订单列表数据
39
- * @example
40
- * const result = await exampleService.getOrderList({ page: 1, pageSize: 20 })
41
- * console.log(result.data.orders) // 订单列表
42
- * console.log(result.data.total) // 总数
43
- * console.log(result.requestId) // 请求 ID
44
- */
45
- getOrderList(request: Service.Request.getOrderList): Promise<StandardResponse<Service.Response.getOrderList>>;
46
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ExampleService = void 0;
7
- const BaseService_1 = __importDefault(require("../BaseService"));
8
- /**
9
- * ExampleService - 演示如何创建服务模块
10
- * 此服务提供用户资料和订单管理的示例方法
11
- */
12
- class ExampleService extends BaseService_1.default {
13
- constructor() {
14
- super(...arguments);
15
- /**
16
- * 此服务的 API 路径前缀
17
- * 此服务中的所有方法都将使用此前缀
18
- */
19
- this.prefixUrl = '/api/v1/user';
20
- }
21
- /**
22
- * 根据 ID 获取用户资料
23
- * @param request - 请求参数
24
- * @returns Promise,解析为标准响应格式,包含用户资料数据
25
- * @example
26
- * const result = await exampleService.getUserProfile({ id: 'user123' })
27
- * console.log(result.data) // 用户资料数据
28
- * console.log(result.message) // 响应消息
29
- * console.log(result.requestId) // 请求 ID
30
- */
31
- async getUserProfile(request) {
32
- return this.request(this.getUserProfile, request);
33
- }
34
- /**
35
- * 更新用户资料
36
- * @param request - 请求参数
37
- * @returns Promise,解析为标准响应格式
38
- * @example
39
- * const result = await exampleService.updateProfile({ name: 'John Doe', email: 'john@example.com' })
40
- * console.log(result.message) // 'success'
41
- * console.log(result.success) // true
42
- */
43
- async updateProfile(request) {
44
- return this.request(this.updateProfile, request);
45
- }
46
- /**
47
- * 获取分页订单列表
48
- * @param request - 请求参数
49
- * @returns Promise,解析为标准响应格式,包含订单列表数据
50
- * @example
51
- * const result = await exampleService.getOrderList({ page: 1, pageSize: 20 })
52
- * console.log(result.data.orders) // 订单列表
53
- * console.log(result.data.total) // 总数
54
- * console.log(result.requestId) // 请求 ID
55
- */
56
- async getOrderList(request) {
57
- return this.request(this.getOrderList, request);
58
- }
59
- }
60
- exports.ExampleService = ExampleService;
@@ -1,22 +0,0 @@
1
- import { Service } from './types';
2
- import BaseService from '../BaseService';
3
- import type { StandardResponse } from '../../../types';
4
- /**
5
- * DemoService - Demo 服务模块
6
- * 提供 Demo 相关的 API 方法
7
- */
8
- declare class DemoService extends BaseService {
9
- protected prefixUrl: string;
10
- /**
11
- * Demo 方法
12
- * @param request - 请求参数
13
- * @returns Promise,解析为标准响应格式
14
- * @example
15
- * const result = await sdk.demo.demoFunc({ demoParam: 'test' })
16
- * console.log(result.data) // 业务数据
17
- * console.log(result.message) // 响应消息
18
- * console.log(result.requestId) // 请求 ID
19
- */
20
- demoFunc(request: Service.Request.demoFunc): Promise<StandardResponse<Service.Response.demoFunc>>;
21
- }
22
- export default DemoService;
@@ -1,25 +0,0 @@
1
- import BaseService from '../BaseService.mjs';
2
- /**
3
- * DemoService - Demo 服务模块
4
- * 提供 Demo 相关的 API 方法
5
- */
6
- class DemoService extends BaseService {
7
- constructor() {
8
- super(...arguments);
9
- this.prefixUrl = '/demo';
10
- }
11
- /**
12
- * Demo 方法
13
- * @param request - 请求参数
14
- * @returns Promise,解析为标准响应格式
15
- * @example
16
- * const result = await sdk.demo.demoFunc({ demoParam: 'test' })
17
- * console.log(result.data) // 业务数据
18
- * console.log(result.message) // 响应消息
19
- * console.log(result.requestId) // 请求 ID
20
- */
21
- demoFunc(request) {
22
- return this.request(this.demoFunc, request);
23
- }
24
- }
25
- export default DemoService;
@@ -1,46 +0,0 @@
1
- import BaseService from '../BaseService';
2
- import type { StandardResponse } from '../../../types';
3
- import { Service } from './types';
4
- /**
5
- * ExampleService - 演示如何创建服务模块
6
- * 此服务提供用户资料和订单管理的示例方法
7
- */
8
- export declare class ExampleService extends BaseService {
9
- /**
10
- * 此服务的 API 路径前缀
11
- * 此服务中的所有方法都将使用此前缀
12
- */
13
- protected prefixUrl: string;
14
- /**
15
- * 根据 ID 获取用户资料
16
- * @param request - 请求参数
17
- * @returns Promise,解析为标准响应格式,包含用户资料数据
18
- * @example
19
- * const result = await exampleService.getUserProfile({ id: 'user123' })
20
- * console.log(result.data) // 用户资料数据
21
- * console.log(result.message) // 响应消息
22
- * console.log(result.requestId) // 请求 ID
23
- */
24
- getUserProfile(request: Service.Request.getUserProfile): Promise<StandardResponse<Service.Response.getUserProfile>>;
25
- /**
26
- * 更新用户资料
27
- * @param request - 请求参数
28
- * @returns Promise,解析为标准响应格式
29
- * @example
30
- * const result = await exampleService.updateProfile({ name: 'John Doe', email: 'john@example.com' })
31
- * console.log(result.message) // 'success'
32
- * console.log(result.success) // true
33
- */
34
- updateProfile(request: Service.Request.updateProfile): Promise<StandardResponse<Service.Response.updateProfile>>;
35
- /**
36
- * 获取分页订单列表
37
- * @param request - 请求参数
38
- * @returns Promise,解析为标准响应格式,包含订单列表数据
39
- * @example
40
- * const result = await exampleService.getOrderList({ page: 1, pageSize: 20 })
41
- * console.log(result.data.orders) // 订单列表
42
- * console.log(result.data.total) // 总数
43
- * console.log(result.requestId) // 请求 ID
44
- */
45
- getOrderList(request: Service.Request.getOrderList): Promise<StandardResponse<Service.Response.getOrderList>>;
46
- }
@@ -1,53 +0,0 @@
1
- import BaseService from '../BaseService.mjs';
2
- /**
3
- * ExampleService - 演示如何创建服务模块
4
- * 此服务提供用户资料和订单管理的示例方法
5
- */
6
- export class ExampleService extends BaseService {
7
- constructor() {
8
- super(...arguments);
9
- /**
10
- * 此服务的 API 路径前缀
11
- * 此服务中的所有方法都将使用此前缀
12
- */
13
- this.prefixUrl = '/api/v1/user';
14
- }
15
- /**
16
- * 根据 ID 获取用户资料
17
- * @param request - 请求参数
18
- * @returns Promise,解析为标准响应格式,包含用户资料数据
19
- * @example
20
- * const result = await exampleService.getUserProfile({ id: 'user123' })
21
- * console.log(result.data) // 用户资料数据
22
- * console.log(result.message) // 响应消息
23
- * console.log(result.requestId) // 请求 ID
24
- */
25
- async getUserProfile(request) {
26
- return this.request(this.getUserProfile, request);
27
- }
28
- /**
29
- * 更新用户资料
30
- * @param request - 请求参数
31
- * @returns Promise,解析为标准响应格式
32
- * @example
33
- * const result = await exampleService.updateProfile({ name: 'John Doe', email: 'john@example.com' })
34
- * console.log(result.message) // 'success'
35
- * console.log(result.success) // true
36
- */
37
- async updateProfile(request) {
38
- return this.request(this.updateProfile, request);
39
- }
40
- /**
41
- * 获取分页订单列表
42
- * @param request - 请求参数
43
- * @returns Promise,解析为标准响应格式,包含订单列表数据
44
- * @example
45
- * const result = await exampleService.getOrderList({ page: 1, pageSize: 20 })
46
- * console.log(result.data.orders) // 订单列表
47
- * console.log(result.data.total) // 总数
48
- * console.log(result.requestId) // 请求 ID
49
- */
50
- async getOrderList(request) {
51
- return this.request(this.getOrderList, request);
52
- }
53
- }