acebase-server 1.12.0 → 1.13.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 (286) hide show
  1. package/.vscode/launch.json +24 -0
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/shared/rootpath.js +2 -0
  4. package/dist/esm/index.d.ts +1 -0
  5. package/dist/esm/shared/rootpath.js +2 -0
  6. package/package.json +3 -3
  7. package/webmanager/acebase-client-browser.min.js +16 -16
  8. package/create-package-files +0 -12
  9. package/dist/cjs/auth.js.map +0 -1
  10. package/dist/cjs/cluster.js.map +0 -1
  11. package/dist/cjs/index.js.map +0 -1
  12. package/dist/cjs/logger.js.map +0 -1
  13. package/dist/cjs/middleware/404.js.map +0 -1
  14. package/dist/cjs/middleware/admin-only.js.map +0 -1
  15. package/dist/cjs/middleware/cache.js.map +0 -1
  16. package/dist/cjs/middleware/connection.js.map +0 -1
  17. package/dist/cjs/middleware/context.js.map +0 -1
  18. package/dist/cjs/middleware/cors.js.map +0 -1
  19. package/dist/cjs/middleware/swagger.js.map +0 -1
  20. package/dist/cjs/middleware/user.js.map +0 -1
  21. package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
  22. package/dist/cjs/oauth-providers/facebook.js.map +0 -1
  23. package/dist/cjs/oauth-providers/google.js.map +0 -1
  24. package/dist/cjs/oauth-providers/index.js.map +0 -1
  25. package/dist/cjs/oauth-providers/instagram.js.map +0 -1
  26. package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
  27. package/dist/cjs/oauth-providers/spotify.js.map +0 -1
  28. package/dist/cjs/routes/auth-change-password.js.map +0 -1
  29. package/dist/cjs/routes/auth-delete.js.map +0 -1
  30. package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
  31. package/dist/cjs/routes/auth-reset-password.js.map +0 -1
  32. package/dist/cjs/routes/auth-signin.js.map +0 -1
  33. package/dist/cjs/routes/auth-signout.js.map +0 -1
  34. package/dist/cjs/routes/auth-signup.js.map +0 -1
  35. package/dist/cjs/routes/auth-state.js.map +0 -1
  36. package/dist/cjs/routes/auth-update.js.map +0 -1
  37. package/dist/cjs/routes/auth-verify-email.js.map +0 -1
  38. package/dist/cjs/routes/auth.js.map +0 -1
  39. package/dist/cjs/routes/data-exists.js.map +0 -1
  40. package/dist/cjs/routes/data-export.js.map +0 -1
  41. package/dist/cjs/routes/data-get.js.map +0 -1
  42. package/dist/cjs/routes/data-import.js.map +0 -1
  43. package/dist/cjs/routes/data-index-create.js.map +0 -1
  44. package/dist/cjs/routes/data-index-delete.js.map +0 -1
  45. package/dist/cjs/routes/data-index-list.js.map +0 -1
  46. package/dist/cjs/routes/data-query.js.map +0 -1
  47. package/dist/cjs/routes/data-reflect.js.map +0 -1
  48. package/dist/cjs/routes/data-schema-get.js.map +0 -1
  49. package/dist/cjs/routes/data-schema-set.js.map +0 -1
  50. package/dist/cjs/routes/data-schema-test.js.map +0 -1
  51. package/dist/cjs/routes/data-schemas-list.js.map +0 -1
  52. package/dist/cjs/routes/data-set.js.map +0 -1
  53. package/dist/cjs/routes/data-sync-changes.js.map +0 -1
  54. package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
  55. package/dist/cjs/routes/data-transaction.js.map +0 -1
  56. package/dist/cjs/routes/data-update.js.map +0 -1
  57. package/dist/cjs/routes/data.js.map +0 -1
  58. package/dist/cjs/routes/docs.js.map +0 -1
  59. package/dist/cjs/routes/meta-info.js.map +0 -1
  60. package/dist/cjs/routes/meta-logs.js.map +0 -1
  61. package/dist/cjs/routes/meta-ping.js.map +0 -1
  62. package/dist/cjs/routes/meta-stats.js.map +0 -1
  63. package/dist/cjs/routes/meta.js.map +0 -1
  64. package/dist/cjs/routes/oauth2-init.js.map +0 -1
  65. package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
  66. package/dist/cjs/routes/oauth2-signin.js.map +0 -1
  67. package/dist/cjs/routes/webmanager.js.map +0 -1
  68. package/dist/cjs/rules.js.map +0 -1
  69. package/dist/cjs/schema/user.js.map +0 -1
  70. package/dist/cjs/server.js.map +0 -1
  71. package/dist/cjs/settings/email.js.map +0 -1
  72. package/dist/cjs/settings/index.js.map +0 -1
  73. package/dist/cjs/shared/clients.js.map +0 -1
  74. package/dist/cjs/shared/email.js.map +0 -1
  75. package/dist/cjs/shared/env.js.map +0 -1
  76. package/dist/cjs/shared/error.js.map +0 -1
  77. package/dist/cjs/shared/http.js.map +0 -1
  78. package/dist/cjs/shared/password.js.map +0 -1
  79. package/dist/cjs/shared/rootpath.js.map +0 -1
  80. package/dist/cjs/shared/signin.js.map +0 -1
  81. package/dist/cjs/shared/simple-fetch.js.map +0 -1
  82. package/dist/cjs/shared/tokens.js.map +0 -1
  83. package/dist/cjs/shared/validate.js.map +0 -1
  84. package/dist/cjs/start.js.map +0 -1
  85. package/dist/cjs/test.js.map +0 -1
  86. package/dist/cjs/websocket/index.js.map +0 -1
  87. package/dist/cjs/websocket/manager.js.map +0 -1
  88. package/dist/cjs/websocket/socket.io.js.map +0 -1
  89. package/dist/esm/auth.js.map +0 -1
  90. package/dist/esm/cluster.js.map +0 -1
  91. package/dist/esm/index.js.map +0 -1
  92. package/dist/esm/logger.js.map +0 -1
  93. package/dist/esm/middleware/404.js.map +0 -1
  94. package/dist/esm/middleware/admin-only.js.map +0 -1
  95. package/dist/esm/middleware/cache.js.map +0 -1
  96. package/dist/esm/middleware/connection.js.map +0 -1
  97. package/dist/esm/middleware/context.js.map +0 -1
  98. package/dist/esm/middleware/cors.js.map +0 -1
  99. package/dist/esm/middleware/swagger.js.map +0 -1
  100. package/dist/esm/middleware/user.js.map +0 -1
  101. package/dist/esm/oauth-providers/dropbox.js.map +0 -1
  102. package/dist/esm/oauth-providers/facebook.js.map +0 -1
  103. package/dist/esm/oauth-providers/google.js.map +0 -1
  104. package/dist/esm/oauth-providers/index.js.map +0 -1
  105. package/dist/esm/oauth-providers/instagram.js.map +0 -1
  106. package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
  107. package/dist/esm/oauth-providers/spotify.js.map +0 -1
  108. package/dist/esm/routes/auth-change-password.js.map +0 -1
  109. package/dist/esm/routes/auth-delete.js.map +0 -1
  110. package/dist/esm/routes/auth-forgot-password.js.map +0 -1
  111. package/dist/esm/routes/auth-reset-password.js.map +0 -1
  112. package/dist/esm/routes/auth-signin.js.map +0 -1
  113. package/dist/esm/routes/auth-signout.js.map +0 -1
  114. package/dist/esm/routes/auth-signup.js.map +0 -1
  115. package/dist/esm/routes/auth-state.js.map +0 -1
  116. package/dist/esm/routes/auth-update.js.map +0 -1
  117. package/dist/esm/routes/auth-verify-email.js.map +0 -1
  118. package/dist/esm/routes/auth.js.map +0 -1
  119. package/dist/esm/routes/data-exists.js.map +0 -1
  120. package/dist/esm/routes/data-export.js.map +0 -1
  121. package/dist/esm/routes/data-get.js.map +0 -1
  122. package/dist/esm/routes/data-import.js.map +0 -1
  123. package/dist/esm/routes/data-index-create.js.map +0 -1
  124. package/dist/esm/routes/data-index-delete.js.map +0 -1
  125. package/dist/esm/routes/data-index-list.js.map +0 -1
  126. package/dist/esm/routes/data-query.js.map +0 -1
  127. package/dist/esm/routes/data-reflect.js.map +0 -1
  128. package/dist/esm/routes/data-schema-get.js.map +0 -1
  129. package/dist/esm/routes/data-schema-set.js.map +0 -1
  130. package/dist/esm/routes/data-schema-test.js.map +0 -1
  131. package/dist/esm/routes/data-schemas-list.js.map +0 -1
  132. package/dist/esm/routes/data-set.js.map +0 -1
  133. package/dist/esm/routes/data-sync-changes.js.map +0 -1
  134. package/dist/esm/routes/data-sync-mutations.js.map +0 -1
  135. package/dist/esm/routes/data-transaction.js.map +0 -1
  136. package/dist/esm/routes/data-update.js.map +0 -1
  137. package/dist/esm/routes/data.js.map +0 -1
  138. package/dist/esm/routes/docs.js.map +0 -1
  139. package/dist/esm/routes/meta-info.js.map +0 -1
  140. package/dist/esm/routes/meta-logs.js.map +0 -1
  141. package/dist/esm/routes/meta-ping.js.map +0 -1
  142. package/dist/esm/routes/meta-stats.js.map +0 -1
  143. package/dist/esm/routes/meta.js.map +0 -1
  144. package/dist/esm/routes/oauth2-init.js.map +0 -1
  145. package/dist/esm/routes/oauth2-refresh.js.map +0 -1
  146. package/dist/esm/routes/oauth2-signin.js.map +0 -1
  147. package/dist/esm/routes/webmanager.js.map +0 -1
  148. package/dist/esm/rules.js.map +0 -1
  149. package/dist/esm/schema/user.js.map +0 -1
  150. package/dist/esm/server.js.map +0 -1
  151. package/dist/esm/settings/email.js.map +0 -1
  152. package/dist/esm/settings/index.js.map +0 -1
  153. package/dist/esm/shared/clients.js.map +0 -1
  154. package/dist/esm/shared/email.js.map +0 -1
  155. package/dist/esm/shared/env.js.map +0 -1
  156. package/dist/esm/shared/error.js.map +0 -1
  157. package/dist/esm/shared/http.js.map +0 -1
  158. package/dist/esm/shared/password.js.map +0 -1
  159. package/dist/esm/shared/rootpath.js.map +0 -1
  160. package/dist/esm/shared/signin.js.map +0 -1
  161. package/dist/esm/shared/simple-fetch.js.map +0 -1
  162. package/dist/esm/shared/tokens.js.map +0 -1
  163. package/dist/esm/shared/validate.js.map +0 -1
  164. package/dist/esm/start.js.map +0 -1
  165. package/dist/esm/test.js.map +0 -1
  166. package/dist/esm/websocket/index.js.map +0 -1
  167. package/dist/esm/websocket/manager.js.map +0 -1
  168. package/dist/esm/websocket/socket.io.js.map +0 -1
  169. package/src/auth.ts +0 -87
  170. package/src/cluster.ts +0 -62
  171. package/src/index.ts +0 -4
  172. package/src/logger.ts +0 -56
  173. package/src/middleware/404.ts +0 -13
  174. package/src/middleware/admin-only.ts +0 -29
  175. package/src/middleware/cache.ts +0 -15
  176. package/src/middleware/connection.ts +0 -48
  177. package/src/middleware/context.ts +0 -23
  178. package/src/middleware/cors.ts +0 -49
  179. package/src/middleware/swagger.ts +0 -19
  180. package/src/middleware/user.ts +0 -51
  181. package/src/oauth-providers/dropbox.ts +0 -144
  182. package/src/oauth-providers/facebook.ts +0 -103
  183. package/src/oauth-providers/google.ts +0 -147
  184. package/src/oauth-providers/index.ts +0 -21
  185. package/src/oauth-providers/instagram.ts +0 -98
  186. package/src/oauth-providers/oauth-provider.ts +0 -65
  187. package/src/oauth-providers/spotify.ts +0 -127
  188. package/src/placeholder.d.ts +0 -12
  189. package/src/routes/auth-change-password.ts +0 -92
  190. package/src/routes/auth-change-password.yaml +0 -74
  191. package/src/routes/auth-delete.ts +0 -49
  192. package/src/routes/auth-delete.yaml +0 -78
  193. package/src/routes/auth-forgot-password.ts +0 -77
  194. package/src/routes/auth-forgot-password.yaml +0 -50
  195. package/src/routes/auth-reset-password.ts +0 -96
  196. package/src/routes/auth-reset-password.yaml +0 -54
  197. package/src/routes/auth-signin.ts +0 -55
  198. package/src/routes/auth-signin.yaml +0 -130
  199. package/src/routes/auth-signout.ts +0 -64
  200. package/src/routes/auth-signout.yaml +0 -46
  201. package/src/routes/auth-signup.ts +0 -164
  202. package/src/routes/auth-signup.yaml +0 -136
  203. package/src/routes/auth-state.ts +0 -20
  204. package/src/routes/auth-state.yaml +0 -29
  205. package/src/routes/auth-update.ts +0 -149
  206. package/src/routes/auth-update.yaml +0 -152
  207. package/src/routes/auth-verify-email.ts +0 -75
  208. package/src/routes/auth-verify-email.yaml +0 -53
  209. package/src/routes/auth.ts +0 -67
  210. package/src/routes/data-exists.ts +0 -31
  211. package/src/routes/data-exists.yaml +0 -44
  212. package/src/routes/data-export.ts +0 -51
  213. package/src/routes/data-export.yaml +0 -64
  214. package/src/routes/data-get.ts +0 -68
  215. package/src/routes/data-get.yaml +0 -54
  216. package/src/routes/data-import.ts +0 -56
  217. package/src/routes/data-import.yaml +0 -75
  218. package/src/routes/data-index-create.ts +0 -82
  219. package/src/routes/data-index-create.yaml +0 -105
  220. package/src/routes/data-index-delete.ts +0 -36
  221. package/src/routes/data-index-delete.yaml +0 -51
  222. package/src/routes/data-index-list.ts +0 -39
  223. package/src/routes/data-index-list.yaml +0 -80
  224. package/src/routes/data-query.ts +0 -97
  225. package/src/routes/data-query.yaml +0 -166
  226. package/src/routes/data-reflect.ts +0 -91
  227. package/src/routes/data-reflect.yaml +0 -124
  228. package/src/routes/data-schema-get.ts +0 -36
  229. package/src/routes/data-schema-get.yaml +0 -53
  230. package/src/routes/data-schema-set.ts +0 -35
  231. package/src/routes/data-schema-set.yaml +0 -60
  232. package/src/routes/data-schema-test.ts +0 -50
  233. package/src/routes/data-schema-test.yaml +0 -66
  234. package/src/routes/data-schemas-list.ts +0 -31
  235. package/src/routes/data-schemas-list.yaml +0 -41
  236. package/src/routes/data-set.ts +0 -84
  237. package/src/routes/data-set.yaml +0 -77
  238. package/src/routes/data-sync-changes.ts +0 -78
  239. package/src/routes/data-sync-changes.yaml +0 -67
  240. package/src/routes/data-sync-mutations.ts +0 -78
  241. package/src/routes/data-sync-mutations.yaml +0 -67
  242. package/src/routes/data-transaction-finish.yaml +0 -82
  243. package/src/routes/data-transaction-start.yaml +0 -58
  244. package/src/routes/data-transaction.ts +0 -168
  245. package/src/routes/data-update.ts +0 -85
  246. package/src/routes/data-update.yaml +0 -77
  247. package/src/routes/data.ts +0 -79
  248. package/src/routes/docs.ts +0 -249
  249. package/src/routes/meta-info.ts +0 -80
  250. package/src/routes/meta-info.yaml +0 -41
  251. package/src/routes/meta-logs.ts +0 -57
  252. package/src/routes/meta-ping.ts +0 -15
  253. package/src/routes/meta-ping.yaml +0 -23
  254. package/src/routes/meta-stats.ts +0 -31
  255. package/src/routes/meta-stats.yaml +0 -41
  256. package/src/routes/meta.ts +0 -22
  257. package/src/routes/oauth2-init.ts +0 -44
  258. package/src/routes/oauth2-init.yaml +0 -63
  259. package/src/routes/oauth2-refresh.ts +0 -39
  260. package/src/routes/oauth2-refresh.yaml +0 -65
  261. package/src/routes/oauth2-signin.ts +0 -286
  262. package/src/routes/oauth2-signin.yaml +0 -66
  263. package/src/routes/webmanager.ts +0 -29
  264. package/src/rules.ts +0 -196
  265. package/src/schema/user.ts +0 -99
  266. package/src/server.ts +0 -420
  267. package/src/settings/email.ts +0 -18
  268. package/src/settings/index.ts +0 -241
  269. package/src/shared/clients.ts +0 -31
  270. package/src/shared/email.ts +0 -33
  271. package/src/shared/env.ts +0 -39
  272. package/src/shared/error.ts +0 -37
  273. package/src/shared/http.ts +0 -26
  274. package/src/shared/password.ts +0 -41
  275. package/src/shared/rootpath.ts +0 -15
  276. package/src/shared/signin.ts +0 -149
  277. package/src/shared/simple-fetch.ts +0 -65
  278. package/src/shared/tokens.ts +0 -77
  279. package/src/shared/validate.ts +0 -53
  280. package/src/start.ts +0 -48
  281. package/src/test.ts +0 -10
  282. package/src/websocket/index.ts +0 -337
  283. package/src/websocket/manager.ts +0 -46
  284. package/src/websocket/socket.io.ts +0 -90
  285. package/tsconfig-cjs.json +0 -10
  286. package/tsconfig.json +0 -21
@@ -1,64 +0,0 @@
1
- /export/{dbname}/{path}:
2
- get:
3
- tags:
4
- - data
5
- summary: Export (stream) the value of a path
6
- description: Exports the value of a path in the database by streaming its content in a serialized format
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
- - name: path
16
- in: path
17
- description: database path
18
- required: true
19
- schema:
20
- type: string
21
- example: collection
22
- - name: format
23
- in: query
24
- description: desired output format. Only `json` is currently supported
25
- schema:
26
- type: string
27
- enum:
28
- - json
29
- example: json
30
- - name: type_safe
31
- in: query
32
- description: Whether to add type information for data that has no native JSON representation (such as dates, binary data etc)
33
- schema:
34
- type: string
35
- enum:
36
- - 0
37
- - 1
38
- example: 1
39
- responses:
40
- 200:
41
- description: Streams the data of requested path in the requested format. In the browser, this will trigger a file download.
42
- headers:
43
- 'Content-Disposition':
44
- description: Tells the browser to download the data as a file
45
- schema:
46
- type: string
47
- example: attachment; filename=[target_key].json
48
- content:
49
- 'text/plain':
50
- schema:
51
- type: object
52
- example: {"l27mgh8r000009mhh84jdp9c":{"name":"My todo list","stats":{"size":216,"created":{".type":"date",".val":"2022-04-07T15:11:42.000Z"},"modified":{".type":"date",".val":"2022-03-08T12:24:05.000Z"}}},"l27mhwz2000109mh11yi7rbo":{"name":"Another child"},"l27mjf9k000209mhafylc3eo":{"name":"And another.."}}
53
- 403:
54
- description: Returns a "403 Forbidden" if the signed in user is not allowed to read from the target path
55
- content:
56
- 'application/json':
57
- schema:
58
- $ref: '#/components/schemas/Error'
59
- 500:
60
- description: An unexpected error occurred
61
- content:
62
- 'application/json':
63
- schema:
64
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,68 +0,0 @@
1
- import { Transport } from 'acebase-core';
2
- import { SerializedValue } from 'acebase-core/types/transport';
3
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
4
- import { sendUnauthorizedError } from '../shared/error';
5
-
6
- export type RequestQuery = { include?: string; exclude?: string; child_objects?: boolean };
7
- export type RequestBody = null;
8
- export type ResponseBody = SerializedValue & { exists: boolean };
9
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
10
-
11
- export const addRoute = (env: RouteInitEnvironment) => {
12
-
13
- env.app.get(`/data/${env.db.name}/*`, async (req: Request, res) => {
14
- // Request data
15
- const path = req.path.slice(env.db.name.length + 7);
16
- const access = env.rules.userHasAccess(req.user, path, false);
17
- if (!access.allow) {
18
- return sendUnauthorizedError(res, access.code, access.message);
19
- }
20
-
21
- const options: { include?: string[]; exclude?: string[]; child_objects?: boolean } = {};
22
- if (req.query.include) {
23
- options.include = req.query.include.split(',');
24
- }
25
- if (req.query.exclude) {
26
- options.exclude = req.query.exclude.split(',');
27
- }
28
- if (typeof req.query.child_objects === 'boolean') {
29
- options.child_objects = req.query.child_objects;
30
- }
31
-
32
- if (path === '') {
33
- // If user has access to the root of database (NOT recommended for others than admin...)
34
- // Do not return private server data. If the admin user wants access, they should use
35
- // direct requests on those paths (GET /data/dbname/__auth__), or use reflection
36
-
37
- if (options.include) {
38
- // Remove all includes for private paths
39
- options.include = options.include.filter(path => !path.startsWith('__'));
40
- }
41
- // Add private paths to exclude
42
- options.exclude = [...options.exclude || [], '__auth__', '__log__'];
43
- }
44
-
45
- try {
46
- // const snap = await db.ref(path).get(options);
47
- // const value = snap.val(), context = snap.context();
48
- const { value, context } = await env.db.api.get(path, options);
49
- if (!env.config.transactions?.log) {
50
- delete context.acebase_cursor;
51
- }
52
- const serialized = Transport.serialize(value);
53
-
54
- res.setHeader('AceBase-Context', JSON.stringify(context));
55
- res.send({
56
- exists: value !== null,
57
- val: serialized.val,
58
- map: serialized.map
59
- });
60
- }
61
- catch (err) {
62
- res.status(500).send(err);
63
- }
64
- });
65
-
66
- };
67
-
68
- export default addRoute;
@@ -1,54 +0,0 @@
1
- /data/{dbname}/{path}:
2
- get:
3
- tags:
4
- - data
5
- summary: Get the value of a path
6
- description: Gets the stored value of a path 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
- - name: path
16
- in: path
17
- description: database path
18
- required: true
19
- schema:
20
- type: string
21
- example: collection/child/property
22
- responses:
23
- 200:
24
- description: Returns the serialized value of the target path, and whether it exists in the database
25
- content:
26
- 'application/json':
27
- schema:
28
- required:
29
- - val
30
- - exists
31
- allOf:
32
- - type: object
33
- properties:
34
- exists:
35
- type: boolean
36
- description: indicates if the path exists (when `false`, `val` property will be `null`)
37
- example: true
38
- - $ref: '#/components/schemas/SerializedValue'
39
- example:
40
- exists: true
41
- val: { name: 'My todo list', stats: { size: 216, created: '2022-04-07T15:11:42Z', modified: '2022-03-08T12:24:05Z' } }
42
- map: { 'stats/created': 'date', 'stats/modified': 'date' }
43
- 403:
44
- description: Returns a "403 Forbidden" if the signed in user is not allowed to read from the target path
45
- content:
46
- 'application/json':
47
- schema:
48
- $ref: '#/components/schemas/Error'
49
- 500:
50
- description: An unexpected error occurred
51
- content:
52
- 'application/json':
53
- schema:
54
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,56 +0,0 @@
1
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
2
- import { sendUnauthorizedError } from '../shared/error';
3
-
4
- export type RequestQuery = {
5
- format?: 'json';
6
- suppress_events?: '0'|'1'
7
- };
8
- export type RequestBody = null;
9
- export type ResponseBody = { success: boolean; reason?: string };
10
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
11
-
12
- export const addRoute = (env: RouteInitEnvironment) => {
13
-
14
- env.app.post(`/import/${env.db.name}/*`, async (req: Request, res) => {
15
- // Import API
16
- const path = req.path.slice(env.db.name.length + 9);
17
- const access = env.rules.userHasAccess(req.user, path, false);
18
- if (!access.allow) {
19
- return sendUnauthorizedError(res, access.code, access.message);
20
- }
21
- const format = req.query.format || 'json';
22
- const suppress_events = req.query.suppress_events === '1';
23
-
24
- req.pause(); // Switch to non-flowing mode so we can use .read() upon request
25
- let eof = false;
26
- req.once('end', () => { eof = true; });
27
- const read = async (length: number) => {
28
- let chunk = req.read();
29
- if (chunk === null && !eof) {
30
- await new Promise(resolve => req.once('readable', resolve));
31
- chunk = req.read();
32
- }
33
- // env.debug.verbose(`Received chunk: `, chunk);
34
- return chunk;
35
- };
36
-
37
- const ref = env.db.ref(path);
38
- try {
39
- await ref.import(read, { format, suppress_events });
40
- res.send({ success: true });
41
- }
42
- catch (err) {
43
- env.debug.error(`Error importing data for path "/${path}": `, err);
44
- if (!res.headersSent) {
45
- res.statusCode = 500;
46
- res.send({ success: false, reason: err.message });
47
- }
48
- }
49
- finally {
50
- res.end();
51
- }
52
- });
53
-
54
- };
55
-
56
- export default addRoute;
@@ -1,75 +0,0 @@
1
- /import/{dbname}/{path}:
2
- post:
3
- tags:
4
- - data
5
- summary: Import (stream) a new value for a path
6
- description: Imports (streams) the sent data for a path into the database (beta functionality, currently not very fast)
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
- - name: path
16
- in: path
17
- description: database path
18
- required: true
19
- schema:
20
- type: string
21
- example: collection
22
- - name: format
23
- in: query
24
- description: used data format. Only `json` is currently supported
25
- schema:
26
- type: string
27
- enum:
28
- - json
29
- example: json
30
- - name: suppress_events
31
- in: query
32
- description: Whether to suppress firing data change events during the import
33
- schema:
34
- type: string
35
- enum:
36
- - 0
37
- - 1
38
- example: 0
39
- requestBody:
40
- description: value to store in the database, can use typesafe values as exported by the _export_ endpoint
41
- content:
42
- 'text/plain':
43
- schema:
44
- type: object
45
- example: {"l27mgh8r000009mhh84jdp9c":{"name":"My todo list","stats":{"size":216,"created":{".type":"date",".val":"2022-04-07T15:11:42.000Z"},"modified":{".type":"date",".val":"2022-03-08T12:24:05.000Z"}}},"l27mhwz2000109mh11yi7rbo":{"name":"Another child"},"l27mjf9k000209mhafylc3eo":{"name":"And another.."}}
46
- responses:
47
- 200:
48
- description: Returns "200 OK" when the database operation succeeded
49
- content:
50
- 'application/json':
51
- schema:
52
- type: object
53
- properties:
54
- success:
55
- type: boolean
56
- example: true
57
- 403:
58
- description: Returns "403 Forbidden" if the signed in user is not allowed to write to the target path
59
- content:
60
- 'application/json':
61
- schema:
62
- $ref: '#/components/schemas/Error'
63
- 500:
64
- description: An error occurred
65
- content:
66
- 'application/json':
67
- schema:
68
- type: object
69
- properties:
70
- success:
71
- type: boolean
72
- example: false
73
- reason:
74
- type: string
75
- example: Something went wrong
@@ -1,82 +0,0 @@
1
- import adminOnly from '../middleware/admin-only';
2
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
- import { sendError } from '../shared/error';
4
- import { Response } from '../shared/http';
5
-
6
- export type FullTextIndexOptions = {
7
- type: 'fulltext';
8
- config?: {
9
- /** Callback function that transforms (and/or filters) words being indexed _and_ queried */
10
- transform?: (locale: string, word: string) => string;
11
- /** Also known as a stoplist. Array of words to automatically be ignored for indexing and querying. */
12
- blacklist?: string[];
13
- /** Words to be included if they did not match minLength and/or blacklist criteria */
14
- whitelist?: string[];
15
- /** Only use words with a minimum length */
16
- minLength?: number;
17
- /** Only use words with a maximum length */
18
- maxLength?: number;
19
- /** Specify a key in the data that contains the locale of the indexed texts. This allows multiple languages to be indexed using their own rules. */
20
- localeKey?: string;
21
- /** Boolean value that specifies whether a default stoplist for the used locale should be used to automatically blacklist words. Currently only available for locale "en", which contains very frequently used words like "a", "i", "me", "it", "the", "they", "them" etc. */
22
- useStoplist?: boolean;
23
- }
24
- };
25
- export type GeoIndexOptions = {
26
- type: 'geo';
27
- };
28
- export type ArrayIndexOptions = {
29
- type: 'array';
30
- };
31
-
32
- export type CreateIndexRequest = {
33
- path: string;
34
- key: string;
35
- options?: {
36
- type?: 'normal'|'array'|'fulltext'|'geo';
37
- rebuild?: boolean;
38
- textLocale?: string;
39
- include?: string[];
40
- config?: {}
41
- } & ({} | FullTextIndexOptions | GeoIndexOptions | ArrayIndexOptions);
42
- };
43
-
44
- export type RequestQuery = null;
45
- export type RequestBody = CreateIndexRequest;
46
- export type ResponseBody = { success: true } // 200
47
- | { code: 'admin_only'; message: string } // 403
48
- | { code: 'unexpected'; message: string }; // 500 (TODO check if 400 is also possible)
49
-
50
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
51
-
52
- export const addRoute = (env: RouteInitEnvironment) => {
53
-
54
- const handleRequest = async (req: Request, res: Response) => {
55
- try {
56
- const data = req.body;
57
- await env.db.indexes.create(data.path, data.key, data.options);
58
- res.contentType('application/json').send({ success: true });
59
- }
60
- catch(err) {
61
- env.debug.error(`failed to perform index action`, err);
62
- sendError(res, err);
63
- }
64
- };
65
-
66
- env.app.post(`/index/${env.db.name}`, adminOnly(env), async (req: RouteRequest<any, ResponseBody, RequestBody & { action: 'create'} >, res) => {
67
- // Legacy endpoint that was designed to handle multiple actions
68
- // The only action ever implemented was 'create', so we'll handle that here
69
- if (req.body?.action !== 'create') {
70
- return sendError(res, { code: 'invalid_action', message: 'Invalid action' });
71
- }
72
- handleRequest(req, res);
73
- });
74
-
75
- env.app.post(`/index/${env.db.name}/create`, adminOnly(env), async (req: Request, res) => {
76
- // New dedicated create endpoint
77
- handleRequest(req, res);
78
- });
79
-
80
- };
81
-
82
- export default addRoute;
@@ -1,105 +0,0 @@
1
- /index/{dbname}/create:
2
- post:
3
- tags:
4
- - data
5
- - indexes
6
- summary: Creates an index
7
- description: Creates a new index in the database if it does not exist already. (admin only)
8
- parameters:
9
- - name: dbname
10
- in: path
11
- description: name of the database
12
- required: true
13
- schema:
14
- type: string
15
- example: mydb
16
- requestBody:
17
- description: request
18
- content:
19
- 'application/json':
20
- schema:
21
- type: object
22
- properties:
23
- path:
24
- type: string
25
- description: path of the collection to index, can contain wildcards and variables such as * and $name
26
- example: books
27
- examples:
28
- simple:
29
- summary: Simple path
30
- value: books
31
- wildcard:
32
- summary: path with a wildcard to index scattered data
33
- value: users/*/reservations
34
- variable:
35
- summary: path with a variable (same as *) to index scattered data
36
- value: hotels/$id/reviews
37
- required: true
38
- key:
39
- type: string
40
- description: key (property) to index for each item in the collection, can contain a nested target path
41
- example: title
42
- examples:
43
- - title
44
- - text
45
- - content/title
46
- - content/stats/size
47
- required: true
48
- options:
49
- type: object
50
- description: Additional options
51
- properties:
52
- 'type':
53
- type: string
54
- enum:
55
- - normal
56
- - array
57
- - fulltext
58
- - geo
59
- description: type of index to create
60
- include:
61
- type: array
62
- items:
63
- type: string
64
- example:
65
- - year
66
- - rating
67
- description: Additional keys to include in the index. Speeds up sorting on these columns when the index is used (and dramatically increases query speed when .take(n) is used in addition)
68
- rebuild:
69
- type: boolean
70
- example: false
71
- description: Whether to rebuild the index if it exists already
72
- textLocale:
73
- type: string
74
- example: en-us
75
- description: If the indexed values are strings, which default locale to use
76
- config:
77
- type: object
78
- description: additional configuration for special indexes, see documentation
79
- properties:
80
- see_docs:
81
- description: See documentation for config options. Note that you can't create fulltext indexes with custom callack functions through the API; those need to be created in your code at the server.
82
- example: (See documentation for config options, many require server-side execution)
83
- responses:
84
- 200:
85
- description: returned when the index was created successfully
86
- content:
87
- 'application/json':
88
- schema:
89
- type: object
90
- properties:
91
- success:
92
- type: boolean
93
- example: true
94
- 403:
95
- description: Returns "403 Forbidden" if the signed in user is not admin
96
- content:
97
- 'application/json':
98
- schema:
99
- $ref: '#/components/schemas/Error'
100
- 500:
101
- description: An unexpected error occurred
102
- content:
103
- 'application/json':
104
- schema:
105
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,36 +0,0 @@
1
- import adminOnly from '../middleware/admin-only';
2
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
- import { sendError } from '../shared/error';
4
-
5
- export type RequestQuery = null;
6
- export type RequestBody = {
7
- fileName: string;
8
- };
9
- export type ResponseBody = { success: true } // 200
10
- | { code: 'admin_only'; message: string } // 403
11
- | { code: 'unexpected'; message: string }; // 500 (TODO check if 400 is also possible)
12
-
13
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
14
-
15
- export const addRoute = (env: RouteInitEnvironment) => {
16
-
17
- env.app.post(`/index/${env.db.name}/delete`, adminOnly(env), async (req: Request, res) => {
18
- // Delete an index
19
- try {
20
- const data = req.body;
21
- if (!data.fileName) {
22
- throw new Error('fileName not given');
23
- }
24
-
25
- await env.db.indexes.delete(data.fileName); // Requires newer acebase & acebase-core packages
26
- res.contentType('application/json').send({ success: true });
27
- }
28
- catch(err) {
29
- env.debug.error(`failed to perform index action`, err);
30
- sendError(res, err);
31
- }
32
- });
33
-
34
- };
35
-
36
- export default addRoute;
@@ -1,51 +0,0 @@
1
- /index/{dbname}/delete:
2
- post:
3
- tags:
4
- - data
5
- - indexes
6
- summary: Removes an index
7
- description: Removes an index from the database
8
- parameters:
9
- - name: dbname
10
- in: path
11
- description: name of the database
12
- required: true
13
- schema:
14
- type: string
15
- example: mydb
16
- requestBody:
17
- description: request
18
- content:
19
- 'application/json':
20
- schema:
21
- type: object
22
- properties:
23
- fileName:
24
- type: string
25
- description: The name of the target index file to delete
26
- required:
27
- - action
28
- - filePath
29
- responses:
30
- 200:
31
- description: Returned when the index is deleted successfully
32
- content:
33
- 'application/json':
34
- schema:
35
- type: object
36
- properties:
37
- success:
38
- type: boolean
39
- example: true
40
- 403:
41
- description: Returns "403 Forbidden" if the signed in user is not admin
42
- content:
43
- 'application/json':
44
- schema:
45
- $ref: '#/components/schemas/Error'
46
- 500:
47
- description: An unexpected error occurred
48
- content:
49
- 'application/json':
50
- schema:
51
- $ref: '#/components/schemas/UnexpectedError'
@@ -1,39 +0,0 @@
1
- import adminOnly from '../middleware/admin-only';
2
- import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
- import { sendError } from '../shared/error';
4
-
5
- export interface PublicDataIndex {
6
- path: string;
7
- key: string;
8
- caseSensitive: boolean;
9
- textLocale: string;
10
- includeKeys: string[];
11
- indexMetadataKeys: string[];
12
- type: "normal" | "array" | "fulltext" | "geo";
13
- fileName: string;
14
- description: string;
15
- };
16
- export type RequestQuery = null;
17
- export type RequestBody = null;
18
- export type ResponseBody = PublicDataIndex[] | { code: string; message: string };
19
- export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
20
-
21
- export const addRoute = (env: RouteInitEnvironment) => {
22
-
23
- env.app.get(`/index/${env.db.name}`, adminOnly(env), async (req: Request, res) => {
24
- // Get all indexes
25
- try {
26
- const indexes = await env.db.indexes.get();
27
- res.contentType('application/json').send(indexes.map(index => {
28
- const { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description } = index;
29
- return { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description };
30
- }));
31
- }
32
- catch (err) {
33
- sendError(res, err);
34
- }
35
- });
36
-
37
- };
38
-
39
- export default addRoute;