@be-link/ecommerce-product-service-node-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # EcommerceProductService SDK
2
+
3
+ EcommerceProductService Node.js SDK - 敏感信息管理服务客户端
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @be-link/ecommerce-product-service-node-sdk
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```typescript
14
+ import { demoService } from '@be-link/ecommerce-product-service-node-sdk'
15
+
16
+ const result = await demoService.demoFunc({ /* 请求参数 */ })
17
+ ```
18
+
19
+ ## 开发
20
+
21
+ ```bash
22
+ # 构建
23
+ npm run build
24
+
25
+ # 生成 Swagger 文档
26
+ npm run swagger
27
+
28
+ # 构建并生成文档
29
+ npm run build:swagger
30
+ ```
31
+
32
+ ## Swagger 文档
33
+
34
+ 查看 [SWAGGER.md](./SWAGGER.md) 了解如何生成和使用 API 文档。
35
+
36
+ ## License
37
+
38
+ ISC
39
+
package/enum.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ export declare namespace ENUM {
2
+ namespace PRODUCT_ENUM {
3
+ enum TYPE {
4
+ ENTITY = "ENTITY",
5
+ VIRTUAL = "VIRTUAL"
6
+ }
7
+ enum TYPE_CHINESE {
8
+ ENTITY = "\u5B9E\u4F53\u5546\u54C1",
9
+ VIRTUAL = "\u865A\u62DF\u5546\u54C1"
10
+ }
11
+ enum STATUS {
12
+ DRAFT = "DRAFT",
13
+ ACTIVE = "ACTIVE",
14
+ INACTIVE = "INACTIVE"
15
+ }
16
+ enum STATUS_CHINESE {
17
+ DRAFT = "\u8349\u7A3F",
18
+ ACTIVE = "\u4E0A\u67B6",
19
+ INACTIVE = "\u4E0B\u67B6"
20
+ }
21
+ enum PICK_TYPE {
22
+ STORE_PICKUP = "STORE_PICKUP",
23
+ DELIVERY = "DELIVERY"
24
+ }
25
+ enum PICK_TYPE_CHINESE {
26
+ STORE_PICKUP = "\u95E8\u5E97\u81EA\u63D0",
27
+ DELIVERY = "\u9001\u8D27\u4E0A\u95E8"
28
+ }
29
+ enum DISPATCH_TYPE {
30
+ WAREHOSE_DISPATCH = "WAREHOSE_DISPATCH",
31
+ SUPPLIER_DISPATCH = "SUPPLIER_DISPATCH"
32
+ }
33
+ enum DISPATCH_TYPE_CHINESE {
34
+ WAREHOSE_DISPATCH = "\u4ED3\u53D1",
35
+ SUPPLIER_DISPATCH = "\u4F9B\u81EA\u53D1"
36
+ }
37
+ enum STORAGE_METHOD {
38
+ NORMAL = "NORMAL",
39
+ REFRIGERATED = "REFRIGERATED",
40
+ FROZEN = "FROZEN"
41
+ }
42
+ enum STORAGE_METHOD_CHINESE {
43
+ NORMAL = "\u5E38\u6E29",
44
+ REFRIGERATED = "\u51B7\u85CF",
45
+ FROZEN = "\u51B7\u51BB"
46
+ }
47
+ enum CLASSIFICATION {
48
+ DEPARTMENT_STORE = "DEPARTMENT_STORE",
49
+ HEALTH = "HEALTH",
50
+ STORE_RETAIL = "STORE_RETAIL",
51
+ OTHER_FRESH = "OTHER_FRESH",
52
+ MORNING_FRESH = "MORNING_FRESH"
53
+ }
54
+ enum CLASSIFICATION_CHINESE {
55
+ DEPARTMENT_STORE = "\u767E\u8D27",
56
+ HEALTH = "\u5065\u5EB7",
57
+ STORE_RETAIL = "\u95E8\u5E97\u96F6\u552E",
58
+ OTHER_FRESH = "\u5176\u4ED6\u751F\u9C9C",
59
+ MORNING_FRESH = "\u65E9\u516B\u751F\u9C9C"
60
+ }
61
+ enum FREIGHT_TYPE {
62
+ JZH = "JZH",
63
+ REMOTE_AREAS = "REMOTE_AREAS"
64
+ }
65
+ enum FREIGHT_TYPE_CHINESE {
66
+ JZH = "\u4EC5\u9650\u6C5F\u6D59\u6CAA\u53D1\u8D27",
67
+ REMOTE_AREAS = "\u504F\u8FDC\u5730\u533A\u4E0D\u53D1\u8D27"
68
+ }
69
+ }
70
+ namespace TASK_ENUM {
71
+ enum STATUS {
72
+ PENDING = "PENDING",
73
+ EXECUTING = "EXECUTING",
74
+ SUCCESS = "SUCCESS",
75
+ CANCEL = "CANCEL",
76
+ FAIL = "FAIL"
77
+ }
78
+ enum STATUS_CHINESE {
79
+ PENDING = "\u5F85\u5904\u7406",
80
+ EXECUTING = "\u6267\u884C\u4E2D",
81
+ SUCCESS = "\u5DF2\u5B8C\u6210",
82
+ CANCEL = "\u5DF2\u53D6\u6D88",
83
+ FAIL = "\u6267\u884C\u5931\u8D25"
84
+ }
85
+ enum OPERATION_TYPE {
86
+ ACTIVE = "ACTIVE",
87
+ INACTIVE = "INACTIVE"
88
+ }
89
+ enum OPERATION_TYPE_CHINESE {
90
+ ACTIVE = "\u4E0A\u67B6",
91
+ INACTIVE = "\u4E0B\u67B6"
92
+ }
93
+ }
94
+ namespace COMMON_ENUM {
95
+ enum BOOLEAN {
96
+ NO = 0,
97
+ YES = 1
98
+ }
99
+ enum BOOLEAN_CHINESE {
100
+ NO = "\u5426",
101
+ YES = "\u662F"
102
+ }
103
+ }
104
+ }
package/enum.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENUM = void 0;
4
+ // 服务.模块.枚举名称.枚举值 示例: DEMO_ENUM.ORDER_ENUM.STATUS.PENDING
5
+ var ENUM;
6
+ (function (ENUM) {
7
+ let PRODUCT_ENUM;
8
+ (function (PRODUCT_ENUM) {
9
+ let TYPE;
10
+ (function (TYPE) {
11
+ TYPE["ENTITY"] = "ENTITY";
12
+ TYPE["VIRTUAL"] = "VIRTUAL";
13
+ })(TYPE = PRODUCT_ENUM.TYPE || (PRODUCT_ENUM.TYPE = {}));
14
+ let TYPE_CHINESE;
15
+ (function (TYPE_CHINESE) {
16
+ TYPE_CHINESE["ENTITY"] = "\u5B9E\u4F53\u5546\u54C1";
17
+ TYPE_CHINESE["VIRTUAL"] = "\u865A\u62DF\u5546\u54C1";
18
+ })(TYPE_CHINESE = PRODUCT_ENUM.TYPE_CHINESE || (PRODUCT_ENUM.TYPE_CHINESE = {}));
19
+ let STATUS;
20
+ (function (STATUS) {
21
+ STATUS["DRAFT"] = "DRAFT";
22
+ STATUS["ACTIVE"] = "ACTIVE";
23
+ STATUS["INACTIVE"] = "INACTIVE";
24
+ })(STATUS = PRODUCT_ENUM.STATUS || (PRODUCT_ENUM.STATUS = {}));
25
+ let STATUS_CHINESE;
26
+ (function (STATUS_CHINESE) {
27
+ STATUS_CHINESE["DRAFT"] = "\u8349\u7A3F";
28
+ STATUS_CHINESE["ACTIVE"] = "\u4E0A\u67B6";
29
+ STATUS_CHINESE["INACTIVE"] = "\u4E0B\u67B6";
30
+ })(STATUS_CHINESE = PRODUCT_ENUM.STATUS_CHINESE || (PRODUCT_ENUM.STATUS_CHINESE = {}));
31
+ let PICK_TYPE;
32
+ (function (PICK_TYPE) {
33
+ PICK_TYPE["STORE_PICKUP"] = "STORE_PICKUP";
34
+ PICK_TYPE["DELIVERY"] = "DELIVERY";
35
+ })(PICK_TYPE = PRODUCT_ENUM.PICK_TYPE || (PRODUCT_ENUM.PICK_TYPE = {}));
36
+ let PICK_TYPE_CHINESE;
37
+ (function (PICK_TYPE_CHINESE) {
38
+ PICK_TYPE_CHINESE["STORE_PICKUP"] = "\u95E8\u5E97\u81EA\u63D0";
39
+ PICK_TYPE_CHINESE["DELIVERY"] = "\u9001\u8D27\u4E0A\u95E8";
40
+ })(PICK_TYPE_CHINESE = PRODUCT_ENUM.PICK_TYPE_CHINESE || (PRODUCT_ENUM.PICK_TYPE_CHINESE = {}));
41
+ let DISPATCH_TYPE;
42
+ (function (DISPATCH_TYPE) {
43
+ DISPATCH_TYPE["WAREHOSE_DISPATCH"] = "WAREHOSE_DISPATCH";
44
+ DISPATCH_TYPE["SUPPLIER_DISPATCH"] = "SUPPLIER_DISPATCH";
45
+ })(DISPATCH_TYPE = PRODUCT_ENUM.DISPATCH_TYPE || (PRODUCT_ENUM.DISPATCH_TYPE = {}));
46
+ let DISPATCH_TYPE_CHINESE;
47
+ (function (DISPATCH_TYPE_CHINESE) {
48
+ DISPATCH_TYPE_CHINESE["WAREHOSE_DISPATCH"] = "\u4ED3\u53D1";
49
+ DISPATCH_TYPE_CHINESE["SUPPLIER_DISPATCH"] = "\u4F9B\u81EA\u53D1";
50
+ })(DISPATCH_TYPE_CHINESE = PRODUCT_ENUM.DISPATCH_TYPE_CHINESE || (PRODUCT_ENUM.DISPATCH_TYPE_CHINESE = {}));
51
+ let STORAGE_METHOD;
52
+ (function (STORAGE_METHOD) {
53
+ STORAGE_METHOD["NORMAL"] = "NORMAL";
54
+ STORAGE_METHOD["REFRIGERATED"] = "REFRIGERATED";
55
+ STORAGE_METHOD["FROZEN"] = "FROZEN";
56
+ })(STORAGE_METHOD = PRODUCT_ENUM.STORAGE_METHOD || (PRODUCT_ENUM.STORAGE_METHOD = {}));
57
+ let STORAGE_METHOD_CHINESE;
58
+ (function (STORAGE_METHOD_CHINESE) {
59
+ STORAGE_METHOD_CHINESE["NORMAL"] = "\u5E38\u6E29";
60
+ STORAGE_METHOD_CHINESE["REFRIGERATED"] = "\u51B7\u85CF";
61
+ STORAGE_METHOD_CHINESE["FROZEN"] = "\u51B7\u51BB";
62
+ })(STORAGE_METHOD_CHINESE = PRODUCT_ENUM.STORAGE_METHOD_CHINESE || (PRODUCT_ENUM.STORAGE_METHOD_CHINESE = {}));
63
+ let CLASSIFICATION;
64
+ (function (CLASSIFICATION) {
65
+ CLASSIFICATION["DEPARTMENT_STORE"] = "DEPARTMENT_STORE";
66
+ CLASSIFICATION["HEALTH"] = "HEALTH";
67
+ CLASSIFICATION["STORE_RETAIL"] = "STORE_RETAIL";
68
+ CLASSIFICATION["OTHER_FRESH"] = "OTHER_FRESH";
69
+ CLASSIFICATION["MORNING_FRESH"] = "MORNING_FRESH";
70
+ })(CLASSIFICATION = PRODUCT_ENUM.CLASSIFICATION || (PRODUCT_ENUM.CLASSIFICATION = {}));
71
+ let CLASSIFICATION_CHINESE;
72
+ (function (CLASSIFICATION_CHINESE) {
73
+ CLASSIFICATION_CHINESE["DEPARTMENT_STORE"] = "\u767E\u8D27";
74
+ CLASSIFICATION_CHINESE["HEALTH"] = "\u5065\u5EB7";
75
+ CLASSIFICATION_CHINESE["STORE_RETAIL"] = "\u95E8\u5E97\u96F6\u552E";
76
+ CLASSIFICATION_CHINESE["OTHER_FRESH"] = "\u5176\u4ED6\u751F\u9C9C";
77
+ CLASSIFICATION_CHINESE["MORNING_FRESH"] = "\u65E9\u516B\u751F\u9C9C";
78
+ })(CLASSIFICATION_CHINESE = PRODUCT_ENUM.CLASSIFICATION_CHINESE || (PRODUCT_ENUM.CLASSIFICATION_CHINESE = {}));
79
+ let FREIGHT_TYPE;
80
+ (function (FREIGHT_TYPE) {
81
+ FREIGHT_TYPE["JZH"] = "JZH";
82
+ FREIGHT_TYPE["REMOTE_AREAS"] = "REMOTE_AREAS";
83
+ })(FREIGHT_TYPE = PRODUCT_ENUM.FREIGHT_TYPE || (PRODUCT_ENUM.FREIGHT_TYPE = {}));
84
+ let FREIGHT_TYPE_CHINESE;
85
+ (function (FREIGHT_TYPE_CHINESE) {
86
+ FREIGHT_TYPE_CHINESE["JZH"] = "\u4EC5\u9650\u6C5F\u6D59\u6CAA\u53D1\u8D27";
87
+ FREIGHT_TYPE_CHINESE["REMOTE_AREAS"] = "\u504F\u8FDC\u5730\u533A\u4E0D\u53D1\u8D27";
88
+ })(FREIGHT_TYPE_CHINESE = PRODUCT_ENUM.FREIGHT_TYPE_CHINESE || (PRODUCT_ENUM.FREIGHT_TYPE_CHINESE = {}));
89
+ })(PRODUCT_ENUM = ENUM.PRODUCT_ENUM || (ENUM.PRODUCT_ENUM = {}));
90
+ let TASK_ENUM;
91
+ (function (TASK_ENUM) {
92
+ let STATUS;
93
+ (function (STATUS) {
94
+ STATUS["PENDING"] = "PENDING";
95
+ STATUS["EXECUTING"] = "EXECUTING";
96
+ STATUS["SUCCESS"] = "SUCCESS";
97
+ STATUS["CANCEL"] = "CANCEL";
98
+ STATUS["FAIL"] = "FAIL";
99
+ })(STATUS = TASK_ENUM.STATUS || (TASK_ENUM.STATUS = {}));
100
+ let STATUS_CHINESE;
101
+ (function (STATUS_CHINESE) {
102
+ STATUS_CHINESE["PENDING"] = "\u5F85\u5904\u7406";
103
+ STATUS_CHINESE["EXECUTING"] = "\u6267\u884C\u4E2D";
104
+ STATUS_CHINESE["SUCCESS"] = "\u5DF2\u5B8C\u6210";
105
+ STATUS_CHINESE["CANCEL"] = "\u5DF2\u53D6\u6D88";
106
+ STATUS_CHINESE["FAIL"] = "\u6267\u884C\u5931\u8D25";
107
+ })(STATUS_CHINESE = TASK_ENUM.STATUS_CHINESE || (TASK_ENUM.STATUS_CHINESE = {}));
108
+ let OPERATION_TYPE;
109
+ (function (OPERATION_TYPE) {
110
+ OPERATION_TYPE["ACTIVE"] = "ACTIVE";
111
+ OPERATION_TYPE["INACTIVE"] = "INACTIVE";
112
+ })(OPERATION_TYPE = TASK_ENUM.OPERATION_TYPE || (TASK_ENUM.OPERATION_TYPE = {}));
113
+ let OPERATION_TYPE_CHINESE;
114
+ (function (OPERATION_TYPE_CHINESE) {
115
+ OPERATION_TYPE_CHINESE["ACTIVE"] = "\u4E0A\u67B6";
116
+ OPERATION_TYPE_CHINESE["INACTIVE"] = "\u4E0B\u67B6";
117
+ })(OPERATION_TYPE_CHINESE = TASK_ENUM.OPERATION_TYPE_CHINESE || (TASK_ENUM.OPERATION_TYPE_CHINESE = {}));
118
+ })(TASK_ENUM = ENUM.TASK_ENUM || (ENUM.TASK_ENUM = {}));
119
+ let COMMON_ENUM;
120
+ (function (COMMON_ENUM) {
121
+ let BOOLEAN;
122
+ (function (BOOLEAN) {
123
+ BOOLEAN[BOOLEAN["NO"] = 0] = "NO";
124
+ BOOLEAN[BOOLEAN["YES"] = 1] = "YES";
125
+ })(BOOLEAN = COMMON_ENUM.BOOLEAN || (COMMON_ENUM.BOOLEAN = {}));
126
+ let BOOLEAN_CHINESE;
127
+ (function (BOOLEAN_CHINESE) {
128
+ BOOLEAN_CHINESE["NO"] = "\u5426";
129
+ BOOLEAN_CHINESE["YES"] = "\u662F";
130
+ })(BOOLEAN_CHINESE = COMMON_ENUM.BOOLEAN_CHINESE || (COMMON_ENUM.BOOLEAN_CHINESE = {}));
131
+ })(COMMON_ENUM = ENUM.COMMON_ENUM || (ENUM.COMMON_ENUM = {}));
132
+ })(ENUM || (exports.ENUM = ENUM = {}));
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { ENUM as PRODUCT_SERVICE_ENUM } from './enum';
2
+ export { productService } from './modules/product/service';
3
+ export type { Service as ProductServiceTypes } from './modules/product/types';
4
+ export { productExpService } from './modules/productExp/service';
5
+ export type { Service as ProductExpServiceTypes } from './modules/productExp/types';
6
+ export { productLiveService } from './modules/productLive/service';
7
+ export type { Service as ProductLiveServiceTypes } from './modules/productLive/types';
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.productLiveService = exports.productExpService = exports.productService = exports.PRODUCT_SERVICE_ENUM = void 0;
4
+ var enum_1 = require("./enum");
5
+ Object.defineProperty(exports, "PRODUCT_SERVICE_ENUM", { enumerable: true, get: function () { return enum_1.ENUM; } });
6
+ var service_1 = require("./modules/product/service");
7
+ Object.defineProperty(exports, "productService", { enumerable: true, get: function () { return service_1.productService; } });
8
+ var service_2 = require("./modules/productExp/service");
9
+ Object.defineProperty(exports, "productExpService", { enumerable: true, get: function () { return service_2.productExpService; } });
10
+ var service_3 = require("./modules/productLive/service");
11
+ Object.defineProperty(exports, "productLiveService", { enumerable: true, get: function () { return service_3.productLiveService; } });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * BaseService 基类
3
+ * 所有服务类都应该继承此类
4
+ */
5
+ export default abstract class BaseService {
6
+ /** URL一级路径 */
7
+ protected abstract prefixUrl: string;
8
+ /** 子网域名 */
9
+ protected readonly natDevHost = "";
10
+ protected readonly natProdHost = "";
11
+ /** 获取API URL */
12
+ protected getApiUrl(func: Function): string;
13
+ }
@@ -0,0 +1,24 @@
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
+ const env_1 = __importDefault(require("../utils/env"));
7
+ const string_1 = require("../utils/string");
8
+ /**
9
+ * BaseService 基类
10
+ * 所有服务类都应该继承此类
11
+ */
12
+ class BaseService {
13
+ constructor() {
14
+ /** 子网域名 */
15
+ this.natDevHost = '';
16
+ this.natProdHost = '';
17
+ }
18
+ /** 获取API URL */
19
+ getApiUrl(func) {
20
+ const host = env_1.default.isProduction() ? this.natProdHost : this.natDevHost;
21
+ return `${host}${this.prefixUrl}/${(0, string_1.camelToKebabCase)(func.name)}`;
22
+ }
23
+ }
24
+ exports.default = BaseService;
@@ -0,0 +1,18 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class ProductService extends BaseService implements Service.ProductController {
4
+ protected prefixUrl: string;
5
+ list(request: Service.Request.list): Promise<Service.Response.list>;
6
+ create(request: Service.ProductData): Promise<Service.Response.create>;
7
+ detail(request: Service.Request.detail): Promise<Service.ProductData>;
8
+ update(request: Service.ProductData): Promise<void>;
9
+ batchUpdate(request: Service.Request.batchUpdate): Promise<void>;
10
+ queryScheduledTask(request: Service.Request.queryScheduledTask): Promise<Service.Response.queryScheduledTask[]>;
11
+ checkSkuCode(request: Service.Request.checkSkuCode): Promise<Service.Response.checkSkuCode>;
12
+ export(request: Service.Request.list): Promise<void>;
13
+ queryProductList(request: Service.Request.queryProductList): Promise<Service.Response.queryProductList>;
14
+ queryProductSkuList(request: Service.Request.queryProductList): Promise<Service.Response.queryProductSkuList>;
15
+ productQrCode(request: Service.Request.productQrCode): Promise<Service.Response.productQrCode>;
16
+ }
17
+ export declare const productService: ProductService;
18
+ export default productService;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
+ return function (target, key) { decorator(target, key, paramIndex); }
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.productService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let ProductService = class ProductService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/product';
23
+ }
24
+ list(request) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.list), request);
26
+ }
27
+ create(request) {
28
+ return (0, http_1.callApi)(this.getApiUrl(this.create), request);
29
+ }
30
+ detail(request) {
31
+ return (0, http_1.callApi)(this.getApiUrl(this.detail), request);
32
+ }
33
+ update(request) {
34
+ return (0, http_1.callApi)(this.getApiUrl(this.update), request);
35
+ }
36
+ batchUpdate(request) {
37
+ return (0, http_1.callApi)(this.getApiUrl(this.batchUpdate), request);
38
+ }
39
+ queryScheduledTask(request) {
40
+ return (0, http_1.callApi)(this.getApiUrl(this.queryScheduledTask), request);
41
+ }
42
+ checkSkuCode(request) {
43
+ return (0, http_1.callApi)(this.getApiUrl(this.checkSkuCode), request);
44
+ }
45
+ export(request) {
46
+ return (0, http_1.callApi)(this.getApiUrl(this.export), request);
47
+ }
48
+ queryProductList(request) {
49
+ return (0, http_1.callApi)(this.getApiUrl(this.queryProductList), request);
50
+ }
51
+ queryProductSkuList(request) {
52
+ return (0, http_1.callApi)(this.getApiUrl(this.queryProductSkuList), request);
53
+ }
54
+ productQrCode(request) {
55
+ return (0, http_1.callApi)(this.getApiUrl(this.productQrCode), request);
56
+ }
57
+ };
58
+ __decorate([
59
+ (0, tsoa_1.OperationId)('商品列表'),
60
+ (0, tsoa_1.Post)('list'),
61
+ __param(0, (0, tsoa_1.Body)())
62
+ ], ProductService.prototype, "list", null);
63
+ __decorate([
64
+ (0, tsoa_1.OperationId)('创建商品'),
65
+ (0, tsoa_1.Post)('create'),
66
+ __param(0, (0, tsoa_1.Body)())
67
+ ], ProductService.prototype, "create", null);
68
+ __decorate([
69
+ (0, tsoa_1.OperationId)('商品详情'),
70
+ (0, tsoa_1.Post)('detail'),
71
+ __param(0, (0, tsoa_1.Body)())
72
+ ], ProductService.prototype, "detail", null);
73
+ __decorate([
74
+ (0, tsoa_1.OperationId)('商品更新'),
75
+ (0, tsoa_1.Post)('update'),
76
+ __param(0, (0, tsoa_1.Body)())
77
+ ], ProductService.prototype, "update", null);
78
+ __decorate([
79
+ (0, tsoa_1.OperationId)('批量更新'),
80
+ (0, tsoa_1.Post)('batch-update'),
81
+ __param(0, (0, tsoa_1.Body)())
82
+ ], ProductService.prototype, "batchUpdate", null);
83
+ __decorate([
84
+ (0, tsoa_1.OperationId)('查询定时任务任务'),
85
+ (0, tsoa_1.Post)('query-scheduled-task'),
86
+ __param(0, (0, tsoa_1.Body)())
87
+ ], ProductService.prototype, "queryScheduledTask", null);
88
+ __decorate([
89
+ (0, tsoa_1.OperationId)('校验69码是否重复'),
90
+ (0, tsoa_1.Post)('check-sku-code'),
91
+ __param(0, (0, tsoa_1.Body)())
92
+ ], ProductService.prototype, "checkSkuCode", null);
93
+ __decorate([
94
+ (0, tsoa_1.OperationId)('商品导出'),
95
+ (0, tsoa_1.Post)('export'),
96
+ __param(0, (0, tsoa_1.Body)())
97
+ ], ProductService.prototype, "export", null);
98
+ __decorate([
99
+ (0, tsoa_1.OperationId)('获取商品信息(不含规格信息)'),
100
+ (0, tsoa_1.Post)('query-product-list'),
101
+ __param(0, (0, tsoa_1.Body)())
102
+ ], ProductService.prototype, "queryProductList", null);
103
+ __decorate([
104
+ (0, tsoa_1.OperationId)('获取商品+规格信息'),
105
+ (0, tsoa_1.Post)('query-product-sku-list'),
106
+ __param(0, (0, tsoa_1.Body)())
107
+ ], ProductService.prototype, "queryProductSkuList", null);
108
+ __decorate([
109
+ (0, tsoa_1.OperationId)('商品二维码'),
110
+ (0, tsoa_1.Post)('product-qr-code'),
111
+ __param(0, (0, tsoa_1.Body)())
112
+ ], ProductService.prototype, "productQrCode", null);
113
+ ProductService = __decorate([
114
+ (0, tsoa_1.Route)('product'),
115
+ (0, tsoa_1.Tags)('Product')
116
+ ], ProductService);
117
+ exports.productService = new ProductService();
118
+ exports.default = exports.productService;
@@ -0,0 +1,246 @@
1
+ export declare namespace Service {
2
+ /**
3
+ * 核销期限接口
4
+ */
5
+ interface VerifyPeriod {
6
+ startDate: number;
7
+ endDate: number;
8
+ payAfterDay: number;
9
+ type: number;
10
+ }
11
+ /**
12
+ * 属性接口
13
+ */
14
+ interface Attr {
15
+ attrName: string;
16
+ attrValue: string;
17
+ }
18
+ /**
19
+ * 绑定的SKU接口
20
+ */
21
+ interface BindSku {
22
+ productId: string;
23
+ skuId: string;
24
+ quantity: number;
25
+ }
26
+ /**
27
+ * 定时任务接口
28
+ */
29
+ interface ScheduledTask {
30
+ scheduledTime: number;
31
+ status: string;
32
+ }
33
+ /**
34
+ * SKU项接口
35
+ */
36
+ interface SkuItem {
37
+ skuId?: string;
38
+ attrs: Attr[];
39
+ price: number;
40
+ strikethroughPrice: number;
41
+ purchasePrice: number;
42
+ skuCode: string;
43
+ multiSkuCodes: string[];
44
+ bindSkus: BindSku[];
45
+ stock: number;
46
+ }
47
+ /**
48
+ * 产品信息接口
49
+ */
50
+ interface ProductInfo {
51
+ productId?: string;
52
+ productType: string;
53
+ isCombo: number;
54
+ productName: string;
55
+ mainImg: string;
56
+ imgList: string[];
57
+ productDesc?: string;
58
+ categoryId: string;
59
+ twoCategoryId: string;
60
+ threeCategoryId: string;
61
+ pickType: string;
62
+ dispatchType: string;
63
+ storageMethod: string;
64
+ classification: string;
65
+ stockUnit: string;
66
+ productManagerId?: string;
67
+ supplierId?: string;
68
+ liveGroupId?: string;
69
+ status?: string;
70
+ scheduledTasks?: ScheduledTask[];
71
+ needVerify?: number;
72
+ verifyPeriod?: VerifyPeriod;
73
+ miniSaleQuantity?: number;
74
+ purchaseLimit?: number;
75
+ freightType?: string;
76
+ }
77
+ interface ProductData {
78
+ productInfo: ProductInfo;
79
+ skuList: SkuItem[];
80
+ creatorId: string;
81
+ }
82
+ namespace Request {
83
+ interface detail {
84
+ productId: string;
85
+ }
86
+ interface list {
87
+ pageIndex: number;
88
+ pageSize: number;
89
+ productIds?: string[];
90
+ productNames?: string[];
91
+ classifications?: string[];
92
+ storageMethods?: string[];
93
+ dispatchTypes?: string[];
94
+ supplierIds?: string[];
95
+ liveGroupIds?: string[];
96
+ productManagerIds?: string[];
97
+ productType?: string;
98
+ status?: string;
99
+ isCombo?: number;
100
+ skuCodes?: string[];
101
+ }
102
+ interface batchUpdate {
103
+ productIds: string[];
104
+ status?: string;
105
+ scheduledTasks?: ScheduledTask[];
106
+ classification?: string;
107
+ storageMethod?: string;
108
+ dispatchType?: string;
109
+ liveGroupId?: string;
110
+ isDelete?: boolean;
111
+ }
112
+ interface queryScheduledTask {
113
+ productId: string;
114
+ }
115
+ interface checkSkuCode {
116
+ productId?: string;
117
+ skuId?: string;
118
+ skuCode: string;
119
+ }
120
+ interface queryProductList {
121
+ pageIndex: number;
122
+ pageSize: number;
123
+ productIds?: string[];
124
+ productNames?: string[];
125
+ skuCodes?: string[];
126
+ isCombo?: number;
127
+ }
128
+ interface productQrCode {
129
+ path: string;
130
+ }
131
+ }
132
+ namespace Response {
133
+ interface create {
134
+ productId: string;
135
+ }
136
+ interface queryScheduledTask {
137
+ scheduledTime: number;
138
+ status: string;
139
+ operationType: string;
140
+ }
141
+ interface list {
142
+ total: number;
143
+ list: {
144
+ productId: string;
145
+ productName: string;
146
+ productImage: string;
147
+ cateName: string;
148
+ classification: string;
149
+ storageMethod: string;
150
+ dispatchType: string;
151
+ salesQuantity: number;
152
+ refundQuantity: number;
153
+ price: number;
154
+ stock: number;
155
+ status: string;
156
+ createdAt: number;
157
+ }[];
158
+ }
159
+ interface checkSkuCode {
160
+ enable: boolean;
161
+ }
162
+ interface queryProductList {
163
+ total: number;
164
+ list: {
165
+ productId: string;
166
+ productName: string;
167
+ productImage: string;
168
+ classification: string;
169
+ storageMethod: string;
170
+ dispatchType: string;
171
+ price: number;
172
+ stock: number;
173
+ status: string;
174
+ }[];
175
+ }
176
+ interface queryProductSkuList {
177
+ total: number;
178
+ list: {
179
+ productId: string;
180
+ productName: string;
181
+ productImage: string;
182
+ classification: string;
183
+ storageMethod: string;
184
+ dispatchType: string;
185
+ price: number;
186
+ stock: number;
187
+ status: string;
188
+ skuId: string;
189
+ attrs: Attr[];
190
+ skuCode: string;
191
+ }[];
192
+ }
193
+ interface productQrCode {
194
+ qrCodeUrl: string;
195
+ }
196
+ }
197
+ /**
198
+ * ProductLive Controller 接口定义
199
+ */
200
+ interface ProductController {
201
+ /**
202
+ * 商品列表
203
+ */
204
+ list(request: Service.Request.list): Promise<Service.Response.list>;
205
+ /**
206
+ * 创建商品
207
+ */
208
+ create(request: Service.ProductData): Promise<Service.Response.create>;
209
+ /**
210
+ * 商品详情
211
+ */
212
+ detail(request: Service.Request.detail): Promise<Service.ProductData>;
213
+ /**
214
+ * 商品更新
215
+ */
216
+ update(request: Service.ProductData): Promise<void>;
217
+ /**
218
+ * 批量更新
219
+ */
220
+ batchUpdate(request: Service.Request.batchUpdate): Promise<void>;
221
+ /**
222
+ * 查询定时任务任务
223
+ */
224
+ queryScheduledTask(request: Service.Request.queryScheduledTask): Promise<Service.Response.queryScheduledTask[]>;
225
+ /**
226
+ * 校验69码是否重复
227
+ */
228
+ checkSkuCode(request: Service.Request.checkSkuCode): Promise<Service.Response.checkSkuCode>;
229
+ /**
230
+ * 商品导出
231
+ */
232
+ export(request: Service.Request.list): Promise<void>;
233
+ /**
234
+ * 获取商品信息(不含规格信息)
235
+ */
236
+ queryProductList(request: Service.Request.queryProductList): Promise<Service.Response.queryProductList>;
237
+ /**
238
+ * 获取商品+规格信息
239
+ */
240
+ queryProductSkuList(request: Service.Request.queryProductList): Promise<Service.Response.queryProductSkuList>;
241
+ /**
242
+ * 商品二维码
243
+ */
244
+ productQrCode(request: Service.Request.productQrCode): Promise<Service.Response.productQrCode>;
245
+ }
246
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class ProductExpService extends BaseService implements Service.ProductExpController {
4
+ protected prefixUrl: string;
5
+ getSupplierList(): Promise<Service.Response.getSupplierList[]>;
6
+ addSupplier(request: Service.Request.addSupplier): Promise<Service.Response.addSupplier>;
7
+ getLiveGroupList(): Promise<Service.Response.getLiveGroupList[]>;
8
+ addLiveGroup(request: Service.Request.addLiveGroup): Promise<Service.Response.addLiveGroup>;
9
+ productCategoryTree(): Promise<Service.Response.ProductCategoryTree>;
10
+ getProductManagerList(): Promise<Service.Response.getProductManagerList>;
11
+ }
12
+ export declare const productExpService: ProductExpService;
13
+ export default productExpService;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
+ return function (target, key) { decorator(target, key, paramIndex); }
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.productExpService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let ProductExpService = class ProductExpService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/product-exp';
23
+ }
24
+ getSupplierList() {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.getSupplierList));
26
+ }
27
+ addSupplier(request) {
28
+ return (0, http_1.callApi)(this.getApiUrl(this.addSupplier), request);
29
+ }
30
+ getLiveGroupList() {
31
+ return (0, http_1.callApi)(this.getApiUrl(this.getLiveGroupList));
32
+ }
33
+ addLiveGroup(request) {
34
+ return (0, http_1.callApi)(this.getApiUrl(this.addLiveGroup), request);
35
+ }
36
+ productCategoryTree() {
37
+ return (0, http_1.callApi)(this.getApiUrl(this.productCategoryTree));
38
+ }
39
+ getProductManagerList() {
40
+ return (0, http_1.callApi)(this.getApiUrl(this.getProductManagerList));
41
+ }
42
+ };
43
+ __decorate([
44
+ (0, tsoa_1.OperationId)('获取供应商列表'),
45
+ (0, tsoa_1.Post)('get-supplier-list')
46
+ ], ProductExpService.prototype, "getSupplierList", null);
47
+ __decorate([
48
+ (0, tsoa_1.OperationId)('新增供应商'),
49
+ (0, tsoa_1.Post)('add-supplier'),
50
+ __param(0, (0, tsoa_1.Body)())
51
+ ], ProductExpService.prototype, "addSupplier", null);
52
+ __decorate([
53
+ (0, tsoa_1.OperationId)('获取直播分组列表'),
54
+ (0, tsoa_1.Post)('get-live-group-list')
55
+ ], ProductExpService.prototype, "getLiveGroupList", null);
56
+ __decorate([
57
+ (0, tsoa_1.OperationId)('新增直播分组'),
58
+ (0, tsoa_1.Post)('add-live-group'),
59
+ __param(0, (0, tsoa_1.Body)())
60
+ ], ProductExpService.prototype, "addLiveGroup", null);
61
+ __decorate([
62
+ (0, tsoa_1.OperationId)('商品分类 树结构'),
63
+ (0, tsoa_1.Post)('product-category-tree')
64
+ ], ProductExpService.prototype, "productCategoryTree", null);
65
+ __decorate([
66
+ (0, tsoa_1.OperationId)('获取产品经理列表'),
67
+ (0, tsoa_1.Post)('get-product-manager-list')
68
+ ], ProductExpService.prototype, "getProductManagerList", null);
69
+ ProductExpService = __decorate([
70
+ (0, tsoa_1.Route)('product-exp'),
71
+ (0, tsoa_1.Tags)('Product-exp')
72
+ ], ProductExpService);
73
+ exports.productExpService = new ProductExpService();
74
+ exports.default = exports.productExpService;
@@ -0,0 +1,80 @@
1
+ export declare namespace Service {
2
+ interface ProductCategory {
3
+ id: string;
4
+ parentId: string;
5
+ level: string;
6
+ categoryName: string;
7
+ }
8
+ namespace Request {
9
+ interface addSupplier {
10
+ supplierName: string;
11
+ creatorId: string;
12
+ }
13
+ interface addLiveGroup {
14
+ liveGroupName: string;
15
+ creatorId: string;
16
+ }
17
+ }
18
+ namespace Response {
19
+ interface addSupplier {
20
+ supplierId: string;
21
+ }
22
+ interface getSupplierList {
23
+ supplierId: string;
24
+ supplierName: string;
25
+ }
26
+ interface addLiveGroup {
27
+ liveGroupId: string;
28
+ }
29
+ interface getLiveGroupList {
30
+ liveGroupId: string;
31
+ liveGroupName: string;
32
+ }
33
+ interface ProductCategoryTree extends ProductCategory {
34
+ children?: ProductCategoryTree[];
35
+ }
36
+ interface list {
37
+ total: number;
38
+ list: {
39
+ productId: string;
40
+ productName: string;
41
+ productImage: string;
42
+ price: number;
43
+ stock: number;
44
+ }[];
45
+ }
46
+ interface getProductManagerList {
47
+ productManagerId: string;
48
+ productManagerName: string;
49
+ }
50
+ }
51
+ /**
52
+ * ProductLive Controller 接口定义
53
+ */
54
+ interface ProductExpController {
55
+ /**
56
+ * 获取供应商列表
57
+ */
58
+ getSupplierList(): Promise<Service.Response.getSupplierList[]>;
59
+ /**
60
+ * 新增供应商
61
+ */
62
+ addSupplier(request: Service.Request.addSupplier): Promise<Service.Response.addSupplier>;
63
+ /**
64
+ * 获取直播分组列表
65
+ */
66
+ getLiveGroupList(): Promise<Service.Response.getLiveGroupList[]>;
67
+ /**
68
+ * 新增直播分组
69
+ */
70
+ addLiveGroup(request: Service.Request.addLiveGroup): Promise<Service.Response.addLiveGroup>;
71
+ /**
72
+ * 商品分类 树结构
73
+ */
74
+ productCategoryTree(): Promise<Service.Response.ProductCategoryTree>;
75
+ /**
76
+ * 获取产品经理列表
77
+ */
78
+ getProductManagerList(): Promise<Service.Response.getProductManagerList>;
79
+ }
80
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class ProductLiveService extends BaseService implements Service.ProductLiveController {
4
+ protected prefixUrl: string;
5
+ list(request: Service.Request.list): Promise<Service.Response.list>;
6
+ add(request: Service.Request.operate): Promise<void>;
7
+ remove(request: Service.Request.operate): Promise<void>;
8
+ }
9
+ export declare const productLiveService: ProductLiveService;
10
+ export default productLiveService;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
+ return function (target, key) { decorator(target, key, paramIndex); }
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.productLiveService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let ProductLiveService = class ProductLiveService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/product-live';
23
+ }
24
+ list(request) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.list), request);
26
+ }
27
+ add(request) {
28
+ return (0, http_1.callApi)(this.getApiUrl(this.add), request);
29
+ }
30
+ remove(request) {
31
+ return (0, http_1.callApi)(this.getApiUrl(this.remove), request);
32
+ }
33
+ };
34
+ __decorate([
35
+ (0, tsoa_1.OperationId)('商品列表'),
36
+ (0, tsoa_1.Post)('list'),
37
+ __param(0, (0, tsoa_1.Body)())
38
+ ], ProductLiveService.prototype, "list", null);
39
+ __decorate([
40
+ (0, tsoa_1.OperationId)('新增商品'),
41
+ (0, tsoa_1.Post)('add'),
42
+ __param(0, (0, tsoa_1.Body)())
43
+ ], ProductLiveService.prototype, "add", null);
44
+ __decorate([
45
+ (0, tsoa_1.OperationId)('删除商品'),
46
+ (0, tsoa_1.Post)('remove'),
47
+ __param(0, (0, tsoa_1.Body)())
48
+ ], ProductLiveService.prototype, "remove", null);
49
+ ProductLiveService = __decorate([
50
+ (0, tsoa_1.Route)('product-live'),
51
+ (0, tsoa_1.Tags)('Product-live')
52
+ ], ProductLiveService);
53
+ exports.productLiveService = new ProductLiveService();
54
+ exports.default = exports.productLiveService;
@@ -0,0 +1,42 @@
1
+ export declare namespace Service {
2
+ namespace Request {
3
+ interface list {
4
+ pageIndex: number;
5
+ pageSize: number;
6
+ liveRoomId: string;
7
+ }
8
+ interface operate {
9
+ productId: string;
10
+ liveRoomId: string;
11
+ }
12
+ }
13
+ namespace Response {
14
+ interface list {
15
+ total: number;
16
+ list: {
17
+ productId: string;
18
+ productName: string;
19
+ productImage: string;
20
+ price: number;
21
+ stock: number;
22
+ }[];
23
+ }
24
+ }
25
+ /**
26
+ * ProductLive Controller 接口定义
27
+ */
28
+ interface ProductLiveController {
29
+ /**
30
+ * 商品列表
31
+ */
32
+ list(request: Service.Request.list): Promise<Service.Response.list>;
33
+ /**
34
+ * 新增商品
35
+ */
36
+ add(request: Service.Request.operate): Promise<void>;
37
+ /**
38
+ * 删除商品
39
+ */
40
+ remove(request: Service.Request.operate): Promise<void>;
41
+ }
42
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@be-link/ecommerce-product-service-node-sdk",
3
+ "version": "0.0.1",
4
+ "description": "EcommerceProductService Node.js SDK",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "author": "",
8
+ "license": "ISC",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "@fastify/request-context": "6.2.1",
14
+ "axios": "1.13.2",
15
+ "axios-retry": "4.0.0",
16
+ "uuid": "9.0.1"
17
+ },
18
+ "devDependencies": {
19
+ "tsoa": "^6.6.0"
20
+ },
21
+ "scripts": {
22
+ "build": "rm -rf ./dist && tsc && cp package.json README.md ./dist/ 2>/dev/null || true",
23
+ "test": "jest",
24
+ "swagger": "tsoa spec",
25
+ "build:swagger": "npm run swagger && npm run build && npm run swagger",
26
+ "auto-generate": "node scripts/auto-generate.js"
27
+ }
28
+ }
package/utils/env.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare class EnvUtils {
2
+ /**
3
+ * 判断是否为生产环境
4
+ */
5
+ isProduction(): boolean;
6
+ /**
7
+ * 获取环境变量
8
+ */
9
+ getEnv(key: string, defaultValue?: string): string | undefined;
10
+ }
11
+ declare const envUtils: EnvUtils;
12
+ export default envUtils;
package/utils/env.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class EnvUtils {
4
+ /**
5
+ * 判断是否为生产环境
6
+ */
7
+ isProduction() {
8
+ return process.env.NODE_ENV === 'prod';
9
+ }
10
+ /**
11
+ * 获取环境变量
12
+ */
13
+ getEnv(key, defaultValue) {
14
+ return process.env[key] || defaultValue;
15
+ }
16
+ }
17
+ const envUtils = new EnvUtils();
18
+ exports.default = envUtils;
@@ -0,0 +1,7 @@
1
+ declare module '@fastify/request-context' {
2
+ interface RequestContextData {
3
+ requestId?: string;
4
+ traceMessageId?: string;
5
+ }
6
+ }
7
+ export declare function callApi<T extends (...args: any[]) => Promise<any>>(url: string, request?: Parameters<T>[0]): Promise<Awaited<ReturnType<T>>>;
package/utils/http.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.callApi = callApi;
40
+ const axios_1 = __importDefault(require("axios"));
41
+ const uuid_1 = require("uuid");
42
+ const axios_retry_1 = __importDefault(require("axios-retry"));
43
+ const request_context_1 = require("@fastify/request-context");
44
+ (0, axios_retry_1.default)(axios_1.default, {
45
+ retries: 1,
46
+ retryCondition(error) {
47
+ return error.response?.status === 502;
48
+ },
49
+ retryDelay: (retryCount) => {
50
+ console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`);
51
+ return retryCount * 500;
52
+ },
53
+ onRetry(retryCount, error, requestConfig) {
54
+ console.info(`retryCount: ${retryCount}, onRetry: ${error.message}, requestHeader: ${JSON.stringify(requestConfig.headers)}`);
55
+ },
56
+ });
57
+ async function callApi(url, request) {
58
+ const requestId = request_context_1.requestContext.get('requestId') || request_context_1.requestContext.get('traceMessageId') || (0, uuid_1.v4)();
59
+ try {
60
+ console.info(`准备发起ecommerce-product-service请求[${requestId}]: ${url}, 参数: ${JSON.stringify(request)}`);
61
+ const response = await axios_1.default.post(url, request, { headers: { 'x-request-id': requestId } });
62
+ const responseData = response.data;
63
+ return responseData.data;
64
+ }
65
+ catch (error) {
66
+ const axiosError = error;
67
+ if (axiosError.response) {
68
+ const response = axiosError.response;
69
+ const data = response.data;
70
+ console.error(`ecommerce-product-service 异常: ${axiosError.message},requestId: ${requestId}`);
71
+ console.info('响应信息', data.message);
72
+ console.error('异常堆栈', JSON.stringify(error.stack));
73
+ throw new Error(data.errorType + ' - ' + data.message);
74
+ }
75
+ // 调用dns模块解析url
76
+ const dns = await Promise.resolve().then(() => __importStar(require('dns')));
77
+ const dnsPromise = new Promise((resolve, reject) => {
78
+ const lookupRes = dns.lookup(url, (err, address) => {
79
+ if (err) {
80
+ console.error(err.message);
81
+ reject(err);
82
+ }
83
+ console.info(`lookup: ${JSON.stringify(lookupRes)}`);
84
+ resolve(address);
85
+ });
86
+ });
87
+ try {
88
+ const address = await dnsPromise;
89
+ console.info(`address: ${JSON.stringify(address)}`);
90
+ }
91
+ catch (error) {
92
+ console.info(`error: ${JSON.stringify(error)}`);
93
+ }
94
+ console.error(`ecommerce-product-service 未知异常: ${axiosError.message}`, error.stack);
95
+ throw error;
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 将驼峰命名转换为短横线命名
3
+ * @param str 驼峰命名字符串
4
+ * @returns 短横线命名字符串
5
+ * @example
6
+ * camelToKebabCase('fetchConfig') // 'fetch-config'
7
+ * camelToKebabCase('getCosTempSecret') // 'get-cos-temp-secret'
8
+ */
9
+ export declare function camelToKebabCase(str: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelToKebabCase = camelToKebabCase;
4
+ /**
5
+ * 将驼峰命名转换为短横线命名
6
+ * @param str 驼峰命名字符串
7
+ * @returns 短横线命名字符串
8
+ * @example
9
+ * camelToKebabCase('fetchConfig') // 'fetch-config'
10
+ * camelToKebabCase('getCosTempSecret') // 'get-cos-temp-secret'
11
+ */
12
+ function camelToKebabCase(str) {
13
+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
14
+ }