-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'egg-mock', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
'webstorm-disable-index', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "eslint-config-egg", | ||
"rules": { | ||
"linebreak-style":"off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
test/fixtures/apps/alicloud-mns-test/logs | ||
test/fixtures/apps/alicloud-mns-test/run | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '8' | ||
install: | ||
- npm i npminstall && npminstall | ||
script: | ||
- npm run ci | ||
after_script: | ||
- npminstall codecov && codecov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# egg-alicloud-mns | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/egg-alicloud-mns.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/egg-alicloud-mns | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-alicloud-mns | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-alicloud-mns?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-alicloud-mns | ||
[snyk-image]: https://snyk.io/test/npm/egg-alicloud-mns/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/egg-alicloud-mns | ||
[download-image]: https://img.shields.io/npm/dm/egg-alicloud-mns.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/egg-alicloud-mns | ||
|
||
<!-- | ||
Description here. | ||
--> | ||
|
||
## [中文说明](https://github.com/jerryhu/egg-alicloud-mns/blob/master/README.zh-CN.md) | ||
|
||
## Install | ||
|
||
```bash | ||
$ npm i egg-alicloud-mns --save | ||
``` | ||
|
||
Alicloud MNS Plugin for egg, support egg application access to Aliyun MNS. | ||
|
||
This plugin is based on [mns-nodejs-sdk](https://github.com/aliyun/mns-nodejs-sdk), | ||
please check the document of mns-nodejs-sdk for API details. | ||
|
||
## Usage | ||
|
||
```js | ||
// {app_root}/config/plugin.js | ||
exports.alicloudMns = { | ||
enable: true, | ||
package: 'egg-alicloud-mns', | ||
}; | ||
``` | ||
|
||
## Configuration | ||
|
||
```js | ||
// {app_root}/config/config.default.js | ||
exports.alicloudMns = { | ||
accountId: '', | ||
accessKeyId: '', | ||
secretAccessKey: '', | ||
region: '', // e.g. 'cn-hangzhou', | ||
secure: true, // use https or http | ||
internal: false, // use internal endpoint | ||
vpc: false, // use vpc endpoint | ||
}; | ||
``` | ||
|
||
See [config/config.default.js](config/config.default.js) for more details. | ||
|
||
|
||
## Questions & Suggestions | ||
|
||
Please open an issue [here](https://github.com/jerryhu/egg-alicloud-mns/issues). | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# egg-alicloud-mns | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![David deps][david-image]][david-url] | ||
[![Known Vulnerabilities][snyk-image]][snyk-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/egg-alicloud-mns.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/egg-alicloud-mns | ||
[travis-image]: https://img.shields.io/travis/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/eggjs/egg-alicloud-mns | ||
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[codecov-url]: https://codecov.io/github/eggjs/egg-alicloud-mns?branch=master | ||
[david-image]: https://img.shields.io/david/eggjs/egg-alicloud-mns.svg?style=flat-square | ||
[david-url]: https://david-dm.org/eggjs/egg-alicloud-mns | ||
[snyk-image]: https://snyk.io/test/npm/egg-alicloud-mns/badge.svg?style=flat-square | ||
[snyk-url]: https://snyk.io/test/npm/egg-alicloud-mns | ||
[download-image]: https://img.shields.io/npm/dm/egg-alicloud-mns.svg?style=flat-square | ||
[download-url]: https://npmjs.org/package/egg-alicloud-mns | ||
|
||
<!-- | ||
Description here. | ||
--> | ||
|
||
## 安装 | ||
|
||
```bash | ||
$ npm i egg-alicloud-mns --save | ||
``` | ||
|
||
阿里云MNS(消息服务)的eggjs插件, 支持eggjs应用访问阿里云的消息服务。 | ||
本插件基于阿里云官方的 [mns-nodejs-sdk](https://github.com/aliyun/mns-nodejs-sdk), SDK使用说明参考[mns-nodejs-sdk](https://github.com/aliyun/mns-nodejs-sdk)文档。 | ||
|
||
## 开启插件 | ||
|
||
```js | ||
// config/plugin.js | ||
exports.alicloudMns = { | ||
enable: true, | ||
package: 'egg-alicloud-mns', | ||
}; | ||
``` | ||
|
||
## 详细配置 | ||
|
||
请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。 | ||
```js | ||
// {app_root}/config/config.default.js | ||
exports.alicloudMns = { | ||
accountId: '', | ||
accessKeyId: '', | ||
secretAccessKey: '', | ||
region: '', // e.g. 'cn-hangzhou', | ||
secure: true, // use https or http | ||
internal: false, // use internal endpoint | ||
vpc: false, // use vpc endpoint | ||
}; | ||
``` | ||
|
||
## 提问交流 | ||
|
||
请到 [egg issues](https://github.com/jerryhu/egg-alicloud-mns/issues) 异步交流。 | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const mns = require('./lib/mns'); | ||
|
||
module.exports = app => { | ||
if (app.config.alicloudMns.agent) mns(app); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
const mns = require('./lib/mns'); | ||
|
||
module.exports = app => { | ||
if (app.config.alicloudMns.app) mns(app); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
environment: | ||
matrix: | ||
- nodejs_version: '8' | ||
- nodejs_version: '9' | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version | ||
- npm i npminstall && node_modules\.bin\npminstall | ||
|
||
test_script: | ||
- node --version | ||
- npm --version | ||
- npm run test | ||
|
||
build: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
exports.alicloudMns = { | ||
app: true, | ||
agent: false, | ||
// accountId: '', | ||
// accessKeyId: '', | ||
// secretAccessKey: '', | ||
// region: '', // e.g. 'cn-hangzhou', | ||
// secure: true, // use https or http | ||
// internal: false, // use internal endpoint | ||
// vpc: false, // use vpc endpoint | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const alicloudMns = require('@alicloud/mns'); | ||
|
||
module.exports = app => { | ||
app.addSingleton('alicloud-mns', createClient); | ||
}; | ||
|
||
function createClient(config) { | ||
assert(config.accountId && config.accessKeyId && config.secretAccessKey && config.region, | ||
`[egg-alicloud-mns] 'accountId: ${config.accountId}', 'accessKeyId: ${config.accessKeyId}', 'secretAccessKey: ${config.secretAccessKey}', 'region: ${config.region}' are required on config`); | ||
|
||
let secure = config.secure; | ||
if (!secure || typeof secure !== 'boolean') { | ||
secure = true; | ||
} | ||
let internal = config.internal; | ||
if (!internal || typeof internal !== 'boolean') { | ||
internal = false; | ||
} | ||
let vpc = config.vpc; | ||
if (!vpc || typeof vpc !== 'boolean') { | ||
vpc = false; | ||
} | ||
|
||
return new alicloudMns(config.accountId, { | ||
region: config.region, | ||
accessKeyId: config.accessKeyId, | ||
accessKeySecret: config.secretAccessKey, | ||
// optional & default | ||
secure, // use https or http | ||
internal, // use internal endpoint | ||
vpc, // use vpc endpoint | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "egg-alicloud-mns", | ||
"version": "1.0.0", | ||
"description": "Alicloud MNS plugin for egg", | ||
"eggPlugin": { | ||
"name": "alicloudMns" | ||
}, | ||
"keywords": [ | ||
"egg", | ||
"eggPlugin", | ||
"egg-plugin" | ||
], | ||
"dependencies": { | ||
"@alicloud/mns": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"autod": "^3.0.0", | ||
"autod-egg": "^1.0.0", | ||
"egg": "^2.0.0", | ||
"egg-bin": "^4.3.0", | ||
"egg-ci": "^1.8.0", | ||
"egg-mock": "^3.13.0", | ||
"eslint": "^4.11.0", | ||
"eslint-config-egg": "^5.1.0", | ||
"webstorm-disable-index": "^1.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"scripts": { | ||
"test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local", | ||
"test-local": "egg-bin test", | ||
"cov": "egg-bin cov", | ||
"lint": "eslint .", | ||
"ci": "egg-bin pkgfiles --check && npm run lint && npm run cov", | ||
"pkgfiles": "egg-bin pkgfiles", | ||
"autod": "autod" | ||
}, | ||
"files": [ | ||
"config", | ||
"agent.js", | ||
"lib", | ||
"app.js" | ||
], | ||
"ci": { | ||
"version": "8, 9" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/eggjs/egg-alicloud-mns.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eggjs/egg/issues" | ||
}, | ||
"homepage": "https://github.com/eggjs/egg-alicloud-mns#readme", | ||
"author": "Jerry Hu", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const mock = require('egg-mock'); | ||
|
||
describe('test/alicloud-mns.test.js', () => { | ||
let app; | ||
before(() => { | ||
app = mock.app({ | ||
baseDir: 'apps/alicloud-mns-test', | ||
}); | ||
return app.ready(); | ||
}); | ||
|
||
after(() => app.close()); | ||
afterEach(mock.restore); | ||
|
||
it('should GET /', () => { | ||
return app.httpRequest() | ||
.get('/') | ||
.expect('hi, alicloudMns') | ||
.expect(200); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
test/fixtures/apps/alicloud-mns-test/app/controller/home.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const Controller = require('egg').Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
this.ctx.body = 'hi, ' + this.app.plugins.alicloudMns.name; | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { router, controller } = app; | ||
|
||
router.get('/', controller.home.index); | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/apps/alicloud-mns-test/config/config.default.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "alicloud-mns-test", | ||
"version": "0.0.1" | ||
} |