acebase-server 1.6.1 → 1.9.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 +55 -37
- package/package.json +6 -4
- package/src/acebase-server.js +165 -167
- package/src/cluster.js +33 -34
- package/src/index.d.ts +25 -1
- package/src/routes/docs.js +90 -0
- package/src/start.js +14 -4
- package/src/ts/routes/auth-change-password.yaml +75 -0
- package/src/ts/routes/auth-delete.yaml +77 -0
- package/src/ts/routes/auth-forgot-password.yaml +49 -0
- package/src/ts/routes/auth-reset-password.yaml +53 -0
- package/src/ts/routes/auth-signin.yaml +129 -0
- package/src/ts/routes/auth-signout.yaml +45 -0
- package/src/ts/routes/auth-signup.yaml +120 -0
- package/src/ts/routes/auth-state.yaml +28 -0
- package/src/ts/routes/auth-update.yaml +131 -0
- package/src/ts/routes/auth-verify-email.yaml +52 -0
- package/src/ts/routes/docs.ts +93 -0
- package/src/webmanager/index.html +1 -1
- package/src/webmanager/index.js +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/auth/{dbname}/signup:
|
|
2
|
+
tags:
|
|
3
|
+
- auth
|
|
4
|
+
post:
|
|
5
|
+
description: Signs up a new user (must be enabled in the server config)
|
|
6
|
+
parameters:
|
|
7
|
+
- name: dbname
|
|
8
|
+
in: path
|
|
9
|
+
description: name of the database
|
|
10
|
+
required: true
|
|
11
|
+
schema:
|
|
12
|
+
type: string
|
|
13
|
+
example: mydb
|
|
14
|
+
requestBody:
|
|
15
|
+
description: new user details
|
|
16
|
+
content:
|
|
17
|
+
'application/json':
|
|
18
|
+
schema:
|
|
19
|
+
type: object
|
|
20
|
+
properties:
|
|
21
|
+
username:
|
|
22
|
+
type: string
|
|
23
|
+
description: Requested username (optional if `email` provided)
|
|
24
|
+
email:
|
|
25
|
+
type: string
|
|
26
|
+
description: Email address (optional if `username` provided)
|
|
27
|
+
displayName:
|
|
28
|
+
type: string
|
|
29
|
+
description: Name of the user for public displaying purposes. Consider this a real name, alias or handle
|
|
30
|
+
password:
|
|
31
|
+
type: string
|
|
32
|
+
format: password
|
|
33
|
+
description: Password to set for the account
|
|
34
|
+
settings:
|
|
35
|
+
type: object
|
|
36
|
+
otherProperties: true
|
|
37
|
+
desciption: (optional) miscellanious other info to store with the user account
|
|
38
|
+
required:
|
|
39
|
+
- username
|
|
40
|
+
- email
|
|
41
|
+
- displayName
|
|
42
|
+
- password
|
|
43
|
+
example:
|
|
44
|
+
email: user@example.com
|
|
45
|
+
displayName: Real Name
|
|
46
|
+
password: sup3rs3cr3t
|
|
47
|
+
responses:
|
|
48
|
+
200:
|
|
49
|
+
description: When signup succeeds, it returns an object with the result
|
|
50
|
+
content:
|
|
51
|
+
'application/json':
|
|
52
|
+
schema:
|
|
53
|
+
type: object
|
|
54
|
+
properties:
|
|
55
|
+
access_token:
|
|
56
|
+
description: The access token that provides access to API calls that require authentication. This access token should be added to the Authorization header of those requests. The token is allowed to be cached by the client to sign in witht the token method later
|
|
57
|
+
type: string
|
|
58
|
+
example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
|
|
59
|
+
user:
|
|
60
|
+
$ref: '#/components/schemas/User'
|
|
61
|
+
403:
|
|
62
|
+
description: If user signup is disabled in the server config, only the admin user can create new accounts and `"403 Forbidden"` is returned
|
|
63
|
+
content:
|
|
64
|
+
'application/json':
|
|
65
|
+
schema:
|
|
66
|
+
type: object
|
|
67
|
+
properties:
|
|
68
|
+
code:
|
|
69
|
+
type: string
|
|
70
|
+
value: admin_only
|
|
71
|
+
message:
|
|
72
|
+
type: string
|
|
73
|
+
value: Only admin is allowed to create users
|
|
74
|
+
example:
|
|
75
|
+
code: admin_only
|
|
76
|
+
message: Only admin is allowed to create users
|
|
77
|
+
409:
|
|
78
|
+
description: An account with the same username or email address exists already
|
|
79
|
+
content:
|
|
80
|
+
'application/json':
|
|
81
|
+
schema:
|
|
82
|
+
type: object
|
|
83
|
+
properties:
|
|
84
|
+
code:
|
|
85
|
+
type: string
|
|
86
|
+
value: conflict
|
|
87
|
+
message:
|
|
88
|
+
type: string
|
|
89
|
+
value: Account with username and/or email already exists
|
|
90
|
+
422:
|
|
91
|
+
description: When the sent request details are incorrect, `"422 Unprocessable Entity"` is returned
|
|
92
|
+
content:
|
|
93
|
+
'application/json':
|
|
94
|
+
schema:
|
|
95
|
+
type: object
|
|
96
|
+
properties:
|
|
97
|
+
code:
|
|
98
|
+
type: string
|
|
99
|
+
description: The exact error code
|
|
100
|
+
enum:
|
|
101
|
+
- missing_details
|
|
102
|
+
- invalid_email
|
|
103
|
+
- invalid_username
|
|
104
|
+
- invalid_display_name
|
|
105
|
+
- invalid_password
|
|
106
|
+
- invalid_settings
|
|
107
|
+
example: missing_details
|
|
108
|
+
message:
|
|
109
|
+
type: string
|
|
110
|
+
description: Description of the error
|
|
111
|
+
example: No username or email provided
|
|
112
|
+
example:
|
|
113
|
+
code: invalid_password
|
|
114
|
+
message: Invalid password, must be at least 8 characters and cannot contain spaces
|
|
115
|
+
500:
|
|
116
|
+
description: An unenexpected error occurred on the server
|
|
117
|
+
content:
|
|
118
|
+
'application/json':
|
|
119
|
+
schema:
|
|
120
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/auth/{dbname}/state:
|
|
2
|
+
tags:
|
|
3
|
+
- auth
|
|
4
|
+
get:
|
|
5
|
+
description: Gets current auth state
|
|
6
|
+
parameters:
|
|
7
|
+
- name: dbname
|
|
8
|
+
in: path
|
|
9
|
+
description: name of the database
|
|
10
|
+
required: true
|
|
11
|
+
schema:
|
|
12
|
+
type: string
|
|
13
|
+
example: mydb
|
|
14
|
+
responses:
|
|
15
|
+
200:
|
|
16
|
+
description: returns whether the request was authenticated and by which user (determined by the sent Authorization header)
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
signed_in:
|
|
23
|
+
type: boolean
|
|
24
|
+
example: true
|
|
25
|
+
user:
|
|
26
|
+
$ref: '#/components/schemas/User'
|
|
27
|
+
required:
|
|
28
|
+
- signed_in
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/auth/{dbname}/update:
|
|
2
|
+
tags:
|
|
3
|
+
- auth
|
|
4
|
+
post:
|
|
5
|
+
description: Updates user account details
|
|
6
|
+
parameters:
|
|
7
|
+
- name: dbname
|
|
8
|
+
in: path
|
|
9
|
+
description: name of the database
|
|
10
|
+
required: true
|
|
11
|
+
schema:
|
|
12
|
+
type: string
|
|
13
|
+
example: mydb
|
|
14
|
+
requestBody:
|
|
15
|
+
description: user details to update
|
|
16
|
+
content:
|
|
17
|
+
'application/json':
|
|
18
|
+
schema:
|
|
19
|
+
type: object
|
|
20
|
+
properties:
|
|
21
|
+
uid:
|
|
22
|
+
type: string
|
|
23
|
+
description: (admin user only) to change a user's account settings, the target account `uid` must be passed with the request
|
|
24
|
+
is_disabled:
|
|
25
|
+
type: boolean
|
|
26
|
+
description: (admin user only) whether the target account should be disabled to enable/disable signin
|
|
27
|
+
email:
|
|
28
|
+
type: string
|
|
29
|
+
description: New email address
|
|
30
|
+
username:
|
|
31
|
+
type: string
|
|
32
|
+
description: New username
|
|
33
|
+
display_name:
|
|
34
|
+
type: string
|
|
35
|
+
description: Name of the user for public displaying purposes. Consider this a real name, alias or handle. (NOTE this property is called `displayName` in the signup endpoint, both will be allowed to be used from acebase-server v1.8.1)
|
|
36
|
+
picture:
|
|
37
|
+
type: object
|
|
38
|
+
properties:
|
|
39
|
+
url:
|
|
40
|
+
type: string
|
|
41
|
+
width:
|
|
42
|
+
type: number
|
|
43
|
+
height:
|
|
44
|
+
type: number
|
|
45
|
+
example:
|
|
46
|
+
url: https://my.profile.pic/me.jpg
|
|
47
|
+
width: 500
|
|
48
|
+
height: 500
|
|
49
|
+
settings:
|
|
50
|
+
type: object
|
|
51
|
+
otherProperties: true
|
|
52
|
+
desciption: (optional) miscellanious other info to store with the user account
|
|
53
|
+
required:
|
|
54
|
+
- username
|
|
55
|
+
- email
|
|
56
|
+
- displayName
|
|
57
|
+
- password
|
|
58
|
+
responses:
|
|
59
|
+
200:
|
|
60
|
+
description: When update succeeds, it returns an object with the new user details
|
|
61
|
+
content:
|
|
62
|
+
'application/json':
|
|
63
|
+
schema:
|
|
64
|
+
type: object
|
|
65
|
+
properties:
|
|
66
|
+
user:
|
|
67
|
+
$ref: '#/components/schemas/User'
|
|
68
|
+
401:
|
|
69
|
+
description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
|
|
70
|
+
content:
|
|
71
|
+
'application/json':
|
|
72
|
+
schema:
|
|
73
|
+
type: object
|
|
74
|
+
properties:
|
|
75
|
+
code:
|
|
76
|
+
type: string
|
|
77
|
+
value: unauthenticated_update
|
|
78
|
+
message:
|
|
79
|
+
type: string
|
|
80
|
+
value: Sign in to change details
|
|
81
|
+
example:
|
|
82
|
+
code: unauthenticated_update
|
|
83
|
+
message: Sign in to change details
|
|
84
|
+
403:
|
|
85
|
+
description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
|
|
86
|
+
content:
|
|
87
|
+
'application/json':
|
|
88
|
+
schema:
|
|
89
|
+
type: object
|
|
90
|
+
properties:
|
|
91
|
+
code:
|
|
92
|
+
type: string
|
|
93
|
+
value: unauthorized_update
|
|
94
|
+
message:
|
|
95
|
+
type: string
|
|
96
|
+
value: You are not authorized to perform this update. This attempt has been logged.
|
|
97
|
+
example:
|
|
98
|
+
code: unauthorized_update
|
|
99
|
+
message: You are not authorized to perform this update. This attempt has been logged.
|
|
100
|
+
422:
|
|
101
|
+
description: When the sent request details are incorrect, this "422 Unprocessable Entity" is returned
|
|
102
|
+
content:
|
|
103
|
+
'application/json':
|
|
104
|
+
schema:
|
|
105
|
+
type: object
|
|
106
|
+
properties:
|
|
107
|
+
code:
|
|
108
|
+
type: string
|
|
109
|
+
description: The exact error code
|
|
110
|
+
enum:
|
|
111
|
+
- invalid_email
|
|
112
|
+
- email_conflict
|
|
113
|
+
- invalid_username
|
|
114
|
+
- username_conflict
|
|
115
|
+
- invalid_display_name
|
|
116
|
+
- invalid_picture
|
|
117
|
+
- invalid_settings
|
|
118
|
+
example: missing_details
|
|
119
|
+
message:
|
|
120
|
+
type: string
|
|
121
|
+
description: Description of the error
|
|
122
|
+
example: Account with email address exists already
|
|
123
|
+
example:
|
|
124
|
+
code: username_conflict
|
|
125
|
+
message: Account with username exists already
|
|
126
|
+
500:
|
|
127
|
+
description: An unenexpected error occurred on the server
|
|
128
|
+
content:
|
|
129
|
+
'application/json':
|
|
130
|
+
schema:
|
|
131
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/auth/{dbname}/verify_email:
|
|
2
|
+
tags:
|
|
3
|
+
- auth
|
|
4
|
+
post:
|
|
5
|
+
description: Verifies an email address with a code sent through their email address
|
|
6
|
+
parameters:
|
|
7
|
+
- name: dbname
|
|
8
|
+
in: path
|
|
9
|
+
description: name of the database
|
|
10
|
+
required: true
|
|
11
|
+
schema:
|
|
12
|
+
type: string
|
|
13
|
+
example: mydb
|
|
14
|
+
requestBody:
|
|
15
|
+
description: verification object
|
|
16
|
+
content:
|
|
17
|
+
'application/json':
|
|
18
|
+
schema:
|
|
19
|
+
type: object
|
|
20
|
+
properties:
|
|
21
|
+
code:
|
|
22
|
+
type: string
|
|
23
|
+
description: Verification code that was sent to the user's email address
|
|
24
|
+
required:
|
|
25
|
+
- code
|
|
26
|
+
example:
|
|
27
|
+
code: ewrg235235g23gwrvsdb34g524rvqewwrv425gervqew...
|
|
28
|
+
responses:
|
|
29
|
+
200:
|
|
30
|
+
description: If the email address is successfully verified, returns the string `"OK"`
|
|
31
|
+
content:
|
|
32
|
+
'text/plain':
|
|
33
|
+
schema:
|
|
34
|
+
type: 'string'
|
|
35
|
+
value: OK
|
|
36
|
+
example: OK
|
|
37
|
+
description: The string `"OK"`
|
|
38
|
+
401:
|
|
39
|
+
description: Returns a `"401 Bad Request"` if the code sent with the request is invalid
|
|
40
|
+
content:
|
|
41
|
+
'application/json':
|
|
42
|
+
schema:
|
|
43
|
+
$ref: '#/components/schemas/Error'
|
|
44
|
+
example:
|
|
45
|
+
code: invalid_code
|
|
46
|
+
message: Invalid token
|
|
47
|
+
500:
|
|
48
|
+
description: An unexpected error occurred
|
|
49
|
+
content:
|
|
50
|
+
'application/json':
|
|
51
|
+
schema:
|
|
52
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import path = require('path');
|
|
3
|
+
import * as swaggerJsdoc from 'swagger-jsdoc';
|
|
4
|
+
import * as swaggerUi from 'swagger-ui-express';
|
|
5
|
+
// import config from '../config';
|
|
6
|
+
|
|
7
|
+
const addRoute = (app: Express) => {
|
|
8
|
+
// Generate docs from all yaml files
|
|
9
|
+
const options:swaggerJsdoc.Options = {
|
|
10
|
+
definition: {
|
|
11
|
+
openapi: '3.0.0',
|
|
12
|
+
info: {
|
|
13
|
+
title: 'AceBase Server API',
|
|
14
|
+
description: 'AceBase Server API',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
contact: {
|
|
17
|
+
name: 'Ewout Stortenbeker',
|
|
18
|
+
email: 'me@appy.one'
|
|
19
|
+
},
|
|
20
|
+
// servers: [`http://${config.server.host}:${config.server.port}`]
|
|
21
|
+
},
|
|
22
|
+
components: {
|
|
23
|
+
securitySchemes: {
|
|
24
|
+
bearerAuth: {
|
|
25
|
+
type: 'http',
|
|
26
|
+
scheme: 'bearer',
|
|
27
|
+
bearerFormat: 'token' // switch to JWT in the future?
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
schemas: {
|
|
31
|
+
User: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
uid: { type: 'string', example: 'jpx0k53u0002ecr7s354c51l' },
|
|
35
|
+
username: { type: 'string', example: 'someuser' },
|
|
36
|
+
email: { type: 'string', example: 'email@domain.com' },
|
|
37
|
+
displayName: { type: 'string', example: 'Some User' },
|
|
38
|
+
picture: {
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
41
|
+
width: { type: 'number', example: 500 },
|
|
42
|
+
height: { type: 'number', example: 500 },
|
|
43
|
+
url: { type: 'string', example: 'https://profile.pic/user.jpg' }
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
emailVerified: { type: 'boolean', example: true },
|
|
47
|
+
created: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
|
|
48
|
+
prevSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
|
|
49
|
+
prevSigninIp: { type: 'string', example: '127.0.0.1' },
|
|
50
|
+
lastSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
|
|
51
|
+
lastSigninIp: { type: 'string', example: '127.0.0.1' },
|
|
52
|
+
changePassword: { type: 'boolean', example: false },
|
|
53
|
+
changePasswordRequested: { type: 'boolean', example: false },
|
|
54
|
+
changePasswordBefore: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
|
|
55
|
+
settings: { type: 'object' }
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
Error: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
code: { type: 'string', description: 'error code', example: 'invalid_request' },
|
|
62
|
+
message: { type: 'string', description: 'The error message', example: 'Invalid request for this endpoint' }
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
UnexpectedError: {
|
|
66
|
+
type: 'object',
|
|
67
|
+
properties: {
|
|
68
|
+
code: { type: 'string', value: 'unexpected', description: 'The string `"unexpected"`' },
|
|
69
|
+
message: { type: 'string', description: 'The server error message' }
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
UnknownError: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
code: { type: 'string', value: 'unknown', description: 'The string `"unknown"`' },
|
|
76
|
+
message: { type: 'string', description: 'The server error message' }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
security: [
|
|
82
|
+
// Enable bearer auth globally
|
|
83
|
+
{ bearerAuth: [] }
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
apis: [path.resolve(__dirname, '../ts/routes/*.yaml')]
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const swaggerDocs = swaggerJsdoc(options);
|
|
90
|
+
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default addRoute;
|
|
@@ -263,7 +263,7 @@ M.AutoInit();
|
|
|
263
263
|
</script>
|
|
264
264
|
|
|
265
265
|
<!-- AceBase client js -->
|
|
266
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/acebase-client@1.
|
|
266
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/acebase-client@1.11.0/dist/browser.min.js"></script>
|
|
267
267
|
<!-- <script type="text/javascript" src="acebase-client-browser.min.js"></script> -->
|
|
268
268
|
|
|
269
269
|
<!-- AceBase Webmanager js -->
|
package/src/webmanager/index.js
CHANGED
|
@@ -276,7 +276,7 @@ function updateBrowsePath(path = '') {
|
|
|
276
276
|
return showError('node does not exist');
|
|
277
277
|
}
|
|
278
278
|
else if (info.children.list.length === 0) {
|
|
279
|
-
|
|
279
|
+
showError('node has no children');
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
if (skip === 0 && !info.children.more) {
|