q-koa 7.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/core/app.js +1813 -0
  2. package/core/config.js +124 -0
  3. package/core/file/plugins/administrator/config.js +17 -0
  4. package/core/file/plugins/administrator/controller.js +264 -0
  5. package/core/file/plugins/administrator/model.js +53 -0
  6. package/core/file/plugins/administrator/validate.js +41 -0
  7. package/core/file/plugins/alipay/controller.js +68 -0
  8. package/core/file/plugins/alipay/validate.js +9 -0
  9. package/core/file/plugins/cache/service.js +16 -0
  10. package/core/file/plugins/cloudfunction/config.js +4 -0
  11. package/core/file/plugins/cloudfunction/model.js +15 -0
  12. package/core/file/plugins/common/controller.js +398 -0
  13. package/core/file/plugins/common/validate.js +47 -0
  14. package/core/file/plugins/douyin/config.js +3 -0
  15. package/core/file/plugins/douyin/controller.js +521 -0
  16. package/core/file/plugins/douyin/validate.js +40 -0
  17. package/core/file/plugins/douyin_user/config.js +15 -0
  18. package/core/file/plugins/douyin_user/model.js +72 -0
  19. package/core/file/plugins/good_sku/controller.js +80 -0
  20. package/core/file/plugins/h5_user/config.js +19 -0
  21. package/core/file/plugins/h5_user/model.js +71 -0
  22. package/core/file/plugins/lang/config.js +4 -0
  23. package/core/file/plugins/lang/model.js +15 -0
  24. package/core/file/plugins/language/config.js +5 -0
  25. package/core/file/plugins/language/model.js +54 -0
  26. package/core/file/plugins/log/config.js +25 -0
  27. package/core/file/plugins/log/controller.js +31 -0
  28. package/core/file/plugins/log/model.js +51 -0
  29. package/core/file/plugins/model/config.js +12 -0
  30. package/core/file/plugins/model/controller.js +69 -0
  31. package/core/file/plugins/model/model.js +169 -0
  32. package/core/file/plugins/model/service.js +218 -0
  33. package/core/file/plugins/model/validate.js +42 -0
  34. package/core/file/plugins/model_attributes/config.js +12 -0
  35. package/core/file/plugins/model_attributes/model.js +114 -0
  36. package/core/file/plugins/mp_user/config.js +19 -0
  37. package/core/file/plugins/mp_user/model.js +59 -0
  38. package/core/file/plugins/permission/config.js +15 -0
  39. package/core/file/plugins/permission/model.js +91 -0
  40. package/core/file/plugins/role/config.js +27 -0
  41. package/core/file/plugins/role/controller.js +26 -0
  42. package/core/file/plugins/role/model.js +58 -0
  43. package/core/file/plugins/role_permission/config.js +12 -0
  44. package/core/file/plugins/role_permission/controller.js +27 -0
  45. package/core/file/plugins/role_permission/model.js +24 -0
  46. package/core/file/plugins/routes/config.js +17 -0
  47. package/core/file/plugins/routes/controller.js +153 -0
  48. package/core/file/plugins/routes/model.js +70 -0
  49. package/core/file/plugins/routes/service.js +22 -0
  50. package/core/file/plugins/setting/afterExecute.js +14 -0
  51. package/core/file/plugins/setting/config.js +14 -0
  52. package/core/file/plugins/setting/controller.js +50 -0
  53. package/core/file/plugins/setting/model.js +118 -0
  54. package/core/file/plugins/setting/validate.js +42 -0
  55. package/core/file/plugins/system/controller.js +501 -0
  56. package/core/file/plugins/system/service.js +148 -0
  57. package/core/file/plugins/system/validate.js +40 -0
  58. package/core/file/plugins/todolist/config.js +31 -0
  59. package/core/file/plugins/todolist/model.js +69 -0
  60. package/core/file/plugins/toutiao/controller.js +201 -0
  61. package/core/file/plugins/toutiao_user/config.js +15 -0
  62. package/core/file/plugins/toutiao_user/model.js +66 -0
  63. package/core/file/plugins/user/afterExecute.js +38 -0
  64. package/core/file/plugins/user/config.js +9 -0
  65. package/core/file/plugins/user/controller.js +329 -0
  66. package/core/file/plugins/user/model.js +96 -0
  67. package/core/file/plugins/user/test.js +71 -0
  68. package/core/file/plugins/user/validate.js +44 -0
  69. package/core/file/plugins/video/config.js +3 -0
  70. package/core/file/plugins/video/controller.js +15 -0
  71. package/core/file/plugins/video/validate.js +12 -0
  72. package/core/file/plugins/weixin/config.js +3 -0
  73. package/core/file/plugins/weixin/controller.js +994 -0
  74. package/core/file/plugins/weixin/service.js +105 -0
  75. package/core/file/plugins/weixin/validate.js +111 -0
  76. package/core/file/services/aliSms.js +45 -0
  77. package/core/file/services/alipay.js +123 -0
  78. package/core/file/services/amap.js +95 -0
  79. package/core/file/services/card.js +24 -0
  80. package/core/file/services/config.js +38 -0
  81. package/core/file/services/douyin.js +151 -0
  82. package/core/file/services/email.js +45 -0
  83. package/core/file/services/express.js +37 -0
  84. package/core/file/services/geo.js +71 -0
  85. package/core/file/services/qqVideo.js +64 -0
  86. package/core/file/services/toutiao.js +102 -0
  87. package/core/file/services/weixin.js +79 -0
  88. package/core/file/services/weixinArticle.js +53 -0
  89. package/core/file/services/weixinCrypt.js +34 -0
  90. package/core/file/services/weixinMP.js +435 -0
  91. package/core/file/services/weixinPay.js +35 -0
  92. package/core/file/services/xml.js +33 -0
  93. package/core/file/task/shop/index.js +589 -0
  94. package/core/file/task/shop/static/562e45760a44632de6fa7219bab78cce.png +0 -0
  95. package/core/file/task/shop/static/d7aeaeb6bfd68f71a00a83c0f5548363.png +0 -0
  96. package/core/file/utils/index.js +61 -0
  97. package/core/middlewares.js +120 -0
  98. package/core/restc/.npminstall.done +1 -0
  99. package/core/restc/LICENSE +21 -0
  100. package/core/restc/README.md +48 -0
  101. package/core/restc/faas/index.html +1112 -0
  102. package/core/restc/faas/index.txt +31 -0
  103. package/core/restc/faas/install_production.sh +6 -0
  104. package/core/restc/index.d.ts +7 -0
  105. package/core/restc/index.js +9 -0
  106. package/core/restc/lib/express.js +7 -0
  107. package/core/restc/lib/hapi.js +17 -0
  108. package/core/restc/lib/hapiLegacy.js +15 -0
  109. package/core/restc/lib/index.js +46 -0
  110. package/core/restc/lib/koa.js +9 -0
  111. package/core/restc/lib/koa2.js +9 -0
  112. package/core/restc/lib/utils/gateway.js +51 -0
  113. package/core/restc/package.json +41 -0
  114. package/core/validator.js +15 -0
  115. package/index.js +1 -0
  116. package/package.json +65 -0
@@ -0,0 +1,31 @@
1
+ Frame
2
+ Header
3
+ Logo
4
+ SideBarToggleButton
5
+ Main
6
+ ResultView
7
+ ResponseView
8
+ HighlightBlock
9
+ RequestView
10
+ HighlightBlock
11
+ SideBar
12
+ SideBarMethod
13
+ SideBarMethodSelect
14
+ SideBarQueryStringInput : SideBarInput
15
+ SideBarSendButton
16
+ SideBarKeyValueCollection
17
+ SideBarBodyEditor
18
+ SideBarHeaderCollection : SideBarKeyValueCollection
19
+
20
+ SideBarKeyValueCollection
21
+ SideBarKeyValueAdd
22
+ SideBarKeyValuePair
23
+ SideBarKeyValuePairCheckBox
24
+ SideBarKeyValuePairInput : SideBarInput
25
+ SideBarKeyValuePairInput : SideBarInput
26
+
27
+ Configuration
28
+
29
+ QueryString
30
+
31
+ loader
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ grep --text -Pzo "<script extract>\s*\K([\s\S]+?)(?=\s*</script>)" index.html | tr '\0' '\n' > index.js
4
+ hash=$(md5sum index.js | cut -c 1-5)
5
+ mv index.js index-$hash.js
6
+ sed -i "/<script extract>/{:b;$!N;/<\/script>/!bb;s/.*/<script src=\"https:\/\/shadow.elemecdn.com\/faas\/restc\/index-$hash.js\"><\/script>/}" index.html
@@ -0,0 +1,7 @@
1
+ declare module "restc" {
2
+ export function koa2(): () => any;
3
+ export function koa(): () => any;
4
+ export function express(): () => any;
5
+ export function hapi(): () => any;
6
+ export function hapiLegacy(): () => any;
7
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const express = require('./lib/express')
4
+ const koa = require('./lib/koa')
5
+ const koa2 = require('./lib/koa2')
6
+ const hapi = require('./lib/hapi')
7
+ const hapiLegacy = require('./lib/hapiLegacy')
8
+
9
+ module.exports = { express, koa, koa2, hapi, hapiLegacy }
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const serve = require('.')
4
+
5
+ module.exports = options => (req, res, next) => {
6
+ serve(options)(req, res) || next()
7
+ }
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+ const serve = require('.')
3
+
4
+ const restcPlugin = {
5
+ name: 'restcPlugin',
6
+ version: '1.0.0',
7
+ register: async function (server, options) {
8
+ server.ext('onPreResponse', (request, reply) => {
9
+ return new Promise((resolve, reject) => {
10
+ if (!serve(options)(request.raw.req, request.raw.res)) {
11
+ resolve(reply.continue)
12
+ }
13
+ })
14
+ })
15
+ }
16
+ }
17
+ exports.plugin = restcPlugin
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+ const serve = require('.')
3
+
4
+ exports.register = function (server, options, next) {
5
+ server.ext('onPreResponse', (request, reply) => {
6
+ if (!serve(options)(request.raw.req, request.raw.res)) {
7
+ reply.continue()
8
+ }
9
+ })
10
+ return next()
11
+ }
12
+ exports.register.attributes = {
13
+ name: 'restcPlugin',
14
+ version: '1.0.0'
15
+ }
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const Gateway = require('./utils/gateway.js')
6
+
7
+ const content = fs.readFileSync(path.join(__dirname, '../faas/index.html'), 'utf-8')
8
+
9
+ const cache = new WeakMap()
10
+
11
+ module.exports = function (options = {}) {
12
+ if (cache.has(options)) {
13
+ return cache.get(options)
14
+ }
15
+
16
+ const { includes, excludes, shouldHandle } = options
17
+ const gateway = new Gateway({ includes, excludes, shouldHandle })
18
+ const handler = function (req, res) {
19
+ // set vary header for every response
20
+ res.setHeader('Vary', 'Accept, Origin')
21
+
22
+ // return if it is a cross-origin request
23
+ if ('origin' in req.headers) {
24
+ return false
25
+ }
26
+
27
+ // return if the client does not prefer text/html
28
+ let accept = req.headers.accept || ''
29
+ if (!/^text\/html(?:,|$)/.test(accept)) {
30
+ return false
31
+ }
32
+
33
+ // feed the request to the gateway
34
+ if (!gateway.shouldHandle(req)) {
35
+ return false
36
+ }
37
+
38
+ // serve restc
39
+ res.end(content)
40
+
41
+ return true
42
+ }
43
+
44
+ cache.set(options, handler)
45
+ return handler
46
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const serve = require('.')
4
+
5
+ module.exports = options => function * (next) {
6
+ if (!serve(options)(this.req, this.res)) {
7
+ yield next
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const serve = require('.')
4
+
5
+ module.exports = options => (ctx, next) => {
6
+ if (!serve(options)(ctx.req, ctx.res)) {
7
+ return next()
8
+ }
9
+ }
@@ -0,0 +1,51 @@
1
+ 'use strict'
2
+
3
+ function Gateway (options) {
4
+ options = options || {}
5
+ let includes = options.includes
6
+ let excludes = options.excludes
7
+ const shouldHandle = options.shouldHandle
8
+
9
+ if (typeof shouldHandle === 'function') {
10
+ Object.defineProperty(this, 'shouldHandle', {
11
+ value: shouldHandle,
12
+ configurable: true
13
+ })
14
+ } else {
15
+ if (includes && !(includes instanceof Array)) {
16
+ includes = [includes]
17
+ }
18
+ if (excludes && !(excludes instanceof Array)) {
19
+ excludes = [excludes]
20
+ }
21
+ this.includes = includes
22
+ this.excludes = excludes
23
+ }
24
+ }
25
+
26
+ Gateway.prototype.shouldHandle = function (req) {
27
+ const test = (url, rule) => {
28
+ switch (true) {
29
+ case typeof rule === 'string':
30
+ rule = rule.replace(/^\/*/, '/')
31
+ return url.indexOf(rule) === 0
32
+ case rule instanceof RegExp:
33
+ return rule.test(url)
34
+ }
35
+ return false
36
+ }
37
+
38
+ const url = req.url
39
+
40
+ if (this.excludes && this.excludes.some(rule => test(url, rule))) {
41
+ return false
42
+ }
43
+
44
+ if (this.includes && this.includes.every(rule => !test(url, rule))) {
45
+ return false
46
+ }
47
+
48
+ return true
49
+ }
50
+
51
+ module.exports = Gateway
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "restc",
3
+ "version": "0.4.0",
4
+ "description": "A server-side middleware to visualize REST requests.",
5
+ "main": "index.js",
6
+ "repository": "https://github.com/ElemeFE/restc.git",
7
+ "license": "MIT",
8
+ "typings": "index.d.ts",
9
+ "files": [
10
+ "lib",
11
+ "faas",
12
+ "index.js",
13
+ "index.d.ts"
14
+ ],
15
+ "scripts": {
16
+ "lint": "eslint .",
17
+ "lint-fix": "eslint --fix .",
18
+ "test": "ava"
19
+ },
20
+ "faas": {
21
+ "domain": "restc",
22
+ "public": "faas",
23
+ "description": "A server-side middleware to visualize REST requests.",
24
+ "author_name": "lujjjh",
25
+ "author_email": "jiahao.lu02@ele.me",
26
+ "notice": [
27
+ "jiahao.lu02@ele.me"
28
+ ]
29
+ },
30
+ "devDependencies": {
31
+ "ava": "^0.22.0",
32
+ "eslint": "^4.2.0",
33
+ "eslint-config-standard": "^10.2.1",
34
+ "eslint-plugin-import": "^2.7.0",
35
+ "eslint-plugin-node": "^5.1.0",
36
+ "eslint-plugin-promise": "^3.5.0",
37
+ "eslint-plugin-standard": "^3.0.1"
38
+ },
39
+ "_from": "restc@0.4.0",
40
+ "_resolved": "https://registry.npm.taobao.org/restc/download/restc-0.4.0.tgz"
41
+ }
@@ -0,0 +1,15 @@
1
+ const { default: Schema } = require('async-validator');
2
+
3
+ module.exports = class Validator {
4
+ constructor(descriptor) {
5
+ this.validator = new Schema(descriptor);
6
+ }
7
+
8
+ async validate(data) {
9
+ try {
10
+ return await this.validator.validate(data);
11
+ } catch (e) {
12
+ throw new Error(e.errors.map(item => `${item.field}:${item.message}`));
13
+ }
14
+ }
15
+ };
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./core/app');
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "q-koa",
3
+ "version": "7.7.2",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "debug": "nodemon app",
8
+ "serve": "pm2 delete all && pm2 start process.json && pm2 log",
9
+ "link": "echo -e 'export PATH=$(npm prefix -g)/bin:$PATH' >> ~/.bashrc && source ~/.bashrc"
10
+ },
11
+ "files": [
12
+ "core",
13
+ "index.js"
14
+ ],
15
+ "keywords": [],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "@sigodenjs/wechatpay": "^2.1.1",
20
+ "ali-oss": "^6.11.2",
21
+ "async-validator": "^3.1.0",
22
+ "axios": "^0.21.1",
23
+ "captchapng": "^0.0.1",
24
+ "chalk": "^3.0.0",
25
+ "cheerio": "^1.0.0-rc.3",
26
+ "consola": "^2.11.3",
27
+ "fast-json-stringify": "^2.7.9",
28
+ "fast-xml-parser": "^3.19.0",
29
+ "fs-extra": "^8.1.0",
30
+ "js-md5": "^0.7.3",
31
+ "jsonwebtoken": "^8.5.1",
32
+ "koa": "^2.13.0",
33
+ "koa-body": "^4.1.1",
34
+ "koa-bodyparser": "^4.3.0",
35
+ "koa-compress": "^3.0.0",
36
+ "koa-easy-ws": "^1.1.3",
37
+ "koa-ratelimit": "^5.0.1",
38
+ "koa-respond": "^2.1.0",
39
+ "koa-router": "^7.4.0",
40
+ "koa-static": "^5.0.0",
41
+ "koa-useragent": "^4.0.0",
42
+ "koa-xml-body": "^2.1.0",
43
+ "lodash": "^4.17.15",
44
+ "lru-cache": "^5.1.1",
45
+ "mockjs": "^1.0.1-beta3",
46
+ "moment": "^2.24.0",
47
+ "mysql2": "^1.7.0",
48
+ "nodemailer": "^6.4.2",
49
+ "ora": "^4.0.3",
50
+ "qr-image": "^3.2.0",
51
+ "sequelize": "^5.21.3",
52
+ "static-koa-router": "^1.0.3",
53
+ "wechat-oauth": "^1.5.0",
54
+ "weixin-pay-for": "^1.0.0",
55
+ "node-uuid": "^1.4.8",
56
+ "sha1": "^1.1.1"
57
+ },
58
+ "devDependencies": {
59
+ "eslint": "^4.19.1",
60
+ "eslint-config-airbnb-base": "^13.2.0",
61
+ "eslint-plugin-import": "^2.18.2",
62
+ "jest": "^24.9.0",
63
+ "ora": "^4.0.3"
64
+ }
65
+ }