acebase-server 1.16.2 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/README.md +180 -10
  2. package/bin/acebase-server.js +8 -0
  3. package/build-vars.js +2 -1
  4. package/dist/cjs/auth.js +88 -88
  5. package/dist/cjs/cluster.js +6 -56
  6. package/dist/cjs/index.d.ts +1 -1
  7. package/dist/cjs/index.js +24 -24
  8. package/dist/cjs/logger.js +73 -73
  9. package/dist/cjs/middleware/404.js +14 -14
  10. package/dist/cjs/middleware/admin-only.js +28 -28
  11. package/dist/cjs/middleware/cache.js +14 -14
  12. package/dist/cjs/middleware/connection.js +49 -49
  13. package/dist/cjs/middleware/context.js +20 -20
  14. package/dist/cjs/middleware/cors.js +50 -50
  15. package/dist/cjs/middleware/swagger.js +17 -17
  16. package/dist/cjs/middleware/user.js +57 -57
  17. package/dist/cjs/oauth-providers/dropbox.js +109 -109
  18. package/dist/cjs/oauth-providers/facebook.js +85 -85
  19. package/dist/cjs/oauth-providers/google.js +119 -119
  20. package/dist/cjs/oauth-providers/index.js +26 -26
  21. package/dist/cjs/oauth-providers/instagram.js +80 -80
  22. package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
  23. package/dist/cjs/oauth-providers/spotify.js +113 -113
  24. package/dist/cjs/routes/auth-change-password.js +87 -87
  25. package/dist/cjs/routes/auth-delete.js +52 -52
  26. package/dist/cjs/routes/auth-forgot-password.js +77 -77
  27. package/dist/cjs/routes/auth-reset-password.js +97 -97
  28. package/dist/cjs/routes/auth-signin.js +46 -46
  29. package/dist/cjs/routes/auth-signout.js +61 -61
  30. package/dist/cjs/routes/auth-signup.js +142 -142
  31. package/dist/cjs/routes/auth-state.js +25 -25
  32. package/dist/cjs/routes/auth-update.js +131 -131
  33. package/dist/cjs/routes/auth-verify-email.js +71 -71
  34. package/dist/cjs/routes/auth.js +57 -54
  35. package/dist/cjs/routes/data-exists.js +33 -33
  36. package/dist/cjs/routes/data-export.js +48 -48
  37. package/dist/cjs/routes/data-get.js +70 -66
  38. package/dist/cjs/routes/data-import.js +54 -54
  39. package/dist/cjs/routes/data-index-create.js +42 -42
  40. package/dist/cjs/routes/data-index-delete.js +33 -33
  41. package/dist/cjs/routes/data-index-list.js +31 -31
  42. package/dist/cjs/routes/data-query.js +80 -70
  43. package/dist/cjs/routes/data-reflect.js +97 -86
  44. package/dist/cjs/routes/data-schema-get.js +36 -36
  45. package/dist/cjs/routes/data-schema-set.js +30 -30
  46. package/dist/cjs/routes/data-schema-test.js +43 -43
  47. package/dist/cjs/routes/data-schemas-list.js +32 -32
  48. package/dist/cjs/routes/data-set.js +85 -75
  49. package/dist/cjs/routes/data-sync-changes.js +81 -67
  50. package/dist/cjs/routes/data-sync-mutations.js +81 -67
  51. package/dist/cjs/routes/data-transaction.js +159 -139
  52. package/dist/cjs/routes/data-update.js +86 -75
  53. package/dist/cjs/routes/data.js +62 -62
  54. package/dist/cjs/routes/docs.js +258 -251
  55. package/dist/cjs/routes/meta-info.js +63 -63
  56. package/dist/cjs/routes/meta-logs.js +49 -49
  57. package/dist/cjs/routes/meta-ping.js +11 -11
  58. package/dist/cjs/routes/meta-stats.js +27 -27
  59. package/dist/cjs/routes/meta.js +19 -19
  60. package/dist/cjs/routes/oauth2-init.js +54 -54
  61. package/dist/cjs/routes/oauth2-refresh.js +42 -42
  62. package/dist/cjs/routes/oauth2-signin.js +265 -265
  63. package/dist/cjs/routes/webmanager.js +26 -26
  64. package/dist/cjs/rules.js +380 -167
  65. package/dist/cjs/sandbox.js +28 -0
  66. package/dist/cjs/schema/user.js +24 -24
  67. package/dist/cjs/server.js +410 -407
  68. package/dist/cjs/settings/email.js +2 -2
  69. package/dist/cjs/settings/index.js +175 -172
  70. package/dist/cjs/shared/clients.js +26 -26
  71. package/dist/cjs/shared/email.js +2 -2
  72. package/dist/cjs/shared/env.js +2 -2
  73. package/dist/cjs/shared/error.js +33 -33
  74. package/dist/cjs/shared/http.js +28 -28
  75. package/dist/cjs/shared/password.js +45 -45
  76. package/dist/cjs/shared/rootpath.js +16 -16
  77. package/dist/cjs/shared/signin.js +143 -143
  78. package/dist/cjs/shared/simple-fetch.js +76 -76
  79. package/dist/cjs/shared/tokens.js +79 -79
  80. package/dist/cjs/shared/validate.js +61 -61
  81. package/dist/cjs/start.js +119 -53
  82. package/dist/cjs/test.js +10 -10
  83. package/dist/cjs/websocket/index.js +331 -319
  84. package/dist/cjs/websocket/manager.js +15 -15
  85. package/dist/cjs/websocket/socket.io.js +76 -76
  86. package/dist/esm/auth.js +75 -75
  87. package/dist/esm/cluster.js +6 -54
  88. package/dist/esm/index.d.ts +1 -1
  89. package/dist/esm/index.js +4 -4
  90. package/dist/esm/logger.js +51 -51
  91. package/dist/esm/middleware/404.js +10 -10
  92. package/dist/esm/middleware/admin-only.js +24 -24
  93. package/dist/esm/middleware/cache.js +10 -10
  94. package/dist/esm/middleware/connection.js +45 -45
  95. package/dist/esm/middleware/context.js +16 -16
  96. package/dist/esm/middleware/cors.js +44 -44
  97. package/dist/esm/middleware/swagger.js +13 -13
  98. package/dist/esm/middleware/user.js +44 -44
  99. package/dist/esm/oauth-providers/dropbox.js +90 -90
  100. package/dist/esm/oauth-providers/facebook.js +66 -66
  101. package/dist/esm/oauth-providers/google.js +96 -96
  102. package/dist/esm/oauth-providers/index.js +18 -18
  103. package/dist/esm/oauth-providers/instagram.js +61 -61
  104. package/dist/esm/oauth-providers/oauth-provider.js +16 -16
  105. package/dist/esm/oauth-providers/spotify.js +92 -92
  106. package/dist/esm/routes/auth-change-password.js +72 -72
  107. package/dist/esm/routes/auth-delete.js +37 -37
  108. package/dist/esm/routes/auth-forgot-password.js +62 -62
  109. package/dist/esm/routes/auth-reset-password.js +81 -81
  110. package/dist/esm/routes/auth-signin.js +33 -33
  111. package/dist/esm/routes/auth-signout.js +47 -47
  112. package/dist/esm/routes/auth-signup.js +127 -127
  113. package/dist/esm/routes/auth-state.js +12 -12
  114. package/dist/esm/routes/auth-update.js +116 -116
  115. package/dist/esm/routes/auth-verify-email.js +57 -57
  116. package/dist/esm/routes/auth.js +53 -50
  117. package/dist/esm/routes/data-exists.js +20 -20
  118. package/dist/esm/routes/data-export.js +35 -35
  119. package/dist/esm/routes/data-get.js +56 -52
  120. package/dist/esm/routes/data-import.js +41 -41
  121. package/dist/esm/routes/data-index-create.js +28 -28
  122. package/dist/esm/routes/data-index-delete.js +20 -20
  123. package/dist/esm/routes/data-index-list.js +18 -18
  124. package/dist/esm/routes/data-query.js +66 -56
  125. package/dist/esm/routes/data-reflect.js +83 -72
  126. package/dist/esm/routes/data-schema-get.js +23 -23
  127. package/dist/esm/routes/data-schema-set.js +17 -17
  128. package/dist/esm/routes/data-schema-test.js +29 -29
  129. package/dist/esm/routes/data-schemas-list.js +19 -19
  130. package/dist/esm/routes/data-set.js +70 -60
  131. package/dist/esm/routes/data-sync-changes.js +67 -53
  132. package/dist/esm/routes/data-sync-mutations.js +67 -53
  133. package/dist/esm/routes/data-transaction.js +142 -123
  134. package/dist/esm/routes/data-update.js +71 -60
  135. package/dist/esm/routes/data.js +58 -58
  136. package/dist/esm/routes/docs.js +252 -245
  137. package/dist/esm/routes/meta-info.js +59 -59
  138. package/dist/esm/routes/meta-logs.js +35 -35
  139. package/dist/esm/routes/meta-ping.js +7 -7
  140. package/dist/esm/routes/meta-stats.js +14 -14
  141. package/dist/esm/routes/meta.js +15 -15
  142. package/dist/esm/routes/oauth2-init.js +41 -41
  143. package/dist/esm/routes/oauth2-refresh.js +29 -29
  144. package/dist/esm/routes/oauth2-signin.js +251 -251
  145. package/dist/esm/routes/webmanager.js +22 -22
  146. package/dist/esm/rules.js +374 -163
  147. package/dist/esm/sandbox.js +12 -0
  148. package/dist/esm/schema/user.js +19 -19
  149. package/dist/esm/server.js +395 -387
  150. package/dist/esm/settings/email.js +1 -1
  151. package/dist/esm/settings/index.js +168 -165
  152. package/dist/esm/shared/clients.js +22 -22
  153. package/dist/esm/shared/email.js +1 -1
  154. package/dist/esm/shared/env.js +1 -1
  155. package/dist/esm/shared/error.js +25 -25
  156. package/dist/esm/shared/http.js +22 -22
  157. package/dist/esm/shared/password.js +38 -38
  158. package/dist/esm/shared/rootpath.js +13 -13
  159. package/dist/esm/shared/signin.js +128 -128
  160. package/dist/esm/shared/simple-fetch.js +59 -59
  161. package/dist/esm/shared/tokens.js +72 -72
  162. package/dist/esm/shared/validate.js +41 -41
  163. package/dist/esm/start.js +116 -50
  164. package/dist/esm/test.js +8 -8
  165. package/dist/esm/websocket/index.js +313 -302
  166. package/dist/esm/websocket/manager.js +11 -11
  167. package/dist/esm/websocket/socket.io.js +71 -71
  168. package/dist/types/auth.d.ts +3 -3
  169. package/dist/types/cluster.d.ts +6 -1
  170. package/dist/types/index.d.ts +4 -4
  171. package/dist/types/logger.d.ts +35 -35
  172. package/dist/types/middleware/404.d.ts +7 -7
  173. package/dist/types/middleware/admin-only.d.ts +19 -19
  174. package/dist/types/middleware/cache.d.ts +3 -3
  175. package/dist/types/middleware/connection.d.ts +7 -7
  176. package/dist/types/middleware/context.d.ts +3 -3
  177. package/dist/types/middleware/cors.d.ts +25 -25
  178. package/dist/types/middleware/swagger.d.ts +3 -3
  179. package/dist/types/middleware/user.d.ts +2 -2
  180. package/dist/types/oauth-providers/dropbox.d.ts +52 -52
  181. package/dist/types/oauth-providers/facebook.d.ts +41 -41
  182. package/dist/types/oauth-providers/google.d.ts +43 -43
  183. package/dist/types/oauth-providers/index.d.ts +10 -10
  184. package/dist/types/oauth-providers/instagram.d.ts +50 -50
  185. package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
  186. package/dist/types/oauth-providers/spotify.d.ts +53 -53
  187. package/dist/types/routes/auth-change-password.d.ts +20 -20
  188. package/dist/types/routes/auth-delete.d.ts +16 -16
  189. package/dist/types/routes/auth-forgot-password.d.ts +16 -16
  190. package/dist/types/routes/auth-reset-password.d.ts +23 -23
  191. package/dist/types/routes/auth-signin.d.ts +24 -24
  192. package/dist/types/routes/auth-signout.d.ts +14 -14
  193. package/dist/types/routes/auth-signup.d.ts +32 -32
  194. package/dist/types/routes/auth-state.d.ts +13 -13
  195. package/dist/types/routes/auth-update.d.ts +33 -33
  196. package/dist/types/routes/auth-verify-email.d.ts +21 -21
  197. package/dist/types/routes/auth.d.ts +6 -6
  198. package/dist/types/routes/data-exists.d.ts +9 -9
  199. package/dist/types/routes/data-export.d.ts +10 -10
  200. package/dist/types/routes/data-get.d.ts +14 -14
  201. package/dist/types/routes/data-import.d.ts +13 -13
  202. package/dist/types/routes/data-index-create.d.ts +51 -51
  203. package/dist/types/routes/data-index-delete.d.ts +17 -17
  204. package/dist/types/routes/data-index-list.d.ts +21 -21
  205. package/dist/types/routes/data-query.d.ts +49 -49
  206. package/dist/types/routes/data-reflect.d.ts +29 -29
  207. package/dist/types/routes/data-schema-get.d.ts +11 -11
  208. package/dist/types/routes/data-schema-set.d.ts +20 -19
  209. package/dist/types/routes/data-schema-test.d.ts +19 -19
  210. package/dist/types/routes/data-schemas-list.d.ts +11 -11
  211. package/dist/types/routes/data-set.d.ts +27 -27
  212. package/dist/types/routes/data-sync-changes.d.ts +25 -28
  213. package/dist/types/routes/data-sync-mutations.d.ts +25 -28
  214. package/dist/types/routes/data-transaction.d.ts +34 -34
  215. package/dist/types/routes/data-update.d.ts +27 -27
  216. package/dist/types/routes/data.d.ts +3 -3
  217. package/dist/types/routes/docs.d.ts +3 -3
  218. package/dist/types/routes/meta-info.d.ts +11 -11
  219. package/dist/types/routes/meta-logs.d.ts +20 -20
  220. package/dist/types/routes/meta-ping.d.ts +7 -7
  221. package/dist/types/routes/meta-stats.d.ts +13 -13
  222. package/dist/types/routes/meta.d.ts +3 -3
  223. package/dist/types/routes/oauth2-init.d.ts +13 -13
  224. package/dist/types/routes/oauth2-refresh.d.ts +17 -17
  225. package/dist/types/routes/oauth2-signin.d.ts +15 -15
  226. package/dist/types/routes/webmanager.d.ts +3 -3
  227. package/dist/types/rules.d.ts +73 -34
  228. package/dist/types/sandbox.d.ts +3 -0
  229. package/dist/types/schema/user.d.ts +85 -85
  230. package/dist/types/server.d.ts +117 -111
  231. package/dist/types/settings/email.d.ts +14 -14
  232. package/dist/types/settings/index.d.ts +195 -187
  233. package/dist/types/shared/clients.d.ts +46 -46
  234. package/dist/types/shared/email.d.ts +34 -34
  235. package/dist/types/shared/env.d.ts +47 -44
  236. package/dist/types/shared/error.d.ts +15 -15
  237. package/dist/types/shared/http.d.ts +22 -21
  238. package/dist/types/shared/password.d.ts +19 -19
  239. package/dist/types/shared/rootpath.d.ts +2 -2
  240. package/dist/types/shared/signin.d.ts +31 -31
  241. package/dist/types/shared/simple-fetch.d.ts +21 -21
  242. package/dist/types/shared/tokens.d.ts +24 -24
  243. package/dist/types/shared/validate.d.ts +22 -22
  244. package/dist/types/start.d.ts +1 -1
  245. package/dist/types/test.d.ts +1 -1
  246. package/dist/types/websocket/index.d.ts +6 -6
  247. package/dist/types/websocket/manager.d.ts +99 -99
  248. package/dist/types/websocket/socket.io.d.ts +10 -10
  249. package/package.json +7 -4
  250. package/src/routes/data-schema-set.yaml +4 -0
  251. package/src/routes/data-set.yaml +5 -5
  252. package/src/routes/data-update.yaml +4 -4
@@ -1,246 +1,253 @@
1
- import * as swaggerJsdoc from 'swagger-jsdoc';
2
- const createSwaggerDocs = swaggerJsdoc.default ?? swaggerJsdoc; // ESM and CJS compatible approach
3
- import * as _swaggerUi from 'swagger-ui-express';
4
- const swaggerUi = _swaggerUi.default ?? _swaggerUi; // ESM and CJS compatible approach
5
- import { packageRootPath } from '../shared/rootpath.js';
6
- import { join as joinPaths } from 'path';
7
- const yamlPath = joinPaths(packageRootPath, '/src/routes/*.yaml');
8
- // console.log(`Using path ${yamlPath} for Swagger documentation`);
9
- export const addRoute = (env) => {
10
- // Generate docs from all yaml files
11
- const options = {
12
- definition: {
13
- openapi: '3.0.0',
14
- info: {
15
- title: 'AceBase Server',
16
- description: 'AceBase Server API endpoint documentation and test environment. This documentation is available on the server because it is running in development mode. To disable this, set your NODE_ENV environment variable to production. Many endpoints require you to authenticate using Bearer authentication. Use the _/auth/{dbname}/signin_ endpoint to obtain an access token, then click the _Authorize_ button and paste your token into the input field. For more information about AceBase, see GitHub',
17
- version: '1.10.0',
18
- contact: {
19
- name: 'AceBase API Support',
20
- email: 'me@appy.one',
21
- url: 'https://github.com/appy-one/acebase-server',
22
- },
23
- },
24
- servers: [
25
- { url: `http${env.config.https?.enabled ? 's' : ''}://${env.config.host}:${env.config.port}${env.config.rootPath ? `/${env.config.rootPath}` : ''}` },
26
- ],
27
- tags: [{
28
- name: 'auth',
29
- description: 'User authentication endpoints',
30
- }, {
31
- name: 'oauth2',
32
- description: 'User authentication using 3rd party OAuth2 providers',
33
- }, {
34
- name: 'data',
35
- description: 'Data manipulation and query endpoints',
36
- }, {
37
- name: 'indexes',
38
- description: 'Index management endpoints',
39
- }, {
40
- name: 'schemas',
41
- description: 'Data schema management endpoints',
42
- }, {
43
- name: 'metadata',
44
- description: 'Metadata endpoints',
45
- }],
46
- components: {
47
- securitySchemes: {
48
- bearerAuth: {
49
- type: 'http',
50
- scheme: 'bearer',
51
- bearerFormat: 'token', // switch to JWT in the future?
52
- },
53
- },
54
- schemas: {
55
- User: {
56
- type: 'object',
57
- properties: {
58
- uid: { type: 'string', example: 'jpx0k53u0002ecr7s354c51l' },
59
- username: { type: 'string', example: 'someuser' },
60
- email: { type: 'string', example: 'email@domain.com' },
61
- displayName: { type: 'string', example: 'Some User' },
62
- picture: {
63
- type: 'object',
64
- properties: {
65
- width: { type: 'number', example: 500 },
66
- height: { type: 'number', example: 500 },
67
- url: { type: 'string', example: 'https://profile.pic/user.jpg' },
68
- },
69
- },
70
- emailVerified: { type: 'boolean', example: true },
71
- created: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
72
- prevSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
73
- prevSigninIp: { type: 'string', example: '127.0.0.1' },
74
- lastSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
75
- lastSigninIp: { type: 'string', example: '127.0.0.1' },
76
- changePassword: { type: 'boolean', example: false },
77
- changePasswordRequested: { type: 'boolean', example: false },
78
- changePasswordBefore: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
79
- settings: { type: 'object' },
80
- },
81
- },
82
- Error: {
83
- type: 'object',
84
- properties: {
85
- code: { type: 'string', description: 'error code', example: 'invalid_request' },
86
- message: { type: 'string', description: 'The error message', example: 'Invalid request for this endpoint' },
87
- },
88
- },
89
- UnexpectedError: {
90
- type: 'object',
91
- properties: {
92
- code: { type: 'string', value: 'unexpected', description: 'The string `"unexpected"`' },
93
- message: { type: 'string', description: 'The server error message' },
94
- },
95
- },
96
- UnknownError: {
97
- type: 'object',
98
- properties: {
99
- code: { type: 'string', value: 'unknown', description: 'The string `"unknown"`' },
100
- message: { type: 'string', description: 'The server error message' },
101
- },
102
- },
103
- SchemaValidationError: {
104
- type: 'object',
105
- properties: {
106
- code: { type: 'string', description: 'The string `"schema_validation_failed"`', example: 'schema_validation_failed' },
107
- message: { type: 'string', description: 'The server error message', example: 'Property at path "path/property" is of the wrong type' },
108
- },
109
- },
110
- SerializedValue: {
111
- type: 'object',
112
- properties: {
113
- val: {
114
- description: 'Any value (serialized for transport)',
115
- oneOf: [
116
- { type: 'string' },
117
- { type: 'number' },
118
- { type: 'integer' },
119
- { type: 'boolean' },
120
- { type: 'object' },
121
- { type: 'array' },
122
- ],
123
- example: '2022-04-07T16:36:21Z',
124
- required: true,
125
- },
126
- map: {
127
- description: 'If the value has been serialized for transport, contains a string defining `val`s data type (eg `"date"` or `"binary"`), or an object with deep property mappings for an object value in `val`',
128
- oneOf: [
129
- { type: 'string', example: 'date' },
130
- { type: 'object', example: { 'stats/created': 'date' } },
131
- ],
132
- example: 'date',
133
- required: false,
134
- },
135
- },
136
- required: ['val'],
137
- example: {
138
- val: { name: 'My todo list', stats: { size: 216, created: '2022-04-07T15:11:42Z', modified: '2022-03-08T12:24:05Z' } },
139
- map: { 'stats/created': 'date', 'stats/modified': 'date' },
140
- },
141
- },
142
- ReflectionNodeInfo: {
143
- type: 'object',
144
- required: ['key', 'exists', 'type'],
145
- properties: {
146
- key: {
147
- description: 'Key or index of the node',
148
- oneOf: [{
149
- type: 'string',
150
- description: 'key of the node',
151
- example: 'jld2cjxh0000qzrmn831i7rn',
152
- }, {
153
- type: 'number',
154
- description: 'index of the node (parent node is an array)',
155
- example: 12,
156
- }],
157
- },
158
- exists: {
159
- type: 'boolean',
160
- description: 'whether the target path exists',
161
- example: true,
162
- },
163
- type: {
164
- type: 'string',
165
- enum: ['unknown', 'object', 'array', 'number', 'boolean', 'string', 'date', 'binary', 'reference'],
166
- description: 'data type of the target path',
167
- example: 'object',
168
- },
169
- value: {
170
- oneOf: [{ type: 'string' }, { type: 'number' }, { type: 'boolean' }, { type: 'array' }, { type: 'object' }],
171
- description: `target node's stored value if it is a boolean, number or date, a small string or binary value (less than configured max inline value size), or an empty object or array`,
172
- example: {},
173
- },
174
- address: {
175
- type: 'object',
176
- description: 'The physical location of the node in the database',
177
- required: ['pageNr', 'recordNr'],
178
- properties: {
179
- pageNr: { type: 'integer' },
180
- recordNr: { type: 'integer' },
181
- },
182
- },
183
- children: {
184
- type: 'object',
185
- description: `Information about the node's children (if requested)`,
186
- required: ['more', 'list'],
187
- properties: {
188
- count: {
189
- type: 'integer',
190
- description: 'The total number of children',
191
- example: 2865,
192
- },
193
- more: {
194
- type: 'boolean',
195
- description: 'If there are more children than the ones in list',
196
- example: true,
197
- },
198
- list: {
199
- type: 'array',
200
- description: 'Reflection info about the requested children',
201
- items: {
202
- $ref: '#/components/schemas/ReflectionNodeInfo',
203
- },
204
- example: [{
205
- key: 'name',
206
- type: 'string',
207
- value: 'My name',
208
- }],
209
- },
210
- },
211
- },
212
- },
213
- example: {
214
- key: 'jld2cjxh0000qzrmn831i7rn',
215
- exists: true,
216
- type: 'object',
217
- address: { pageNr: 0, recordNr: 234 },
218
- children: {
219
- count: 2865,
220
- more: true,
221
- list: [{
222
- key: 'l260qein000009jy3yjig8h9',
223
- type: 'object',
224
- address: { pageNr: 1, recordNr: 25 },
225
- }, {
226
- key: 'l260rp5b000109jy98ykf7x2',
227
- type: 'object',
228
- address: { pageNr: 1, recordNr: 54 },
229
- }],
230
- },
231
- },
232
- },
233
- },
234
- },
235
- security: [
236
- // Enable bearer auth globally
237
- { bearerAuth: [] },
238
- ],
239
- },
240
- apis: [yamlPath],
241
- };
242
- const swaggerDocs = createSwaggerDocs(options);
243
- env.app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
244
- };
245
- export default addRoute;
1
+ import * as swaggerJsdoc from 'swagger-jsdoc';
2
+ const createSwaggerDocs = swaggerJsdoc.default ?? swaggerJsdoc; // ESM and CJS compatible approach
3
+ import * as _swaggerUi from 'swagger-ui-express';
4
+ const swaggerUi = _swaggerUi.default ?? _swaggerUi; // ESM and CJS compatible approach
5
+ import { packageRootPath } from '../shared/rootpath.js';
6
+ import { join as joinPaths } from 'path';
7
+ const yamlPath = joinPaths(packageRootPath, '/src/routes/*.yaml');
8
+ // console.log(`Using path ${yamlPath} for Swagger documentation`);
9
+ export const addRoute = (env) => {
10
+ // Generate docs from all yaml files
11
+ const options = {
12
+ definition: {
13
+ openapi: '3.0.0',
14
+ info: {
15
+ title: 'AceBase Server',
16
+ description: 'AceBase Server API endpoint documentation and test environment. This documentation is available on the server because it is running in development mode. To disable this, set your NODE_ENV environment variable to production. Many endpoints require you to authenticate using Bearer authentication. Use the _/auth/{dbname}/signin_ endpoint to obtain an access token, then click the _Authorize_ button and paste your token into the input field. For more information about AceBase, see GitHub',
17
+ version: '1.18.0',
18
+ contact: {
19
+ name: 'AceBase API Support',
20
+ email: 'me@appy.one',
21
+ url: 'https://github.com/appy-one/acebase-server',
22
+ },
23
+ },
24
+ servers: [
25
+ { url: `http${env.config.https?.enabled ? 's' : ''}://${env.config.host}:${env.config.port}${env.config.rootPath ? `/${env.config.rootPath}` : ''}` },
26
+ ],
27
+ tags: [{
28
+ name: 'auth',
29
+ description: 'User authentication endpoints',
30
+ }, {
31
+ name: 'oauth2',
32
+ description: 'User authentication using 3rd party OAuth2 providers',
33
+ }, {
34
+ name: 'data',
35
+ description: 'Data manipulation and query endpoints',
36
+ }, {
37
+ name: 'indexes',
38
+ description: 'Index management endpoints',
39
+ }, {
40
+ name: 'schemas',
41
+ description: 'Data schema management endpoints',
42
+ }, {
43
+ name: 'metadata',
44
+ description: 'Metadata endpoints',
45
+ }],
46
+ components: {
47
+ securitySchemes: {
48
+ bearerAuth: {
49
+ type: 'http',
50
+ scheme: 'bearer',
51
+ bearerFormat: 'token', // switch to JWT in the future?
52
+ },
53
+ },
54
+ schemas: {
55
+ User: {
56
+ type: 'object',
57
+ properties: {
58
+ uid: { type: 'string', example: 'jpx0k53u0002ecr7s354c51l' },
59
+ username: { type: 'string', example: 'someuser' },
60
+ email: { type: 'string', example: 'email@domain.com' },
61
+ displayName: { type: 'string', example: 'Some User' },
62
+ picture: {
63
+ type: 'object',
64
+ properties: {
65
+ width: { type: 'number', example: 500 },
66
+ height: { type: 'number', example: 500 },
67
+ url: { type: 'string', example: 'https://profile.pic/user.jpg' },
68
+ },
69
+ },
70
+ emailVerified: { type: 'boolean', example: true },
71
+ created: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
72
+ prevSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
73
+ prevSigninIp: { type: 'string', example: '127.0.0.1' },
74
+ lastSignin: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
75
+ lastSigninIp: { type: 'string', example: '127.0.0.1' },
76
+ changePassword: { type: 'boolean', example: false },
77
+ changePasswordRequested: { type: 'boolean', example: false },
78
+ changePasswordBefore: { type: 'string', example: '2022-03-09T15:38:57.361Z' },
79
+ settings: { type: 'object' },
80
+ },
81
+ },
82
+ Error: {
83
+ type: 'object',
84
+ properties: {
85
+ code: { type: 'string', description: 'error code', example: 'invalid_request' },
86
+ message: { type: 'string', description: 'The error message', example: 'Invalid request for this endpoint' },
87
+ },
88
+ },
89
+ UnexpectedError: {
90
+ type: 'object',
91
+ properties: {
92
+ code: { type: 'string', value: 'unexpected', description: 'The string `"unexpected"`' },
93
+ message: { type: 'string', description: 'The server error message' },
94
+ },
95
+ },
96
+ UnknownError: {
97
+ type: 'object',
98
+ properties: {
99
+ code: { type: 'string', value: 'unknown', description: 'The string `"unknown"`' },
100
+ message: { type: 'string', description: 'The server error message' },
101
+ },
102
+ },
103
+ SchemaValidationError: {
104
+ type: 'object',
105
+ properties: {
106
+ code: { type: 'string', description: 'The string `"schema_validation_failed"`', example: 'schema_validation_failed' },
107
+ message: { type: 'string', description: 'The server error message', example: 'Property at path "path/property" is of the wrong type' },
108
+ },
109
+ },
110
+ RuleValidationError: {
111
+ type: 'object',
112
+ properties: {
113
+ code: { type: 'string', description: 'The string `"rule"`', example: 'rule' },
114
+ message: { type: 'string', description: 'The server error message', example: 'write operation denied to path "path/property" by set rule' },
115
+ },
116
+ },
117
+ SerializedValue: {
118
+ type: 'object',
119
+ properties: {
120
+ val: {
121
+ description: 'Any value (serialized for transport)',
122
+ oneOf: [
123
+ { type: 'string' },
124
+ { type: 'number' },
125
+ { type: 'integer' },
126
+ { type: 'boolean' },
127
+ { type: 'object' },
128
+ { type: 'array' },
129
+ ],
130
+ example: '2022-04-07T16:36:21Z',
131
+ required: true,
132
+ },
133
+ map: {
134
+ description: 'If the value has been serialized for transport, contains a string defining `val`s data type (eg `"date"` or `"binary"`), or an object with deep property mappings for an object value in `val`',
135
+ oneOf: [
136
+ { type: 'string', example: 'date' },
137
+ { type: 'object', example: { 'stats/created': 'date' } },
138
+ ],
139
+ example: 'date',
140
+ required: false,
141
+ },
142
+ },
143
+ required: ['val'],
144
+ example: {
145
+ val: { name: 'My todo list', stats: { size: 216, created: '2022-04-07T15:11:42Z', modified: '2022-03-08T12:24:05Z' } },
146
+ map: { 'stats/created': 'date', 'stats/modified': 'date' },
147
+ },
148
+ },
149
+ ReflectionNodeInfo: {
150
+ type: 'object',
151
+ required: ['key', 'exists', 'type'],
152
+ properties: {
153
+ key: {
154
+ description: 'Key or index of the node',
155
+ oneOf: [{
156
+ type: 'string',
157
+ description: 'key of the node',
158
+ example: 'jld2cjxh0000qzrmn831i7rn',
159
+ }, {
160
+ type: 'number',
161
+ description: 'index of the node (parent node is an array)',
162
+ example: 12,
163
+ }],
164
+ },
165
+ exists: {
166
+ type: 'boolean',
167
+ description: 'whether the target path exists',
168
+ example: true,
169
+ },
170
+ type: {
171
+ type: 'string',
172
+ enum: ['unknown', 'object', 'array', 'number', 'boolean', 'string', 'date', 'binary', 'reference'],
173
+ description: 'data type of the target path',
174
+ example: 'object',
175
+ },
176
+ value: {
177
+ oneOf: [{ type: 'string' }, { type: 'number' }, { type: 'boolean' }, { type: 'array' }, { type: 'object' }],
178
+ description: `target node's stored value if it is a boolean, number or date, a small string or binary value (less than configured max inline value size), or an empty object or array`,
179
+ example: {},
180
+ },
181
+ address: {
182
+ type: 'object',
183
+ description: 'The physical location of the node in the database',
184
+ required: ['pageNr', 'recordNr'],
185
+ properties: {
186
+ pageNr: { type: 'integer' },
187
+ recordNr: { type: 'integer' },
188
+ },
189
+ },
190
+ children: {
191
+ type: 'object',
192
+ description: `Information about the node's children (if requested)`,
193
+ required: ['more', 'list'],
194
+ properties: {
195
+ count: {
196
+ type: 'integer',
197
+ description: 'The total number of children',
198
+ example: 2865,
199
+ },
200
+ more: {
201
+ type: 'boolean',
202
+ description: 'If there are more children than the ones in list',
203
+ example: true,
204
+ },
205
+ list: {
206
+ type: 'array',
207
+ description: 'Reflection info about the requested children',
208
+ items: {
209
+ $ref: '#/components/schemas/ReflectionNodeInfo',
210
+ },
211
+ example: [{
212
+ key: 'name',
213
+ type: 'string',
214
+ value: 'My name',
215
+ }],
216
+ },
217
+ },
218
+ },
219
+ },
220
+ example: {
221
+ key: 'jld2cjxh0000qzrmn831i7rn',
222
+ exists: true,
223
+ type: 'object',
224
+ address: { pageNr: 0, recordNr: 234 },
225
+ children: {
226
+ count: 2865,
227
+ more: true,
228
+ list: [{
229
+ key: 'l260qein000009jy3yjig8h9',
230
+ type: 'object',
231
+ address: { pageNr: 1, recordNr: 25 },
232
+ }, {
233
+ key: 'l260rp5b000109jy98ykf7x2',
234
+ type: 'object',
235
+ address: { pageNr: 1, recordNr: 54 },
236
+ }],
237
+ },
238
+ },
239
+ },
240
+ },
241
+ },
242
+ security: [
243
+ // Enable bearer auth globally
244
+ { bearerAuth: [] },
245
+ ],
246
+ },
247
+ apis: [yamlPath],
248
+ };
249
+ const swaggerDocs = createSwaggerDocs(options);
250
+ env.router.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
251
+ };
252
+ export default addRoute;
246
253
  //# sourceMappingURL=docs.js.map
@@ -1,60 +1,60 @@
1
- import * as os from 'os';
2
- const SERVER_VERSION = '1.16.2'; // Loaded from package.json by npm scripts
3
- export const addRoute = (env) => {
4
- // Add info endpoint
5
- env.app.get(`/info/${env.db.name}`, (req, res) => {
6
- const info = {
7
- version: SERVER_VERSION,
8
- time: Date.now(),
9
- process: process.pid,
10
- };
11
- if (req.user && req.user.uid === 'admin') {
12
- const numberToByteSize = number => {
13
- return Math.round((number / 1024 / 1024) * 100) / 100 + 'MB';
14
- };
15
- const sPerMinute = 60;
16
- const sPerHour = sPerMinute * 60;
17
- const sPerDay = sPerHour * 24;
18
- const numberToTime = number => {
19
- const days = Math.floor(number / sPerDay);
20
- number -= sPerDay * days;
21
- const hours = Math.floor(number / sPerHour);
22
- number -= hours * sPerHour;
23
- const minutes = Math.floor(number / sPerMinute);
24
- number -= minutes * sPerMinute;
25
- const seconds = Math.floor(number);
26
- return `${days}d${hours}h${minutes}m${seconds}s`;
27
- };
28
- const mem = process.memoryUsage();
29
- const adminInfo = {
30
- dbname: env.db.name,
31
- platform: os.platform(),
32
- arch: os.arch(),
33
- release: os.release(),
34
- host: os.hostname(),
35
- uptime: numberToTime(os.uptime()),
36
- load: os.loadavg(),
37
- mem: {
38
- total: numberToByteSize(os.totalmem()),
39
- free: numberToByteSize(os.freemem()),
40
- process: {
41
- arrayBuffers: numberToByteSize(mem.arrayBuffers),
42
- external: numberToByteSize(mem.external),
43
- heapTotal: numberToByteSize(mem.heapTotal),
44
- heapUsed: numberToByteSize(mem.heapUsed),
45
- residentSet: numberToByteSize(mem.rss),
46
- },
47
- },
48
- cpus: os.cpus(),
49
- network: os.networkInterfaces(),
50
- };
51
- Object.assign(info, adminInfo);
52
- }
53
- // for (let i = 0; i < 1000000000; i++) {
54
- // let j = Math.pow(i, 2);
55
- // }
56
- res.send(info);
57
- });
58
- };
59
- export default addRoute;
1
+ import * as os from 'os';
2
+ const SERVER_VERSION = '1.18.0'; // Loaded from package.json by npm scripts
3
+ export const addRoute = (env) => {
4
+ // Add info endpoint
5
+ env.router.get(`/info/${env.db.name}`, (req, res) => {
6
+ const info = {
7
+ version: SERVER_VERSION,
8
+ time: Date.now(),
9
+ process: process.pid,
10
+ };
11
+ if (req.user && req.user.uid === 'admin') {
12
+ const numberToByteSize = number => {
13
+ return Math.round((number / 1024 / 1024) * 100) / 100 + 'MB';
14
+ };
15
+ const sPerMinute = 60;
16
+ const sPerHour = sPerMinute * 60;
17
+ const sPerDay = sPerHour * 24;
18
+ const numberToTime = number => {
19
+ const days = Math.floor(number / sPerDay);
20
+ number -= sPerDay * days;
21
+ const hours = Math.floor(number / sPerHour);
22
+ number -= hours * sPerHour;
23
+ const minutes = Math.floor(number / sPerMinute);
24
+ number -= minutes * sPerMinute;
25
+ const seconds = Math.floor(number);
26
+ return `${days}d${hours}h${minutes}m${seconds}s`;
27
+ };
28
+ const mem = process.memoryUsage();
29
+ const adminInfo = {
30
+ dbname: env.db.name,
31
+ platform: os.platform(),
32
+ arch: os.arch(),
33
+ release: os.release(),
34
+ host: os.hostname(),
35
+ uptime: numberToTime(os.uptime()),
36
+ load: os.loadavg(),
37
+ mem: {
38
+ total: numberToByteSize(os.totalmem()),
39
+ free: numberToByteSize(os.freemem()),
40
+ process: {
41
+ arrayBuffers: numberToByteSize(mem.arrayBuffers),
42
+ external: numberToByteSize(mem.external),
43
+ heapTotal: numberToByteSize(mem.heapTotal),
44
+ heapUsed: numberToByteSize(mem.heapUsed),
45
+ residentSet: numberToByteSize(mem.rss),
46
+ },
47
+ },
48
+ cpus: os.cpus(),
49
+ network: os.networkInterfaces(),
50
+ };
51
+ Object.assign(info, adminInfo);
52
+ }
53
+ // for (let i = 0; i < 1000000000; i++) {
54
+ // let j = Math.pow(i, 2);
55
+ // }
56
+ res.send(info);
57
+ });
58
+ };
59
+ export default addRoute;
60
60
  //# sourceMappingURL=meta-info.js.map