acebase-server 1.16.1 → 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.
- package/README.md +180 -10
- package/build-vars.js +2 -1
- package/dist/cjs/auth.js +88 -88
- package/dist/cjs/cluster.js +56 -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 +415 -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 -78
- package/dist/cjs/shared/validate.js +61 -61
- package/dist/cjs/start.js +53 -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 +54 -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 -71
- package/dist/esm/shared/validate.js +41 -41
- package/dist/esm/start.js +50 -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 +1 -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 +19 -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 -23
- 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 +4 -4
- package/src/routes/data-set.yaml +5 -5
- package/src/routes/data-update.yaml +4 -4
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSocketManager = void 0;
|
|
4
|
-
const acebase_core_1 = require("acebase-core");
|
|
5
|
-
class WebSocketManager extends acebase_core_1.SimpleEventEmitter {
|
|
6
|
-
constructor(framework) {
|
|
7
|
-
super();
|
|
8
|
-
this.framework = framework;
|
|
9
|
-
}
|
|
10
|
-
on(event, callback) {
|
|
11
|
-
super.on(event, callback);
|
|
12
|
-
}
|
|
13
|
-
emit(event, data) { super.emit(event, data); return this; }
|
|
14
|
-
}
|
|
15
|
-
exports.WebSocketManager = WebSocketManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketManager = void 0;
|
|
4
|
+
const acebase_core_1 = require("acebase-core");
|
|
5
|
+
class WebSocketManager extends acebase_core_1.SimpleEventEmitter {
|
|
6
|
+
constructor(framework) {
|
|
7
|
+
super();
|
|
8
|
+
this.framework = framework;
|
|
9
|
+
}
|
|
10
|
+
on(event, callback) {
|
|
11
|
+
super.on(event, callback);
|
|
12
|
+
}
|
|
13
|
+
emit(event, data) { super.emit(event, data); return this; }
|
|
14
|
+
}
|
|
15
|
+
exports.WebSocketManager = WebSocketManager;
|
|
16
16
|
//# sourceMappingURL=manager.js.map
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createServer = exports.SocketIOManager = void 0;
|
|
4
|
-
const socket_io_1 = require("socket.io");
|
|
5
|
-
const createSocketIOServer = (httpServer, options) => {
|
|
6
|
-
return new socket_io_1.Server(httpServer, options);
|
|
7
|
-
};
|
|
8
|
-
const manager_1 = require("./manager");
|
|
9
|
-
const cors_1 = require("../middleware/cors");
|
|
10
|
-
class SocketIOManager extends manager_1.WebSocketManager {
|
|
11
|
-
constructor() {
|
|
12
|
-
super('Socket.IO');
|
|
13
|
-
}
|
|
14
|
-
disconnect(socket) {
|
|
15
|
-
socket.disconnect(true);
|
|
16
|
-
}
|
|
17
|
-
send(socket, event, message) {
|
|
18
|
-
socket.emit(event, message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.SocketIOManager = SocketIOManager;
|
|
22
|
-
const createServer = (env) => {
|
|
23
|
-
// TODO: determine max socket payload using env.config.maxPayloadSize which is now only used for json POST data
|
|
24
|
-
// const maxPayloadBytes = ((payloadStr) => {
|
|
25
|
-
// const match = payloadStr.match(/^([0-9]+)(?:mb|kb|b)$/i);
|
|
26
|
-
// if (!match) { return 10e7; } // Socket.IO 2.x default (100MB), 3.x default is 1MB (1e6)
|
|
27
|
-
// const nr = +match[0], unit = match[1].toLowerCase();
|
|
28
|
-
// switch (unit) {
|
|
29
|
-
// case 'mb': return nr * 1e6;
|
|
30
|
-
// case 'kb': return nr * 1e3;
|
|
31
|
-
// case 'b': return nr;
|
|
32
|
-
// }
|
|
33
|
-
// }, env.config.maxPayloadSize);
|
|
34
|
-
const maxPayloadBytes = 10e7; // Socket is closed if sent message exceeds this. Socket.io 2.x default is 10e7 (100MB)
|
|
35
|
-
const server = createSocketIOServer(env.server, {
|
|
36
|
-
// See https://socket.io/docs/v2/server-initialization/ and https://socket.io/docs/v3/server-initialization/
|
|
37
|
-
pingInterval: 5000,
|
|
38
|
-
pingTimeout: 5000,
|
|
39
|
-
maxHttpBufferSize: maxPayloadBytes,
|
|
40
|
-
path: `/${env.rootPath ? `${env.rootPath}/` : ''}socket.io`,
|
|
41
|
-
// Allow socket.io 2.x clients (using engine.io 3.x):
|
|
42
|
-
allowEIO3: true,
|
|
43
|
-
// socket.io 3+ uses cors package:
|
|
44
|
-
cors: (0, cors_1.getCorsOptions)(env.config.allowOrigin),
|
|
45
|
-
});
|
|
46
|
-
// Setup event emitter for communication with consuming server
|
|
47
|
-
const manager = new SocketIOManager();
|
|
48
|
-
server.sockets.on('connection', socket => {
|
|
49
|
-
const { protocol, host, port } = socket.request.headers;
|
|
50
|
-
// Notify manager of new connection
|
|
51
|
-
manager.emit('connect', { socket, socket_id: socket.id });
|
|
52
|
-
// Pass any events to manager
|
|
53
|
-
socket.on('disconnect', reason => manager.emit('disconnect', { socket, socket_id: socket.id, data: reason }));
|
|
54
|
-
socket.on('reconnect', data => manager.emit('connect', { socket, socket_id: socket.id, data }));
|
|
55
|
-
socket.on('signin', accessToken => manager.emit('signin', { socket, socket_id: socket.id, data: { accessToken } }));
|
|
56
|
-
socket.on('signout', data => manager.emit('signout', { socket, socket_id: socket.id, data }));
|
|
57
|
-
socket.on('oauth2-signin', data => {
|
|
58
|
-
data.server = { protocol, host, port }; // Add server info - event handler needs that to contruct callback url for OAuth2 provider
|
|
59
|
-
manager.emit('oauth2-signin', { socket, socket_id: socket.id, data });
|
|
60
|
-
});
|
|
61
|
-
socket.on('subscribe', data => manager.emit('subscribe', { socket, socket_id: socket.id, data }));
|
|
62
|
-
socket.on('unsubscribe', data => manager.emit('unsubscribe', { socket, socket_id: socket.id, data }));
|
|
63
|
-
socket.on('query-unsubscribe', data => manager.emit('query-unsubscribe', { socket, socket_id: socket.id, data }));
|
|
64
|
-
socket.on('query_unsubscribe', data => manager.emit('query-unsubscribe', { socket, socket_id: socket.id, data })); // OLD spelling "query_unsubscribe"
|
|
65
|
-
socket.on('transaction', data => {
|
|
66
|
-
if (data.action === 'start') {
|
|
67
|
-
manager.emit('transaction-start', { socket, socket_id: socket.id, data });
|
|
68
|
-
}
|
|
69
|
-
else if (data.action === 'finish') {
|
|
70
|
-
manager.emit('transaction-finish', { socket, socket_id: socket.id, data });
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
return manager;
|
|
75
|
-
};
|
|
76
|
-
exports.createServer = createServer;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServer = exports.SocketIOManager = void 0;
|
|
4
|
+
const socket_io_1 = require("socket.io");
|
|
5
|
+
const createSocketIOServer = (httpServer, options) => {
|
|
6
|
+
return new socket_io_1.Server(httpServer, options);
|
|
7
|
+
};
|
|
8
|
+
const manager_1 = require("./manager");
|
|
9
|
+
const cors_1 = require("../middleware/cors");
|
|
10
|
+
class SocketIOManager extends manager_1.WebSocketManager {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('Socket.IO');
|
|
13
|
+
}
|
|
14
|
+
disconnect(socket) {
|
|
15
|
+
socket.disconnect(true);
|
|
16
|
+
}
|
|
17
|
+
send(socket, event, message) {
|
|
18
|
+
socket.emit(event, message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.SocketIOManager = SocketIOManager;
|
|
22
|
+
const createServer = (env) => {
|
|
23
|
+
// TODO: determine max socket payload using env.config.maxPayloadSize which is now only used for json POST data
|
|
24
|
+
// const maxPayloadBytes = ((payloadStr) => {
|
|
25
|
+
// const match = payloadStr.match(/^([0-9]+)(?:mb|kb|b)$/i);
|
|
26
|
+
// if (!match) { return 10e7; } // Socket.IO 2.x default (100MB), 3.x default is 1MB (1e6)
|
|
27
|
+
// const nr = +match[0], unit = match[1].toLowerCase();
|
|
28
|
+
// switch (unit) {
|
|
29
|
+
// case 'mb': return nr * 1e6;
|
|
30
|
+
// case 'kb': return nr * 1e3;
|
|
31
|
+
// case 'b': return nr;
|
|
32
|
+
// }
|
|
33
|
+
// }, env.config.maxPayloadSize);
|
|
34
|
+
const maxPayloadBytes = 10e7; // Socket is closed if sent message exceeds this. Socket.io 2.x default is 10e7 (100MB)
|
|
35
|
+
const server = createSocketIOServer(env.server, {
|
|
36
|
+
// See https://socket.io/docs/v2/server-initialization/ and https://socket.io/docs/v3/server-initialization/
|
|
37
|
+
pingInterval: 5000,
|
|
38
|
+
pingTimeout: 5000,
|
|
39
|
+
maxHttpBufferSize: maxPayloadBytes,
|
|
40
|
+
path: `/${env.rootPath ? `${env.rootPath}/` : ''}socket.io`,
|
|
41
|
+
// Allow socket.io 2.x clients (using engine.io 3.x):
|
|
42
|
+
allowEIO3: true,
|
|
43
|
+
// socket.io 3+ uses cors package:
|
|
44
|
+
cors: (0, cors_1.getCorsOptions)(env.config.allowOrigin),
|
|
45
|
+
});
|
|
46
|
+
// Setup event emitter for communication with consuming server
|
|
47
|
+
const manager = new SocketIOManager();
|
|
48
|
+
server.sockets.on('connection', socket => {
|
|
49
|
+
const { protocol, host, port } = socket.request.headers;
|
|
50
|
+
// Notify manager of new connection
|
|
51
|
+
manager.emit('connect', { socket, socket_id: socket.id });
|
|
52
|
+
// Pass any events to manager
|
|
53
|
+
socket.on('disconnect', reason => manager.emit('disconnect', { socket, socket_id: socket.id, data: reason }));
|
|
54
|
+
socket.on('reconnect', data => manager.emit('connect', { socket, socket_id: socket.id, data }));
|
|
55
|
+
socket.on('signin', accessToken => manager.emit('signin', { socket, socket_id: socket.id, data: { accessToken } }));
|
|
56
|
+
socket.on('signout', data => manager.emit('signout', { socket, socket_id: socket.id, data }));
|
|
57
|
+
socket.on('oauth2-signin', data => {
|
|
58
|
+
data.server = { protocol, host, port }; // Add server info - event handler needs that to contruct callback url for OAuth2 provider
|
|
59
|
+
manager.emit('oauth2-signin', { socket, socket_id: socket.id, data });
|
|
60
|
+
});
|
|
61
|
+
socket.on('subscribe', data => manager.emit('subscribe', { socket, socket_id: socket.id, data }));
|
|
62
|
+
socket.on('unsubscribe', data => manager.emit('unsubscribe', { socket, socket_id: socket.id, data }));
|
|
63
|
+
socket.on('query-unsubscribe', data => manager.emit('query-unsubscribe', { socket, socket_id: socket.id, data }));
|
|
64
|
+
socket.on('query_unsubscribe', data => manager.emit('query-unsubscribe', { socket, socket_id: socket.id, data })); // OLD spelling "query_unsubscribe"
|
|
65
|
+
socket.on('transaction', data => {
|
|
66
|
+
if (data.action === 'start') {
|
|
67
|
+
manager.emit('transaction-start', { socket, socket_id: socket.id, data });
|
|
68
|
+
}
|
|
69
|
+
else if (data.action === 'finish') {
|
|
70
|
+
manager.emit('transaction-finish', { socket, socket_id: socket.id, data });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return manager;
|
|
75
|
+
};
|
|
76
|
+
exports.createServer = createServer;
|
|
77
77
|
//# sourceMappingURL=socket.io.js.map
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { ColorStyle, SimpleCache } from 'acebase-core';
|
|
2
|
-
import { randomBytes } from 'crypto';
|
|
3
|
-
import { createPasswordHash, generatePassword, getOldPasswordHash, getPasswordHash } from './shared/password.js';
|
|
4
|
-
export const setupAuthentication = async (env) => {
|
|
5
|
-
// Setup auth cache
|
|
6
|
-
env.authCache = new SimpleCache({ expirySeconds: 300, cloneValues: false, maxEntries: 1000 });
|
|
7
|
-
// Get or generate a salt to hash public tokens with
|
|
8
|
-
await env.securityRef.child('token_salt').transaction(snap => {
|
|
9
|
-
env.tokenSalt = snap.val();
|
|
10
|
-
if (!env.tokenSalt) {
|
|
11
|
-
const length = 256;
|
|
12
|
-
env.tokenSalt = randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
13
|
-
return env.tokenSalt;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
// Setup admin account
|
|
17
|
-
await env.authRef.child('admin').transaction(snap => {
|
|
18
|
-
let adminAccount = snap.val();
|
|
19
|
-
if (adminAccount === null) {
|
|
20
|
-
// Use provided default password, or generate one:
|
|
21
|
-
const adminPassword = env.config.auth.defaultAdminPassword || generatePassword();
|
|
22
|
-
const pwd = createPasswordHash(adminPassword);
|
|
23
|
-
adminAccount = {
|
|
24
|
-
uid: null,
|
|
25
|
-
username: 'admin',
|
|
26
|
-
email: null,
|
|
27
|
-
display_name: `${env.db.name} AceBase admin`,
|
|
28
|
-
password: pwd.hash,
|
|
29
|
-
password_salt: pwd.salt,
|
|
30
|
-
change_password: true,
|
|
31
|
-
created: new Date(),
|
|
32
|
-
access_token: null,
|
|
33
|
-
settings: {},
|
|
34
|
-
};
|
|
35
|
-
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
36
|
-
env.debug.warn(``.colorize(ColorStyle.red));
|
|
37
|
-
env.debug.warn(`IMPORTANT: Admin account created`.colorize(ColorStyle.red));
|
|
38
|
-
env.debug.warn(`You need the admin account to remotely administer the database`.colorize(ColorStyle.red));
|
|
39
|
-
env.debug.warn(`Use the following credentials to authenticate an AceBaseClient:`.colorize(ColorStyle.red));
|
|
40
|
-
env.debug.warn(``);
|
|
41
|
-
env.debug.warn(` username: admin`.colorize(ColorStyle.red));
|
|
42
|
-
env.debug.warn(` password: ${adminPassword}`.colorize(ColorStyle.red));
|
|
43
|
-
env.debug.warn(``);
|
|
44
|
-
env.debug.warn(`THIS IS ONLY SHOWN ONCE!`.colorize(ColorStyle.red));
|
|
45
|
-
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
46
|
-
return adminAccount; // Save it
|
|
47
|
-
}
|
|
48
|
-
else if (env.config.auth.defaultAdminPassword) {
|
|
49
|
-
// Check if the default password was changed
|
|
50
|
-
let passwordHash;
|
|
51
|
-
if (!adminAccount.password_salt) {
|
|
52
|
-
// Old md5 password hash?
|
|
53
|
-
passwordHash = getOldPasswordHash(env.config.auth.defaultAdminPassword);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
passwordHash = getPasswordHash(env.config.auth.defaultAdminPassword, adminAccount.password_salt);
|
|
57
|
-
}
|
|
58
|
-
if (adminAccount.password === passwordHash) {
|
|
59
|
-
env.debug.warn(`WARNING: default password for admin user was not changed!`.colorize(ColorStyle.red));
|
|
60
|
-
if (!adminAccount.password_salt) {
|
|
61
|
-
// Create new password hash
|
|
62
|
-
const pwd = createPasswordHash(env.config.auth.defaultAdminPassword);
|
|
63
|
-
adminAccount.password = pwd.hash;
|
|
64
|
-
adminAccount.password_salt = pwd.salt;
|
|
65
|
-
return adminAccount; // Save it
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
// Make sure indexes are present for quick user lookups
|
|
71
|
-
env.authDb.indexes.create(env.authRef.path, 'username');
|
|
72
|
-
env.authDb.indexes.create(env.authRef.path, 'email');
|
|
73
|
-
env.authDb.indexes.create(env.authRef.path, 'access_token');
|
|
74
|
-
};
|
|
75
|
-
export default setupAuthentication;
|
|
1
|
+
import { ColorStyle, SimpleCache } from 'acebase-core';
|
|
2
|
+
import { randomBytes } from 'crypto';
|
|
3
|
+
import { createPasswordHash, generatePassword, getOldPasswordHash, getPasswordHash } from './shared/password.js';
|
|
4
|
+
export const setupAuthentication = async (env) => {
|
|
5
|
+
// Setup auth cache
|
|
6
|
+
env.authCache = new SimpleCache({ expirySeconds: 300, cloneValues: false, maxEntries: 1000 });
|
|
7
|
+
// Get or generate a salt to hash public tokens with
|
|
8
|
+
await env.securityRef.child('token_salt').transaction(snap => {
|
|
9
|
+
env.tokenSalt = snap.val();
|
|
10
|
+
if (!env.tokenSalt) {
|
|
11
|
+
const length = 256;
|
|
12
|
+
env.tokenSalt = randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
13
|
+
return env.tokenSalt;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
// Setup admin account
|
|
17
|
+
await env.authRef.child('admin').transaction(snap => {
|
|
18
|
+
let adminAccount = snap.val();
|
|
19
|
+
if (adminAccount === null) {
|
|
20
|
+
// Use provided default password, or generate one:
|
|
21
|
+
const adminPassword = env.config.auth.defaultAdminPassword || generatePassword();
|
|
22
|
+
const pwd = createPasswordHash(adminPassword);
|
|
23
|
+
adminAccount = {
|
|
24
|
+
uid: null,
|
|
25
|
+
username: 'admin',
|
|
26
|
+
email: null,
|
|
27
|
+
display_name: `${env.db.name} AceBase admin`,
|
|
28
|
+
password: pwd.hash,
|
|
29
|
+
password_salt: pwd.salt,
|
|
30
|
+
change_password: true,
|
|
31
|
+
created: new Date(),
|
|
32
|
+
access_token: null,
|
|
33
|
+
settings: {},
|
|
34
|
+
};
|
|
35
|
+
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
36
|
+
env.debug.warn(``.colorize(ColorStyle.red));
|
|
37
|
+
env.debug.warn(`IMPORTANT: Admin account created`.colorize(ColorStyle.red));
|
|
38
|
+
env.debug.warn(`You need the admin account to remotely administer the database`.colorize(ColorStyle.red));
|
|
39
|
+
env.debug.warn(`Use the following credentials to authenticate an AceBaseClient:`.colorize(ColorStyle.red));
|
|
40
|
+
env.debug.warn(``);
|
|
41
|
+
env.debug.warn(` username: admin`.colorize(ColorStyle.red));
|
|
42
|
+
env.debug.warn(` password: ${adminPassword}`.colorize(ColorStyle.red));
|
|
43
|
+
env.debug.warn(``);
|
|
44
|
+
env.debug.warn(`THIS IS ONLY SHOWN ONCE!`.colorize(ColorStyle.red));
|
|
45
|
+
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
46
|
+
return adminAccount; // Save it
|
|
47
|
+
}
|
|
48
|
+
else if (env.config.auth.defaultAdminPassword) {
|
|
49
|
+
// Check if the default password was changed
|
|
50
|
+
let passwordHash;
|
|
51
|
+
if (!adminAccount.password_salt) {
|
|
52
|
+
// Old md5 password hash?
|
|
53
|
+
passwordHash = getOldPasswordHash(env.config.auth.defaultAdminPassword);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
passwordHash = getPasswordHash(env.config.auth.defaultAdminPassword, adminAccount.password_salt);
|
|
57
|
+
}
|
|
58
|
+
if (adminAccount.password === passwordHash) {
|
|
59
|
+
env.debug.warn(`WARNING: default password for admin user was not changed!`.colorize(ColorStyle.red));
|
|
60
|
+
if (!adminAccount.password_salt) {
|
|
61
|
+
// Create new password hash
|
|
62
|
+
const pwd = createPasswordHash(env.config.auth.defaultAdminPassword);
|
|
63
|
+
adminAccount.password = pwd.hash;
|
|
64
|
+
adminAccount.password_salt = pwd.salt;
|
|
65
|
+
return adminAccount; // Save it
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// Make sure indexes are present for quick user lookups
|
|
71
|
+
env.authDb.indexes.create(env.authRef.path, 'username');
|
|
72
|
+
env.authDb.indexes.create(env.authRef.path, 'email');
|
|
73
|
+
env.authDb.indexes.create(env.authRef.path, 'access_token');
|
|
74
|
+
};
|
|
75
|
+
export default setupAuthentication;
|
|
76
76
|
//# sourceMappingURL=auth.js.map
|
package/dist/esm/cluster.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { AceBase } from 'acebase';
|
|
2
|
-
import { AceBaseServer } from './server.js';
|
|
3
|
-
import * as cluster from 'cluster';
|
|
4
|
-
const numCPUs = 2; //os.cpus().length;
|
|
5
|
-
/**
|
|
6
|
-
* Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
|
|
7
|
-
* built-in cluster functionality.
|
|
8
|
-
*
|
|
9
|
-
* If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
|
|
10
|
-
* To do that, see https://github.com/appy-one/acebase-ipc-server
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
const dbname = 'default';
|
|
14
|
-
const options = { /* default options */}; // Load from cluster.config.js!
|
|
15
|
-
options.authentication = { enabled: false };
|
|
16
|
-
options.https = { enabled: false };
|
|
17
|
-
if (cluster.isMaster) {
|
|
18
|
-
// Startup master
|
|
19
|
-
console.log(`Starting database server cluster with ${numCPUs} workers`);
|
|
20
|
-
const master = new AceBase(dbname, options);
|
|
21
|
-
master.once('ready', () => {
|
|
22
|
-
console.log(`Master database server started on process ${process.pid}`);
|
|
23
|
-
});
|
|
24
|
-
for (let i = 0; i < numCPUs; i++) {
|
|
25
|
-
const worker = cluster.fork();
|
|
26
|
-
worker.on('disconnect', () => {
|
|
27
|
-
console.error(`worker ${worker.process.pid} disconnected`);
|
|
28
|
-
});
|
|
29
|
-
worker.on('message', (msg) => {
|
|
30
|
-
if (msg === 'acebase-server-shutdown') {
|
|
31
|
-
// We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
|
|
32
|
-
// worker.kill();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
cluster.on('exit', (worker, code, signal) => {
|
|
37
|
-
console.error(`worker ${worker.process.pid} died`);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
console.log(`Worker ${process.pid} is running`);
|
|
42
|
-
const server = new AceBaseServer(dbname, options);
|
|
43
|
-
server.ready(() => {
|
|
44
|
-
console.log(`Worker database server started on process ${process.pid}`);
|
|
45
|
-
});
|
|
46
|
-
// Handle shutdown event to exit the worker process safely
|
|
47
|
-
server.on('shutdown', () => {
|
|
48
|
-
process.exit();
|
|
49
|
-
});
|
|
50
|
-
// Other option:
|
|
51
|
-
// process.on('acebase-server-shutdown', () => {
|
|
52
|
-
// process.exit();
|
|
53
|
-
// });
|
|
54
|
-
}
|
|
1
|
+
import { AceBase } from 'acebase';
|
|
2
|
+
import { AceBaseServer } from './server.js';
|
|
3
|
+
import * as cluster from 'cluster';
|
|
4
|
+
const numCPUs = 2; //os.cpus().length;
|
|
5
|
+
/**
|
|
6
|
+
* Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
|
|
7
|
+
* built-in cluster functionality.
|
|
8
|
+
*
|
|
9
|
+
* If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
|
|
10
|
+
* To do that, see https://github.com/appy-one/acebase-ipc-server
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
const dbname = 'default';
|
|
14
|
+
const options = { /* default options */}; // Load from cluster.config.js!
|
|
15
|
+
options.authentication = { enabled: false };
|
|
16
|
+
options.https = { enabled: false };
|
|
17
|
+
if (cluster.isMaster) {
|
|
18
|
+
// Startup master
|
|
19
|
+
console.log(`Starting database server cluster with ${numCPUs} workers`);
|
|
20
|
+
const master = new AceBase(dbname, options);
|
|
21
|
+
master.once('ready', () => {
|
|
22
|
+
console.log(`Master database server started on process ${process.pid}`);
|
|
23
|
+
});
|
|
24
|
+
for (let i = 0; i < numCPUs; i++) {
|
|
25
|
+
const worker = cluster.fork();
|
|
26
|
+
worker.on('disconnect', () => {
|
|
27
|
+
console.error(`worker ${worker.process.pid} disconnected`);
|
|
28
|
+
});
|
|
29
|
+
worker.on('message', (msg) => {
|
|
30
|
+
if (msg === 'acebase-server-shutdown') {
|
|
31
|
+
// We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
|
|
32
|
+
// worker.kill();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
cluster.on('exit', (worker, code, signal) => {
|
|
37
|
+
console.error(`worker ${worker.process.pid} died`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.log(`Worker ${process.pid} is running`);
|
|
42
|
+
const server = new AceBaseServer(dbname, options);
|
|
43
|
+
server.ready(() => {
|
|
44
|
+
console.log(`Worker database server started on process ${process.pid}`);
|
|
45
|
+
});
|
|
46
|
+
// Handle shutdown event to exit the worker process safely
|
|
47
|
+
server.on('shutdown', () => {
|
|
48
|
+
process.exit();
|
|
49
|
+
});
|
|
50
|
+
// Other option:
|
|
51
|
+
// process.on('acebase-server-shutdown', () => {
|
|
52
|
+
// process.exit();
|
|
53
|
+
// });
|
|
54
|
+
}
|
|
55
55
|
//# sourceMappingURL=cluster.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../types';
|
|
1
|
+
export * from '../types/index.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { AceBaseServer } from './server.js';
|
|
2
|
-
export { AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings/index.js';
|
|
3
|
-
export * from './shared/email.js';
|
|
4
|
-
export * from './oauth-providers/index.js';
|
|
1
|
+
export { AceBaseServer } from './server.js';
|
|
2
|
+
export { AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings/index.js';
|
|
3
|
+
export * from './shared/email.js';
|
|
4
|
+
export * from './oauth-providers/index.js';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/logger.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
export class DatabaseLog {
|
|
2
|
-
constructor(logRef) {
|
|
3
|
-
this.logRef = logRef;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Logs an action initiated by a client/user with a positive or negative outcome. Used by `success` and `failure`
|
|
7
|
-
* @param action action identifier
|
|
8
|
-
* @param success whether the action was successful
|
|
9
|
-
* @param details any additional details to be logged
|
|
10
|
-
*/
|
|
11
|
-
async event(action, details) {
|
|
12
|
-
await this.logRef?.push({ type: 'event', action, date: new Date(), ...details });
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Logs a system warning
|
|
16
|
-
* @param action action identifier
|
|
17
|
-
* @param code warning code
|
|
18
|
-
* @param details any additional details to be logged
|
|
19
|
-
*/
|
|
20
|
-
async warning(action, code, details) {
|
|
21
|
-
await this.logRef?.push({ type: 'warning', action, code, date: new Date(), ...details });
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Logs a system or client/user error
|
|
25
|
-
* @param action action identifier
|
|
26
|
-
* @param code error code
|
|
27
|
-
* @param details any additional details to be logged
|
|
28
|
-
*/
|
|
29
|
-
async error(action, code, details, unexpectedError) {
|
|
30
|
-
const errorDetails = unexpectedError instanceof Error
|
|
31
|
-
? { error: unexpectedError.stack ?? unexpectedError.message }
|
|
32
|
-
: { error: unexpectedError?.message ?? unexpectedError?.toString() ?? null };
|
|
33
|
-
await this.logRef?.push({ type: 'error', action, code, date: new Date(), ...errorDetails, ...details });
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Query the logs
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
query() {
|
|
40
|
-
if (!this.logRef) {
|
|
41
|
-
throw new Error('Logging is not enabled');
|
|
42
|
-
}
|
|
43
|
-
return this.logRef.query();
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Reference to the logs database collection
|
|
47
|
-
*/
|
|
48
|
-
get ref() {
|
|
49
|
-
return this?.logRef;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
export class DatabaseLog {
|
|
2
|
+
constructor(logRef) {
|
|
3
|
+
this.logRef = logRef;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Logs an action initiated by a client/user with a positive or negative outcome. Used by `success` and `failure`
|
|
7
|
+
* @param action action identifier
|
|
8
|
+
* @param success whether the action was successful
|
|
9
|
+
* @param details any additional details to be logged
|
|
10
|
+
*/
|
|
11
|
+
async event(action, details) {
|
|
12
|
+
await this.logRef?.push({ type: 'event', action, date: new Date(), ...details });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Logs a system warning
|
|
16
|
+
* @param action action identifier
|
|
17
|
+
* @param code warning code
|
|
18
|
+
* @param details any additional details to be logged
|
|
19
|
+
*/
|
|
20
|
+
async warning(action, code, details) {
|
|
21
|
+
await this.logRef?.push({ type: 'warning', action, code, date: new Date(), ...details });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Logs a system or client/user error
|
|
25
|
+
* @param action action identifier
|
|
26
|
+
* @param code error code
|
|
27
|
+
* @param details any additional details to be logged
|
|
28
|
+
*/
|
|
29
|
+
async error(action, code, details, unexpectedError) {
|
|
30
|
+
const errorDetails = unexpectedError instanceof Error
|
|
31
|
+
? { error: unexpectedError.stack ?? unexpectedError.message }
|
|
32
|
+
: { error: unexpectedError?.message ?? unexpectedError?.toString() ?? null };
|
|
33
|
+
await this.logRef?.push({ type: 'error', action, code, date: new Date(), ...errorDetails, ...details });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Query the logs
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
query() {
|
|
40
|
+
if (!this.logRef) {
|
|
41
|
+
throw new Error('Logging is not enabled');
|
|
42
|
+
}
|
|
43
|
+
return this.logRef.query();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reference to the logs database collection
|
|
47
|
+
*/
|
|
48
|
+
get ref() {
|
|
49
|
+
return this?.logRef;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
52
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds 404 middleware.
|
|
3
|
-
* @param env
|
|
4
|
-
*/
|
|
5
|
-
export const addMiddleware = (env) => {
|
|
6
|
-
env.app.use((req, res, next) => {
|
|
7
|
-
res.status(404).send('Not Found');
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export default addMiddleware;
|
|
1
|
+
/**
|
|
2
|
+
* Adds 404 middleware. This binds to `env.app` so routes added to `env.router` always come first, even if they are added after the 404 handler
|
|
3
|
+
* @param env
|
|
4
|
+
*/
|
|
5
|
+
export const addMiddleware = (env) => {
|
|
6
|
+
env.app.use((req, res, next) => {
|
|
7
|
+
res.status(404).send('Not Found');
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export default addMiddleware;
|
|
11
11
|
//# sourceMappingURL=404.js.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { sendUnauthorizedError } from '../shared/error.js';
|
|
2
|
-
/**
|
|
3
|
-
* Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
|
|
4
|
-
* authentication is enabled on the server and the user is not signed in as admin.
|
|
5
|
-
*
|
|
6
|
-
* Can be applied to any route by adding it in the router chain.
|
|
7
|
-
* @example
|
|
8
|
-
* app.get('/endpoint', adminOnly(env), (req, res) => {
|
|
9
|
-
* // If we get here we are either an admin,
|
|
10
|
-
* // or the server doesn't have authentication enabled.
|
|
11
|
-
* })
|
|
12
|
-
* @param env Middle
|
|
13
|
-
* @param errorMessage
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export const adminOnly = (env, errorMessage = 'only admin can perform this operation') => {
|
|
17
|
-
return (req, res, next) => {
|
|
18
|
-
if (env.config.auth.enabled && (!req.user || req.user.uid !== 'admin')) {
|
|
19
|
-
return sendUnauthorizedError(res, 'admin_only', errorMessage);
|
|
20
|
-
}
|
|
21
|
-
next();
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export default adminOnly;
|
|
1
|
+
import { sendUnauthorizedError } from '../shared/error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
|
|
4
|
+
* authentication is enabled on the server and the user is not signed in as admin.
|
|
5
|
+
*
|
|
6
|
+
* Can be applied to any route by adding it in the router chain.
|
|
7
|
+
* @example
|
|
8
|
+
* app.get('/endpoint', adminOnly(env), (req, res) => {
|
|
9
|
+
* // If we get here we are either an admin,
|
|
10
|
+
* // or the server doesn't have authentication enabled.
|
|
11
|
+
* })
|
|
12
|
+
* @param env Middle
|
|
13
|
+
* @param errorMessage
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export const adminOnly = (env, errorMessage = 'only admin can perform this operation') => {
|
|
17
|
+
return (req, res, next) => {
|
|
18
|
+
if (env.config.auth.enabled && (!req.user || req.user.uid !== 'admin')) {
|
|
19
|
+
return sendUnauthorizedError(res, 'admin_only', errorMessage);
|
|
20
|
+
}
|
|
21
|
+
next();
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export default adminOnly;
|
|
25
25
|
//# sourceMappingURL=admin-only.js.map
|