@cloudbase/app 3.0.5 → 3.1.0

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/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "@cloudbase/app",
3
- "version": "3.0.5",
3
+ "version": "3.1.0",
4
4
  "description": "cloudbase javascript sdk core",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "node": {
10
+ "import": "./dist/esm/index.node.js",
11
+ "require": "./dist/cjs/index.node.js"
12
+ },
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/cjs/index.js",
15
+ "default": "./dist/cjs/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
7
19
  "scripts": {
8
20
  "tsc": "rm -rf dist/ && tsc -p tsconfig.esm.json && tsc -p tsconfig.json",
9
21
  "lint": "eslint --fix \"./src/**/*.ts\"",
@@ -31,8 +43,8 @@
31
43
  "dependencies": {
32
44
  "@cloudbase/adapter-interface": "^0.7.1",
33
45
  "@cloudbase/adapter-wx_mp": "^1.2.1",
34
- "@cloudbase/types": "3.0.5",
35
- "@cloudbase/utilities": "3.0.5"
46
+ "@cloudbase/types": "3.1.0",
47
+ "@cloudbase/utilities": "3.1.0"
36
48
  },
37
49
  "peerDependencies": {
38
50
  "@cloudbase/signature-nodejs": ">=1.0.0",
@@ -50,5 +62,5 @@
50
62
  "optional": true
51
63
  }
52
64
  },
53
- "gitHead": "5f712e638aa0a0f082986a31c6288b18125a3e24"
65
+ "gitHead": "fa22a3b2fae8327ba8243c5634d540e99e0aefe7"
54
66
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Node.js 入口
3
+ * 引用 base 模块的全部导出,并额外加载 Node adapter
4
+ */
5
+ import cloudbase from './index'
6
+
7
+ export { getBaseEndPoint } from './constants/common'
8
+ export { LANGS } from './libs/lang'
9
+ export type { Cloudbase } from './index'
10
+ export { cloudbase }
11
+
12
+ // Node 环境下加载 Node adapter
13
+ try {
14
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
15
+ const nodeAdapter = require('./libs/adapter-node').default
16
+ cloudbase.useAdapters(nodeAdapter)
17
+ } catch (error) {
18
+ throw error
19
+ }
20
+
21
+ // 默认导出实例
22
+ export default cloudbase
package/src/index.ts CHANGED
@@ -119,7 +119,7 @@ class Cloudbase implements ICloudbase {
119
119
  }
120
120
 
121
121
  const reqConfig: IRequestConfig & { auth: ICloudbaseConfig['auth'] } = {
122
- timeout: config.timeout || 5000,
122
+ timeout: config.timeout || 15000,
123
123
  timeoutMsg: `[${getSdkName()}][REQUEST TIMEOUT] request had been abort since didn't finished within${
124
124
  config.timeout / 1000
125
125
  }s`,
@@ -294,7 +294,7 @@ class Cloudbase implements ICloudbase {
294
294
  */
295
295
  private dealNodeAdapterConfig(config: ICloudbaseConfig) {
296
296
  // node环境可以从adapter获取默认的secretId和secretKey
297
- if (!process.env.IS_BROWSER_BUILD && Platform.adapter?.getSecretInfo) {
297
+ if (typeof process !== 'undefined' && typeof process.env !== 'undefined' && !process.env.IS_BROWSER_BUILD && Platform.adapter?.getSecretInfo) {
298
298
  const secretInfo = Platform.adapter?.getSecretInfo(config)
299
299
  // 将 adapter 提供的密钥信息写入 config.auth
300
300
  config.auth = {
@@ -328,16 +328,5 @@ export const cloudbase: ICloudbase = new Cloudbase()
328
328
 
329
329
  cloudbase.useAdapters(getWxDefaultAdapter())
330
330
 
331
- // Node 环境下动态引入 adapter,浏览器/小程序打包时 IS_BROWSER_BUILD=true,此分支会被 tree-shaking 移除
332
- if (!process.env.IS_BROWSER_BUILD) {
333
- try {
334
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
335
- const nodeAdapter = require('./libs/adapter-node').default
336
- cloudbase.useAdapters(nodeAdapter)
337
- } catch (error) {
338
- throw error
339
- }
340
- }
341
-
342
331
  // 默认导出实例
343
332
  export default cloudbase
@@ -21,6 +21,7 @@ import {
21
21
  getCurrRunEnvTag,
22
22
  } from './utils'
23
23
  import { ICloudbaseConfig } from '@cloudbase/types'
24
+ import { getSdkVersion } from '../../constants/common'
24
25
  // 延迟加载,避免非 Node 环境打包时引入此包
25
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
27
  let signFn: ((...args: any[]) => any) | null = null
@@ -133,7 +134,7 @@ export class NodeRequest implements SDKRequestInterface {
133
134
 
134
135
  options.headers = {
135
136
  ...options.headers,
136
- 'User-Agent': `adapter-node/${options.headers?.['X-SDK-Version'] || ''}`,
137
+ 'User-Agent': `adapter-node/${options.headers?.['X-SDK-Version'] || `@cloudbase/js-sdk/${getSdkVersion()}`}`,
137
138
  'X-TCB-Source': SOURCE,
138
139
  'X-Client-Timestamp': new Date().valueOf(),
139
140
  'X-TCB-Region': INIT_CONFIG.region || getEnv('TENCENTCLOUD_REGION') || '',
@@ -199,6 +200,10 @@ export class NodeRequest implements SDKRequestInterface {
199
200
  headers['Content-Type'] = headers['Content-Type'].toLowerCase()
200
201
  }
201
202
 
203
+ if (isAdminPath && !!sessionToken) {
204
+ params.sessionToken = sessionToken
205
+ }
206
+
202
207
  const signedParams = {
203
208
  secretId,
204
209
  secretKey,
@@ -211,7 +216,6 @@ export class NodeRequest implements SDKRequestInterface {
211
216
  isCloudApi: !isAdminPath,
212
217
  }
213
218
 
214
- console.log('======signedParams', signedParams)
215
219
 
216
220
  const sign = await getSign()
217
221
  if (!sign) return options
@@ -219,8 +223,14 @@ export class NodeRequest implements SDKRequestInterface {
219
223
  const { authorization, timestamp } = sign(signedParams)
220
224
 
221
225
  if (typeof sessionToken === 'string' && sessionToken !== '') {
222
- // 临时密钥需要额外附带 Token
223
- headers.Authorization = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
226
+ if (isAdminPath) {
227
+ headers.Authorization = `${authorization}`
228
+ headers['X-Timestamp'] = timestamp
229
+ headers['X-Signature-Expires'] = 600
230
+ } else {
231
+ // 临时密钥需要额外附带 Token
232
+ headers.Authorization = `${authorization}, Timestamp=${timestamp}, Token=${sessionToken}`
233
+ }
224
234
  } else {
225
235
  headers.Authorization = `${authorization}, Timestamp=${timestamp}`
226
236
 
@@ -365,8 +375,6 @@ export class NodeRequest implements SDKRequestInterface {
365
375
  signal: abortController.signal,
366
376
  })
367
377
 
368
- console.log('======fetchOptions', url, fetchOptions)
369
-
370
378
  const res = await fetch(url, fetchOptions as RequestInit)
371
379
  .then((x) => {
372
380
  clearTimeout(timer)
@@ -451,8 +459,6 @@ export class NodeRequest implements SDKRequestInterface {
451
459
  signal,
452
460
  })
453
461
 
454
- console.log('======requestOptions', realUrl, requestOptions)
455
-
456
462
  try {
457
463
  const response = await fetch(realUrl, requestOptions as RequestInit)
458
464
  const result: ResponseObject = {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-require-imports */
1
2
  const path = require('path')
2
3
  const webpack = require('webpack')
3
4
  const TerserPlugin = require('terser-webpack-plugin')
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-require-imports */
1
2
  const path = require('path')
2
3
  const { ignoreNodeDepsPlugins } = require('../../../webpack.ignore-node-deps')
3
4