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