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