@vandenberghinc/volt 1.1.12 → 1.1.14

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 (38) hide show
  1. package/backend/dist/cjs/database.d.ts +30 -4
  2. package/backend/dist/cjs/database.js +76 -1
  3. package/backend/dist/cjs/endpoint.js +1 -1
  4. package/backend/dist/cjs/payments/paddle.js +2 -2
  5. package/backend/dist/cjs/server.js +0 -8
  6. package/backend/dist/cjs/users.js +5 -5
  7. package/backend/dist/cjs/utils.d.ts +17 -3
  8. package/backend/dist/cjs/utils.js +43 -5
  9. package/backend/dist/cjs/volt.d.ts +1 -1
  10. package/backend/dist/cjs/volt.js +1 -1
  11. package/backend/dist/esm/database.d.ts +30 -4
  12. package/backend/dist/esm/database.js +77 -4
  13. package/backend/dist/esm/endpoint.js +2 -2
  14. package/backend/dist/esm/payments/paddle.js +3 -3
  15. package/backend/dist/esm/server.js +0 -8
  16. package/backend/dist/esm/users.js +5 -5
  17. package/backend/dist/esm/utils.d.ts +17 -3
  18. package/backend/dist/esm/utils.js +40 -3
  19. package/backend/dist/esm/volt.d.ts +1 -1
  20. package/backend/dist/esm/volt.js +1 -1
  21. package/backend/dist/esm-dev/database.d.ts +30 -4
  22. package/backend/dist/esm-dev/database.js +77 -4
  23. package/backend/dist/esm-dev/endpoint.js +2 -2
  24. package/backend/dist/esm-dev/payments/paddle.js +3 -3
  25. package/backend/dist/esm-dev/server.js +0 -8
  26. package/backend/dist/esm-dev/users.js +5 -5
  27. package/backend/dist/esm-dev/utils.d.ts +17 -3
  28. package/backend/dist/esm-dev/utils.js +40 -3
  29. package/backend/dist/esm-dev/volt.d.ts +1 -1
  30. package/backend/dist/esm-dev/volt.js +1 -1
  31. package/backend/src/database.ts +103 -4
  32. package/backend/src/endpoint.ts +2 -2
  33. package/backend/src/payments/paddle.ts +3 -3
  34. package/backend/src/server.ts +1 -10
  35. package/backend/src/users.ts +5 -5
  36. package/backend/src/utils.ts +43 -4
  37. package/backend/src/volt.ts +1 -1
  38. package/package.json +1 -1
@@ -13,7 +13,7 @@ type IndexOptions = (BaseOptions & {
13
13
  key?: never;
14
14
  keys: string[];
15
15
  });
16
- declare class Collection {
16
+ export declare class Collection {
17
17
  static chunk_size: number;
18
18
  static constructor_scheme: {
19
19
  name: string;
@@ -103,7 +103,7 @@ declare class Collection {
103
103
  /** Write bulk operations. */
104
104
  bulk_operations(operations?: any[]): Promise<any>;
105
105
  }
106
- declare class UIDCollection {
106
+ export declare class UIDCollection {
107
107
  private _col;
108
108
  col: MongoCollection;
109
109
  constructor(name: string, collection: MongoCollection, indexes?: IndexOptions[], ttl?: number | null);
@@ -144,7 +144,7 @@ declare class UIDCollection {
144
144
  /** Write bulk operations. */
145
145
  bulk_operations(operations?: any[]): Promise<any>;
146
146
  }
147
- declare class Database {
147
+ export declare class Database {
148
148
  static constructor_scheme: {
149
149
  uri: {
150
150
  type: string;
@@ -334,4 +334,30 @@ declare class Database {
334
334
  } | string): Promise<UIDCollection>;
335
335
  get_collections(): Promise<string[]>;
336
336
  }
337
- export { Collection, UIDCollection, Database };
337
+ /** Objective document class. */
338
+ export declare class UIDDocument<DocumentOptions = any> {
339
+ col: UIDCollection;
340
+ data?: DocumentOptions;
341
+ uid: string;
342
+ path: string | Record<string, any>;
343
+ chunked: boolean;
344
+ error_document_name: string;
345
+ constructor({ col, uid, path, data, chunked, error_document_name }: {
346
+ col: UIDCollection;
347
+ uid: string;
348
+ path: string | Record<string, any>;
349
+ data?: DocumentOptions;
350
+ chunked?: boolean;
351
+ error_document_name?: string;
352
+ });
353
+ /** As database document. */
354
+ document(): undefined | DocumentOptions;
355
+ /** Check if a project exists. */
356
+ exists(): Promise<boolean>;
357
+ /** Load a project from the database */
358
+ load(): Promise<DocumentOptions>;
359
+ try_load(): Promise<undefined | DocumentOptions>;
360
+ /** Save the project to the database */
361
+ save(): Promise<void>;
362
+ }
363
+ export {};
@@ -4,14 +4,16 @@
4
4
  * Copyright: © 2022 - 2024 Daan van den Bergh.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Database = exports.UIDCollection = exports.Collection = void 0;
7
+ exports.UIDDocument = exports.Database = exports.UIDCollection = exports.Collection = void 0;
8
8
  // ---------------------------------------------------------
9
9
  // Libraries.
10
10
  const child_process_1 = require("child_process");
11
11
  const bson_1 = require("bson");
12
12
  const mongodb_1 = require("mongodb");
13
13
  const logger_js_1 = require("./logger.js");
14
+ const status_js_1 = require("./status.js");
14
15
  const _vinc_1 = require("./vinc.js");
16
+ const utils_js_1 = require("./utils.js");
15
17
  const log_source = new logger_js_1.LogSource("Database");
16
18
  // ---------------------------------------------------------
17
19
  // Collection.
@@ -2018,3 +2020,76 @@ class Database {
2018
2020
  }
2019
2021
  }
2020
2022
  exports.Database = Database;
2023
+ // ---------------------------------------------------------
2024
+ /** Objective document class. */
2025
+ class UIDDocument {
2026
+ col;
2027
+ data;
2028
+ uid;
2029
+ path;
2030
+ chunked;
2031
+ error_document_name;
2032
+ constructor({ col, uid, path, data, chunked = false, error_document_name = "document" }) {
2033
+ this.col = col;
2034
+ this.uid = uid;
2035
+ this.path = path;
2036
+ this.data = data;
2037
+ this.chunked = chunked;
2038
+ this.error_document_name = error_document_name;
2039
+ }
2040
+ /** As database document. */
2041
+ document() {
2042
+ return this.data;
2043
+ }
2044
+ /** Check if a project exists. */
2045
+ async exists() {
2046
+ return await this.col.exists(this.uid, this.path);
2047
+ }
2048
+ /** Load a project from the database */
2049
+ async load() {
2050
+ const data = await this.col.load(this.uid, this.path, { chunked: this.chunked });
2051
+ if (!data) {
2052
+ let id = this.uid + "/";
2053
+ if (typeof this.path === "string") {
2054
+ id += this.path;
2055
+ }
2056
+ else {
2057
+ id += Object.values(this.path).join("@");
2058
+ }
2059
+ throw new utils_js_1.InternalError({
2060
+ type: "DocumentNotFound",
2061
+ message: `Requested ${this.error_document_name} "${id}" does not exist.`,
2062
+ status: status_js_1.Status.bad_request,
2063
+ });
2064
+ }
2065
+ this.data = data;
2066
+ return this.data;
2067
+ }
2068
+ async try_load() {
2069
+ const data = await this.col.load(this.uid, this.path, { chunked: this.chunked });
2070
+ if (!data) {
2071
+ return undefined;
2072
+ }
2073
+ this.data = data;
2074
+ return this.data;
2075
+ }
2076
+ /** Save the project to the database */
2077
+ async save() {
2078
+ if (!this.data) {
2079
+ let id = this.uid + "/";
2080
+ if (typeof this.path === "string") {
2081
+ id += this.path;
2082
+ }
2083
+ else {
2084
+ id += Object.values(this.path).join("@");
2085
+ }
2086
+ throw new utils_js_1.InternalError({
2087
+ type: "DocumentNotFound",
2088
+ message: `Document "${id}" is not loaded yet.`,
2089
+ status: status_js_1.Status.bad_request,
2090
+ });
2091
+ }
2092
+ await this.col.save(this.uid, this.path, this.data, { chunked: this.chunked });
2093
+ }
2094
+ }
2095
+ exports.UIDDocument = UIDDocument;
@@ -461,7 +461,7 @@ class Endpoint {
461
461
  }
462
462
  }
463
463
  catch (err) {
464
- if (err instanceof utils_js_1.APIError) {
464
+ if (err instanceof utils_js_1.ExternalError || err instanceof utils_js_1.InternalError) {
465
465
  err.serve(stream);
466
466
  }
467
467
  else {
@@ -624,7 +624,7 @@ class Paddle {
624
624
  }
625
625
  // Cancel.
626
626
  if (subscription.status !== "active") {
627
- throw new utils_js_1.APIError({
627
+ throw new utils_js_1.ExternalError({
628
628
  type: "NoActiveSubscriptionError",
629
629
  message: `This subscription is already cancelled and will become inactive at the end of the billing period.`,
630
630
  status: status_js_1.Status.bad_request,
@@ -1990,7 +1990,7 @@ class Paddle {
1990
1990
  }
1991
1991
  });
1992
1992
  if (_throw_no_cancelled_err && cancelled.length === 0) {
1993
- throw new utils_js_1.APIError({
1993
+ throw new utils_js_1.ExternalError({
1994
1994
  type: "NoCancellableSubscriptions",
1995
1995
  message: "No cancellable subscriptions found.",
1996
1996
  status: status_js_1.Status.bad_request,
@@ -974,14 +974,6 @@ class Server {
974
974
  // this.ts = ts as TypeScriptConfig;
975
975
  this.endpoints = new Map();
976
976
  this.err_endpoints = new Map();
977
- // Assign based on localhost.
978
- // if (localhost) {
979
- // this.ip = "127.0.0.1";
980
- // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
981
- // } else if (!production && !localhost && ip == null) { // use argument ip not attr since that already has a default.
982
- // this.ip = vlib.Network.private_ip();
983
- // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
984
- // }
985
977
  /* @performance */ this.performance = new _vinc_1.vlib.Performance("Server performance");
986
978
  // Assign objects to server so it is easy to access.
987
979
  this.status = status_js_1.Status;
@@ -44,7 +44,7 @@ const _vinc_1 = require("./vinc.js");
44
44
  const utils = __importStar(require("./utils.js"));
45
45
  const Mail = __importStar(require("./plugins/mail.js"));
46
46
  const status_js_1 = require("./status.js");
47
- const { APIError } = utils;
47
+ const { ExternalError } = utils;
48
48
  const logger_js_1 = require("./logger.js");
49
49
  const log_source = logger_js_1.logger.LogSource("Users");
50
50
  // interface Server {
@@ -519,7 +519,7 @@ class Users {
519
519
  }
520
520
  // Verify username and email.
521
521
  if (await this.username_exists(params.username)) {
522
- throw new APIError({
522
+ throw new ExternalError({
523
523
  type: "UsernameAlreadyExists",
524
524
  message: `Username "${params.username}" is already registered.`,
525
525
  status: status_js_1.Status.bad_request,
@@ -527,7 +527,7 @@ class Users {
527
527
  });
528
528
  }
529
529
  if (await this.email_exists(params.email)) {
530
- throw new APIError({
530
+ throw new ExternalError({
531
531
  type: "EmailAlreadyExists",
532
532
  message: `Email "${params.email}" is already registered.`,
533
533
  status: status_js_1.Status.bad_request,
@@ -1151,7 +1151,7 @@ class Users {
1151
1151
  // Check if username & email already exist.
1152
1152
  if (_check_username_email) {
1153
1153
  if (await this.username_exists(username)) {
1154
- throw new APIError({
1154
+ throw new ExternalError({
1155
1155
  type: "UsernameAlreadyExists",
1156
1156
  message: `Username "${username}" is already registered.`,
1157
1157
  status: status_js_1.Status.bad_request,
@@ -1159,7 +1159,7 @@ class Users {
1159
1159
  });
1160
1160
  }
1161
1161
  if (await this.email_exists(email)) {
1162
- throw new APIError({
1162
+ throw new ExternalError({
1163
1163
  type: "EmailAlreadyExists",
1164
1164
  message: `Email "${email}" is already registered.`,
1165
1165
  status: status_js_1.Status.bad_request,
@@ -1,8 +1,8 @@
1
1
  import type { Stream } from "./stream.js";
2
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.
3
+ * The base class for internal and external errors.
4
4
  */
5
- export declare class APIError extends Error {
5
+ declare class BaseError extends Error {
6
6
  type: string;
7
7
  status: number;
8
8
  data?: any[] | Record<string, any>;
@@ -16,8 +16,22 @@ export declare class APIError extends Error {
16
16
  });
17
17
  serve(stream: Stream): this;
18
18
  }
19
+ /**
20
+ * Thrown external errors are presented to the user.
21
+ */
22
+ export declare class ExternalError extends BaseError {
23
+ constructor(args: ConstructorParameters<typeof BaseError>[0]);
24
+ serve(stream: Stream): this;
25
+ }
26
+ /**
27
+ * Thrown internal errors are not presented to the user, isntead an internal server error message is shown.
28
+ */
29
+ export declare class InternalError extends BaseError {
30
+ constructor(args: ConstructorParameters<typeof BaseError>[0]);
31
+ serve(stream: Stream): this;
32
+ }
19
33
  interface UtilsInt {
20
- "APIError": typeof APIError;
34
+ "APIError": typeof ExternalError;
21
35
  clean_endpoint(endpoint: undefined): undefined;
22
36
  clean_endpoint(endpoint: RegExp): RegExp;
23
37
  clean_endpoint(endpoint: string): string;
@@ -4,15 +4,15 @@
4
4
  * Copyright: © 2022 - 2024 Daan van den Bergh.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.utils = exports.Utils = exports.APIError = void 0;
7
+ exports.utils = exports.Utils = exports.InternalError = exports.ExternalError = void 0;
8
8
  const _vinc_1 = require("./vinc.js");
9
9
  const status_js_1 = require("./status.js");
10
10
  // ---------------------------------------------------------
11
11
  // Utils.
12
12
  /**
13
- * 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.
13
+ * The base class for internal and external errors.
14
14
  */
15
- class APIError extends Error {
15
+ class BaseError extends Error {
16
16
  type;
17
17
  status;
18
18
  data;
@@ -36,11 +36,49 @@ class APIError extends Error {
36
36
  return this;
37
37
  }
38
38
  }
39
- exports.APIError = APIError;
39
+ /**
40
+ * Thrown external errors are presented to the user.
41
+ */
42
+ class ExternalError extends BaseError {
43
+ constructor(args) {
44
+ args.type ??= "ExternalError";
45
+ super(args);
46
+ }
47
+ serve(stream) {
48
+ stream.error({
49
+ status: this.status ?? status_js_1.Status.internal_server_error,
50
+ headers: { "Content-Type": "application/json" },
51
+ message: this.message,
52
+ type: this.type,
53
+ invalid_fields: this.invalid_fields,
54
+ });
55
+ return this;
56
+ }
57
+ }
58
+ exports.ExternalError = ExternalError;
59
+ /**
60
+ * Thrown internal errors are not presented to the user, isntead an internal server error message is shown.
61
+ */
62
+ class InternalError extends BaseError {
63
+ constructor(args) {
64
+ args.type ??= "InternalError";
65
+ super(args);
66
+ }
67
+ serve(stream) {
68
+ stream.error({
69
+ status: status_js_1.Status.internal_server_error,
70
+ headers: { "Content-Type": "application/json" },
71
+ message: "Internal Server Error",
72
+ type: "InternalServerError",
73
+ });
74
+ return this;
75
+ }
76
+ }
77
+ exports.InternalError = InternalError;
40
78
  // Implementation
41
79
  exports.Utils = {
42
80
  // An error that may be shown to the frontend user.
43
- "APIError": APIError,
81
+ "APIError": ExternalError,
44
82
  // Clean an endpoint url.
45
83
  clean_endpoint(endpoint) {
46
84
  if (endpoint == null || endpoint instanceof RegExp) {
@@ -1,4 +1,4 @@
1
- export { APIError } from "./utils.js";
1
+ export { ExternalError as APIError } from "./utils.js";
2
2
  export * from "./status.js";
3
3
  export * from "./meta.js";
4
4
  export * from "./splash_screen.js";
@@ -45,7 +45,7 @@ exports.TypeScript = exports.Mail = exports.APIError = void 0;
45
45
  // Exports.
46
46
  // Create volt lib.
47
47
  var utils_js_1 = require("./utils.js");
48
- Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return utils_js_1.APIError; } });
48
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return utils_js_1.ExternalError; } });
49
49
  __exportStar(require("./status.js"), exports);
50
50
  __exportStar(require("./meta.js"), exports);
51
51
  __exportStar(require("./splash_screen.js"), exports);
@@ -13,7 +13,7 @@ type IndexOptions = (BaseOptions & {
13
13
  key?: never;
14
14
  keys: string[];
15
15
  });
16
- declare class Collection {
16
+ export declare class Collection {
17
17
  static chunk_size: number;
18
18
  static constructor_scheme: {
19
19
  name: string;
@@ -103,7 +103,7 @@ declare class Collection {
103
103
  /** Write bulk operations. */
104
104
  bulk_operations(operations?: any[]): Promise<any>;
105
105
  }
106
- declare class UIDCollection {
106
+ export declare class UIDCollection {
107
107
  private _col;
108
108
  col: MongoCollection;
109
109
  constructor(name: string, collection: MongoCollection, indexes?: IndexOptions[], ttl?: number | null);
@@ -144,7 +144,7 @@ declare class UIDCollection {
144
144
  /** Write bulk operations. */
145
145
  bulk_operations(operations?: any[]): Promise<any>;
146
146
  }
147
- declare class Database {
147
+ export declare class Database {
148
148
  static constructor_scheme: {
149
149
  uri: {
150
150
  type: string;
@@ -334,4 +334,30 @@ declare class Database {
334
334
  } | string): Promise<UIDCollection>;
335
335
  get_collections(): Promise<string[]>;
336
336
  }
337
- export { Collection, UIDCollection, Database };
337
+ /** Objective document class. */
338
+ export declare class UIDDocument<DocumentOptions = any> {
339
+ col: UIDCollection;
340
+ data?: DocumentOptions;
341
+ uid: string;
342
+ path: string | Record<string, any>;
343
+ chunked: boolean;
344
+ error_document_name: string;
345
+ constructor({ col, uid, path, data, chunked, error_document_name }: {
346
+ col: UIDCollection;
347
+ uid: string;
348
+ path: string | Record<string, any>;
349
+ data?: DocumentOptions;
350
+ chunked?: boolean;
351
+ error_document_name?: string;
352
+ });
353
+ /** As database document. */
354
+ document(): undefined | DocumentOptions;
355
+ /** Check if a project exists. */
356
+ exists(): Promise<boolean>;
357
+ /** Load a project from the database */
358
+ load(): Promise<DocumentOptions>;
359
+ try_load(): Promise<undefined | DocumentOptions>;
360
+ /** Save the project to the database */
361
+ save(): Promise<void>;
362
+ }
363
+ export {};
@@ -8,7 +8,9 @@ import { spawn } from "child_process";
8
8
  import { deserialize, serialize } from "bson";
9
9
  import { MongoClient, ServerApiVersion } from 'mongodb';
10
10
  import { logger, LogSource } from "./logger.js";
11
+ import { Status } from "./status.js";
11
12
  import { vlib } from "./vinc.js";
13
+ import { InternalError } from "./utils.js";
12
14
  const log_source = new LogSource("Database");
13
15
  // ---------------------------------------------------------
14
16
  // Collection.
@@ -25,7 +27,7 @@ const log_source = new LogSource("Database");
25
27
  @name: col
26
28
  @desc: The native mongodb collection.
27
29
  */
28
- class Collection {
30
+ export class Collection {
29
31
  // Static attributes.
30
32
  static chunk_size = 1024 * 1024 * 4; // 4MB chunks, lower is better for frequent updates.
31
33
  static constructor_scheme = {
@@ -744,7 +746,7 @@ class Collection {
744
746
  @name: col
745
747
  @desc: The native mongodb collection.
746
748
  */
747
- class UIDCollection {
749
+ export class UIDCollection {
748
750
  _col;
749
751
  col;
750
752
  constructor(name, collection, indexes = [], ttl = null) {
@@ -1127,7 +1129,7 @@ class UIDCollection {
1127
1129
  @desc: The MongoClient options.
1128
1130
  @type: null, object
1129
1131
  */
1130
- class Database {
1132
+ export class Database {
1131
1133
  static constructor_scheme = {
1132
1134
  uri: { type: "string", default: null },
1133
1135
  source: { type: "string", default: null },
@@ -2012,4 +2014,75 @@ class Database {
2012
2014
  });
2013
2015
  }
2014
2016
  }
2015
- export { Collection, UIDCollection, Database };
2017
+ // ---------------------------------------------------------
2018
+ /** Objective document class. */
2019
+ export class UIDDocument {
2020
+ col;
2021
+ data;
2022
+ uid;
2023
+ path;
2024
+ chunked;
2025
+ error_document_name;
2026
+ constructor({ col, uid, path, data, chunked = false, error_document_name = "document" }) {
2027
+ this.col = col;
2028
+ this.uid = uid;
2029
+ this.path = path;
2030
+ this.data = data;
2031
+ this.chunked = chunked;
2032
+ this.error_document_name = error_document_name;
2033
+ }
2034
+ /** As database document. */
2035
+ document() {
2036
+ return this.data;
2037
+ }
2038
+ /** Check if a project exists. */
2039
+ async exists() {
2040
+ return await this.col.exists(this.uid, this.path);
2041
+ }
2042
+ /** Load a project from the database */
2043
+ async load() {
2044
+ const data = await this.col.load(this.uid, this.path, { chunked: this.chunked });
2045
+ if (!data) {
2046
+ let id = this.uid + "/";
2047
+ if (typeof this.path === "string") {
2048
+ id += this.path;
2049
+ }
2050
+ else {
2051
+ id += Object.values(this.path).join("@");
2052
+ }
2053
+ throw new InternalError({
2054
+ type: "DocumentNotFound",
2055
+ message: `Requested ${this.error_document_name} "${id}" does not exist.`,
2056
+ status: Status.bad_request,
2057
+ });
2058
+ }
2059
+ this.data = data;
2060
+ return this.data;
2061
+ }
2062
+ async try_load() {
2063
+ const data = await this.col.load(this.uid, this.path, { chunked: this.chunked });
2064
+ if (!data) {
2065
+ return undefined;
2066
+ }
2067
+ this.data = data;
2068
+ return this.data;
2069
+ }
2070
+ /** Save the project to the database */
2071
+ async save() {
2072
+ if (!this.data) {
2073
+ let id = this.uid + "/";
2074
+ if (typeof this.path === "string") {
2075
+ id += this.path;
2076
+ }
2077
+ else {
2078
+ id += Object.values(this.path).join("@");
2079
+ }
2080
+ throw new InternalError({
2081
+ type: "DocumentNotFound",
2082
+ message: `Document "${id}" is not loaded yet.`,
2083
+ status: Status.bad_request,
2084
+ });
2085
+ }
2086
+ await this.col.save(this.uid, this.path, this.data, { chunked: this.chunked });
2087
+ }
2088
+ }
@@ -8,7 +8,7 @@ import CleanCSS from 'clean-css';
8
8
  import zlib from 'zlib';
9
9
  import { View } from './view.js';
10
10
  import { vlib } from "./vinc.js";
11
- import { Utils, APIError } from "./utils.js";
11
+ import { Utils, ExternalError, InternalError } from "./utils.js";
12
12
  import { Status } from "./status.js";
13
13
  import { logger, LogSource } from "./logger.js";
14
14
  import { RateLimits } from "./rate_limit.js";
@@ -455,7 +455,7 @@ class Endpoint {
455
455
  }
456
456
  }
457
457
  catch (err) {
458
- if (err instanceof APIError) {
458
+ if (err instanceof ExternalError || err instanceof InternalError) {
459
459
  err.serve(stream);
460
460
  }
461
461
  else {
@@ -8,7 +8,7 @@ import * as PDFDocument from "pdfkit";
8
8
  import * as libcrypto from "crypto";
9
9
  import blobstream from 'blob-stream';
10
10
  import { vlib } from "../vinc.js";
11
- import { Utils, APIError } from "../utils.js";
11
+ import { Utils, ExternalError } from "../utils.js";
12
12
  import { logger } from "../logger.js";
13
13
  import { Status } from "../status.js";
14
14
  const log_source = logger.LogSource("Payments");
@@ -585,7 +585,7 @@ export class Paddle {
585
585
  }
586
586
  // Cancel.
587
587
  if (subscription.status !== "active") {
588
- throw new APIError({
588
+ throw new ExternalError({
589
589
  type: "NoActiveSubscriptionError",
590
590
  message: `This subscription is already cancelled and will become inactive at the end of the billing period.`,
591
591
  status: Status.bad_request,
@@ -1951,7 +1951,7 @@ export class Paddle {
1951
1951
  }
1952
1952
  });
1953
1953
  if (_throw_no_cancelled_err && cancelled.length === 0) {
1954
- throw new APIError({
1954
+ throw new ExternalError({
1955
1955
  type: "NoCancellableSubscriptions",
1956
1956
  message: "No cancellable subscriptions found.",
1957
1957
  status: Status.bad_request,
@@ -935,14 +935,6 @@ export class Server {
935
935
  // this.ts = ts as TypeScriptConfig;
936
936
  this.endpoints = new Map();
937
937
  this.err_endpoints = new Map();
938
- // Assign based on localhost.
939
- // if (localhost) {
940
- // this.ip = "127.0.0.1";
941
- // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
942
- // } else if (!production && !localhost && ip == null) { // use argument ip not attr since that already has a default.
943
- // this.ip = vlib.Network.private_ip();
944
- // this.domain = this.ip + ":" + (port + (this.tls ? 1 : 0));
945
- // }
946
938
  /* @performance */ this.performance = new vlib.Performance("Server performance");
947
939
  // Assign objects to server so it is easy to access.
948
940
  this.status = Status;
@@ -8,7 +8,7 @@ import { vlib } from "./vinc.js";
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 { APIError } = utils;
11
+ const { ExternalError } = utils;
12
12
  import { logger } from "./logger.js";
13
13
  const log_source = logger.LogSource("Users");
14
14
  // interface Server {
@@ -483,7 +483,7 @@ export class Users {
483
483
  }
484
484
  // Verify username and email.
485
485
  if (await this.username_exists(params.username)) {
486
- throw new APIError({
486
+ throw new ExternalError({
487
487
  type: "UsernameAlreadyExists",
488
488
  message: `Username "${params.username}" is already registered.`,
489
489
  status: Status.bad_request,
@@ -491,7 +491,7 @@ export class Users {
491
491
  });
492
492
  }
493
493
  if (await this.email_exists(params.email)) {
494
- throw new APIError({
494
+ throw new ExternalError({
495
495
  type: "EmailAlreadyExists",
496
496
  message: `Email "${params.email}" is already registered.`,
497
497
  status: Status.bad_request,
@@ -1115,7 +1115,7 @@ export class Users {
1115
1115
  // Check if username & email already exist.
1116
1116
  if (_check_username_email) {
1117
1117
  if (await this.username_exists(username)) {
1118
- throw new APIError({
1118
+ throw new ExternalError({
1119
1119
  type: "UsernameAlreadyExists",
1120
1120
  message: `Username "${username}" is already registered.`,
1121
1121
  status: Status.bad_request,
@@ -1123,7 +1123,7 @@ export class Users {
1123
1123
  });
1124
1124
  }
1125
1125
  if (await this.email_exists(email)) {
1126
- throw new APIError({
1126
+ throw new ExternalError({
1127
1127
  type: "EmailAlreadyExists",
1128
1128
  message: `Email "${email}" is already registered.`,
1129
1129
  status: Status.bad_request,