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/cjs/server.js
CHANGED
|
@@ -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
|
|
30
|
-
const
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
this.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
(yield Promise.resolve().then(() => require('./
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
server.off('
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
407
|
-
|
|
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
|