Skip to content

Commit

Permalink
Merge pull request #12 from kimver/master
Browse files Browse the repository at this point in the history
add typescript support
  • Loading branch information
calvinxiao authored Mar 29, 2019
2 parents 77b499d + 0e47a6a commit d46be67
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
58 changes: 58 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
}

class Api {

constructor(token: string, option?: ApiOption);

// 发送 GET 请求
get(path: string, query?: object): Promise<any>;

// 发送 PUT 请求
put(path: string, data?: object): Promise<any>;

// 发送 POST 请求
post(path: string, data?: object): Promise<any>;

// 发送 DELETE 请求
delete(path: string): Promise<any>;

// 请求函数
request(method: string, path: string, params?: object): Promise<any>
}

class WebHook {
constructor(webHookToken: string);

// 验证WebHook Hmac
verifyHmac(hmac: string, bodyData: string): boolean;
}
}

2 changes: 1 addition & 1 deletion lib/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yhsd-api",
"version": "2.0.0",
"version": "2.1.0",
"description": "Youhaosuda API SDK for node.",
"main": "index.js",
"repository": {
Expand All @@ -25,6 +25,9 @@
"mocha": "^2.3.4",
"should": "^8.0.2"
},
"engines": {
"node": ">= 6.0.0"
},
"dependencies": {
"bluebird": "^3.5.1"
}
Expand Down

0 comments on commit d46be67

Please sign in to comment.