acebase-server 1.18.2 → 1.19.1

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.
Files changed (93) hide show
  1. package/.eslintrc.json +49 -49
  2. package/.github/workflows/publish.yml +125 -0
  3. package/Dockerfile +26 -26
  4. package/LICENSE +21 -21
  5. package/bin/acebase-server.js +8 -8
  6. package/create-package-files.sh +25 -0
  7. package/dist/cjs/middleware/admin-only.js +2 -1
  8. package/dist/cjs/middleware/user.js +1 -0
  9. package/dist/cjs/routes/auth-delete.js +3 -2
  10. package/dist/cjs/routes/auth-signup.js +11 -11
  11. package/dist/cjs/routes/auth-update.js +2 -1
  12. package/dist/cjs/routes/auth.js +0 -3
  13. package/dist/cjs/routes/data-exists.js +2 -2
  14. package/dist/cjs/routes/data-export.js +2 -2
  15. package/dist/cjs/routes/data-get.js +2 -2
  16. package/dist/cjs/routes/data-reflect.js +4 -4
  17. package/dist/cjs/routes/data-set.js +4 -3
  18. package/dist/cjs/routes/data-transaction.js +4 -3
  19. package/dist/cjs/routes/data-update.js +4 -3
  20. package/dist/cjs/routes/docs.js +1 -1
  21. package/dist/cjs/routes/meta-info.js +3 -2
  22. package/dist/cjs/rules.js +2 -1
  23. package/dist/cjs/schema/user.js +2 -1
  24. package/dist/cjs/server.js +12 -3
  25. package/dist/cjs/settings/index.js +6 -0
  26. package/dist/cjs/shared/admin.js +8 -0
  27. package/dist/cjs/websocket/index.js +2 -1
  28. package/dist/esm/middleware/admin-only.js +2 -1
  29. package/dist/esm/middleware/user.js +1 -0
  30. package/dist/esm/routes/auth-delete.js +3 -2
  31. package/dist/esm/routes/auth-signup.js +4 -4
  32. package/dist/esm/routes/auth-update.js +2 -1
  33. package/dist/esm/routes/auth.js +0 -3
  34. package/dist/esm/routes/data-exists.js +1 -2
  35. package/dist/esm/routes/data-export.js +1 -2
  36. package/dist/esm/routes/data-get.js +1 -1
  37. package/dist/esm/routes/data-reflect.js +3 -3
  38. package/dist/esm/routes/data-set.js +2 -1
  39. package/dist/esm/routes/data-transaction.js +2 -1
  40. package/dist/esm/routes/data-update.js +2 -1
  41. package/dist/esm/routes/docs.js +1 -1
  42. package/dist/esm/routes/meta-info.js +3 -2
  43. package/dist/esm/rules.js +2 -1
  44. package/dist/esm/schema/user.js +1 -0
  45. package/dist/esm/server.js +12 -3
  46. package/dist/esm/settings/index.js +6 -0
  47. package/dist/esm/shared/admin.js +4 -0
  48. package/dist/esm/websocket/index.js +1 -1
  49. package/dist/types/middleware/user.d.ts +1 -0
  50. package/dist/types/routes/auth-update.d.ts +2 -0
  51. package/dist/types/rules.d.ts +1 -1
  52. package/dist/types/schema/user.d.ts +4 -0
  53. package/dist/types/settings/index.d.ts +14 -2
  54. package/dist/types/shared/admin.d.ts +3 -0
  55. package/package.json +4 -5
  56. package/release_notes.md +4 -0
  57. package/src/routes/auth-change-password.yaml +73 -73
  58. package/src/routes/auth-delete.yaml +77 -77
  59. package/src/routes/auth-forgot-password.yaml +49 -49
  60. package/src/routes/auth-reset-password.yaml +53 -53
  61. package/src/routes/auth-signin.yaml +129 -129
  62. package/src/routes/auth-signout.yaml +46 -46
  63. package/src/routes/auth-signup.yaml +135 -135
  64. package/src/routes/auth-state.yaml +28 -28
  65. package/src/routes/auth-update.yaml +151 -151
  66. package/src/routes/auth-verify-email.yaml +52 -52
  67. package/src/routes/data-exists.yaml +44 -44
  68. package/src/routes/data-export.yaml +63 -63
  69. package/src/routes/data-import.yaml +74 -74
  70. package/src/routes/data-index-create.yaml +105 -105
  71. package/src/routes/data-index-delete.yaml +51 -51
  72. package/src/routes/data-index-list.yaml +84 -84
  73. package/src/routes/data-query.yaml +165 -165
  74. package/src/routes/data-reflect.yaml +124 -124
  75. package/src/routes/data-schema-get.yaml +53 -53
  76. package/src/routes/data-schema-set.yaml +64 -64
  77. package/src/routes/data-schema-test.yaml +66 -66
  78. package/src/routes/data-schemas-list.yaml +41 -41
  79. package/src/routes/data-set.yaml +77 -77
  80. package/src/routes/data-sync-changes.yaml +66 -66
  81. package/src/routes/data-sync-mutations.yaml +66 -66
  82. package/src/routes/data-transaction-finish.yaml +82 -82
  83. package/src/routes/data-transaction-start.yaml +58 -58
  84. package/src/routes/data-update.yaml +77 -77
  85. package/src/routes/meta-info.yaml +40 -40
  86. package/src/routes/meta-ping.yaml +22 -22
  87. package/src/routes/meta-stats.yaml +40 -40
  88. package/src/routes/oauth2-init.yaml +62 -62
  89. package/src/routes/oauth2-refresh.yaml +64 -64
  90. package/src/routes/oauth2-signin.yaml +65 -65
  91. package/webmanager/acebase-client-browser.min.js +12 -12
  92. package/webmanager/index.html +271 -271
  93. package/webmanager/index.js +437 -437
@@ -167,7 +167,17 @@ export type AceBaseServerSettings = Partial<{
167
167
  */
168
168
  logColors: boolean;
169
169
  /**
170
- * Init callback that runs before the server adds 404 middleware and starts listening to incoming calls.
170
+ * Callback that runs before the server adds middleware and routes.
171
+ * Use this callback to add custom middleware for logging purposes, header processing etc before the server's own.
172
+ */
173
+ preMiddleware?: (server: AceBaseServer) => Promise<void>;
174
+ /**
175
+ * Callback that runs after the server has added its middleware, before any routes are added.
176
+ * Use this callback to add custom middleware for logging purposes, header processing etc before the server's own.
177
+ */
178
+ postMiddleware?: (server: AceBaseServer) => Promise<void>;
179
+ /**
180
+ * Init callback that runs after all middleware (except 404 handler) has been added, before the server starts listening to incoming calls.
171
181
  * Use this callback to extend the server with custom routes, add data validation rules, wait for external events, etc.
172
182
  * @param server Instance of the `AceBaseServer`
173
183
  */
@@ -190,7 +200,9 @@ export declare class AceBaseServerConfig {
190
200
  readonly storage?: AceBaseStorageSettings;
191
201
  readonly sponsor: boolean;
192
202
  readonly logColors: boolean;
193
- readonly init?: (server: AceBaseServer) => Promise<void>;
203
+ readonly preMiddleware?: AceBaseServerSettings['preMiddleware'];
204
+ readonly postMiddleware?: AceBaseServerSettings['postMiddleware'];
205
+ readonly init?: AceBaseServerSettings['init'];
194
206
  constructor(settings: AceBaseServerSettings);
195
207
  }
196
208
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { DbUserAccountDetails } from '../schema/user.js';
2
+ export declare function isAdmin(user?: Pick<DbUserAccountDetails, 'uid' | 'roles'>): boolean;
3
+ //# sourceMappingURL=admin.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acebase-server",
3
- "version": "1.18.2",
3
+ "version": "1.19.1",
4
4
  "description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -22,13 +22,12 @@
22
22
  "test": "set NODE_ENV=development && npm run start",
23
23
  "lint": "eslint .",
24
24
  "lint:fix": "eslint . --fix",
25
- "build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:packages && echo Done!",
25
+ "build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:packages && npm run build:vars && echo Done!",
26
26
  "build:clean": "rm -fr dist/*",
27
27
  "build:esm": "tsc -p tsconfig.json && npx tsc-esm-fix ---target='dist/esm'",
28
28
  "build:cjs": "tsc -p tsconfig-cjs.json",
29
- "build:packages": "bash ./create-package-files",
30
- "preversion": "npm run build",
31
- "version": "node ./build-vars.js"
29
+ "build:packages": "bash ./create-package-files.sh",
30
+ "build:vars": "node ./build-vars.js"
32
31
  },
33
32
  "keywords": [
34
33
  "database",
@@ -0,0 +1,4 @@
1
+ - Add github publish workflow to npm (5a97437)
2
+ - rename script file (651ec0f)
3
+ - Fix tsc errors (7d88d1b)
4
+ - Fix "TypeError: Converting circular structure to JSON" in error response if `err` is an object with circular structure (9b3bdf5)
@@ -1,74 +1,74 @@
1
- /auth/{dbname}/change_password:
2
- post:
3
- tags:
4
- - auth
5
- summary: Change a user's password
6
- description: Changes a user account's password by providing the current and new passwords
7
- parameters:
8
- - name: dbname
9
- in: path
10
- description: name of the database
11
- required: true
12
- schema:
13
- type: string
14
- example: mydb
15
- requestBody:
16
- description: request object
17
- content:
18
- 'application/json':
19
- schema:
20
- type: object
21
- properties:
22
- uid:
23
- type: string
24
- description: Account's uid
25
- password:
26
- type: string
27
- description: Current password set on the account
28
- new_password:
29
- type: string
30
- description: New password to set on the account
31
- required:
32
- - uid
33
- - password
34
- - new_password
35
- responses:
36
- 200:
37
- description: If the password change is successful, returns an object with a new access token
38
- content:
39
- 'application/json':
40
- schema:
41
- type: object
42
- properties:
43
- access_token:
44
- description: New access token that provides access to API calls that require authentication.
45
- type: string
46
- example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
47
- 400:
48
- description: Returns a `"400 Bad Request"` if the sent request is invalid. If the request is missing details, response is the string `"Bad Request"`. Otherwise, it's an object with `code` and `message` properties. Possible codes are `"unknown_uid"`, `"wrong_password"`, `"wrong_access_token"` (if not signed in as the user the password change was requested for)
49
- content:
50
- 'text/plain':
51
- schema:
52
- type: string
53
- value: Bad Request
54
- example: Bad Request
55
- 'application/json':
56
- schema:
57
- $ref: '#/components/schemas/Error'
58
- example:
59
- code: wrong_access_token
60
- message: "Cannot change password while signed in as other user, or with an old token"
61
- 422:
62
- description: New password does not meet the criteria
63
- content:
64
- 'text/plain':
65
- schema:
66
- type: string
67
- value: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
68
- example: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
69
- 500:
70
- description: An unexpected error occurred
71
- content:
72
- 'application/json':
73
- schema:
1
+ /auth/{dbname}/change_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Change a user's password
6
+ description: Changes a user account's password by providing the current and new passwords
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: request object
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ uid:
23
+ type: string
24
+ description: Account's uid
25
+ password:
26
+ type: string
27
+ description: Current password set on the account
28
+ new_password:
29
+ type: string
30
+ description: New password to set on the account
31
+ required:
32
+ - uid
33
+ - password
34
+ - new_password
35
+ responses:
36
+ 200:
37
+ description: If the password change is successful, returns an object with a new access token
38
+ content:
39
+ 'application/json':
40
+ schema:
41
+ type: object
42
+ properties:
43
+ access_token:
44
+ description: New access token that provides access to API calls that require authentication.
45
+ type: string
46
+ example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
47
+ 400:
48
+ description: Returns a `"400 Bad Request"` if the sent request is invalid. If the request is missing details, response is the string `"Bad Request"`. Otherwise, it's an object with `code` and `message` properties. Possible codes are `"unknown_uid"`, `"wrong_password"`, `"wrong_access_token"` (if not signed in as the user the password change was requested for)
49
+ content:
50
+ 'text/plain':
51
+ schema:
52
+ type: string
53
+ value: Bad Request
54
+ example: Bad Request
55
+ 'application/json':
56
+ schema:
57
+ $ref: '#/components/schemas/Error'
58
+ example:
59
+ code: wrong_access_token
60
+ message: "Cannot change password while signed in as other user, or with an old token"
61
+ 422:
62
+ description: New password does not meet the criteria
63
+ content:
64
+ 'text/plain':
65
+ schema:
66
+ type: string
67
+ value: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
68
+ example: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
69
+ 500:
70
+ description: An unexpected error occurred
71
+ content:
72
+ 'application/json':
73
+ schema:
74
74
  $ref: '#/components/schemas/UnexpectedError'
@@ -1,78 +1,78 @@
1
- /auth/{dbname}/delete:
2
- post:
3
- tags:
4
- - auth
5
- summary: Delete a user account
6
- description: Deletes an existing user account
7
- parameters:
8
- - name: dbname
9
- in: path
10
- description: name of the database
11
- required: true
12
- schema:
13
- type: string
14
- example: mydb
15
- requestBody:
16
- description: Account to delete
17
- content:
18
- 'text/plain':
19
- schema:
20
- type: string
21
- value: ''
22
- example: ''
23
- description: Empty content to delete signed in user account
24
- 'application/json':
25
- schema:
26
- type: object
27
- properties:
28
- uid:
29
- type: string
30
- description: (admin user only) to delete a specific user account, the target account `uid` must be passed with the request
31
- example: jpx0k53u0002ecr7s354c51l
32
- responses:
33
- 200:
34
- description: When delete succeeds, it returns the string `"Farewell"`
35
- content:
36
- 'text/plain':
37
- schema:
38
- type: text
39
- value: Farewell
40
- example: Farewell
41
- 401:
42
- description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
43
- content:
44
- 'application/json':
45
- schema:
46
- type: object
47
- properties:
48
- code:
49
- type: string
50
- value: unauthenticated_delete
51
- message:
52
- type: string
53
- value: You are not authorized to perform this operation, your attempt has been logged
54
- example:
55
- code: unauthenticated_delete
56
- message: You are not authorized to perform this operation, your attempt has been logged
57
- 403:
58
- description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
59
- content:
60
- 'application/json':
61
- schema:
62
- type: object
63
- properties:
64
- code:
65
- type: string
66
- value: unauthorized_delete
67
- message:
68
- type: string
69
- value: You are not authorized to perform this operation. This attempt has been logged.
70
- example:
71
- code: unauthorized_delete
72
- message: You are not authorized to perform this operation. This attempt has been logged.
73
- 500:
74
- description: An unenexpected error occurred on the server
75
- content:
76
- 'application/json':
77
- schema:
1
+ /auth/{dbname}/delete:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Delete a user account
6
+ description: Deletes an existing user account
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: Account to delete
17
+ content:
18
+ 'text/plain':
19
+ schema:
20
+ type: string
21
+ value: ''
22
+ example: ''
23
+ description: Empty content to delete signed in user account
24
+ 'application/json':
25
+ schema:
26
+ type: object
27
+ properties:
28
+ uid:
29
+ type: string
30
+ description: (admin user only) to delete a specific user account, the target account `uid` must be passed with the request
31
+ example: jpx0k53u0002ecr7s354c51l
32
+ responses:
33
+ 200:
34
+ description: When delete succeeds, it returns the string `"Farewell"`
35
+ content:
36
+ 'text/plain':
37
+ schema:
38
+ type: text
39
+ value: Farewell
40
+ example: Farewell
41
+ 401:
42
+ description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
43
+ content:
44
+ 'application/json':
45
+ schema:
46
+ type: object
47
+ properties:
48
+ code:
49
+ type: string
50
+ value: unauthenticated_delete
51
+ message:
52
+ type: string
53
+ value: You are not authorized to perform this operation, your attempt has been logged
54
+ example:
55
+ code: unauthenticated_delete
56
+ message: You are not authorized to perform this operation, your attempt has been logged
57
+ 403:
58
+ description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
59
+ content:
60
+ 'application/json':
61
+ schema:
62
+ type: object
63
+ properties:
64
+ code:
65
+ type: string
66
+ value: unauthorized_delete
67
+ message:
68
+ type: string
69
+ value: You are not authorized to perform this operation. This attempt has been logged.
70
+ example:
71
+ code: unauthorized_delete
72
+ message: You are not authorized to perform this operation. This attempt has been logged.
73
+ 500:
74
+ description: An unenexpected error occurred on the server
75
+ content:
76
+ 'application/json':
77
+ schema:
78
78
  $ref: '#/components/schemas/UnexpectedError'
@@ -1,50 +1,50 @@
1
- /auth/{dbname}/forgot_password:
2
- post:
3
- tags:
4
- - auth
5
- summary: Issue a password reset
6
- description: Issues a password reset for a user that forgot their password. User must have an email address in the database.
7
- parameters:
8
- - name: dbname
9
- in: path
10
- description: name of the database
11
- required: true
12
- schema:
13
- type: string
14
- example: mydb
15
- requestBody:
16
- description: user details
17
- content:
18
- 'application/json':
19
- schema:
20
- type: object
21
- properties:
22
- email:
23
- type: string
24
- description: User's email address. A password reset email will be sent to this address
25
- required:
26
- - email
27
- responses:
28
- 200:
29
- description: If a password reset email has been successfully sent, returns the string `"OK"`
30
- content:
31
- 'text/plain':
32
- schema:
33
- type: 'string'
34
- value: OK
35
- description: The string `"OK"`
36
- 400:
37
- description: Returns a `"400 Bad Request"` if the server has not been configured properly, or if no or invalid email address was sent with the request
38
- content:
39
- 'application/json':
40
- schema:
41
- $ref: '#/components/schemas/Error'
42
- example:
43
- code: invalid_email
44
- message: Email address not found, or duplicate entries found
45
- 500:
46
- description: An unexpected error occurred
47
- content:
48
- 'application/json':
49
- schema:
1
+ /auth/{dbname}/forgot_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Issue a password reset
6
+ description: Issues a password reset for a user that forgot their password. User must have an email address in the database.
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: user details
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ email:
23
+ type: string
24
+ description: User's email address. A password reset email will be sent to this address
25
+ required:
26
+ - email
27
+ responses:
28
+ 200:
29
+ description: If a password reset email has been successfully sent, returns the string `"OK"`
30
+ content:
31
+ 'text/plain':
32
+ schema:
33
+ type: 'string'
34
+ value: OK
35
+ description: The string `"OK"`
36
+ 400:
37
+ description: Returns a `"400 Bad Request"` if the server has not been configured properly, or if no or invalid email address was sent with the request
38
+ content:
39
+ 'application/json':
40
+ schema:
41
+ $ref: '#/components/schemas/Error'
42
+ example:
43
+ code: invalid_email
44
+ message: Email address not found, or duplicate entries found
45
+ 500:
46
+ description: An unexpected error occurred
47
+ content:
48
+ 'application/json':
49
+ schema:
50
50
  $ref: '#/components/schemas/UnexpectedError'
@@ -1,54 +1,54 @@
1
- /auth/{dbname}/reset_password:
2
- post:
3
- tags:
4
- - auth
5
- summary: Completes a password reset
6
- description: Completes a password reset request for a user account with a code sent to the email address by the `forgot_password` endpoint
7
- parameters:
8
- - name: dbname
9
- in: path
10
- description: name of the database
11
- required: true
12
- schema:
13
- type: string
14
- example: mydb
15
- requestBody:
16
- description: verification object
17
- content:
18
- 'application/json':
19
- schema:
20
- type: object
21
- properties:
22
- code:
23
- type: string
24
- description: Password reset code that was sent to the user's email address
25
- password:
26
- type: string
27
- description: New password to set on the account
28
- required:
29
- - code
30
- - password
31
- responses:
32
- 200:
33
- description: If the password reset is successful, returns the string `"OK"`
34
- content:
35
- 'text/plain':
36
- schema:
37
- type: 'string'
38
- value: OK
39
- description: The string `"OK"`
40
- 400:
41
- description: Returns a `"401 Bad Request"` if the code sent with the request is invalid, or the new password doesn't meet the requirements
42
- content:
43
- 'application/json':
44
- schema:
45
- $ref: '#/components/schemas/Error'
46
- example:
47
- code: invalid_code
48
- message: Invalid token
49
- 500:
50
- description: An unexpected error occurred
51
- content:
52
- 'application/json':
53
- schema:
1
+ /auth/{dbname}/reset_password:
2
+ post:
3
+ tags:
4
+ - auth
5
+ summary: Completes a password reset
6
+ description: Completes a password reset request for a user account with a code sent to the email address by the `forgot_password` endpoint
7
+ parameters:
8
+ - name: dbname
9
+ in: path
10
+ description: name of the database
11
+ required: true
12
+ schema:
13
+ type: string
14
+ example: mydb
15
+ requestBody:
16
+ description: verification object
17
+ content:
18
+ 'application/json':
19
+ schema:
20
+ type: object
21
+ properties:
22
+ code:
23
+ type: string
24
+ description: Password reset code that was sent to the user's email address
25
+ password:
26
+ type: string
27
+ description: New password to set on the account
28
+ required:
29
+ - code
30
+ - password
31
+ responses:
32
+ 200:
33
+ description: If the password reset is successful, returns the string `"OK"`
34
+ content:
35
+ 'text/plain':
36
+ schema:
37
+ type: 'string'
38
+ value: OK
39
+ description: The string `"OK"`
40
+ 400:
41
+ description: Returns a `"401 Bad Request"` if the code sent with the request is invalid, or the new password doesn't meet the requirements
42
+ content:
43
+ 'application/json':
44
+ schema:
45
+ $ref: '#/components/schemas/Error'
46
+ example:
47
+ code: invalid_code
48
+ message: Invalid token
49
+ 500:
50
+ description: An unexpected error occurred
51
+ content:
52
+ 'application/json':
53
+ schema:
54
54
  $ref: '#/components/schemas/UnexpectedError'