@alicloud/pop-core
Advanced tools
Comparing version 1.1.2 to 1.2.0
'use strict'; | ||
const assert = require('assert'); | ||
const crypto = require('crypto'); | ||
const httpx = require('httpx'); | ||
const kitx = require('kitx'); | ||
@@ -21,14 +22,11 @@ function firstLetterUpper(str) { | ||
function pad(value) { | ||
return (value < 10) ? '0' + value : '' + value; | ||
} | ||
function timestamp() { | ||
var date = new Date(); | ||
var YYYY = '' + date.getUTCFullYear(); | ||
var MM = pad(date.getUTCMonth() + 1); | ||
var DD = pad(date.getUTCDate()); | ||
var HH = pad(date.getUTCHours()); | ||
var mm = pad(date.getUTCMinutes()); | ||
var ss = pad(date.getUTCSeconds()); | ||
var YYYY = date.getUTCFullYear(); | ||
var MM = kitx.pad2(date.getUTCMonth() + 1); | ||
var DD = kitx.pad2(date.getUTCDate()); | ||
var HH = kitx.pad2(date.getUTCHours()); | ||
var mm = kitx.pad2(date.getUTCMinutes()); | ||
var ss = kitx.pad2(date.getUTCSeconds()); | ||
// 删除掉毫秒部分 | ||
@@ -38,6 +36,2 @@ return `${YYYY}-${MM}-${DD}T${HH}:${mm}:${ss}Z`; | ||
function sha1(str, key) { | ||
return crypto.createHmac('sha1', key).update(str).digest('base64'); | ||
} | ||
function encode(str) { | ||
@@ -79,3 +73,4 @@ var result = encodeURIComponent(str); | ||
assert(config.accessKeyId, 'must pass "config.accessKeyId"'); | ||
assert(config.secretAccessKey, 'must pass "config.secretAccessKey"'); | ||
var accessKeySecret = config.secretAccessKey || config.accessKeySecret; | ||
assert(accessKeySecret, 'must pass "config.accessKeySecret"'); | ||
@@ -89,3 +84,3 @@ if (config.endpoint.endsWith('/')) { | ||
this.accessKeyId = config.accessKeyId; | ||
this.secretAccessKey = config.secretAccessKey; | ||
this.accessKeySecret = accessKeySecret; | ||
this.verbose = verbose === true; | ||
@@ -116,3 +111,4 @@ | ||
// 2.2 get signature | ||
var signature = sha1(stringToSign, this.secretAccessKey + '&'); | ||
const key = this.accessKeySecret + '&'; | ||
var signature = kitx.sha1(stringToSign, key, 'base64'); | ||
// add signature | ||
@@ -162,3 +158,3 @@ normalized.push(['Signature', encode(signature)]); | ||
SignatureMethod: 'HMAC-SHA1', | ||
SignatureNonce: Math.round(Math.random() * 1000000), | ||
SignatureNonce: kitx.makeNonce(), | ||
SignatureVersion: '1.0', | ||
@@ -165,0 +161,0 @@ Timestamp: timestamp(), |
{ | ||
"name": "@alicloud/pop-core", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "AliCloud POP SDK core", | ||
"main": "lib/core.js", | ||
"main": "index.js", | ||
"types": "lib/core.d.ts", | ||
@@ -23,6 +23,8 @@ "scripts": { | ||
"dependencies": { | ||
"httpx": "^2.0.0" | ||
"httpx": "^2.1.1", | ||
"kitx": "^1.2.1" | ||
}, | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"index.js" | ||
], | ||
@@ -29,0 +31,0 @@ "devDependencies": { |
@@ -19,6 +19,8 @@ # @alicloud/pop-core | ||
The RPC style client: | ||
```js | ||
var Core = require('@alicloud/pop-core'); | ||
var RPCClient = require('@alicloud/pop-core').RPCClient; | ||
var client = new Core({ | ||
var client = new RPCClient({ | ||
accessKeyId: '<accessKeyId>', | ||
@@ -35,3 +37,21 @@ secretAccessKey: '<secretAccessKey>', | ||
The ROA style client: | ||
```js | ||
var ROAClient = require('@alicloud/pop-core').ROAClient; | ||
var client = new ROAClient({ | ||
accessKeyId: '<accessKeyId>', | ||
accessKeySecret: '<secretAccessKey>', | ||
endpoint: '<endpoint>', | ||
apiVersion: '<apiVersion>' | ||
}); | ||
// => returns Promise | ||
// request(HTTPMethod, uriPath, queries, body, headers); | ||
client.request('GET', '/regions'); | ||
// co/yield, async/await | ||
``` | ||
## License | ||
The MIT License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12863
7
310
56
2
4
+ Addedkitx@^1.2.1
+ Addedkitx@1.3.0(transitive)
Updatedhttpx@^2.1.1