@cloudbase/node-sdk 3.17.1-alpha.0 → 3.17.2
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/dist/auth/index.js +0 -4
- package/dist/cloudbase.js +36 -9
- package/dist/utils/tcbapirequester.js +6 -13
- package/dist/utils/tcbcontext.js +0 -1
- package/dist/utils/tcbopenapicommonrequester.js +7 -25
- package/dist/utils/tcbopenapirequester.js +5 -26
- package/dist/utils/utils.js +1 -73
- package/dist/wx/index.js +3 -3
- package/package.json +1 -1
- package/src/auth/index.ts +1 -5
- package/src/cloudbase.ts +38 -9
- package/src/utils/tcbapirequester.ts +6 -12
- package/src/utils/tcbcontext.ts +0 -1
- package/src/utils/tcbdbapirequester.ts +1 -0
- package/src/utils/tcbopenapicommonrequester.ts +8 -22
- package/src/utils/tcbopenapirequester.ts +6 -24
- package/src/utils/utils.ts +0 -62
- package/src/wx/index.ts +3 -3
- package/types/index.d.ts +2 -1
package/dist/auth/index.js
CHANGED
|
@@ -135,10 +135,6 @@ class Auth {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
async getClientCredential(opts) {
|
|
138
|
-
// 如果有 accessKey 直接返回 accessKey,不用再去换取 token
|
|
139
|
-
if (this.cloudbase.config.accessKey) {
|
|
140
|
-
return this.cloudbase.config.accessKey;
|
|
141
|
-
}
|
|
142
138
|
return await tcbopenapicommonrequester.request({
|
|
143
139
|
config: this.cloudbase.config,
|
|
144
140
|
method: 'POST',
|
package/dist/cloudbase.js
CHANGED
|
@@ -22,6 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
25
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
38
|
};
|
|
@@ -38,13 +49,14 @@ const wx_1 = require("./wx");
|
|
|
38
49
|
const analytics_1 = require("./analytics");
|
|
39
50
|
const ai_1 = require("./ai");
|
|
40
51
|
const logger_1 = require("./logger");
|
|
52
|
+
const code_1 = require("./const/code");
|
|
53
|
+
const utils = __importStar(require("./utils/utils"));
|
|
41
54
|
const cloudplatform_1 = require("./utils/cloudplatform");
|
|
42
55
|
const tcbcontext_1 = require("./utils/tcbcontext");
|
|
43
56
|
const notification_1 = require("./notification");
|
|
44
57
|
const openapicommonrequester = __importStar(require("./utils/tcbopenapicommonrequester"));
|
|
45
58
|
const tcbopenapiendpoint_1 = require("./utils/tcbopenapiendpoint");
|
|
46
59
|
const symbol_1 = require("./const/symbol");
|
|
47
|
-
const utils_1 = require("./utils/utils");
|
|
48
60
|
class CloudBase {
|
|
49
61
|
static parseContext(context) {
|
|
50
62
|
const parseResult = (0, tcbcontext_1.parseContext)(context);
|
|
@@ -58,14 +70,33 @@ class CloudBase {
|
|
|
58
70
|
this.init(config);
|
|
59
71
|
}
|
|
60
72
|
init(config = {}) {
|
|
73
|
+
var _a, _b, _c, _d;
|
|
61
74
|
// 预检运行环境,调用与否并不影响后续逻辑
|
|
62
75
|
// 注意:该函数为异步函数,这里并不等待检查结果
|
|
63
76
|
/* eslint-disable-next-line */
|
|
64
77
|
(0, cloudplatform_1.preflightRuntimeCloudPlatform)();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
const { debug, secretId, secretKey, sessionToken, env, timeout, headers = {} } = config, restConfig = __rest(config, ["debug", "secretId", "secretKey", "sessionToken", "env", "timeout", "headers"]);
|
|
79
|
+
if (('secretId' in config && !('secretKey' in config)) || (!('secretId' in config) && 'secretKey' in config)) {
|
|
80
|
+
throw utils.E(Object.assign(Object.assign({}, code_1.ERROR.INVALID_PARAM), { message: 'secretId and secretKey must be a pair' }));
|
|
81
|
+
}
|
|
82
|
+
const newConfig = Object.assign(Object.assign({}, restConfig), { debug: !!debug, secretId,
|
|
83
|
+
secretKey,
|
|
84
|
+
sessionToken,
|
|
85
|
+
env, envName: env, headers: Object.assign({}, headers), timeout: timeout || 15000 });
|
|
86
|
+
if ((_a = config.context) === null || _a === void 0 ? void 0 : _a.extendedContext) {
|
|
87
|
+
const extendedContext = config.context.extendedContext;
|
|
88
|
+
if (!newConfig.env) {
|
|
89
|
+
newConfig.env = extendedContext.envId;
|
|
90
|
+
newConfig.envName = newConfig.env;
|
|
91
|
+
}
|
|
92
|
+
// 从 context 中获取 secret
|
|
93
|
+
if (!newConfig.secretId && !newConfig.secretKey) {
|
|
94
|
+
newConfig.secretId = (_b = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _b === void 0 ? void 0 : _b.secretId;
|
|
95
|
+
newConfig.secretKey = (_c = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _c === void 0 ? void 0 : _c.secretKey;
|
|
96
|
+
newConfig.sessionToken = (_d = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _d === void 0 ? void 0 : _d.token;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.config = newConfig;
|
|
69
100
|
this.extensionMap = new Map();
|
|
70
101
|
// NOTE:try-catch 为防止 init 报错
|
|
71
102
|
try {
|
|
@@ -81,10 +112,6 @@ class CloudBase {
|
|
|
81
112
|
method: (_a = options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
82
113
|
url: options.url,
|
|
83
114
|
headers: Object.assign({ 'Content-Type': 'application/json' }, headersInitToRecord(options.headers)),
|
|
84
|
-
/**
|
|
85
|
-
* 既然 openapicommonrequester.request 的参数里的 token 获取也是通过 openapicommonrequester.request 方法去获取的
|
|
86
|
-
* 为什么不把这里的 token 去掉,全部放在 openapicommonrequester.request 中去统一处理 token 获取的逻辑
|
|
87
|
-
*/
|
|
88
115
|
token: (await this.auth().getClientCredential()).access_token
|
|
89
116
|
});
|
|
90
117
|
return result.body;
|
|
@@ -127,15 +127,9 @@ class TcbApiHttpRequester {
|
|
|
127
127
|
this.tracingInfo = (0, tracing_1.generateTracingInfo)((_b = (_a = args.config) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.eventID);
|
|
128
128
|
}
|
|
129
129
|
async request() {
|
|
130
|
-
|
|
131
|
-
if (!this.config.accessKey) {
|
|
132
|
-
// 检查密钥是否存在
|
|
133
|
-
await this.prepareCredentials();
|
|
134
|
-
}
|
|
130
|
+
await this.prepareCredentials();
|
|
135
131
|
const params = await this.makeParams();
|
|
136
|
-
// console.log('params', params)
|
|
137
132
|
const opts = this.makeReqOpts(params);
|
|
138
|
-
// console.log('opts', opts)
|
|
139
133
|
const action = this.getAction();
|
|
140
134
|
const key = {
|
|
141
135
|
functions: 'function_name',
|
|
@@ -232,7 +226,7 @@ class TcbApiHttpRequester {
|
|
|
232
226
|
return params;
|
|
233
227
|
}
|
|
234
228
|
makeReqOpts(params) {
|
|
235
|
-
var _a;
|
|
229
|
+
var _a, _b;
|
|
236
230
|
const config = this.config;
|
|
237
231
|
const args = this.args;
|
|
238
232
|
const url = (0, tcbapiendpoint_1.buildUrl)({
|
|
@@ -251,7 +245,8 @@ class TcbApiHttpRequester {
|
|
|
251
245
|
timeout,
|
|
252
246
|
// 优先取config,其次取模块,最后取默认
|
|
253
247
|
headers: this.getHeaders(method, url, params),
|
|
254
|
-
proxy: config.proxy
|
|
248
|
+
proxy: config.proxy,
|
|
249
|
+
type: ((_b = this.opts) === null || _b === void 0 ? void 0 : _b.type) || 'json'
|
|
255
250
|
};
|
|
256
251
|
if (typeof config.keepalive === 'undefined' && !(0, cloudplatform_1.checkIsInScf)()) {
|
|
257
252
|
// 非云函数环境下,默认开启 keepalive
|
|
@@ -283,7 +278,7 @@ class TcbApiHttpRequester {
|
|
|
283
278
|
getHeaders(method, url, params) {
|
|
284
279
|
var _a;
|
|
285
280
|
const config = this.config;
|
|
286
|
-
const { context, secretId, secretKey
|
|
281
|
+
const { context, secretId, secretKey } = config;
|
|
287
282
|
const args = this.args;
|
|
288
283
|
const { TCB_SOURCE } = cloudbase_1.CloudBase.getCloudbaseContext();
|
|
289
284
|
// Note: 云函数被调用时可能调用端未传递 SOURCE,TCB_SOURCE 可能为空
|
|
@@ -323,8 +318,7 @@ class TcbApiHttpRequester {
|
|
|
323
318
|
timestamp: second() - 1
|
|
324
319
|
});
|
|
325
320
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
326
|
-
|
|
327
|
-
requiredHeaders['Authorization'] = accessKey ? `Bearer ${accessKey}` : authorization;
|
|
321
|
+
requiredHeaders['Authorization'] = authorization;
|
|
328
322
|
requiredHeaders['X-Signature-Expires'] = 600;
|
|
329
323
|
requiredHeaders['X-Timestamp'] = timestamp;
|
|
330
324
|
return Object.assign({}, requiredHeaders);
|
|
@@ -341,7 +335,6 @@ const handleWxOpenApiData = (res, err, response, body) => {
|
|
|
341
335
|
return transformRes;
|
|
342
336
|
};
|
|
343
337
|
async function request(args) {
|
|
344
|
-
// console.log('args', args)
|
|
345
338
|
if (typeof args.isInternal === 'undefined') {
|
|
346
339
|
args.isInternal = await (0, cloudplatform_1.checkIsInternalAsync)();
|
|
347
340
|
}
|
package/dist/utils/tcbcontext.js
CHANGED
|
@@ -60,7 +60,6 @@ exports.parseContext = parseContext;
|
|
|
60
60
|
* 获取当前函数内的所有环境变量(作为获取变量的统一方法,取值来源 process.env 和 context)
|
|
61
61
|
*/
|
|
62
62
|
function getCloudbaseContext(context) {
|
|
63
|
-
// console.log('context', context)
|
|
64
63
|
if ((0, cloudplatform_1.checkIsInScf)()) {
|
|
65
64
|
// 云函数环境下,应该包含以下环境变量,如果没有,后续逻辑可能会有问题
|
|
66
65
|
if (!process.env.TENCENTCLOUD_REGION) {
|
|
@@ -56,13 +56,8 @@ class TcbOpenApiHttpCommonRequester {
|
|
|
56
56
|
this.tracingInfo = (0, tracing_1.generateTracingInfo)((_b = (_a = args.config) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.eventID);
|
|
57
57
|
}
|
|
58
58
|
async request() {
|
|
59
|
-
|
|
60
|
-
if (!this.config.accessKey) {
|
|
61
|
-
// 检查密钥是否存在
|
|
62
|
-
await this.prepareCredentials();
|
|
63
|
-
}
|
|
59
|
+
await this.prepareCredentials();
|
|
64
60
|
const opts = this.makeReqOpts();
|
|
65
|
-
// console.log('opts', opts)
|
|
66
61
|
const argopts = this.opts;
|
|
67
62
|
const config = this.config;
|
|
68
63
|
// 注意:必须初始化为 null
|
|
@@ -145,7 +140,7 @@ class TcbOpenApiHttpCommonRequester {
|
|
|
145
140
|
buildHeaders(method, url) {
|
|
146
141
|
var _a;
|
|
147
142
|
const config = this.config;
|
|
148
|
-
const { context, secretId, secretKey, sessionToken
|
|
143
|
+
const { context, secretId, secretKey, sessionToken } = config;
|
|
149
144
|
const args = this.args;
|
|
150
145
|
const { TCB_SOURCE } = cloudbase_1.CloudBase.getCloudbaseContext();
|
|
151
146
|
// Note: 云函数被调用时可能调用端未传递 SOURCE,TCB_SOURCE 可能为空
|
|
@@ -186,25 +181,12 @@ class TcbOpenApiHttpCommonRequester {
|
|
|
186
181
|
withSignedParams: false,
|
|
187
182
|
isCloudApi: true
|
|
188
183
|
});
|
|
189
|
-
// console.log('xxxx', authorization)
|
|
190
|
-
let token = '';
|
|
191
|
-
// 如果请求参数里面传了 token,优先使用 token
|
|
192
|
-
if (args.token) {
|
|
193
|
-
token = makeBearerToken(args.token);
|
|
194
|
-
}
|
|
195
|
-
else if (accessKey) {
|
|
196
|
-
// 如果配置了 API_KEY,优先使用 API_KEY
|
|
197
|
-
token = makeBearerToken(accessKey);
|
|
198
|
-
}
|
|
199
|
-
else if (typeof sessionToken === 'string' && sessionToken !== '') {
|
|
200
|
-
// 如果配置了 sessionToken,携带 sessionToken
|
|
201
|
-
token = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`;
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
token = `${authorization}, Timestamp=${timestamp}`;
|
|
205
|
-
}
|
|
206
184
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
207
|
-
requiredHeaders['Authorization'] = token
|
|
185
|
+
requiredHeaders['Authorization'] = args.token
|
|
186
|
+
? makeBearerToken(args.token)
|
|
187
|
+
: typeof sessionToken === 'string' && sessionToken !== ''
|
|
188
|
+
? `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
189
|
+
: `${authorization}, Timestamp=${timestamp}`;
|
|
208
190
|
return Object.assign({}, requiredHeaders);
|
|
209
191
|
}
|
|
210
192
|
}
|
|
@@ -56,11 +56,8 @@ class TcbOpenApiHttpRequester {
|
|
|
56
56
|
this.tracingInfo = (0, tracing_1.generateTracingInfo)((_b = (_a = args.config) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.eventID);
|
|
57
57
|
}
|
|
58
58
|
async request() {
|
|
59
|
-
|
|
60
|
-
await this.prepareCredentials();
|
|
61
|
-
}
|
|
59
|
+
await this.prepareCredentials();
|
|
62
60
|
const opts = this.makeReqOpts();
|
|
63
|
-
// console.log('opts', opts)
|
|
64
61
|
const argopts = this.opts;
|
|
65
62
|
const config = this.config;
|
|
66
63
|
// 注意:必须初始化为 null
|
|
@@ -143,7 +140,7 @@ class TcbOpenApiHttpRequester {
|
|
|
143
140
|
buildHeaders(method, url) {
|
|
144
141
|
var _a;
|
|
145
142
|
const config = this.config;
|
|
146
|
-
const { context, secretId, secretKey, sessionToken
|
|
143
|
+
const { context, secretId, secretKey, sessionToken } = config;
|
|
147
144
|
const args = this.args;
|
|
148
145
|
const { TCB_SOURCE } = cloudbase_1.CloudBase.getCloudbaseContext();
|
|
149
146
|
// Note: 云函数被调用时可能调用端未传递 SOURCE,TCB_SOURCE 可能为空
|
|
@@ -189,24 +186,10 @@ class TcbOpenApiHttpRequester {
|
|
|
189
186
|
withSignedParams: false,
|
|
190
187
|
isCloudApi: true
|
|
191
188
|
});
|
|
192
|
-
let token = '';
|
|
193
|
-
// 如果请求参数里面传了 token,优先使用 token
|
|
194
|
-
if (args.token) {
|
|
195
|
-
token = makeBearerToken(args.token);
|
|
196
|
-
}
|
|
197
|
-
else if (accessKey) {
|
|
198
|
-
// 如果配置了 API_KEY,优先使用 API_KEY
|
|
199
|
-
token = makeBearerToken(accessKey);
|
|
200
|
-
}
|
|
201
|
-
else if (typeof sessionToken === 'string' && sessionToken !== '') {
|
|
202
|
-
// 如果配置了 sessionToken,使用 sessionToken
|
|
203
|
-
token = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
token = `${authorization}, Timestamp=${timestamp}`;
|
|
207
|
-
}
|
|
208
189
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
209
|
-
requiredHeaders['Authorization'] =
|
|
190
|
+
requiredHeaders['Authorization'] = typeof sessionToken === 'string' && sessionToken !== ''
|
|
191
|
+
? `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
192
|
+
: `${authorization}, Timestamp=${timestamp}`;
|
|
210
193
|
return Object.assign({}, requiredHeaders);
|
|
211
194
|
}
|
|
212
195
|
}
|
|
@@ -221,7 +204,3 @@ async function request(args) {
|
|
|
221
204
|
return await requester.request();
|
|
222
205
|
}
|
|
223
206
|
exports.request = request;
|
|
224
|
-
function makeBearerToken(token) {
|
|
225
|
-
const trimmed = token.trim();
|
|
226
|
-
return trimmed.startsWith('Bearer ') ? trimmed : `Bearer ${trimmed}`;
|
|
227
|
-
}
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,31 +1,6 @@
|
|
|
1
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 (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const utils = __importStar(require("../utils/utils"));
|
|
28
|
-
const code_1 = require("../const/code");
|
|
3
|
+
exports.isValidEnvFormat = exports.isPageModuleName = exports.processReturn = exports.setThrowOnCode = exports.second = exports.isNonEmptyString = exports.E = exports.filterUndefined = exports.filterValue = exports.isAppId = exports.TcbError = void 0;
|
|
29
4
|
class TcbError extends Error {
|
|
30
5
|
constructor(error) {
|
|
31
6
|
super(error.message);
|
|
@@ -97,50 +72,3 @@ function isValidEnvFormat(env = '') {
|
|
|
97
72
|
return typeof env === 'string' && kEnvRuleReg.test(env);
|
|
98
73
|
}
|
|
99
74
|
exports.isValidEnvFormat = isValidEnvFormat;
|
|
100
|
-
function normalizeConfig(config) {
|
|
101
|
-
var _a, _b, _c, _d;
|
|
102
|
-
const { debug = false, secretId, secretKey, env, timeout = 15000, headers = {}, accessKey } = config;
|
|
103
|
-
// 检查用户显示配置的 secretId 和 secretKey 是否成对出现,要么都有,要么都没有
|
|
104
|
-
if (!secretId !== !secretKey) {
|
|
105
|
-
throw utils.E(Object.assign(Object.assign({}, code_1.ERROR.INVALID_PARAM), { message: 'secretId and secretKey must be a pair' }));
|
|
106
|
-
}
|
|
107
|
-
const cloudbaseConfigBase = Object.assign(Object.assign({}, config), { debug,
|
|
108
|
-
// secretId,
|
|
109
|
-
// secretKey,
|
|
110
|
-
envName: env, headers: Object.assign({}, headers), // 结构用户传进来的 headers,防止用户修改原对象
|
|
111
|
-
timeout
|
|
112
|
-
// accessKey: accessKey || process.env.CLOUDBASE_APIKEY
|
|
113
|
-
});
|
|
114
|
-
const { TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, TENCENTCLOUD_SESSIONTOKEN, CLOUDBASE_APIKEY } = process.env;
|
|
115
|
-
// 如果用户显示配置了accessKey,取用户显示配置的 accessKey,优先级最高
|
|
116
|
-
if (accessKey) {
|
|
117
|
-
return Object.assign(cloudbaseConfigBase, { secretId: undefined, secretKey: undefined, accessKey });
|
|
118
|
-
}
|
|
119
|
-
// 显示配置了 secretId, secretKey,取 secretId, secretKey
|
|
120
|
-
if (secretId && secretKey) {
|
|
121
|
-
return Object.assign(cloudbaseConfigBase, { secretId, secretKey, accessKey: undefined });
|
|
122
|
-
}
|
|
123
|
-
// 下面从环境变量取 secretId, secretKey, accessKey
|
|
124
|
-
if (CLOUDBASE_APIKEY) {
|
|
125
|
-
return Object.assign(cloudbaseConfigBase, { secretId: undefined, secretKey: undefined, accessKey: CLOUDBASE_APIKEY });
|
|
126
|
-
}
|
|
127
|
-
if (TENCENTCLOUD_SECRETID && TENCENTCLOUD_SECRETKEY) {
|
|
128
|
-
return Object.assign(cloudbaseConfigBase, { secretId: TENCENTCLOUD_SECRETID, secretKey: TENCENTCLOUD_SECRETKEY, sessionToken: TENCENTCLOUD_SESSIONTOKEN, accessKey: undefined });
|
|
129
|
-
}
|
|
130
|
-
if ((_a = config.context) === null || _a === void 0 ? void 0 : _a.extendedContext) {
|
|
131
|
-
const extendedContext = config.context.extendedContext;
|
|
132
|
-
if (!cloudbaseConfigBase.env) {
|
|
133
|
-
cloudbaseConfigBase.env = extendedContext.envId;
|
|
134
|
-
cloudbaseConfigBase.envName = extendedContext.envId;
|
|
135
|
-
}
|
|
136
|
-
// 从 context 中获取 secret
|
|
137
|
-
if (!cloudbaseConfigBase.secretId && !cloudbaseConfigBase.secretKey) {
|
|
138
|
-
cloudbaseConfigBase.secretId = (_b = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _b === void 0 ? void 0 : _b.secretId;
|
|
139
|
-
cloudbaseConfigBase.secretKey = (_c = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _c === void 0 ? void 0 : _c.secretKey;
|
|
140
|
-
cloudbaseConfigBase.sessionToken = (_d = extendedContext === null || extendedContext === void 0 ? void 0 : extendedContext.tmpSecret) === null || _d === void 0 ? void 0 : _d.token;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// 都没有配置,返回原始的配置
|
|
144
|
-
return cloudbaseConfigBase;
|
|
145
|
-
}
|
|
146
|
-
exports.normalizeConfig = normalizeConfig;
|
package/dist/wx/index.js
CHANGED
|
@@ -96,7 +96,7 @@ async function callCompatibleWxOpenApi(cloudbase, { apiName, apiOptions, cgiName
|
|
|
96
96
|
headers: { 'content-type': 'multipart/form-data' },
|
|
97
97
|
params,
|
|
98
98
|
isFormData: true,
|
|
99
|
-
opts
|
|
99
|
+
opts: Object.assign({ type: 'raw' }, opts)
|
|
100
100
|
}).then(res => res);
|
|
101
101
|
}
|
|
102
102
|
exports.callCompatibleWxOpenApi = callCompatibleWxOpenApi;
|
|
@@ -121,7 +121,7 @@ async function callWxPayApi(cloudbase, { apiName, apiOptions, cgiName, requestDa
|
|
|
121
121
|
headers: { 'content-type': 'multipart/form-data' },
|
|
122
122
|
params,
|
|
123
123
|
isFormData: true,
|
|
124
|
-
opts
|
|
124
|
+
opts: Object.assign({ type: 'raw' }, opts)
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
127
|
exports.callWxPayApi = callWxPayApi;
|
|
@@ -146,7 +146,7 @@ async function wxCallContainerApi(cloudbase, { apiName, apiOptions, cgiName, req
|
|
|
146
146
|
headers: { 'content-type': 'multipart/form-data' },
|
|
147
147
|
params,
|
|
148
148
|
isFormData: true,
|
|
149
|
-
opts
|
|
149
|
+
opts: Object.assign({ type: 'raw' }, opts)
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
exports.wxCallContainerApi = wxCallContainerApi;
|
package/package.json
CHANGED
package/src/auth/index.ts
CHANGED
|
@@ -147,10 +147,6 @@ export class Auth {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
public async getClientCredential(opts?: ICustomReqOpts): Promise<any> {
|
|
150
|
-
// 如果有 accessKey 直接返回 accessKey,不用再去换取 token
|
|
151
|
-
if (this.cloudbase.config.accessKey) {
|
|
152
|
-
return this.cloudbase.config.accessKey
|
|
153
|
-
}
|
|
154
150
|
return await tcbopenapicommonrequester.request({
|
|
155
151
|
config: this.cloudbase.config,
|
|
156
152
|
method: 'POST',
|
|
@@ -187,7 +183,7 @@ export class Auth {
|
|
|
187
183
|
throw E({
|
|
188
184
|
...ERROR.INVALID_PARAM,
|
|
189
185
|
message:
|
|
190
|
-
|
|
186
|
+
'当前私钥未包含env_id 信息, 请前往腾讯云云开发控制台,获取自定义登录最新私钥'
|
|
191
187
|
})
|
|
192
188
|
}
|
|
193
189
|
|
package/src/cloudbase.ts
CHANGED
|
@@ -63,7 +63,7 @@ import { IFetchOptions } from '@cloudbase/adapter-interface'
|
|
|
63
63
|
import { buildCommonOpenApiUrlWithPath } from './utils/tcbopenapiendpoint'
|
|
64
64
|
import { SYMBOL_CURRENT_ENV } from './const/symbol'
|
|
65
65
|
import { IncomingHttpHeaders } from 'http'
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
export class CloudBase {
|
|
68
68
|
public static scfContext: ISCFContext
|
|
69
69
|
|
|
@@ -100,10 +100,43 @@ export class CloudBase {
|
|
|
100
100
|
/* eslint-disable-next-line */
|
|
101
101
|
preflightRuntimeCloudPlatform()
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
const { debug, secretId, secretKey, sessionToken, env, timeout, headers = {}, ...restConfig } = config
|
|
104
|
+
|
|
105
|
+
if (('secretId' in config && !('secretKey' in config)) || (!('secretId' in config) && 'secretKey' in config)) {
|
|
106
|
+
throw utils.E({
|
|
107
|
+
...ERROR.INVALID_PARAM,
|
|
108
|
+
message: 'secretId and secretKey must be a pair'
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const newConfig: ICloudBaseConfig = {
|
|
113
|
+
...restConfig,
|
|
114
|
+
debug: !!debug,
|
|
115
|
+
secretId,
|
|
116
|
+
secretKey,
|
|
117
|
+
sessionToken,
|
|
118
|
+
env,
|
|
119
|
+
envName: env,
|
|
120
|
+
headers: { ...headers },
|
|
121
|
+
timeout: timeout || 15000
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (config.context?.extendedContext) {
|
|
125
|
+
const extendedContext = config.context.extendedContext
|
|
126
|
+
if (!newConfig.env) {
|
|
127
|
+
newConfig.env = extendedContext.envId
|
|
128
|
+
newConfig.envName = newConfig.env
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 从 context 中获取 secret
|
|
132
|
+
if (!newConfig.secretId && !newConfig.secretKey) {
|
|
133
|
+
newConfig.secretId = extendedContext?.tmpSecret?.secretId
|
|
134
|
+
newConfig.secretKey = extendedContext?.tmpSecret?.secretKey
|
|
135
|
+
newConfig.sessionToken = extendedContext?.tmpSecret?.token
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.config = newConfig
|
|
107
140
|
this.extensionMap = new Map()
|
|
108
141
|
|
|
109
142
|
// NOTE:try-catch 为防止 init 报错
|
|
@@ -122,10 +155,6 @@ export class CloudBase {
|
|
|
122
155
|
'Content-Type': 'application/json',
|
|
123
156
|
...headersInitToRecord(options.headers)
|
|
124
157
|
},
|
|
125
|
-
/**
|
|
126
|
-
* 既然 openapicommonrequester.request 的参数里的 token 获取也是通过 openapicommonrequester.request 方法去获取的
|
|
127
|
-
* 为什么不把这里的 token 去掉,全部放在 openapicommonrequester.request 中去统一处理 token 获取的逻辑
|
|
128
|
-
*/
|
|
129
158
|
token: (await this.auth().getClientCredential()).access_token
|
|
130
159
|
})
|
|
131
160
|
return result.body
|
|
@@ -147,15 +147,10 @@ export class TcbApiHttpRequester {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
public async request(): Promise<any> {
|
|
150
|
-
|
|
151
|
-
if (!this.config.accessKey) {
|
|
152
|
-
// 检查密钥是否存在
|
|
153
|
-
await this.prepareCredentials()
|
|
154
|
-
}
|
|
150
|
+
await this.prepareCredentials()
|
|
155
151
|
const params = await this.makeParams()
|
|
156
|
-
|
|
152
|
+
|
|
157
153
|
const opts = this.makeReqOpts(params)
|
|
158
|
-
// console.log('opts', opts)
|
|
159
154
|
const action = this.getAction()
|
|
160
155
|
const key = {
|
|
161
156
|
functions: 'function_name',
|
|
@@ -292,7 +287,8 @@ export class TcbApiHttpRequester {
|
|
|
292
287
|
timeout,
|
|
293
288
|
// 优先取config,其次取模块,最后取默认
|
|
294
289
|
headers: this.getHeaders(method, url, params),
|
|
295
|
-
proxy: config.proxy
|
|
290
|
+
proxy: config.proxy,
|
|
291
|
+
type: this.opts?.type || 'json'
|
|
296
292
|
}
|
|
297
293
|
|
|
298
294
|
if (typeof config.keepalive === 'undefined' && !checkIsInScf()) {
|
|
@@ -325,7 +321,7 @@ export class TcbApiHttpRequester {
|
|
|
325
321
|
|
|
326
322
|
private getHeaders(method: string, url: string, params: any): any {
|
|
327
323
|
const config = this.config
|
|
328
|
-
const { context, secretId, secretKey
|
|
324
|
+
const { context, secretId, secretKey } = config
|
|
329
325
|
const args = this.args
|
|
330
326
|
|
|
331
327
|
const { TCB_SOURCE } = CloudBase.getCloudbaseContext()
|
|
@@ -375,8 +371,7 @@ export class TcbApiHttpRequester {
|
|
|
375
371
|
})
|
|
376
372
|
|
|
377
373
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
378
|
-
|
|
379
|
-
requiredHeaders['Authorization'] = accessKey ? `Bearer ${accessKey}` : authorization
|
|
374
|
+
requiredHeaders['Authorization'] = authorization
|
|
380
375
|
requiredHeaders['X-Signature-Expires'] = 600
|
|
381
376
|
requiredHeaders['X-Timestamp'] = timestamp
|
|
382
377
|
|
|
@@ -395,7 +390,6 @@ const handleWxOpenApiData = (res: any, err: any, response: any, body: any): any
|
|
|
395
390
|
}
|
|
396
391
|
|
|
397
392
|
export async function request(args: IRequestInfo): Promise<any> {
|
|
398
|
-
// console.log('args', args)
|
|
399
393
|
if (typeof args.isInternal === 'undefined') {
|
|
400
394
|
args.isInternal = await checkIsInternalAsync()
|
|
401
395
|
}
|
package/src/utils/tcbcontext.ts
CHANGED
|
@@ -76,7 +76,6 @@ export function parseContext(context: IContextParam): ISCFContext {
|
|
|
76
76
|
* 获取当前函数内的所有环境变量(作为获取变量的统一方法,取值来源 process.env 和 context)
|
|
77
77
|
*/
|
|
78
78
|
export function getCloudbaseContext(context?: IContextParam): ICompleteCloudbaseContext {
|
|
79
|
-
// console.log('context', context)
|
|
80
79
|
if (checkIsInScf()) {
|
|
81
80
|
// 云函数环境下,应该包含以下环境变量,如果没有,后续逻辑可能会有问题
|
|
82
81
|
if (!process.env.TENCENTCLOUD_REGION) {
|
|
@@ -17,6 +17,7 @@ export class TcbDBApiHttpRequester {
|
|
|
17
17
|
public async send(api: string, data: any, opts?: ICustomReqOpts): Promise<any> {
|
|
18
18
|
const { instance, database, ...config } = this.config
|
|
19
19
|
const params = { ...data, action: api, instance, database }
|
|
20
|
+
|
|
20
21
|
return await tcbapicaller.request({
|
|
21
22
|
config,
|
|
22
23
|
params,
|
|
@@ -54,14 +54,9 @@ export class TcbOpenApiHttpCommonRequester {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
public async request() {
|
|
57
|
-
|
|
58
|
-
if (!this.config.accessKey) {
|
|
59
|
-
// 检查密钥是否存在
|
|
60
|
-
await this.prepareCredentials()
|
|
61
|
-
}
|
|
57
|
+
await this.prepareCredentials()
|
|
62
58
|
|
|
63
59
|
const opts = this.makeReqOpts()
|
|
64
|
-
// console.log('opts', opts)
|
|
65
60
|
|
|
66
61
|
const argopts: any = this.opts
|
|
67
62
|
const config = this.config
|
|
@@ -149,7 +144,7 @@ export class TcbOpenApiHttpCommonRequester {
|
|
|
149
144
|
|
|
150
145
|
private buildHeaders(method: string, url: string): any {
|
|
151
146
|
const config = this.config
|
|
152
|
-
const { context, secretId, secretKey, sessionToken
|
|
147
|
+
const { context, secretId, secretKey, sessionToken } = config
|
|
153
148
|
const args = this.args
|
|
154
149
|
|
|
155
150
|
const { TCB_SOURCE } = CloudBase.getCloudbaseContext()
|
|
@@ -199,22 +194,13 @@ export class TcbOpenApiHttpCommonRequester {
|
|
|
199
194
|
withSignedParams: false,
|
|
200
195
|
isCloudApi: true
|
|
201
196
|
})
|
|
202
|
-
|
|
203
|
-
let token = ''
|
|
204
|
-
// 如果请求参数里面传了 token,优先使用 token
|
|
205
|
-
if (args.token) {
|
|
206
|
-
token = makeBearerToken(args.token)
|
|
207
|
-
} else if (accessKey) {
|
|
208
|
-
// 如果配置了 API_KEY,优先使用 API_KEY
|
|
209
|
-
token = makeBearerToken(accessKey)
|
|
210
|
-
} else if (typeof sessionToken === 'string' && sessionToken !== '') {
|
|
211
|
-
// 如果配置了 sessionToken,携带 sessionToken
|
|
212
|
-
token = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
213
|
-
} else {
|
|
214
|
-
token = `${authorization}, Timestamp=${timestamp}`
|
|
215
|
-
}
|
|
197
|
+
|
|
216
198
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
217
|
-
requiredHeaders['Authorization'] = token
|
|
199
|
+
requiredHeaders['Authorization'] = args.token
|
|
200
|
+
? makeBearerToken(args.token)
|
|
201
|
+
: typeof sessionToken === 'string' && sessionToken !== ''
|
|
202
|
+
? `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
203
|
+
: `${authorization}, Timestamp=${timestamp}`
|
|
218
204
|
|
|
219
205
|
return { ...requiredHeaders }
|
|
220
206
|
}
|
|
@@ -30,7 +30,6 @@ export function getEnvIdFromContext(): string {
|
|
|
30
30
|
type ICallContainerRequestInfo = Omit<IRequestInfo, 'params'> & {
|
|
31
31
|
path: string
|
|
32
32
|
data: any
|
|
33
|
-
token?: string
|
|
34
33
|
cloudrun: {
|
|
35
34
|
name: string
|
|
36
35
|
// version: string
|
|
@@ -57,12 +56,9 @@ export class TcbOpenApiHttpRequester {
|
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
public async request(): Promise<any> {
|
|
60
|
-
|
|
61
|
-
await this.prepareCredentials()
|
|
62
|
-
}
|
|
59
|
+
await this.prepareCredentials()
|
|
63
60
|
|
|
64
61
|
const opts = this.makeReqOpts()
|
|
65
|
-
// console.log('opts', opts)
|
|
66
62
|
|
|
67
63
|
const argopts: any = this.opts
|
|
68
64
|
const config = this.config
|
|
@@ -151,7 +147,7 @@ export class TcbOpenApiHttpRequester {
|
|
|
151
147
|
|
|
152
148
|
private buildHeaders(method: string, url: string): any {
|
|
153
149
|
const config = this.config
|
|
154
|
-
const { context, secretId, secretKey, sessionToken
|
|
150
|
+
const { context, secretId, secretKey, sessionToken } = config
|
|
155
151
|
const args = this.args
|
|
156
152
|
|
|
157
153
|
const { TCB_SOURCE } = CloudBase.getCloudbaseContext()
|
|
@@ -208,21 +204,11 @@ export class TcbOpenApiHttpRequester {
|
|
|
208
204
|
withSignedParams: false,
|
|
209
205
|
isCloudApi: true
|
|
210
206
|
})
|
|
211
|
-
|
|
212
|
-
// 如果请求参数里面传了 token,优先使用 token
|
|
213
|
-
if (args.token) {
|
|
214
|
-
token = makeBearerToken(args.token)
|
|
215
|
-
} else if (accessKey) {
|
|
216
|
-
// 如果配置了 API_KEY,优先使用 API_KEY
|
|
217
|
-
token = makeBearerToken(accessKey)
|
|
218
|
-
} else if (typeof sessionToken === 'string' && sessionToken !== '') {
|
|
219
|
-
// 如果配置了 sessionToken,使用 sessionToken
|
|
220
|
-
token = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
221
|
-
} else {
|
|
222
|
-
token = `${authorization}, Timestamp=${timestamp}`
|
|
223
|
-
}
|
|
207
|
+
|
|
224
208
|
/* eslint-disable @typescript-eslint/dot-notation */
|
|
225
|
-
requiredHeaders['Authorization'] =
|
|
209
|
+
requiredHeaders['Authorization'] = typeof sessionToken === 'string' && sessionToken !== ''
|
|
210
|
+
? `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
|
|
211
|
+
: `${authorization}, Timestamp=${timestamp}`
|
|
226
212
|
|
|
227
213
|
return { ...requiredHeaders }
|
|
228
214
|
}
|
|
@@ -239,7 +225,3 @@ export async function request(args: ICallContainerRequestInfo & { path: string }
|
|
|
239
225
|
|
|
240
226
|
return await requester.request()
|
|
241
227
|
}
|
|
242
|
-
function makeBearerToken(token: string): string {
|
|
243
|
-
const trimmed = token.trim()
|
|
244
|
-
return trimmed.startsWith('Bearer ') ? trimmed : `Bearer ${trimmed}`
|
|
245
|
-
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { ICloudBaseConfig } from '../../types'
|
|
2
|
-
import * as utils from '../utils/utils'
|
|
3
|
-
import { ERROR } from '../const/code'
|
|
4
|
-
|
|
5
1
|
interface IErrorInfo {
|
|
6
2
|
requestId?: string
|
|
7
3
|
code?: string
|
|
@@ -85,61 +81,3 @@ const kEnvRuleReg = /^[a-z0-9_-]{1,40}$/
|
|
|
85
81
|
export function isValidEnvFormat(env = '') {
|
|
86
82
|
return typeof env === 'string' && kEnvRuleReg.test(env)
|
|
87
83
|
}
|
|
88
|
-
export function normalizeConfig(config: ICloudBaseConfig) {
|
|
89
|
-
const { debug = false, secretId, secretKey, env, timeout = 15000, headers = {}, accessKey } = config
|
|
90
|
-
|
|
91
|
-
// 检查用户显示配置的 secretId 和 secretKey 是否成对出现,要么都有,要么都没有
|
|
92
|
-
if (!secretId !== !secretKey) {
|
|
93
|
-
throw utils.E({
|
|
94
|
-
...ERROR.INVALID_PARAM,
|
|
95
|
-
message: 'secretId and secretKey must be a pair'
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
const cloudbaseConfigBase: ICloudBaseConfig = {
|
|
99
|
-
...config,
|
|
100
|
-
debug,
|
|
101
|
-
// secretId,
|
|
102
|
-
// secretKey,
|
|
103
|
-
envName: env,
|
|
104
|
-
headers: { ...headers }, // 结构用户传进来的 headers,防止用户修改原对象
|
|
105
|
-
timeout
|
|
106
|
-
// accessKey: accessKey || process.env.CLOUDBASE_APIKEY
|
|
107
|
-
}
|
|
108
|
-
const {
|
|
109
|
-
TENCENTCLOUD_SECRETID,
|
|
110
|
-
TENCENTCLOUD_SECRETKEY,
|
|
111
|
-
TENCENTCLOUD_SESSIONTOKEN,
|
|
112
|
-
CLOUDBASE_APIKEY
|
|
113
|
-
} = process.env
|
|
114
|
-
// 如果用户显示配置了accessKey,取用户显示配置的 accessKey,优先级最高
|
|
115
|
-
if (accessKey) {
|
|
116
|
-
return Object.assign(cloudbaseConfigBase, { secretId: undefined, secretKey: undefined, accessKey })
|
|
117
|
-
}
|
|
118
|
-
// 显示配置了 secretId, secretKey,取 secretId, secretKey
|
|
119
|
-
if (secretId && secretKey) {
|
|
120
|
-
return Object.assign(cloudbaseConfigBase, { secretId, secretKey, accessKey: undefined })
|
|
121
|
-
}
|
|
122
|
-
// 下面从环境变量取 secretId, secretKey, accessKey
|
|
123
|
-
if (CLOUDBASE_APIKEY) {
|
|
124
|
-
return Object.assign(cloudbaseConfigBase, { secretId: undefined, secretKey: undefined, accessKey: CLOUDBASE_APIKEY })
|
|
125
|
-
}
|
|
126
|
-
if (TENCENTCLOUD_SECRETID && TENCENTCLOUD_SECRETKEY) {
|
|
127
|
-
return Object.assign(cloudbaseConfigBase, { secretId: TENCENTCLOUD_SECRETID, secretKey: TENCENTCLOUD_SECRETKEY, sessionToken: TENCENTCLOUD_SESSIONTOKEN, accessKey: undefined })
|
|
128
|
-
}
|
|
129
|
-
if (config.context?.extendedContext) {
|
|
130
|
-
const extendedContext = config.context.extendedContext
|
|
131
|
-
if (!cloudbaseConfigBase.env) {
|
|
132
|
-
cloudbaseConfigBase.env = extendedContext.envId
|
|
133
|
-
cloudbaseConfigBase.envName = extendedContext.envId
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 从 context 中获取 secret
|
|
137
|
-
if (!cloudbaseConfigBase.secretId && !cloudbaseConfigBase.secretKey) {
|
|
138
|
-
cloudbaseConfigBase.secretId = extendedContext?.tmpSecret?.secretId
|
|
139
|
-
cloudbaseConfigBase.secretKey = extendedContext?.tmpSecret?.secretKey
|
|
140
|
-
cloudbaseConfigBase.sessionToken = extendedContext?.tmpSecret?.token
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// 都没有配置,返回原始的配置
|
|
144
|
-
return cloudbaseConfigBase
|
|
145
|
-
}
|
package/src/wx/index.ts
CHANGED
|
@@ -89,7 +89,7 @@ export async function callCompatibleWxOpenApi(
|
|
|
89
89
|
headers: { 'content-type': 'multipart/form-data' },
|
|
90
90
|
params,
|
|
91
91
|
isFormData: true,
|
|
92
|
-
opts
|
|
92
|
+
opts: { type: 'raw', ...opts }
|
|
93
93
|
}).then(res => res)
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -120,7 +120,7 @@ export async function callWxPayApi(
|
|
|
120
120
|
headers: { 'content-type': 'multipart/form-data' },
|
|
121
121
|
params,
|
|
122
122
|
isFormData: true,
|
|
123
|
-
opts
|
|
123
|
+
opts: { type: 'raw', ...opts }
|
|
124
124
|
})
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -151,6 +151,6 @@ export async function wxCallContainerApi(
|
|
|
151
151
|
headers: { 'content-type': 'multipart/form-data' },
|
|
152
152
|
params,
|
|
153
153
|
isFormData: true,
|
|
154
|
-
opts
|
|
154
|
+
opts: { type: 'raw', ...opts }
|
|
155
155
|
})
|
|
156
156
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import fs from 'fs'
|
|
|
3
3
|
import { Db } from '@cloudbase/database'
|
|
4
4
|
import { OrmClient, OrmRawQueryClient } from '@cloudbase/wx-cloud-client-sdk'
|
|
5
5
|
import { AI } from '@cloudbase/ai'
|
|
6
|
+
import { IReqOpts } from './internal'
|
|
6
7
|
|
|
7
8
|
type IKeyValue = Record<string, any>
|
|
8
9
|
|
|
@@ -196,7 +197,6 @@ export interface ICloudBaseConfig extends IKeyValue {
|
|
|
196
197
|
version?: string
|
|
197
198
|
credentials?: ICredentialsInfo
|
|
198
199
|
region?: string
|
|
199
|
-
accessKey?: string
|
|
200
200
|
|
|
201
201
|
// @cloudbase/functions-framework 函数上下文,只要求部分字段
|
|
202
202
|
context?: Readonly<{
|
|
@@ -243,6 +243,7 @@ export interface ICustomReqOpts {
|
|
|
243
243
|
* 获取跨帐号调用信息
|
|
244
244
|
*/
|
|
245
245
|
getCrossAccountInfo?: () => Promise<ICrossAccountInfo>
|
|
246
|
+
type?: IReqOpts['type']
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
export interface IBaseResult {
|