hotstaq 0.5.24

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 (299) hide show
  1. package/.eslintignore +17 -0
  2. package/.eslintrc.js +11 -0
  3. package/.vscode/launch.json +199 -0
  4. package/.vscode/settings.json +2 -0
  5. package/.vscode/tasks.json +78 -0
  6. package/CONTRIBUTING.md +157 -0
  7. package/README.md +126 -0
  8. package/bin/hotstaq +3 -0
  9. package/bin/hotstaq.cmd +1 -0
  10. package/build/src/Hot.d.ts +167 -0
  11. package/build/src/Hot.d.ts.map +1 -0
  12. package/build/src/Hot.js +365 -0
  13. package/build/src/Hot.js.map +1 -0
  14. package/build/src/HotAPI.d.ts +130 -0
  15. package/build/src/HotAPI.d.ts.map +1 -0
  16. package/build/src/HotAPI.js +353 -0
  17. package/build/src/HotAPI.js.map +1 -0
  18. package/build/src/HotAgentAPI.d.ts +22 -0
  19. package/build/src/HotAgentAPI.d.ts.map +1 -0
  20. package/build/src/HotAgentAPI.js +85 -0
  21. package/build/src/HotAgentAPI.js.map +1 -0
  22. package/build/src/HotAgentRoute.d.ts +17 -0
  23. package/build/src/HotAgentRoute.d.ts.map +1 -0
  24. package/build/src/HotAgentRoute.js +109 -0
  25. package/build/src/HotAgentRoute.js.map +1 -0
  26. package/build/src/HotBuilder.d.ts +52 -0
  27. package/build/src/HotBuilder.d.ts.map +1 -0
  28. package/build/src/HotBuilder.js +239 -0
  29. package/build/src/HotBuilder.js.map +1 -0
  30. package/build/src/HotClient.d.ts +31 -0
  31. package/build/src/HotClient.d.ts.map +1 -0
  32. package/build/src/HotClient.js +19 -0
  33. package/build/src/HotClient.js.map +1 -0
  34. package/build/src/HotComponent.d.ts +118 -0
  35. package/build/src/HotComponent.d.ts.map +1 -0
  36. package/build/src/HotComponent.js +89 -0
  37. package/build/src/HotComponent.js.map +1 -0
  38. package/build/src/HotCreator.d.ts +92 -0
  39. package/build/src/HotCreator.d.ts.map +1 -0
  40. package/build/src/HotCreator.js +465 -0
  41. package/build/src/HotCreator.js.map +1 -0
  42. package/build/src/HotDB.d.ts +69 -0
  43. package/build/src/HotDB.d.ts.map +1 -0
  44. package/build/src/HotDB.js +29 -0
  45. package/build/src/HotDB.js.map +1 -0
  46. package/build/src/HotDBConnectionInterface.d.ts +40 -0
  47. package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
  48. package/build/src/HotDBConnectionInterface.js +3 -0
  49. package/build/src/HotDBConnectionInterface.js.map +1 -0
  50. package/build/src/HotFile.d.ts +134 -0
  51. package/build/src/HotFile.d.ts.map +1 -0
  52. package/build/src/HotFile.js +454 -0
  53. package/build/src/HotFile.js.map +1 -0
  54. package/build/src/HotHTTPServer.d.ts +162 -0
  55. package/build/src/HotHTTPServer.d.ts.map +1 -0
  56. package/build/src/HotHTTPServer.js +863 -0
  57. package/build/src/HotHTTPServer.js.map +1 -0
  58. package/build/src/HotIO.d.ts +39 -0
  59. package/build/src/HotIO.d.ts.map +1 -0
  60. package/build/src/HotIO.js +195 -0
  61. package/build/src/HotIO.js.map +1 -0
  62. package/build/src/HotLog.d.ts +60 -0
  63. package/build/src/HotLog.d.ts.map +1 -0
  64. package/build/src/HotLog.js +126 -0
  65. package/build/src/HotLog.js.map +1 -0
  66. package/build/src/HotPage.d.ts +125 -0
  67. package/build/src/HotPage.d.ts.map +1 -0
  68. package/build/src/HotPage.js +178 -0
  69. package/build/src/HotPage.js.map +1 -0
  70. package/build/src/HotRoute.d.ts +82 -0
  71. package/build/src/HotRoute.d.ts.map +1 -0
  72. package/build/src/HotRoute.js +83 -0
  73. package/build/src/HotRoute.js.map +1 -0
  74. package/build/src/HotRouteMethod.d.ts +129 -0
  75. package/build/src/HotRouteMethod.d.ts.map +1 -0
  76. package/build/src/HotRouteMethod.js +84 -0
  77. package/build/src/HotRouteMethod.js.map +1 -0
  78. package/build/src/HotServer.d.ts +152 -0
  79. package/build/src/HotServer.d.ts.map +1 -0
  80. package/build/src/HotServer.js +109 -0
  81. package/build/src/HotServer.js.map +1 -0
  82. package/build/src/HotSetAsWeb.d.ts +2 -0
  83. package/build/src/HotSetAsWeb.d.ts.map +1 -0
  84. package/build/src/HotSetAsWeb.js +5 -0
  85. package/build/src/HotSetAsWeb.js.map +1 -0
  86. package/build/src/HotStaq.d.ts +601 -0
  87. package/build/src/HotStaq.d.ts.map +1 -0
  88. package/build/src/HotStaq.js +1258 -0
  89. package/build/src/HotStaq.js.map +1 -0
  90. package/build/src/HotStaqWeb.d.ts +18 -0
  91. package/build/src/HotStaqWeb.d.ts.map +1 -0
  92. package/build/src/HotStaqWeb.js +44 -0
  93. package/build/src/HotStaqWeb.js.map +1 -0
  94. package/build/src/HotTestDriver.d.ts +63 -0
  95. package/build/src/HotTestDriver.d.ts.map +1 -0
  96. package/build/src/HotTestDriver.js +187 -0
  97. package/build/src/HotTestDriver.js.map +1 -0
  98. package/build/src/HotTestElement.d.ts +71 -0
  99. package/build/src/HotTestElement.d.ts.map +1 -0
  100. package/build/src/HotTestElement.js +37 -0
  101. package/build/src/HotTestElement.js.map +1 -0
  102. package/build/src/HotTestMap.d.ts +83 -0
  103. package/build/src/HotTestMap.d.ts.map +1 -0
  104. package/build/src/HotTestMap.js +58 -0
  105. package/build/src/HotTestMap.js.map +1 -0
  106. package/build/src/HotTestSeleniumDriver.d.ts +82 -0
  107. package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
  108. package/build/src/HotTestSeleniumDriver.js +398 -0
  109. package/build/src/HotTestSeleniumDriver.js.map +1 -0
  110. package/build/src/HotTester.d.ts +188 -0
  111. package/build/src/HotTester.d.ts.map +1 -0
  112. package/build/src/HotTester.js +623 -0
  113. package/build/src/HotTester.js.map +1 -0
  114. package/build/src/HotTesterAPI.d.ts +15 -0
  115. package/build/src/HotTesterAPI.d.ts.map +1 -0
  116. package/build/src/HotTesterAPI.js +161 -0
  117. package/build/src/HotTesterAPI.js.map +1 -0
  118. package/build/src/HotTesterMocha.d.ts +50 -0
  119. package/build/src/HotTesterMocha.d.ts.map +1 -0
  120. package/build/src/HotTesterMocha.js +205 -0
  121. package/build/src/HotTesterMocha.js.map +1 -0
  122. package/build/src/HotTesterMochaSelenium.d.ts +70 -0
  123. package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
  124. package/build/src/HotTesterMochaSelenium.js +257 -0
  125. package/build/src/HotTesterMochaSelenium.js.map +1 -0
  126. package/build/src/HotTesterServer.d.ts +114 -0
  127. package/build/src/HotTesterServer.d.ts.map +1 -0
  128. package/build/src/HotTesterServer.js +575 -0
  129. package/build/src/HotTesterServer.js.map +1 -0
  130. package/build/src/api.d.ts +33 -0
  131. package/build/src/api.d.ts.map +1 -0
  132. package/build/src/api.js +78 -0
  133. package/build/src/api.js.map +1 -0
  134. package/build/src/cli.d.ts +2 -0
  135. package/build/src/cli.d.ts.map +1 -0
  136. package/build/src/cli.js +935 -0
  137. package/build/src/cli.js.map +1 -0
  138. package/build/src/schemas/HotDBInflux.d.ts +63 -0
  139. package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
  140. package/build/src/schemas/HotDBInflux.js +239 -0
  141. package/build/src/schemas/HotDBInflux.js.map +1 -0
  142. package/build/src/schemas/HotDBMigration.d.ts +19 -0
  143. package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
  144. package/build/src/schemas/HotDBMigration.js +15 -0
  145. package/build/src/schemas/HotDBMigration.js.map +1 -0
  146. package/build/src/schemas/HotDBMySQL.d.ts +65 -0
  147. package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
  148. package/build/src/schemas/HotDBMySQL.js +387 -0
  149. package/build/src/schemas/HotDBMySQL.js.map +1 -0
  150. package/build/src/schemas/HotDBSchema.d.ts +15 -0
  151. package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
  152. package/build/src/schemas/HotDBSchema.js +19 -0
  153. package/build/src/schemas/HotDBSchema.js.map +1 -0
  154. package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
  155. package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
  156. package/build/src/schemas/influx/InfluxSchema.js +33 -0
  157. package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
  158. package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
  159. package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
  160. package/build/src/schemas/mysql/MySQLSchema.js +151 -0
  161. package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
  162. package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
  163. package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
  164. package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
  165. package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
  166. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
  167. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
  168. package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
  169. package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
  170. package/build-web/HotStaq.js +2 -0
  171. package/build-web/HotStaq.min.js +125 -0
  172. package/builder/docker/Dockerfile.linux.gen +42 -0
  173. package/builder/docker/README.md +36 -0
  174. package/builder/docker/app/start.sh +8 -0
  175. package/builder/docker/dockerignore +3 -0
  176. package/builder/docker/scripts/build.bat +11 -0
  177. package/builder/docker/scripts/build.sh +11 -0
  178. package/builder/docker/scripts/start-app.bat +7 -0
  179. package/builder/docker/scripts/start-app.sh +7 -0
  180. package/builder/docker/scripts/stop-app.bat +5 -0
  181. package/builder/docker/scripts/stop-app.sh +5 -0
  182. package/builder/docker-compose/docker-compose.gen.yaml +41 -0
  183. package/builder/docker-compose/env-skeleton +4 -0
  184. package/creator/project/.vscode/launch.json +59 -0
  185. package/creator/project/README.md +20 -0
  186. package/creator/project/gitignore +118 -0
  187. package/creator/project/npmignore +118 -0
  188. package/creator/public/api-test.hott +28 -0
  189. package/creator/public/index.hott +12 -0
  190. package/creator/ts/src/AppAPI.ts +30 -0
  191. package/creator/ts/src/HelloWorld.ts +39 -0
  192. package/creator/ts/src/WebExport.ts +7 -0
  193. package/creator/ts/tsconfig-web.json +73 -0
  194. package/creator/ts/tsconfig.json +73 -0
  195. package/creator/ts/webpack-api.config.js +57 -0
  196. package/dbstart.sh +19 -0
  197. package/dbstop.sh +4 -0
  198. package/docs/.nojekyll +1 -0
  199. package/docs/README.md +128 -0
  200. package/docs/classes/Hot.md +477 -0
  201. package/docs/classes/HotAPI.md +369 -0
  202. package/docs/classes/HotClient.md +95 -0
  203. package/docs/classes/HotComponent.md +279 -0
  204. package/docs/classes/HotDB.md +247 -0
  205. package/docs/classes/HotDBInflux.md +404 -0
  206. package/docs/classes/HotDBMigration.md +80 -0
  207. package/docs/classes/HotDBMySQL.md +310 -0
  208. package/docs/classes/HotDBSchema.md +51 -0
  209. package/docs/classes/HotFile.md +353 -0
  210. package/docs/classes/HotHTTPServer.md +700 -0
  211. package/docs/classes/HotLog.md +162 -0
  212. package/docs/classes/HotPage.md +357 -0
  213. package/docs/classes/HotRoute.md +312 -0
  214. package/docs/classes/HotRouteMethod.md +271 -0
  215. package/docs/classes/HotServer.md +311 -0
  216. package/docs/classes/HotStaq.md +1153 -0
  217. package/docs/classes/HotTestDestination.md +58 -0
  218. package/docs/classes/HotTestDriver.md +332 -0
  219. package/docs/classes/HotTestElement.md +88 -0
  220. package/docs/classes/HotTestElementOptions.md +71 -0
  221. package/docs/classes/HotTestMap.md +92 -0
  222. package/docs/classes/HotTestSeleniumDriver.md +529 -0
  223. package/docs/classes/HotTester.md +653 -0
  224. package/docs/classes/HotTesterAPI.md +493 -0
  225. package/docs/classes/HotTesterMocha.md +843 -0
  226. package/docs/classes/HotTesterMochaSelenium.md +896 -0
  227. package/docs/classes/HotTesterServer.md +633 -0
  228. package/docs/classes/InfluxSchema.md +74 -0
  229. package/docs/classes/MySQLSchema.md +199 -0
  230. package/docs/classes/MySQLSchemaField.md +330 -0
  231. package/docs/classes/MySQLSchemaTable.md +176 -0
  232. package/docs/enums/ConnectionStatus.md +43 -0
  233. package/docs/enums/DeveloperMode.md +38 -0
  234. package/docs/enums/EventExecutionType.md +43 -0
  235. package/docs/enums/HTTPMethod.md +32 -0
  236. package/docs/enums/HotDBGenerationType.md +30 -0
  237. package/docs/enums/HotLogLevel.md +88 -0
  238. package/docs/interfaces/HotDBConnectionInterface.md +116 -0
  239. package/docs/interfaces/HotDestination.md +62 -0
  240. package/docs/interfaces/HotSite.md +187 -0
  241. package/docs/interfaces/HotSiteMapPath.md +37 -0
  242. package/docs/interfaces/HotSiteRoute.md +79 -0
  243. package/docs/interfaces/HotStartOptions.md +115 -0
  244. package/docs/interfaces/HotTestPage.md +44 -0
  245. package/docs/interfaces/HotTestStop.md +62 -0
  246. package/docs/interfaces/IHotComponent.md +135 -0
  247. package/docs/interfaces/IHotStaq.md +118 -0
  248. package/docs/interfaces/IHotTestElement.md +54 -0
  249. package/docs/interfaces/IHotTestElementOptions.md +43 -0
  250. package/docs/interfaces/MySQLResults.md +43 -0
  251. package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
  252. package/docs/modules.md +162 -0
  253. package/package.json +65 -0
  254. package/selenium-start.sh +7 -0
  255. package/selenium-stop.sh +3 -0
  256. package/src/Hot.ts +319 -0
  257. package/src/HotAPI.ts +378 -0
  258. package/src/HotAgentAPI.ts +43 -0
  259. package/src/HotAgentRoute.ts +44 -0
  260. package/src/HotBuilder.ts +221 -0
  261. package/src/HotClient.ts +40 -0
  262. package/src/HotComponent.ts +158 -0
  263. package/src/HotCreator.ts +482 -0
  264. package/src/HotDB.ts +79 -0
  265. package/src/HotDBConnectionInterface.ts +40 -0
  266. package/src/HotFile.ts +617 -0
  267. package/src/HotHTTPServer.ts +954 -0
  268. package/src/HotIO.ts +128 -0
  269. package/src/HotLog.ts +158 -0
  270. package/src/HotPage.ts +206 -0
  271. package/src/HotRoute.ts +137 -0
  272. package/src/HotRouteMethod.ts +216 -0
  273. package/src/HotServer.ts +211 -0
  274. package/src/HotSetAsWeb.ts +3 -0
  275. package/src/HotStaq.ts +1877 -0
  276. package/src/HotStaqWeb.ts +59 -0
  277. package/src/HotTestDriver.ts +172 -0
  278. package/src/HotTestElement.ts +97 -0
  279. package/src/HotTestMap.ts +130 -0
  280. package/src/HotTestSeleniumDriver.ts +374 -0
  281. package/src/HotTester.ts +697 -0
  282. package/src/HotTesterAPI.ts +126 -0
  283. package/src/HotTesterMocha.ts +133 -0
  284. package/src/HotTesterMochaSelenium.ts +189 -0
  285. package/src/HotTesterServer.ts +551 -0
  286. package/src/api.ts +102 -0
  287. package/src/cli.ts +1147 -0
  288. package/src/schemas/HotDBInflux.ts +211 -0
  289. package/src/schemas/HotDBMigration.ts +24 -0
  290. package/src/schemas/HotDBMySQL.ts +312 -0
  291. package/src/schemas/HotDBSchema.ts +21 -0
  292. package/src/schemas/influx/InfluxSchema.ts +19 -0
  293. package/src/schemas/mysql/MySQLSchema.ts +90 -0
  294. package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
  295. package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
  296. package/tsconfig-web.json +74 -0
  297. package/tsconfig.json +73 -0
  298. package/webpack.config.js +51 -0
  299. package/webpack.config.tests.js +56 -0
package/src/HotAPI.ts ADDED
@@ -0,0 +1,378 @@
1
+ import fetch from "cross-fetch";
2
+
3
+ import { HotServer } from "./HotServer";
4
+ import { HotRoute } from "./HotRoute";
5
+ import { HotClient } from "./HotClient";
6
+ import { HotRouteMethod, ServerAuthorizationFunction } from "./HotRouteMethod";
7
+ import { HotDB } from "./HotDB";
8
+
9
+ import { HotDBSchema } from "./schemas/HotDBSchema";
10
+
11
+ /**
12
+ * The type of object to use during event executions.
13
+ */
14
+ export enum EventExecutionType
15
+ {
16
+ HotRoute,
17
+ HotMethod,
18
+ HotAPI
19
+ }
20
+
21
+ /**
22
+ * The API to use.
23
+ */
24
+ export abstract class HotAPI
25
+ {
26
+ /**
27
+ * The server connection.
28
+ */
29
+ connection: HotServer | HotClient;
30
+ /**
31
+ * The base url for the server.
32
+ */
33
+ baseUrl: string;
34
+ /**
35
+ * If set, this will create the route variables and functions for
36
+ * easy client/server calling.
37
+ */
38
+ createFunctions: boolean;
39
+ /**
40
+ * The database connection.
41
+ */
42
+ executeEventsUsing: EventExecutionType;
43
+ /**
44
+ * The database connection.
45
+ */
46
+ db: HotDB;
47
+ /**
48
+ * The authorization credentials to use throughout the application.
49
+ */
50
+ authCredentials: any;
51
+ /**
52
+ * The function used for user authentication.
53
+ */
54
+ userAuth: ServerAuthorizationFunction;
55
+ /**
56
+ * The database connection.
57
+ */
58
+ routes: { [name: string]: HotRoute };
59
+ /**
60
+ * Executed when the API is about to start registering routes. If
61
+ * this function returns false, the server will not start.
62
+ */
63
+ onPreRegister: () => Promise<boolean>;
64
+ /**
65
+ * Executed when the API has finished registering routes. If
66
+ * this function returns false, the server will not start.
67
+ */
68
+ onPostRegister: () => Promise<boolean>;
69
+
70
+ constructor (baseUrl: string, connection: HotServer | HotClient = null, db: HotDB = null)
71
+ {
72
+ this.connection = connection;
73
+ this.baseUrl = baseUrl;
74
+ this.createFunctions = true;
75
+ this.executeEventsUsing = EventExecutionType.HotRoute;
76
+ this.db = db;
77
+ this.authCredentials = null;
78
+ this.userAuth = null;
79
+ this.routes = {};
80
+ this.onPreRegister = null;
81
+ this.onPostRegister = null;
82
+ }
83
+
84
+ /**
85
+ * Set the database schema for use.
86
+ */
87
+ setDBSchema (schema: HotDBSchema): void
88
+ {
89
+ if (this.connection.api == null)
90
+ throw new Error (`No API has been set!`);
91
+
92
+ if (this.connection.api.db == null)
93
+ throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
94
+
95
+ this.connection.api.db.schema = schema;
96
+ }
97
+
98
+ /**
99
+ * Get the database being used.
100
+ */
101
+ getDB (): HotDB
102
+ {
103
+ if (this.connection.api.db == null)
104
+ throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
105
+
106
+ return (this.connection.api.db);
107
+ }
108
+
109
+ /**
110
+ * Get the database schema being used.
111
+ */
112
+ getDBSchema (): HotDBSchema
113
+ {
114
+ if (this.connection.api.db == null)
115
+ throw new Error (`No database has been set for API base url ${this.connection.api.baseUrl}`);
116
+
117
+ return (this.connection.api.db.schema);
118
+ }
119
+
120
+ /**
121
+ * Add a route. If this.createFunctions is set to true, this will take the incoming
122
+ * route and create an object in this HotAPI object using the name of the route. If there's
123
+ * any HotRouteMethods inside of the incoming HotRoute, it will create the methods
124
+ * and attach them to the newly created HotRoute object.
125
+ *
126
+ * Example:
127
+ * ```
128
+ * export class Users extends HotRoute
129
+ * {
130
+ * constructor (api: FreeLightAPI)
131
+ * {
132
+ * super (api.connection, "user");
133
+ *
134
+ * this.addMethod ("create", this._create, HTTPMethod.POST);
135
+ * }
136
+ *
137
+ * protected async _create (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any): Promise<any>
138
+ * {
139
+ * return (true);
140
+ * }
141
+ * }
142
+ * ```
143
+ *
144
+ * This in turn could be used like so:
145
+ * ```
146
+ * Hot.API.user.create ({});
147
+ * ```
148
+ *
149
+ * Additionally it would create the endpoint: ```http://127.0.0.1:8080/v1/user/create```
150
+ *
151
+ * @param route The route to add. Can be either a full HotRoute object, or just
152
+ * the route's name. If a HotRoute object is supplied, the rest of the parameters
153
+ * will be ignored.
154
+ * @param routeMethod The route's method to add. If the route parameter is a string,
155
+ * it will be interpreted as the route's name, and this will be the method added to
156
+ * the new route.
157
+ * @param executeFunction The function to execute when routeMethod is called by the API.
158
+ */
159
+ addRoute (
160
+ route: HotRoute | string,
161
+ routeMethod: HotRouteMethod | string = null,
162
+ executeFunction: (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any) => Promise<any> = null
163
+ ): void
164
+ {
165
+ let routeName: string = "";
166
+
167
+ if (route instanceof HotRoute)
168
+ {
169
+ routeName = route.route;
170
+ this.routes[route.route] = route;
171
+ }
172
+ else
173
+ {
174
+ routeName = route;
175
+
176
+ if (this.routes[routeName] == null)
177
+ this.routes[routeName] = new HotRoute (this.connection, routeName);
178
+
179
+ if (routeMethod instanceof HotRouteMethod)
180
+ this.routes[routeName].addMethod (routeMethod);
181
+ else
182
+ {
183
+ this.routes[routeName].addMethod (new HotRouteMethod (
184
+ this.routes[routeName], routeMethod, executeFunction));
185
+ }
186
+ }
187
+
188
+ this.routes[routeName].connection = this.connection;
189
+
190
+ // Create the route functions for the server/client.
191
+ if (this.createFunctions === true)
192
+ {
193
+ // @ts-ignore
194
+ let newRoute: { [name: string]: Function } = this[routeName];
195
+
196
+ if (newRoute == null)
197
+ newRoute = {};
198
+
199
+ for (let iIdx = 0; iIdx < this.routes[routeName].methods.length; iIdx++)
200
+ {
201
+ let currentRoute: HotRoute = this.routes[routeName];
202
+ let newRouteMethod: HotRouteMethod = this.routes[routeName].methods[iIdx];
203
+
204
+ /*
205
+ /// @fixme Is this really necessary? A HTTP call is much more preferable,
206
+ /// especially for accruate testing.
207
+ if (this.connection instanceof HotServer)
208
+ {
209
+ if (newRouteMethod.onServerExecute != null)
210
+ newRoute[newRouteMethod.name] = newRouteMethod.onServerExecute;
211
+ }
212
+ else*/
213
+ {
214
+ /*
215
+ /// @fixme Is onClientExecute necessary? I'm thinking the dev can just simply create
216
+ /// their own function to call.
217
+ if (newRouteMethod.onClientExecute != null)
218
+ newRoute[newRouteMethod.name] = newRouteMethod.onClientExecute;
219
+ else
220
+ {*/
221
+ newRoute[newRouteMethod.name] = (data: any): any =>
222
+ {
223
+ let httpMethod: string = newRouteMethod.type;
224
+ // Construct the url here. Base + route + route method
225
+ let routeStr: string = "";
226
+
227
+ if (currentRoute.version !== "")
228
+ routeStr += `/${currentRoute.version}`;
229
+
230
+ if (currentRoute.route !== "")
231
+ routeStr += `/${currentRoute.route}`;
232
+
233
+ if (newRouteMethod.name !== "")
234
+ routeStr += `/${newRouteMethod.name}`;
235
+
236
+ let authCredentials: any = null;
237
+
238
+ // Getting the authorization credentials from the API is the lowest
239
+ // priority for getting credentials. The priorities are in this order:
240
+ // 1. HotRouteMethod
241
+ // 2. HotRoute
242
+ // 3. HotAPI
243
+ if (this.authCredentials != null)
244
+ authCredentials = this.authCredentials;
245
+
246
+ // Find the authorization credentials. Prioritize them when they're
247
+ // in the method. Only add the ones from the route if the ones from
248
+ // the method are missing.
249
+ if (newRouteMethod.authCredentials != null)
250
+ authCredentials = newRouteMethod.authCredentials;
251
+ else
252
+ {
253
+ if (newRouteMethod.parentRoute.authCredentials != null)
254
+ authCredentials = newRouteMethod.parentRoute.authCredentials;
255
+ }
256
+
257
+ if (authCredentials == null)
258
+ {
259
+ // @ts-ignore
260
+ if (typeof (Hot) !== "undefined")
261
+ {
262
+ // @ts-ignore
263
+ if (Hot != null)
264
+ {
265
+ // @ts-ignore
266
+ if (Hot.API != null)
267
+ {
268
+ // @ts-ignore
269
+ if (Hot.API[currentRoute.route] != null)
270
+ {
271
+ // @ts-ignore
272
+ if (Hot.API[currentRoute.route].authCredentials != null)
273
+ {
274
+ // @ts-ignore
275
+ authCredentials = Hot.API[currentRoute.route].authCredentials;
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+
283
+ if (authCredentials != null)
284
+ {
285
+ // Add the authorization credentials to the data being sent.
286
+ for (let key in authCredentials)
287
+ {
288
+ let authCredential: any = authCredentials[key];
289
+
290
+ // Do not overwrite any existing keys in the data about
291
+ // to be sent.
292
+ if (data[key] == null)
293
+ data[key] = authCredential;
294
+ }
295
+ }
296
+
297
+ let args: any[] = [routeStr, data, httpMethod];
298
+
299
+ return (this.call.apply (this, args));
300
+ };
301
+ //}
302
+ }
303
+ }
304
+
305
+ // @ts-ignore
306
+ this[routeName] = newRoute;
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Register a route with the server.
312
+ */
313
+ async registerRoute (route: HotRoute): Promise<void>
314
+ {
315
+ if (this.connection instanceof HotServer)
316
+ await this.connection.registerRoute (route);
317
+ }
318
+
319
+ /**
320
+ * Register all routes with the server.
321
+ */
322
+ async registerRoutes (): Promise<void>
323
+ {
324
+ for (let key in this.routes)
325
+ {
326
+ let route: HotRoute = this.routes[key];
327
+
328
+ await this.registerRoute (route);
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Make a call to the API.
334
+ */
335
+ async call (route: string, data: any, httpMethod: string = "POST"): Promise<any>
336
+ {
337
+ let url: string = this.baseUrl;
338
+
339
+ if (url[(url.length - 1)] === "/")
340
+ url = url.substr (0, (url.length - 1));
341
+
342
+ if (route[0] !== "/")
343
+ url += "/";
344
+
345
+ url += route;
346
+
347
+ httpMethod = httpMethod.toUpperCase ();
348
+
349
+ let fetchObj: any = {
350
+ method: httpMethod,
351
+ headers: {
352
+ "Accept": "application/json",
353
+ "Content-Type": "application/json"
354
+ }
355
+ };
356
+
357
+ if ((httpMethod !== "GET") &&
358
+ (httpMethod !== "HEAD"))
359
+ {
360
+ fetchObj["body"] = JSON.stringify (data);
361
+ }
362
+
363
+ let res: any = null;
364
+
365
+ try
366
+ {
367
+ res = await fetch (url, fetchObj);
368
+ }
369
+ catch (ex)
370
+ {
371
+ throw ex;
372
+ }
373
+
374
+ let jsonObj: any = await res.json ();
375
+
376
+ return (jsonObj);
377
+ }
378
+ }
@@ -0,0 +1,43 @@
1
+ import { HotAPI, HotServer, HotClient } from "./api";
2
+ import { HotAgentRoute } from "./HotAgentRoute";
3
+
4
+ /**
5
+ * The App's API and routes.
6
+ */
7
+ export class HotAgentAPI extends HotAPI
8
+ {
9
+ /**
10
+ * The key to use.
11
+ */
12
+ key: string;
13
+ /**
14
+ * The secret key to use.
15
+ */
16
+ secret: string;
17
+ /**
18
+ * The commands to execute.
19
+ */
20
+ commands: { [name: string]: string };
21
+
22
+ constructor (baseUrl: string, connection: HotServer | HotClient = null, db: any = null)
23
+ {
24
+ super(baseUrl, connection, db);
25
+
26
+ this.key = "";
27
+ this.secret = "";
28
+ this.commands = {};
29
+
30
+ this.userAuth = async (req: any, res: any, jsonObj: any, queryObj: any): Promise<any> =>
31
+ {
32
+ const apiKey: string = jsonObj["key"];
33
+ const apiSecret: string = jsonObj["secret"];
34
+
35
+ if ((apiKey !== this.key) && (apiSecret !== this.secret))
36
+ throw new Error ("Incorrect API key or secret!");
37
+
38
+ return (true);
39
+ };
40
+
41
+ this.addRoute (new HotAgentRoute (this));
42
+ }
43
+ }
@@ -0,0 +1,44 @@
1
+ import { HotRoute, HTTPMethod, HotRouteMethod, HotStaq } from "./api";
2
+ import { HotAgentAPI } from "./HotAgentAPI";
3
+
4
+ import * as fs from "fs";
5
+ import * as vm from "vm";
6
+
7
+ /**
8
+ * Hello world route.
9
+ */
10
+ export class HotAgentRoute extends HotRoute
11
+ {
12
+ /**
13
+ * Helper to the parent API.
14
+ */
15
+ thisApi: HotAgentAPI;
16
+
17
+ constructor (api: HotAgentAPI)
18
+ {
19
+ super (api.connection, "agent");
20
+
21
+ this.thisApi = api;
22
+
23
+ this.addMethod (new HotRouteMethod (this, "execute", this.execute,
24
+ HTTPMethod.POST, api.userAuth));
25
+ }
26
+
27
+ /**
28
+ * Execute a file.
29
+ */
30
+ protected async execute (req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any): Promise<any>
31
+ {
32
+ const cmd: string = HotStaq.getParam ("cmd", jsonObj);
33
+ const data: any = HotStaq.getParamDefault ("data", jsonObj, undefined);
34
+ let foundCmd: string = this.thisApi.commands[cmd];
35
+
36
+ if (foundCmd == null)
37
+ throw new Error (`Command ${cmd} not found!`);
38
+
39
+ const cmdData: string = fs.readFileSync (foundCmd).toString ();
40
+ vm.runInNewContext (cmdData, data);
41
+
42
+ return (true);
43
+ }
44
+ }
@@ -0,0 +1,221 @@
1
+ import * as ppath from "path";
2
+ import { HotIO } from "./HotIO";
3
+
4
+ import { HotStaq, HotSite } from "./HotStaq";
5
+ import { HotLog } from "./HotLog";
6
+
7
+ /**
8
+ * Builds stuff for the CLI like docker images and Kubernetes clusters.
9
+ */
10
+ export class HotBuilder
11
+ {
12
+ /**
13
+ * The HotSites to build from.
14
+ */
15
+ protected hotsites: HotSite[];
16
+ /**
17
+ * Will build the web api.
18
+ * @default true
19
+ */
20
+ api: boolean;
21
+ /**
22
+ * Will build the Dockerfiles.
23
+ */
24
+ dockerFiles: boolean;
25
+ /**
26
+ * Will harden the Dockerfiles security when possible.
27
+ */
28
+ dockerHardenSecurity: boolean;
29
+ /**
30
+ * Will append the docker documentation to the existing README.md.
31
+ */
32
+ appendReadMe: boolean;
33
+ /**
34
+ * Will build the Docker compose file.
35
+ */
36
+ dockerCompose: boolean;
37
+ /**
38
+ * Will build the Kubernetes cluster.
39
+ */
40
+ kubernetes: boolean;
41
+ /**
42
+ * The logger.
43
+ */
44
+ logger: HotLog;
45
+ /**
46
+ * The output directory.
47
+ */
48
+ outputDir: string;
49
+
50
+ constructor (logger: HotLog = new HotLog ())
51
+ {
52
+ this.api = true;
53
+ this.dockerFiles = true;
54
+ this.dockerHardenSecurity = true;
55
+ this.appendReadMe = true;
56
+ this.dockerCompose = false;
57
+ this.kubernetes = false;
58
+ this.hotsites = [];
59
+ this.logger = logger;
60
+ this.outputDir = ppath.normalize (`${process.cwd ()}/`);
61
+ }
62
+
63
+ /**
64
+ * Build everything and output to outputDir.
65
+ *
66
+ * @fixme Needs tests!
67
+ */
68
+ async build (hotsites: HotSite[]): Promise<void>
69
+ {
70
+ this.hotsites = hotsites;
71
+
72
+ if (this.api === true)
73
+ {
74
+ this.logger.info ("Building web API...");
75
+
76
+ /// @todo Finish this...
77
+
78
+ this.logger.info ("Finished building web API...");
79
+ }
80
+
81
+ if (this.dockerFiles === true)
82
+ {
83
+ this.logger.info ("Building docker files...");
84
+
85
+ const dockerDir: string = ppath.normalize (`${__dirname}/../../builder/docker`);
86
+ const dockerFileContent: string = await HotIO.readTextFile (
87
+ ppath.normalize (`${dockerDir}/Dockerfile.linux.gen`));
88
+ const startFileContent: string = await HotIO.readTextFile (
89
+ ppath.normalize (`${dockerDir}/app/start.sh`));
90
+
91
+ for (let iIdx = 0; iIdx < this.hotsites.length; iIdx++)
92
+ {
93
+ const hotsite: HotSite = this.hotsites[iIdx];
94
+
95
+ this.logger.info (`Building Dockerfile "${hotsite.name}"...`);
96
+
97
+ if (hotsite.name == null)
98
+ throw new Error (`HotSite ${hotsite.hotsitePath} is missing a name!`);
99
+
100
+ HotStaq.checkHotSiteName (hotsite.name, true);
101
+
102
+ const hotsiteName: string = hotsite.name;
103
+ let outputDir: string = ppath.normalize (`${this.outputDir}/`);
104
+ let newDockerfileContent: string = dockerFileContent;
105
+ let newStartFileContent: string = startFileContent;
106
+ let dockerfilePortsStr: string = "";
107
+ let dockercomposeAppPortsStr: string = "";
108
+ let dockercomposeAppAPIPortsStr: string = "";
109
+ let httpPort: number = HotStaq.getValueFromHotSiteObj (hotsite, ["server", "ports", "http"]);
110
+ let httpsPort: number = HotStaq.getValueFromHotSiteObj (hotsite, ["server", "ports", "https"]);
111
+ let hotsitePath: string = `/app/${hotsiteName}/HotSite.json`;
112
+ let hardenSecurity: string =
113
+ `
114
+ RUN npm -g uninstall npm && \
115
+ apk --purge del apk-tools
116
+ `;
117
+ /**
118
+ * Replace any keywords in a string.
119
+ */
120
+ let replaceKeywords = (str: string): string =>
121
+ {
122
+ str = str.replace (/\$\{HOTSITE_NAME\}/g, hotsiteName);
123
+ str = str.replace (/\$\{DOCKERFILE_PORTS\}/g, dockerfilePortsStr);
124
+ str = str.replace (/\$\{DOCKER_COMPOSE_APP_PORTS\}/g, dockercomposeAppPortsStr);
125
+ str = str.replace (/\$\{DOCKER_COMPOSE_APP_API_PORTS\}/g, dockercomposeAppAPIPortsStr);
126
+ str = str.replace (/\$\{HARDEN\_SECURITY\}/g, hardenSecurity);
127
+ str = str.replace (/\$\{HOTSITE_PATH\}/g, hotsitePath);
128
+
129
+ return (str);
130
+ };
131
+ /**
132
+ * Replace any keywords in a file.
133
+ */
134
+ let replaceKeywordsInFile = async (filepath: string): Promise<string> =>
135
+ {
136
+ let fileContent: string = await HotIO.readTextFile (ppath.normalize (filepath));
137
+ fileContent = replaceKeywords (fileContent);
138
+
139
+ return (fileContent);
140
+ };
141
+
142
+ if (this.dockerHardenSecurity === false)
143
+ hardenSecurity = "";
144
+
145
+ await HotIO.mkdir (`${outputDir}/docker/${hotsiteName}/app/`);
146
+
147
+ if (httpPort != null)
148
+ {
149
+ dockerfilePortsStr += `ARG HTTP_PORT=${httpPort}
150
+ ENV HTTP_PORT \${HTTP_PORT}
151
+ EXPOSE \${HTTP_PORT}`;
152
+ dockercomposeAppPortsStr += `
153
+ ports:
154
+ - "${httpPort}:${httpPort}"`;
155
+ }
156
+
157
+ if (httpsPort != null)
158
+ {
159
+ dockerfilePortsStr += `ARG HTTPS_PORT=${httpsPort}
160
+ ENV HTTPS_PORT \${HTTPS_PORT}
161
+ EXPOSE \${HTTPS_PORT}`;
162
+ dockercomposeAppPortsStr += `
163
+ - "${httpsPort}:${httpsPort}"`;
164
+ }
165
+
166
+ if (dockerfilePortsStr === "")
167
+ {
168
+ dockerfilePortsStr += `ARG HTTP_PORT=80
169
+ ENV HTTP_PORT \${HTTP_PORT}
170
+ EXPOSE \${HTTP_PORT}`;
171
+ dockercomposeAppPortsStr += `
172
+ ports:
173
+ - "80:80"`;
174
+ }
175
+
176
+ newDockerfileContent = replaceKeywords (newDockerfileContent);
177
+ newStartFileContent = replaceKeywords (newStartFileContent);
178
+
179
+ await HotIO.writeTextFile (`${outputDir}/docker/${hotsiteName}/Dockerfile`, newDockerfileContent);
180
+ await HotIO.copyFiles (`${dockerDir}/scripts/`, `${outputDir}/`);
181
+ await HotIO.writeTextFile (`${outputDir}/docker/${hotsiteName}/app/start.sh`, newStartFileContent);
182
+ await HotIO.copyFile (`${dockerDir}/dockerignore`, `${outputDir}/.dockerignore`);
183
+
184
+ if (await HotIO.exists (`${outputDir}/README.md`) === true)
185
+ {
186
+ const prevREADME: string = await HotIO.readTextFile (`${outputDir}/README.md`);
187
+ const dockerREADME: string = await HotIO.readTextFile (`${dockerDir}/README.md`);
188
+
189
+ // Only append the docker readme if it's not already there...
190
+ if (prevREADME.indexOf ("Docker Getting Started") < 0)
191
+ await HotIO.writeTextFile (`${outputDir}/README.md`, `${prevREADME}\n${dockerREADME}`);
192
+ }
193
+
194
+ this.logger.info (`Finished building Dockerfile "${hotsite.name}"...`);
195
+ }
196
+
197
+ this.logger.info ("Finished building docker files...");
198
+ }
199
+
200
+ if (this.dockerCompose === true)
201
+ {
202
+ this.logger.info ("Building Docker Compose files...");
203
+
204
+ const dockerDir: string = ppath.normalize (`${__dirname}/../../builder/docker-compose`);
205
+ const dockerFileContent: string = await HotIO.readTextFile (
206
+ ppath.normalize (`${dockerDir}/docker-compose.gen.yaml`));
207
+ const startFileContent: string = await HotIO.readTextFile (
208
+ ppath.normalize (`${dockerDir}/app/start.sh`));
209
+
210
+ for (let iIdx = 0; iIdx < this.hotsites.length; iIdx++)
211
+ {
212
+ const hotsite: HotSite = this.hotsites[iIdx];
213
+
214
+ this.logger.info ("Building Docker Compose files...");
215
+ this.logger.info (`Finished building Docker Compose "${hotsite.name}"...`);
216
+ }
217
+
218
+ this.logger.info ("Finished building Docker Compose files...");
219
+ }
220
+ }
221
+ }