Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = require('./lib/core');
module.exports = require('./lib/rpc');
module.exports.ROAClient = require('./lib/roa');
module.exports.RPCClient = require('./lib/core');
module.exports.RPCClient = require('./lib/rpc');
13 changes: 4 additions & 9 deletions lib/core.d.ts → lib/rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@
/*~ This declaration specifies that the class constructor function
*~ is the exported object from the file
*/
export = Core;
export = RPCClient;

/*~ Write your module's methods and properties in this class */
declare class CoreConstructor {
constructor(config: Core.Config);
declare class RPCClient {
constructor(config: RPCClient.Config);

request<T>(action: String, params: Object, options?: Object): Promise<T>;
}

declare class Core extends CoreConstructor {
static ROAClient:typeof CoreConstructor
static RPCClient:typeof CoreConstructor
}

/*~ If you want to expose types from your module as well, you can
*~ place them in this block.
*/
declare namespace Core {
declare namespace RPCClient {
export interface Config {
endpoint: string;
apiVersion: string;
Expand Down
8 changes: 4 additions & 4 deletions lib/core.js → lib/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function canonicalize(normalized) {
return fields.join('&');
}

class Core {
class RPCClient {
constructor(config, verbose) {
assert(config, 'must pass "config"');
assert(config.endpoint, 'must pass "config.endpoint"');
Expand Down Expand Up @@ -182,7 +182,7 @@ class Core {
}).then((buffer) => {
var json = JSON.parse(buffer);
if (json.Code && !this.codes.has(json.Code)) {
var err = new Error(json.Message);
var err = new Error(`${json.Message}, URL: ${url}`);
err.name = json.Code + 'Error';
err.data = json;
err.code = json.Code;
Expand Down Expand Up @@ -210,10 +210,10 @@ class Core {
Version: this.apiVersion,
};
if (this.securityToken) {
defaultParams.SecurityToken = this.securityToken
defaultParams.SecurityToken = this.securityToken;
}
return defaultParams;
}
}

module.exports = Core;
module.exports = RPCClient;
18 changes: 9 additions & 9 deletions test/core.test.js → test/rpc.test.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
'use strict';

const expect = require('expect.js');
const Core = require('../lib/core');
const RPCClient = require('../lib/rpc');

describe('core', function() {
describe('rpc core', function() {
it('should pass into "config"', function() {
expect(function () {
new Core();
new RPCClient();
}).to.throwException(/must pass "config"/);
});

it('should pass into "config.endpoint"', function() {
expect(function () {
new Core({});
new RPCClient({});
}).to.throwException(/must pass "config\.endpoint"/);
});

it('should pass into valid "config.endpoint"', function() {
expect(function () {
new Core({
new RPCClient({
endpoint: 'ecs.aliyuncs.com/'
});
}).to.throwException(/"config\.endpoint" must starts with 'https:\/\/' or 'http:\/\/'\./);
});

it('should pass into "config.apiVersion"', function() {
expect(function () {
new Core({
new RPCClient({
endpoint: 'http://ecs.aliyuncs.com/'
});
}).to.throwException(/must pass "config\.apiVersion"/);
});

it('should pass into "config.accessKeyId"', function() {
expect(function () {
new Core({
new RPCClient({
endpoint: 'http://ecs.aliyuncs.com/',
apiVersion: '1.0'
});
Expand All @@ -43,7 +43,7 @@ describe('core', function() {

it('should pass into "config.accessKeySecret"', function() {
expect(function () {
new Core({
new RPCClient({
endpoint: 'http://ecs.aliyuncs.com/',
apiVersion: '1.0',
accessKeyId: 'accessKeyId'
Expand All @@ -52,7 +52,7 @@ describe('core', function() {
});

describe('request', function() {
var client = new Core({
var client = new RPCClient({
accessKeyId: process.env.ACCESS_KEY_ID,
accessKeySecret: process.env.ACCESS_KEY_SECRET,
endpoint: 'https://ecs.aliyuncs.com',
Expand Down