@be-link/ecommerce-backend-bff-service-node-sdk 0.0.1 → 0.0.3
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/bff/modules/demo/service.js +2 -21
- package/bff/modules/example/service.js +2 -31
- package/bff/request/client.js +4 -2
- package/package.json +3 -3
- package/types/index.d.ts +1 -0
- package/utils/env.js +8 -3
|
@@ -1,24 +1,14 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const tsoa_1 = require("tsoa");
|
|
16
6
|
const BaseService_1 = __importDefault(require("../BaseService"));
|
|
17
7
|
/**
|
|
18
8
|
* DemoService - Demo 服务模块
|
|
19
9
|
* 提供 Demo 相关的 API 方法
|
|
20
10
|
*/
|
|
21
|
-
|
|
11
|
+
class DemoService extends BaseService_1.default {
|
|
22
12
|
constructor() {
|
|
23
13
|
super(...arguments);
|
|
24
14
|
this.prefixUrl = '/demo';
|
|
@@ -36,14 +26,5 @@ let DemoService = class DemoService extends BaseService_1.default {
|
|
|
36
26
|
demoFunc(request) {
|
|
37
27
|
return this.request(this.demoFunc, request);
|
|
38
28
|
}
|
|
39
|
-
}
|
|
40
|
-
__decorate([
|
|
41
|
-
(0, tsoa_1.OperationId)('示例接口'),
|
|
42
|
-
(0, tsoa_1.Post)('demo-func'),
|
|
43
|
-
__param(0, (0, tsoa_1.Body)())
|
|
44
|
-
], DemoService.prototype, "demoFunc", null);
|
|
45
|
-
DemoService = __decorate([
|
|
46
|
-
(0, tsoa_1.Route)('demo'),
|
|
47
|
-
(0, tsoa_1.Tags)('Demo')
|
|
48
|
-
], DemoService);
|
|
29
|
+
}
|
|
49
30
|
exports.default = DemoService;
|
|
@@ -1,25 +1,15 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.ExampleService = void 0;
|
|
16
|
-
const tsoa_1 = require("tsoa");
|
|
17
7
|
const BaseService_1 = __importDefault(require("../BaseService"));
|
|
18
8
|
/**
|
|
19
9
|
* ExampleService - 演示如何创建服务模块
|
|
20
10
|
* 此服务提供用户资料和订单管理的示例方法
|
|
21
11
|
*/
|
|
22
|
-
|
|
12
|
+
class ExampleService extends BaseService_1.default {
|
|
23
13
|
constructor() {
|
|
24
14
|
super(...arguments);
|
|
25
15
|
/**
|
|
@@ -66,24 +56,5 @@ let ExampleService = class ExampleService extends BaseService_1.default {
|
|
|
66
56
|
async getOrderList(request) {
|
|
67
57
|
return this.request(this.getOrderList, request);
|
|
68
58
|
}
|
|
69
|
-
}
|
|
59
|
+
}
|
|
70
60
|
exports.ExampleService = ExampleService;
|
|
71
|
-
__decorate([
|
|
72
|
-
(0, tsoa_1.OperationId)('获取用户资料'),
|
|
73
|
-
(0, tsoa_1.Post)('get-user-profile'),
|
|
74
|
-
__param(0, (0, tsoa_1.Body)())
|
|
75
|
-
], ExampleService.prototype, "getUserProfile", null);
|
|
76
|
-
__decorate([
|
|
77
|
-
(0, tsoa_1.OperationId)('更新用户资料'),
|
|
78
|
-
(0, tsoa_1.Post)('update-profile'),
|
|
79
|
-
__param(0, (0, tsoa_1.Body)())
|
|
80
|
-
], ExampleService.prototype, "updateProfile", null);
|
|
81
|
-
__decorate([
|
|
82
|
-
(0, tsoa_1.OperationId)('获取订单列表'),
|
|
83
|
-
(0, tsoa_1.Post)('get-order-list'),
|
|
84
|
-
__param(0, (0, tsoa_1.Body)())
|
|
85
|
-
], ExampleService.prototype, "getOrderList", null);
|
|
86
|
-
exports.ExampleService = ExampleService = __decorate([
|
|
87
|
-
(0, tsoa_1.Route)('api/v1/user'),
|
|
88
|
-
(0, tsoa_1.Tags)('User')
|
|
89
|
-
], ExampleService);
|
package/bff/request/client.js
CHANGED
|
@@ -37,9 +37,10 @@ class HttpClient {
|
|
|
37
37
|
*/
|
|
38
38
|
async request(opts) {
|
|
39
39
|
// 并发获取凭证,带错误处理
|
|
40
|
-
const [token, userId] = await Promise.all([
|
|
40
|
+
const [token, userId, ruleId] = await Promise.all([
|
|
41
41
|
Promise.resolve(this.options.getToken()).catch(() => ''),
|
|
42
42
|
Promise.resolve(this.options.getUserId()).catch(() => ''),
|
|
43
|
+
Promise.resolve(this.options.getRuleId?.() ?? '').catch(() => ''),
|
|
43
44
|
]);
|
|
44
45
|
// 生成唯一的请求 ID
|
|
45
46
|
const requestId = `b-${crypto.randomUUID()}`;
|
|
@@ -48,7 +49,8 @@ class HttpClient {
|
|
|
48
49
|
'Content-Type': 'application/json',
|
|
49
50
|
'X-Request-Id': requestId,
|
|
50
51
|
'x-belink-authorization': token,
|
|
51
|
-
'x-belink-userId': userId,
|
|
52
|
+
'x-belink-pandora-userId': userId,
|
|
53
|
+
'x-belink-pandora-ruleId': ruleId,
|
|
52
54
|
};
|
|
53
55
|
// 合并自定义请求头(自定义请求头优先)
|
|
54
56
|
const headers = {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@be-link/ecommerce-backend-bff-service-node-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "EcommerceBackendBffService Node.js SDK",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"publishConfig": {
|
package/types/index.d.ts
CHANGED
package/utils/env.js
CHANGED
|
@@ -18,23 +18,28 @@ function isMiniProgram() {
|
|
|
18
18
|
*/
|
|
19
19
|
function getContainerHost(environment) {
|
|
20
20
|
// 生产环境和测试环境使用不同的主机地址
|
|
21
|
+
// TODO 生产url
|
|
21
22
|
return environment === 'production'
|
|
22
23
|
? 'http://bxbvjnca.tfs.cwl9ok0a.mk2u3r3l.com:8090' // 生产环境
|
|
23
|
-
: '
|
|
24
|
+
: 'https://backend-bff-service-196345-5-1304510571.sh.run.tcloudbase.com'; // 测试环境
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* 根据环境获取微信云环境标识符
|
|
27
28
|
* @param environment - 运行环境 ('production' 或 'test')
|
|
28
29
|
* @returns 云环境标识符
|
|
29
30
|
*/
|
|
31
|
+
// TODO 生产改
|
|
30
32
|
function getContainerEnv(environment) {
|
|
31
|
-
return environment === 'production'
|
|
33
|
+
return environment === 'production'
|
|
34
|
+
? 'ecommerce-dev-1g0iert2838e56dd'
|
|
35
|
+
: 'ecommerce-dev-1g0iert2838e56dd';
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* 根据环境获取微信云服务名称
|
|
35
39
|
* @param environment - 运行环境 ('production' 或 'test')
|
|
36
40
|
* @returns 云服务名称
|
|
37
41
|
*/
|
|
42
|
+
// TODO 生产改
|
|
38
43
|
function getContainerService(environment) {
|
|
39
|
-
return environment === 'production' ? 'bff-
|
|
44
|
+
return environment === 'production' ? 'backend-bff-service' : 'backend-bff-service';
|
|
40
45
|
}
|