Compare commits

..

6 Commits

Author SHA1 Message Date
Harry Chen 8a5568de77 v2.6.0 2023-12-14 10:43:15 +08:00
Bob 57cd21060b
chore: nacos-naming add more types (#105)
Co-authored-by: Harry Chen <czy88840616@gmail.com>
2023-12-14 10:41:52 +08:00
Nolan Zhang 7fa34ff6a6
chore: add Hosts typings (#97)
I have deployed NACOS version 2.1.1. Has the type changed here because of the version upgrade? I have fixed it
2023-12-13 19:56:09 +08:00
Marc SUN 22c0e57947
chore: add nacos auth supportt typings (#114)
* Update index.d.ts

add nacos auth support

* Update interface.ts

add nacos auth support
2023-12-13 19:54:50 +08:00
陈浩 Nineteen cdea9a26b1
chore: support nacos-sdk-nodejs(2.5.0) example and add auth example (#100) 2023-12-13 19:52:01 +08:00
唯然 50ac48e026
chore: update pkg.license => Apache-2.0 (#101)
rome reports "✖ Unknown license Apache".

refs: https://rome.tools/
2023-03-10 11:23:25 +08:00
10 changed files with 59 additions and 14 deletions

View File

@ -3,8 +3,11 @@
const NacosConfigClient = require('nacos').NacosConfigClient;
const configClient = new NacosConfigClient({
serverAddr: '106.14.43.196:8848',
serverAddr: 'aliyun.nacos.net:80',
namespace: '',
// 如果nacos开启了认证鉴权需要在此处填写用户名密码
// username: 'xxx',
// password: 'xxx'
});
function sleep(time){
@ -18,7 +21,7 @@ function sleep(time){
(async () => {
await configClient.ready();
const dataId = 'nacos.test.1';
const dataId = 'nacos.test.22';
const group = 'DEFAULT_GROUP';
const str = `example_test_${Math.random()}_${Date.now()}`;

View File

@ -2,6 +2,6 @@
"name": "nacos-example",
"version": "1.0.0",
"dependencies": {
"nacos": "^1.0.0"
"nacos": "^2.5.0"
}
}

View File

@ -16,5 +16,5 @@
]
}
},
"version": "2.5.2"
"version": "2.6.0"
}

View File

@ -13,7 +13,7 @@
"ci": "npm run cov",
"build": "lerna run build && cp ./README.md ./packages/nacos/README.md"
},
"license": "Apache",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/nacos-group/nacos-sdk-nodejs/issues"
},

View File

@ -1,6 +1,6 @@
{
"name": "nacos-config",
"version": "2.5.2",
"version": "2.6.0",
"description": "nacos config client",
"keywords": [
"nacos-config",

View File

@ -142,7 +142,7 @@ export class HttpAgent {
// 携带统一的头部信息
Object.assign(headers, {
'Client-Version': VERSION,
'Content-Type': 'application/x-www-form-urlencoded; charset=utf8',
'Content-Type': 'application/x-www-form-urlencoded; charset=GBK',
'Spas-AccessKey': this.accessKey,
timeStamp: ts,
exConfigInfo: 'true',

View File

@ -262,6 +262,8 @@ export interface ClientOptions {
serverAddr?: string; // 用于直连,包含端口
unit?: string; // 内部单元化用
nameServerAddr?: string; // 老的兼容参数,逐步废弃,同 endpoint
username?: string; // 认证的用户名
password?: string; // 认证的密码
cacheDir?: string; // 缓存文件的路径
identityKey?: string; // Identity Key
identityValue?: string; // Identity Value

View File

@ -3,14 +3,35 @@
* Create Time: 2021/8/20 9:12
*/
interface Instance {
instanceId: string,
ip: string, //IP of instance
port: number, //Port of instance
healthy: boolean,
enabled: boolean,
serviceName?: string,
weight?: number,
ephemeral?: boolean,
clusterName?: string
}
type Hosts = string[];
export interface Host {
instanceId: string;
ip: string;
port: number;
weight: number;
healthy: boolean;
enabled: boolean;
ephemeral: boolean;
clusterName: string;
serviceName: string;
metadata: any;
instanceHeartBeatInterval: number;
instanceIdGenerator: string;
instanceHeartBeatTimeOut: number;
ipDeleteTimeout: number;
}
type Hosts = Host[];
interface SubscribeInfo {
serviceName: string,
@ -18,11 +39,22 @@ interface SubscribeInfo {
clusters?: string
}
interface NacosNamingClientConfig {
logger: typeof console,
serverList: string | string[],
namespace?: string,
username?: string,
password?: string,
endpoint?: string,
vipSrvRefInterMillis?: number,
ssl?: boolean
}
/**
* Nacos服务发现组件
*/
export class NacosNamingClient {
constructor (config: { logger: typeof console, serverList: string | string[], namespace?: string })
constructor (config: NacosNamingClientConfig);
ready: () => Promise<void>;
// Register an instance to service
@ -44,6 +76,14 @@ export class NacosNamingClient {
clusters?: string, //Cluster names
subscribe?: boolean //whether subscribe the service, default is true
) => Promise<Hosts>;
// Select instance list of service.
selectInstances: (
serviceName: string,
groupName?: string,
clusters?: string,
healthy?: boolean,
subscribe?: boolean
) => Promise<Hosts>;
// Get the status of nacos server, 'UP' or 'DOWN'.
getServerStatus: () => 'UP' | 'DOWN';
subscribe: (
@ -54,4 +94,4 @@ export class NacosNamingClient {
info: SubscribeInfo | string, //service info, if type is string, it's the serviceName
listener: (host: Hosts) => void //the listener function
) => void;
}
}

View File

@ -1,6 +1,6 @@
{
"name": "nacos-naming",
"version": "2.5.0",
"version": "2.6.0",
"description": "nacos (https://nacos.io/en-us/) nodejs sdk",
"main": "index.js",
"files": [

View File

@ -1,6 +1,6 @@
{
"name": "nacos",
"version": "2.5.2",
"version": "2.6.0",
"description": "nacos client main package",
"keywords": [
"nacos",
@ -12,8 +12,8 @@
"main": "dist/index.js",
"author": "czy88840616@gmail.com",
"dependencies": {
"nacos-config": "^2.5.2",
"nacos-naming": "^2.5.0"
"nacos-config": "^2.6.0",
"nacos-naming": "^2.6.0"
},
"devDependencies": {
"@types/mocha": "^5.2.5",