From 984b6e00a523c88d2d7841f3e7a9de99115be40a Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 22 Mar 2019 17:58:38 +0800 Subject: [PATCH 1/6] add typescript support. --- index.d.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..aae52f5 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,58 @@ +interface ApiOption { + host?: string; + protocol?: string; + getRequestCount?: (token: string) => any; + saveRequestCount?: (token: string) => void; +} + +interface AuthOption { + appKey: string; + appSecret: string; + callbackUrl?: string; + redirectUrl?: string; + scope?: string[]; + private?: boolean; +} + +declare module 'yhsd-api' { + class Auth { + constructor(options: AuthOption); + + // 验证 Hmac + verifyHmac(queryObj: object): boolean; + + // 获取应用授权页面地址,用于开放应用 + getAuthorizeUrl(shopKey: string, state: string): string; + + // 获取 token + getToken(code?: string): Promise; + } + + class Api { + + constructor(token: string, option?: ApiOption); + + // 发送 GET 请求 + get(path: string, query?: object): Promise; + + // 发送 PUT 请求 + put(path: string, data?: object): Promise; + + // 发送 POST 请求 + post(path: string, data?: object): Promise; + + // 发送 DELETE 请求 + delete(path: string): Promise; + + // 请求函数 + request(method: string, path: string, params?: object): Promise + } + + class WebHook { + constructor(webHookToken: string); + + // 验证WebHook Hmac + verifyHmac(hmac: string, bodyData: string): boolean; + } +} + From 3ff3efa93f9d2558371af6888777d198e2ee012d Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 22 Mar 2019 18:01:26 +0800 Subject: [PATCH 2/6] remove DeprecationWarning: Buffer() is deprecated due to security and usability issues. --- lib/Auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Auth.js b/lib/Auth.js index 4bb112f..9e2e119 100644 --- a/lib/Auth.js +++ b/lib/Auth.js @@ -89,7 +89,7 @@ Auth.prototype = { if (this.private) { - headers.Authorization = 'Basic ' + new Buffer(this.app_key + ':' + this.app_secret).toString('base64'); + headers.Authorization = 'Basic ' + Buffer.from(this.app_key + ':' + this.app_secret).toString('base64'); params = { grant_type: 'client_credentials' }; From 29abcb235fe60371971958129aa2244aadf01816 Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 22 Mar 2019 18:01:57 +0800 Subject: [PATCH 3/6] update version => 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 112cd12..3d1b835 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yhsd-api", - "version": "2.0.0", + "version": "2.0.1", "description": "Youhaosuda API SDK for node.", "main": "index.js", "repository": { From 4d10b0573e0c82e1bdcef501ac3d3fb8c5db16dc Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 22 Mar 2019 18:28:22 +0800 Subject: [PATCH 4/6] update travis ci node version. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8798947..d81cf1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: node_js node_js: - - '4.2.2' + - 'v6.17.0' before_script: - npm install - + script: "npm test" after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" From b7a1537ccbab37dbd1056360610325af0e3d0b9f Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 22 Mar 2019 18:35:48 +0800 Subject: [PATCH 5/6] update readme. --- README.md | 2 +- package.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 920ebc3..202b68b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # yhsd-api-node -友好速搭 API SDK for Node(v4.9.1) +友好速搭 API SDK for Node(>= v6) 支持`Promise`依赖[bluebird](https://github.com/petkaantonov/bluebird)。 diff --git a/package.json b/package.json index 3d1b835..b0c507f 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,9 @@ "mocha": "^2.3.4", "should": "^8.0.2" }, + "engines": { + "node": ">= 6.0.0" + }, "dependencies": { "bluebird": "^3.5.1" } From 0e47a6a9e75c98241b261c7a25683ad21e32ee9c Mon Sep 17 00:00:00 2001 From: kimver <1373703100@qq.com> Date: Fri, 29 Mar 2019 10:32:46 +0800 Subject: [PATCH 6/6] change version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0c507f..d9fe9ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yhsd-api", - "version": "2.0.1", + "version": "2.1.0", "description": "Youhaosuda API SDK for node.", "main": "index.js", "repository": {