acebase-server 1.16.2 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/README.md +180 -10
  2. package/bin/acebase-server.js +8 -0
  3. package/build-vars.js +2 -1
  4. package/dist/cjs/auth.js +88 -88
  5. package/dist/cjs/cluster.js +6 -56
  6. package/dist/cjs/index.d.ts +1 -1
  7. package/dist/cjs/index.js +24 -24
  8. package/dist/cjs/logger.js +73 -73
  9. package/dist/cjs/middleware/404.js +14 -14
  10. package/dist/cjs/middleware/admin-only.js +28 -28
  11. package/dist/cjs/middleware/cache.js +14 -14
  12. package/dist/cjs/middleware/connection.js +49 -49
  13. package/dist/cjs/middleware/context.js +20 -20
  14. package/dist/cjs/middleware/cors.js +50 -50
  15. package/dist/cjs/middleware/swagger.js +17 -17
  16. package/dist/cjs/middleware/user.js +57 -57
  17. package/dist/cjs/oauth-providers/dropbox.js +109 -109
  18. package/dist/cjs/oauth-providers/facebook.js +85 -85
  19. package/dist/cjs/oauth-providers/google.js +119 -119
  20. package/dist/cjs/oauth-providers/index.js +26 -26
  21. package/dist/cjs/oauth-providers/instagram.js +80 -80
  22. package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
  23. package/dist/cjs/oauth-providers/spotify.js +113 -113
  24. package/dist/cjs/routes/auth-change-password.js +87 -87
  25. package/dist/cjs/routes/auth-delete.js +52 -52
  26. package/dist/cjs/routes/auth-forgot-password.js +77 -77
  27. package/dist/cjs/routes/auth-reset-password.js +97 -97
  28. package/dist/cjs/routes/auth-signin.js +46 -46
  29. package/dist/cjs/routes/auth-signout.js +61 -61
  30. package/dist/cjs/routes/auth-signup.js +142 -142
  31. package/dist/cjs/routes/auth-state.js +25 -25
  32. package/dist/cjs/routes/auth-update.js +131 -131
  33. package/dist/cjs/routes/auth-verify-email.js +71 -71
  34. package/dist/cjs/routes/auth.js +57 -54
  35. package/dist/cjs/routes/data-exists.js +33 -33
  36. package/dist/cjs/routes/data-export.js +48 -48
  37. package/dist/cjs/routes/data-get.js +70 -66
  38. package/dist/cjs/routes/data-import.js +54 -54
  39. package/dist/cjs/routes/data-index-create.js +42 -42
  40. package/dist/cjs/routes/data-index-delete.js +33 -33
  41. package/dist/cjs/routes/data-index-list.js +31 -31
  42. package/dist/cjs/routes/data-query.js +80 -70
  43. package/dist/cjs/routes/data-reflect.js +97 -86
  44. package/dist/cjs/routes/data-schema-get.js +36 -36
  45. package/dist/cjs/routes/data-schema-set.js +30 -30
  46. package/dist/cjs/routes/data-schema-test.js +43 -43
  47. package/dist/cjs/routes/data-schemas-list.js +32 -32
  48. package/dist/cjs/routes/data-set.js +85 -75
  49. package/dist/cjs/routes/data-sync-changes.js +81 -67
  50. package/dist/cjs/routes/data-sync-mutations.js +81 -67
  51. package/dist/cjs/routes/data-transaction.js +159 -139
  52. package/dist/cjs/routes/data-update.js +86 -75
  53. package/dist/cjs/routes/data.js +62 -62
  54. package/dist/cjs/routes/docs.js +258 -251
  55. package/dist/cjs/routes/meta-info.js +63 -63
  56. package/dist/cjs/routes/meta-logs.js +49 -49
  57. package/dist/cjs/routes/meta-ping.js +11 -11
  58. package/dist/cjs/routes/meta-stats.js +27 -27
  59. package/dist/cjs/routes/meta.js +19 -19
  60. package/dist/cjs/routes/oauth2-init.js +54 -54
  61. package/dist/cjs/routes/oauth2-refresh.js +42 -42
  62. package/dist/cjs/routes/oauth2-signin.js +265 -265
  63. package/dist/cjs/routes/webmanager.js +26 -26
  64. package/dist/cjs/rules.js +380 -167
  65. package/dist/cjs/sandbox.js +28 -0
  66. package/dist/cjs/schema/user.js +24 -24
  67. package/dist/cjs/server.js +410 -407
  68. package/dist/cjs/settings/email.js +2 -2
  69. package/dist/cjs/settings/index.js +175 -172
  70. package/dist/cjs/shared/clients.js +26 -26
  71. package/dist/cjs/shared/email.js +2 -2
  72. package/dist/cjs/shared/env.js +2 -2
  73. package/dist/cjs/shared/error.js +33 -33
  74. package/dist/cjs/shared/http.js +28 -28
  75. package/dist/cjs/shared/password.js +45 -45
  76. package/dist/cjs/shared/rootpath.js +16 -16
  77. package/dist/cjs/shared/signin.js +143 -143
  78. package/dist/cjs/shared/simple-fetch.js +76 -76
  79. package/dist/cjs/shared/tokens.js +79 -79
  80. package/dist/cjs/shared/validate.js +61 -61
  81. package/dist/cjs/start.js +119 -53
  82. package/dist/cjs/test.js +10 -10
  83. package/dist/cjs/websocket/index.js +331 -319
  84. package/dist/cjs/websocket/manager.js +15 -15
  85. package/dist/cjs/websocket/socket.io.js +76 -76
  86. package/dist/esm/auth.js +75 -75
  87. package/dist/esm/cluster.js +6 -54
  88. package/dist/esm/index.d.ts +1 -1
  89. package/dist/esm/index.js +4 -4
  90. package/dist/esm/logger.js +51 -51
  91. package/dist/esm/middleware/404.js +10 -10
  92. package/dist/esm/middleware/admin-only.js +24 -24
  93. package/dist/esm/middleware/cache.js +10 -10
  94. package/dist/esm/middleware/connection.js +45 -45
  95. package/dist/esm/middleware/context.js +16 -16
  96. package/dist/esm/middleware/cors.js +44 -44
  97. package/dist/esm/middleware/swagger.js +13 -13
  98. package/dist/esm/middleware/user.js +44 -44
  99. package/dist/esm/oauth-providers/dropbox.js +90 -90
  100. package/dist/esm/oauth-providers/facebook.js +66 -66
  101. package/dist/esm/oauth-providers/google.js +96 -96
  102. package/dist/esm/oauth-providers/index.js +18 -18
  103. package/dist/esm/oauth-providers/instagram.js +61 -61
  104. package/dist/esm/oauth-providers/oauth-provider.js +16 -16
  105. package/dist/esm/oauth-providers/spotify.js +92 -92
  106. package/dist/esm/routes/auth-change-password.js +72 -72
  107. package/dist/esm/routes/auth-delete.js +37 -37
  108. package/dist/esm/routes/auth-forgot-password.js +62 -62
  109. package/dist/esm/routes/auth-reset-password.js +81 -81
  110. package/dist/esm/routes/auth-signin.js +33 -33
  111. package/dist/esm/routes/auth-signout.js +47 -47
  112. package/dist/esm/routes/auth-signup.js +127 -127
  113. package/dist/esm/routes/auth-state.js +12 -12
  114. package/dist/esm/routes/auth-update.js +116 -116
  115. package/dist/esm/routes/auth-verify-email.js +57 -57
  116. package/dist/esm/routes/auth.js +53 -50
  117. package/dist/esm/routes/data-exists.js +20 -20
  118. package/dist/esm/routes/data-export.js +35 -35
  119. package/dist/esm/routes/data-get.js +56 -52
  120. package/dist/esm/routes/data-import.js +41 -41
  121. package/dist/esm/routes/data-index-create.js +28 -28
  122. package/dist/esm/routes/data-index-delete.js +20 -20
  123. package/dist/esm/routes/data-index-list.js +18 -18
  124. package/dist/esm/routes/data-query.js +66 -56
  125. package/dist/esm/routes/data-reflect.js +83 -72
  126. package/dist/esm/routes/data-schema-get.js +23 -23
  127. package/dist/esm/routes/data-schema-set.js +17 -17
  128. package/dist/esm/routes/data-schema-test.js +29 -29
  129. package/dist/esm/routes/data-schemas-list.js +19 -19
  130. package/dist/esm/routes/data-set.js +70 -60
  131. package/dist/esm/routes/data-sync-changes.js +67 -53
  132. package/dist/esm/routes/data-sync-mutations.js +67 -53
  133. package/dist/esm/routes/data-transaction.js +142 -123
  134. package/dist/esm/routes/data-update.js +71 -60
  135. package/dist/esm/routes/data.js +58 -58
  136. package/dist/esm/routes/docs.js +252 -245
  137. package/dist/esm/routes/meta-info.js +59 -59
  138. package/dist/esm/routes/meta-logs.js +35 -35
  139. package/dist/esm/routes/meta-ping.js +7 -7
  140. package/dist/esm/routes/meta-stats.js +14 -14
  141. package/dist/esm/routes/meta.js +15 -15
  142. package/dist/esm/routes/oauth2-init.js +41 -41
  143. package/dist/esm/routes/oauth2-refresh.js +29 -29
  144. package/dist/esm/routes/oauth2-signin.js +251 -251
  145. package/dist/esm/routes/webmanager.js +22 -22
  146. package/dist/esm/rules.js +374 -163
  147. package/dist/esm/sandbox.js +12 -0
  148. package/dist/esm/schema/user.js +19 -19
  149. package/dist/esm/server.js +395 -387
  150. package/dist/esm/settings/email.js +1 -1
  151. package/dist/esm/settings/index.js +168 -165
  152. package/dist/esm/shared/clients.js +22 -22
  153. package/dist/esm/shared/email.js +1 -1
  154. package/dist/esm/shared/env.js +1 -1
  155. package/dist/esm/shared/error.js +25 -25
  156. package/dist/esm/shared/http.js +22 -22
  157. package/dist/esm/shared/password.js +38 -38
  158. package/dist/esm/shared/rootpath.js +13 -13
  159. package/dist/esm/shared/signin.js +128 -128
  160. package/dist/esm/shared/simple-fetch.js +59 -59
  161. package/dist/esm/shared/tokens.js +72 -72
  162. package/dist/esm/shared/validate.js +41 -41
  163. package/dist/esm/start.js +116 -50
  164. package/dist/esm/test.js +8 -8
  165. package/dist/esm/websocket/index.js +313 -302
  166. package/dist/esm/websocket/manager.js +11 -11
  167. package/dist/esm/websocket/socket.io.js +71 -71
  168. package/dist/types/auth.d.ts +3 -3
  169. package/dist/types/cluster.d.ts +6 -1
  170. package/dist/types/index.d.ts +4 -4
  171. package/dist/types/logger.d.ts +35 -35
  172. package/dist/types/middleware/404.d.ts +7 -7
  173. package/dist/types/middleware/admin-only.d.ts +19 -19
  174. package/dist/types/middleware/cache.d.ts +3 -3
  175. package/dist/types/middleware/connection.d.ts +7 -7
  176. package/dist/types/middleware/context.d.ts +3 -3
  177. package/dist/types/middleware/cors.d.ts +25 -25
  178. package/dist/types/middleware/swagger.d.ts +3 -3
  179. package/dist/types/middleware/user.d.ts +2 -2
  180. package/dist/types/oauth-providers/dropbox.d.ts +52 -52
  181. package/dist/types/oauth-providers/facebook.d.ts +41 -41
  182. package/dist/types/oauth-providers/google.d.ts +43 -43
  183. package/dist/types/oauth-providers/index.d.ts +10 -10
  184. package/dist/types/oauth-providers/instagram.d.ts +50 -50
  185. package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
  186. package/dist/types/oauth-providers/spotify.d.ts +53 -53
  187. package/dist/types/routes/auth-change-password.d.ts +20 -20
  188. package/dist/types/routes/auth-delete.d.ts +16 -16
  189. package/dist/types/routes/auth-forgot-password.d.ts +16 -16
  190. package/dist/types/routes/auth-reset-password.d.ts +23 -23
  191. package/dist/types/routes/auth-signin.d.ts +24 -24
  192. package/dist/types/routes/auth-signout.d.ts +14 -14
  193. package/dist/types/routes/auth-signup.d.ts +32 -32
  194. package/dist/types/routes/auth-state.d.ts +13 -13
  195. package/dist/types/routes/auth-update.d.ts +33 -33
  196. package/dist/types/routes/auth-verify-email.d.ts +21 -21
  197. package/dist/types/routes/auth.d.ts +6 -6
  198. package/dist/types/routes/data-exists.d.ts +9 -9
  199. package/dist/types/routes/data-export.d.ts +10 -10
  200. package/dist/types/routes/data-get.d.ts +14 -14
  201. package/dist/types/routes/data-import.d.ts +13 -13
  202. package/dist/types/routes/data-index-create.d.ts +51 -51
  203. package/dist/types/routes/data-index-delete.d.ts +17 -17
  204. package/dist/types/routes/data-index-list.d.ts +21 -21
  205. package/dist/types/routes/data-query.d.ts +49 -49
  206. package/dist/types/routes/data-reflect.d.ts +29 -29
  207. package/dist/types/routes/data-schema-get.d.ts +11 -11
  208. package/dist/types/routes/data-schema-set.d.ts +20 -19
  209. package/dist/types/routes/data-schema-test.d.ts +19 -19
  210. package/dist/types/routes/data-schemas-list.d.ts +11 -11
  211. package/dist/types/routes/data-set.d.ts +27 -27
  212. package/dist/types/routes/data-sync-changes.d.ts +25 -28
  213. package/dist/types/routes/data-sync-mutations.d.ts +25 -28
  214. package/dist/types/routes/data-transaction.d.ts +34 -34
  215. package/dist/types/routes/data-update.d.ts +27 -27
  216. package/dist/types/routes/data.d.ts +3 -3
  217. package/dist/types/routes/docs.d.ts +3 -3
  218. package/dist/types/routes/meta-info.d.ts +11 -11
  219. package/dist/types/routes/meta-logs.d.ts +20 -20
  220. package/dist/types/routes/meta-ping.d.ts +7 -7
  221. package/dist/types/routes/meta-stats.d.ts +13 -13
  222. package/dist/types/routes/meta.d.ts +3 -3
  223. package/dist/types/routes/oauth2-init.d.ts +13 -13
  224. package/dist/types/routes/oauth2-refresh.d.ts +17 -17
  225. package/dist/types/routes/oauth2-signin.d.ts +15 -15
  226. package/dist/types/routes/webmanager.d.ts +3 -3
  227. package/dist/types/rules.d.ts +73 -34
  228. package/dist/types/sandbox.d.ts +3 -0
  229. package/dist/types/schema/user.d.ts +85 -85
  230. package/dist/types/server.d.ts +117 -111
  231. package/dist/types/settings/email.d.ts +14 -14
  232. package/dist/types/settings/index.d.ts +195 -187
  233. package/dist/types/shared/clients.d.ts +46 -46
  234. package/dist/types/shared/email.d.ts +34 -34
  235. package/dist/types/shared/env.d.ts +47 -44
  236. package/dist/types/shared/error.d.ts +15 -15
  237. package/dist/types/shared/http.d.ts +22 -21
  238. package/dist/types/shared/password.d.ts +19 -19
  239. package/dist/types/shared/rootpath.d.ts +2 -2
  240. package/dist/types/shared/signin.d.ts +31 -31
  241. package/dist/types/shared/simple-fetch.d.ts +21 -21
  242. package/dist/types/shared/tokens.d.ts +24 -24
  243. package/dist/types/shared/validate.d.ts +22 -22
  244. package/dist/types/start.d.ts +1 -1
  245. package/dist/types/test.d.ts +1 -1
  246. package/dist/types/websocket/index.d.ts +6 -6
  247. package/dist/types/websocket/manager.d.ts +99 -99
  248. package/dist/types/websocket/socket.io.d.ts +10 -10
  249. package/package.json +7 -4
  250. package/src/routes/data-schema-set.yaml +4 -0
  251. package/src/routes/data-set.yaml +5 -5
  252. package/src/routes/data-update.yaml +4 -4
@@ -1,408 +1,411 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AceBaseServer = exports.AceBaseExternalServerError = exports.AceBaseServerNotReadyError = void 0;
13
- const acebase_core_1 = require("acebase-core");
14
- const settings_1 = require("./settings");
15
- const http_1 = require("./shared/http");
16
- const websocket_1 = require("./websocket");
17
- const acebase_1 = require("acebase");
18
- const http_2 = require("http");
19
- const https_1 = require("https");
20
- const oauth_providers_1 = require("./oauth-providers");
21
- const rules_1 = require("./rules");
22
- const connection_1 = require("./middleware/connection");
23
- const cors_1 = require("./middleware/cors");
24
- const auth_1 = require("./routes/auth");
25
- const auth_2 = require("./auth");
26
- const data_1 = require("./routes/data");
27
- const webmanager_1 = require("./routes/webmanager");
28
- const meta_1 = require("./routes/meta");
29
- const cache_1 = require("./middleware/cache");
30
- const logger_1 = require("./logger");
31
- // type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
32
- class AceBaseServerNotReadyError extends Error {
33
- constructor() { super('Server is not ready yet'); }
34
- }
35
- exports.AceBaseServerNotReadyError = AceBaseServerNotReadyError;
36
- class AceBaseExternalServerError extends Error {
37
- constructor() { super('This method is not available with an external server'); }
38
- }
39
- exports.AceBaseExternalServerError = AceBaseExternalServerError;
40
- class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
41
- constructor(dbname, options) {
42
- super();
43
- this._ready = false;
44
- this.authProviders = {};
45
- this.config = new settings_1.AceBaseServerConfig(options);
46
- this.debug = new acebase_core_1.DebugLogger(this.config.logLevel, `[${dbname}]`.colorize(acebase_core_1.ColorStyle.green));
47
- if (this.config.auth.enabled && !this.config.https.enabled) {
48
- this.debug.warn(`WARNING: Authentication is enabled, but the server is not using https. Any password and other data transmitted may be intercepted!`.colorize(acebase_core_1.ColorStyle.red));
49
- }
50
- else if (!this.config.https.enabled) {
51
- this.debug.warn(`WARNING: Server is not using https, any data transmitted may be intercepted!`.colorize(acebase_core_1.ColorStyle.red));
52
- }
53
- if (!this.config.auth.enabled) {
54
- this.debug.warn(`WARNING: Authentication is disabled, *anyone* can do *anything* with your data!`.colorize(acebase_core_1.ColorStyle.red));
55
- }
56
- // Open database(s)
57
- const dbOptions = {
58
- logLevel: this.config.logLevel,
59
- info: 'realtime database server',
60
- // NEW: Allow storage setting like AceBaseLocalSettings - could allow using other db backend (typed, but undocumented)
61
- storage: this.config.storage || {
62
- path: this.config.path,
63
- removeVoidProperties: true,
64
- },
65
- transactions: this.config.transactions,
66
- ipc: this.config.ipc,
67
- sponsor: this.config.sponsor,
68
- logColors: this.config.logColors,
69
- };
70
- this.db = new acebase_1.AceBase(dbname, dbOptions);
71
- const otherDbsPath = `${this.config.path}/${this.db.name}.acebase`;
72
- const authDb = (() => {
73
- if (!this.config.auth.enabled) {
74
- return null;
75
- }
76
- switch (this.config.auth.separateDb) {
77
- case true: return new acebase_1.AceBase('auth', { logLevel: dbOptions.logLevel, storage: { path: otherDbsPath, removeVoidProperties: true, info: `${dbname} auth database` } });
78
- case 'v2': /*NOT TESTED YET*/ return new acebase_1.AceBase(dbname, { logLevel: dbOptions.logLevel, storage: { type: 'auth', path: this.config.path, removeVoidProperties: true, info: `${dbname} auth database` } });
79
- default: return this.db;
80
- }
81
- })();
82
- // Create Express app
83
- this.app = (0, http_1.createApp)({ trustProxy: true, maxPayloadSize: this.config.maxPayloadSize });
84
- // Initialize and start server
85
- this.init({ authDb });
86
- }
87
- get isReady() { return this._ready; }
88
- /**
89
- * Wait for the server to be ready to accept incoming connections
90
- * @param callback (optional) callback function that is called when ready. You can also use the returned promise
91
- * @returns returns a promise that resolves when ready
92
- */
93
- ready(callback) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- if (!this._ready) {
96
- yield this.once('ready');
97
- }
98
- callback === null || callback === void 0 ? void 0 : callback();
99
- });
100
- }
101
- /**
102
- * Gets the url the server is running at
103
- */
104
- get url() {
105
- return `http${this.config.https.enabled ? 's' : ''}://${this.config.host}:${this.config.port}/${this.config.rootPath}`;
106
- }
107
- init(env) {
108
- var _a;
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const config = this.config;
111
- const db = this.db;
112
- const authDb = env.authDb;
113
- // Wait for databases to be ready to use
114
- yield Promise.all([
115
- db.ready(),
116
- authDb === null || authDb === void 0 ? void 0 : authDb.ready(),
117
- ]);
118
- // Create http server
119
- const app = this.app;
120
- (_a = this.config.server) === null || _a === void 0 ? void 0 : _a.on('request', app);
121
- const server = this.config.server || (config.https.enabled ? (0, https_1.createServer)(config.https, app) : (0, http_2.createServer)(app));
122
- const clients = new Map();
123
- const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
124
- const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
125
- const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
126
- const logger = new logger_1.DatabaseLog(logRef);
127
- // Setup rules
128
- const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
129
- const rules = new rules_1.PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
130
- const router = (0, http_1.createRouter)();
131
- const routeEnv = {
132
- config: this.config,
133
- server,
134
- db: db,
135
- authDb,
136
- app: router,
137
- rootPath: this.config.rootPath,
138
- debug: this.debug,
139
- securityRef,
140
- authRef,
141
- log: logger,
142
- tokenSalt: null,
143
- clients,
144
- authCache: null,
145
- authProviders: this.authProviders,
146
- rules,
147
- };
148
- // Add connection middleware
149
- const killConnections = (0, connection_1.default)(routeEnv);
150
- // Add CORS middleware
151
- (0, cors_1.default)(routeEnv);
152
- // Add cache middleware
153
- (0, cache_1.default)(routeEnv);
154
- if (config.auth.enabled) {
155
- // Setup auth database
156
- yield (0, auth_2.default)(routeEnv);
157
- // Add auth endpoints
158
- const { resetPassword, verifyEmailAddress } = (0, auth_1.default)(routeEnv);
159
- this.resetPassword = resetPassword;
160
- this.verifyEmailAddress = verifyEmailAddress;
161
- }
162
- // Add metadata endpoints
163
- (0, meta_1.default)(routeEnv);
164
- // If environment is development, add API docs
165
- if (process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'development') {
166
- this.debug.warn('DEVELOPMENT MODE: adding API docs endpoint at /docs');
167
- (yield Promise.resolve().then(() => require('./routes/docs'))).addRoute(routeEnv);
168
- (yield Promise.resolve().then(() => require('./middleware/swagger'))).addMiddleware(routeEnv);
169
- }
170
- // Add data endpoints
171
- (0, data_1.default)(routeEnv);
172
- // Add webmanager endpoints
173
- (0, webmanager_1.default)(routeEnv);
174
- // Allow adding custom routes
175
- this.extend = (method, ext_path, handler) => {
176
- const route = `/ext/${db.name}/${ext_path}`;
177
- this.debug.log(`Extending server: `, method, route);
178
- routeEnv.app[method.toLowerCase()](route, handler);
179
- };
180
- // Create websocket server
181
- (0, websocket_1.addWebsocketServer)(routeEnv);
182
- // Register all the routes for the app
183
- app.use(`/${this.config.rootPath}`, router);
184
- // Last but not least, add 404 handler
185
- // DISABLED because it causes server extension routes through server.extend (see above) not be be executed
186
- // add404Middleware(routeEnv);
187
- // Start listening, if no external server
188
- if (!this.config.server) {
189
- server.listen(config.port, config.host, () => {
190
- // Ready!!
191
- this.debug.log(`"${db.name}" database server running at ${this.url}`);
192
- this._ready = true;
193
- this.emitOnce(`ready`);
194
- });
195
- }
196
- // Setup pause and resume methods
197
- let paused = false;
198
- this.pause = () => __awaiter(this, void 0, void 0, function* () {
199
- if (this.config.server) {
200
- throw new AceBaseExternalServerError();
201
- }
202
- if (paused) {
203
- throw new Error('Server is already paused');
204
- }
205
- server.close();
206
- this.debug.warn(`Paused "${db.name}" database server at ${this.url}`);
207
- this.emit('pause');
208
- paused = true;
209
- });
210
- this.resume = () => __awaiter(this, void 0, void 0, function* () {
211
- if (this.config.server) {
212
- throw new AceBaseExternalServerError();
213
- }
214
- if (!paused) {
215
- throw new Error('Server is not paused');
216
- }
217
- return new Promise(resolve => {
218
- server.listen(config.port, config.host, () => {
219
- this.debug.warn(`Resumed "${db.name}" database server at ${this.url}`);
220
- this.emit('resume');
221
- paused = false;
222
- resolve();
223
- });
224
- });
225
- });
226
- // Handle SIGINT and shutdown requests
227
- const shutdown = (request) => __awaiter(this, void 0, void 0, function* () {
228
- this.debug.warn('shutting down server');
229
- routeEnv.rules.stop();
230
- const getConnectionsCount = () => {
231
- return new Promise((resolve, reject) => {
232
- server.getConnections((err, connections) => {
233
- if (err) {
234
- reject(err);
235
- }
236
- else {
237
- resolve(connections);
238
- }
239
- });
240
- });
241
- };
242
- const connections = yield getConnectionsCount();
243
- this.debug.log(`Server has ${connections} connections`);
244
- yield new Promise((resolve) => {
245
- // const interval = setInterval(async () => {
246
- // const connections = await getConnectionsCount();
247
- // this.debug.log(`Server still has ${connections} connections`);
248
- // }, 5000);
249
- // interval.unref();
250
- server.close(err => {
251
- if (err) {
252
- this.debug.error(`server.close() error: ${err.message}`);
253
- }
254
- else {
255
- this.debug.log(`server.close() success`);
256
- }
257
- resolve();
258
- });
259
- // If for some reason connection aren't broken in time - do proceed with shutdown sequence
260
- const timeout = setTimeout(() => {
261
- if (clients.size === 0) {
262
- return;
263
- }
264
- this.debug.warn(`server.close() timed out, there are still open connections`);
265
- killConnections();
266
- }, 5000);
267
- timeout.unref();
268
- this.debug.log(`Closing ${clients.size} websocket connections`);
269
- clients.forEach((client, id) => {
270
- const socket = client.socket;
271
- socket.once('disconnect', reason => {
272
- this.debug.log(`Socket ${socket.id} disconnected: ${reason}`);
273
- });
274
- socket.disconnect(true);
275
- });
276
- });
277
- this.debug.warn('closing database');
278
- yield db.close();
279
- this.debug.warn('shutdown complete');
280
- // Emit events to let the outside world know we shut down.
281
- // This is especially important if this instance was running in a Node.js cluster: the process will
282
- // not exit automatically after this shutdown because Node.js' IPC channel between worker and master is still open.
283
- // By sending these events, the cluster manager can determine if it should (and when to) execute process.exit()
284
- // process.emit('acebase-server-shutdown'); // Emit on process
285
- process.emit('beforeExit', request.sigint ? 130 : 0); // Emit on process
286
- try {
287
- process.send && process.send('acebase-server-shutdown'); // Send to master process when running in a Node.js cluster
288
- }
289
- catch (err) {
290
- // IPC Channel has apparently been closed already
291
- }
292
- this.emit('shutdown'); // Emit on AceBaseServer instance
293
- });
294
- this.shutdown = () => __awaiter(this, void 0, void 0, function* () {
295
- if (this.config.server) {
296
- throw new AceBaseExternalServerError();
297
- }
298
- yield shutdown({ sigint: false });
299
- });
300
- // Offload shutdown control to an external server
301
- if (this.config.server) {
302
- server.on('close', function close() {
303
- server.off('request', app);
304
- server.off('close', close);
305
- shutdown({ sigint: false });
306
- });
307
- const ready = () => {
308
- this.debug.log(`"${db.name}" database server running at ${this.url}`);
309
- this._ready = true;
310
- this.emitOnce(`ready`);
311
- server.off('listening', ready);
312
- };
313
- if (server.listening) {
314
- ready();
315
- }
316
- else {
317
- server.on('listening', ready);
318
- }
319
- }
320
- else {
321
- process.on('SIGINT', () => shutdown({ sigint: true }));
322
- }
323
- });
324
- }
325
- /**
326
- * Reset a user's password. This can also be done using the auth/reset_password API endpoint
327
- * @param clientIp ip address of the user
328
- * @param code reset code that was sent to the user's email address
329
- * @param newPassword new password chosen by the user
330
- */
331
- resetPassword(clientIp, code, newPassword) {
332
- throw new AceBaseServerNotReadyError();
333
- }
334
- /**
335
- * Marks a user account's email address as validated. This can also be done using the auth/verify_email API endpoint
336
- * @param clientIp ip address of the user
337
- * @param code verification code sent to the user's email address
338
- */
339
- verifyEmailAddress(clientIp, code) {
340
- throw new AceBaseServerNotReadyError();
341
- }
342
- /**
343
- * Shuts down the server. Stops listening for incoming connections, breaks current connections and closes the database.
344
- * Is automatically executed when a "SIGINT" process event is received.
345
- *
346
- * Once the shutdown procedure is completed, it emits a "shutdown" event on the server instance, "acebase-server-shutdown" event on the `process`, and sends an 'acebase-server-shutdown' IPC message if Node.js clustering is used.
347
- * These events can be handled by cluster managing code to `kill` or `exit` the process safely.
348
- */
349
- shutdown() {
350
- throw new AceBaseServerNotReadyError();
351
- }
352
- /**
353
- * Temporarily stops the server from handling incoming connections, but keeps existing connections open
354
- */
355
- pause() {
356
- throw new AceBaseServerNotReadyError();
357
- }
358
- /**
359
- * Resumes handling incoming connections
360
- */
361
- resume() {
362
- throw new AceBaseServerNotReadyError();
363
- }
364
- /**
365
- * Extend the server API with your own custom functions. Your handler will be listening
366
- * on path /ext/[db name]/[ext_path].
367
- * @example
368
- * // Server side:
369
- * const _quotes = [...];
370
- * server.extend('get', 'quotes/random', (req, res) => {
371
- * let index = Math.round(Math.random() * _quotes.length);
372
- * res.send(quotes[index]);
373
- * })
374
- * // Client side:
375
- * client.callExtension('get', 'quotes/random')
376
- * .then(quote => {
377
- * console.log(`Got random quote: ${quote}`);
378
- * })
379
- * @param method http method to bind to
380
- * @param ext_path path to bind to (appended to /ext/)
381
- * @param handler your Express request handler callback
382
- */
383
- extend(method, ext_path, handler) {
384
- throw new AceBaseServerNotReadyError();
385
- }
386
- /**
387
- * Configure an auth provider to allow users to sign in with Facebook, Google, etc
388
- * @param providerName name of the third party OAuth provider. Eg: "Facebook", "Google", "spotify" etc
389
- * @param settings API key & secret for the OAuth provider
390
- * @returns Returns the created auth provider instance, which can be used to call non-user specific methods the provider might support. (example: the Spotify auth provider supports getClientAuthToken, which allows API calls to be made to the core (non-user) spotify service)
391
- */
392
- configAuthProvider(providerName, settings) {
393
- if (!this.config.auth.enabled) {
394
- throw new Error(`Authentication is not enabled`);
395
- }
396
- try {
397
- const AuthProvider = oauth_providers_1.default[providerName];
398
- const provider = new AuthProvider(settings);
399
- this.authProviders[providerName] = provider;
400
- return provider;
401
- }
402
- catch (err) {
403
- throw new Error(`Failed to configure provider ${providerName}: ${err.message}`);
404
- }
405
- }
406
- }
407
- exports.AceBaseServer = AceBaseServer;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AceBaseServer = exports.AceBaseExternalServerError = exports.AceBaseServerNotReadyError = void 0;
13
+ const acebase_core_1 = require("acebase-core");
14
+ const settings_1 = require("./settings");
15
+ const http_1 = require("./shared/http");
16
+ const websocket_1 = require("./websocket");
17
+ const acebase_1 = require("acebase");
18
+ const http_2 = require("http");
19
+ const https_1 = require("https");
20
+ const oauth_providers_1 = require("./oauth-providers");
21
+ const rules_1 = require("./rules");
22
+ const connection_1 = require("./middleware/connection");
23
+ const cors_1 = require("./middleware/cors");
24
+ const auth_1 = require("./routes/auth");
25
+ const auth_2 = require("./auth");
26
+ const data_1 = require("./routes/data");
27
+ const webmanager_1 = require("./routes/webmanager");
28
+ const meta_1 = require("./routes/meta");
29
+ const _404_1 = require("./middleware/404");
30
+ const cache_1 = require("./middleware/cache");
31
+ const logger_1 = require("./logger");
32
+ // type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
33
+ class AceBaseServerNotReadyError extends Error {
34
+ constructor() { super('Server is not ready yet'); }
35
+ }
36
+ exports.AceBaseServerNotReadyError = AceBaseServerNotReadyError;
37
+ class AceBaseExternalServerError extends Error {
38
+ constructor() { super('This method is not available with an external server'); }
39
+ }
40
+ exports.AceBaseExternalServerError = AceBaseExternalServerError;
41
+ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
42
+ get isReady() { return this._ready; }
43
+ /**
44
+ * Wait for the server to be ready to accept incoming connections
45
+ * @param callback (optional) callback function that is called when ready. You can also use the returned promise
46
+ * @returns returns a promise that resolves when ready
47
+ */
48
+ ready(callback) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (!this._ready) {
51
+ yield this.once('ready');
52
+ }
53
+ callback === null || callback === void 0 ? void 0 : callback();
54
+ });
55
+ }
56
+ /**
57
+ * Gets the url the server is running at
58
+ */
59
+ get url() {
60
+ return `http${this.config.https.enabled ? 's' : ''}://${this.config.host}:${this.config.port}/${this.config.rootPath}`;
61
+ }
62
+ constructor(dbname, options) {
63
+ super();
64
+ this._ready = false;
65
+ this.authProviders = {};
66
+ this.config = new settings_1.AceBaseServerConfig(options);
67
+ this.debug = new acebase_core_1.DebugLogger(this.config.logLevel, `[${dbname}]`.colorize(acebase_core_1.ColorStyle.green));
68
+ if (this.config.auth.enabled && !this.config.https.enabled) {
69
+ this.debug.warn(`WARNING: Authentication is enabled, but the server is not using https. Any password and other data transmitted may be intercepted!`.colorize(acebase_core_1.ColorStyle.red));
70
+ }
71
+ else if (!this.config.https.enabled) {
72
+ this.debug.warn(`WARNING: Server is not using https, any data transmitted may be intercepted!`.colorize(acebase_core_1.ColorStyle.red));
73
+ }
74
+ if (!this.config.auth.enabled) {
75
+ this.debug.warn(`WARNING: Authentication is disabled, *anyone* can do *anything* with your data!`.colorize(acebase_core_1.ColorStyle.red));
76
+ }
77
+ // Open database(s)
78
+ const dbOptions = {
79
+ logLevel: this.config.logLevel,
80
+ info: 'realtime database server',
81
+ storage: Object.assign({ path: this.config.path, removeVoidProperties: true, ipc: this.config.ipc }, this.config.storage),
82
+ transactions: this.config.transactions,
83
+ sponsor: this.config.sponsor,
84
+ logColors: this.config.logColors,
85
+ };
86
+ this.db = new acebase_1.AceBase(dbname, dbOptions);
87
+ const otherDbsPath = `${this.config.path}/${this.db.name}.acebase`;
88
+ const authDb = (() => {
89
+ if (!this.config.auth.enabled) {
90
+ return null;
91
+ }
92
+ switch (this.config.auth.separateDb) {
93
+ case true: return new acebase_1.AceBase('auth', { logLevel: dbOptions.logLevel, storage: { path: otherDbsPath, removeVoidProperties: true, info: `${dbname} auth database` } });
94
+ case 'v2': /*NOT TESTED YET*/ return new acebase_1.AceBase(dbname, { logLevel: dbOptions.logLevel, storage: { type: 'auth', path: this.config.path, removeVoidProperties: true, info: `${dbname} auth database` } });
95
+ default: return this.db;
96
+ }
97
+ })();
98
+ // Create Express app
99
+ this.app = (0, http_1.createApp)({ trustProxy: true, maxPayloadSize: this.config.maxPayloadSize });
100
+ this.router = (0, http_1.createRouter)();
101
+ this.app.use(`/${this.config.rootPath}`, this.router);
102
+ // Initialize and start server
103
+ this.init({ authDb });
104
+ }
105
+ init(env) {
106
+ var _a, _b, _c;
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const config = this.config;
109
+ const db = this.db;
110
+ const authDb = env.authDb;
111
+ // Wait for databases to be ready to use
112
+ yield Promise.all([
113
+ db.ready(),
114
+ authDb === null || authDb === void 0 ? void 0 : authDb.ready(),
115
+ ]);
116
+ // Create http server
117
+ (_a = this.config.server) === null || _a === void 0 ? void 0 : _a.on('request', this.app);
118
+ const server = this.config.server || (config.https.enabled ? (0, https_1.createServer)(config.https, this.app) : (0, http_2.createServer)(this.app));
119
+ const clients = new Map();
120
+ const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
121
+ const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
122
+ const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
123
+ const logger = new logger_1.DatabaseLog(logRef);
124
+ // Setup rules
125
+ const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
126
+ const rules = new rules_1.PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
127
+ this.setRule = (rulePath, ruleType, callback) => {
128
+ return rules.add(rulePath, ruleType, callback);
129
+ };
130
+ const routeEnv = {
131
+ config: this.config,
132
+ server,
133
+ db: db,
134
+ authDb,
135
+ app: this.app,
136
+ router: this.router,
137
+ rootPath: this.config.rootPath,
138
+ debug: this.debug,
139
+ securityRef,
140
+ authRef,
141
+ log: logger,
142
+ tokenSalt: null,
143
+ clients,
144
+ authCache: null,
145
+ authProviders: this.authProviders,
146
+ rules,
147
+ instance: this,
148
+ };
149
+ // Add connection middleware
150
+ const killConnections = (0, connection_1.default)(routeEnv);
151
+ // Add CORS middleware
152
+ (0, cors_1.default)(routeEnv);
153
+ // Add cache middleware
154
+ (0, cache_1.default)(routeEnv);
155
+ if (config.auth.enabled) {
156
+ // Setup auth database
157
+ yield (0, auth_2.default)(routeEnv);
158
+ // Add auth endpoints
159
+ const { resetPassword, verifyEmailAddress } = (0, auth_1.default)(routeEnv);
160
+ this.resetPassword = resetPassword;
161
+ this.verifyEmailAddress = verifyEmailAddress;
162
+ }
163
+ // Add metadata endpoints
164
+ (0, meta_1.default)(routeEnv);
165
+ // If environment is development, add API docs
166
+ if (process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'development') {
167
+ this.debug.warn('DEVELOPMENT MODE: adding API docs endpoint at /docs');
168
+ (yield Promise.resolve().then(() => require('./routes/docs'))).addRoute(routeEnv);
169
+ (yield Promise.resolve().then(() => require('./middleware/swagger'))).addMiddleware(routeEnv);
170
+ }
171
+ // Add data endpoints
172
+ (0, data_1.default)(routeEnv);
173
+ // Add webmanager endpoints
174
+ (0, webmanager_1.default)(routeEnv);
175
+ // Allow adding custom routes
176
+ this.extend = (method, ext_path, handler) => {
177
+ const route = `/ext/${db.name}/${ext_path}`;
178
+ this.debug.log(`Extending server: `, method, route);
179
+ this.router[method.toLowerCase()](route, handler);
180
+ };
181
+ // Create websocket server
182
+ (0, websocket_1.addWebsocketServer)(routeEnv);
183
+ // Run init callback to allow user code to call `server.extend`, `server.router.[method]`, `server.setRule` etc before the server starts listening
184
+ yield ((_c = (_b = this.config).init) === null || _c === void 0 ? void 0 : _c.call(_b, this));
185
+ // If we own the server, add 404 handler
186
+ if (!this.config.server) {
187
+ (0, _404_1.default)(routeEnv);
188
+ }
189
+ // Setup pause and resume methods
190
+ let paused = false;
191
+ this.pause = () => __awaiter(this, void 0, void 0, function* () {
192
+ if (this.config.server) {
193
+ throw new AceBaseExternalServerError();
194
+ }
195
+ if (paused) {
196
+ throw new Error('Server is already paused');
197
+ }
198
+ server.close();
199
+ this.debug.warn(`Paused "${db.name}" database server at ${this.url}`);
200
+ this.emit('pause');
201
+ paused = true;
202
+ });
203
+ this.resume = () => __awaiter(this, void 0, void 0, function* () {
204
+ if (this.config.server) {
205
+ throw new AceBaseExternalServerError();
206
+ }
207
+ if (!paused) {
208
+ throw new Error('Server is not paused');
209
+ }
210
+ return new Promise(resolve => {
211
+ server.listen(config.port, config.host, () => {
212
+ this.debug.warn(`Resumed "${db.name}" database server at ${this.url}`);
213
+ this.emit('resume');
214
+ paused = false;
215
+ resolve();
216
+ });
217
+ });
218
+ });
219
+ // Handle SIGINT and shutdown requests
220
+ const shutdown = (request) => __awaiter(this, void 0, void 0, function* () {
221
+ this.debug.warn('shutting down server');
222
+ routeEnv.rules.stop();
223
+ const getConnectionsCount = () => {
224
+ return new Promise((resolve, reject) => {
225
+ server.getConnections((err, connections) => {
226
+ if (err) {
227
+ reject(err);
228
+ }
229
+ else {
230
+ resolve(connections);
231
+ }
232
+ });
233
+ });
234
+ };
235
+ const connections = yield getConnectionsCount();
236
+ this.debug.log(`Server has ${connections} connections`);
237
+ yield new Promise((resolve) => {
238
+ // const interval = setInterval(async () => {
239
+ // const connections = await getConnectionsCount();
240
+ // this.debug.log(`Server still has ${connections} connections`);
241
+ // }, 5000);
242
+ // interval.unref();
243
+ server.close(err => {
244
+ if (err) {
245
+ this.debug.error(`server.close() error: ${err.message}`);
246
+ }
247
+ else {
248
+ this.debug.log(`server.close() success`);
249
+ }
250
+ resolve();
251
+ });
252
+ // If for some reason connection aren't broken in time - do proceed with shutdown sequence
253
+ const timeout = setTimeout(() => {
254
+ if (clients.size === 0) {
255
+ return;
256
+ }
257
+ this.debug.warn(`server.close() timed out, there are still open connections`);
258
+ killConnections();
259
+ }, 5000);
260
+ timeout.unref();
261
+ this.debug.log(`Closing ${clients.size} websocket connections`);
262
+ clients.forEach((client, id) => {
263
+ const socket = client.socket;
264
+ socket.once('disconnect', reason => {
265
+ this.debug.log(`Socket ${socket.id} disconnected: ${reason}`);
266
+ });
267
+ socket.disconnect(true);
268
+ });
269
+ });
270
+ this.debug.warn('closing database');
271
+ yield db.close();
272
+ this.debug.warn('shutdown complete');
273
+ // Emit events to let the outside world know we shut down.
274
+ // This is especially important if this instance was running in a Node.js cluster: the process will
275
+ // not exit automatically after this shutdown because Node.js' IPC channel between worker and master is still open.
276
+ // By sending these events, the cluster manager can determine if it should (and when to) execute process.exit()
277
+ // process.emit('acebase-server-shutdown'); // Emit on process
278
+ process.emit('beforeExit', request.sigint ? 130 : 0); // Emit on process
279
+ try {
280
+ process.send && process.send('acebase-server-shutdown'); // Send to master process when running in a Node.js cluster
281
+ }
282
+ catch (err) {
283
+ // IPC Channel has apparently been closed already
284
+ }
285
+ this.emit('shutdown'); // Emit on AceBaseServer instance
286
+ });
287
+ this.shutdown = () => __awaiter(this, void 0, void 0, function* () {
288
+ if (this.config.server) {
289
+ throw new AceBaseExternalServerError();
290
+ }
291
+ yield shutdown({ sigint: false });
292
+ });
293
+ if (this.config.server) {
294
+ // Offload shutdown control to an external server
295
+ server.on('close', function close() {
296
+ server.off('request', this.app);
297
+ server.off('close', close);
298
+ shutdown({ sigint: false });
299
+ });
300
+ const ready = () => {
301
+ this.debug.log(`"${db.name}" database server running at ${this.url}`);
302
+ this._ready = true;
303
+ this.emitOnce(`ready`);
304
+ server.off('listening', ready);
305
+ };
306
+ if (server.listening) {
307
+ ready();
308
+ }
309
+ else {
310
+ server.on('listening', ready);
311
+ }
312
+ }
313
+ else {
314
+ // Start listening
315
+ server.listen(config.port, config.host, () => {
316
+ // Ready!!
317
+ this.debug.log(`"${db.name}" database server running at ${this.url}`);
318
+ this._ready = true;
319
+ this.emitOnce(`ready`);
320
+ });
321
+ process.on('SIGINT', () => shutdown({ sigint: true }));
322
+ }
323
+ });
324
+ }
325
+ /**
326
+ * Reset a user's password. This can also be done using the auth/reset_password API endpoint
327
+ * @param clientIp ip address of the user
328
+ * @param code reset code that was sent to the user's email address
329
+ * @param newPassword new password chosen by the user
330
+ */
331
+ resetPassword(clientIp, code, newPassword) {
332
+ throw new AceBaseServerNotReadyError();
333
+ }
334
+ /**
335
+ * Marks a user account's email address as validated. This can also be done using the auth/verify_email API endpoint
336
+ * @param clientIp ip address of the user
337
+ * @param code verification code sent to the user's email address
338
+ */
339
+ verifyEmailAddress(clientIp, code) {
340
+ throw new AceBaseServerNotReadyError();
341
+ }
342
+ /**
343
+ * Shuts down the server. Stops listening for incoming connections, breaks current connections and closes the database.
344
+ * Is automatically executed when a "SIGINT" process event is received.
345
+ *
346
+ * Once the shutdown procedure is completed, it emits a "shutdown" event on the server instance, "acebase-server-shutdown" event on the `process`, and sends an 'acebase-server-shutdown' IPC message if Node.js clustering is used.
347
+ * These events can be handled by cluster managing code to `kill` or `exit` the process safely.
348
+ */
349
+ shutdown() {
350
+ throw new AceBaseServerNotReadyError();
351
+ }
352
+ /**
353
+ * Temporarily stops the server from handling incoming connections, but keeps existing connections open
354
+ */
355
+ pause() {
356
+ throw new AceBaseServerNotReadyError();
357
+ }
358
+ /**
359
+ * Resumes handling incoming connections
360
+ */
361
+ resume() {
362
+ throw new AceBaseServerNotReadyError();
363
+ }
364
+ /**
365
+ * Extend the server API with your own custom functions. Your handler will be listening
366
+ * on path /ext/[db name]/[ext_path].
367
+ * @example
368
+ * // Server side:
369
+ * const _quotes = [...];
370
+ * server.extend('get', 'quotes/random', (req, res) => {
371
+ * let index = Math.round(Math.random() * _quotes.length);
372
+ * res.send(quotes[index]);
373
+ * })
374
+ * // Client side:
375
+ * client.callExtension('get', 'quotes/random')
376
+ * .then(quote => {
377
+ * console.log(`Got random quote: ${quote}`);
378
+ * })
379
+ * @param method http method to bind to
380
+ * @param ext_path path to bind to (appended to /ext/)
381
+ * @param handler your Express request handler callback
382
+ */
383
+ extend(method, ext_path, handler) {
384
+ throw new AceBaseServerNotReadyError();
385
+ }
386
+ /**
387
+ * Configure an auth provider to allow users to sign in with Facebook, Google, etc
388
+ * @param providerName name of the third party OAuth provider. Eg: "Facebook", "Google", "spotify" etc
389
+ * @param settings API key & secret for the OAuth provider
390
+ * @returns Returns the created auth provider instance, which can be used to call non-user specific methods the provider might support. (example: the Spotify auth provider supports getClientAuthToken, which allows API calls to be made to the core (non-user) spotify service)
391
+ */
392
+ configAuthProvider(providerName, settings) {
393
+ if (!this.config.auth.enabled) {
394
+ throw new Error(`Authentication is not enabled`);
395
+ }
396
+ try {
397
+ const AuthProvider = oauth_providers_1.default[providerName];
398
+ const provider = new AuthProvider(settings);
399
+ this.authProviders[providerName] = provider;
400
+ return provider;
401
+ }
402
+ catch (err) {
403
+ throw new Error(`Failed to configure provider ${providerName}: ${err.message}`);
404
+ }
405
+ }
406
+ setRule(paths, types, callback) {
407
+ throw new AceBaseServerNotReadyError();
408
+ }
409
+ }
410
+ exports.AceBaseServer = AceBaseServer;
408
411
  //# sourceMappingURL=server.js.map