New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cloudbase/node-sdk

Package Overview
Dependencies
Maintainers
11
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudbase/node-sdk - npm Package Compare versions

Comparing version 2.3.4 to 2.4.0-beta

4

CHANGELOG.md

@@ -1,5 +0,1 @@

# v2.3.4
- [bugfix] 修复geo centerSphere 兼容问题
# v2.3.3

@@ -6,0 +2,0 @@

1

lib/type/index.d.ts

@@ -18,2 +18,3 @@ /// <reference types="node" />

env?: string;
region?: string;
sessionToken?: string;

@@ -20,0 +21,0 @@ serviceUrl?: string;

@@ -6,4 +6,2 @@ import { IRequestInfo, IReqOpts, IReqHooks } from '../type/index';

private opts;
private defaultEndPoint;
private inScfHost;
private urlPath;

@@ -10,0 +8,0 @@ private defaultTimeout;

@@ -30,5 +30,2 @@ "use strict";

constructor(args) {
this.defaultEndPoint = 'tcb-admin.tencentcloudapi.com';
this.inScfHost = 'tcb-admin.tencentyun.com';
// private openApiHost: string = 'tcb-open.tencentcloudapi.com'
this.urlPath = '/admin';

@@ -288,2 +285,6 @@ this.defaultTimeout = 15000;

}
const region = this.config.region || process.env.TENCENTCLOUD_REGION || '';
if (region) {
requiredHeaders['X-TCB-Region'] = region;
}
requiredHeaders = Object.assign(Object.assign(Object.assign({}, config.headers), args.headers), requiredHeaders);

@@ -310,25 +311,39 @@ const { authorization, timestamp } = signature_nodejs_1.sign({

getUrl() {
const protocol = this.getProtocol();
const isInSCF = utils.checkIsInScf();
const isInContainer = utils.checkIsInContainer();
const { eventId, seqId } = this.tracingInfo;
const { customApiUrl } = this.args;
const { serviceUrl } = this.config;
const serverInjectUrl = getServerInjectUrl();
const defaultUrl = isInSCF || isInContainer
? `http://${this.inScfHost}${this.urlPath}`
: `${protocol}://${this.defaultEndPoint}${this.urlPath}`;
let url = serviceUrl || serverInjectUrl || customApiUrl || defaultUrl;
let urlQueryStr = `&eventId=${eventId}&seqId=${seqId}`;
const scfContext = cloudbase_1.CloudBase.scfContext;
if (scfContext) {
urlQueryStr = `&eventId=${eventId}&seqId=${seqId}&scfRequestId=${scfContext.request_id}`;
if (isInSCF) {
// 云函数环境下,应该包含以下环境变量,如果没有,后续逻辑可能会有问题
if (!process.env.TENCENTCLOUD_REGION) {
console.error('[ERROR] missing `TENCENTCLOUD_REGION` environment');
}
if (!process.env.SCF_NAMESPACE) {
console.error('[ERROR] missing `SCF_NAMESPACE` environment');
}
}
if (url.includes('?')) {
url = `${url}${urlQueryStr}`;
}
else {
url = `${url}?${urlQueryStr}`;
}
return url;
const { TCB_ENV, SCF_NAMESPACE } = cloudbase_1.CloudBase.getCloudbaseContext();
// 优先级:用户配置 > 环境变量
const region = this.config.region || process.env.TENCENTCLOUD_REGION || '';
const envId = this.config.envName === symbol_1.SYMBOL_CURRENT_ENV
? TCB_ENV || SCF_NAMESPACE
: this.config.envName || '';
// 有地域信息则访问地域级别域名,无地域信息则访问默认域名,默认域名固定解析到上海地域保持兼容
const internetRegionEndpoint = region
? `${region}.tcb-api.tencentcloudapi.com`
: `tcb-api.tencentcloudapi.com`;
const internalRegionEndpoint = region
? `internal.${region}.tcb-api.tencentcloudapi.com`
: `internal.tcb-api.tencentcloudapi.com`;
const endpoint = (isInSCF || isInContainer) ? internalRegionEndpoint : internetRegionEndpoint;
const envEndpoint = envId ? `${envId}.${endpoint}` : endpoint;
const protocol = isInSCF ? 'http' : this.getProtocol();
// 注意:云函数环境下有地域信息,云应用环境下不确定是否有,如果没有,用户必须显式的传入
const defaultUrl = `${protocol}://${envEndpoint}${this.urlPath}`;
const url = serviceUrl || serverInjectUrl || defaultUrl;
const qs = cloudbase_1.CloudBase.scfContext
? `&eventId=${eventId}&seqId=${seqId}&scfRequestId=${cloudbase_1.CloudBase.scfContext.request_id}`
: `&eventId=${eventId}&seqId=${seqId}`;
return url.includes('?') ? `${url}${qs}` : `${url}?${qs}`;
}

@@ -335,0 +350,0 @@ }

@@ -36,4 +36,3 @@ "use strict";

'content-type': 'application/json'
},
customApiUrl: utils_1.getWxUrl(cloudbase.config)
}
}).then(res => {

@@ -79,3 +78,2 @@ if (res.code) {

isFormData: true,
customApiUrl: utils_1.getWxUrl(cloudbase.config),
opts

@@ -104,3 +102,2 @@ }).then(res => res);

isFormData: true,
customApiUrl: utils_1.getWxUrl(cloudbase.config),
opts

@@ -107,0 +104,0 @@ });

{
"name": "@cloudbase/node-sdk",
"version": "2.3.4",
"version": "2.4.0-beta",
"description": "tencent cloud base server sdk for node.js",

@@ -32,3 +32,3 @@ "main": "lib/index.js",

"dependencies": {
"@cloudbase/database": "1.2.2",
"@cloudbase/database": "1.2.1",
"@cloudbase/signature-nodejs": "1.0.0-beta.0",

@@ -35,0 +35,0 @@ "@types/retry": "^0.12.0",

@@ -19,2 +19,3 @@ export interface IKeyValue {

env?: string
region?: string
sessionToken?: string

@@ -97,3 +98,3 @@ serviceUrl?: string

authorization: {
mpToken?: string //base64 buffer
mpToken?: string // base64 buffer
}

@@ -100,0 +101,0 @@ }

@@ -31,5 +31,2 @@ import http from 'http'

private opts: ICustomReqOpts
private defaultEndPoint = 'tcb-admin.tencentcloudapi.com'
private inScfHost = 'tcb-admin.tencentyun.com'
// private openApiHost: string = 'tcb-open.tencentcloudapi.com'
private urlPath = '/admin'

@@ -359,2 +356,8 @@ private defaultTimeout = 15000

const region = this.config.region || process.env.TENCENTCLOUD_REGION || ''
if (region) {
requiredHeaders['X-TCB-Region'] = region
}
requiredHeaders = { ...config.headers, ...args.headers, ...requiredHeaders }

@@ -385,30 +388,49 @@

private getUrl(): string {
const protocol = this.getProtocol()
const isInSCF = utils.checkIsInScf()
const isInContainer = utils.checkIsInContainer()
const { eventId, seqId } = this.tracingInfo
const { customApiUrl } = this.args
const { serviceUrl } = this.config
const serverInjectUrl = getServerInjectUrl()
const defaultUrl =
isInSCF || isInContainer
? `http://${this.inScfHost}${this.urlPath}`
: `${protocol}://${this.defaultEndPoint}${this.urlPath}`
if (isInSCF) {
// 云函数环境下,应该包含以下环境变量,如果没有,后续逻辑可能会有问题
if (!process.env.TENCENTCLOUD_REGION) {
console.error('[ERROR] missing `TENCENTCLOUD_REGION` environment')
}
if (!process.env.SCF_NAMESPACE) {
console.error('[ERROR] missing `SCF_NAMESPACE` environment')
}
}
let url = serviceUrl || serverInjectUrl || customApiUrl || defaultUrl
const { TCB_ENV, SCF_NAMESPACE } = CloudBase.getCloudbaseContext()
let urlQueryStr = `&eventId=${eventId}&seqId=${seqId}`
const scfContext = CloudBase.scfContext
if (scfContext) {
urlQueryStr = `&eventId=${eventId}&seqId=${seqId}&scfRequestId=${scfContext.request_id}`
}
// 优先级:用户配置 > 环境变量
const region = this.config.region || process.env.TENCENTCLOUD_REGION || ''
const envId = this.config.envName === SYMBOL_CURRENT_ENV
? TCB_ENV || SCF_NAMESPACE
: this.config.envName || ''
if (url.includes('?')) {
url = `${url}${urlQueryStr}`
} else {
url = `${url}?${urlQueryStr}`
}
// 有地域信息则访问地域级别域名,无地域信息则访问默认域名,默认域名固定解析到上海地域保持兼容
const internetRegionEndpoint = region
? `${region}.tcb-api.tencentcloudapi.com`
: `tcb-api.tencentcloudapi.com`
const internalRegionEndpoint = region
? `internal.${region}.tcb-api.tencentcloudapi.com`
: `internal.tcb-api.tencentcloudapi.com`
return url
const endpoint = (isInSCF || isInContainer) ? internalRegionEndpoint : internetRegionEndpoint
const envEndpoint = envId ? `${envId}.${endpoint}` : endpoint
const protocol = isInSCF ? 'http' : this.getProtocol()
// 注意:云函数环境下有地域信息,云应用环境下不确定是否有,如果没有,用户必须显式的传入
const defaultUrl = `${protocol}://${envEndpoint}${this.urlPath}`
const url = serviceUrl || serverInjectUrl || defaultUrl
const qs = CloudBase.scfContext
? `&eventId=${eventId}&seqId=${seqId}&scfRequestId=${CloudBase.scfContext.request_id}`
: `&eventId=${eventId}&seqId=${seqId}`
return url.includes('?') ? `${url}${qs}` : `${url}?${qs}`
}

@@ -415,0 +437,0 @@ }

@@ -44,4 +44,3 @@ import httpRequest from '../utils/httpRequest'

'content-type': 'application/json'
},
customApiUrl: getWxUrl(cloudbase.config)
}
}).then(res => {

@@ -92,3 +91,2 @@ if (res.code) {

isFormData: true,
customApiUrl: getWxUrl(cloudbase.config),
opts

@@ -123,5 +121,4 @@ }).then(res => res)

isFormData: true,
customApiUrl: getWxUrl(cloudbase.config),
opts
})
}

@@ -262,14 +262,3 @@ import * as assert from 'power-assert'

// 校验第一个参数传二维数组
const readRes1 = await collection
.where({
point: db.command.geoWithin({
centerSphere: [[-88, 30], 10 / 6378.1]
})
})
.get()
assert(readRes1.data.length > 0)
assert.deepStrictEqual(readRes1.data[0].point, new Point(-88, 30.001))
// 校验第一个参数传 不符合地理位置规范 二维数组
// 校验第一个参数不传point
try {

@@ -279,3 +268,3 @@ await collection

point: db.command.geoWithin({
centerSphere: [[-288, 30], 10 / 6378.1]
centerSphere: [[-88, 30], 10 / 6378.1]
})

@@ -298,2 +287,3 @@ })

} catch (e) {
console.log(e)
assert(e !== undefined)

@@ -300,0 +290,0 @@ }

@@ -35,2 +35,3 @@ import tcb from '../../lib/index'

it('执行不存在的云函数', async () => {
expect.assertions(1)
try {

@@ -42,3 +43,3 @@ const result = await app.callFunction({

} catch (e) {
assert(e.code === 'FUNCTION_NOT_FOUND')
expect(e.code).toBe('FUNCTION_NOT_FOUND')
}

@@ -88,3 +89,3 @@ })

it('function debug', async () => {
it.only('function debug', async () => {
const app = tcb.init(config)

@@ -91,0 +92,0 @@ const callRes = await app.callFunction({

@@ -6,3 +6,3 @@ import tcb from '../lib/index'

describe('tcb.init: 初始化tcb', () => {
it.skip('mock 导入本地config报错', async () => {
it('mock 导入本地config报错', async () => {
jest.resetModules()

@@ -9,0 +9,0 @@ jest.mock('./config', () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc