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,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=email.js.map
|
|
@@ -1,166 +1,169 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
export class AceBaseServerHttpsConfig {
|
|
3
|
-
constructor(settings) {
|
|
4
|
-
this.enabled = true;
|
|
5
|
-
this.enabled = typeof settings === 'object' && settings.enabled !== false;
|
|
6
|
-
if (!this.enabled) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (settings.keyPath) {
|
|
10
|
-
this.key = readFileSync(settings.keyPath);
|
|
11
|
-
this.cert = readFileSync(settings.certPath);
|
|
12
|
-
}
|
|
13
|
-
else if (settings.pfxPath) {
|
|
14
|
-
this.pfx = readFileSync(settings.pfxPath);
|
|
15
|
-
this.passphrase = settings.passphrase;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export const AUTH_ACCESS_DEFAULT = {
|
|
20
|
-
DENY_ALL: 'deny',
|
|
21
|
-
ALLOW_ALL: 'allow',
|
|
22
|
-
ALLOW_AUTHENTICATED: 'auth',
|
|
23
|
-
};
|
|
24
|
-
export class AceBaseServerAuthenticationSettings {
|
|
25
|
-
constructor(settings) {
|
|
26
|
-
/**
|
|
27
|
-
* Whether to enable authorization. Without authorization the entire db can be read and written to by anyone (not recommended 🤷🏼♂️)
|
|
28
|
-
*/
|
|
29
|
-
this.enabled = true;
|
|
30
|
-
/**
|
|
31
|
-
* Whether new users creation is allowed for anyone, or just the admin
|
|
32
|
-
*/
|
|
33
|
-
this.allowUserSignup = false;
|
|
34
|
-
/**
|
|
35
|
-
* How many new users can sign up per hour per IP address. not implemented yet
|
|
36
|
-
*/
|
|
37
|
-
this.newUserRateLimit = 0;
|
|
38
|
-
/**
|
|
39
|
-
* How many minutes before access tokens expire. 0 for no expiration. (not implemented yet)
|
|
40
|
-
*/
|
|
41
|
-
this.tokensExpire = 0;
|
|
42
|
-
/**
|
|
43
|
-
* When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
|
|
44
|
-
*/
|
|
45
|
-
this.defaultAccessRule = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
|
|
46
|
-
/**
|
|
47
|
-
* Whether to use a separate database for auth and logging. 'v2' will store data in auth.db, which is NOT TESTED YET!
|
|
48
|
-
*/
|
|
49
|
-
this.separateDb = false;
|
|
50
|
-
if (typeof settings !== 'object') {
|
|
51
|
-
settings = {};
|
|
52
|
-
}
|
|
53
|
-
if (typeof settings.enabled === 'boolean') {
|
|
54
|
-
this.enabled = settings.enabled;
|
|
55
|
-
}
|
|
56
|
-
if (typeof settings.allowUserSignup === 'boolean') {
|
|
57
|
-
this.allowUserSignup = settings.allowUserSignup;
|
|
58
|
-
}
|
|
59
|
-
if (typeof settings.newUserRateLimit === 'number') {
|
|
60
|
-
this.newUserRateLimit = settings.newUserRateLimit;
|
|
61
|
-
}
|
|
62
|
-
if (typeof settings.tokensExpire === 'number') {
|
|
63
|
-
this.tokensExpire = settings.tokensExpire;
|
|
64
|
-
}
|
|
65
|
-
if (typeof settings.defaultAccessRule === 'string') {
|
|
66
|
-
this.defaultAccessRule = settings.defaultAccessRule;
|
|
67
|
-
}
|
|
68
|
-
if (typeof settings.defaultAdminPassword === 'string') {
|
|
69
|
-
this.defaultAdminPassword = settings.defaultAdminPassword;
|
|
70
|
-
}
|
|
71
|
-
if (typeof settings.seperateDb === 'boolean') {
|
|
72
|
-
this.separateDb = settings.seperateDb;
|
|
73
|
-
} // Handle previous _wrong_ spelling
|
|
74
|
-
if (typeof settings.separateDb === 'boolean') {
|
|
75
|
-
this.separateDb = settings.separateDb;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* TODO: Use AceBaseTransactionLogSettings from acebase
|
|
81
|
-
*/
|
|
82
|
-
export class AceBaseServerTransactionSettings {
|
|
83
|
-
constructor(settings) {
|
|
84
|
-
/**
|
|
85
|
-
* Whether to enable transaction logging
|
|
86
|
-
*/
|
|
87
|
-
this.log = false;
|
|
88
|
-
/**
|
|
89
|
-
* Max age in days to keep transactions in the log file
|
|
90
|
-
*/
|
|
91
|
-
this.maxAge = 30;
|
|
92
|
-
/**
|
|
93
|
-
* Whether database write operations should not wait until transaction has been logged
|
|
94
|
-
*/
|
|
95
|
-
this.noWait = false;
|
|
96
|
-
if (typeof settings !== 'object') {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (typeof settings.log === 'boolean') {
|
|
100
|
-
this.log = settings.log;
|
|
101
|
-
}
|
|
102
|
-
if (typeof settings.maxAge === 'number') {
|
|
103
|
-
this.maxAge = settings.maxAge;
|
|
104
|
-
}
|
|
105
|
-
if (typeof settings.noWait === 'boolean') {
|
|
106
|
-
this.noWait = settings.noWait;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export class AceBaseServerConfig {
|
|
111
|
-
constructor(settings) {
|
|
112
|
-
this.logLevel = 'log';
|
|
113
|
-
this.host = 'localhost';
|
|
114
|
-
this.port = 3000;
|
|
115
|
-
this.path = '.';
|
|
116
|
-
this.maxPayloadSize = '10mb';
|
|
117
|
-
this.allowOrigin = '*';
|
|
118
|
-
this.rootPath = '';
|
|
119
|
-
this.sponsor = false;
|
|
120
|
-
this.logColors = true;
|
|
121
|
-
if (typeof settings !== 'object') {
|
|
122
|
-
settings = {};
|
|
123
|
-
}
|
|
124
|
-
if (typeof settings.logLevel === 'string') {
|
|
125
|
-
this.logLevel = settings.logLevel;
|
|
126
|
-
}
|
|
127
|
-
if (typeof settings.host === 'string') {
|
|
128
|
-
this.host = settings.host;
|
|
129
|
-
}
|
|
130
|
-
if (typeof settings.port === 'number') {
|
|
131
|
-
this.port = settings.port;
|
|
132
|
-
}
|
|
133
|
-
if (typeof settings.path === 'string') {
|
|
134
|
-
this.path = settings.path;
|
|
135
|
-
}
|
|
136
|
-
if (typeof settings.server === 'object') {
|
|
137
|
-
this.server = settings.server;
|
|
138
|
-
}
|
|
139
|
-
if (typeof settings.rootPath === 'string') {
|
|
140
|
-
this.rootPath = settings.rootPath.replace(/^\/|\/$/g, '');
|
|
141
|
-
}
|
|
142
|
-
this.https = new AceBaseServerHttpsConfig(settings.https);
|
|
143
|
-
this.auth = new AceBaseServerAuthenticationSettings(settings.authentication);
|
|
144
|
-
if (typeof settings.maxPayloadSize === 'string') {
|
|
145
|
-
this.maxPayloadSize = settings.maxPayloadSize;
|
|
146
|
-
}
|
|
147
|
-
if (typeof settings.allowOrigin === 'string') {
|
|
148
|
-
this.allowOrigin = settings.allowOrigin;
|
|
149
|
-
}
|
|
150
|
-
if (typeof settings.email === 'object') {
|
|
151
|
-
this.email = settings.email;
|
|
152
|
-
}
|
|
153
|
-
this.transactions = new AceBaseServerTransactionSettings(settings.transactions);
|
|
154
|
-
this.ipc = settings.ipc;
|
|
155
|
-
if (typeof settings.storage === 'object') {
|
|
156
|
-
this.storage = settings.storage;
|
|
157
|
-
}
|
|
158
|
-
if (typeof settings.sponsor === 'boolean') {
|
|
159
|
-
this.sponsor = settings.sponsor;
|
|
160
|
-
}
|
|
161
|
-
if (typeof settings.logColors === 'boolean') {
|
|
162
|
-
this.logColors = settings.logColors;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
export class AceBaseServerHttpsConfig {
|
|
3
|
+
constructor(settings) {
|
|
4
|
+
this.enabled = true;
|
|
5
|
+
this.enabled = typeof settings === 'object' && settings.enabled !== false;
|
|
6
|
+
if (!this.enabled) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (settings.keyPath) {
|
|
10
|
+
this.key = readFileSync(settings.keyPath);
|
|
11
|
+
this.cert = readFileSync(settings.certPath);
|
|
12
|
+
}
|
|
13
|
+
else if (settings.pfxPath) {
|
|
14
|
+
this.pfx = readFileSync(settings.pfxPath);
|
|
15
|
+
this.passphrase = settings.passphrase;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const AUTH_ACCESS_DEFAULT = {
|
|
20
|
+
DENY_ALL: 'deny',
|
|
21
|
+
ALLOW_ALL: 'allow',
|
|
22
|
+
ALLOW_AUTHENTICATED: 'auth',
|
|
23
|
+
};
|
|
24
|
+
export class AceBaseServerAuthenticationSettings {
|
|
25
|
+
constructor(settings) {
|
|
26
|
+
/**
|
|
27
|
+
* Whether to enable authorization. Without authorization the entire db can be read and written to by anyone (not recommended 🤷🏼♂️)
|
|
28
|
+
*/
|
|
29
|
+
this.enabled = true;
|
|
30
|
+
/**
|
|
31
|
+
* Whether new users creation is allowed for anyone, or just the admin
|
|
32
|
+
*/
|
|
33
|
+
this.allowUserSignup = false;
|
|
34
|
+
/**
|
|
35
|
+
* How many new users can sign up per hour per IP address. not implemented yet
|
|
36
|
+
*/
|
|
37
|
+
this.newUserRateLimit = 0;
|
|
38
|
+
/**
|
|
39
|
+
* How many minutes before access tokens expire. 0 for no expiration. (not implemented yet)
|
|
40
|
+
*/
|
|
41
|
+
this.tokensExpire = 0;
|
|
42
|
+
/**
|
|
43
|
+
* When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
|
|
44
|
+
*/
|
|
45
|
+
this.defaultAccessRule = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to use a separate database for auth and logging. 'v2' will store data in auth.db, which is NOT TESTED YET!
|
|
48
|
+
*/
|
|
49
|
+
this.separateDb = false;
|
|
50
|
+
if (typeof settings !== 'object') {
|
|
51
|
+
settings = {};
|
|
52
|
+
}
|
|
53
|
+
if (typeof settings.enabled === 'boolean') {
|
|
54
|
+
this.enabled = settings.enabled;
|
|
55
|
+
}
|
|
56
|
+
if (typeof settings.allowUserSignup === 'boolean') {
|
|
57
|
+
this.allowUserSignup = settings.allowUserSignup;
|
|
58
|
+
}
|
|
59
|
+
if (typeof settings.newUserRateLimit === 'number') {
|
|
60
|
+
this.newUserRateLimit = settings.newUserRateLimit;
|
|
61
|
+
}
|
|
62
|
+
if (typeof settings.tokensExpire === 'number') {
|
|
63
|
+
this.tokensExpire = settings.tokensExpire;
|
|
64
|
+
}
|
|
65
|
+
if (typeof settings.defaultAccessRule === 'string') {
|
|
66
|
+
this.defaultAccessRule = settings.defaultAccessRule;
|
|
67
|
+
}
|
|
68
|
+
if (typeof settings.defaultAdminPassword === 'string') {
|
|
69
|
+
this.defaultAdminPassword = settings.defaultAdminPassword;
|
|
70
|
+
}
|
|
71
|
+
if (typeof settings.seperateDb === 'boolean') {
|
|
72
|
+
this.separateDb = settings.seperateDb;
|
|
73
|
+
} // Handle previous _wrong_ spelling
|
|
74
|
+
if (typeof settings.separateDb === 'boolean') {
|
|
75
|
+
this.separateDb = settings.separateDb;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* TODO: Use AceBaseTransactionLogSettings from acebase
|
|
81
|
+
*/
|
|
82
|
+
export class AceBaseServerTransactionSettings {
|
|
83
|
+
constructor(settings) {
|
|
84
|
+
/**
|
|
85
|
+
* Whether to enable transaction logging
|
|
86
|
+
*/
|
|
87
|
+
this.log = false;
|
|
88
|
+
/**
|
|
89
|
+
* Max age in days to keep transactions in the log file
|
|
90
|
+
*/
|
|
91
|
+
this.maxAge = 30;
|
|
92
|
+
/**
|
|
93
|
+
* Whether database write operations should not wait until transaction has been logged
|
|
94
|
+
*/
|
|
95
|
+
this.noWait = false;
|
|
96
|
+
if (typeof settings !== 'object') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (typeof settings.log === 'boolean') {
|
|
100
|
+
this.log = settings.log;
|
|
101
|
+
}
|
|
102
|
+
if (typeof settings.maxAge === 'number') {
|
|
103
|
+
this.maxAge = settings.maxAge;
|
|
104
|
+
}
|
|
105
|
+
if (typeof settings.noWait === 'boolean') {
|
|
106
|
+
this.noWait = settings.noWait;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export class AceBaseServerConfig {
|
|
111
|
+
constructor(settings) {
|
|
112
|
+
this.logLevel = 'log';
|
|
113
|
+
this.host = 'localhost';
|
|
114
|
+
this.port = 3000;
|
|
115
|
+
this.path = '.';
|
|
116
|
+
this.maxPayloadSize = '10mb';
|
|
117
|
+
this.allowOrigin = '*';
|
|
118
|
+
this.rootPath = '';
|
|
119
|
+
this.sponsor = false;
|
|
120
|
+
this.logColors = true;
|
|
121
|
+
if (typeof settings !== 'object') {
|
|
122
|
+
settings = {};
|
|
123
|
+
}
|
|
124
|
+
if (typeof settings.logLevel === 'string') {
|
|
125
|
+
this.logLevel = settings.logLevel;
|
|
126
|
+
}
|
|
127
|
+
if (typeof settings.host === 'string') {
|
|
128
|
+
this.host = settings.host;
|
|
129
|
+
}
|
|
130
|
+
if (typeof settings.port === 'number') {
|
|
131
|
+
this.port = settings.port;
|
|
132
|
+
}
|
|
133
|
+
if (typeof settings.path === 'string') {
|
|
134
|
+
this.path = settings.path;
|
|
135
|
+
}
|
|
136
|
+
if (typeof settings.server === 'object') {
|
|
137
|
+
this.server = settings.server;
|
|
138
|
+
}
|
|
139
|
+
if (typeof settings.rootPath === 'string') {
|
|
140
|
+
this.rootPath = settings.rootPath.replace(/^\/|\/$/g, '');
|
|
141
|
+
}
|
|
142
|
+
this.https = new AceBaseServerHttpsConfig(settings.https);
|
|
143
|
+
this.auth = new AceBaseServerAuthenticationSettings(settings.authentication);
|
|
144
|
+
if (typeof settings.maxPayloadSize === 'string') {
|
|
145
|
+
this.maxPayloadSize = settings.maxPayloadSize;
|
|
146
|
+
}
|
|
147
|
+
if (typeof settings.allowOrigin === 'string') {
|
|
148
|
+
this.allowOrigin = settings.allowOrigin;
|
|
149
|
+
}
|
|
150
|
+
if (typeof settings.email === 'object') {
|
|
151
|
+
this.email = settings.email;
|
|
152
|
+
}
|
|
153
|
+
this.transactions = new AceBaseServerTransactionSettings(settings.transactions);
|
|
154
|
+
this.ipc = settings.ipc;
|
|
155
|
+
if (typeof settings.storage === 'object') {
|
|
156
|
+
this.storage = settings.storage;
|
|
157
|
+
}
|
|
158
|
+
if (typeof settings.sponsor === 'boolean') {
|
|
159
|
+
this.sponsor = settings.sponsor;
|
|
160
|
+
}
|
|
161
|
+
if (typeof settings.logColors === 'boolean') {
|
|
162
|
+
this.logColors = settings.logColors;
|
|
163
|
+
}
|
|
164
|
+
if (typeof settings.init === 'function') {
|
|
165
|
+
this.init = settings.init;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
166
169
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export class ConnectedClient {
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param socket Socket object used by the framework
|
|
5
|
-
* @param id optional: use if the socket object does not have an `id` property.
|
|
6
|
-
*/
|
|
7
|
-
constructor(socket, id) {
|
|
8
|
-
this.socket = socket;
|
|
9
|
-
// get id() { return this.socket.id; };
|
|
10
|
-
this.connectedDate = new Date();
|
|
11
|
-
/** Active event subscriptions for this client */
|
|
12
|
-
this.subscriptions = {};
|
|
13
|
-
/** Active realtime query subscriptions for this client */
|
|
14
|
-
this.realtimeQueries = {};
|
|
15
|
-
/** Currently running transactions */
|
|
16
|
-
this.transactions = {};
|
|
17
|
-
this.id = id ?? socket.id;
|
|
18
|
-
if (!this.id) {
|
|
19
|
-
throw new Error('Socket has no id');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
export class ConnectedClient {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param socket Socket object used by the framework
|
|
5
|
+
* @param id optional: use if the socket object does not have an `id` property.
|
|
6
|
+
*/
|
|
7
|
+
constructor(socket, id) {
|
|
8
|
+
this.socket = socket;
|
|
9
|
+
// get id() { return this.socket.id; };
|
|
10
|
+
this.connectedDate = new Date();
|
|
11
|
+
/** Active event subscriptions for this client */
|
|
12
|
+
this.subscriptions = {};
|
|
13
|
+
/** Active realtime query subscriptions for this client */
|
|
14
|
+
this.realtimeQueries = {};
|
|
15
|
+
/** Currently running transactions */
|
|
16
|
+
this.transactions = {};
|
|
17
|
+
this.id = id ?? socket.id;
|
|
18
|
+
if (!this.id) {
|
|
19
|
+
throw new Error('Socket has no id');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
23
|
//# sourceMappingURL=clients.js.map
|
package/dist/esm/shared/email.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=email.js.map
|
package/dist/esm/shared/env.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=env.js.map
|
package/dist/esm/shared/error.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export const sendNotAuthenticatedError = (res, code, message) => {
|
|
2
|
-
res.statusCode = 401; // Unauthorized (not unauthenticated)
|
|
3
|
-
res.statusMessage = 'Not Authenticated';
|
|
4
|
-
res.contentType('application/json').send({ code, message });
|
|
5
|
-
};
|
|
6
|
-
export const sendUnauthorizedError = (res, code, message) => {
|
|
7
|
-
res.statusCode = 403; // Forbidden
|
|
8
|
-
res.statusMessage = 'Unauthorized';
|
|
9
|
-
res.contentType('application/json').send({ code, message });
|
|
10
|
-
};
|
|
11
|
-
export const sendError = (res, err) => {
|
|
12
|
-
res.contentType('application/json');
|
|
13
|
-
if (typeof err.code === 'string') {
|
|
14
|
-
sendBadRequestError(res, err); //res.status(400).send({ code: err.code, message: err.message }); // Bad Request
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
sendUnexpectedError(res, err); // res.status(500).send({ code: 'unknown', message: 'server error', details: err.message }); // Internal server error
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export const sendBadRequestError = (res, err) => {
|
|
21
|
-
res.status(400).contentType('application/json').send({ code: err.code, message: err.message }); // Bad Request
|
|
22
|
-
};
|
|
23
|
-
export const sendUnexpectedError = (res, err) => {
|
|
24
|
-
res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: err.message }); // Internal server error
|
|
25
|
-
};
|
|
1
|
+
export const sendNotAuthenticatedError = (res, code, message) => {
|
|
2
|
+
res.statusCode = 401; // Unauthorized (not unauthenticated)
|
|
3
|
+
res.statusMessage = 'Not Authenticated';
|
|
4
|
+
res.contentType('application/json').send({ code, message });
|
|
5
|
+
};
|
|
6
|
+
export const sendUnauthorizedError = (res, code, message) => {
|
|
7
|
+
res.statusCode = 403; // Forbidden
|
|
8
|
+
res.statusMessage = 'Unauthorized';
|
|
9
|
+
res.contentType('application/json').send({ code, message });
|
|
10
|
+
};
|
|
11
|
+
export const sendError = (res, err) => {
|
|
12
|
+
res.contentType('application/json');
|
|
13
|
+
if (typeof err.code === 'string') {
|
|
14
|
+
sendBadRequestError(res, err); //res.status(400).send({ code: err.code, message: err.message }); // Bad Request
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
sendUnexpectedError(res, err); // res.status(500).send({ code: 'unknown', message: 'server error', details: err.message }); // Internal server error
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const sendBadRequestError = (res, err) => {
|
|
21
|
+
res.status(400).contentType('application/json').send({ code: err.code, message: err.message }); // Bad Request
|
|
22
|
+
};
|
|
23
|
+
export const sendUnexpectedError = (res, err) => {
|
|
24
|
+
res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: err.message }); // Internal server error
|
|
25
|
+
};
|
|
26
26
|
//# sourceMappingURL=error.js.map
|
package/dist/esm/shared/http.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as express from 'express';
|
|
2
|
-
const createExpress = express.default ?? express; // ESM and CJS compatible approach
|
|
3
|
-
/**
|
|
4
|
-
* Creates an app that handles http requests, adds json body parsing.
|
|
5
|
-
* @param settings
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export const createApp = (settings) => {
|
|
9
|
-
const app = createExpress();
|
|
10
|
-
// When behind a trusted proxy server, req.ip and req.hostname will be set the right way
|
|
11
|
-
app.set('trust proxy', settings.trustProxy);
|
|
12
|
-
// Parse json request bodies
|
|
13
|
-
app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
|
|
14
|
-
return app;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Creates an express router
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export const createRouter = () => {
|
|
21
|
-
return createExpress.Router();
|
|
22
|
-
};
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
const createExpress = express.default ?? express; // ESM and CJS compatible approach
|
|
3
|
+
/**
|
|
4
|
+
* Creates an app that handles http requests, adds json body parsing.
|
|
5
|
+
* @param settings
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const createApp = (settings) => {
|
|
9
|
+
const app = createExpress();
|
|
10
|
+
// When behind a trusted proxy server, req.ip and req.hostname will be set the right way
|
|
11
|
+
app.set('trust proxy', settings.trustProxy);
|
|
12
|
+
// Parse json request bodies
|
|
13
|
+
app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
|
|
14
|
+
return app;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Creates an express router
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export const createRouter = () => {
|
|
21
|
+
return createExpress.Router();
|
|
22
|
+
};
|
|
23
23
|
//# sourceMappingURL=http.js.map
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
export const generatePassword = () => {
|
|
3
|
-
return Array.prototype.reduce.call('abcedefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ012345789!@#$%&', (password, c, i, chars) => {
|
|
4
|
-
if (i > 15) {
|
|
5
|
-
return password;
|
|
6
|
-
}
|
|
7
|
-
return password + chars[Math.floor(Math.random() * chars.length)];
|
|
8
|
-
}, '');
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Generates a random salt and hashes the provided password with it. The resulting salt and hash should be stored in the database
|
|
12
|
-
* @param password password to hash
|
|
13
|
-
*/
|
|
14
|
-
export const createPasswordHash = (password) => {
|
|
15
|
-
const length = 16;
|
|
16
|
-
const salt = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
17
|
-
const hash = crypto.createHmac('sha512', salt).update(password).digest('hex');
|
|
18
|
-
return {
|
|
19
|
-
salt,
|
|
20
|
-
hash,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* For checking passwords: uses given password and salt to get the hash that can be compared to a stored version.
|
|
25
|
-
* @param password A password prodived by the user trying to sign in
|
|
26
|
-
* @param salt the salt used to generate the hash, must be stored with the hash in the database
|
|
27
|
-
*/
|
|
28
|
-
export const getPasswordHash = (password, salt) => {
|
|
29
|
-
return crypto.createHmac('sha512', salt).update(password).digest('hex');
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Backward compatibility with old saltless md5 passwords. Becomes obsolete once all passwords have been updated (probably already so)
|
|
33
|
-
*/
|
|
34
|
-
export const getOldPasswordHash = (password) => {
|
|
35
|
-
// Backward compatibility with old saltless md5 passwords.
|
|
36
|
-
// Becomes obsolete once all passwords have been updated
|
|
37
|
-
return crypto.createHash('md5').update(password).digest('hex');
|
|
38
|
-
};
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
export const generatePassword = () => {
|
|
3
|
+
return Array.prototype.reduce.call('abcedefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ012345789!@#$%&', (password, c, i, chars) => {
|
|
4
|
+
if (i > 15) {
|
|
5
|
+
return password;
|
|
6
|
+
}
|
|
7
|
+
return password + chars[Math.floor(Math.random() * chars.length)];
|
|
8
|
+
}, '');
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Generates a random salt and hashes the provided password with it. The resulting salt and hash should be stored in the database
|
|
12
|
+
* @param password password to hash
|
|
13
|
+
*/
|
|
14
|
+
export const createPasswordHash = (password) => {
|
|
15
|
+
const length = 16;
|
|
16
|
+
const salt = crypto.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
17
|
+
const hash = crypto.createHmac('sha512', salt).update(password).digest('hex');
|
|
18
|
+
return {
|
|
19
|
+
salt,
|
|
20
|
+
hash,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* For checking passwords: uses given password and salt to get the hash that can be compared to a stored version.
|
|
25
|
+
* @param password A password prodived by the user trying to sign in
|
|
26
|
+
* @param salt the salt used to generate the hash, must be stored with the hash in the database
|
|
27
|
+
*/
|
|
28
|
+
export const getPasswordHash = (password, salt) => {
|
|
29
|
+
return crypto.createHmac('sha512', salt).update(password).digest('hex');
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Backward compatibility with old saltless md5 passwords. Becomes obsolete once all passwords have been updated (probably already so)
|
|
33
|
+
*/
|
|
34
|
+
export const getOldPasswordHash = (password) => {
|
|
35
|
+
// Backward compatibility with old saltless md5 passwords.
|
|
36
|
+
// Becomes obsolete once all passwords have been updated
|
|
37
|
+
return crypto.createHash('md5').update(password).digest('hex');
|
|
38
|
+
};
|
|
39
39
|
//# sourceMappingURL=password.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
// This file is in ./src/shared/rootpath.ts
|
|
3
|
-
// When this code runs it is at ./dist/cjs/shared/rootpath.js or ./dist/esm/shared/rootpath.js
|
|
4
|
-
// So, the package root is at ../../..
|
|
5
|
-
let currentDir = /file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1];
|
|
6
|
-
if (process.platform === 'win32' && currentDir.startsWith('/')) {
|
|
7
|
-
// tsc-esm-fix does not handle win32 file urls correctly, the drive letter in import.meta.url is prefixed with a slash: file:///C:/dir/file.js
|
|
8
|
-
currentDir = currentDir.slice(1);
|
|
9
|
-
}
|
|
10
|
-
// tsc-esm-fix also does not use decodeURI to remove encoded characters (such as %20 for spaces)
|
|
11
|
-
currentDir = decodeURI(currentDir);
|
|
12
|
-
export const packageRootPath = resolve(currentDir, '../../..');
|
|
13
|
-
export default packageRootPath;
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
// This file is in ./src/shared/rootpath.ts
|
|
3
|
+
// When this code runs it is at ./dist/cjs/shared/rootpath.js or ./dist/esm/shared/rootpath.js
|
|
4
|
+
// So, the package root is at ../../..
|
|
5
|
+
let currentDir = /file:\/\/(.+)\/[^/]/.exec(import.meta.url)[1];
|
|
6
|
+
if (process.platform === 'win32' && currentDir.startsWith('/')) {
|
|
7
|
+
// tsc-esm-fix does not handle win32 file urls correctly, the drive letter in import.meta.url is prefixed with a slash: file:///C:/dir/file.js
|
|
8
|
+
currentDir = currentDir.slice(1);
|
|
9
|
+
}
|
|
10
|
+
// tsc-esm-fix also does not use decodeURI to remove encoded characters (such as %20 for spaces)
|
|
11
|
+
currentDir = decodeURI(currentDir);
|
|
12
|
+
export const packageRootPath = resolve(currentDir, '../../..');
|
|
13
|
+
export default packageRootPath;
|
|
14
14
|
//# sourceMappingURL=rootpath.js.map
|