正在显示
47 个修改的文件
包含
3976 行增加
和
4 行删除
node_modules/@alicloud/dybaseapi/.npmignore
0 → 100644
| 1 | + | ||
| 2 | +'use strict'; | ||
| 3 | + | ||
| 4 | +const { RPCClient } = require('@alicloud/pop-core'); | ||
| 5 | + | ||
| 6 | +function hasOwnProperty(obj, key) { | ||
| 7 | + return Object.prototype.hasOwnProperty.call(obj, key); | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +class Client extends RPCClient { | ||
| 11 | + constructor(config) { | ||
| 12 | + config.apiVersion = '2017-05-25'; | ||
| 13 | + super(config); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + queryTokenForMnsQueue(params = {}, options) { | ||
| 17 | + if (!hasOwnProperty(params, 'MessageType')) { | ||
| 18 | + throw new TypeError('parameter "MessageType" is required'); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + return this.request('QueryTokenForMnsQueue', params, options); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +module.exports = Client; |
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "@alicloud/dybaseapi@^1.0.0", | ||
| 6 | + "scope": "@alicloud", | ||
| 7 | + "escapedName": "@alicloud%2fdybaseapi", | ||
| 8 | + "name": "@alicloud/dybaseapi", | ||
| 9 | + "rawSpec": "^1.0.0", | ||
| 10 | + "spec": ">=1.0.0 <2.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "@alicloud/dybaseapi@>=1.0.0 <2.0.0", | ||
| 17 | + "_id": "@alicloud/dybaseapi@1.0.0", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/@alicloud/dybaseapi", | ||
| 20 | + "_nodeVersion": "8.1.4", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/dybaseapi-1.0.0.tgz_1501232100324_0.6043512229807675" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "5.0.3", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "@alicloud/dybaseapi@^1.0.0", | ||
| 33 | + "scope": "@alicloud", | ||
| 34 | + "escapedName": "@alicloud%2fdybaseapi", | ||
| 35 | + "name": "@alicloud/dybaseapi", | ||
| 36 | + "rawSpec": "^1.0.0", | ||
| 37 | + "spec": ">=1.0.0 <2.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/sms-sdk" | ||
| 42 | + ], | ||
| 43 | + "_resolved": "https://registry.npmjs.org/@alicloud/dybaseapi/-/dybaseapi-1.0.0.tgz", | ||
| 44 | + "_shasum": "552edd0990f90dbd69d40237cdfeffc366d0a1f5", | ||
| 45 | + "_shrinkwrap": null, | ||
| 46 | + "_spec": "@alicloud/dybaseapi@^1.0.0", | ||
| 47 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk", | ||
| 48 | + "author": { | ||
| 49 | + "name": "Jackson Tian" | ||
| 50 | + }, | ||
| 51 | + "dependencies": { | ||
| 52 | + "@alicloud/pop-core": "^1.3.3" | ||
| 53 | + }, | ||
| 54 | + "description": "Dybaseapi SDK", | ||
| 55 | + "devDependencies": {}, | ||
| 56 | + "directories": {}, | ||
| 57 | + "dist": { | ||
| 58 | + "integrity": "sha512-4KEDgqES7IL60T/TWGSkLQkN6BYeHEw8smnPgac2J2MTES5v1ieCWvbLSuUUWi5SAXi7cydKoD4HUOmX7xwM+A==", | ||
| 59 | + "shasum": "552edd0990f90dbd69d40237cdfeffc366d0a1f5", | ||
| 60 | + "tarball": "https://registry.npmjs.org/@alicloud/dybaseapi/-/dybaseapi-1.0.0.tgz" | ||
| 61 | + }, | ||
| 62 | + "gitHead": "62285c0fb2fc5772b31812621a52bda85ad5d2ee", | ||
| 63 | + "license": "MIT", | ||
| 64 | + "main": "lib/client.js", | ||
| 65 | + "maintainers": [ | ||
| 66 | + { | ||
| 67 | + "name": "jacksontian", | ||
| 68 | + "email": "shyvo1987@gmail.com" | ||
| 69 | + } | ||
| 70 | + ], | ||
| 71 | + "name": "@alicloud/dybaseapi", | ||
| 72 | + "optionalDependencies": {}, | ||
| 73 | + "readme": "ERROR: No README data found!", | ||
| 74 | + "scripts": {}, | ||
| 75 | + "version": "1.0.0" | ||
| 76 | +} |
node_modules/@alicloud/dysmsapi/.npmignore
0 → 100644
| 1 | + | ||
| 2 | +'use strict'; | ||
| 3 | + | ||
| 4 | +const { RPCClient } = require('@alicloud/pop-core'); | ||
| 5 | + | ||
| 6 | +function hasOwnProperty(obj, key) { | ||
| 7 | + return Object.prototype.hasOwnProperty.call(obj, key); | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +class Client extends RPCClient { | ||
| 11 | + constructor(config) { | ||
| 12 | + config.apiVersion = '2017-05-25'; | ||
| 13 | + super(config); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + queryInterSmsIsoInfo(params = {}, options) { | ||
| 17 | + return this.request('QueryInterSmsIsoInfo', params, options); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + querySendDetails(params = {}, options) { | ||
| 21 | + if (!hasOwnProperty(params, 'PhoneNumber')) { | ||
| 22 | + throw new TypeError('parameter "PhoneNumber" is required'); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + if (!hasOwnProperty(params, 'SendDate')) { | ||
| 26 | + throw new TypeError('parameter "SendDate" is required'); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + if (!hasOwnProperty(params, 'PageSize')) { | ||
| 30 | + throw new TypeError('parameter "PageSize" is required'); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + if (!hasOwnProperty(params, 'CurrentPage')) { | ||
| 34 | + throw new TypeError('parameter "CurrentPage" is required'); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + return this.request('QuerySendDetails', params, options); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + sendInterSms(params = {}, options) { | ||
| 41 | + if (!hasOwnProperty(params, 'CountryCode')) { | ||
| 42 | + throw new TypeError('parameter "CountryCode" is required'); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + if (!hasOwnProperty(params, 'PhoneNumbers')) { | ||
| 46 | + throw new TypeError('parameter "PhoneNumbers" is required'); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + if (!hasOwnProperty(params, 'SignName')) { | ||
| 50 | + throw new TypeError('parameter "SignName" is required'); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + if (!hasOwnProperty(params, 'TemplateCode')) { | ||
| 54 | + throw new TypeError('parameter "TemplateCode" is required'); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + return this.request('SendInterSms', params, options); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + sendSms(params = {}, options) { | ||
| 61 | + if (!hasOwnProperty(params, 'PhoneNumbers')) { | ||
| 62 | + throw new TypeError('parameter "PhoneNumbers" is required'); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + if (!hasOwnProperty(params, 'SignName')) { | ||
| 66 | + throw new TypeError('parameter "SignName" is required'); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + if (!hasOwnProperty(params, 'TemplateCode')) { | ||
| 70 | + throw new TypeError('parameter "TemplateCode" is required'); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + return this.request('SendSms', params, options); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +module.exports = Client; |
node_modules/@alicloud/dysmsapi/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "@alicloud/dysmsapi@^1.0.0", | ||
| 6 | + "scope": "@alicloud", | ||
| 7 | + "escapedName": "@alicloud%2fdysmsapi", | ||
| 8 | + "name": "@alicloud/dysmsapi", | ||
| 9 | + "rawSpec": "^1.0.0", | ||
| 10 | + "spec": ">=1.0.0 <2.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "@alicloud/dysmsapi@>=1.0.0 <2.0.0", | ||
| 17 | + "_id": "@alicloud/dysmsapi@1.0.0", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/@alicloud/dysmsapi", | ||
| 20 | + "_nodeVersion": "8.1.4", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/dysmsapi-1.0.0.tgz_1501232179304_0.009140280773863196" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "5.0.3", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "@alicloud/dysmsapi@^1.0.0", | ||
| 33 | + "scope": "@alicloud", | ||
| 34 | + "escapedName": "@alicloud%2fdysmsapi", | ||
| 35 | + "name": "@alicloud/dysmsapi", | ||
| 36 | + "rawSpec": "^1.0.0", | ||
| 37 | + "spec": ">=1.0.0 <2.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/sms-sdk" | ||
| 42 | + ], | ||
| 43 | + "_resolved": "https://registry.npmjs.org/@alicloud/dysmsapi/-/dysmsapi-1.0.0.tgz", | ||
| 44 | + "_shasum": "712ddd7ecff5c063537a3c304867d2eae02ffc95", | ||
| 45 | + "_shrinkwrap": null, | ||
| 46 | + "_spec": "@alicloud/dysmsapi@^1.0.0", | ||
| 47 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk", | ||
| 48 | + "author": { | ||
| 49 | + "name": "Jackson Tian" | ||
| 50 | + }, | ||
| 51 | + "dependencies": { | ||
| 52 | + "@alicloud/pop-core": "^1.3.3" | ||
| 53 | + }, | ||
| 54 | + "description": "Dysmsapi SDK", | ||
| 55 | + "devDependencies": {}, | ||
| 56 | + "directories": {}, | ||
| 57 | + "dist": { | ||
| 58 | + "integrity": "sha512-EKfEk/1g1+1UflbPDTISGhl9Zm+cnaxN792gWsqSzgqNmYAZs8DdXhf9ZvnoexiHvftmrHhQyXZZNGkozKK28g==", | ||
| 59 | + "shasum": "712ddd7ecff5c063537a3c304867d2eae02ffc95", | ||
| 60 | + "tarball": "https://registry.npmjs.org/@alicloud/dysmsapi/-/dysmsapi-1.0.0.tgz" | ||
| 61 | + }, | ||
| 62 | + "gitHead": "5afcc0844a738d5b0680dae9aea70baeb7e59523", | ||
| 63 | + "license": "MIT", | ||
| 64 | + "main": "lib/client.js", | ||
| 65 | + "maintainers": [ | ||
| 66 | + { | ||
| 67 | + "name": "jacksontian", | ||
| 68 | + "email": "shyvo1987@gmail.com" | ||
| 69 | + } | ||
| 70 | + ], | ||
| 71 | + "name": "@alicloud/dysmsapi", | ||
| 72 | + "optionalDependencies": {}, | ||
| 73 | + "readme": "ERROR: No README data found!", | ||
| 74 | + "scripts": {}, | ||
| 75 | + "version": "1.0.0" | ||
| 76 | +} |
node_modules/@alicloud/mns/LICENSE
0 → 100644
| 1 | +MIT License | ||
| 2 | + | ||
| 3 | +Copyright (c) 2017 Alibaba Cloud | ||
| 4 | + | ||
| 5 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 6 | +of this software and associated documentation files (the "Software"), to deal | ||
| 7 | +in the Software without restriction, including without limitation the rights | ||
| 8 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 9 | +copies of the Software, and to permit persons to whom the Software is | ||
| 10 | +furnished to do so, subject to the following conditions: | ||
| 11 | + | ||
| 12 | +The above copyright notice and this permission notice shall be included in all | ||
| 13 | +copies or substantial portions of the Software. | ||
| 14 | + | ||
| 15 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 16 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 17 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 18 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 19 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 20 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 21 | +SOFTWARE. |
node_modules/@alicloud/mns/README.md
0 → 100644
| 1 | +# mns-nodejs-sdk | ||
| 2 | + | ||
| 3 | +[![NPM version][npm-image]][npm-url] | ||
| 4 | +[![build status][travis-image]][travis-url] | ||
| 5 | +[![coverage][cov-image]][cov-url] | ||
| 6 | + | ||
| 7 | +[npm-image]: https://img.shields.io/npm/v/@alicloud/mns.svg?style=flat-square | ||
| 8 | +[npm-url]: https://npmjs.org/package/@alicloud/mns | ||
| 9 | +[travis-image]: https://img.shields.io/travis/aliyun/mns-nodejs-sdk/master.svg?style=flat-square | ||
| 10 | +[travis-url]: https://travis-ci.org/aliyun/mns-nodejs-sdk.svg?branch=master | ||
| 11 | +[cov-image]: https://coveralls.io/repos/aliyun/mns-nodejs-sdk/badge.svg?branch=master&service=github | ||
| 12 | +[cov-url]: https://coveralls.io/github/aliyun/mns-nodejs-sdk?branch=master | ||
| 13 | + | ||
| 14 | +Documents: http://doxmate.cool/aliyun/mns-nodejs-sdk/api.html | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +> 该 SDK 并未完全实现所有文档所提及的功能,如果您想使用的功能并未实现,请提[issue](https://github.com/aliyun/mns-nodejs-sdk/issues/new)以增加优先级。 | ||
| 18 | + | ||
| 19 | +## Installation | ||
| 20 | + | ||
| 21 | +```bash | ||
| 22 | +npm install @alicloud/mns --save | ||
| 23 | +``` | ||
| 24 | + | ||
| 25 | +## API Spec | ||
| 26 | + | ||
| 27 | +See: https://help.aliyun.com/document_detail/27475.html | ||
| 28 | + | ||
| 29 | +## Test | ||
| 30 | + | ||
| 31 | +```sh | ||
| 32 | +ACCOUNT_ID=<ACCOUNT_ID> ACCESS_KEY_ID=<ACCESS_KEY_ID> ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET> make test | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +## Installation | ||
| 36 | + | ||
| 37 | +You can install it via npm/cnpm/yarn. | ||
| 38 | + | ||
| 39 | +```sh | ||
| 40 | +$ npm install @alicloud/mns --save | ||
| 41 | +``` | ||
| 42 | + | ||
| 43 | +## Usage | ||
| 44 | + | ||
| 45 | +```js | ||
| 46 | +const MNSClient = require('@alicloud/mns'); | ||
| 47 | + | ||
| 48 | +const accountid = '<account id>'; | ||
| 49 | +var client = new MNSClient(accountid, { | ||
| 50 | + region: '<region>', | ||
| 51 | + accessKeyId: '<access key id>', | ||
| 52 | + accessKeySecret: '<access key secret>', | ||
| 53 | + // optional & default | ||
| 54 | + secure: false, // use https or http | ||
| 55 | + internal: false, // use internal endpoint | ||
| 56 | + vpc: false // use vpc endpoint | ||
| 57 | +}); | ||
| 58 | + | ||
| 59 | +(async function () { | ||
| 60 | + let res; | ||
| 61 | + // create queue | ||
| 62 | + res = await client.createQueue('test-queue2'); | ||
| 63 | + console.log(res); | ||
| 64 | + // list queue | ||
| 65 | + res = await client.listQueue(); | ||
| 66 | + console.log(JSON.stringify(res, null, 2)); | ||
| 67 | + // create topic | ||
| 68 | + res = await client.createTopic('test-topic'); | ||
| 69 | + console.log(res); | ||
| 70 | + // get topic attributes | ||
| 71 | + res = await client.getTopicAttributes('test-topic'); | ||
| 72 | + console.log(res); | ||
| 73 | + // publish message | ||
| 74 | + res = await client.publishMessage('<topic name>', { | ||
| 75 | + MessageBody: 'content', | ||
| 76 | + MessageAttributes: { | ||
| 77 | + DirectSMS: JSON.stringify({ | ||
| 78 | + FreeSignName: '', | ||
| 79 | + TemplateCode: '<template code>', | ||
| 80 | + Type: '<type>', | ||
| 81 | + Receiver: '<phone number>', | ||
| 82 | + SmsParams: JSON.stringify({ | ||
| 83 | + code: '<code>', | ||
| 84 | + product: '<product>' | ||
| 85 | + }) | ||
| 86 | + }) | ||
| 87 | + } | ||
| 88 | + }); | ||
| 89 | + console.log(res); | ||
| 90 | +})().then((data) => { | ||
| 91 | + console.log(data); | ||
| 92 | +}, (err) => { | ||
| 93 | + console.log(err.stack); | ||
| 94 | +}); | ||
| 95 | +``` | ||
| 96 | + | ||
| 97 | +## License | ||
| 98 | + | ||
| 99 | +The [MIT](LICENSE) License |
node_modules/@alicloud/mns/index.js
0 → 100644
node_modules/@alicloud/mns/lib/client.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const assert = require('assert'); | ||
| 4 | + | ||
| 5 | +const debug = require('debug')('mns:client'); | ||
| 6 | +const httpx = require('httpx'); | ||
| 7 | +const kitx = require('kitx'); | ||
| 8 | + | ||
| 9 | +const { | ||
| 10 | + getEndpoint, | ||
| 11 | + toXMLBuffer, | ||
| 12 | + parseXML, | ||
| 13 | + extract, | ||
| 14 | + getResponseHeaders, | ||
| 15 | + getCanonicalizedMNSHeaders | ||
| 16 | +} = require('./helper'); | ||
| 17 | + | ||
| 18 | +class Client { | ||
| 19 | + constructor(accountid, opts) { | ||
| 20 | + assert(accountid, '"accountid" must be passed in'); | ||
| 21 | + this.accountid = accountid; | ||
| 22 | + assert(opts, 'must pass in "opts"'); | ||
| 23 | + // 兼容 | ||
| 24 | + const accessKeyID = opts.accessKeyId || opts.accessKeyID; | ||
| 25 | + assert(accessKeyID, 'must pass in "opts.accessKeyID"'); | ||
| 26 | + this.accessKeyID = accessKeyID; | ||
| 27 | + assert(opts.accessKeySecret, 'must pass in "opts.accessKeySecret"'); | ||
| 28 | + this.accessKeySecret = opts.accessKeySecret; | ||
| 29 | + assert(opts.region, 'must pass in "opts.region"'); | ||
| 30 | + const {domain, endpoint} = getEndpoint(accountid, opts); | ||
| 31 | + this.endpointDomain = domain; | ||
| 32 | + this.endpoint = endpoint; | ||
| 33 | + | ||
| 34 | + // security token | ||
| 35 | + this.securityToken = opts.securityToken; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + async request(method, resource, type, requestBody, attentions = [], opts = {}) { | ||
| 39 | + const url = `${this.endpoint}${resource}`; | ||
| 40 | + debug('url: %s', url); | ||
| 41 | + debug('method: %s', method); | ||
| 42 | + const headers = this.buildHeaders(method, requestBody, resource, opts.headers); | ||
| 43 | + debug('request headers: %j', headers); | ||
| 44 | + debug('request body: %s', requestBody.toString()); | ||
| 45 | + const response = await httpx.request(url, Object.assign(opts, { | ||
| 46 | + method: method, | ||
| 47 | + headers: headers, | ||
| 48 | + data: requestBody | ||
| 49 | + })); | ||
| 50 | + | ||
| 51 | + debug('statusCode %s', response.statusCode); | ||
| 52 | + debug('response headers: %j', response.headers); | ||
| 53 | + const code = response.statusCode; | ||
| 54 | + | ||
| 55 | + const contentType = response.headers['content-type'] || ''; | ||
| 56 | + // const contentLength = response.headers['content-length']; | ||
| 57 | + const responseBody = await httpx.read(response, 'utf8'); | ||
| 58 | + debug('response body: %s', responseBody); | ||
| 59 | + | ||
| 60 | + var body; | ||
| 61 | + if (responseBody && contentType.startsWith('text/xml')) { | ||
| 62 | + const responseData = await parseXML(responseBody); | ||
| 63 | + | ||
| 64 | + if (responseData.Error) { | ||
| 65 | + const e = responseData.Error; | ||
| 66 | + const message = extract(e.Message); | ||
| 67 | + const requestid = extract(e.RequestId); | ||
| 68 | + const hostid = extract(e.HostId); | ||
| 69 | + const err = new Error(`${method} ${url} failed with ${code}. ` + | ||
| 70 | + `requestid: ${requestid}, hostid: ${hostid}, message: ${message}`); | ||
| 71 | + err.name = 'MNS' + extract(e.Code) + err.name; | ||
| 72 | + throw err; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + body = {}; | ||
| 76 | + Object.keys(responseData[type]).forEach((key) => { | ||
| 77 | + if (key !== '$') { | ||
| 78 | + body[key] = extract(responseData[type][key]); | ||
| 79 | + } | ||
| 80 | + }); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + return { | ||
| 84 | + code, | ||
| 85 | + headers: getResponseHeaders(response.headers, attentions), | ||
| 86 | + body: body | ||
| 87 | + }; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + get(resource, type, opts) { | ||
| 91 | + return this.request('GET', resource, type, '', [], opts); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + put(resource, type, body, attentions = [], opts = {}) { | ||
| 95 | + return this.request('PUT', resource, type, body, attentions, opts); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + post(resource, type, body) { | ||
| 99 | + return this.request('POST', resource, type, body); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + delete(resource) { | ||
| 103 | + return this.request('DELETE', resource, undefined, ''); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + sign(verb, headers, resource) { | ||
| 107 | + const canonicalizedMNSHeaders = getCanonicalizedMNSHeaders(headers); | ||
| 108 | + const md5 = headers['content-md5'] || ''; | ||
| 109 | + const date = headers['date']; | ||
| 110 | + const type = headers['content-type'] || ''; | ||
| 111 | + | ||
| 112 | + var toSignString = `${verb}\n${md5}\n${type}\n${date}\n${canonicalizedMNSHeaders}${resource}`; | ||
| 113 | + // Signature = base64(hmac-sha1(VERB + "\n" | ||
| 114 | + // + CONTENT-MD5 + "\n" | ||
| 115 | + // + CONTENT-TYPE + "\n" | ||
| 116 | + // + DATE + "\n" | ||
| 117 | + // + CanonicalizedMNSHeaders | ||
| 118 | + // + CanonicalizedResource)) | ||
| 119 | + var buff = Buffer.from(toSignString, 'utf8'); | ||
| 120 | + const degist = kitx.sha1(buff, this.accessKeySecret, 'binary'); | ||
| 121 | + return Buffer.from(degist, 'binary').toString('base64'); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + buildHeaders(method, body, resource, customHeaders) { | ||
| 125 | + const date = new Date().toGMTString(); | ||
| 126 | + | ||
| 127 | + const headers = { | ||
| 128 | + 'date': date, | ||
| 129 | + 'host': this.endpointDomain, | ||
| 130 | + 'x-mns-date': date, | ||
| 131 | + 'x-mns-version': '2015-06-06' | ||
| 132 | + }; | ||
| 133 | + | ||
| 134 | + if (method !== 'GET' && method !== 'HEAD') { | ||
| 135 | + const contentType = 'text/xml'; | ||
| 136 | + const digest = kitx.md5(body, 'hex'); | ||
| 137 | + const md5 = Buffer.from(digest, 'utf8').toString('base64'); | ||
| 138 | + Object.assign(headers, { | ||
| 139 | + 'content-length': body.length, | ||
| 140 | + 'content-type': contentType, | ||
| 141 | + 'content-md5': md5 | ||
| 142 | + }); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + Object.assign(headers, customHeaders); | ||
| 146 | + | ||
| 147 | + const signature = this.sign(method, headers, resource); | ||
| 148 | + | ||
| 149 | + headers['authorization'] = `MNS ${this.accessKeyID}:${signature}`; | ||
| 150 | + | ||
| 151 | + if (this.securityToken) { | ||
| 152 | + headers['security-token'] = this.securityToken; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + return headers; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + // Queue | ||
| 159 | + createQueue(name, params = {}) { | ||
| 160 | + const body = toXMLBuffer('Queue', params); | ||
| 161 | + const url = `/queues/${name}`; | ||
| 162 | + return this.put(url, 'Queue', body, ['location']); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + deleteQueue(name) { | ||
| 166 | + return this.delete(`/queues/${name}`, 'Queue', ''); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + async listQueue(start, limit, prefix) { | ||
| 170 | + var customHeaders = {}; | ||
| 171 | + if (typeof start !== 'undefined') { | ||
| 172 | + customHeaders['x-mns-marker'] = start; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + if (typeof limit !== 'undefined') { | ||
| 176 | + customHeaders['x-mns-ret-number'] = limit; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + if (typeof limit !== 'undefined') { | ||
| 180 | + customHeaders['x-mns-prefix'] = prefix; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + const subType = 'Queue'; | ||
| 184 | + const response = await this.get('/queues', 'Queues', { | ||
| 185 | + headers: customHeaders | ||
| 186 | + }); | ||
| 187 | + response.body = response.body[subType]; | ||
| 188 | + return response; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + getQueueAttributes(queueName) { | ||
| 192 | + return this.get(`/queues/${queueName}`, 'Queue'); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + setQueueAttributes(queueName, params = {}) { | ||
| 196 | + const body = toXMLBuffer('Queue', params); | ||
| 197 | + const url = `/queues/${queueName}?metaoverride=true`; | ||
| 198 | + return this.put(url, 'Queue', body); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + // Message | ||
| 202 | + sendMessage(queueName, params) { | ||
| 203 | + const url = `/queues/${queueName}/messages`; | ||
| 204 | + const body = toXMLBuffer('Message', params); | ||
| 205 | + return this.post(url, 'Message', body); | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + async batchSendMessage(queueName, params) { | ||
| 209 | + const url = `/queues/${queueName}/messages`; | ||
| 210 | + const subType = 'Message'; | ||
| 211 | + const body = toXMLBuffer('Messages', params, subType); | ||
| 212 | + var response = await this.post(url, 'Messages', body); | ||
| 213 | + response.body = response.body[subType]; | ||
| 214 | + return response; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + receiveMessage(queueName, waitSeconds) { | ||
| 218 | + var url = `/queues/${queueName}/messages`; | ||
| 219 | + if (waitSeconds) { | ||
| 220 | + url += `?waitseconds=${waitSeconds}`; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + // 31000 31s +1s max waitSeconds is 30s | ||
| 224 | + return this.get(url, 'Message', {timeout: 31000}); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + async batchReceiveMessage(queueName, numOfMessages, waitSeconds) { | ||
| 228 | + var url = `/queues/${queueName}/messages?numOfMessages=${numOfMessages}`; | ||
| 229 | + if (waitSeconds) { | ||
| 230 | + url += `&waitseconds=${waitSeconds}`; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + const subType = 'Message'; | ||
| 234 | + // 31000 31s +1s max waitSeconds is 30s | ||
| 235 | + var response = await this.get(url, 'Messages', {timeout: 31000}); | ||
| 236 | + response.body = response.body[subType]; | ||
| 237 | + return response; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + peekMessage(queueName) { | ||
| 241 | + return this.get(`/queues/${queueName}/messages?peekonly=true`, 'Message'); | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + async batchPeekMessage(queueName, numOfMessages) { | ||
| 245 | + const url = `/queues/${queueName}/messages?` + | ||
| 246 | + `peekonly=true&numOfMessages=${numOfMessages}`; | ||
| 247 | + | ||
| 248 | + const subType = 'Message'; | ||
| 249 | + // 31000 31s +1s max waitSeconds is 30s | ||
| 250 | + var response = await this.get(url, 'Messages'); | ||
| 251 | + response.body = response.body[subType]; | ||
| 252 | + return response; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + deleteMessage(queueName, receiptHandle) { | ||
| 256 | + const url = `/queues/${queueName}/messages?ReceiptHandle=${receiptHandle}`; | ||
| 257 | + return this.delete(url, 'Message', ''); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + async batchDeleteMessage(queueName, receiptHandles) { | ||
| 261 | + const body = toXMLBuffer('ReceiptHandles', receiptHandles); | ||
| 262 | + const url = `/queues/${queueName}/messages`; | ||
| 263 | + const response = await this.delete(url, 'Errors', body); | ||
| 264 | + const subType = 'Error'; | ||
| 265 | + response.body = response.body[subType]; | ||
| 266 | + return response; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + changeMessageVisibility(queueName, receiptHandle, visibilityTimeout) { | ||
| 270 | + const url = `/queues/${queueName}/messages?` + | ||
| 271 | + `receiptHandle=${receiptHandle}&visibilityTimeout=${visibilityTimeout}`; | ||
| 272 | + return this.put(url, 'ChangeVisibility'); | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + // Topic | ||
| 276 | + createTopic(name, params = {}) { | ||
| 277 | + const body = toXMLBuffer('Topic', params); | ||
| 278 | + return this.put(`/topics/${name}`, 'Topic', body, ['location']); | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + deleteTopic() {} | ||
| 282 | + async listTopic(start, limit, prefix) { | ||
| 283 | + var customHeaders = {}; | ||
| 284 | + if (typeof start !== 'undefined') { | ||
| 285 | + customHeaders['x-mns-marker'] = start; | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + if (typeof limit !== 'undefined') { | ||
| 289 | + customHeaders['x-mns-ret-number'] = limit; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + if (typeof limit !== 'undefined') { | ||
| 293 | + customHeaders['x-mns-prefix'] = prefix; | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + const subType = 'Topic'; | ||
| 297 | + const response = await this.get('/topics', 'Topics', { | ||
| 298 | + headers: customHeaders | ||
| 299 | + }); | ||
| 300 | + response.body = response.body[subType]; | ||
| 301 | + return response; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + getTopicAttributes(name) { | ||
| 305 | + return this.get(`/topics/${name}`, 'Topic'); | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + setTopicAttributes(name, params = {}) { | ||
| 309 | + const body = toXMLBuffer('Topic', params); | ||
| 310 | + const url = `/topics/${name}?metaoverride=true`; | ||
| 311 | + return this.put(url, 'Topic', body); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + // Subscription | ||
| 315 | + subscribe() {} | ||
| 316 | + unsubscribe() {} | ||
| 317 | + listSubscriptionByTopic() {} | ||
| 318 | + getSubscriptionAttributes() {} | ||
| 319 | + setSubscriptionAttributes() {} | ||
| 320 | + | ||
| 321 | + // Message | ||
| 322 | + publishMessage(topic, params) { | ||
| 323 | + const url = `/topics/${topic}/messages`; | ||
| 324 | + const body = toXMLBuffer('Message', params); | ||
| 325 | + return this.post(url, 'Message', body); | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + // Notifications | ||
| 329 | + httpEndpoint() {} | ||
| 330 | +} | ||
| 331 | + | ||
| 332 | +module.exports = Client; |
node_modules/@alicloud/mns/lib/helper.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const xml2js = require('xml2js'); | ||
| 4 | + | ||
| 5 | +exports.parseXML = function (input) { | ||
| 6 | + return new Promise((resolve, reject) => { | ||
| 7 | + xml2js.parseString(input, (err, obj) => { | ||
| 8 | + if (err) { | ||
| 9 | + return reject(err); | ||
| 10 | + } | ||
| 11 | + resolve(obj); | ||
| 12 | + }); | ||
| 13 | + }); | ||
| 14 | +}; | ||
| 15 | + | ||
| 16 | +exports.extract = function extract (arr) { | ||
| 17 | + if (arr && arr.length === 1 && typeof arr[0] === 'string') { | ||
| 18 | + return arr[0]; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + arr.forEach((item) => { | ||
| 22 | + Object.keys(item).forEach((key) => { | ||
| 23 | + item[key] = extract(item[key]); | ||
| 24 | + }); | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + return arr; | ||
| 28 | +}; | ||
| 29 | + | ||
| 30 | +function format (params) { | ||
| 31 | + var xml = ''; | ||
| 32 | + Object.keys(params).forEach((key) => { | ||
| 33 | + const value = params[key]; | ||
| 34 | + if (typeof value === 'object') { | ||
| 35 | + xml += `<${key}>${format(value)}</${key}>`; | ||
| 36 | + } else { | ||
| 37 | + xml += `<${key}>${value}</${key}>`; | ||
| 38 | + } | ||
| 39 | + }); | ||
| 40 | + return xml; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +exports.toXMLBuffer = function (entityType, params, subType) { | ||
| 44 | + var xml = '<?xml version="1.0" encoding="UTF-8"?>'; | ||
| 45 | + xml += `<${entityType} xmlns="http://mns.aliyuncs.com/doc/v1/">`; | ||
| 46 | + if (Array.isArray(params)) { | ||
| 47 | + params.forEach((item) => { | ||
| 48 | + xml += `<${subType}>`; | ||
| 49 | + xml += format(item); | ||
| 50 | + xml += `</${subType}>`; | ||
| 51 | + }); | ||
| 52 | + } else { | ||
| 53 | + xml += format(params); | ||
| 54 | + } | ||
| 55 | + xml += `</${entityType}>`; | ||
| 56 | + return Buffer.from(xml, 'utf8'); | ||
| 57 | +}; | ||
| 58 | + | ||
| 59 | +// http(s)://{AccountId}.mns.cn-beijing.aliyuncs.com | ||
| 60 | +// http://{AccountId}.mns.cn-beijing-internal.aliyuncs.com | ||
| 61 | +// http://{AccountId}.mns.cn-beijing-internal-vpc.aliyuncs.com | ||
| 62 | + | ||
| 63 | +exports.getEndpoint = function (accountid, opts) { | ||
| 64 | + const protocol = opts.secure ? 'https' : 'http'; | ||
| 65 | + let region = `${opts.region}`; | ||
| 66 | + if (opts.internal) { | ||
| 67 | + region += '-internal'; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + if (opts.vpc) { | ||
| 71 | + region += '-vpc'; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + return { | ||
| 75 | + endpoint: `${protocol}://${accountid}.mns.${region}.aliyuncs.com`, | ||
| 76 | + domain: `${accountid}.mns.${region}.aliyuncs.com` | ||
| 77 | + }; | ||
| 78 | +}; | ||
| 79 | + | ||
| 80 | +exports.getCanonicalizedMNSHeaders = function (headers) { | ||
| 81 | + return Object.keys(headers) | ||
| 82 | + .filter((key) => key.startsWith('x-mns-')) | ||
| 83 | + .sort() | ||
| 84 | + .map((key) => `${key}:${headers[key]}\n`) | ||
| 85 | + .join(''); | ||
| 86 | +}; | ||
| 87 | + | ||
| 88 | +exports.getResponseHeaders = function (headers, attentions) { | ||
| 89 | + var result = {}; | ||
| 90 | + attentions.forEach((key) => { | ||
| 91 | + result[key] = headers[key]; | ||
| 92 | + }); | ||
| 93 | + return result; | ||
| 94 | +}; |
node_modules/@alicloud/mns/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "@alicloud/mns@^1.0.0-beta4", | ||
| 6 | + "scope": "@alicloud", | ||
| 7 | + "escapedName": "@alicloud%2fmns", | ||
| 8 | + "name": "@alicloud/mns", | ||
| 9 | + "rawSpec": "^1.0.0-beta4", | ||
| 10 | + "spec": ">=1.0.0-beta4 <2.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "@alicloud/mns@>=1.0.0-beta4 <2.0.0", | ||
| 17 | + "_id": "@alicloud/mns@1.0.0-beta5", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/@alicloud/mns", | ||
| 20 | + "_nodeVersion": "8.1.4", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/mns-1.0.0-beta5.tgz_1501596837512_0.22118755243718624" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "5.0.3", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "@alicloud/mns@^1.0.0-beta4", | ||
| 33 | + "scope": "@alicloud", | ||
| 34 | + "escapedName": "@alicloud%2fmns", | ||
| 35 | + "name": "@alicloud/mns", | ||
| 36 | + "rawSpec": "^1.0.0-beta4", | ||
| 37 | + "spec": ">=1.0.0-beta4 <2.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/sms-sdk" | ||
| 42 | + ], | ||
| 43 | + "_resolved": "https://registry.npmjs.org/@alicloud/mns/-/mns-1.0.0-beta5.tgz", | ||
| 44 | + "_shasum": "aea60984f6715bbc9f7ea2f8aaef844f241f4b68", | ||
| 45 | + "_shrinkwrap": null, | ||
| 46 | + "_spec": "@alicloud/mns@^1.0.0-beta4", | ||
| 47 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/sms-sdk", | ||
| 48 | + "author": { | ||
| 49 | + "name": "Jackson Tian" | ||
| 50 | + }, | ||
| 51 | + "bugs": { | ||
| 52 | + "url": "https://github.com/aliyun/mns-nodejs-sdk/issues" | ||
| 53 | + }, | ||
| 54 | + "dependencies": { | ||
| 55 | + "debug": "^2.6.3", | ||
| 56 | + "httpx": "^2.1.1", | ||
| 57 | + "kitx": "^1.2.0", | ||
| 58 | + "xml2js": "^0.4.17" | ||
| 59 | + }, | ||
| 60 | + "description": "> 该 SDK 并未完全实现所有文档所提及的功能,如果您想使用的功能并未实现,请提[issue](https://github.com/aliyun/aliyun-mns-nodejs-sdk/issues/new)以增加优先级。", | ||
| 61 | + "devDependencies": { | ||
| 62 | + "coveralls": "^2.13.1", | ||
| 63 | + "eslint": "^3.19.0", | ||
| 64 | + "expect.js": "^0.3.1", | ||
| 65 | + "mocha": "^3.3.0", | ||
| 66 | + "nyc": "^10.3.2" | ||
| 67 | + }, | ||
| 68 | + "directories": { | ||
| 69 | + "test": "test" | ||
| 70 | + }, | ||
| 71 | + "dist": { | ||
| 72 | + "integrity": "sha512-P4WYJSKPZb548DteQtKu8Yc1ZRdkw2Q8r7xPQthJgJIQxgTPfmiJx5hE/PEJY7GrL6N60ZS+16QIE7ErbB1xGQ==", | ||
| 73 | + "shasum": "aea60984f6715bbc9f7ea2f8aaef844f241f4b68", | ||
| 74 | + "tarball": "https://registry.npmjs.org/@alicloud/mns/-/mns-1.0.0-beta5.tgz" | ||
| 75 | + }, | ||
| 76 | + "files": [ | ||
| 77 | + "lib", | ||
| 78 | + "index.js" | ||
| 79 | + ], | ||
| 80 | + "gitHead": "b7eb01489f2454878462d259833f4914a321c761", | ||
| 81 | + "homepage": "https://github.com/aliyun/mns-nodejs-sdk#readme", | ||
| 82 | + "keywords": [ | ||
| 83 | + "MNS", | ||
| 84 | + "Message", | ||
| 85 | + "Service", | ||
| 86 | + "Aliyun", | ||
| 87 | + "Alicloud" | ||
| 88 | + ], | ||
| 89 | + "license": "MIT", | ||
| 90 | + "main": "index.js", | ||
| 91 | + "maintainers": [ | ||
| 92 | + { | ||
| 93 | + "name": "rockuw", | ||
| 94 | + "email": "rockuw@gmail.com" | ||
| 95 | + }, | ||
| 96 | + { | ||
| 97 | + "name": "humanhuang", | ||
| 98 | + "email": "halfthink@gmail.com" | ||
| 99 | + }, | ||
| 100 | + { | ||
| 101 | + "name": "jacksontian", | ||
| 102 | + "email": "shyvo1987@gmail.com" | ||
| 103 | + } | ||
| 104 | + ], | ||
| 105 | + "name": "@alicloud/mns", | ||
| 106 | + "optionalDependencies": {}, | ||
| 107 | + "readme": "# mns-nodejs-sdk\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![coverage][cov-image]][cov-url]\n\n[npm-image]: https://img.shields.io/npm/v/@alicloud/mns.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@alicloud/mns\n[travis-image]: https://img.shields.io/travis/aliyun/mns-nodejs-sdk/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/aliyun/mns-nodejs-sdk.svg?branch=master\n[cov-image]: https://coveralls.io/repos/aliyun/mns-nodejs-sdk/badge.svg?branch=master&service=github\n[cov-url]: https://coveralls.io/github/aliyun/mns-nodejs-sdk?branch=master\n\nDocuments: http://doxmate.cool/aliyun/mns-nodejs-sdk/api.html\n\n\n> 该 SDK 并未完全实现所有文档所提及的功能,如果您想使用的功能并未实现,请提[issue](https://github.com/aliyun/mns-nodejs-sdk/issues/new)以增加优先级。\n\n## Installation\n\n```bash\nnpm install @alicloud/mns --save\n```\n\n## API Spec\n\nSee: https://help.aliyun.com/document_detail/27475.html\n\n## Test\n\n```sh\nACCOUNT_ID=<ACCOUNT_ID> ACCESS_KEY_ID=<ACCESS_KEY_ID> ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET> make test\n```\n\n## Installation\n\nYou can install it via npm/cnpm/yarn.\n\n```sh\n$ npm install @alicloud/mns --save\n```\n\n## Usage\n\n```js\nconst MNSClient = require('@alicloud/mns');\n\nconst accountid = '<account id>';\nvar client = new MNSClient(accountid, {\n region: '<region>',\n accessKeyId: '<access key id>',\n accessKeySecret: '<access key secret>',\n // optional & default\n secure: false, // use https or http\n internal: false, // use internal endpoint\n vpc: false // use vpc endpoint\n});\n\n(async function () {\n let res;\n // create queue\n res = await client.createQueue('test-queue2');\n console.log(res);\n // list queue\n res = await client.listQueue();\n console.log(JSON.stringify(res, null, 2));\n // create topic\n res = await client.createTopic('test-topic');\n console.log(res);\n // get topic attributes\n res = await client.getTopicAttributes('test-topic');\n console.log(res);\n // publish message\n res = await client.publishMessage('<topic name>', {\n MessageBody: 'content',\n MessageAttributes: {\n DirectSMS: JSON.stringify({\n FreeSignName: '',\n TemplateCode: '<template code>',\n Type: '<type>',\n Receiver: '<phone number>',\n SmsParams: JSON.stringify({\n code: '<code>',\n product: '<product>'\n })\n })\n }\n });\n console.log(res);\n})().then((data) => {\n console.log(data);\n}, (err) => {\n console.log(err.stack);\n});\n```\n\n## License\n\nThe [MIT](LICENSE) License\n", | ||
| 108 | + "readmeFilename": "README.md", | ||
| 109 | + "repository": { | ||
| 110 | + "type": "git", | ||
| 111 | + "url": "git+https://github.com/aliyun/mns-nodejs-sdk.git" | ||
| 112 | + }, | ||
| 113 | + "scripts": { | ||
| 114 | + "test": "make test" | ||
| 115 | + }, | ||
| 116 | + "version": "1.0.0-beta5" | ||
| 117 | +} |
node_modules/@alicloud/pop-core/CHANGELOG.md
0 → 100644
node_modules/@alicloud/pop-core/README.md
0 → 100644
| 1 | +# @alicloud/pop-core | ||
| 2 | + | ||
| 3 | +The core SDK of POP API. | ||
| 4 | + | ||
| 5 | +## Installation | ||
| 6 | + | ||
| 7 | +Install it and write into package.json dependences. | ||
| 8 | + | ||
| 9 | +```sh | ||
| 10 | +$ npm install @alicloud/pop-core -S | ||
| 11 | +``` | ||
| 12 | + | ||
| 13 | +## Prerequisite | ||
| 14 | + | ||
| 15 | +Node.js >= 6.x | ||
| 16 | + | ||
| 17 | +## Usage | ||
| 18 | + | ||
| 19 | +The RPC style client: | ||
| 20 | + | ||
| 21 | +```js | ||
| 22 | +var RPCClient = require('@alicloud/pop-core').RPCClient; | ||
| 23 | + | ||
| 24 | +var client = new RPCClient({ | ||
| 25 | + accessKeyId: '<accessKeyId>', | ||
| 26 | + secretAccessKey: '<secretAccessKey>', | ||
| 27 | + endpoint: '<endpoint>', | ||
| 28 | + apiVersion: '<apiVersion>' | ||
| 29 | +}); | ||
| 30 | + | ||
| 31 | +// => returns Promise | ||
| 32 | +client.request(action, params); | ||
| 33 | +// co/yield, async/await | ||
| 34 | +``` | ||
| 35 | + | ||
| 36 | +The ROA style client: | ||
| 37 | + | ||
| 38 | +```js | ||
| 39 | +var ROAClient = require('@alicloud/pop-core').ROAClient; | ||
| 40 | + | ||
| 41 | +var client = new ROAClient({ | ||
| 42 | + accessKeyId: '<accessKeyId>', | ||
| 43 | + accessKeySecret: '<secretAccessKey>', | ||
| 44 | + endpoint: '<endpoint>', | ||
| 45 | + apiVersion: '<apiVersion>' | ||
| 46 | +}); | ||
| 47 | + | ||
| 48 | +// => returns Promise | ||
| 49 | +// request(HTTPMethod, uriPath, queries, body, headers, options); | ||
| 50 | +// options => {timeout} | ||
| 51 | +client.request('GET', '/regions'); | ||
| 52 | +// co/yield, async/await | ||
| 53 | +``` | ||
| 54 | + | ||
| 55 | +## License | ||
| 56 | +The MIT License |
node_modules/@alicloud/pop-core/index.js
0 → 100644
| 1 | +// Type definitions for [~THE LIBRARY NAME~] [~OPTIONAL VERSION NUMBER~] | ||
| 2 | +// Project: [~THE PROJECT NAME~] | ||
| 3 | +// Definitions by: [~YOUR NAME~] <[~A URL FOR YOU~]> | ||
| 4 | + | ||
| 5 | +/*~ This is the module template file for class modules. | ||
| 6 | + *~ You should rename it to index.d.ts and place it in a folder with the same name as the module. | ||
| 7 | + *~ For example, if you were writing a file for "super-greeter", this | ||
| 8 | + *~ file should be 'super-greeter/index.d.ts' | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*~ Note that ES6 modules cannot directly export class objects. | ||
| 12 | + *~ This file should be imported using the CommonJS-style: | ||
| 13 | + *~ import x = require('someLibrary'); | ||
| 14 | + *~ | ||
| 15 | + *~ Refer to the documentation to understand common | ||
| 16 | + *~ workarounds for this limitation of ES6 modules. | ||
| 17 | + */ | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +/*~ This declaration specifies that the class constructor function | ||
| 21 | + *~ is the exported object from the file | ||
| 22 | + */ | ||
| 23 | +export = Core; | ||
| 24 | + | ||
| 25 | +/*~ Write your module's methods and properties in this class */ | ||
| 26 | +declare class Core { | ||
| 27 | + constructor(config: Core.Config); | ||
| 28 | + | ||
| 29 | + request(action: String, params: Object, options: Object): Promise; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +/*~ If you want to expose types from your module as well, you can | ||
| 33 | + *~ place them in this block. | ||
| 34 | + */ | ||
| 35 | +declare namespace Core { | ||
| 36 | + export interface Config { | ||
| 37 | + endpoint: string; | ||
| 38 | + apiVersion: string; | ||
| 39 | + accessKeyId: string; | ||
| 40 | + secretAccessKey: string; | ||
| 41 | + } | ||
| 42 | +} |
node_modules/@alicloud/pop-core/lib/core.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const assert = require('assert'); | ||
| 4 | + | ||
| 5 | +const httpx = require('httpx'); | ||
| 6 | +const kitx = require('kitx'); | ||
| 7 | +const JSON = require('json-bigint'); | ||
| 8 | + | ||
| 9 | +function firstLetterUpper(str) { | ||
| 10 | + return str.slice(0, 1).toUpperCase() + str.slice(1); | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +function formatParams(params) { | ||
| 14 | + var keys = Object.keys(params); | ||
| 15 | + var newParams = {}; | ||
| 16 | + for (var i = 0; i < keys.length; i++) { | ||
| 17 | + var key = keys[i]; | ||
| 18 | + newParams[firstLetterUpper(key)] = params[key]; | ||
| 19 | + } | ||
| 20 | + return newParams; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +function timestamp() { | ||
| 25 | + var date = new Date(); | ||
| 26 | + var YYYY = date.getUTCFullYear(); | ||
| 27 | + var MM = kitx.pad2(date.getUTCMonth() + 1); | ||
| 28 | + var DD = kitx.pad2(date.getUTCDate()); | ||
| 29 | + var HH = kitx.pad2(date.getUTCHours()); | ||
| 30 | + var mm = kitx.pad2(date.getUTCMinutes()); | ||
| 31 | + var ss = kitx.pad2(date.getUTCSeconds()); | ||
| 32 | + // 删除掉毫秒部分 | ||
| 33 | + return `${YYYY}-${MM}-${DD}T${HH}:${mm}:${ss}Z`; | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +function encode(str) { | ||
| 37 | + var result = encodeURIComponent(str); | ||
| 38 | + | ||
| 39 | + return result.replace(/\!/g, '%21') | ||
| 40 | + .replace(/\'/g, '%27') | ||
| 41 | + .replace(/\(/g, '%28') | ||
| 42 | + .replace(/\)/g, '%29') | ||
| 43 | + .replace(/\*/g, '%2A'); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +function repeatList(list, key, repeat) { | ||
| 47 | + for (var i = 0; i < repeat.length; i++) { | ||
| 48 | + var item = repeat[i]; | ||
| 49 | + var prefix = `${key}.${i + 1}`; | ||
| 50 | + list.push([encode(prefix), encode(item)]); | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +function normalize(params) { | ||
| 55 | + var list = []; | ||
| 56 | + var keys = Object.keys(params).sort(); | ||
| 57 | + for (let i = 0; i < keys.length; i++) { | ||
| 58 | + var key = keys[i]; | ||
| 59 | + var value = params[key]; | ||
| 60 | + if (Array.isArray(value)) { | ||
| 61 | + repeatList(list, key, value); | ||
| 62 | + } else { | ||
| 63 | + list.push([encode(key), encode(value)]); //push [] | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + return list; | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +function canonicalize(normalized) { | ||
| 71 | + var fields = []; | ||
| 72 | + for (var i = 0; i < normalized.length; i++) { | ||
| 73 | + var [key, value] = normalized[i]; | ||
| 74 | + fields.push(key + '=' + value); | ||
| 75 | + } | ||
| 76 | + return fields.join('&'); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +class Core { | ||
| 80 | + constructor(config, verbose) { | ||
| 81 | + assert(config, 'must pass "config"'); | ||
| 82 | + assert(config.endpoint, 'must pass "config.endpoint"'); | ||
| 83 | + assert(config.apiVersion, 'must pass "config.apiVersion"'); | ||
| 84 | + assert(config.accessKeyId, 'must pass "config.accessKeyId"'); | ||
| 85 | + var accessKeySecret = config.secretAccessKey || config.accessKeySecret; | ||
| 86 | + assert(accessKeySecret, 'must pass "config.accessKeySecret"'); | ||
| 87 | + | ||
| 88 | + if (config.endpoint.endsWith('/')) { | ||
| 89 | + config.endpoint = config.endpoint.slice(0, -1); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + this.endpoint = config.endpoint; | ||
| 93 | + this.apiVersion = config.apiVersion; | ||
| 94 | + this.accessKeyId = config.accessKeyId; | ||
| 95 | + this.accessKeySecret = accessKeySecret; | ||
| 96 | + this.verbose = verbose === true; | ||
| 97 | + // 非 codes 里的值,将抛出异常 | ||
| 98 | + this.codes = new Set([200, '200', 'OK', 'Success']); | ||
| 99 | + if (config.codes) { | ||
| 100 | + // 合并 codes | ||
| 101 | + for (var elem of config.codes) { | ||
| 102 | + this.codes.add(elem); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + var httpModule = this.endpoint.startsWith('https://') | ||
| 107 | + ? require('https') : require('http'); | ||
| 108 | + this.keepAliveAgent = new httpModule.Agent({ | ||
| 109 | + keepAlive: true, | ||
| 110 | + keepAliveMsecs: 3000 | ||
| 111 | + }); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + request(action, params = {}, opts = {}) { | ||
| 115 | + // 1. compose params | ||
| 116 | + // format action until formatAction is false | ||
| 117 | + if (opts.formatAction !== false) { | ||
| 118 | + action = firstLetterUpper(action); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + // format params until formatParams is false | ||
| 122 | + if (opts.formatParams !== false) { | ||
| 123 | + params = formatParams(params); | ||
| 124 | + } | ||
| 125 | + var defaults = this._buildParams(); | ||
| 126 | + params = Object.assign({Action: action}, defaults, params); | ||
| 127 | + | ||
| 128 | + // 2. caculate signature | ||
| 129 | + var method = (opts.method || 'GET').toUpperCase(); | ||
| 130 | + var normalized = normalize(params); | ||
| 131 | + var canonicalized = canonicalize(normalized); | ||
| 132 | + // 2.1 get string to sign | ||
| 133 | + var stringToSign = `${method}&${encode('/')}&${encode(canonicalized)}`; | ||
| 134 | + // 2.2 get signature | ||
| 135 | + const key = this.accessKeySecret + '&'; | ||
| 136 | + var signature = kitx.sha1(stringToSign, key, 'base64'); | ||
| 137 | + // add signature | ||
| 138 | + normalized.push(['Signature', encode(signature)]); | ||
| 139 | + // 3. generate final url | ||
| 140 | + const url = `${this.endpoint}/?${canonicalize(normalized)}`; | ||
| 141 | + // 4. send request | ||
| 142 | + var entry = { | ||
| 143 | + url: url, | ||
| 144 | + request: null, | ||
| 145 | + response: null | ||
| 146 | + }; | ||
| 147 | + | ||
| 148 | + if (opts && !opts.agent) { | ||
| 149 | + opts.agent = this.keepAliveAgent; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + return httpx.request(url, opts).then((response) => { | ||
| 153 | + entry.request = { | ||
| 154 | + headers: response.req._headers | ||
| 155 | + }; | ||
| 156 | + entry.response = { | ||
| 157 | + statusCode: response.statusCode, | ||
| 158 | + headers: response.headers | ||
| 159 | + }; | ||
| 160 | + | ||
| 161 | + return httpx.read(response); | ||
| 162 | + }).then((buffer) => { | ||
| 163 | + var json = JSON.parse(buffer); | ||
| 164 | + if (json.Code && !this.codes.has(json.Code)) { | ||
| 165 | + var err = new Error(json.Message); | ||
| 166 | + err.name = json.Code + 'Error'; | ||
| 167 | + err.data = json; | ||
| 168 | + err.code = json.Code; | ||
| 169 | + err.url = url; | ||
| 170 | + err.entry = entry; | ||
| 171 | + return Promise.reject(err); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + if (this.verbose) { | ||
| 175 | + return [json, entry]; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + return json; | ||
| 179 | + }); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + _buildParams() { | ||
| 183 | + return { | ||
| 184 | + Format: 'JSON', | ||
| 185 | + SignatureMethod: 'HMAC-SHA1', | ||
| 186 | + SignatureNonce: kitx.makeNonce(), | ||
| 187 | + SignatureVersion: '1.0', | ||
| 188 | + Timestamp: timestamp(), | ||
| 189 | + AccessKeyId: this.accessKeyId, | ||
| 190 | + Version: this.apiVersion, | ||
| 191 | + }; | ||
| 192 | + } | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +module.exports = Core; |
node_modules/@alicloud/pop-core/lib/roa.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const assert = require('assert'); | ||
| 4 | +const url = require('url'); | ||
| 5 | +const querystring = require('querystring'); | ||
| 6 | + | ||
| 7 | +const kitx = require('kitx'); | ||
| 8 | +const httpx = require('httpx'); | ||
| 9 | +const xml2js = require('xml2js'); | ||
| 10 | +const JSON = require('json-bigint'); | ||
| 11 | +const debug = require('debug')('roa'); | ||
| 12 | + | ||
| 13 | +const pkg = require('../package.json'); | ||
| 14 | + | ||
| 15 | +function filter(value) { | ||
| 16 | + return value.replace(/[\t\n\r\f]/g, ' '); | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +function parseXML(xml) { | ||
| 20 | + const parser = new xml2js.Parser({ | ||
| 21 | + // explicitArray: false | ||
| 22 | + }); | ||
| 23 | + return new Promise((resolve, reject) => { | ||
| 24 | + parser.parseString(xml, (err, result) => { | ||
| 25 | + if (err) { | ||
| 26 | + return reject(err); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + resolve(result); | ||
| 30 | + }); | ||
| 31 | + }); | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +class ACSError extends Error { | ||
| 35 | + constructor(err) { | ||
| 36 | + const message = err.Message[0]; | ||
| 37 | + const code = err.Code[0]; | ||
| 38 | + const hostid = err.HostId[0]; | ||
| 39 | + const requestid = err.RequestId[0]; | ||
| 40 | + super(`${message} hostid: ${hostid}, requestid: ${requestid}`); | ||
| 41 | + this.code = code; | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +class ROAClient { | ||
| 46 | + constructor(config) { | ||
| 47 | + assert(config, 'must pass "config"'); | ||
| 48 | + assert(config.endpoint, 'must pass "config.endpoint"'); | ||
| 49 | + assert(config.apiVersion, 'must pass "config.apiVersion"'); | ||
| 50 | + assert(config.accessKeyId, 'must pass "config.accessKeyId"'); | ||
| 51 | + assert(config.accessKeySecret, 'must pass "config.accessKeySecret"'); | ||
| 52 | + | ||
| 53 | + this.endpoint = config.endpoint; | ||
| 54 | + this.apiVersion = config.apiVersion; | ||
| 55 | + this.accessKeyId = config.accessKeyId; | ||
| 56 | + this.accessKeySecret = config.accessKeySecret; | ||
| 57 | + this.host = url.parse(this.endpoint).hostname; | ||
| 58 | + | ||
| 59 | + var httpModule = this.host.startsWith('https://') ? require('https') : require('http'); | ||
| 60 | + this.keepAliveAgent = new httpModule.Agent({ | ||
| 61 | + keepAlive: true, | ||
| 62 | + keepAliveMsecs: 3000 | ||
| 63 | + }); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + buildHeaders() { | ||
| 67 | + const now = new Date(); | ||
| 68 | + return { | ||
| 69 | + accept: 'application/json', | ||
| 70 | + date: now.toGMTString(), | ||
| 71 | + host: this.host, | ||
| 72 | + 'x-acs-signature-nonce': kitx.makeNonce(), | ||
| 73 | + 'x-acs-signature-method': 'HMAC-SHA1', | ||
| 74 | + 'x-acs-signature-version': '1.0', | ||
| 75 | + 'x-acs-version': this.apiVersion, | ||
| 76 | + 'x-sdk-client': `Node.js(${process.version}), ${pkg.name}: ${pkg.version}` | ||
| 77 | + }; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + getCanonicalizedHeaders(headers) { | ||
| 81 | + const prefix = 'x-acs-'; | ||
| 82 | + const keys = Object.keys(headers); | ||
| 83 | + | ||
| 84 | + const canonicalizedKeys = []; | ||
| 85 | + for (let i = 0; i < keys.length; i++) { | ||
| 86 | + const key = keys[i]; | ||
| 87 | + if (key.startsWith(prefix)) { | ||
| 88 | + canonicalizedKeys.push(key); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + canonicalizedKeys.sort(); | ||
| 93 | + | ||
| 94 | + var result = ''; | ||
| 95 | + for (let i = 0; i < canonicalizedKeys.length; i++) { | ||
| 96 | + const key = canonicalizedKeys[i]; | ||
| 97 | + result += `${key}:${filter(headers[key]).trim()}\n`; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + return result; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + getCanonicalizedResource(uriPattern, query) { | ||
| 104 | + const keys = Object.keys(query).sort(); | ||
| 105 | + | ||
| 106 | + if (keys.length === 0) { | ||
| 107 | + return uriPattern; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + var result = []; | ||
| 111 | + for (var i = 0; i < keys.length; i++) { | ||
| 112 | + const key = keys[i]; | ||
| 113 | + result.push(`${key}=${query[key]}`); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + return `${uriPattern}?${result.join('&')}`; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + buildStringToSign(method, uriPattern, headers, query) { | ||
| 120 | + const accept = headers['accept']; | ||
| 121 | + const contentMD5 = headers['content-md5'] || ''; | ||
| 122 | + const contentType = headers['content-type'] || ''; | ||
| 123 | + const date = headers['date'] || ''; | ||
| 124 | + | ||
| 125 | + const header = `${method}\n${accept}\n${contentMD5}\n${contentType}\n${date}\n`; | ||
| 126 | + | ||
| 127 | + const canonicalizedHeaders = this.getCanonicalizedHeaders(headers); | ||
| 128 | + const canonicalizedResource = this.getCanonicalizedResource(uriPattern, query); | ||
| 129 | + | ||
| 130 | + return `${header}${canonicalizedHeaders}${canonicalizedResource}`; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + signature(stringToSign) { | ||
| 134 | + const utf8Buff = Buffer.from(stringToSign, 'utf8'); | ||
| 135 | + | ||
| 136 | + return kitx.sha1(utf8Buff, this.accessKeySecret, 'base64'); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + buildAuthorization(stringToSign) { | ||
| 140 | + return `acs ${this.accessKeyId}:${this.signature(stringToSign)}`; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + request(method, uriPattern, query = {}, body = '', headers = {}, opts) { | ||
| 144 | + var postBody = null; | ||
| 145 | + | ||
| 146 | + var mixHeaders = Object.assign(this.buildHeaders(), headers); | ||
| 147 | + if (body) { | ||
| 148 | + postBody = Buffer.from(body, 'utf8'); | ||
| 149 | + mixHeaders['content-md5'] = kitx.md5(postBody, 'base64'); | ||
| 150 | + mixHeaders['content-length'] = postBody.length; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + var url = `${this.endpoint}${uriPattern}`; | ||
| 154 | + if (Object.keys(query).length) { | ||
| 155 | + url += `?${querystring.stringify(query)}`; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + const stringToSign = this.buildStringToSign(method, uriPattern, mixHeaders, query); | ||
| 159 | + debug('stringToSign: %s', stringToSign); | ||
| 160 | + mixHeaders['authorization'] = this.buildAuthorization(stringToSign); | ||
| 161 | + | ||
| 162 | + const options = Object.assign({ | ||
| 163 | + method, | ||
| 164 | + agent: this.keepAliveAgent, | ||
| 165 | + headers: mixHeaders, | ||
| 166 | + data: postBody | ||
| 167 | + }, opts); | ||
| 168 | + | ||
| 169 | + return httpx.request(url, options).then((response) => { | ||
| 170 | + return httpx.read(response, 'utf8').then((body) => { | ||
| 171 | + const contentType = response.headers['content-type'] || ''; | ||
| 172 | + // JSON | ||
| 173 | + if (contentType.startsWith('application/json')) { | ||
| 174 | + var result = JSON.parse(body); | ||
| 175 | + const statusCode = response.statusCode; | ||
| 176 | + if (statusCode >= 400) { | ||
| 177 | + var message = `code: ${statusCode}, ${result.Message} requestid: ${result.RequestId}`; | ||
| 178 | + var err = new Error(message); | ||
| 179 | + err.name = `${result.Code}Error`; | ||
| 180 | + return Promise.reject(err); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + return result; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + if (contentType.startsWith('text/xml')) { | ||
| 187 | + return parseXML(body).then((result) => { | ||
| 188 | + if (result.Error) { | ||
| 189 | + return Promise.reject(new ACSError(result.Error)); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + return result; | ||
| 193 | + }); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + return body; | ||
| 197 | + }); | ||
| 198 | + }); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + put(path, query, body, headers, options) { | ||
| 202 | + return this.request('PUT', path, query, body, headers, options); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + post(path, query, body, headers, options) { | ||
| 206 | + return this.request('POST', path, query, body, headers, options); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + get(path, query, headers, options) { | ||
| 210 | + return this.request('GET', path, query, '', headers, options); | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + delete(path, query, headers, options) { | ||
| 214 | + return this.request('DELETE', path, query, '', headers, options); | ||
| 215 | + } | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +module.exports = ROAClient; |
node_modules/@alicloud/pop-core/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "@alicloud/pop-core@^1.3.3", | ||
| 6 | + "scope": "@alicloud", | ||
| 7 | + "escapedName": "@alicloud%2fpop-core", | ||
| 8 | + "name": "@alicloud/pop-core", | ||
| 9 | + "rawSpec": "^1.3.3", | ||
| 10 | + "spec": ">=1.3.3 <2.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/dybaseapi" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "@alicloud/pop-core@>=1.3.3 <2.0.0", | ||
| 17 | + "_id": "@alicloud/pop-core@1.5.0", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/@alicloud/pop-core", | ||
| 20 | + "_nodeVersion": "8.5.0", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/pop-core-1.5.0.tgz_1508916658658_0.08523054211400449" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "5.4.2", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "@alicloud/pop-core@^1.3.3", | ||
| 33 | + "scope": "@alicloud", | ||
| 34 | + "escapedName": "@alicloud%2fpop-core", | ||
| 35 | + "name": "@alicloud/pop-core", | ||
| 36 | + "rawSpec": "^1.3.3", | ||
| 37 | + "spec": ">=1.3.3 <2.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/dybaseapi", | ||
| 42 | + "/@alicloud/dysmsapi" | ||
| 43 | + ], | ||
| 44 | + "_resolved": "https://registry.npmjs.org/@alicloud/pop-core/-/pop-core-1.5.0.tgz", | ||
| 45 | + "_shasum": "b0f44b216237ee278d4dde245f287c94daffd68d", | ||
| 46 | + "_shrinkwrap": null, | ||
| 47 | + "_spec": "@alicloud/pop-core@^1.3.3", | ||
| 48 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/dybaseapi", | ||
| 49 | + "author": { | ||
| 50 | + "name": "Jackson Tian" | ||
| 51 | + }, | ||
| 52 | + "bugs": { | ||
| 53 | + "url": "https://github.com/aliyun/openapi-core-nodejs-sdk/issues" | ||
| 54 | + }, | ||
| 55 | + "dependencies": { | ||
| 56 | + "httpx": "^2.1.2", | ||
| 57 | + "json-bigint": "^0.2.3", | ||
| 58 | + "kitx": "^1.2.1", | ||
| 59 | + "xml2js": "^0.4.17" | ||
| 60 | + }, | ||
| 61 | + "description": "AliCloud POP SDK core", | ||
| 62 | + "devDependencies": { | ||
| 63 | + "co-mocha": "^1.1.3", | ||
| 64 | + "eslint": "^3.13.0", | ||
| 65 | + "expect.js": "^0.3.1", | ||
| 66 | + "istanbul": "^0.4.5", | ||
| 67 | + "mocha": "^3.2.0" | ||
| 68 | + }, | ||
| 69 | + "directories": { | ||
| 70 | + "test": "test" | ||
| 71 | + }, | ||
| 72 | + "dist": { | ||
| 73 | + "integrity": "sha512-GoxTbqp+4nGPwAE3swZyVpWGdolnHhW4tkwIG/g6l7sNn1gd3EuFrA4HmhaJwTrwCgZTOkV8vgYzPiCYAophOA==", | ||
| 74 | + "shasum": "b0f44b216237ee278d4dde245f287c94daffd68d", | ||
| 75 | + "tarball": "https://registry.npmjs.org/@alicloud/pop-core/-/pop-core-1.5.0.tgz" | ||
| 76 | + }, | ||
| 77 | + "files": [ | ||
| 78 | + "lib", | ||
| 79 | + "index.js" | ||
| 80 | + ], | ||
| 81 | + "gitHead": "209d46ca673e5b8f7586d4eb863002ff25e62bd1", | ||
| 82 | + "homepage": "https://github.com/aliyun/openapi-core-nodejs-sdk#readme", | ||
| 83 | + "keywords": [ | ||
| 84 | + "Aliyun", | ||
| 85 | + "AliCloud", | ||
| 86 | + "OpenAPI", | ||
| 87 | + "POP", | ||
| 88 | + "SDK", | ||
| 89 | + "Core" | ||
| 90 | + ], | ||
| 91 | + "license": "MIT", | ||
| 92 | + "main": "index.js", | ||
| 93 | + "maintainers": [ | ||
| 94 | + { | ||
| 95 | + "name": "chuck.ql", | ||
| 96 | + "email": "kunqian434@gmail.com" | ||
| 97 | + }, | ||
| 98 | + { | ||
| 99 | + "name": "rockuw", | ||
| 100 | + "email": "rockuw@gmail.com" | ||
| 101 | + }, | ||
| 102 | + { | ||
| 103 | + "name": "humanhuang", | ||
| 104 | + "email": "halfthink@gmail.com" | ||
| 105 | + }, | ||
| 106 | + { | ||
| 107 | + "name": "jacksontian", | ||
| 108 | + "email": "shyvo1987@gmail.com" | ||
| 109 | + } | ||
| 110 | + ], | ||
| 111 | + "name": "@alicloud/pop-core", | ||
| 112 | + "optionalDependencies": {}, | ||
| 113 | + "readme": "# @alicloud/pop-core\n\nThe core SDK of POP API.\n\n## Installation\n\nInstall it and write into package.json dependences.\n\n```sh\n$ npm install @alicloud/pop-core -S\n```\n\n## Prerequisite\n\nNode.js >= 6.x\n\n## Usage\n\nThe RPC style client:\n\n```js\nvar RPCClient = require('@alicloud/pop-core').RPCClient;\n\nvar client = new RPCClient({\n accessKeyId: '<accessKeyId>',\n secretAccessKey: '<secretAccessKey>',\n endpoint: '<endpoint>',\n apiVersion: '<apiVersion>'\n});\n\n// => returns Promise\nclient.request(action, params);\n// co/yield, async/await\n```\n\nThe ROA style client:\n\n```js\nvar ROAClient = require('@alicloud/pop-core').ROAClient;\n\nvar client = new ROAClient({\n accessKeyId: '<accessKeyId>',\n accessKeySecret: '<secretAccessKey>',\n endpoint: '<endpoint>',\n apiVersion: '<apiVersion>'\n});\n\n// => returns Promise\n// request(HTTPMethod, uriPath, queries, body, headers, options);\n// options => {timeout}\nclient.request('GET', '/regions');\n// co/yield, async/await\n```\n\n## License\nThe MIT License\n", | ||
| 114 | + "readmeFilename": "README.md", | ||
| 115 | + "repository": { | ||
| 116 | + "type": "git", | ||
| 117 | + "url": "git+https://github.com/aliyun/openapi-core-nodejs-sdk.git" | ||
| 118 | + }, | ||
| 119 | + "scripts": { | ||
| 120 | + "lint": "eslint --fix lib", | ||
| 121 | + "test": "mocha --require co-mocha --reporter spec test/*.test.js", | ||
| 122 | + "test-cov": "istanbul cover --report html ./node_modules/.bin/_mocha -- --require co-mocha --reporter spec test/*.test.js" | ||
| 123 | + }, | ||
| 124 | + "types": "lib/core.d.ts", | ||
| 125 | + "version": "1.5.0" | ||
| 126 | +} |
node_modules/@alicloud/sms-sdk/.npmignore
0 → 100644
node_modules/@alicloud/sms-sdk/README.md
0 → 100644
| 1 | +### 安装 | ||
| 2 | + | ||
| 3 | +``` javascript | ||
| 4 | + $ npm install @alicloud/sms-sdk --save | ||
| 5 | +``` | ||
| 6 | + | ||
| 7 | +### 使用方法 | ||
| 8 | +1. 安装@alicloud/sms-sdk,请需要根据官方文档做一些配置 | ||
| 9 | +2. 产品文档: https://dysms.console.aliyun.com/dysms.htm | ||
| 10 | + | ||
| 11 | +### DEMO | ||
| 12 | + | ||
| 13 | +``` javascript | ||
| 14 | +/** | ||
| 15 | + * 云通信基础能力业务短信发送、查询详情以及消费消息示例,供参考。 | ||
| 16 | + * Created on 2017-07-31 | ||
| 17 | + */ | ||
| 18 | + | ||
| 19 | +const SMSClient = require('./../index') | ||
| 20 | + | ||
| 21 | +// ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换 | ||
| 22 | +const accessKeyId = 'yourAccessKeyId' | ||
| 23 | +const secretAccessKey = 'yourAccessKeySecret' | ||
| 24 | + | ||
| 25 | +//在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName,不用填最后面一段 | ||
| 26 | +const queueName = 'Alicom-Queue-1092397003988387-' | ||
| 27 | + | ||
| 28 | +//初始化sms_client | ||
| 29 | +let smsClient = new SMSClient({accessKeyId, secretAccessKey}) | ||
| 30 | + | ||
| 31 | +//短信回执报告 | ||
| 32 | +smsClient.receiveMsg(0, queueName).then(function (res) { | ||
| 33 | + //消息体需要base64解码 | ||
| 34 | + let {code, body}=res | ||
| 35 | + if (code === 200) { | ||
| 36 | + //处理消息体,messagebody | ||
| 37 | + console.log(body) | ||
| 38 | + } | ||
| 39 | +}, function (err) { | ||
| 40 | + console.log(err) | ||
| 41 | +}) | ||
| 42 | + | ||
| 43 | +//短信上行报告 | ||
| 44 | +smsClient.receiveMsg(1, queueName).then(function (res) { | ||
| 45 | + //消息体需要base64解码 | ||
| 46 | + let {code, body}=res | ||
| 47 | + if (code === 200) { | ||
| 48 | + //处理消息体,messagebody | ||
| 49 | + console.log(body) | ||
| 50 | + } | ||
| 51 | +}, function (err) { | ||
| 52 | + console.log(err) | ||
| 53 | +}) | ||
| 54 | + | ||
| 55 | + | ||
| 56 | +//查询短信发送详情 | ||
| 57 | +smsClient.queryDetail({ | ||
| 58 | + PhoneNumber: '1500000000', | ||
| 59 | + SendDate: '20170731', | ||
| 60 | + PageSize: '10', | ||
| 61 | + CurrentPage: "1" | ||
| 62 | +}).then(function (res) { | ||
| 63 | + let {Code, SmsSendDetailDTOs}=res | ||
| 64 | + if (Code === 'OK') { | ||
| 65 | + //处理发送详情内容 | ||
| 66 | + console.log(SmsSendDetailDTOs) | ||
| 67 | + } | ||
| 68 | +}, function (err) { | ||
| 69 | + //处理错误 | ||
| 70 | + console.log(err) | ||
| 71 | +}) | ||
| 72 | + | ||
| 73 | +//发送短信 | ||
| 74 | +smsClient.sendSMS({ | ||
| 75 | + PhoneNumbers: '1500000000', | ||
| 76 | + SignName: '云通信产品', | ||
| 77 | + TemplateCode: 'SMS_000000', | ||
| 78 | + TemplateParam: '{"code":"12345","product":"云通信"}' | ||
| 79 | +}).then(function (res) { | ||
| 80 | + let {Code}=res | ||
| 81 | + if (Code === 'OK') { | ||
| 82 | + //处理返回参数 | ||
| 83 | + console.log(res) | ||
| 84 | + } | ||
| 85 | +}, function (err) { | ||
| 86 | + console.log(err) | ||
| 87 | +}) | ||
| 88 | +``` |
node_modules/@alicloud/sms-sdk/demo/index.js
0 → 100644
| 1 | +/** | ||
| 2 | + * 云通信基础能力业务短信发送、查询详情以及消费消息示例,供参考。 | ||
| 3 | + * Created on 2017-07-31 | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +const SMSClient = require('./../index') | ||
| 7 | + | ||
| 8 | +// ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换 | ||
| 9 | +const accessKeyId = 'yourAccessKeyId' | ||
| 10 | +const secretAccessKey = 'yourAccessKeySecret' | ||
| 11 | + | ||
| 12 | +//在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName,不用填最后面一段 | ||
| 13 | +const queueName = 'Alicom-Queue-1092397003988387-' | ||
| 14 | + | ||
| 15 | +//初始化sms_client | ||
| 16 | +let smsClient = new SMSClient({accessKeyId, secretAccessKey}) | ||
| 17 | + | ||
| 18 | +//短信回执报告 | ||
| 19 | +smsClient.receiveMsg(0, queueName).then(function (res) { | ||
| 20 | + //消息体需要base64解码 | ||
| 21 | + let {code, body}=res | ||
| 22 | + if (code === 200) { | ||
| 23 | + //处理消息体,messagebody | ||
| 24 | + console.log(body) | ||
| 25 | + } | ||
| 26 | +}, function (err) { | ||
| 27 | + console.log(err) | ||
| 28 | +}) | ||
| 29 | + | ||
| 30 | +//短信上行报告 | ||
| 31 | +smsClient.receiveMsg(1, queueName).then(function (res) { | ||
| 32 | + //消息体需要base64解码 | ||
| 33 | + let {code, body}=res | ||
| 34 | + if (code === 200) { | ||
| 35 | + //处理消息体,messagebody | ||
| 36 | + console.log(body) | ||
| 37 | + } | ||
| 38 | +}, function (err) { | ||
| 39 | + console.log(err) | ||
| 40 | +}) | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +//查询短信发送详情 | ||
| 44 | +smsClient.queryDetail({ | ||
| 45 | + PhoneNumber: '1500000000', | ||
| 46 | + SendDate: '20170731', | ||
| 47 | + PageSize: '10', | ||
| 48 | + CurrentPage: "1" | ||
| 49 | +}).then(function (res) { | ||
| 50 | + let {Code, SmsSendDetailDTOs}=res | ||
| 51 | + if (Code === 'OK') { | ||
| 52 | + //处理发送详情内容 | ||
| 53 | + console.log(SmsSendDetailDTOs) | ||
| 54 | + } | ||
| 55 | +}, function (err) { | ||
| 56 | + //处理错误 | ||
| 57 | + console.log(err) | ||
| 58 | +}) | ||
| 59 | + | ||
| 60 | +//发送短信 | ||
| 61 | +smsClient.sendSMS({ | ||
| 62 | + PhoneNumbers: '1500000000', | ||
| 63 | + SignName: '云通信产品', | ||
| 64 | + TemplateCode: 'SMS_000000', | ||
| 65 | + TemplateParam: '{"code":"12345","product":"云通信"}' | ||
| 66 | +}).then(function (res) { | ||
| 67 | + let {Code}=res | ||
| 68 | + if (Code === 'OK') { | ||
| 69 | + //处理返回参数 | ||
| 70 | + console.log(res) | ||
| 71 | + } | ||
| 72 | +}, function (err) { | ||
| 73 | + console.log(err) | ||
| 74 | +}) |
node_modules/@alicloud/sms-sdk/index.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const DysmsapiClient = require('@alicloud/dysmsapi') | ||
| 4 | +const DybaseapiClient = require('@alicloud/dybaseapi') | ||
| 5 | +const MNSClient = require('@alicloud/mns') | ||
| 6 | + | ||
| 7 | +// 短信回执报告:SmsReport,短信上行:SmsUp | ||
| 8 | +const msgTypeList = ["SmsReport", "SmsUp"] | ||
| 9 | + | ||
| 10 | +const DYSMSAPI_ENDPOINT = 'http://dysmsapi.aliyuncs.com' | ||
| 11 | +const DYBASEAPI_ENDPOINT = 'http://dybaseapi.aliyuncs.com' | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +class SMSClient { | ||
| 15 | + constructor(options) { | ||
| 16 | + let {accessKeyId, secretAccessKey}=options | ||
| 17 | + if (!accessKeyId) { | ||
| 18 | + throw new TypeError('parameter "accessKeyId" is required'); | ||
| 19 | + } | ||
| 20 | + if (!secretAccessKey) { | ||
| 21 | + throw new TypeError('parameter "secretAccessKey" is required'); | ||
| 22 | + } | ||
| 23 | + this.dysmsapiClient = new DysmsapiClient({accessKeyId, secretAccessKey, endpoint: DYSMSAPI_ENDPOINT}) | ||
| 24 | + this.dybaseClient = new DybaseapiClient({accessKeyId, secretAccessKey, endpoint: DYBASEAPI_ENDPOINT}) | ||
| 25 | + this.expire = [] | ||
| 26 | + this.mnsClient = [] | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + //发送短信 | ||
| 30 | + sendSMS(params) { | ||
| 31 | + return this.dysmsapiClient.sendSms(params) | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + //查询详情 | ||
| 35 | + queryDetail(params) { | ||
| 36 | + return this.dysmsapiClient.querySendDetails(params) | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + //失效时间与当前系统时间比较,提前2分钟刷新token | ||
| 40 | + _refresh(type) { | ||
| 41 | + return this.expire[type] - new Date().getTime() > 2 * 60 * 1000 | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + //获取token | ||
| 45 | + _getToken(type) { | ||
| 46 | + let msgType = msgTypeList[type] | ||
| 47 | + return this.dybaseClient.queryTokenForMnsQueue({MessageType: msgType}) | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + //根据类型获取mnsclient实例 | ||
| 51 | + async _getMNSClient(type) { | ||
| 52 | + if (this.mnsClient && (this.mnsClient[type] instanceof MNSClient) && this._refresh(type)) { | ||
| 53 | + return this.mnsClient[type] | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + let { | ||
| 57 | + MessageTokenDTO:{ | ||
| 58 | + SecurityToken, | ||
| 59 | + AccessKeyId, | ||
| 60 | + AccessKeySecret | ||
| 61 | + } | ||
| 62 | + }=await this._getToken(type) | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + if (!(AccessKeyId && AccessKeySecret && SecurityToken)) { | ||
| 66 | + throw new TypeError('get token fail') | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + let mnsClient = new MNSClient('1943695596114318', { | ||
| 71 | + securityToken: SecurityToken, | ||
| 72 | + region: 'cn-hangzhou', | ||
| 73 | + accessKeyId: AccessKeyId, | ||
| 74 | + accessKeySecret: AccessKeySecret, | ||
| 75 | + // optional & default | ||
| 76 | + secure: false, // use https or http | ||
| 77 | + internal: false, // use internal endpoint | ||
| 78 | + vpc: false // use vpc endpoint | ||
| 79 | + }) | ||
| 80 | + this.mnsClient[type] = mnsClient | ||
| 81 | + this.expire[type] = (new Date().getTime() + 10 * 60 * 1000) | ||
| 82 | + return mnsClient | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + //typeIndex :0 为回执,1为上行 | ||
| 86 | + async receiveMsg(typeIndex = 0, preQueueName, waitSeconds = 10) { | ||
| 87 | + let mnsClient = await this._getMNSClient(typeIndex) | ||
| 88 | + return await mnsClient.receiveMessage(preQueueName + msgTypeList[typeIndex], waitSeconds) | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +module.exports = SMSClient | ||
| 94 | + | ||
| 95 | + | ||
| 96 | + | ||
| 97 | + |
| 1 | +{ | ||
| 2 | + "name": "aliyun-dysms-sdk", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "lockfileVersion": 1, | ||
| 5 | + "dependencies": { | ||
| 6 | + "@alicloud/dybaseapi": { | ||
| 7 | + "version": "1.0.0", | ||
| 8 | + "resolved": "http://registry.npm.alibaba-inc.com/@alicloud/dybaseapi/download/@alicloud/dybaseapi-1.0.0.tgz", | ||
| 9 | + "dependencies": { | ||
| 10 | + "@alicloud/pop-core": { | ||
| 11 | + "version": "1.3.3", | ||
| 12 | + "resolved": "http://registry.npm.alibaba-inc.com/@alicloud/pop-core/download/@alicloud/pop-core-1.3.3.tgz", | ||
| 13 | + "dependencies": { | ||
| 14 | + "httpx": { | ||
| 15 | + "version": "2.1.2", | ||
| 16 | + "resolved": "http://registry.npm.alibaba-inc.com/httpx/download/httpx-2.1.2.tgz" | ||
| 17 | + }, | ||
| 18 | + "kitx": { | ||
| 19 | + "version": "1.2.1", | ||
| 20 | + "resolved": "http://registry.npm.alibaba-inc.com/kitx/download/kitx-1.2.1.tgz" | ||
| 21 | + }, | ||
| 22 | + "xml2js": { | ||
| 23 | + "version": "0.4.17", | ||
| 24 | + "resolved": "http://registry.npm.alibaba-inc.com/xml2js/download/xml2js-0.4.17.tgz" | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + }, | ||
| 30 | + "@alicloud/dysmsapi": { | ||
| 31 | + "version": "https://registry.npmjs.org/@alicloud/dysmsapi/-/dysmsapi-1.0.0.tgz", | ||
| 32 | + "integrity": "sha1-cS3dfs/1wGNTejwwSGfS6uAv/JU=" | ||
| 33 | + }, | ||
| 34 | + "@alicloud/mns": { | ||
| 35 | + "version": "1.0.0-beta4", | ||
| 36 | + "resolved": "https://registry.npmjs.org/@alicloud/mns/-/mns-1.0.0-beta4.tgz", | ||
| 37 | + "integrity": "sha512-bN/OoL3HuaXKRerUa+sWaGvhH58PTONEPTkujwOGxd0ZSg1Zs+Pk5WdXokm2yeddVfYJmU6DkuUOmox/E08+Wg==" | ||
| 38 | + }, | ||
| 39 | + "@alicloud/pop-core": { | ||
| 40 | + "version": "https://registry.npmjs.org/@alicloud/pop-core/-/pop-core-1.3.3.tgz", | ||
| 41 | + "integrity": "sha1-ClZ8Cuxg4S1E4pVk52ZXvuvNvW8=" | ||
| 42 | + }, | ||
| 43 | + "assertion-error": { | ||
| 44 | + "version": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", | ||
| 45 | + "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", | ||
| 46 | + "dev": true | ||
| 47 | + }, | ||
| 48 | + "chai": { | ||
| 49 | + "version": "https://registry.npmjs.org/chai/-/chai-4.0.2.tgz", | ||
| 50 | + "integrity": "sha1-L3MnxN5vOF3XeHmZ4qsCaXoyuDs=", | ||
| 51 | + "dev": true | ||
| 52 | + }, | ||
| 53 | + "check-error": { | ||
| 54 | + "version": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", | ||
| 55 | + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", | ||
| 56 | + "dev": true | ||
| 57 | + }, | ||
| 58 | + "debug": { | ||
| 59 | + "version": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", | ||
| 60 | + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" | ||
| 61 | + }, | ||
| 62 | + "deep-eql": { | ||
| 63 | + "version": "https://registry.npmjs.org/deep-eql/-/deep-eql-2.0.2.tgz", | ||
| 64 | + "integrity": "sha1-sbrAblbwp2d3aG1Qyf63XC7XZ5o=", | ||
| 65 | + "dev": true, | ||
| 66 | + "dependencies": { | ||
| 67 | + "type-detect": { | ||
| 68 | + "version": "https://registry.npmjs.org/type-detect/-/type-detect-3.0.0.tgz", | ||
| 69 | + "integrity": "sha1-RtDMhVOrt7E6NSsNbeov1Y8tm1U=", | ||
| 70 | + "dev": true | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + }, | ||
| 74 | + "get-func-name": { | ||
| 75 | + "version": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", | ||
| 76 | + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", | ||
| 77 | + "dev": true | ||
| 78 | + }, | ||
| 79 | + "httpx": { | ||
| 80 | + "version": "https://registry.npmjs.org/httpx/-/httpx-2.1.2.tgz", | ||
| 81 | + "integrity": "sha1-Wa7BWK1o3wqtNopymyXyKo2/sRQ=" | ||
| 82 | + }, | ||
| 83 | + "kitx": { | ||
| 84 | + "version": "https://registry.npmjs.org/kitx/-/kitx-1.2.1.tgz", | ||
| 85 | + "integrity": "sha1-uvvi526hmbATleEwEcdnCo/ULT8=" | ||
| 86 | + }, | ||
| 87 | + "lodash": { | ||
| 88 | + "version": "http://registry.npm.alibaba-inc.com/lodash/download/lodash-4.17.4.tgz", | ||
| 89 | + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" | ||
| 90 | + }, | ||
| 91 | + "ms": { | ||
| 92 | + "version": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | ||
| 93 | + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | ||
| 94 | + }, | ||
| 95 | + "pathval": { | ||
| 96 | + "version": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", | ||
| 97 | + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", | ||
| 98 | + "dev": true | ||
| 99 | + }, | ||
| 100 | + "sax": { | ||
| 101 | + "version": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", | ||
| 102 | + "integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk=" | ||
| 103 | + }, | ||
| 104 | + "type-detect": { | ||
| 105 | + "version": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.3.tgz", | ||
| 106 | + "integrity": "sha1-Dj8mcLRAmbC0bChNE2p+9Jx0wuo=", | ||
| 107 | + "dev": true | ||
| 108 | + }, | ||
| 109 | + "xml2js": { | ||
| 110 | + "version": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz", | ||
| 111 | + "integrity": "sha1-F76T6q4/O3eTWceVtBlwWogX6Gg=" | ||
| 112 | + }, | ||
| 113 | + "xmlbuilder": { | ||
| 114 | + "version": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz", | ||
| 115 | + "integrity": "sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU=" | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | +} |
node_modules/@alicloud/sms-sdk/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "@alicloud/sms-sdk", | ||
| 6 | + "scope": "@alicloud", | ||
| 7 | + "escapedName": "@alicloud%2fsms-sdk", | ||
| 8 | + "name": "@alicloud/sms-sdk", | ||
| 9 | + "rawSpec": "", | ||
| 10 | + "spec": "latest", | ||
| 11 | + "type": "tag" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "@alicloud/sms-sdk@latest", | ||
| 17 | + "_id": "@alicloud/sms-sdk@1.0.2", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/@alicloud/sms-sdk", | ||
| 20 | + "_nodeVersion": "6.9.2", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/sms-sdk-1.0.2.tgz_1502680187908_0.7891042081173509" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "chuck.ql", | ||
| 27 | + "email": "kunqian434@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "3.10.9", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "@alicloud/sms-sdk", | ||
| 33 | + "scope": "@alicloud", | ||
| 34 | + "escapedName": "@alicloud%2fsms-sdk", | ||
| 35 | + "name": "@alicloud/sms-sdk", | ||
| 36 | + "rawSpec": "", | ||
| 37 | + "spec": "latest", | ||
| 38 | + "type": "tag" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "#USER", | ||
| 42 | + "/" | ||
| 43 | + ], | ||
| 44 | + "_resolved": "https://registry.npmjs.org/@alicloud/sms-sdk/-/sms-sdk-1.0.2.tgz", | ||
| 45 | + "_shasum": "8842ed88bc88e55a9deaf28ba5b2c872aa48f5c1", | ||
| 46 | + "_shrinkwrap": null, | ||
| 47 | + "_spec": "@alicloud/sms-sdk", | ||
| 48 | + "_where": "/Users/fzy/project/koa2_Sequelize_project", | ||
| 49 | + "author": { | ||
| 50 | + "name": "chuck.ql" | ||
| 51 | + }, | ||
| 52 | + "dependencies": { | ||
| 53 | + "@alicloud/dybaseapi": "^1.0.0", | ||
| 54 | + "@alicloud/dysmsapi": "^1.0.0", | ||
| 55 | + "@alicloud/mns": "^1.0.0-beta4" | ||
| 56 | + }, | ||
| 57 | + "description": "阿里云-云通信-短信产品SDK", | ||
| 58 | + "devDependencies": { | ||
| 59 | + "chai": "^4.0.2" | ||
| 60 | + }, | ||
| 61 | + "directories": {}, | ||
| 62 | + "dist": { | ||
| 63 | + "shasum": "8842ed88bc88e55a9deaf28ba5b2c872aa48f5c1", | ||
| 64 | + "tarball": "https://registry.npmjs.org/@alicloud/sms-sdk/-/sms-sdk-1.0.2.tgz" | ||
| 65 | + }, | ||
| 66 | + "gitHead": "95da6c8fa4096b459f1dbe5ed7a15528b42aaef4", | ||
| 67 | + "keywords": [ | ||
| 68 | + "SDK", | ||
| 69 | + "云通信", | ||
| 70 | + "阿里云", | ||
| 71 | + "短信", | ||
| 72 | + "Node.js" | ||
| 73 | + ], | ||
| 74 | + "license": "ISC", | ||
| 75 | + "main": "index.js", | ||
| 76 | + "maintainers": [ | ||
| 77 | + { | ||
| 78 | + "name": "chuck.ql", | ||
| 79 | + "email": "kunqian434@gmail.com" | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + "name": "rockuw", | ||
| 83 | + "email": "rockuw@gmail.com" | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + "name": "humanhuang", | ||
| 87 | + "email": "halfthink@gmail.com" | ||
| 88 | + }, | ||
| 89 | + { | ||
| 90 | + "name": "jacksontian", | ||
| 91 | + "email": "shyvo1987@gmail.com" | ||
| 92 | + } | ||
| 93 | + ], | ||
| 94 | + "name": "@alicloud/sms-sdk", | ||
| 95 | + "optionalDependencies": {}, | ||
| 96 | + "readme": "### 安装\n\n``` javascript\n $ npm install @alicloud/sms-sdk --save\n```\n\n### 使用方法\n1. 安装@alicloud/sms-sdk,请需要根据官方文档做一些配置\n2. 产品文档: https://dysms.console.aliyun.com/dysms.htm\n\n### DEMO\n\n``` javascript\n/**\n * 云通信基础能力业务短信发送、查询详情以及消费消息示例,供参考。\n * Created on 2017-07-31\n */\n\nconst SMSClient = require('./../index')\n\n// ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换\nconst accessKeyId = 'yourAccessKeyId'\nconst secretAccessKey = 'yourAccessKeySecret'\n\n//在云通信页面开通相应业务消息后,就能在页面上获得对应的queueName,不用填最后面一段\nconst queueName = 'Alicom-Queue-1092397003988387-'\n\n//初始化sms_client\nlet smsClient = new SMSClient({accessKeyId, secretAccessKey})\n\n//短信回执报告\nsmsClient.receiveMsg(0, queueName).then(function (res) {\n //消息体需要base64解码\n let {code, body}=res\n if (code === 200) {\n //处理消息体,messagebody\n console.log(body)\n }\n}, function (err) {\n console.log(err)\n})\n\n//短信上行报告\nsmsClient.receiveMsg(1, queueName).then(function (res) {\n //消息体需要base64解码\n let {code, body}=res\n if (code === 200) {\n //处理消息体,messagebody\n console.log(body)\n }\n}, function (err) {\n console.log(err)\n})\n\n\n//查询短信发送详情\nsmsClient.queryDetail({\n PhoneNumber: '1500000000',\n SendDate: '20170731',\n PageSize: '10',\n CurrentPage: \"1\"\n}).then(function (res) {\n let {Code, SmsSendDetailDTOs}=res\n if (Code === 'OK') {\n //处理发送详情内容\n console.log(SmsSendDetailDTOs)\n }\n}, function (err) {\n //处理错误\n console.log(err)\n})\n\n//发送短信\nsmsClient.sendSMS({\n PhoneNumbers: '1500000000',\n SignName: '云通信产品',\n TemplateCode: 'SMS_000000',\n TemplateParam: '{\"code\":\"12345\",\"product\":\"云通信\"}'\n}).then(function (res) {\n let {Code}=res\n if (Code === 'OK') {\n //处理返回参数\n console.log(res)\n }\n}, function (err) {\n console.log(err)\n})\n```", | ||
| 97 | + "readmeFilename": "README.md", | ||
| 98 | + "repository": { | ||
| 99 | + "type": "git", | ||
| 100 | + "url": "git@gitlab.alibaba-inc.com:alidayu/aliyun-dysms-sdk.git" | ||
| 101 | + }, | ||
| 102 | + "scripts": { | ||
| 103 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
| 104 | + }, | ||
| 105 | + "version": "1.0.2" | ||
| 106 | +} |
node_modules/httpx/README.md
0 → 100644
| 1 | +httpx | ||
| 2 | +=========== | ||
| 3 | +http(s) module with power. | ||
| 4 | + | ||
| 5 | +[![NPM version][npm-image]][npm-url] | ||
| 6 | +[![build status][travis-image]][travis-url] | ||
| 7 | +[](https://coveralls.io/github/JacksonTian/httpx?branch=master) | ||
| 8 | +[![David deps][david-image]][david-url] | ||
| 9 | +[![npm download][download-image]][download-url] | ||
| 10 | + | ||
| 11 | +[npm-image]: https://img.shields.io/npm/v/httpx.svg?style=flat-square | ||
| 12 | +[npm-url]: https://npmjs.org/package/httpx | ||
| 13 | +[travis-image]: https://img.shields.io/travis/JacksonTian/httpx.svg?style=flat-square | ||
| 14 | +[travis-url]: https://travis-ci.org/JacksonTian/httpx | ||
| 15 | +[david-image]: https://img.shields.io/david/JacksonTian/httpx.svg?style=flat-square | ||
| 16 | +[david-url]: https://david-dm.org/JacksonTian/httpx | ||
| 17 | +[download-image]: https://img.shields.io/npm/dm/httpx.svg?style=flat-square | ||
| 18 | +[download-url]: https://npmjs.org/package/httpx | ||
| 19 | + | ||
| 20 | +## Installation | ||
| 21 | + | ||
| 22 | +```bash | ||
| 23 | +$ npm install httpx --save | ||
| 24 | +``` | ||
| 25 | + | ||
| 26 | +## Usage | ||
| 27 | + | ||
| 28 | +```js | ||
| 29 | +'use strict'; | ||
| 30 | + | ||
| 31 | +const httpx = require('httpx'); | ||
| 32 | + | ||
| 33 | +httpx.request('http://www.baidu.com/').then((response) => { | ||
| 34 | + response.pipe(process.stdout); | ||
| 35 | + | ||
| 36 | + response.on('end', () => { | ||
| 37 | + process.stdout.write('\n'); | ||
| 38 | + }); | ||
| 39 | +}, (err) => { | ||
| 40 | + // on error | ||
| 41 | +}); | ||
| 42 | +``` | ||
| 43 | + | ||
| 44 | +Or with `co`. | ||
| 45 | + | ||
| 46 | +```js | ||
| 47 | +co(function* () { | ||
| 48 | + var response = yield httpx.request('http://www.baidu.com/'); | ||
| 49 | + | ||
| 50 | + response.pipe(process.stdout); | ||
| 51 | + | ||
| 52 | + response.on('end', () => { | ||
| 53 | + process.stdout.write('\n'); | ||
| 54 | + }); | ||
| 55 | +}); | ||
| 56 | +``` | ||
| 57 | + | ||
| 58 | +Or with `async/await`. | ||
| 59 | + | ||
| 60 | +```js | ||
| 61 | +(async function () { | ||
| 62 | + var response = await httpx.request('http://www.baidu.com/'); | ||
| 63 | + | ||
| 64 | + response.pipe(process.stdout); | ||
| 65 | + | ||
| 66 | + response.on('end', () => { | ||
| 67 | + process.stdout.write('\n'); | ||
| 68 | + }); | ||
| 69 | +})(); | ||
| 70 | +``` | ||
| 71 | + | ||
| 72 | +## API | ||
| 73 | + | ||
| 74 | +### `httpx.request(url[, options])` | ||
| 75 | + | ||
| 76 | +- **url** String | Object - The URL to request, either a String or a Object that return by [url.parse](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost). | ||
| 77 | +- ***options*** Object - Optional | ||
| 78 | + - ***method*** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`. | ||
| 79 | + - ***data*** String | [Buffer](http://nodejs.org/api/buffer.html) | Readable - Manually set the content of payload. | ||
| 80 | + - ***headers*** Object - Request headers. | ||
| 81 | + - ***timeout*** Number - Request timeout in milliseconds. Defaults to 3000. When timeout happen, will return `RequestTimeout`. | ||
| 82 | + - ***agent*** [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) - HTTP/HTTPS Agent object. | ||
| 83 | + Set `false` if you does not use agent. | ||
| 84 | + - ***beforeRequest*** Function - Before request hook, you can change every thing here. | ||
| 85 | + - ***compression*** Boolean - Enable compression support. Tell server side responses compressed data | ||
| 86 | + | ||
| 87 | +### `httpx.read(response[, encoding])` | ||
| 88 | + | ||
| 89 | +- **response** Response - the Client response. Don't setEncoding() for the response. | ||
| 90 | +- **encoding** String - Optional. | ||
| 91 | + | ||
| 92 | +## License | ||
| 93 | +The MIT license |
node_modules/httpx/lib/index.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const zlib = require('zlib'); | ||
| 4 | +const http = require('http'); | ||
| 5 | +const https = require('https'); | ||
| 6 | +const parse = require('url').parse; | ||
| 7 | +const format = require('url').format; | ||
| 8 | + | ||
| 9 | +const debug = require('debug')('httpx'); | ||
| 10 | + | ||
| 11 | +const httpAgent = new http.Agent({ keepAlive: true }); | ||
| 12 | +const httpsAgent = new https.Agent({ keepAlive: true }); | ||
| 13 | + | ||
| 14 | +const TIMEOUT = 3000; // 3s | ||
| 15 | + | ||
| 16 | +var append = function (err, name, message) { | ||
| 17 | + err.name = name + err.name; | ||
| 18 | + err.message = message + '\n' + err.message; | ||
| 19 | + return err; | ||
| 20 | +}; | ||
| 21 | + | ||
| 22 | +exports.request = function (url, opts) { | ||
| 23 | + // request(url) | ||
| 24 | + opts || (opts = {}); | ||
| 25 | + | ||
| 26 | + const parsed = typeof url === 'string' ? parse(url) : url; | ||
| 27 | + | ||
| 28 | + const timeout = opts.timeout || TIMEOUT; | ||
| 29 | + const isHttps = parsed.protocol === 'https:'; | ||
| 30 | + const method = (opts.method || 'GET').toUpperCase(); | ||
| 31 | + const defaultAgent = isHttps ? httpsAgent : httpAgent; | ||
| 32 | + const agent = opts.agent || defaultAgent; | ||
| 33 | + | ||
| 34 | + var options = { | ||
| 35 | + host: parsed.hostname || 'localhost', | ||
| 36 | + path: parsed.path || '/', | ||
| 37 | + method: method, | ||
| 38 | + port: parsed.port || (parsed.protocol === 'https:' ? 443 : 80), | ||
| 39 | + agent: agent, | ||
| 40 | + headers: opts.headers || {} | ||
| 41 | + }; | ||
| 42 | + | ||
| 43 | + if (opts.compression) { | ||
| 44 | + options.headers['accept-encoding'] = 'gzip,deflate'; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + const httplib = isHttps ? https : http; | ||
| 48 | + | ||
| 49 | + if (typeof opts.beforeRequest === 'function') { | ||
| 50 | + options = opts.beforeRequest(options); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + return new Promise((resolve, reject) => { | ||
| 54 | + const startTime = Date.now(); | ||
| 55 | + | ||
| 56 | + const request = httplib.request(options); | ||
| 57 | + const body = opts.data; | ||
| 58 | + | ||
| 59 | + var timer; | ||
| 60 | + | ||
| 61 | + var cleanup = () => { | ||
| 62 | + if (timer) { | ||
| 63 | + clearTimeout(timer); | ||
| 64 | + timer = null; | ||
| 65 | + } | ||
| 66 | + }; | ||
| 67 | + | ||
| 68 | + var fulfilled = (response) => { | ||
| 69 | + cleanup(); | ||
| 70 | + if (debug.enabled) { | ||
| 71 | + const requestHeaders = response.req._header; | ||
| 72 | + requestHeaders.split('\r\n').forEach((line) => { | ||
| 73 | + debug('> %s', line); | ||
| 74 | + }); | ||
| 75 | + | ||
| 76 | + debug('< HTTP/%s %s %s', response.httpVersion, response.statusCode, response.statusMessage); | ||
| 77 | + Object.keys(response.headers).forEach((key) => { | ||
| 78 | + debug('< %s: %s', key, response.headers[key]); | ||
| 79 | + }); | ||
| 80 | + } | ||
| 81 | + resolve(response); | ||
| 82 | + }; | ||
| 83 | + | ||
| 84 | + var rejected = (err) => { | ||
| 85 | + cleanup(); | ||
| 86 | + err.message += ` ${method} ${format(parsed)} failed.`; | ||
| 87 | + reject(err); | ||
| 88 | + }; | ||
| 89 | + | ||
| 90 | + var abort = (err) => { | ||
| 91 | + request.abort(); | ||
| 92 | + rejected(err); | ||
| 93 | + }; | ||
| 94 | + | ||
| 95 | + // string | ||
| 96 | + if (!body || 'string' === typeof body || body instanceof Buffer) { | ||
| 97 | + request.end(body); | ||
| 98 | + } else if ('function' === typeof body.pipe) { // stream | ||
| 99 | + body.pipe(request); | ||
| 100 | + body.once('error', (err) => { | ||
| 101 | + abort(append(err, 'HttpX', 'Stream occor error')); | ||
| 102 | + }); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + request.on('response', fulfilled); | ||
| 106 | + request.on('error', rejected); | ||
| 107 | + // for timeout | ||
| 108 | + timer = setTimeout(() => { | ||
| 109 | + timer = null; | ||
| 110 | + var err = new Error(); | ||
| 111 | + var message = `${method} ${format(parsed)} timeout(${timeout}).`; | ||
| 112 | + abort(append(err, 'RequestTimeout', message)); | ||
| 113 | + }, timeout); | ||
| 114 | + }); | ||
| 115 | +}; | ||
| 116 | + | ||
| 117 | +exports.read = function (response, encoding) { | ||
| 118 | + var readable = response; | ||
| 119 | + switch (response.headers['content-encoding']) { | ||
| 120 | + // or, just use zlib.createUnzip() to handle both cases | ||
| 121 | + case 'gzip': | ||
| 122 | + readable = response.pipe(zlib.createGunzip()); | ||
| 123 | + break; | ||
| 124 | + case 'deflate': | ||
| 125 | + readable = response.pipe(zlib.createInflate()); | ||
| 126 | + break; | ||
| 127 | + default: | ||
| 128 | + break; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + return new Promise((resolve, reject) => { | ||
| 132 | + var cleanup = function () { | ||
| 133 | + // cleanup | ||
| 134 | + readable.removeListener('error', onError); | ||
| 135 | + readable.removeListener('data', onData); | ||
| 136 | + readable.removeListener('end', onEnd); | ||
| 137 | + }; | ||
| 138 | + | ||
| 139 | + const bufs = []; | ||
| 140 | + var size = 0; | ||
| 141 | + | ||
| 142 | + var onData = function (buf) { | ||
| 143 | + bufs.push(buf); | ||
| 144 | + size += buf.length; | ||
| 145 | + }; | ||
| 146 | + | ||
| 147 | + var onError = function (err) { | ||
| 148 | + cleanup(); | ||
| 149 | + reject(err); | ||
| 150 | + }; | ||
| 151 | + | ||
| 152 | + var onEnd = function () { | ||
| 153 | + cleanup(); | ||
| 154 | + var buff = Buffer.concat(bufs, size); | ||
| 155 | + | ||
| 156 | + debug(''); | ||
| 157 | + if (encoding) { | ||
| 158 | + const result = buff.toString(encoding); | ||
| 159 | + debug(result); | ||
| 160 | + return resolve(result); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + debug('Buffer <ignored>'); | ||
| 164 | + resolve(buff); | ||
| 165 | + }; | ||
| 166 | + | ||
| 167 | + readable.on('error', onError); | ||
| 168 | + readable.on('data', onData); | ||
| 169 | + readable.on('end', onEnd); | ||
| 170 | + }); | ||
| 171 | +}; |
node_modules/httpx/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "httpx@^2.1.2", | ||
| 6 | + "scope": null, | ||
| 7 | + "escapedName": "httpx", | ||
| 8 | + "name": "httpx", | ||
| 9 | + "rawSpec": "^2.1.2", | ||
| 10 | + "spec": ">=2.1.2 <3.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "httpx@>=2.1.2 <3.0.0", | ||
| 17 | + "_id": "httpx@2.1.2", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/httpx", | ||
| 20 | + "_nodeVersion": "7.7.4", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/httpx-2.1.2.tgz_1495703755237_0.4486262151040137" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "4.1.2", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "httpx@^2.1.2", | ||
| 33 | + "scope": null, | ||
| 34 | + "escapedName": "httpx", | ||
| 35 | + "name": "httpx", | ||
| 36 | + "rawSpec": "^2.1.2", | ||
| 37 | + "spec": ">=2.1.2 <3.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/mns", | ||
| 42 | + "/@alicloud/pop-core" | ||
| 43 | + ], | ||
| 44 | + "_resolved": "https://registry.npmjs.org/httpx/-/httpx-2.1.2.tgz", | ||
| 45 | + "_shasum": "59aec158ad68df0aad368a729b25f22a8dbfb114", | ||
| 46 | + "_shrinkwrap": null, | ||
| 47 | + "_spec": "httpx@^2.1.2", | ||
| 48 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core", | ||
| 49 | + "author": { | ||
| 50 | + "name": "Jackson Tian" | ||
| 51 | + }, | ||
| 52 | + "bugs": { | ||
| 53 | + "url": "https://github.com/JacksonTian/httpx/issues" | ||
| 54 | + }, | ||
| 55 | + "dependencies": { | ||
| 56 | + "debug": "^2.2.0" | ||
| 57 | + }, | ||
| 58 | + "description": "http(s) module with power", | ||
| 59 | + "devDependencies": { | ||
| 60 | + "co-mocha": "^1.1.3", | ||
| 61 | + "coveralls": "^2.11.15", | ||
| 62 | + "eslint": "^3.13.1", | ||
| 63 | + "istanbul": "^0.4.5", | ||
| 64 | + "mocha": "^3.2.0" | ||
| 65 | + }, | ||
| 66 | + "directories": {}, | ||
| 67 | + "dist": { | ||
| 68 | + "shasum": "59aec158ad68df0aad368a729b25f22a8dbfb114", | ||
| 69 | + "tarball": "https://registry.npmjs.org/httpx/-/httpx-2.1.2.tgz" | ||
| 70 | + }, | ||
| 71 | + "files": [ | ||
| 72 | + "lib" | ||
| 73 | + ], | ||
| 74 | + "gitHead": "bbe3ce084ae2818be6051d0018ab2618e5f2f24a", | ||
| 75 | + "homepage": "https://github.com/JacksonTian/httpx", | ||
| 76 | + "license": "MIT", | ||
| 77 | + "main": "lib/index.js", | ||
| 78 | + "maintainers": [ | ||
| 79 | + { | ||
| 80 | + "name": "jacksontian", | ||
| 81 | + "email": "shyvo1987@gmail.com" | ||
| 82 | + } | ||
| 83 | + ], | ||
| 84 | + "name": "httpx", | ||
| 85 | + "optionalDependencies": {}, | ||
| 86 | + "readme": "httpx\n===========\nhttp(s) module with power.\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[](https://coveralls.io/github/JacksonTian/httpx?branch=master)\n[![David deps][david-image]][david-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/httpx.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/httpx\n[travis-image]: https://img.shields.io/travis/JacksonTian/httpx.svg?style=flat-square\n[travis-url]: https://travis-ci.org/JacksonTian/httpx\n[david-image]: https://img.shields.io/david/JacksonTian/httpx.svg?style=flat-square\n[david-url]: https://david-dm.org/JacksonTian/httpx\n[download-image]: https://img.shields.io/npm/dm/httpx.svg?style=flat-square\n[download-url]: https://npmjs.org/package/httpx\n\n## Installation\n\n```bash\n$ npm install httpx --save\n```\n\n## Usage\n\n```js\n'use strict';\n\nconst httpx = require('httpx');\n\nhttpx.request('http://www.baidu.com/').then((response) => {\n response.pipe(process.stdout);\n\n response.on('end', () => {\n process.stdout.write('\\n');\n });\n}, (err) => {\n // on error\n});\n```\n\nOr with `co`.\n\n```js\nco(function* () {\n var response = yield httpx.request('http://www.baidu.com/');\n\n response.pipe(process.stdout);\n\n response.on('end', () => {\n process.stdout.write('\\n');\n });\n});\n```\n\nOr with `async/await`.\n\n```js\n(async function () {\n var response = await httpx.request('http://www.baidu.com/');\n\n response.pipe(process.stdout);\n\n response.on('end', () => {\n process.stdout.write('\\n');\n });\n})();\n```\n\n## API\n\n### `httpx.request(url[, options])`\n\n- **url** String | Object - The URL to request, either a String or a Object that return by [url.parse](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost).\n- ***options*** Object - Optional\n - ***method*** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`.\n - ***data*** String | [Buffer](http://nodejs.org/api/buffer.html) | Readable - Manually set the content of payload.\n - ***headers*** Object - Request headers.\n - ***timeout*** Number - Request timeout in milliseconds. Defaults to 3000. When timeout happen, will return `RequestTimeout`.\n - ***agent*** [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) - HTTP/HTTPS Agent object.\n Set `false` if you does not use agent.\n - ***beforeRequest*** Function - Before request hook, you can change every thing here.\n - ***compression*** Boolean - Enable compression support. Tell server side responses compressed data\n\n### `httpx.read(response[, encoding])`\n\n- **response** Response - the Client response. Don't setEncoding() for the response.\n- **encoding** String - Optional.\n\n## License\nThe MIT license\n", | ||
| 87 | + "readmeFilename": "README.md", | ||
| 88 | + "repository": { | ||
| 89 | + "type": "git", | ||
| 90 | + "url": "git+https://github.com/JacksonTian/httpx.git" | ||
| 91 | + }, | ||
| 92 | + "scripts": { | ||
| 93 | + "test": "make test" | ||
| 94 | + }, | ||
| 95 | + "version": "2.1.2" | ||
| 96 | +} |
node_modules/json-bigint/.npmignore
0 → 100644
node_modules/json-bigint/.travis.yml
0 → 100644
node_modules/json-bigint/LICENSE
0 → 100644
| 1 | +The MIT License (MIT) | ||
| 2 | + | ||
| 3 | +Copyright (c) 2013 Andrey Sidorov | ||
| 4 | + | ||
| 5 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 6 | +this software and associated documentation files (the "Software"), to deal in | ||
| 7 | +the Software without restriction, including without limitation the rights to | ||
| 8 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 9 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 10 | +subject to the following conditions: | ||
| 11 | + | ||
| 12 | +The above copyright notice and this permission notice shall be included in all | ||
| 13 | +copies or substantial portions of the Software. | ||
| 14 | + | ||
| 15 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 16 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 17 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 18 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 19 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 20 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
node_modules/json-bigint/README.md
0 → 100644
| 1 | +json-bigint | ||
| 2 | +=========== | ||
| 3 | + | ||
| 4 | +[](http://travis-ci.org/sidorares/json-bigint) | ||
| 5 | +[](https://nodei.co/npm/json-bigint/) | ||
| 6 | + | ||
| 7 | +JSON.parse/stringify with bigints support. Based on Douglas Crockford [JSON.js](https://github.com/douglascrockford/JSON-js) package and [bignumber.js](https://github.com/MikeMcl/bignumber.js) library. | ||
| 8 | + | ||
| 9 | +While most JSON parsers assume numeric values have same precision restrictions as IEEE 754 double, JSON specification _does not_ say anything about number precision. Any floating point number in decimal (optionally scientific) notation is valid JSON value. It's a good idea to serialize values which might fall out of IEEE 754 integer precision as strings in your JSON api, but `{ "value" : 9223372036854775807}`, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of `JSON.parse` is this object: `{ value: 9223372036854776000 }` | ||
| 10 | + | ||
| 11 | +========== | ||
| 12 | + | ||
| 13 | +example: | ||
| 14 | + | ||
| 15 | +```js | ||
| 16 | +var JSONbig = require('json-bigint'); | ||
| 17 | + | ||
| 18 | +var json = '{ "value" : 9223372036854775807, "v2": 123 }'; | ||
| 19 | +console.log('Input:', json); | ||
| 20 | +console.log(''); | ||
| 21 | + | ||
| 22 | +console.log('node.js bult-in JSON:') | ||
| 23 | +var r = JSON.parse(json); | ||
| 24 | +console.log('JSON.parse(input).value : ', r.value.toString()); | ||
| 25 | +console.log('JSON.stringify(JSON.parse(input)):', JSON.stringify(r)); | ||
| 26 | + | ||
| 27 | +console.log('\n\nbig number JSON:'); | ||
| 28 | +var r1 = JSONbig.parse(json); | ||
| 29 | +console.log('JSON.parse(input).value : ', r1.value.toString()); | ||
| 30 | +console.log('JSON.stringify(JSON.parse(input)):', JSONbig.stringify(r1)); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +Output: | ||
| 34 | + | ||
| 35 | +``` | ||
| 36 | +Input: { "value" : 9223372036854775807, "v2": 123 } | ||
| 37 | + | ||
| 38 | +node.js bult-in JSON: | ||
| 39 | +JSON.parse(input).value : 9223372036854776000 | ||
| 40 | +JSON.stringify(JSON.parse(input)): {"value":9223372036854776000,"v2":123} | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +big number JSON: | ||
| 44 | +JSON.parse(input).value : 9223372036854775807 | ||
| 45 | +JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123} | ||
| 46 | +``` | ||
| 47 | +### Options | ||
| 48 | +The behaviour of the parser is somewhat configurable through 'options' | ||
| 49 | + | ||
| 50 | +#### options.strict, boolean, default false | ||
| 51 | +Specifies the parsing should be "strict" towards reporting duplicate-keys in the parsed string. | ||
| 52 | +The default follows what is allowed in standard json and resembles the behavior of JSON.parse, but overwrites any previous values with the last one assigned to the duplicate-key. | ||
| 53 | + | ||
| 54 | +Setting options.strict = true will fail-fast on such duplicate-key occurances and thus warn you upfront of possible lost information. | ||
| 55 | + | ||
| 56 | +example: | ||
| 57 | +```js | ||
| 58 | +var JSONbig = require('json-bigint'); | ||
| 59 | +var JSONstrict = require('json-bigint')({"strict": true}); | ||
| 60 | + | ||
| 61 | +var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}'; | ||
| 62 | +console.log('\n\nDuplicate Key test with both lenient and strict JSON parsing'); | ||
| 63 | +console.log('Input:', dupkeys); | ||
| 64 | +var works = JSONbig.parse(dupkeys); | ||
| 65 | +console.log('JSON.parse(dupkeys).dupkey: %s', works.dupkey); | ||
| 66 | +var fails = "will stay like this"; | ||
| 67 | +try { | ||
| 68 | + fails = JSONstrict.parse(dupkeys); | ||
| 69 | + console.log('ERROR!! Should never get here'); | ||
| 70 | +} catch (e) { | ||
| 71 | + console.log('Succesfully catched expected exception on duplicate keys: %j', e); | ||
| 72 | +} | ||
| 73 | +``` | ||
| 74 | + | ||
| 75 | +Output | ||
| 76 | +``` | ||
| 77 | +Duplicate Key test with big number JSON | ||
| 78 | +Input: { "dupkey": "value 1", "dupkey": "value 2"} | ||
| 79 | +JSON.parse(dupkeys).dupkey: value 2 | ||
| 80 | +Succesfully catched expected exception on duplicate keys: {"name":"SyntaxError","message":"Duplicate key \"dupkey\"","at":33,"text":"{ \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}"} | ||
| 81 | + | ||
| 82 | +``` | ||
| 83 | + | ||
| 84 | +#### options.storeAsString, boolean, default false | ||
| 85 | +Specifies if BigInts should be stored in the object as a string, rather than the default BigNumber. | ||
| 86 | + | ||
| 87 | +Note that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all BigInts to be-and-stay strings). | ||
| 88 | + | ||
| 89 | +example: | ||
| 90 | +```js | ||
| 91 | +var JSONbig = require('json-bigint'); | ||
| 92 | +var JSONbigString = require('json-bigint')({"storeAsString": true}); | ||
| 93 | +var key = '{ "key": 1234567890123456789 }'; | ||
| 94 | +console.log('\n\nStoring the BigInt as a string, instead of a BigNumber'); | ||
| 95 | +console.log('Input:', key); | ||
| 96 | +var withInt = JSONbig.parse(key); | ||
| 97 | +var withString = JSONbigString.parse(key); | ||
| 98 | +console.log('Default type: %s, With option type: %s', typeof withInt.key, typeof withString.key); | ||
| 99 | + | ||
| 100 | +``` | ||
| 101 | + | ||
| 102 | +Output | ||
| 103 | +``` | ||
| 104 | +Storing the BigInt as a string, instead of a BigNumber | ||
| 105 | +Input: { "key": 1234567890123456789 } | ||
| 106 | +Default type: object, With option type: string | ||
| 107 | + | ||
| 108 | +``` | ||
| 109 | + | ||
| 110 | + | ||
| 111 | +### Links: | ||
| 112 | +- [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt) | ||
| 113 | +- [Re: \[Json\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html) | ||
| 114 | +- [Is there any proper way to parse JSON with large numbers? (long, bigint, int64)](http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint) | ||
| 115 | +- [What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t) | ||
| 116 | +- [Large numbers erroneously rounded in Javascript](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript) | ||
| 117 | + |
node_modules/json-bigint/index.js
0 → 100644
| 1 | +var json_stringify = require('./lib/stringify.js').stringify; | ||
| 2 | +var json_parse = require('./lib/parse.js'); | ||
| 3 | + | ||
| 4 | +module.exports = function(options) { | ||
| 5 | + return { | ||
| 6 | + parse: json_parse(options), | ||
| 7 | + stringify: json_stringify | ||
| 8 | + } | ||
| 9 | +}; | ||
| 10 | +//create the default method members with no options applied for backwards compatibility | ||
| 11 | +module.exports.parse = json_parse(); | ||
| 12 | +module.exports.stringify = json_stringify; |
node_modules/json-bigint/lib/parse.js
0 → 100644
| 1 | +var BigNumber = null; | ||
| 2 | +/* | ||
| 3 | + json_parse.js | ||
| 4 | + 2012-06-20 | ||
| 5 | + | ||
| 6 | + Public Domain. | ||
| 7 | + | ||
| 8 | + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | ||
| 9 | + | ||
| 10 | + This file creates a json_parse function. | ||
| 11 | + During create you can (optionally) specify some behavioural switches | ||
| 12 | + | ||
| 13 | + require('json-bigint')(options) | ||
| 14 | + | ||
| 15 | + The optional options parameter holds switches that drive certain | ||
| 16 | + aspects of the parsing process: | ||
| 17 | + * options.strict = true will warn about duplicate-key usage in the json. | ||
| 18 | + The default (strict = false) will silently ignore those and overwrite | ||
| 19 | + values for keys that are in duplicate use. | ||
| 20 | + | ||
| 21 | + The resulting function follows this signature: | ||
| 22 | + json_parse(text, reviver) | ||
| 23 | + This method parses a JSON text to produce an object or array. | ||
| 24 | + It can throw a SyntaxError exception. | ||
| 25 | + | ||
| 26 | + The optional reviver parameter is a function that can filter and | ||
| 27 | + transform the results. It receives each of the keys and values, | ||
| 28 | + and its return value is used instead of the original value. | ||
| 29 | + If it returns what it received, then the structure is not modified. | ||
| 30 | + If it returns undefined then the member is deleted. | ||
| 31 | + | ||
| 32 | + Example: | ||
| 33 | + | ||
| 34 | + // Parse the text. Values that look like ISO date strings will | ||
| 35 | + // be converted to Date objects. | ||
| 36 | + | ||
| 37 | + myData = json_parse(text, function (key, value) { | ||
| 38 | + var a; | ||
| 39 | + if (typeof value === 'string') { | ||
| 40 | + a = | ||
| 41 | +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); | ||
| 42 | + if (a) { | ||
| 43 | + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], | ||
| 44 | + +a[5], +a[6])); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + return value; | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + This is a reference implementation. You are free to copy, modify, or | ||
| 51 | + redistribute. | ||
| 52 | + | ||
| 53 | + This code should be minified before deployment. | ||
| 54 | + See http://javascript.crockford.com/jsmin.html | ||
| 55 | + | ||
| 56 | + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO | ||
| 57 | + NOT CONTROL. | ||
| 58 | +*/ | ||
| 59 | + | ||
| 60 | +/*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode, | ||
| 61 | + hasOwnProperty, message, n, name, prototype, push, r, t, text | ||
| 62 | +*/ | ||
| 63 | + | ||
| 64 | +var json_parse = function (options) { | ||
| 65 | + "use strict"; | ||
| 66 | + | ||
| 67 | +// This is a function that can parse a JSON text, producing a JavaScript | ||
| 68 | +// data structure. It is a simple, recursive descent parser. It does not use | ||
| 69 | +// eval or regular expressions, so it can be used as a model for implementing | ||
| 70 | +// a JSON parser in other languages. | ||
| 71 | + | ||
| 72 | +// We are defining the function inside of another function to avoid creating | ||
| 73 | +// global variables. | ||
| 74 | + | ||
| 75 | + | ||
| 76 | +// Default options one can override by passing options to the parse() | ||
| 77 | + var _options = { | ||
| 78 | + "strict": false, // not being strict means do not generate syntax errors for "duplicate key" | ||
| 79 | + "storeAsString": false // toggles whether the values should be stored as BigNumber (default) or a string | ||
| 80 | + }; | ||
| 81 | + | ||
| 82 | + | ||
| 83 | +// If there are options, then use them to override the default _options | ||
| 84 | + if (options !== undefined && options !== null) { | ||
| 85 | + if (options.strict === true) { | ||
| 86 | + _options.strict = true; | ||
| 87 | + } | ||
| 88 | + if (options.storeAsString === true) { | ||
| 89 | + _options.storeAsString = true; | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + | ||
| 94 | + var at, // The index of the current character | ||
| 95 | + ch, // The current character | ||
| 96 | + escapee = { | ||
| 97 | + '"': '"', | ||
| 98 | + '\\': '\\', | ||
| 99 | + '/': '/', | ||
| 100 | + b: '\b', | ||
| 101 | + f: '\f', | ||
| 102 | + n: '\n', | ||
| 103 | + r: '\r', | ||
| 104 | + t: '\t' | ||
| 105 | + }, | ||
| 106 | + text, | ||
| 107 | + | ||
| 108 | + error = function (m) { | ||
| 109 | + | ||
| 110 | +// Call error when something is wrong. | ||
| 111 | + | ||
| 112 | + throw { | ||
| 113 | + name: 'SyntaxError', | ||
| 114 | + message: m, | ||
| 115 | + at: at, | ||
| 116 | + text: text | ||
| 117 | + }; | ||
| 118 | + }, | ||
| 119 | + | ||
| 120 | + next = function (c) { | ||
| 121 | + | ||
| 122 | +// If a c parameter is provided, verify that it matches the current character. | ||
| 123 | + | ||
| 124 | + if (c && c !== ch) { | ||
| 125 | + error("Expected '" + c + "' instead of '" + ch + "'"); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | +// Get the next character. When there are no more characters, | ||
| 129 | +// return the empty string. | ||
| 130 | + | ||
| 131 | + ch = text.charAt(at); | ||
| 132 | + at += 1; | ||
| 133 | + return ch; | ||
| 134 | + }, | ||
| 135 | + | ||
| 136 | + number = function () { | ||
| 137 | +// Parse a number value. | ||
| 138 | + | ||
| 139 | + var number, | ||
| 140 | + string = ''; | ||
| 141 | + | ||
| 142 | + if (ch === '-') { | ||
| 143 | + string = '-'; | ||
| 144 | + next('-'); | ||
| 145 | + } | ||
| 146 | + while (ch >= '0' && ch <= '9') { | ||
| 147 | + string += ch; | ||
| 148 | + next(); | ||
| 149 | + } | ||
| 150 | + if (ch === '.') { | ||
| 151 | + string += '.'; | ||
| 152 | + while (next() && ch >= '0' && ch <= '9') { | ||
| 153 | + string += ch; | ||
| 154 | + } | ||
| 155 | + } | ||
| 156 | + if (ch === 'e' || ch === 'E') { | ||
| 157 | + string += ch; | ||
| 158 | + next(); | ||
| 159 | + if (ch === '-' || ch === '+') { | ||
| 160 | + string += ch; | ||
| 161 | + next(); | ||
| 162 | + } | ||
| 163 | + while (ch >= '0' && ch <= '9') { | ||
| 164 | + string += ch; | ||
| 165 | + next(); | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + number = +string; | ||
| 169 | + if (!isFinite(number)) { | ||
| 170 | + error("Bad number"); | ||
| 171 | + } else { | ||
| 172 | + if (BigNumber == null) | ||
| 173 | + BigNumber = require('bignumber.js'); | ||
| 174 | + //if (number > 9007199254740992 || number < -9007199254740992) | ||
| 175 | + // Bignumber has stricter check: everything with length > 15 digits disallowed | ||
| 176 | + if (string.length > 15) | ||
| 177 | + return (_options.storeAsString === true) ? string : new BigNumber(string); | ||
| 178 | + return number; | ||
| 179 | + } | ||
| 180 | + }, | ||
| 181 | + | ||
| 182 | + string = function () { | ||
| 183 | + | ||
| 184 | +// Parse a string value. | ||
| 185 | + | ||
| 186 | + var hex, | ||
| 187 | + i, | ||
| 188 | + string = '', | ||
| 189 | + uffff; | ||
| 190 | + | ||
| 191 | +// When parsing for string values, we must look for " and \ characters. | ||
| 192 | + | ||
| 193 | + if (ch === '"') { | ||
| 194 | + while (next()) { | ||
| 195 | + if (ch === '"') { | ||
| 196 | + next(); | ||
| 197 | + return string; | ||
| 198 | + } | ||
| 199 | + if (ch === '\\') { | ||
| 200 | + next(); | ||
| 201 | + if (ch === 'u') { | ||
| 202 | + uffff = 0; | ||
| 203 | + for (i = 0; i < 4; i += 1) { | ||
| 204 | + hex = parseInt(next(), 16); | ||
| 205 | + if (!isFinite(hex)) { | ||
| 206 | + break; | ||
| 207 | + } | ||
| 208 | + uffff = uffff * 16 + hex; | ||
| 209 | + } | ||
| 210 | + string += String.fromCharCode(uffff); | ||
| 211 | + } else if (typeof escapee[ch] === 'string') { | ||
| 212 | + string += escapee[ch]; | ||
| 213 | + } else { | ||
| 214 | + break; | ||
| 215 | + } | ||
| 216 | + } else { | ||
| 217 | + string += ch; | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + error("Bad string"); | ||
| 222 | + }, | ||
| 223 | + | ||
| 224 | + white = function () { | ||
| 225 | + | ||
| 226 | +// Skip whitespace. | ||
| 227 | + | ||
| 228 | + while (ch && ch <= ' ') { | ||
| 229 | + next(); | ||
| 230 | + } | ||
| 231 | + }, | ||
| 232 | + | ||
| 233 | + word = function () { | ||
| 234 | + | ||
| 235 | +// true, false, or null. | ||
| 236 | + | ||
| 237 | + switch (ch) { | ||
| 238 | + case 't': | ||
| 239 | + next('t'); | ||
| 240 | + next('r'); | ||
| 241 | + next('u'); | ||
| 242 | + next('e'); | ||
| 243 | + return true; | ||
| 244 | + case 'f': | ||
| 245 | + next('f'); | ||
| 246 | + next('a'); | ||
| 247 | + next('l'); | ||
| 248 | + next('s'); | ||
| 249 | + next('e'); | ||
| 250 | + return false; | ||
| 251 | + case 'n': | ||
| 252 | + next('n'); | ||
| 253 | + next('u'); | ||
| 254 | + next('l'); | ||
| 255 | + next('l'); | ||
| 256 | + return null; | ||
| 257 | + } | ||
| 258 | + error("Unexpected '" + ch + "'"); | ||
| 259 | + }, | ||
| 260 | + | ||
| 261 | + value, // Place holder for the value function. | ||
| 262 | + | ||
| 263 | + array = function () { | ||
| 264 | + | ||
| 265 | +// Parse an array value. | ||
| 266 | + | ||
| 267 | + var array = []; | ||
| 268 | + | ||
| 269 | + if (ch === '[') { | ||
| 270 | + next('['); | ||
| 271 | + white(); | ||
| 272 | + if (ch === ']') { | ||
| 273 | + next(']'); | ||
| 274 | + return array; // empty array | ||
| 275 | + } | ||
| 276 | + while (ch) { | ||
| 277 | + array.push(value()); | ||
| 278 | + white(); | ||
| 279 | + if (ch === ']') { | ||
| 280 | + next(']'); | ||
| 281 | + return array; | ||
| 282 | + } | ||
| 283 | + next(','); | ||
| 284 | + white(); | ||
| 285 | + } | ||
| 286 | + } | ||
| 287 | + error("Bad array"); | ||
| 288 | + }, | ||
| 289 | + | ||
| 290 | + object = function () { | ||
| 291 | + | ||
| 292 | +// Parse an object value. | ||
| 293 | + | ||
| 294 | + var key, | ||
| 295 | + object = {}; | ||
| 296 | + | ||
| 297 | + if (ch === '{') { | ||
| 298 | + next('{'); | ||
| 299 | + white(); | ||
| 300 | + if (ch === '}') { | ||
| 301 | + next('}'); | ||
| 302 | + return object; // empty object | ||
| 303 | + } | ||
| 304 | + while (ch) { | ||
| 305 | + key = string(); | ||
| 306 | + white(); | ||
| 307 | + next(':'); | ||
| 308 | + if (_options.strict === true && Object.hasOwnProperty.call(object, key)) { | ||
| 309 | + error('Duplicate key "' + key + '"'); | ||
| 310 | + } | ||
| 311 | + object[key] = value(); | ||
| 312 | + white(); | ||
| 313 | + if (ch === '}') { | ||
| 314 | + next('}'); | ||
| 315 | + return object; | ||
| 316 | + } | ||
| 317 | + next(','); | ||
| 318 | + white(); | ||
| 319 | + } | ||
| 320 | + } | ||
| 321 | + error("Bad object"); | ||
| 322 | + }; | ||
| 323 | + | ||
| 324 | + value = function () { | ||
| 325 | + | ||
| 326 | +// Parse a JSON value. It could be an object, an array, a string, a number, | ||
| 327 | +// or a word. | ||
| 328 | + | ||
| 329 | + white(); | ||
| 330 | + switch (ch) { | ||
| 331 | + case '{': | ||
| 332 | + return object(); | ||
| 333 | + case '[': | ||
| 334 | + return array(); | ||
| 335 | + case '"': | ||
| 336 | + return string(); | ||
| 337 | + case '-': | ||
| 338 | + return number(); | ||
| 339 | + default: | ||
| 340 | + return ch >= '0' && ch <= '9' ? number() : word(); | ||
| 341 | + } | ||
| 342 | + }; | ||
| 343 | + | ||
| 344 | +// Return the json_parse function. It will have access to all of the above | ||
| 345 | +// functions and variables. | ||
| 346 | + | ||
| 347 | + return function (source, reviver) { | ||
| 348 | + var result; | ||
| 349 | + | ||
| 350 | + text = source + ''; | ||
| 351 | + at = 0; | ||
| 352 | + ch = ' '; | ||
| 353 | + result = value(); | ||
| 354 | + white(); | ||
| 355 | + if (ch) { | ||
| 356 | + error("Syntax error"); | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | +// If there is a reviver function, we recursively walk the new structure, | ||
| 360 | +// passing each name/value pair to the reviver function for possible | ||
| 361 | +// transformation, starting with a temporary root object that holds the result | ||
| 362 | +// in an empty key. If there is not a reviver function, we simply return the | ||
| 363 | +// result. | ||
| 364 | + | ||
| 365 | + return typeof reviver === 'function' | ||
| 366 | + ? (function walk(holder, key) { | ||
| 367 | + var k, v, value = holder[key]; | ||
| 368 | + if (value && typeof value === 'object') { | ||
| 369 | + Object.keys(value).forEach(function(k) { | ||
| 370 | + v = walk(value, k); | ||
| 371 | + if (v !== undefined) { | ||
| 372 | + value[k] = v; | ||
| 373 | + } else { | ||
| 374 | + delete value[k]; | ||
| 375 | + } | ||
| 376 | + }); | ||
| 377 | + } | ||
| 378 | + return reviver.call(holder, key, value); | ||
| 379 | + }({'': result}, '')) | ||
| 380 | + : result; | ||
| 381 | + }; | ||
| 382 | +} | ||
| 383 | + | ||
| 384 | +module.exports = json_parse; |
node_modules/json-bigint/lib/stringify.js
0 → 100644
| 1 | +var BigNumber = require('bignumber.js'); | ||
| 2 | + | ||
| 3 | +/* | ||
| 4 | + json2.js | ||
| 5 | + 2013-05-26 | ||
| 6 | + | ||
| 7 | + Public Domain. | ||
| 8 | + | ||
| 9 | + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | ||
| 10 | + | ||
| 11 | + See http://www.JSON.org/js.html | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + This code should be minified before deployment. | ||
| 15 | + See http://javascript.crockford.com/jsmin.html | ||
| 16 | + | ||
| 17 | + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO | ||
| 18 | + NOT CONTROL. | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + This file creates a global JSON object containing two methods: stringify | ||
| 22 | + and parse. | ||
| 23 | + | ||
| 24 | + JSON.stringify(value, replacer, space) | ||
| 25 | + value any JavaScript value, usually an object or array. | ||
| 26 | + | ||
| 27 | + replacer an optional parameter that determines how object | ||
| 28 | + values are stringified for objects. It can be a | ||
| 29 | + function or an array of strings. | ||
| 30 | + | ||
| 31 | + space an optional parameter that specifies the indentation | ||
| 32 | + of nested structures. If it is omitted, the text will | ||
| 33 | + be packed without extra whitespace. If it is a number, | ||
| 34 | + it will specify the number of spaces to indent at each | ||
| 35 | + level. If it is a string (such as '\t' or ' '), | ||
| 36 | + it contains the characters used to indent at each level. | ||
| 37 | + | ||
| 38 | + This method produces a JSON text from a JavaScript value. | ||
| 39 | + | ||
| 40 | + When an object value is found, if the object contains a toJSON | ||
| 41 | + method, its toJSON method will be called and the result will be | ||
| 42 | + stringified. A toJSON method does not serialize: it returns the | ||
| 43 | + value represented by the name/value pair that should be serialized, | ||
| 44 | + or undefined if nothing should be serialized. The toJSON method | ||
| 45 | + will be passed the key associated with the value, and this will be | ||
| 46 | + bound to the value | ||
| 47 | + | ||
| 48 | + For example, this would serialize Dates as ISO strings. | ||
| 49 | + | ||
| 50 | + Date.prototype.toJSON = function (key) { | ||
| 51 | + function f(n) { | ||
| 52 | + // Format integers to have at least two digits. | ||
| 53 | + return n < 10 ? '0' + n : n; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + return this.getUTCFullYear() + '-' + | ||
| 57 | + f(this.getUTCMonth() + 1) + '-' + | ||
| 58 | + f(this.getUTCDate()) + 'T' + | ||
| 59 | + f(this.getUTCHours()) + ':' + | ||
| 60 | + f(this.getUTCMinutes()) + ':' + | ||
| 61 | + f(this.getUTCSeconds()) + 'Z'; | ||
| 62 | + }; | ||
| 63 | + | ||
| 64 | + You can provide an optional replacer method. It will be passed the | ||
| 65 | + key and value of each member, with this bound to the containing | ||
| 66 | + object. The value that is returned from your method will be | ||
| 67 | + serialized. If your method returns undefined, then the member will | ||
| 68 | + be excluded from the serialization. | ||
| 69 | + | ||
| 70 | + If the replacer parameter is an array of strings, then it will be | ||
| 71 | + used to select the members to be serialized. It filters the results | ||
| 72 | + such that only members with keys listed in the replacer array are | ||
| 73 | + stringified. | ||
| 74 | + | ||
| 75 | + Values that do not have JSON representations, such as undefined or | ||
| 76 | + functions, will not be serialized. Such values in objects will be | ||
| 77 | + dropped; in arrays they will be replaced with null. You can use | ||
| 78 | + a replacer function to replace those with JSON values. | ||
| 79 | + JSON.stringify(undefined) returns undefined. | ||
| 80 | + | ||
| 81 | + The optional space parameter produces a stringification of the | ||
| 82 | + value that is filled with line breaks and indentation to make it | ||
| 83 | + easier to read. | ||
| 84 | + | ||
| 85 | + If the space parameter is a non-empty string, then that string will | ||
| 86 | + be used for indentation. If the space parameter is a number, then | ||
| 87 | + the indentation will be that many spaces. | ||
| 88 | + | ||
| 89 | + Example: | ||
| 90 | + | ||
| 91 | + text = JSON.stringify(['e', {pluribus: 'unum'}]); | ||
| 92 | + // text is '["e",{"pluribus":"unum"}]' | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); | ||
| 96 | + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' | ||
| 97 | + | ||
| 98 | + text = JSON.stringify([new Date()], function (key, value) { | ||
| 99 | + return this[key] instanceof Date ? | ||
| 100 | + 'Date(' + this[key] + ')' : value; | ||
| 101 | + }); | ||
| 102 | + // text is '["Date(---current time---)"]' | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + JSON.parse(text, reviver) | ||
| 106 | + This method parses a JSON text to produce an object or array. | ||
| 107 | + It can throw a SyntaxError exception. | ||
| 108 | + | ||
| 109 | + The optional reviver parameter is a function that can filter and | ||
| 110 | + transform the results. It receives each of the keys and values, | ||
| 111 | + and its return value is used instead of the original value. | ||
| 112 | + If it returns what it received, then the structure is not modified. | ||
| 113 | + If it returns undefined then the member is deleted. | ||
| 114 | + | ||
| 115 | + Example: | ||
| 116 | + | ||
| 117 | + // Parse the text. Values that look like ISO date strings will | ||
| 118 | + // be converted to Date objects. | ||
| 119 | + | ||
| 120 | + myData = JSON.parse(text, function (key, value) { | ||
| 121 | + var a; | ||
| 122 | + if (typeof value === 'string') { | ||
| 123 | + a = | ||
| 124 | +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); | ||
| 125 | + if (a) { | ||
| 126 | + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], | ||
| 127 | + +a[5], +a[6])); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + return value; | ||
| 131 | + }); | ||
| 132 | + | ||
| 133 | + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { | ||
| 134 | + var d; | ||
| 135 | + if (typeof value === 'string' && | ||
| 136 | + value.slice(0, 5) === 'Date(' && | ||
| 137 | + value.slice(-1) === ')') { | ||
| 138 | + d = new Date(value.slice(5, -1)); | ||
| 139 | + if (d) { | ||
| 140 | + return d; | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + return value; | ||
| 144 | + }); | ||
| 145 | + | ||
| 146 | + | ||
| 147 | + This is a reference implementation. You are free to copy, modify, or | ||
| 148 | + redistribute. | ||
| 149 | +*/ | ||
| 150 | + | ||
| 151 | +/*jslint evil: true, regexp: true */ | ||
| 152 | + | ||
| 153 | +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, | ||
| 154 | + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, | ||
| 155 | + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, | ||
| 156 | + lastIndex, length, parse, prototype, push, replace, slice, stringify, | ||
| 157 | + test, toJSON, toString, valueOf | ||
| 158 | +*/ | ||
| 159 | + | ||
| 160 | + | ||
| 161 | +// Create a JSON object only if one does not already exist. We create the | ||
| 162 | +// methods in a closure to avoid creating global variables. | ||
| 163 | + | ||
| 164 | +var JSON = module.exports; | ||
| 165 | + | ||
| 166 | +(function () { | ||
| 167 | + 'use strict'; | ||
| 168 | + | ||
| 169 | + function f(n) { | ||
| 170 | + // Format integers to have at least two digits. | ||
| 171 | + return n < 10 ? '0' + n : n; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, | ||
| 175 | + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, | ||
| 176 | + gap, | ||
| 177 | + indent, | ||
| 178 | + meta = { // table of character substitutions | ||
| 179 | + '\b': '\\b', | ||
| 180 | + '\t': '\\t', | ||
| 181 | + '\n': '\\n', | ||
| 182 | + '\f': '\\f', | ||
| 183 | + '\r': '\\r', | ||
| 184 | + '"' : '\\"', | ||
| 185 | + '\\': '\\\\' | ||
| 186 | + }, | ||
| 187 | + rep; | ||
| 188 | + | ||
| 189 | + | ||
| 190 | + function quote(string) { | ||
| 191 | + | ||
| 192 | +// If the string contains no control characters, no quote characters, and no | ||
| 193 | +// backslash characters, then we can safely slap some quotes around it. | ||
| 194 | +// Otherwise we must also replace the offending characters with safe escape | ||
| 195 | +// sequences. | ||
| 196 | + | ||
| 197 | + escapable.lastIndex = 0; | ||
| 198 | + return escapable.test(string) ? '"' + string.replace(escapable, function (a) { | ||
| 199 | + var c = meta[a]; | ||
| 200 | + return typeof c === 'string' | ||
| 201 | + ? c | ||
| 202 | + : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); | ||
| 203 | + }) + '"' : '"' + string + '"'; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + | ||
| 207 | + function str(key, holder) { | ||
| 208 | + | ||
| 209 | +// Produce a string from holder[key]. | ||
| 210 | + | ||
| 211 | + var i, // The loop counter. | ||
| 212 | + k, // The member key. | ||
| 213 | + v, // The member value. | ||
| 214 | + length, | ||
| 215 | + mind = gap, | ||
| 216 | + partial, | ||
| 217 | + value = holder[key], | ||
| 218 | + isBigNumber = value != null && (value instanceof BigNumber || value.isBigNumber);; | ||
| 219 | + | ||
| 220 | +// If the value has a toJSON method, call it to obtain a replacement value. | ||
| 221 | + | ||
| 222 | + if (value && typeof value === 'object' && | ||
| 223 | + typeof value.toJSON === 'function') { | ||
| 224 | + value = value.toJSON(key); | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | +// If we were called with a replacer function, then call the replacer to | ||
| 228 | +// obtain a replacement value. | ||
| 229 | + | ||
| 230 | + if (typeof rep === 'function') { | ||
| 231 | + value = rep.call(holder, key, value); | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | +// What happens next depends on the value's type. | ||
| 235 | + | ||
| 236 | + switch (typeof value) { | ||
| 237 | + case 'string': | ||
| 238 | + if (isBigNumber) { | ||
| 239 | + return value; | ||
| 240 | + } else { | ||
| 241 | + return quote(value); | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + case 'number': | ||
| 245 | + | ||
| 246 | +// JSON numbers must be finite. Encode non-finite numbers as null. | ||
| 247 | + | ||
| 248 | + return isFinite(value) ? String(value) : 'null'; | ||
| 249 | + | ||
| 250 | + case 'boolean': | ||
| 251 | + case 'null': | ||
| 252 | + | ||
| 253 | +// If the value is a boolean or null, convert it to a string. Note: | ||
| 254 | +// typeof null does not produce 'null'. The case is included here in | ||
| 255 | +// the remote chance that this gets fixed someday. | ||
| 256 | + | ||
| 257 | + return String(value); | ||
| 258 | + | ||
| 259 | +// If the type is 'object', we might be dealing with an object or an array or | ||
| 260 | +// null. | ||
| 261 | + | ||
| 262 | + case 'object': | ||
| 263 | + | ||
| 264 | +// Due to a specification blunder in ECMAScript, typeof null is 'object', | ||
| 265 | +// so watch out for that case. | ||
| 266 | + | ||
| 267 | + if (!value) { | ||
| 268 | + return 'null'; | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | +// Make an array to hold the partial results of stringifying this object value. | ||
| 272 | + | ||
| 273 | + gap += indent; | ||
| 274 | + partial = []; | ||
| 275 | + | ||
| 276 | +// Is the value an array? | ||
| 277 | + | ||
| 278 | + if (Object.prototype.toString.apply(value) === '[object Array]') { | ||
| 279 | + | ||
| 280 | +// The value is an array. Stringify every element. Use null as a placeholder | ||
| 281 | +// for non-JSON values. | ||
| 282 | + | ||
| 283 | + length = value.length; | ||
| 284 | + for (i = 0; i < length; i += 1) { | ||
| 285 | + partial[i] = str(i, value) || 'null'; | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | +// Join all of the elements together, separated with commas, and wrap them in | ||
| 289 | +// brackets. | ||
| 290 | + | ||
| 291 | + v = partial.length === 0 | ||
| 292 | + ? '[]' | ||
| 293 | + : gap | ||
| 294 | + ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' | ||
| 295 | + : '[' + partial.join(',') + ']'; | ||
| 296 | + gap = mind; | ||
| 297 | + return v; | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | +// If the replacer is an array, use it to select the members to be stringified. | ||
| 301 | + | ||
| 302 | + if (rep && typeof rep === 'object') { | ||
| 303 | + length = rep.length; | ||
| 304 | + for (i = 0; i < length; i += 1) { | ||
| 305 | + if (typeof rep[i] === 'string') { | ||
| 306 | + k = rep[i]; | ||
| 307 | + v = str(k, value); | ||
| 308 | + if (v) { | ||
| 309 | + partial.push(quote(k) + (gap ? ': ' : ':') + v); | ||
| 310 | + } | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + } else { | ||
| 314 | + | ||
| 315 | +// Otherwise, iterate through all of the keys in the object. | ||
| 316 | + | ||
| 317 | + Object.keys(value).forEach(function(k) { | ||
| 318 | + var v = str(k, value); | ||
| 319 | + if (v) { | ||
| 320 | + partial.push(quote(k) + (gap ? ': ' : ':') + v); | ||
| 321 | + } | ||
| 322 | + }); | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | +// Join all of the member texts together, separated with commas, | ||
| 326 | +// and wrap them in braces. | ||
| 327 | + | ||
| 328 | + v = partial.length === 0 | ||
| 329 | + ? '{}' | ||
| 330 | + : gap | ||
| 331 | + ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' | ||
| 332 | + : '{' + partial.join(',') + '}'; | ||
| 333 | + gap = mind; | ||
| 334 | + return v; | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | +// If the JSON object does not yet have a stringify method, give it one. | ||
| 339 | + | ||
| 340 | + if (typeof JSON.stringify !== 'function') { | ||
| 341 | + JSON.stringify = function (value, replacer, space) { | ||
| 342 | + | ||
| 343 | +// The stringify method takes a value and an optional replacer, and an optional | ||
| 344 | +// space parameter, and returns a JSON text. The replacer can be a function | ||
| 345 | +// that can replace values, or an array of strings that will select the keys. | ||
| 346 | +// A default replacer method can be provided. Use of the space parameter can | ||
| 347 | +// produce text that is more easily readable. | ||
| 348 | + | ||
| 349 | + var i; | ||
| 350 | + gap = ''; | ||
| 351 | + indent = ''; | ||
| 352 | + | ||
| 353 | +// If the space parameter is a number, make an indent string containing that | ||
| 354 | +// many spaces. | ||
| 355 | + | ||
| 356 | + if (typeof space === 'number') { | ||
| 357 | + for (i = 0; i < space; i += 1) { | ||
| 358 | + indent += ' '; | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | +// If the space parameter is a string, it will be used as the indent string. | ||
| 362 | + | ||
| 363 | + } else if (typeof space === 'string') { | ||
| 364 | + indent = space; | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | +// If there is a replacer, it must be a function or an array. | ||
| 368 | +// Otherwise, throw an error. | ||
| 369 | + | ||
| 370 | + rep = replacer; | ||
| 371 | + if (replacer && typeof replacer !== 'function' && | ||
| 372 | + (typeof replacer !== 'object' || | ||
| 373 | + typeof replacer.length !== 'number')) { | ||
| 374 | + throw new Error('JSON.stringify'); | ||
| 375 | + } | ||
| 376 | + | ||
| 377 | +// Make a fake root object containing our value under the key of ''. | ||
| 378 | +// Return the result of stringifying the value. | ||
| 379 | + | ||
| 380 | + return str('', {'': value}); | ||
| 381 | + }; | ||
| 382 | + } | ||
| 383 | +}()); |
node_modules/json-bigint/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "json-bigint@^0.2.3", | ||
| 6 | + "scope": null, | ||
| 7 | + "escapedName": "json-bigint", | ||
| 8 | + "name": "json-bigint", | ||
| 9 | + "rawSpec": "^0.2.3", | ||
| 10 | + "spec": ">=0.2.3 <0.3.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "json-bigint@>=0.2.3 <0.3.0", | ||
| 17 | + "_id": "json-bigint@0.2.3", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/json-bigint", | ||
| 20 | + "_nodeVersion": "6.9.1", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "packages-12-west.internal.npmjs.com", | ||
| 23 | + "tmp": "tmp/json-bigint-0.2.3.tgz_1484003726024_0.7127540863584727" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "sidorares", | ||
| 27 | + "email": "sidorares@yandex.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "3.10.8", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "json-bigint@^0.2.3", | ||
| 33 | + "scope": null, | ||
| 34 | + "escapedName": "json-bigint", | ||
| 35 | + "name": "json-bigint", | ||
| 36 | + "rawSpec": "^0.2.3", | ||
| 37 | + "spec": ">=0.2.3 <0.3.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/pop-core" | ||
| 42 | + ], | ||
| 43 | + "_resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.2.3.tgz", | ||
| 44 | + "_shasum": "118d7f6ff1d38659f19f94cf73e64a75a3f988a8", | ||
| 45 | + "_shrinkwrap": null, | ||
| 46 | + "_spec": "json-bigint@^0.2.3", | ||
| 47 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core", | ||
| 48 | + "author": { | ||
| 49 | + "name": "Andrey Sidorov", | ||
| 50 | + "email": "sidorares@yandex.ru" | ||
| 51 | + }, | ||
| 52 | + "bugs": { | ||
| 53 | + "url": "https://github.com/sidorares/json-bigint/issues" | ||
| 54 | + }, | ||
| 55 | + "dependencies": { | ||
| 56 | + "bignumber.js": "^4.0.0" | ||
| 57 | + }, | ||
| 58 | + "description": "JSON.parse with bigints support", | ||
| 59 | + "devDependencies": { | ||
| 60 | + "chai": "~1.9.1", | ||
| 61 | + "mocha": "~1.20.1" | ||
| 62 | + }, | ||
| 63 | + "directories": {}, | ||
| 64 | + "dist": { | ||
| 65 | + "shasum": "118d7f6ff1d38659f19f94cf73e64a75a3f988a8", | ||
| 66 | + "tarball": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.2.3.tgz" | ||
| 67 | + }, | ||
| 68 | + "gitHead": "7c3dbc180df56d329578b040bf5bedda6769ab63", | ||
| 69 | + "homepage": "https://github.com/sidorares/json-bigint#readme", | ||
| 70 | + "keywords": [ | ||
| 71 | + "JSON", | ||
| 72 | + "bigint", | ||
| 73 | + "bignumber", | ||
| 74 | + "parse", | ||
| 75 | + "json" | ||
| 76 | + ], | ||
| 77 | + "license": "MIT", | ||
| 78 | + "main": "index.js", | ||
| 79 | + "maintainers": [ | ||
| 80 | + { | ||
| 81 | + "name": "sidorares", | ||
| 82 | + "email": "sidorares@yandex.com" | ||
| 83 | + } | ||
| 84 | + ], | ||
| 85 | + "name": "json-bigint", | ||
| 86 | + "optionalDependencies": {}, | ||
| 87 | + "readme": "json-bigint\n===========\n\n[](http://travis-ci.org/sidorares/json-bigint)\n[](https://nodei.co/npm/json-bigint/)\n\nJSON.parse/stringify with bigints support. Based on Douglas Crockford [JSON.js](https://github.com/douglascrockford/JSON-js) package and [bignumber.js](https://github.com/MikeMcl/bignumber.js) library.\n\nWhile most JSON parsers assume numeric values have same precision restrictions as IEEE 754 double, JSON specification _does not_ say anything about number precision. Any floating point number in decimal (optionally scientific) notation is valid JSON value. It's a good idea to serialize values which might fall out of IEEE 754 integer precision as strings in your JSON api, but `{ \"value\" : 9223372036854775807}`, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of `JSON.parse` is this object: `{ value: 9223372036854776000 }`\n\n==========\n\nexample:\n\n```js\nvar JSONbig = require('json-bigint');\n\nvar json = '{ \"value\" : 9223372036854775807, \"v2\": 123 }';\nconsole.log('Input:', json);\nconsole.log('');\n\nconsole.log('node.js bult-in JSON:')\nvar r = JSON.parse(json);\nconsole.log('JSON.parse(input).value : ', r.value.toString());\nconsole.log('JSON.stringify(JSON.parse(input)):', JSON.stringify(r));\n\nconsole.log('\\n\\nbig number JSON:');\nvar r1 = JSONbig.parse(json);\nconsole.log('JSON.parse(input).value : ', r1.value.toString());\nconsole.log('JSON.stringify(JSON.parse(input)):', JSONbig.stringify(r1));\n```\n\nOutput:\n\n```\nInput: { \"value\" : 9223372036854775807, \"v2\": 123 }\n\nnode.js bult-in JSON:\nJSON.parse(input).value : 9223372036854776000\nJSON.stringify(JSON.parse(input)): {\"value\":9223372036854776000,\"v2\":123}\n\n\nbig number JSON:\nJSON.parse(input).value : 9223372036854775807\nJSON.stringify(JSON.parse(input)): {\"value\":9223372036854775807,\"v2\":123}\n```\n### Options\nThe behaviour of the parser is somewhat configurable through 'options'\n\n#### options.strict, boolean, default false\nSpecifies the parsing should be \"strict\" towards reporting duplicate-keys in the parsed string.\nThe default follows what is allowed in standard json and resembles the behavior of JSON.parse, but overwrites any previous values with the last one assigned to the duplicate-key.\n\nSetting options.strict = true will fail-fast on such duplicate-key occurances and thus warn you upfront of possible lost information.\n\nexample:\n```js\nvar JSONbig = require('json-bigint');\nvar JSONstrict = require('json-bigint')({\"strict\": true});\n\nvar dupkeys = '{ \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}';\nconsole.log('\\n\\nDuplicate Key test with both lenient and strict JSON parsing');\nconsole.log('Input:', dupkeys);\nvar works = JSONbig.parse(dupkeys);\nconsole.log('JSON.parse(dupkeys).dupkey: %s', works.dupkey);\nvar fails = \"will stay like this\";\ntry {\n fails = JSONstrict.parse(dupkeys);\n console.log('ERROR!! Should never get here');\n} catch (e) {\n console.log('Succesfully catched expected exception on duplicate keys: %j', e);\n}\n```\n\nOutput\n```\nDuplicate Key test with big number JSON\nInput: { \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}\nJSON.parse(dupkeys).dupkey: value 2\nSuccesfully catched expected exception on duplicate keys: {\"name\":\"SyntaxError\",\"message\":\"Duplicate key \\\"dupkey\\\"\",\"at\":33,\"text\":\"{ \\\"dupkey\\\": \\\"value 1\\\", \\\"dupkey\\\": \\\"value 2\\\"}\"}\n\n```\n\n#### options.storeAsString, boolean, default false\nSpecifies if BigInts should be stored in the object as a string, rather than the default BigNumber.\n\nNote that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all BigInts to be-and-stay strings).\n\nexample:\n```js\nvar JSONbig = require('json-bigint');\nvar JSONbigString = require('json-bigint')({\"storeAsString\": true});\nvar key = '{ \"key\": 1234567890123456789 }';\nconsole.log('\\n\\nStoring the BigInt as a string, instead of a BigNumber');\nconsole.log('Input:', key);\nvar withInt = JSONbig.parse(key);\nvar withString = JSONbigString.parse(key);\nconsole.log('Default type: %s, With option type: %s', typeof withInt.key, typeof withString.key);\n\n```\n\nOutput\n```\nStoring the BigInt as a string, instead of a BigNumber\nInput: { \"key\": 1234567890123456789 }\nDefault type: object, With option type: string\n\n```\n\n\n### Links:\n- [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt)\n- [Re: \\[Json\\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html)\n- [Is there any proper way to parse JSON with large numbers? (long, bigint, int64)](http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint)\n- [What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t)\n- [Large numbers erroneously rounded in Javascript](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript)\n\n", | ||
| 88 | + "readmeFilename": "README.md", | ||
| 89 | + "repository": { | ||
| 90 | + "type": "git", | ||
| 91 | + "url": "git+ssh://git@github.com/sidorares/json-bigint.git" | ||
| 92 | + }, | ||
| 93 | + "scripts": { | ||
| 94 | + "test": "./node_modules/mocha/bin/mocha -R spec --check-leaks test/*-test.js" | ||
| 95 | + }, | ||
| 96 | + "version": "0.2.3" | ||
| 97 | +} |
node_modules/json-bigint/test/bigint-test.js
0 → 100644
| 1 | +var mocha = require('mocha') | ||
| 2 | + , assert = require('chai').assert | ||
| 3 | + , expect = require('chai').expect | ||
| 4 | + , BigNumber = require('bignumber.js') | ||
| 5 | + ; | ||
| 6 | + | ||
| 7 | +describe("Testing bigint support", function(){ | ||
| 8 | + var input = '{"big":9223372036854775807,"small":123}'; | ||
| 9 | + | ||
| 10 | + it("Should show classic JSON.parse lacks bigint support", function(done){ | ||
| 11 | + var obj = JSON.parse(input); | ||
| 12 | + expect(obj.small.toString(), "string from small int").to.equal("123"); | ||
| 13 | + expect(obj.big.toString(), "string from big int").to.not.equal("9223372036854775807"); | ||
| 14 | + | ||
| 15 | + var output = JSON.stringify(obj); | ||
| 16 | + expect(output).to.not.equal(input); | ||
| 17 | + done(); | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + it("Should show JSNbig does support bigint parse/stringify roundtrip", function(done){ | ||
| 21 | + var JSONbig = require('../index'); | ||
| 22 | + var obj = JSONbig.parse(input); | ||
| 23 | + expect(obj.small.toString(), "string from small int").to.equal("123"); | ||
| 24 | + expect(obj.big.toString(), "string from big int").to.equal("9223372036854775807"); | ||
| 25 | + expect(obj.big, "instanceof big int").to.be.instanceof(BigNumber); | ||
| 26 | + | ||
| 27 | + var output = JSONbig.stringify(obj); | ||
| 28 | + expect(output).to.equal(input); | ||
| 29 | + done(); | ||
| 30 | + }); | ||
| 31 | +}); |
| 1 | +var mocha = require('mocha') | ||
| 2 | + , assert = require('chai').assert | ||
| 3 | + , expect = require('chai').expect | ||
| 4 | + ; | ||
| 5 | + | ||
| 6 | +describe("Testing 'strict' option", function(){ | ||
| 7 | + var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}'; | ||
| 8 | + it("Should show that duplicate keys just get overwritten by default", function(done){ | ||
| 9 | + var JSONbig = require('../index'); | ||
| 10 | + var result = "before"; | ||
| 11 | + function tryParse() { | ||
| 12 | + result = JSONbig.parse(dupkeys); | ||
| 13 | + } | ||
| 14 | + expect(tryParse).to.not.throw("anything"); | ||
| 15 | + expect(result.dupkey).to.equal("value 2"); | ||
| 16 | + done(); | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + it("Should show that the 'strict' option will fail-fast on duplicate keys", function(done){ | ||
| 20 | + var JSONstrict = require('../index')({"strict": true}); | ||
| 21 | + var result = "before"; | ||
| 22 | + function tryParse() { | ||
| 23 | + result = JSONstrict.parse(dupkeys); | ||
| 24 | + } | ||
| 25 | + expect(tryParse).to.throw({ | ||
| 26 | + name: 'SyntaxError', | ||
| 27 | + message: 'Duplicate key "dupkey"', | ||
| 28 | + at: 33, | ||
| 29 | + text: '{ "dupkey": "value 1", "dupkey": "value 2"}' | ||
| 30 | + }); | ||
| 31 | + expect(result).to.equal("before"); | ||
| 32 | + done(); | ||
| 33 | + }); | ||
| 34 | +}); |
| 1 | +var mocha = require('mocha') | ||
| 2 | + , assert = require('chai').assert | ||
| 3 | + , expect = require('chai').expect | ||
| 4 | + ; | ||
| 5 | + | ||
| 6 | +describe("Testing 'storeAsString' option", function(){ | ||
| 7 | + var key = '{ "key": 12345678901234567 }'; | ||
| 8 | + it("Should show that the key is of type object", function(done){ | ||
| 9 | + var JSONbig = require('../index'); | ||
| 10 | + var result = JSONbig.parse(key); | ||
| 11 | + expect(typeof result.key).to.equal("object"); | ||
| 12 | + done(); | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + it("Should show that key is of type string, when storeAsString option is true", function(done){ | ||
| 16 | + var JSONstring = require('../index')({"storeAsString": true}); | ||
| 17 | + var result = JSONstring.parse(key); | ||
| 18 | + expect(typeof result.key).to.equal("string"); | ||
| 19 | + done(); | ||
| 20 | + }); | ||
| 21 | +}); |
node_modules/kitx/LICENSE
0 → 100644
| 1 | +The MIT License (MIT) | ||
| 2 | + | ||
| 3 | +Copyright (c) 2016 Jackson Tian | ||
| 4 | + | ||
| 5 | +Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 6 | +of this software and associated documentation files (the "Software"), to deal | ||
| 7 | +in the Software without restriction, including without limitation the rights | ||
| 8 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 9 | +copies of the Software, and to permit persons to whom the Software is | ||
| 10 | +furnished to do so, subject to the following conditions: | ||
| 11 | + | ||
| 12 | +The above copyright notice and this permission notice shall be included in all | ||
| 13 | +copies or substantial portions of the Software. | ||
| 14 | + | ||
| 15 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 16 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 17 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 18 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 19 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 20 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 21 | +SOFTWARE. |
node_modules/kitx/README.md
0 → 100644
| 1 | +# kitx | ||
| 2 | +A Node.js toolkit. | ||
| 3 | + | ||
| 4 | +[![NPM version][npm-image]][npm-url] | ||
| 5 | +[![build status][travis-image]][travis-url] | ||
| 6 | +[](https://coveralls.io/github/JacksonTian/kitx?branch=master) | ||
| 7 | +[![David deps][david-image]][david-url] | ||
| 8 | +[![npm download][download-image]][download-url] | ||
| 9 | + | ||
| 10 | +[npm-image]: https://img.shields.io/npm/v/kitx.svg?style=flat-square | ||
| 11 | +[npm-url]: https://npmjs.org/package/kitx | ||
| 12 | +[travis-image]: https://img.shields.io/travis/JacksonTian/kitx.svg?style=flat-square | ||
| 13 | +[travis-url]: https://travis-ci.org/JacksonTian/kitx | ||
| 14 | +[david-image]: https://img.shields.io/david/JacksonTian/kitx.svg?style=flat-square | ||
| 15 | +[david-url]: https://david-dm.org/JacksonTian/kitx | ||
| 16 | +[download-image]: https://img.shields.io/npm/dm/kitx.svg?style=flat-square | ||
| 17 | +[download-url]: https://npmjs.org/package/kitx | ||
| 18 | + | ||
| 19 | +## Installation | ||
| 20 | + | ||
| 21 | +```sh | ||
| 22 | +$ npm install kitx --save | ||
| 23 | +``` | ||
| 24 | + | ||
| 25 | +## Usage | ||
| 26 | + | ||
| 27 | +Require it: | ||
| 28 | + | ||
| 29 | +```js | ||
| 30 | +var kit = require('kitx'); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## API | ||
| 34 | +See [API docs](http://doxmate.cool/JacksonTian/kitx/api.html). | ||
| 35 | + | ||
| 36 | +## License | ||
| 37 | +The MIT license. |
node_modules/kitx/lib/index.js
0 → 100644
| 1 | +'use strict'; | ||
| 2 | + | ||
| 3 | +const fs = require('fs'); | ||
| 4 | +const os = require('os'); | ||
| 5 | +const crypto = require('crypto'); | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * Load *.json file synchronous. Don't use require('*.json') | ||
| 9 | + * to load *.json files, it will cached in process. | ||
| 10 | + * @param {String} filename absolute file path | ||
| 11 | + * @return {Object} a parsed object | ||
| 12 | + */ | ||
| 13 | +exports.loadJSONSync = function (filename) { | ||
| 14 | + // strip BOM | ||
| 15 | + var content = fs.readFileSync(filename, 'utf8'); | ||
| 16 | + if (content.charCodeAt(0) === 0xFEFF) { | ||
| 17 | + content = content.slice(1); | ||
| 18 | + } | ||
| 19 | + try { | ||
| 20 | + return JSON.parse(content); | ||
| 21 | + } catch (err) { | ||
| 22 | + err.message = filename + ': ' + err.message; | ||
| 23 | + throw err; | ||
| 24 | + } | ||
| 25 | +}; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * Encoding a string to Buffer safely | ||
| 29 | + * @param {String} str string. | ||
| 30 | + * @param {String} encoding. optional. | ||
| 31 | + * @return {Buffer} encoded buffer | ||
| 32 | + */ | ||
| 33 | +exports.encode = function (str, encoding) { | ||
| 34 | + if (typeof str !== 'string') { | ||
| 35 | + str = '' + str; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + return new Buffer(str, encoding); | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * Generate a haser with specfied algorithm | ||
| 43 | + * @param {String} algorithm can be md5, etc. | ||
| 44 | + * @return {Function} a haser with specfied algorithm | ||
| 45 | + */ | ||
| 46 | +exports.makeHasher = function (algorithm) { | ||
| 47 | + return function (data, encoding) { | ||
| 48 | + var shasum = crypto.createHash(algorithm); | ||
| 49 | + shasum.update(data); | ||
| 50 | + return shasum.digest(encoding); | ||
| 51 | + }; | ||
| 52 | +}; | ||
| 53 | + | ||
| 54 | +exports.createHash = exports.makeHasher; | ||
| 55 | + | ||
| 56 | +/** | ||
| 57 | + * Get md5 hash digests of data | ||
| 58 | + * @param {String|Buffer} data data. | ||
| 59 | + * @param {String} encoding optionnal. can be 'hex', 'binary', 'base64'. | ||
| 60 | + * @return {String|Buffer} if no encoding is provided, a buffer is returned. | ||
| 61 | + */ | ||
| 62 | +exports.md5 = exports.makeHasher('md5'); | ||
| 63 | + | ||
| 64 | +/** | ||
| 65 | + * Get sha1 hash digests of data | ||
| 66 | + * @param {String|Buffer} data data. | ||
| 67 | + * @param {String} key the key. | ||
| 68 | + * @param {String} encoding optionnal. can be 'hex', 'binary', 'base64'. | ||
| 69 | + * @return {String|Buffer} if no encoding is provided, a buffer is returned. | ||
| 70 | + */ | ||
| 71 | +exports.createHmac = function (algorithm) { | ||
| 72 | + return function (data, key, encoding) { | ||
| 73 | + return crypto.createHmac(algorithm, key).update(data).digest(encoding); | ||
| 74 | + }; | ||
| 75 | +}; | ||
| 76 | + | ||
| 77 | +/** | ||
| 78 | + * Get sha1 hash digests of data | ||
| 79 | + * @param {String|Buffer} data data. | ||
| 80 | + * @param {String} key the key. | ||
| 81 | + * @param {String} encoding optionnal. can be 'hex', 'binary', 'base64'. | ||
| 82 | + * @return {String|Buffer} if no encoding is provided, a buffer is returned. | ||
| 83 | + */ | ||
| 84 | +exports.sha1 = exports.createHmac('sha1'); | ||
| 85 | + | ||
| 86 | +/** | ||
| 87 | + * Get a random value in a range | ||
| 88 | + * @param {Number} min range start. | ||
| 89 | + * @param {Number} max range end. | ||
| 90 | + */ | ||
| 91 | +exports.random = function (min, max) { | ||
| 92 | + return Math.floor(min + Math.random() * (max - min)); | ||
| 93 | +}; | ||
| 94 | + | ||
| 95 | +/** | ||
| 96 | + * Generate a nonce string | ||
| 97 | + * @return {String} a nonce string. | ||
| 98 | + */ | ||
| 99 | +exports.makeNonce = (function() { | ||
| 100 | + var counter = 0; | ||
| 101 | + var last; | ||
| 102 | + const machine = os.hostname(); | ||
| 103 | + const pid = process.pid; | ||
| 104 | + | ||
| 105 | + return function () { | ||
| 106 | + var val = Math.floor(Math.random() * 1000000000000); | ||
| 107 | + if (val === last) { | ||
| 108 | + counter++; | ||
| 109 | + } else { | ||
| 110 | + counter = 0; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + last = val; | ||
| 114 | + | ||
| 115 | + var uid = `${machine}${pid}${val}${counter}`; | ||
| 116 | + return exports.md5(uid, 'hex'); | ||
| 117 | + }; | ||
| 118 | +}()); | ||
| 119 | + | ||
| 120 | +/** | ||
| 121 | + * Pad a number as \d\d format | ||
| 122 | + * @param {Number} num a number that less than 100. | ||
| 123 | + * @return {String} if number less than 10, pad with 0, | ||
| 124 | + * otherwise, returns string of number. | ||
| 125 | + */ | ||
| 126 | +exports.pad2 = function (num) { | ||
| 127 | + if (num < 10) { | ||
| 128 | + return '0' + num; | ||
| 129 | + } | ||
| 130 | + return '' + num; | ||
| 131 | +}; | ||
| 132 | + | ||
| 133 | +/** | ||
| 134 | + * Pad a number as \d\d\d format | ||
| 135 | + * @param {Number} num a number that less than 1000. | ||
| 136 | + * @return {String} if number less than 100, pad with 0, | ||
| 137 | + * otherwise, returns string of number. | ||
| 138 | + */ | ||
| 139 | +exports.pad3 = function (num) { | ||
| 140 | + if (num < 10) { | ||
| 141 | + return '00' + num; | ||
| 142 | + } else if (num < 100) { | ||
| 143 | + return '0' + num; | ||
| 144 | + } | ||
| 145 | + return '' + num; | ||
| 146 | +}; | ||
| 147 | + | ||
| 148 | +/** | ||
| 149 | + * Return the YYYYMMDD format of a date. | ||
| 150 | + * @param {Date} date a Date object. | ||
| 151 | + * @return {String} the YYYYMMDD format. | ||
| 152 | + */ | ||
| 153 | +exports.getYYYYMMDD = function (date) { | ||
| 154 | + var YYYY = date.getFullYear(); | ||
| 155 | + var MM = exports.pad2(date.getMonth() + 1); | ||
| 156 | + var DD = exports.pad2(date.getDate()); | ||
| 157 | + return '' + YYYY + MM + DD; | ||
| 158 | +}; | ||
| 159 | + | ||
| 160 | +/** | ||
| 161 | + * sleep a while. | ||
| 162 | + * @param {Number} in milliseconds | ||
| 163 | + * @return {Promise} a Promise | ||
| 164 | + */ | ||
| 165 | +exports.sleep = function (ms) { | ||
| 166 | + return new Promise((resolve) => { | ||
| 167 | + setTimeout(resolve, ms); | ||
| 168 | + }); | ||
| 169 | +}; | ||
| 170 | + | ||
| 171 | +/** | ||
| 172 | + * Get the IPv4 address | ||
| 173 | + * @return {String} the IPv4 address, or empty string | ||
| 174 | + */ | ||
| 175 | +exports.getIPv4 = function () { | ||
| 176 | + var interfaces = os.networkInterfaces(); | ||
| 177 | + var keys = Object.keys(interfaces); | ||
| 178 | + for (var i = 0; i < keys.length; i++) { | ||
| 179 | + var key = keys[i]; | ||
| 180 | + var addresses = interfaces[key]; | ||
| 181 | + for (var j = 0; j < addresses.length; j++) { | ||
| 182 | + var item = addresses[j]; | ||
| 183 | + if (!item.internal && item.family === 'IPv4') { | ||
| 184 | + return item.address; | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + // without non-internal address | ||
| 190 | + return ''; | ||
| 191 | +}; | ||
| 192 | + | ||
| 193 | +/** | ||
| 194 | + * Get the Mac address | ||
| 195 | + * @return {String} the Mac address | ||
| 196 | + */ | ||
| 197 | +exports.getMac = function () { | ||
| 198 | + var interfaces = os.networkInterfaces(); | ||
| 199 | + var keys = Object.keys(interfaces); | ||
| 200 | + for (var i = 0; i < keys.length; i++) { | ||
| 201 | + var key = keys[i]; | ||
| 202 | + var addresses = interfaces[key]; | ||
| 203 | + for (var j = 0; j < addresses.length; j++) { | ||
| 204 | + var item = addresses[j]; | ||
| 205 | + if (!item.internal && item.family === 'IPv4') { | ||
| 206 | + return item.mac; | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + // without non-internal address | ||
| 212 | + return '00:00:00:00:00:00'; | ||
| 213 | +}; |
node_modules/kitx/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "_args": [ | ||
| 3 | + [ | ||
| 4 | + { | ||
| 5 | + "raw": "kitx@^1.2.1", | ||
| 6 | + "scope": null, | ||
| 7 | + "escapedName": "kitx", | ||
| 8 | + "name": "kitx", | ||
| 9 | + "rawSpec": "^1.2.1", | ||
| 10 | + "spec": ">=1.2.1 <2.0.0", | ||
| 11 | + "type": "range" | ||
| 12 | + }, | ||
| 13 | + "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core" | ||
| 14 | + ] | ||
| 15 | + ], | ||
| 16 | + "_from": "kitx@>=1.2.1 <2.0.0", | ||
| 17 | + "_id": "kitx@1.3.0", | ||
| 18 | + "_inCache": true, | ||
| 19 | + "_location": "/kitx", | ||
| 20 | + "_nodeVersion": "8.4.0", | ||
| 21 | + "_npmOperationalInternal": { | ||
| 22 | + "host": "s3://npm-registry-packages", | ||
| 23 | + "tmp": "tmp/kitx-1.3.0.tgz_1505918631177_0.661639561643824" | ||
| 24 | + }, | ||
| 25 | + "_npmUser": { | ||
| 26 | + "name": "jacksontian", | ||
| 27 | + "email": "shyvo1987@gmail.com" | ||
| 28 | + }, | ||
| 29 | + "_npmVersion": "5.3.0", | ||
| 30 | + "_phantomChildren": {}, | ||
| 31 | + "_requested": { | ||
| 32 | + "raw": "kitx@^1.2.1", | ||
| 33 | + "scope": null, | ||
| 34 | + "escapedName": "kitx", | ||
| 35 | + "name": "kitx", | ||
| 36 | + "rawSpec": "^1.2.1", | ||
| 37 | + "spec": ">=1.2.1 <2.0.0", | ||
| 38 | + "type": "range" | ||
| 39 | + }, | ||
| 40 | + "_requiredBy": [ | ||
| 41 | + "/@alicloud/mns", | ||
| 42 | + "/@alicloud/pop-core" | ||
| 43 | + ], | ||
| 44 | + "_resolved": "https://registry.npmjs.org/kitx/-/kitx-1.3.0.tgz", | ||
| 45 | + "_shasum": "ab3ee7c598d2b1d629fd55568f868c4440c200ea", | ||
| 46 | + "_shrinkwrap": null, | ||
| 47 | + "_spec": "kitx@^1.2.1", | ||
| 48 | + "_where": "/Users/fzy/project/koa2_Sequelize_project/node_modules/@alicloud/pop-core", | ||
| 49 | + "author": { | ||
| 50 | + "name": "Jackson Tian" | ||
| 51 | + }, | ||
| 52 | + "bugs": { | ||
| 53 | + "url": "https://github.com/JacksonTian/kitx/issues" | ||
| 54 | + }, | ||
| 55 | + "dependencies": {}, | ||
| 56 | + "description": "toolkit", | ||
| 57 | + "devDependencies": { | ||
| 58 | + "co-mocha": "~1.1.2", | ||
| 59 | + "coveralls": "~2.11.9", | ||
| 60 | + "expect.js": "~0.3.1", | ||
| 61 | + "istanbul": "~0.4.2", | ||
| 62 | + "mocha": "^3.4.2" | ||
| 63 | + }, | ||
| 64 | + "directories": { | ||
| 65 | + "test": "test" | ||
| 66 | + }, | ||
| 67 | + "dist": { | ||
| 68 | + "integrity": "sha512-fhBqFlXd0GkKTB+8ayLfpzPUw+LHxZlPAukPNBD1Om7JMeInT+/PxCAf1yLagvD+VKoyWhXtJR68xQkX/a0wOQ==", | ||
| 69 | + "shasum": "ab3ee7c598d2b1d629fd55568f868c4440c200ea", | ||
| 70 | + "tarball": "https://registry.npmjs.org/kitx/-/kitx-1.3.0.tgz" | ||
| 71 | + }, | ||
| 72 | + "files": [ | ||
| 73 | + "lib" | ||
| 74 | + ], | ||
| 75 | + "gitHead": "8c57ced8d32ad3ba7db407d5f348cfbdba777b8d", | ||
| 76 | + "homepage": "https://github.com/JacksonTian/kitx#readme", | ||
| 77 | + "keywords": [ | ||
| 78 | + "toolkit", | ||
| 79 | + "kit" | ||
| 80 | + ], | ||
| 81 | + "license": "MIT", | ||
| 82 | + "main": "lib/index.js", | ||
| 83 | + "maintainers": [ | ||
| 84 | + { | ||
| 85 | + "name": "jacksontian", | ||
| 86 | + "email": "shyvo1987@gmail.com" | ||
| 87 | + } | ||
| 88 | + ], | ||
| 89 | + "name": "kitx", | ||
| 90 | + "optionalDependencies": {}, | ||
| 91 | + "readme": "# kitx\nA Node.js toolkit.\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[](https://coveralls.io/github/JacksonTian/kitx?branch=master)\n[![David deps][david-image]][david-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/kitx.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/kitx\n[travis-image]: https://img.shields.io/travis/JacksonTian/kitx.svg?style=flat-square\n[travis-url]: https://travis-ci.org/JacksonTian/kitx\n[david-image]: https://img.shields.io/david/JacksonTian/kitx.svg?style=flat-square\n[david-url]: https://david-dm.org/JacksonTian/kitx\n[download-image]: https://img.shields.io/npm/dm/kitx.svg?style=flat-square\n[download-url]: https://npmjs.org/package/kitx\n\n## Installation\n\n```sh\n$ npm install kitx --save\n```\n\n## Usage\n\nRequire it:\n\n```js\nvar kit = require('kitx');\n```\n\n## API\nSee [API docs](http://doxmate.cool/JacksonTian/kitx/api.html).\n\n## License\nThe MIT license.\n", | ||
| 92 | + "readmeFilename": "README.md", | ||
| 93 | + "repository": { | ||
| 94 | + "type": "git", | ||
| 95 | + "url": "git+https://github.com/JacksonTian/kitx.git" | ||
| 96 | + }, | ||
| 97 | + "scripts": { | ||
| 98 | + "test": "make test" | ||
| 99 | + }, | ||
| 100 | + "version": "1.3.0" | ||
| 101 | +} |
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | "test": "echo \"Error: no test specified\" && exit 1" | 9 | "test": "echo \"Error: no test specified\" && exit 1" |
| 10 | }, | 10 | }, |
| 11 | "dependencies": { | 11 | "dependencies": { |
| 12 | + "@alicloud/sms-sdk": "^1.0.2", | ||
| 12 | "co-busboy": "^1.3.1", | 13 | "co-busboy": "^1.3.1", |
| 13 | "debug": "^2.6.3", | 14 | "debug": "^2.6.3", |
| 14 | "filepreview": "^1.0.14", | 15 | "filepreview": "^1.0.14", |
| 1 | const router = require('koa-router')() | 1 | const router = require('koa-router')() |
| 2 | var status = require('../util/resTemplate') | 2 | var status = require('../util/resTemplate') |
| 3 | const emailUtil = require('../util/emailUtil') | 3 | const emailUtil = require('../util/emailUtil') |
| 4 | +const sendMessageUtil = require('../util/sendMessageUtil') | ||
| 4 | 5 | ||
| 5 | router.prefix('/email') | 6 | router.prefix('/email') |
| 6 | 7 | ||
| @@ -19,5 +20,18 @@ router.post('/sendEmail', async (ctx, next) => { | @@ -19,5 +20,18 @@ router.post('/sendEmail', async (ctx, next) => { | ||
| 19 | status.catchError(ctx,400,e.message); | 20 | status.catchError(ctx,400,e.message); |
| 20 | } | 21 | } |
| 21 | }) | 22 | }) |
| 23 | +router.post('/sendMessage', async (ctx, next) => { | ||
| 24 | + try{ | ||
| 25 | + var body = ctx.request.body; | ||
| 26 | + let back = await sendMessageUtil.sendMessage(body.Email,null, body.userName+body.phone+body.company+body.landline+body.ip) | ||
| 27 | + ctx.response.status= 200; | ||
| 28 | + ctx.response.body= { | ||
| 29 | + msg:'发送成功' | ||
| 30 | + }; | ||
| 31 | + }catch(e){ | ||
| 32 | + console.error(e) | ||
| 33 | + status.catchError(ctx,400,e.message); | ||
| 34 | + } | ||
| 35 | +}) | ||
| 22 | 36 | ||
| 23 | - module.exports = router; | ||
| 37 | +module.exports = router; |
| @@ -53,16 +53,18 @@ recordInfoService.prototype.getRecordFileURL = async(path,time)=>{ | @@ -53,16 +53,18 @@ recordInfoService.prototype.getRecordFileURL = async(path,time)=>{ | ||
| 53 | var backFile=[]; | 53 | var backFile=[]; |
| 54 | var fileU | 54 | var fileU |
| 55 | let addrecord = await recordInfo.findAll({where:{channel:path}}); | 55 | let addrecord = await recordInfo.findAll({where:{channel:path}}); |
| 56 | - console.log('录制文件',addrecord) | ||
| 57 | let noFile = []; | 56 | let noFile = []; |
| 58 | var allFile = []; | 57 | var allFile = []; |
| 58 | + let date1 = '' | ||
| 59 | var channefiles = ''; | 59 | var channefiles = ''; |
| 60 | addrecord.forEach(function(record,top){ | 60 | addrecord.forEach(function(record,top){ |
| 61 | - let date1 = moment(Number( record.createTime)).format('YYYYMMDD') | ||
| 62 | let date2 = moment(Number(record.createTime)-8*60*60*1000).format('YYYYMMDDhhmmss') | 61 | let date2 = moment(Number(record.createTime)-8*60*60*1000).format('YYYYMMDDhhmmss') |
| 63 | let channeFile = onlinePath+date1; | 62 | let channeFile = onlinePath+date1; |
| 64 | var fschannefiles=fs.readdirSync(channeFile); | 63 | var fschannefiles=fs.readdirSync(channeFile); |
| 65 | - | 64 | + if(top == 0){ |
| 65 | + date1 = moment(Number( record.createTime)).format('YYYYMMDD') | ||
| 66 | + } | ||
| 67 | + console.log(top) | ||
| 66 | fschannefiles.forEach(function(cfile,index){ | 68 | fschannefiles.forEach(function(cfile,index){ |
| 67 | if(record.channel == cfile.split('_')[0]+'_'+cfile.split("_")[1]){ | 69 | if(record.channel == cfile.split('_')[0]+'_'+cfile.split("_")[1]){ |
| 68 | let pathURL = onlinePath+date1+"/"+cfile; | 70 | let pathURL = onlinePath+date1+"/"+cfile; |
util/sendMessageUtil.js
0 → 100644
| 1 | +/** | ||
| 2 | + * 发送短信 | ||
| 3 | + */ | ||
| 4 | +const SMSClient = require('@alicloud/sms-sdk') | ||
| 5 | + | ||
| 6 | +// ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换 | ||
| 7 | +const accessKeyId = 'yourAccessKeyId' | ||
| 8 | +const secretAccessKey = 'yourAccessKeySecret' | ||
| 9 | +//初始化sms_client | ||
| 10 | +let smsClient = new SMSClient({accessKeyId, secretAccessKey}) | ||
| 11 | + | ||
| 12 | +function message(){ | ||
| 13 | + | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +message.prototype.sendMessage = async(recipient, subject, html) => { | ||
| 17 | + try { | ||
| 18 | + let smsData = await smsClient.sendSMS({ | ||
| 19 | + PhoneNumbers: '15314352870', | ||
| 20 | + SignName: '云通信产品', | ||
| 21 | + TemplateCode: 'SMS_000000', | ||
| 22 | + TemplateParam: '{"code":"12345","product":"云通信"}' | ||
| 23 | + }) | ||
| 24 | + console.log(smsData); | ||
| 25 | + } catch (error) { | ||
| 26 | + throw error | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +module.exports = new message(); |
-
请 注册 或 登录 后发表评论