deploy.sh 0.2.0 → 2.0.0

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 (147) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +7 -9
  3. package/.github/workflows/ci.yml +48 -0
  4. package/.husky/pre-commit +5 -0
  5. package/{test/fixtures/unknown/.gitkeep → .prettierrc} +0 -0
  6. package/.release-it.json +5 -0
  7. package/CHANGELOG.md +26 -0
  8. package/README.md +5 -6
  9. package/__tests__/fixtures/unknown/.gitkeep +0 -0
  10. package/__tests__/lib/classifier.test.js +49 -0
  11. package/__tests__/lib/helpers/util.test.js +57 -0
  12. package/bin/deploy-delete.js +14 -0
  13. package/bin/deploy-deploy.js +34 -59
  14. package/bin/deploy-list.js +25 -52
  15. package/bin/deploy-login.js +36 -52
  16. package/bin/deploy-logout.js +9 -40
  17. package/bin/deploy-logs.js +22 -48
  18. package/bin/deploy-open.js +14 -37
  19. package/bin/deploy-register.js +37 -50
  20. package/bin/deploy-server.js +8 -5
  21. package/bin/deploy-whoami.js +8 -37
  22. package/bin/deploy.js +145 -19
  23. package/{test/fixtures → examples}/docker/Dockerfile +0 -0
  24. package/examples/docker/index.js +12 -0
  25. package/examples/node/index.js +8 -0
  26. package/{test/fixtures → examples}/node/package.json +0 -0
  27. package/examples/static/index.html +22 -0
  28. package/{test/fixtures → examples}/static/main.css +4 -2
  29. package/examples/static/out.gifcd +0 -0
  30. package/generate-docs.js +55 -0
  31. package/index.js +54 -55
  32. package/jsdoc.json +6 -3
  33. package/lib/classifier.js +24 -17
  34. package/lib/deploy.js +56 -64
  35. package/lib/helpers/cli.js +178 -207
  36. package/lib/helpers/util.js +94 -21
  37. package/lib/models/deployment.js +415 -474
  38. package/lib/models/request.js +77 -66
  39. package/lib/models/user.js +119 -144
  40. package/lib/server.js +187 -97
  41. package/lib/static/not-found.html +30 -0
  42. package/lib/static/page-could-not-load.html +30 -0
  43. package/lib/static/static-server.js +70 -0
  44. package/package.json +47 -34
  45. package/website/README.md +41 -0
  46. package/website/babel.config.js +3 -0
  47. package/website/docs/api/_category_.yml +1 -0
  48. package/website/docs/api/lib/classifier.js.md +11 -0
  49. package/website/docs/api/lib/deploy.js.md +13 -0
  50. package/website/docs/api/lib/helpers/cli.js.md +193 -0
  51. package/website/docs/api/lib/helpers/util.js.md +65 -0
  52. package/website/docs/api/lib/models/deployment.js.md +171 -0
  53. package/website/docs/api/lib/models/request.js.md +67 -0
  54. package/website/docs/api/lib/models/user.js.md +92 -0
  55. package/website/docs/api/lib/server.js.md +0 -0
  56. package/website/docs/api/lib/static/static-server.js.md +0 -0
  57. package/website/docs/intro.md +57 -0
  58. package/website/docusaurus.config.js +82 -0
  59. package/website/package-lock.json +25218 -0
  60. package/website/package.json +39 -0
  61. package/website/sidebars.js +31 -0
  62. package/website/src/components/HomepageFeatures/index.js +79 -0
  63. package/website/src/components/HomepageFeatures/styles.module.css +11 -0
  64. package/website/src/css/custom.css +39 -0
  65. package/website/src/pages/index.js +57 -0
  66. package/website/src/pages/index.module.css +23 -0
  67. package/website/static/.nojekyll +0 -0
  68. package/website/static/example.gif +0 -0
  69. package/website/static/example.mov +0 -0
  70. package/website/static/img/favicon.ico +0 -0
  71. package/website/static/img/intro/deploy.png +0 -0
  72. package/website/static/img/intro/logs.png +0 -0
  73. package/{docs → website/static/img}/logo.png +0 -0
  74. package/{docs → website/static/img}/logo.pxm +0 -0
  75. package/{docs → website/static/img}/logo@2x.png +0 -0
  76. package/.npmignore +0 -9
  77. package/.travis.yml +0 -9
  78. package/TODO.md +0 -12
  79. package/docs/code/classifier.js.html +0 -116
  80. package/docs/code/deploy.js.html +0 -138
  81. package/docs/code/fonts/OpenSans-Bold-webfont.eot +0 -0
  82. package/docs/code/fonts/OpenSans-Bold-webfont.svg +0 -1830
  83. package/docs/code/fonts/OpenSans-Bold-webfont.woff +0 -0
  84. package/docs/code/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  85. package/docs/code/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  86. package/docs/code/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  87. package/docs/code/fonts/OpenSans-Italic-webfont.eot +0 -0
  88. package/docs/code/fonts/OpenSans-Italic-webfont.svg +0 -1830
  89. package/docs/code/fonts/OpenSans-Italic-webfont.woff +0 -0
  90. package/docs/code/fonts/OpenSans-Light-webfont.eot +0 -0
  91. package/docs/code/fonts/OpenSans-Light-webfont.svg +0 -1831
  92. package/docs/code/fonts/OpenSans-Light-webfont.woff +0 -0
  93. package/docs/code/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  94. package/docs/code/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  95. package/docs/code/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  96. package/docs/code/fonts/OpenSans-Regular-webfont.eot +0 -0
  97. package/docs/code/fonts/OpenSans-Regular-webfont.svg +0 -1831
  98. package/docs/code/fonts/OpenSans-Regular-webfont.woff +0 -0
  99. package/docs/code/fonts/OpenSans-Semibold-webfont.eot +0 -0
  100. package/docs/code/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  101. package/docs/code/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  102. package/docs/code/fonts/OpenSans-Semibold-webfont.woff +0 -0
  103. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  104. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  105. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  106. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  107. package/docs/code/global.html +0 -325
  108. package/docs/code/helpers_cli.js.html +0 -351
  109. package/docs/code/helpers_util.js.html +0 -127
  110. package/docs/code/index.html +0 -81
  111. package/docs/code/models_deployment.js.html +0 -593
  112. package/docs/code/models_request.js.html +0 -150
  113. package/docs/code/models_user.js.html +0 -232
  114. package/docs/code/module-lib_classifier.html +0 -246
  115. package/docs/code/module-lib_deploy.html +0 -350
  116. package/docs/code/module-lib_helpers_cli.html +0 -2067
  117. package/docs/code/module-lib_helpers_util.html +0 -608
  118. package/docs/code/module-models_deployment-Deployment.html +0 -359
  119. package/docs/code/module-models_deployment-DeploymentSchema.html +0 -359
  120. package/docs/code/module-models_deployment.Deployment.html +0 -359
  121. package/docs/code/module-models_deployment.html +0 -1851
  122. package/docs/code/module-models_request-Request.html +0 -409
  123. package/docs/code/module-models_request-RequestSchema.html +0 -359
  124. package/docs/code/module-models_request.html +0 -446
  125. package/docs/code/module-models_user-User.html +0 -306
  126. package/docs/code/module-models_user-UserSchema.html +0 -306
  127. package/docs/code/module-models_user.User.html +0 -306
  128. package/docs/code/module-models_user.html +0 -1200
  129. package/docs/code/scripts/linenumber.js +0 -25
  130. package/docs/code/scripts/prettify/Apache-License-2.0.txt +0 -202
  131. package/docs/code/scripts/prettify/lang-css.js +0 -2
  132. package/docs/code/scripts/prettify/prettify.js +0 -28
  133. package/docs/code/styles/jsdoc-default.css +0 -692
  134. package/docs/code/styles/prettify-jsdoc.css +0 -111
  135. package/docs/code/styles/prettify-tomorrow.css +0 -132
  136. package/docs/example-docker.gif +0 -0
  137. package/docs/example-node.gif +0 -0
  138. package/docs/example-static.gif +0 -0
  139. package/docs/index.html +0 -50
  140. package/docs/main.css +0 -12
  141. package/docs/psychic-min.css +0 -1
  142. package/lib/helpers/static-server.js +0 -69
  143. package/test/fixtures/docker/index.js +0 -12
  144. package/test/fixtures/node/index.js +0 -8
  145. package/test/fixtures/static/index.html +0 -14
  146. package/test/lib/classifier.js +0 -51
  147. package/test/lib/helpers/util.js +0 -30
@@ -1,31 +1,32 @@
1
- /**
2
- * @module models/request
3
- */
4
-
5
- const mongoose = require('mongoose');
1
+ import mongoose from "mongoose";
6
2
 
7
3
  const Schema = mongoose.Schema;
8
4
 
9
- const RequestSchema = new Schema({
10
- url: String,
11
- time: Number,
12
- subdomain: String,
13
- statusCode: String,
14
- userAgent: String,
15
- referer: String,
16
- method: String,
17
- acceptLanguage: String
18
- }, {
19
- minimize: false,
20
- timestamps: {
21
- createdAt: 'created_at',
22
- updatedAt: 'updated_at'
5
+ const RequestSchema = new Schema(
6
+ {
7
+ url: String,
8
+ time: Number,
9
+ subdomain: String,
10
+ statusCode: String,
11
+ userAgent: String,
12
+ referer: String,
13
+ method: String,
14
+ acceptLanguage: String,
15
+ },
16
+ {
17
+ minimize: false,
18
+ timestamps: {
19
+ createdAt: "created_at",
20
+ updatedAt: "updated_at",
21
+ },
23
22
  }
24
- });
23
+ );
24
+
25
+ const RequestModel = mongoose.model("Request", RequestSchema);
25
26
 
26
27
  /**
27
28
  * Request definition
28
- * @class {Object} Request
29
+ * @class Request
29
30
  * @property {String} subdomain - the subdomain of the request
30
31
  * @property {String} url - the url that was being accessed
31
32
  * @property {Number} time - the time it took to access the resource
@@ -35,56 +36,66 @@ const RequestSchema = new Schema({
35
36
  * @property {String} referer - the referer that the user was at before accessing the address
36
37
  * @property {String} acceptLanguage - browser based language preferences
37
38
  */
38
- const Request = mongoose.model('Request', RequestSchema);
39
+ class Request {
40
+ /**
41
+ * express middleware that logs requests
42
+ * @method log
43
+ * @memberof Request
44
+ * @param {Object} req - express request object
45
+ * @param {Object} res - express response object
46
+ * @param {Function} next - callback function
47
+ */
48
+ static log(req, res, next) {
49
+ const { url, headers, method } = req;
50
+ const { host } = headers;
39
51
 
40
- /**
41
- * express middleware that logs requests
42
- * @method log
43
- * @param {Object} req - express request object
44
- * @param {Object} res - express response object
45
- * @param {Function} next - callback function
46
- */
47
- module.exports.log = function log(req, res, next) {
48
- const { url, headers, method } = req;
49
- const { host } = headers;
52
+ const subdomain = host.split(".")[0];
53
+ const startAt = process.hrtime();
50
54
 
51
- const subdomain = host.split('.')[0];
52
- const startAt = process.hrtime();
55
+ res.on("finish", () => {
56
+ const diff = process.hrtime(startAt);
57
+ const time = diff[0] * 1e3 + diff[1] * 1e-6;
53
58
 
54
- res.on('finish', () => {
55
- const diff = process.hrtime(startAt);
56
- const time = diff[0] * 1e3 + diff[1] * 1e-6;
59
+ const { statusCode } = res;
57
60
 
58
- const { statusCode } = res;
61
+ RequestModel.create({
62
+ url,
63
+ time,
64
+ subdomain,
65
+ method,
66
+ statusCode,
67
+ userAgent: headers["user-agent"],
68
+ referer: headers["referer"],
69
+ acceptLanguage: headers["accept-language"],
70
+ });
71
+ });
59
72
 
60
- Request.create({
61
- url,
62
- time,
73
+ next();
74
+ }
75
+ /**
76
+ * returns the amount of requests for the specified subdomain
77
+ * @method count
78
+ * @memberof Request
79
+ * @param {string} subdomain - the subdomain of which to get the count of requests for
80
+ * @return {Promise}
81
+ */
82
+ static async count({ subdomain }) {
83
+ return await RequestModel.count({
63
84
  subdomain,
64
- method,
65
- statusCode,
66
- userAgent: headers['user-agent'],
67
- referer: headers['referer'],
68
- acceptLanguage: headers['accept-language']
69
85
  });
70
- });
71
-
72
- next();
73
- };
74
-
75
- /**
76
- * returns the amount of requests for the specified subdomain
77
- * @method count
78
- * @param {string} subdomain - the subdomain of which to get the count of requests for
79
- * @return {Promise}
80
- */
81
- module.exports.count = function count({ subdomain }) {
82
- return new Promise(function(resolve, reject) {
83
- Request.count({
84
- subdomain
85
- }, (err, count) => {
86
- if(err) return reject(err);
87
- return resolve(count);
86
+ }
87
+ /**
88
+ * removes all entries associated with a particular subdomain
89
+ * @method del
90
+ * @memberof Request
91
+ * @param {String} subdomain - the subdomain that the entries are related to
92
+ * @return {Promise}
93
+ */
94
+ static async del({ subdomain }) {
95
+ return await RequestModel.deleteMany({
96
+ subdomain,
88
97
  });
89
- });
90
- };
98
+ }
99
+ }
100
+
101
+ export default Request;
@@ -1,172 +1,147 @@
1
- /**
2
- * @module models/user
3
- */
4
-
5
- const mongoose = require('mongoose');
6
- const crypto = require('crypto');
1
+ import mongoose from "mongoose";
2
+ import crypto from "crypto";
7
3
 
8
4
  const Schema = mongoose.Schema;
9
5
 
10
- const UserSchema = new Schema({
11
- _id: String,
12
- username: String,
13
- password: String,
14
- token: String
15
- }, {
16
- minimize: false,
17
- timestamps: {
18
- createdAt: 'created_at',
19
- updatedAt: 'updated_at'
6
+ const UserSchema = new Schema(
7
+ {
8
+ _id: String,
9
+ username: String,
10
+ password: String,
11
+ token: String,
12
+ },
13
+ {
14
+ minimize: false,
15
+ timestamps: {
16
+ createdAt: "created_at",
17
+ updatedAt: "updated_at",
18
+ },
20
19
  }
21
- });
20
+ );
22
21
 
23
- const User = mongoose.model('User', UserSchema);
22
+ const UserModel = mongoose.model("User", UserSchema);
24
23
 
25
24
  /**
26
25
  * User definition
27
- * @class {Object} User
26
+ * @class User
28
27
  * @property {String} username - a string that defines the user's accounts
29
28
  * @property {String} password - a password for the user
30
29
  * @property {String=} token - an access token
31
30
  */
32
- module.exports.User = User;
31
+ class User {
32
+ /**
33
+ * middleware to verify the username and token are valid, will then set the user to req.user
34
+ * @function authenticateMiddleware
35
+ * @memberof User
36
+ * @param {Object} req - express request
37
+ * @param {Object} res - express response
38
+ * @param {Function} next - callback to go to next middleware
39
+ */
40
+ static async authenticateMiddleware(req, res, next) {
41
+ const username = req.headers["x-deploy-username"];
42
+ const token = req.headers["x-deploy-token"];
33
43
 
34
- /**
35
- * middleware to verify the username and token are valid, will then set the user to req.user
36
- * @function authenticateMiddleware
37
- * @param {Object} req - express request
38
- * @param {Object} res - express response
39
- * @param {Function} next - callback to go to next middleware
40
- */
41
- module.exports.authenticateMiddleware = function authenticateMiddleware(req, res, next) {
42
- const { headers } = req;
43
- const username = headers['x-deploy-username'];
44
- const token = headers['x-deploy-token'];
45
- if(!username && !token) {
46
- res.status(500).send({ error: 'authentication necessary' });
47
- }
48
- authenticate(username, token)
49
- .then((user) => {
50
- req.user = user;
51
- next();
52
- })
53
- .catch((error) => res.status(500).send({ error }));
54
- };
44
+ if (!username && !token) {
45
+ res.status(500).send({ error: "authentication necessary" });
46
+ }
55
47
 
56
- /**
57
- * verify the username and token are valid
58
- * @method authenticate
59
- * @param {String} token - the token associated with the username
60
- * @param {String} username - the username of the user
61
- * @return {Promise}
62
- */
63
- var authenticate;
64
- module.exports.authenticate = authenticate = function authenticate(username, token) {
65
- return new Promise(function(resolve, reject) {
66
- User.findOne({
48
+ req.user = await User.authenticate(username, token);
49
+
50
+ next();
51
+ }
52
+ /**
53
+ * verify the username and token are valid
54
+ * @method authenticate
55
+ * @memberof User
56
+ * @param {String} token - the token associated with the username
57
+ * @param {String} username - the username of the user
58
+ * @return {Promise}
59
+ */
60
+ static async authenticate(username, token) {
61
+ let user = await UserModel.findOne({
67
62
  _id: username,
68
- token
69
- }, function(err, user) {
70
- if(err || !user) return reject('not authenticated');
71
- return resolve({
72
- username: user.username,
73
- token: user.token,
74
- depoyments: user.deployments
75
- });
63
+ token,
76
64
  });
77
- });
78
- };
79
65
 
80
- /**
81
- * logs out a user by deleting their token
82
- * @method logout
83
- * @param {String} token - the token associated with the username
84
- * @param {String} username - the username of the user
85
- * @return {Promise}
86
- */
87
- module.exports.logout = function logout({ token, username }) {
88
- return new Promise(function(resolve, reject) {
89
- User.findOne({
66
+ if (!user) throw new Error("not authenticated");
67
+
68
+ return {
69
+ username: user.username,
70
+ token: user.token,
71
+ };
72
+ }
73
+ /**
74
+ * logs out a user by deleting their token
75
+ * @method logout
76
+ * @memberof User
77
+ * @param {String} token - the token associated with the username
78
+ * @param {String} username - the username of the user
79
+ * @return {Promise}
80
+ */
81
+ static async logout({ token, username }) {
82
+ let user = await UserModel.findOne({
90
83
  _id: username,
91
- token
92
- }, function(err, user) {
93
- if(err || !user) return reject('token and username not valid');
94
- user.token = '';
95
- user.save((err) => {
96
- if(err) return reject('erro removing token from the database');
97
- return resolve();
98
- });
84
+ token,
99
85
  });
100
- });
101
- };
102
86
 
103
- /**
104
- * logs in a user and returns
105
- * @method login
106
- * @param {String} username - the username of the user who is logging in
107
- * @param {String} password - the password associated with the user
108
- * @return {Promise}
109
- */
110
- module.exports.login = function login({ username, password }) {
111
- return new Promise(function(resolve, reject) {
112
- User.findOne({
87
+ if (!user) throw new Error("token and username not valid");
88
+
89
+ user.token = "";
90
+
91
+ return await user.save();
92
+ }
93
+ /**
94
+ * logs in a user and returns
95
+ * @method login
96
+ * @memberof User
97
+ * @param {String} username - the username of the user who is logging in
98
+ * @param {String} password - the password associated with the user
99
+ * @return {Promise}
100
+ */
101
+ static async login({ username, password }) {
102
+ let user = await UserModel.findOne({
113
103
  _id: username,
114
- password: crypto.createHash('sha256').update(password).digest('hex')
115
- }, function(err, user) {
116
- if(err || !user) return reject('password username combination not correct');
117
- user.token = crypto.createHash('sha256').update(Date.now() + password + username).digest('hex');
118
- user.save((err) => {
119
- if(err) return reject('erro persisting token to database');
120
- return resolve({
121
- username: user.username,
122
- token: user.token
123
- });
124
- });
104
+ password: crypto.createHash("sha256").update(password).digest("hex"),
125
105
  });
126
- });
127
- };
128
106
 
129
- /**
130
- * registers a user
131
- * @method register
132
- * @param {String} username - the username of the user who is logging in
133
- * @param {String} password - the password associated with the user
134
- * @return {Promise}
135
- */
136
- module.exports.register = function register({ username, password }) {
137
- return new Promise(function(resolve, reject) {
138
- User.create({
107
+ if (!user) throw new Error("password username combination not correct");
108
+
109
+ user.token = crypto
110
+ .createHash("sha256")
111
+ .update(Date.now() + password + username)
112
+ .digest("hex");
113
+ await user.save();
114
+
115
+ return {
116
+ username: user.username,
117
+ token: user.token,
118
+ };
119
+ }
120
+ /**
121
+ * registers a user
122
+ * @method register
123
+ * @memberof User
124
+ * @param {String} username - the username of the user who is logging in
125
+ * @param {String} password - the password associated with the user
126
+ * @return {Promise}
127
+ */
128
+ static async register({ username, password }) {
129
+ let user = await UserModel.create({
139
130
  _id: username,
140
131
  username,
141
- password: crypto.createHash('sha256').update(password).digest('hex'),
142
- token: crypto.createHash('sha256').update(Date.now() + password + username).digest('hex')
143
- }, function(error, user) {
144
- if(error) return reject(error);
145
- resolve({
146
- username: user.username,
147
- token: user.token,
148
- depoyments: user.deployments
149
- });
132
+ password: crypto.createHash("sha256").update(password).digest("hex"),
133
+ token: crypto
134
+ .createHash("sha256")
135
+ .update(Date.now() + password + username)
136
+ .digest("hex"),
150
137
  });
151
- });
152
- };
153
138
 
154
- /**
155
- * returns the user if token and username are valid
156
- * @method get
157
- * @param {String} token - the token associated with the username
158
- * @param {String} username - the username of the user
159
- * @return {Promise}
160
- */
161
- module.exports.get = function get({ token, username }) {
162
- return new Promise(function(resolve, reject) {
163
- User.findOne({
164
- _id: username,
165
- token
166
- }, function(err, user) {
167
- if(err || !user) return reject('token is no longer valid');
168
- return resolve(user);
169
- });
139
+ return {
140
+ username: user.username,
141
+ token: user.token,
142
+ depoyments: user.deployments,
143
+ };
144
+ }
145
+ }
170
146
 
171
- });
172
- };
147
+ export default User;