@be-link/ecommerce-trade-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
+ # EcommerceTradeService SDK
2
+
3
+ EcommerceTradeService Node.js SDK - 敏感信息管理服务客户端
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @be-link/ecommerce-trade-service-node-sdk
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```typescript
14
+ import { demoService } from '@be-link/ecommerce-trade-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/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { configService } from './modules/config/service';
2
+ export type { Service as DemoControllerTypes } from './modules/config/types';
3
+ export * as POS from './modules/pos';
4
+ export type { PosOrderQueryTypes } from './modules/pos';
5
+ export * as ROS from './modules/ros';
6
+ export type { RosOrderQueryTypes } from './modules/ros';
package/index.js ADDED
@@ -0,0 +1,40 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ROS = exports.POS = exports.configService = void 0;
37
+ var service_1 = require("./modules/config/service");
38
+ Object.defineProperty(exports, "configService", { enumerable: true, get: function () { return service_1.configService; } });
39
+ exports.POS = __importStar(require("./modules/pos"));
40
+ exports.ROS = __importStar(require("./modules/ros"));
@@ -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,8 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class ConfigService extends BaseService implements Service.DemoController {
4
+ protected prefixUrl: string;
5
+ demoFunc(request: Service.Request.demoFunc, req: any): Promise<Service.Response.demoFunc>;
6
+ }
7
+ export declare const configService: ConfigService;
8
+ export default configService;
@@ -0,0 +1,38 @@
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.configService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let ConfigService = class ConfigService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/config';
23
+ }
24
+ demoFunc(request, req) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.demoFunc), request);
26
+ }
27
+ };
28
+ __decorate([
29
+ (0, tsoa_1.OperationId)('示例接口'),
30
+ (0, tsoa_1.Post)('demo-func'),
31
+ __param(0, (0, tsoa_1.Body)())
32
+ ], ConfigService.prototype, "demoFunc", null);
33
+ ConfigService = __decorate([
34
+ (0, tsoa_1.Route)('config'),
35
+ (0, tsoa_1.Tags)('Config')
36
+ ], ConfigService);
37
+ exports.configService = new ConfigService();
38
+ exports.default = exports.configService;
@@ -0,0 +1,17 @@
1
+ export declare namespace Service {
2
+ namespace Entity { }
3
+ namespace Request {
4
+ interface demoFunc {
5
+ /** 参数 */
6
+ demoParam: string;
7
+ }
8
+ }
9
+ namespace Response {
10
+ interface demoFunc {
11
+ }
12
+ }
13
+ interface DemoController {
14
+ /** 示例接口 */
15
+ demoFunc(request: Service.Request.demoFunc, req: any): Promise<Service.Response.demoFunc>;
16
+ }
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { Service } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class Config2Service extends BaseService implements Service.Demo2Controller {
4
+ protected prefixUrl: string;
5
+ demoFunc2(request: Service.Request.demoFunc2): Promise<Service.Response.demoFunc2>;
6
+ }
7
+ export declare const config2Service: Config2Service;
8
+ export default config2Service;
@@ -0,0 +1,38 @@
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.config2Service = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let Config2Service = class Config2Service extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/config2';
23
+ }
24
+ demoFunc2(request) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.demoFunc2), request);
26
+ }
27
+ };
28
+ __decorate([
29
+ (0, tsoa_1.OperationId)('示例接口2'),
30
+ (0, tsoa_1.Post)('demo-func2'),
31
+ __param(0, (0, tsoa_1.Body)())
32
+ ], Config2Service.prototype, "demoFunc2", null);
33
+ Config2Service = __decorate([
34
+ (0, tsoa_1.Route)('config2'),
35
+ (0, tsoa_1.Tags)('Config2')
36
+ ], Config2Service);
37
+ exports.config2Service = new Config2Service();
38
+ exports.default = exports.config2Service;
@@ -0,0 +1,22 @@
1
+ export declare namespace Service {
2
+ namespace Entity { }
3
+ namespace Request {
4
+ interface demoFunc2 {
5
+ /** 参数 */
6
+ demoParam: string;
7
+ }
8
+ }
9
+ namespace Response {
10
+ interface demoFunc2 {
11
+ /**
12
+ * 结果
13
+ * @minLength 255
14
+ */
15
+ demoResult: string;
16
+ }
17
+ }
18
+ interface Demo2Controller {
19
+ /** 示例接口2 */
20
+ demoFunc2(request: Service.Request.demoFunc2, req: any): Promise<Service.Response.demoFunc2>;
21
+ }
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export { orderQueryService } from './orderQuery/web';
2
+ export type { Service as PosOrderQueryTypes } from './orderQuery/types';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orderQueryService = void 0;
4
+ var web_1 = require("./orderQuery/web");
5
+ Object.defineProperty(exports, "orderQueryService", { enumerable: true, get: function () { return web_1.orderQueryService; } });
@@ -0,0 +1,35 @@
1
+ import * as DTO from '../../../types';
2
+ export declare namespace Service {
3
+ namespace Entity { }
4
+ namespace Request {
5
+ interface IOrderList<K> {
6
+ /** 查询条件 */
7
+ conditions?: {};
8
+ /** 分页 */
9
+ pagination: {
10
+ /** 页码(从0开始) */
11
+ pageIndex: number;
12
+ /** 每页数量 */
13
+ pageSize: number;
14
+ };
15
+ /** 排序 */
16
+ sort?: {
17
+ /** 订单创建时间 */
18
+ createdAt?: 'ASC' | 'DESC';
19
+ /** 订单支付时间 */
20
+ payTime?: 'ASC' | 'DESC';
21
+ /** 完结时间 */
22
+ completedAt?: 'ASC' | 'DESC';
23
+ };
24
+ queryBlocks: K[];
25
+ }
26
+ }
27
+ namespace Response {
28
+ interface IOrderList {
29
+ }
30
+ }
31
+ interface QueryByWebController {
32
+ /** 示例接口 */
33
+ orderList<K extends (keyof DTO.PosQueryBlockMap)[]>(request: Service.Request.IOrderList<K>): Promise<DTO.PosQueryResult<K>[]>;
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,9 @@
1
+ import { Service } from './types';
2
+ import * as DTO from '../../../types';
3
+ import BaseService from '../../BaseService';
4
+ declare class OrderQueryService extends BaseService implements Service.QueryByWebController {
5
+ protected prefixUrl: string;
6
+ orderList<K extends (keyof DTO.PosQueryBlockMap)[]>(request: Service.Request.IOrderList<K>): Promise<DTO.PosQueryResult<K>[]>;
7
+ }
8
+ export declare const orderQueryService: OrderQueryService;
9
+ export default orderQueryService;
@@ -0,0 +1,38 @@
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.orderQueryService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../../BaseService"));
19
+ let OrderQueryService = class OrderQueryService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/pos/query';
23
+ }
24
+ orderList(request) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.orderList), request);
26
+ }
27
+ };
28
+ __decorate([
29
+ (0, tsoa_1.OperationId)('订单列表查询'),
30
+ (0, tsoa_1.Post)('order-list'),
31
+ __param(0, (0, tsoa_1.Body)())
32
+ ], OrderQueryService.prototype, "orderList", null);
33
+ OrderQueryService = __decorate([
34
+ (0, tsoa_1.Route)('pos/query'),
35
+ (0, tsoa_1.Tags)('PosOrderQuery')
36
+ ], OrderQueryService);
37
+ exports.orderQueryService = new OrderQueryService();
38
+ exports.default = exports.orderQueryService;
@@ -0,0 +1,2 @@
1
+ export { orderQueryService } from './orderQuery/web';
2
+ export type { Service as RosOrderQueryTypes } from './orderQuery/types';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orderQueryService = void 0;
4
+ var web_1 = require("./orderQuery/web");
5
+ Object.defineProperty(exports, "orderQueryService", { enumerable: true, get: function () { return web_1.orderQueryService; } });
@@ -0,0 +1,45 @@
1
+ import * as DTO from '../../../types';
2
+ export declare namespace Service {
3
+ namespace Entity { }
4
+ namespace Request {
5
+ interface IOrderList<K> {
6
+ /** 查询条件 */
7
+ conditions?: {
8
+ createdAt: string;
9
+ operateTime: string;
10
+ orderTime: string;
11
+ status: string;
12
+ arrivalStatusList: string[];
13
+ wayList: string[];
14
+ typeList: string[];
15
+ userIds: string[];
16
+ orderIds: string[];
17
+ storeIds: string[];
18
+ };
19
+ /** 分页 */
20
+ pagination: {
21
+ /** 页码(从0开始) */
22
+ pageIndex: number;
23
+ /** 每页数量 */
24
+ pageSize: number;
25
+ };
26
+ /** 排序 */
27
+ sort?: {
28
+ /** 订单创建时间 */
29
+ createdAt?: 'ASC' | 'DESC';
30
+ /** 订单支付时间 */
31
+ payTime?: 'ASC' | 'DESC';
32
+ /** 完结时间 */
33
+ completedAt?: 'ASC' | 'DESC';
34
+ };
35
+ queryBlocks: K[];
36
+ }
37
+ }
38
+ namespace Response {
39
+ interface IOrderList {
40
+ }
41
+ }
42
+ interface QueryByWebController {
43
+ orderList<K extends (keyof DTO.ReverseQueryBlockMap)[]>(request: Service.Request.IOrderList<K>): Promise<DTO.ReverseQueryResult<K>[]>;
44
+ }
45
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Service } from './types';
2
+ import * as DTO from '../../../types';
3
+ import BaseService from '../../BaseService';
4
+ declare class OrderQueryService extends BaseService implements Service.QueryByWebController {
5
+ protected prefixUrl: string;
6
+ orderList<K extends (keyof DTO.ReverseQueryBlockMap)[]>(request: Service.Request.IOrderList<K>): Promise<DTO.ReverseQueryResult<K>[]>;
7
+ }
8
+ export declare const orderQueryService: OrderQueryService;
9
+ export default orderQueryService;
@@ -0,0 +1,38 @@
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.orderQueryService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../../BaseService"));
19
+ let OrderQueryService = class OrderQueryService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/ros/query';
23
+ }
24
+ orderList(request) {
25
+ return (0, http_1.callApi)(this.getApiUrl(this.orderList), request);
26
+ }
27
+ };
28
+ __decorate([
29
+ (0, tsoa_1.OperationId)('订单列表查询'),
30
+ (0, tsoa_1.Post)('order-list'),
31
+ __param(0, (0, tsoa_1.Body)())
32
+ ], OrderQueryService.prototype, "orderList", null);
33
+ OrderQueryService = __decorate([
34
+ (0, tsoa_1.Route)('ros/query'),
35
+ (0, tsoa_1.Tags)('RosOrderQuery')
36
+ ], OrderQueryService);
37
+ exports.orderQueryService = new OrderQueryService();
38
+ exports.default = exports.orderQueryService;
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@be-link/ecommerce-trade-service-node-sdk",
3
+ "version": "0.0.1",
4
+ "description": "EcommerceTradeService 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/types.d.ts ADDED
@@ -0,0 +1,178 @@
1
+ /** 正向订单 */
2
+ /** 基础信息 */
3
+ export interface ITradeOrder {
4
+ id: string;
5
+ userId: string;
6
+ openId: string;
7
+ unionId: string;
8
+ source: string;
9
+ platform: string;
10
+ osType: string;
11
+ status: string;
12
+ payStatus: string;
13
+ verificationStatus: string;
14
+ storeId: string;
15
+ liveRoomId: string;
16
+ liveRoomGroupId: string;
17
+ totalAmount: number;
18
+ actualAmount: number;
19
+ remainAmount: number;
20
+ pointsNum: number;
21
+ receiverName: string;
22
+ receiverPhone: string;
23
+ payTime: number;
24
+ completedAt: number;
25
+ createdAt: number;
26
+ updatedAt: number;
27
+ }
28
+ export interface ITradeOrderAttributes {
29
+ id: string;
30
+ attributes: string;
31
+ isMemberOrder: boolean;
32
+ isCombo: boolean;
33
+ isVirtual: boolean;
34
+ isVerification: boolean;
35
+ isOneRmbMember: boolean;
36
+ isFreeGift: boolean;
37
+ isLivePlayback: boolean;
38
+ createdAt: number;
39
+ updatedAt: number;
40
+ }
41
+ export interface ITradeOrderSkuInfo {
42
+ id: string;
43
+ orderId: string;
44
+ quantity: number;
45
+ productSnapshot: Object;
46
+ skuSnapshot: Object;
47
+ productId: string | null;
48
+ productSkuId: string | null;
49
+ skuCode: string | null;
50
+ productPrice: string | null;
51
+ createdAt: number;
52
+ updatedAt: number;
53
+ }
54
+ export interface ITradeOrderItem {
55
+ id: string;
56
+ orderId: string;
57
+ userId: string;
58
+ storeId: string;
59
+ productId: string;
60
+ productName: string;
61
+ skuId: string;
62
+ skuCode: string;
63
+ productPrice: number;
64
+ productImg: string;
65
+ productCate: string;
66
+ productDispatch: string;
67
+ productPick: string;
68
+ verificationStatus: string;
69
+ verificationStartTime: number;
70
+ verificationEndTime: number;
71
+ receiverAddress: string;
72
+ logisticsNo: string;
73
+ logisticsInfo: Object | null;
74
+ createdAt: number;
75
+ updatedAt: number;
76
+ }
77
+ export interface ITradeOrderPayment {
78
+ id: string;
79
+ orderId: string;
80
+ payChannel: string;
81
+ payPlatform: string;
82
+ payAmount: number;
83
+ payType: string;
84
+ outBizId: string;
85
+ extraInfo: Object | null;
86
+ createdAt: number;
87
+ updatedAt: number;
88
+ }
89
+ export interface ITradeOrderPromotion {
90
+ id: string;
91
+ orderId: string;
92
+ type: string;
93
+ quantity: number;
94
+ discount: number;
95
+ snapshot: Object | null;
96
+ createdAt: number;
97
+ updatedAt: number;
98
+ }
99
+ /** 正向订单查询块映射 */
100
+ export interface PosQueryBlockMap {
101
+ /** 订单Id */
102
+ id: string;
103
+ /** 主要信息 */
104
+ basicInfo: ITradeOrder;
105
+ /** 标记信息 */
106
+ attributes: ITradeOrderAttributes;
107
+ /** 商品SKU快照信息 */
108
+ skuInfo: ITradeOrderSkuInfo[];
109
+ /** 订单商品项信息 */
110
+ itemInfo: ITradeOrderItem[];
111
+ /** 支付信息 */
112
+ paymentInfo: ITradeOrderPayment[];
113
+ /** 营销信息 */
114
+ promotionInfo: ITradeOrderPromotion[];
115
+ }
116
+ /** 正向订单查询结果 */
117
+ export type PosQueryResult<K extends (keyof PosQueryBlockMap)[]> = {
118
+ [key in K[number]]: PosQueryBlockMap[key];
119
+ };
120
+ /** 逆向订单 ------------------------------------------------------------------ */
121
+ export interface ITradeReverseOrder {
122
+ id: string;
123
+ orderId: string;
124
+ userId: string;
125
+ unionId: string;
126
+ openId: string;
127
+ liveRoomId: string;
128
+ storeId: string;
129
+ amount: number;
130
+ points: number;
131
+ quantity: number;
132
+ status: string;
133
+ type: string;
134
+ way: string;
135
+ reason: string;
136
+ comment: string;
137
+ isAllRefunded: boolean;
138
+ refundAt: number;
139
+ payTime: number;
140
+ attachments: Object | null;
141
+ operator: string;
142
+ operateTime: number;
143
+ createdAt: number;
144
+ updatedAt: number;
145
+ }
146
+ export interface ITradeReverseOrderResource {
147
+ id: string;
148
+ orderId: string;
149
+ reverseOrderId: string;
150
+ resourceType: string;
151
+ bizId: string;
152
+ bizExtraInfo: Object;
153
+ bizValue: number;
154
+ isRefunded: boolean;
155
+ refundedAt: number;
156
+ createdAt: number;
157
+ updatedAt: number;
158
+ }
159
+ export interface ITradeReverseOrderOperateRecord {
160
+ id: string;
161
+ orderId: string;
162
+ reverseOrderId: string;
163
+ operator: string;
164
+ fromStatus: string;
165
+ toStatus: string;
166
+ reason: string;
167
+ createdAt: number;
168
+ updatedAt: number;
169
+ }
170
+ export interface ReverseQueryBlockMap {
171
+ id: string;
172
+ basicInfo: ITradeReverseOrder;
173
+ resourceInfo: ITradeReverseOrderResource[];
174
+ operateRecords: ITradeReverseOrderOperateRecord[];
175
+ }
176
+ export type ReverseQueryResult<K extends (keyof ReverseQueryBlockMap)[]> = {
177
+ [key in K[number]]: ReverseQueryBlockMap[key];
178
+ };
package/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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-trade-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-trade-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-trade-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
+ }