@vandenberghinc/volt 1.1.5 → 1.1.7

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 (287) hide show
  1. package/backend/dist/cjs/database.d.ts +41 -68
  2. package/backend/dist/cjs/database.js +127 -76
  3. package/backend/dist/cjs/endpoint.d.ts +23 -9
  4. package/backend/dist/cjs/endpoint.js +98 -21
  5. package/backend/dist/cjs/frontend.d.ts +0 -2
  6. package/backend/dist/cjs/frontend.js +9 -9
  7. package/backend/dist/cjs/image_endpoint.d.ts +3 -1
  8. package/backend/dist/cjs/image_endpoint.js +2 -1
  9. package/backend/dist/cjs/payments/paddle.js +10 -2
  10. package/backend/dist/cjs/plugins/css.d.ts +6 -5
  11. package/backend/dist/cjs/plugins/css.js +32 -7
  12. package/backend/dist/cjs/plugins/ts/compiler.d.ts +6 -1
  13. package/backend/dist/cjs/plugins/ts/compiler.js +26 -2
  14. package/backend/dist/cjs/plugins/ts/preprocessing.js +5 -3
  15. package/backend/dist/cjs/server.d.ts +7 -13
  16. package/backend/dist/cjs/server.js +184 -303
  17. package/backend/dist/cjs/status.d.ts +1 -0
  18. package/backend/dist/cjs/status.js +2 -1
  19. package/backend/dist/cjs/stream.d.ts +5 -3
  20. package/backend/dist/cjs/stream.js +13 -4
  21. package/backend/dist/cjs/users.d.ts +1 -1
  22. package/backend/dist/cjs/users.js +87 -72
  23. package/backend/dist/cjs/utils.d.ts +17 -9
  24. package/backend/dist/cjs/utils.js +22 -64
  25. package/backend/dist/cjs/view.d.ts +2 -2
  26. package/backend/dist/cjs/view.js +38 -40
  27. package/backend/dist/cjs/volt.d.ts +3 -2
  28. package/backend/dist/cjs/volt.js +2 -2
  29. package/backend/dist/css/volt.css +5 -0
  30. package/backend/dist/esm/database.d.ts +41 -68
  31. package/backend/dist/esm/database.js +127 -76
  32. package/backend/dist/esm/endpoint.d.ts +23 -9
  33. package/backend/dist/esm/endpoint.js +99 -22
  34. package/backend/dist/esm/frontend.d.ts +0 -2
  35. package/backend/dist/esm/frontend.js +9 -9
  36. package/backend/dist/esm/image_endpoint.d.ts +3 -1
  37. package/backend/dist/esm/image_endpoint.js +2 -1
  38. package/backend/dist/esm/payments/paddle.js +11 -3
  39. package/backend/dist/esm/plugins/css.d.ts +6 -5
  40. package/backend/dist/esm/plugins/css.js +32 -6
  41. package/backend/dist/esm/plugins/ts/compiler.d.ts +6 -1
  42. package/backend/dist/esm/plugins/ts/compiler.js +26 -2
  43. package/backend/dist/esm/plugins/ts/preprocessing.js +5 -3
  44. package/backend/dist/esm/server.d.ts +7 -13
  45. package/backend/dist/esm/server.js +182 -301
  46. package/backend/dist/esm/status.d.ts +1 -0
  47. package/backend/dist/esm/status.js +1 -0
  48. package/backend/dist/esm/stream.d.ts +5 -3
  49. package/backend/dist/esm/stream.js +13 -4
  50. package/backend/dist/esm/users.d.ts +1 -1
  51. package/backend/dist/esm/users.js +87 -72
  52. package/backend/dist/esm/utils.d.ts +17 -9
  53. package/backend/dist/esm/utils.js +21 -62
  54. package/backend/dist/esm/view.d.ts +2 -2
  55. package/backend/dist/esm/view.js +38 -40
  56. package/backend/dist/esm/volt.d.ts +3 -2
  57. package/backend/dist/esm/volt.js +2 -1
  58. package/backend/dist/esm-dev/blacklist.js +1 -1
  59. package/backend/dist/esm-dev/cli.js +2 -2
  60. package/backend/dist/esm-dev/database.d.ts +41 -68
  61. package/backend/dist/esm-dev/database.js +128 -77
  62. package/backend/dist/esm-dev/endpoint.d.ts +23 -9
  63. package/backend/dist/esm-dev/endpoint.js +100 -23
  64. package/backend/dist/esm-dev/file_watcher.js +1 -1
  65. package/backend/dist/esm-dev/frontend.d.ts +0 -2
  66. package/backend/dist/esm-dev/frontend.js +9 -9
  67. package/backend/dist/esm-dev/image_endpoint.d.ts +3 -1
  68. package/backend/dist/esm-dev/image_endpoint.js +2 -1
  69. package/backend/dist/esm-dev/logger.js +1 -1
  70. package/backend/dist/esm-dev/payments/paddle.js +12 -4
  71. package/backend/dist/esm-dev/plugins/css.d.ts +6 -5
  72. package/backend/dist/esm-dev/plugins/css.js +33 -7
  73. package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +6 -1
  74. package/backend/dist/esm-dev/plugins/ts/compiler.js +27 -3
  75. package/backend/dist/esm-dev/plugins/ts/preprocessing.js +7 -5
  76. package/backend/dist/esm-dev/rate_limit.js +1 -1
  77. package/backend/dist/esm-dev/server.d.ts +7 -13
  78. package/backend/dist/esm-dev/server.js +184 -303
  79. package/backend/dist/esm-dev/status.d.ts +1 -0
  80. package/backend/dist/esm-dev/status.js +1 -0
  81. package/backend/dist/esm-dev/stream.d.ts +5 -3
  82. package/backend/dist/esm-dev/stream.js +13 -4
  83. package/backend/dist/esm-dev/users.d.ts +1 -1
  84. package/backend/dist/esm-dev/users.js +88 -73
  85. package/backend/dist/esm-dev/utils.d.ts +17 -9
  86. package/backend/dist/esm-dev/utils.js +22 -63
  87. package/backend/dist/esm-dev/view.d.ts +2 -2
  88. package/backend/dist/esm-dev/view.js +39 -41
  89. package/backend/dist/esm-dev/volt.d.ts +3 -2
  90. package/backend/dist/esm-dev/volt.js +2 -1
  91. package/backend/src/database.ts +163 -152
  92. package/backend/src/endpoint.ts +123 -31
  93. package/backend/src/frontend.ts +9 -8
  94. package/backend/src/image_endpoint.ts +4 -0
  95. package/backend/src/payments/paddle.ts +11 -3
  96. package/backend/src/plugins/css.ts +36 -8
  97. package/backend/src/plugins/ts/compiler.ts +37 -1
  98. package/backend/src/plugins/ts/preprocessing.ts +5 -3
  99. package/backend/src/server.ts +167 -306
  100. package/backend/src/status.ts +1 -0
  101. package/backend/src/stream.ts +28 -8
  102. package/backend/src/users.ts +87 -72
  103. package/backend/src/utils.ts +58 -25
  104. package/backend/src/view.ts +30 -28
  105. package/backend/src/{volt.js → volt.ts} +2 -1
  106. package/backend/tsconfig.cjs.json +3 -3
  107. package/backend/tsconfig.esm.json +3 -3
  108. package/frontend/dist/elements/base.d.ts +397 -415
  109. package/frontend/dist/elements/base.js +565 -328
  110. package/frontend/dist/elements/module.d.ts +26 -12
  111. package/frontend/dist/elements/module.js +69 -32
  112. package/frontend/dist/elements/register_element.d.ts +3 -0
  113. package/frontend/dist/elements/register_element.js +22 -0
  114. package/frontend/dist/modules/auth.d.ts +1 -0
  115. package/frontend/dist/modules/auth.js +6 -5
  116. package/frontend/dist/modules/color.d.ts +159 -0
  117. package/frontend/dist/modules/color.js +315 -0
  118. package/frontend/dist/modules/colors.d.ts +1 -26
  119. package/frontend/dist/modules/colors.js +417 -338
  120. package/frontend/dist/modules/cookies.d.ts +1 -0
  121. package/frontend/dist/modules/cookies.js +1 -0
  122. package/frontend/dist/modules/events.d.ts +1 -0
  123. package/frontend/dist/modules/events.js +1 -0
  124. package/frontend/dist/modules/google.d.ts +1 -0
  125. package/frontend/dist/modules/google.js +1 -0
  126. package/frontend/dist/modules/meta.d.ts +1 -0
  127. package/frontend/dist/modules/meta.js +1 -0
  128. package/frontend/dist/modules/mutex.d.ts +1 -2
  129. package/frontend/dist/modules/mutex.js +3 -4
  130. package/frontend/dist/modules/paddle.d.ts +1 -0
  131. package/frontend/dist/modules/paddle.js +14 -13
  132. package/frontend/dist/modules/scheme.d.ts +1 -0
  133. package/frontend/dist/modules/scheme.js +4 -2
  134. package/frontend/dist/modules/statics.d.ts +1 -0
  135. package/frontend/dist/modules/statics.js +1 -0
  136. package/frontend/dist/modules/support.d.ts +1 -0
  137. package/frontend/dist/modules/support.js +3 -2
  138. package/frontend/dist/modules/theme.d.ts +56 -0
  139. package/frontend/dist/{ui → modules}/theme.js +186 -75
  140. package/frontend/dist/modules/themes.d.ts +1 -1
  141. package/frontend/dist/modules/themes.js +1 -0
  142. package/frontend/dist/modules/user.d.ts +1 -0
  143. package/frontend/dist/modules/user.js +11 -10
  144. package/frontend/dist/modules/utils.d.ts +23 -2
  145. package/frontend/dist/modules/utils.js +93 -1
  146. package/frontend/dist/types/gradient.js +4 -0
  147. package/frontend/dist/ui/border_button.d.ts +0 -25
  148. package/frontend/dist/ui/border_button.js +50 -51
  149. package/frontend/dist/ui/button.d.ts +0 -21
  150. package/frontend/dist/ui/button.js +41 -46
  151. package/frontend/dist/ui/canvas.js +15 -15
  152. package/frontend/dist/ui/checkbox.d.ts +3 -17
  153. package/frontend/dist/ui/checkbox.js +36 -30
  154. package/frontend/dist/ui/code.d.ts +15 -82
  155. package/frontend/dist/ui/code.js +150 -125
  156. package/frontend/dist/ui/color.d.ts +0 -1
  157. package/frontend/dist/ui/color.js +1 -1
  158. package/frontend/dist/ui/context_menu.d.ts +4 -2
  159. package/frontend/dist/ui/context_menu.js +16 -17
  160. package/frontend/dist/ui/css.js +2 -0
  161. package/frontend/dist/ui/divider.d.ts +0 -7
  162. package/frontend/dist/ui/divider.js +21 -25
  163. package/frontend/dist/ui/dropdown.d.ts +13 -7
  164. package/frontend/dist/ui/dropdown.js +65 -30
  165. package/frontend/dist/ui/for_each.d.ts +0 -5
  166. package/frontend/dist/ui/for_each.js +17 -22
  167. package/frontend/dist/ui/form.d.ts +17 -12
  168. package/frontend/dist/ui/form.js +21 -18
  169. package/frontend/dist/ui/frame_modes.d.ts +9 -12
  170. package/frontend/dist/ui/frame_modes.js +8 -10
  171. package/frontend/dist/ui/google_map.d.ts +0 -11
  172. package/frontend/dist/ui/google_map.js +23 -28
  173. package/frontend/dist/ui/gradient.d.ts +0 -5
  174. package/frontend/dist/ui/gradient.js +17 -22
  175. package/frontend/dist/ui/image.d.ts +27 -58
  176. package/frontend/dist/ui/image.js +99 -93
  177. package/frontend/dist/ui/input.d.ts +20 -97
  178. package/frontend/dist/ui/input.js +192 -170
  179. package/frontend/dist/ui/link.d.ts +0 -18
  180. package/frontend/dist/ui/link.js +42 -48
  181. package/frontend/dist/ui/list.js +36 -37
  182. package/frontend/dist/ui/loader_button.d.ts +4 -19
  183. package/frontend/dist/ui/loader_button.js +35 -37
  184. package/frontend/dist/ui/loaders.d.ts +0 -8
  185. package/frontend/dist/ui/loaders.js +20 -25
  186. package/frontend/dist/ui/popup.d.ts +11 -8
  187. package/frontend/dist/ui/popup.js +183 -24
  188. package/frontend/dist/ui/pseudo.d.ts +3 -3
  189. package/frontend/dist/ui/pseudo.js +14 -17
  190. package/frontend/dist/ui/scroller.d.ts +10 -48
  191. package/frontend/dist/ui/scroller.js +306 -300
  192. package/frontend/dist/ui/slider.d.ts +9 -3
  193. package/frontend/dist/ui/slider.js +31 -17
  194. package/frontend/dist/ui/spacer.d.ts +0 -9
  195. package/frontend/dist/ui/spacer.js +21 -26
  196. package/frontend/dist/ui/span.js +13 -15
  197. package/frontend/dist/ui/stack.d.ts +14 -75
  198. package/frontend/dist/ui/stack.js +166 -169
  199. package/frontend/dist/ui/steps.d.ts +10 -23
  200. package/frontend/dist/ui/steps.js +47 -34
  201. package/frontend/dist/ui/style.d.ts +4 -3
  202. package/frontend/dist/ui/style.js +13 -18
  203. package/frontend/dist/ui/switch.d.ts +10 -4
  204. package/frontend/dist/ui/switch.js +24 -16
  205. package/frontend/dist/ui/table.d.ts +0 -23
  206. package/frontend/dist/ui/table.js +113 -119
  207. package/frontend/dist/ui/tabs.d.ts +3 -19
  208. package/frontend/dist/ui/tabs.js +35 -29
  209. package/frontend/dist/ui/text.d.ts +0 -8
  210. package/frontend/dist/ui/text.js +20 -25
  211. package/frontend/dist/ui/title.d.ts +0 -15
  212. package/frontend/dist/ui/title.js +39 -45
  213. package/frontend/dist/ui/ui.d.ts +0 -2
  214. package/frontend/dist/ui/ui.js +0 -2
  215. package/frontend/dist/ui/view.d.ts +3 -17
  216. package/frontend/dist/ui/view.js +27 -32
  217. package/frontend/dist/volt.d.ts +2 -1
  218. package/frontend/dist/volt.js +3 -1
  219. package/frontend/examples/dashboard/dashboard.ts +774 -0
  220. package/frontend/examples/theme/theme.ts +58 -0
  221. package/frontend/src/css/volt.css +5 -0
  222. package/frontend/src/elements/base.ts +767 -545
  223. package/frontend/src/elements/module.ts +90 -29
  224. package/frontend/src/elements/register_element.ts +24 -0
  225. package/frontend/src/modules/auth.ts +7 -6
  226. package/frontend/src/modules/color.ts +348 -0
  227. package/frontend/src/modules/colors.ts +468 -449
  228. package/frontend/src/modules/cookies.ts +1 -0
  229. package/frontend/src/modules/events.ts +1 -0
  230. package/frontend/src/modules/google.ts +1 -0
  231. package/frontend/src/modules/meta.ts +2 -1
  232. package/frontend/src/modules/mutex.ts +2 -4
  233. package/frontend/src/modules/paddle.ts +21 -20
  234. package/frontend/src/modules/scheme.ts +4 -3
  235. package/frontend/src/modules/statics.ts +2 -1
  236. package/frontend/src/modules/support.ts +3 -2
  237. package/frontend/src/modules/theme.ts +413 -0
  238. package/frontend/src/modules/themes.ts +2 -1
  239. package/frontend/src/modules/user.ts +12 -11
  240. package/frontend/src/modules/utils.ts +125 -2
  241. package/frontend/src/ui/border_button.ts +41 -37
  242. package/frontend/src/ui/button.ts +33 -32
  243. package/frontend/src/ui/canvas.ts +5 -2
  244. package/frontend/src/ui/checkbox.ts +21 -22
  245. package/frontend/src/ui/code.ts +92 -86
  246. package/frontend/src/ui/context_menu.ts +7 -5
  247. package/frontend/src/ui/css.ts +1 -1
  248. package/frontend/src/ui/divider.ts +15 -10
  249. package/frontend/src/ui/dropdown.ts +38 -21
  250. package/frontend/src/ui/for_each.ts +9 -8
  251. package/frontend/src/ui/form.ts +26 -21
  252. package/frontend/src/ui/frame_modes.ts +13 -17
  253. package/frontend/src/ui/google_map.ts +15 -13
  254. package/frontend/src/ui/gradient.ts +9 -8
  255. package/frontend/src/ui/image.ts +108 -86
  256. package/frontend/src/ui/input.ts +145 -144
  257. package/frontend/src/ui/link.ts +25 -23
  258. package/frontend/src/ui/list.ts +12 -6
  259. package/frontend/src/ui/loader_button.ts +26 -25
  260. package/frontend/src/ui/loaders.ts +12 -11
  261. package/frontend/src/ui/popup.ts +168 -14
  262. package/frontend/src/ui/pseudo.ts +5 -3
  263. package/frontend/src/ui/scroller.ts +303 -294
  264. package/frontend/src/ui/slider.ts +15 -10
  265. package/frontend/src/ui/spacer.ts +14 -11
  266. package/frontend/src/ui/span.ts +6 -2
  267. package/frontend/src/ui/stack.ts +196 -183
  268. package/frontend/src/ui/steps.ts +38 -22
  269. package/frontend/src/ui/style.ts +7 -4
  270. package/frontend/src/ui/switch.ts +16 -11
  271. package/frontend/src/ui/table.ts +42 -34
  272. package/frontend/src/ui/tabs.ts +20 -19
  273. package/frontend/src/ui/text.ts +12 -11
  274. package/frontend/src/ui/title.ts +22 -20
  275. package/frontend/src/ui/ui.ts +0 -2
  276. package/frontend/src/ui/view.ts +20 -19
  277. package/frontend/src/volt.ts +3 -1
  278. package/frontend/{compile.js → tools/compile.old.js} +2 -2
  279. package/frontend/tools/embed_scripts.js +69 -0
  280. package/frontend/tsconfig.json +26 -0
  281. package/package.json +8 -8
  282. package/frontend/dist/ui/theme.d.ts +0 -25
  283. package/frontend/exports.json +0 -1340
  284. package/frontend/src/modules/date.js +0 -535
  285. package/frontend/src/ui/color.ts +0 -117
  286. package/frontend/src/ui/theme.ts +0 -279
  287. /package/backend/src/{vinc.dev.js → vinc.dev.ts} +0 -0
@@ -57,4 +57,5 @@ export declare const Status: {
57
57
  two_factor_auth_required: number;
58
58
  get_description(status: number): string;
59
59
  };
60
+ export { Status as status };
60
61
  export default Status;
@@ -193,4 +193,5 @@ export const Status = {
193
193
  }
194
194
  }
195
195
  };
196
+ export { Status as status }; // lowercase export for compatibility
196
197
  export default Status;
@@ -55,12 +55,14 @@ export declare class Stream {
55
55
  data?: any;
56
56
  compress?: boolean;
57
57
  }): this;
58
- error({ status, headers, body, data, compress }?: {
58
+ error({ message, type, invalid_fields, status, headers, compress, data, }: {
59
+ message: string;
60
+ type?: string;
61
+ invalid_fields?: Record<string, string>;
59
62
  status?: number;
60
63
  headers?: Record<string, any>;
61
- body?: any;
62
- data?: any;
63
64
  compress?: boolean;
65
+ data?: any[] | Record<string, any>;
64
66
  }): this;
65
67
  set_header(name: string, value: any): this;
66
68
  set_headers(headers?: Record<string, any>): this;
@@ -664,6 +664,7 @@ export class Stream {
664
664
  * stream.send({status: 200, data: "Hello World!"});
665
665
  */
666
666
  send({ status = 200, headers = {}, body = null, data = null, compress = false } = {}) {
667
+ compress = false; // @todo @tmp
667
668
  // Copy body.
668
669
  if (data != null) {
669
670
  body = data;
@@ -688,12 +689,12 @@ export class Stream {
688
689
  this.res_headers["Content-Type"] = "application/json";
689
690
  body = JSON.stringify(body);
690
691
  }
691
- // Respond.
692
- stream.respond(this.res_headers);
693
692
  // Compress.
694
693
  if (compress) {
695
694
  body = zlib.gzipSync(body, { level: zlib.constants.Z_BEST_COMPRESSION });
696
695
  }
696
+ // Respond.
697
+ stream.respond(this.res_headers);
697
698
  // End.
698
699
  if (body != null) {
699
700
  stream.end(Buffer.from(body));
@@ -805,8 +806,16 @@ export class Stream {
805
806
  * ...
806
807
  * stream.error({data: "Some error occured"});
807
808
  */
808
- error({ status = 500, headers = {}, body = null, data = null, compress = false } = {}) {
809
- return this.send({ status: status, headers: headers, body: body ?? data, compress: compress });
809
+ error({ message, type = "APIError", invalid_fields = {}, status = 500, headers = {}, compress = false, data = undefined, }) {
810
+ return this.send({ status: status, headers: headers, compress: compress, body: {
811
+ error: {
812
+ type,
813
+ message,
814
+ status,
815
+ invalid_fields,
816
+ },
817
+ data,
818
+ } });
810
819
  }
811
820
  // Set headers.
812
821
  /* @docs:
@@ -55,7 +55,7 @@ export declare class Users {
55
55
  _create_user_cookie(stream: Stream, uid: string): Promise<void>;
56
56
  _create_detailed_user_cookie(stream: Stream, uid: string): Promise<void>;
57
57
  _reset_cookies(stream: Stream): void;
58
- _initialize(): void;
58
+ _initialize(): Promise<void>;
59
59
  uid_exists(uid: string): Promise<boolean>;
60
60
  username_exists(username: string): Promise<boolean>;
61
61
  email_exists(email: string): Promise<boolean>;
@@ -4,11 +4,11 @@
4
4
  */
5
5
  // ---------------------------------------------------------
6
6
  // Imports.
7
- import { vlib } from "/Users/administrator/persistance/private/dev/vinc/volt/backend/./src/vinc.dev.js";
7
+ import { vlib } from "@vinc";
8
8
  import * as utils from "./utils.js";
9
9
  import * as Mail from "./plugins/mail.js";
10
10
  import { Status } from "./status.js";
11
- const { FrontendError } = utils;
11
+ const { APIError } = utils;
12
12
  import { logger } from "./logger.js";
13
13
  const log_source = logger.LogSource("Users");
14
14
  // interface Server {
@@ -270,14 +270,14 @@ export class Users {
270
270
  // ---------------------------------------------------------
271
271
  // Initialization (private).
272
272
  // Initialize.
273
- _initialize() {
273
+ async _initialize() {
274
274
  // Database collections.
275
- this._tokens_db = this.server.db.create_uid_collection("_tokens");
276
- this._users_db = this.server.db.create_uid_collection("_users");
275
+ this._tokens_db = await this.server.db.create_uid_collection("_tokens");
276
+ this._users_db = await this.server.db.create_uid_collection("_users");
277
277
  // Public database collections.
278
- this.public = this.server.db.create_uid_collection("_users_public");
279
- this.protected = this.server.db.create_uid_collection("_users_protected");
280
- this.private = this.server.db.create_uid_collection("_users_private");
278
+ this.public = await this.server.db.create_uid_collection("_users_public");
279
+ this.protected = await this.server.db.create_uid_collection("_users_protected");
280
+ this.private = await this.server.db.create_uid_collection("_users_private");
281
281
  // ---------------------------------------------------------
282
282
  // Default auth endpoints.
283
283
  this.server.endpoint(
@@ -331,26 +331,33 @@ export class Users {
331
331
  username_err = err;
332
332
  }
333
333
  if (email_err && username_err) {
334
- return stream.error({ status: Status.bad_request, data: { error: email_err.message } });
334
+ return stream.error({
335
+ status: Status.bad_request,
336
+ type: "InvalidParams",
337
+ message: email_err.message,
338
+ });
335
339
  }
336
340
  try {
337
341
  password = stream.param("password");
338
342
  }
339
343
  catch (err) {
340
- return stream.error({ status: Status.bad_request, data: { error: err.message } });
344
+ return stream.error({
345
+ status: Status.bad_request,
346
+ type: "InvalidParams",
347
+ message: err.message,
348
+ });
341
349
  }
342
350
  // Get uid.
343
351
  if (email) {
344
352
  if ((uid = await this.get_uid_by_email(email)) == null) {
345
353
  return stream.error({
346
354
  status: Status.unauthorized,
347
- data: {
348
- error: "Unauthorized.",
349
- invalid_fields: {
350
- "email": "Invalid or unrecognized email",
351
- "password": "Invalid or unrecognized password",
352
- },
353
- }
355
+ type: "Unauthorized",
356
+ message: "Unauthorized.",
357
+ invalid_fields: {
358
+ "email": "Invalid or unrecognized email",
359
+ "password": "Invalid or unrecognized password",
360
+ },
354
361
  });
355
362
  }
356
363
  }
@@ -358,13 +365,12 @@ export class Users {
358
365
  if ((uid = await this.get_uid(username)) == null) {
359
366
  return stream.error({
360
367
  status: Status.unauthorized,
361
- data: {
362
- error: "Unauthorized.",
363
- invalid_fields: {
364
- "username": "Invalid or unrecognized username",
365
- "password": "Invalid or unrecognized password",
366
- },
367
- }
368
+ type: "Unauthorized",
369
+ message: "Unauthorized.",
370
+ invalid_fields: {
371
+ "username": "Invalid or unrecognized username",
372
+ "password": "Invalid or unrecognized password",
373
+ },
368
374
  });
369
375
  }
370
376
  }
@@ -470,22 +476,27 @@ export class Users {
470
476
  if (error) {
471
477
  return stream.error({
472
478
  status: Status.bad_request,
473
- data: {
474
- error,
475
- invalid_fields,
476
- }
479
+ type: "InvalidParams",
480
+ message: error,
481
+ invalid_fields: invalid_fields ?? undefined,
477
482
  });
478
483
  }
479
484
  // Verify username and email.
480
485
  if (await this.username_exists(params.username)) {
481
- const e = new FrontendError(`Username "${params.username}" is already registered.`);
482
- e.invalid_fields = { "username": "Username is already registered" };
483
- throw e;
486
+ throw new APIError({
487
+ type: "UsernameAlreadyExists",
488
+ message: `Username "${params.username}" is already registered.`,
489
+ status: Status.bad_request,
490
+ invalid_fields: { "username": "Username is already registered" },
491
+ });
484
492
  }
485
493
  if (await this.email_exists(params.email)) {
486
- const e = new FrontendError(`Email "${params.email}" is already registered.`);
487
- e.invalid_fields = { "email": "Email is already registered" };
488
- throw e;
494
+ throw new APIError({
495
+ type: "EmailAlreadyExists",
496
+ message: `Email "${params.email}" is already registered.`,
497
+ status: Status.bad_request,
498
+ invalid_fields: { "email": "Email is already registered" }
499
+ });
489
500
  }
490
501
  // Verify 2fa.
491
502
  if (this.server.enable_2fa) {
@@ -536,10 +547,9 @@ export class Users {
536
547
  catch (err) {
537
548
  return stream.error({
538
549
  status: Status.bad_request,
539
- data: {
540
- error: err.message,
541
- invalid_fields: err.invalid_fields || {},
542
- }
550
+ type: "InvalidParams",
551
+ message: err.message,
552
+ invalid_fields: err.invalid_fields || {},
543
553
  });
544
554
  }
545
555
  // Sign in.
@@ -567,19 +577,17 @@ export class Users {
567
577
  }
568
578
  // Check uid.
569
579
  if (uid == null) {
570
- return stream.error({ status: Status.forbidden, data: { error: "Permission denied." } });
580
+ return stream.error({ status: Status.forbidden, message: "Permission denied." });
571
581
  }
572
582
  // Verify.
573
583
  const err = await this.verify_2fa(uid, params.code);
574
584
  if (err) {
575
585
  return stream.error({
576
586
  status: Status.forbidden,
577
- data: {
578
- error: "Permission denied.",
579
- invalid_fields: {
580
- "code": err,
581
- },
582
- }
587
+ message: "Permission denied.",
588
+ invalid_fields: {
589
+ "code": err,
590
+ },
583
591
  });
584
592
  }
585
593
  // Set activated.
@@ -607,28 +615,24 @@ export class Users {
607
615
  if (error) {
608
616
  return stream.error({
609
617
  status: Status.bad_request,
610
- data: {
611
- error: error,
612
- invalid_fields,
613
- }
618
+ message: error,
619
+ invalid_fields: invalid_fields ?? undefined,
614
620
  });
615
621
  }
616
622
  // Get uid.
617
623
  let uid;
618
624
  if ((uid = await this.get_uid_by_email(params.email)) == null) {
619
- return stream.error({ status: Status.forbidden, data: { error: "Invalid email." } });
625
+ return stream.error({ status: Status.forbidden, message: "Invalid email." });
620
626
  }
621
627
  // Verify 2fa.
622
628
  const err = await this.verify_2fa(uid, params.code);
623
629
  if (err) {
624
630
  return stream.error({
625
631
  status: Status.forbidden,
626
- data: {
627
- error: "Invalid 2FA code.",
628
- invalid_fields: {
629
- "code": "Invalid code"
630
- },
631
- }
632
+ message: "Invalid 2FA code.",
633
+ invalid_fields: {
634
+ "code": "Invalid code"
635
+ },
632
636
  });
633
637
  }
634
638
  // Set password.
@@ -674,6 +678,7 @@ export class Users {
674
678
  {
675
679
  method: "POST",
676
680
  endpoint: "/volt/user",
681
+ content_type: "application/json",
677
682
  authenticated: true,
678
683
  rate_limit: "global",
679
684
  callback: async (stream) => {
@@ -686,6 +691,7 @@ export class Users {
686
691
  {
687
692
  method: "POST",
688
693
  endpoint: "/volt/user/change_password",
694
+ content_type: "application/json",
689
695
  authenticated: true,
690
696
  rate_limit: "global",
691
697
  params: {
@@ -698,12 +704,10 @@ export class Users {
698
704
  if (await this.verify_password(stream.uid, params.current_password) !== true) {
699
705
  return stream.error({
700
706
  status: Status.unauthorized,
701
- data: {
702
- error: "Incorrect password.",
703
- invalid_fields: {
704
- current_password: "Incorrect password.",
705
- }
706
- },
707
+ message: "Incorrect password.",
708
+ invalid_fields: {
709
+ current_password: "Incorrect password.",
710
+ }
707
711
  });
708
712
  }
709
713
  // Verify new password.
@@ -711,10 +715,8 @@ export class Users {
711
715
  if (error) {
712
716
  return stream.error({
713
717
  status: Status.bad_request,
714
- data: {
715
- error: error,
716
- invalid_fields,
717
- }
718
+ message: error,
719
+ invalid_fields: invalid_fields ?? undefined,
718
720
  });
719
721
  }
720
722
  // Set password.
@@ -730,6 +732,7 @@ export class Users {
730
732
  {
731
733
  method: "DELETE",
732
734
  endpoint: "/volt/user",
735
+ content_type: "application/json",
733
736
  authenticated: true,
734
737
  rate_limit: "global",
735
738
  callback: async (stream) => {
@@ -748,6 +751,7 @@ export class Users {
748
751
  {
749
752
  method: "POST",
750
753
  endpoint: "/volt/user/api_key",
754
+ content_type: "application/json",
751
755
  authenticated: true,
752
756
  rate_limit: "global",
753
757
  callback: async (stream) => {
@@ -763,6 +767,7 @@ export class Users {
763
767
  {
764
768
  method: "DELETE",
765
769
  endpoint: "/volt/user/api_key",
770
+ content_type: "application/json",
766
771
  authenticated: true,
767
772
  rate_limit: "global",
768
773
  callback: async (stream) => {
@@ -777,6 +782,7 @@ export class Users {
777
782
  {
778
783
  method: "GET",
779
784
  endpoint: "/volt/user/data",
785
+ content_type: "application/json",
780
786
  authenticated: true,
781
787
  rate_limit: "global",
782
788
  params: {
@@ -794,6 +800,7 @@ export class Users {
794
800
  {
795
801
  method: "POST",
796
802
  endpoint: "/volt/user/data",
803
+ content_type: "application/json",
797
804
  authenticated: true,
798
805
  rate_limit: "global",
799
806
  params: {
@@ -812,6 +819,7 @@ export class Users {
812
819
  {
813
820
  method: "DELETE",
814
821
  endpoint: "/volt/user/data",
822
+ content_type: "application/json",
815
823
  authenticated: true,
816
824
  rate_limit: "global",
817
825
  params: {
@@ -831,6 +839,7 @@ export class Users {
831
839
  {
832
840
  method: "GET",
833
841
  endpoint: "/volt/user/data/protected",
842
+ content_type: "application/json",
834
843
  authenticated: true,
835
844
  rate_limit: "global",
836
845
  params: {
@@ -884,7 +893,7 @@ export class Users {
884
893
  last_name = stream.param("last_name");
885
894
  }
886
895
  catch (err) {
887
- return stream.error({ status: Status.bad_request, data: { error: err.message } });
896
+ return stream.error({ status: Status.bad_request, message: err.message });
888
897
  }
889
898
  }
890
899
  else {
@@ -1106,14 +1115,20 @@ export class Users {
1106
1115
  // Check if username & email already exist.
1107
1116
  if (_check_username_email) {
1108
1117
  if (await this.username_exists(username)) {
1109
- const e = new FrontendError(`Username "${username}" is already registered.`);
1110
- e.invalid_fields = { "username": "Username is already registered" };
1111
- throw e;
1118
+ throw new APIError({
1119
+ type: "UsernameAlreadyExists",
1120
+ message: `Username "${username}" is already registered.`,
1121
+ status: Status.bad_request,
1122
+ invalid_fields: { "username": "Username is already registered" },
1123
+ });
1112
1124
  }
1113
1125
  if (await this.email_exists(email)) {
1114
- const e = new FrontendError(`Email "${email}" is already registered.`);
1115
- e.invalid_fields = { "email": "Email is already registered" };
1116
- throw e;
1126
+ throw new APIError({
1127
+ type: "EmailAlreadyExists",
1128
+ message: `Email "${email}" is already registered.`,
1129
+ status: Status.bad_request,
1130
+ invalid_fields: { "email": "Email is already registered" }
1131
+ });
1117
1132
  }
1118
1133
  }
1119
1134
  // Generate a uid.
@@ -1,15 +1,22 @@
1
- export declare class FrontendError extends Error {
2
- name: string;
3
- status?: number;
4
- data?: any;
1
+ import type { Stream } from "./stream.js";
2
+ /**
3
+ * The API error class is used to throw an error that will be presented to the user. All other errors will result in an internal server error response without the error's message.
4
+ */
5
+ export declare class APIError extends Error {
6
+ type: string;
7
+ status: number;
8
+ data?: any[] | Record<string, any>;
5
9
  invalid_fields: Record<string, string>;
6
- constructor(message: string, status?: number, data?: any, invalid_fields?: Record<string, string>);
7
- }
8
- export declare class APIError extends FrontendError {
9
- constructor(message: string, status?: number, data?: any, invalid_fields?: Record<string, string>);
10
+ constructor({ type, message, status, data, invalid_fields }: {
11
+ type?: string;
12
+ message: string;
13
+ status?: number;
14
+ data?: any;
15
+ invalid_fields?: Record<string, string>;
16
+ });
17
+ serve(stream: Stream): this;
10
18
  }
11
19
  interface UtilsInt {
12
- "FrontendError": typeof FrontendError;
13
20
  "APIError": typeof APIError;
14
21
  clean_endpoint(endpoint: undefined): undefined;
15
22
  clean_endpoint(endpoint: RegExp): RegExp;
@@ -24,4 +31,5 @@ interface UtilsInt {
24
31
  set_compiled_cache(path: any, data: string, hash: string): void;
25
32
  }
26
33
  export declare const Utils: UtilsInt;
34
+ export { Utils as utils };
27
35
  export default Utils;
@@ -2,81 +2,39 @@
2
2
  * Author: Daan van den Bergh
3
3
  * Copyright: © 2022 - 2024 Daan van den Bergh.
4
4
  */
5
- import { vlib } from "/Users/administrator/persistance/private/dev/vinc/volt/backend/./src/vinc.dev.js";
5
+ import { vlib } from "@vinc";
6
+ import { Status } from "./status.js";
6
7
  // ---------------------------------------------------------
7
8
  // Utils.
8
- /* @docs:
9
- * @nav: Backend
10
- @parent: Utils
11
- @chapter: Exceptions
12
- @title: Frontend Error
13
- @description:
14
- The frontend error class can be used to throw an error that will be presented to the user. All other errors will result in an internal server error response without the error's message.
15
- @usage:
16
- throw new volt.FrontendError("Some error occured.");
17
- throw new volt.FrontendError("Bad request.", volt.status.bad_request);
18
- @param:
19
- @name: message
20
- @descr: The error message.
21
- @type: string
22
- @param:
23
- @name: status
24
- @descr: The http error status.
25
- @type: number
26
- @param:
27
- @name: data
28
- @descr: The error body data.
29
- @type: any
9
+ /**
10
+ * The API error class is used to throw an error that will be presented to the user. All other errors will result in an internal server error response without the error's message.
30
11
  */
31
- export class FrontendError extends Error {
32
- name;
12
+ export class APIError extends Error {
13
+ type;
33
14
  status;
34
15
  data;
35
- invalid_fields = {};
36
- constructor(message, status, data, invalid_fields) {
16
+ invalid_fields;
17
+ constructor({ type = "APIError", message, status, data, invalid_fields }) {
37
18
  super(message);
38
- this.name = "FrontendError";
39
- this.status = status;
19
+ this.name = "APIError";
20
+ this.type = type;
21
+ this.status = status ?? Status.internal_server_error;
40
22
  this.data = data;
41
- if (invalid_fields !== undefined) {
42
- this;
43
- invalid_fields = invalid_fields;
44
- }
23
+ this.invalid_fields = invalid_fields ?? {};
45
24
  }
46
- }
47
- /* @docs:
48
- * @nav: Backend
49
- @parent: Utils
50
- @chapter: Exceptions
51
- @title: API Error
52
- @description:
53
- The api error class can be used to throw an error that will be presented to the user. All other errors will result in an internal server error response without the error's message.
54
- @usage:
55
- throw new volt.APIError("Some error occured.");
56
- throw new volt.APIError("Bad request.", volt.status.bad_request);
57
- @param:
58
- @name: message
59
- @descr: The error message.
60
- @type: string
61
- @param:
62
- @name: status
63
- @descr: The http error status.
64
- @type: number
65
- @param:
66
- @name: data
67
- @descr: The error body data.
68
- @type: any
69
- */
70
- export class APIError extends FrontendError {
71
- constructor(message, status, data, invalid_fields) {
72
- super(message, status, data, invalid_fields);
73
- this.name = "APIError";
25
+ serve(stream) {
26
+ stream.error({
27
+ status: this.status ?? Status.internal_server_error,
28
+ headers: { "Content-Type": "application/json" },
29
+ message: this.message,
30
+ type: this.type,
31
+ invalid_fields: this.invalid_fields,
32
+ });
33
+ return this;
74
34
  }
75
35
  }
76
36
  // Implementation
77
37
  export const Utils = {
78
- // An error that may be shown to the frontend user.
79
- "FrontendError": FrontendError,
80
38
  // An error that may be shown to the frontend user.
81
39
  "APIError": APIError,
82
40
  // Clean an endpoint url.
@@ -321,4 +279,5 @@ export const Utils = {
321
279
  new vlib.Path(path.str() + '.hash').save_sync(hash);
322
280
  },
323
281
  };
282
+ export { Utils as utils }; // lowercase export for compatibility
324
283
  export default Utils;
@@ -23,7 +23,7 @@ export declare class View {
23
23
  is_js_ts_view: boolean;
24
24
  html?: string | Buffer;
25
25
  raw_html?: string | Buffer;
26
- bundle: any;
26
+ _bundle: any;
27
27
  payments?: string | undefined;
28
28
  min_device_width?: number;
29
29
  _server?: any;
@@ -45,7 +45,7 @@ export declare class View {
45
45
  _src?: string;
46
46
  });
47
47
  _initialize(server: any, endpoint: any): void;
48
- _bundle_ts(dist_path: string, bundle?: any): Promise<any>;
48
+ _dynamic_bundle(): Promise<void>;
49
49
  _build_html(): Promise<void>;
50
50
  _serve(stream: any, status_code?: number): void;
51
51
  }