acebase-server 1.11.0 → 1.13.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.
- package/.vscode/launch.json +24 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/logger.js +74 -0
- package/dist/cjs/middleware/admin-only.js +29 -0
- package/dist/cjs/middleware/user.js +4 -4
- package/dist/cjs/routes/auth-change-password.js +7 -4
- package/dist/cjs/routes/auth-delete.js +9 -7
- package/dist/cjs/routes/auth-forgot-password.js +9 -6
- package/dist/cjs/routes/auth-reset-password.js +5 -3
- package/dist/cjs/routes/auth-signout.js +6 -4
- package/dist/cjs/routes/auth-signup.js +17 -15
- package/dist/cjs/routes/auth-update.js +9 -6
- package/dist/cjs/routes/auth-verify-email.js +6 -3
- package/dist/cjs/routes/data-index-create.js +3 -5
- package/dist/cjs/routes/data-index-delete.js +2 -4
- package/dist/cjs/routes/data-index-list.js +2 -4
- package/dist/cjs/routes/data-reflect.js +2 -4
- package/dist/cjs/routes/data-schema-get.js +2 -4
- package/dist/cjs/routes/data-schema-set.js +2 -4
- package/dist/cjs/routes/data-schema-test.js +2 -4
- package/dist/cjs/routes/data-schemas-list.js +2 -4
- package/dist/cjs/routes/data-set.js +8 -7
- package/dist/cjs/routes/data-transaction.js +15 -8
- package/dist/cjs/routes/data-update.js +8 -6
- package/dist/cjs/routes/meta-logs.js +50 -0
- package/dist/cjs/routes/meta.js +3 -0
- package/dist/cjs/routes/oauth2-signin.js +9 -6
- package/dist/cjs/server.js +3 -1
- package/dist/cjs/shared/rootpath.js +2 -0
- package/dist/cjs/shared/signin.js +8 -3
- package/dist/cjs/start.js +3 -0
- package/dist/cjs/websocket/index.js +42 -23
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/logger.js +52 -0
- package/dist/esm/middleware/admin-only.js +25 -0
- package/dist/esm/middleware/user.js +4 -4
- package/dist/esm/routes/auth-change-password.js +6 -3
- package/dist/esm/routes/auth-delete.js +7 -5
- package/dist/esm/routes/auth-forgot-password.js +8 -6
- package/dist/esm/routes/auth-reset-password.js +4 -2
- package/dist/esm/routes/auth-signout.js +4 -2
- package/dist/esm/routes/auth-signup.js +12 -10
- package/dist/esm/routes/auth-update.js +8 -6
- package/dist/esm/routes/auth-verify-email.js +6 -2
- package/dist/esm/routes/data-index-create.js +4 -6
- package/dist/esm/routes/data-index-delete.js +3 -5
- package/dist/esm/routes/data-index-list.js +3 -5
- package/dist/esm/routes/data-reflect.js +1 -4
- package/dist/esm/routes/data-schema-get.js +3 -5
- package/dist/esm/routes/data-schema-set.js +3 -5
- package/dist/esm/routes/data-schema-test.js +3 -5
- package/dist/esm/routes/data-schemas-list.js +3 -5
- package/dist/esm/routes/data-set.js +6 -5
- package/dist/esm/routes/data-transaction.js +12 -5
- package/dist/esm/routes/data-update.js +6 -4
- package/dist/esm/routes/meta-logs.js +36 -0
- package/dist/esm/routes/meta.js +3 -0
- package/dist/esm/routes/oauth2-signin.js +8 -5
- package/dist/esm/server.js +3 -1
- package/dist/esm/shared/rootpath.js +2 -0
- package/dist/esm/shared/signin.js +7 -3
- package/dist/esm/start.js +3 -0
- package/dist/esm/websocket/index.js +37 -22
- package/dist/types/logger.d.ts +35 -0
- package/dist/types/middleware/admin-only.d.ts +19 -0
- package/dist/types/routes/meta-logs.d.ts +20 -0
- package/dist/types/rules.d.ts +2 -2
- package/dist/types/shared/env.d.ts +3 -1
- package/dist/types/shared/signin.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +4 -0
- package/package.json +5 -5
- package/webmanager/acebase-client-browser.min.js +16 -16
- package/create-package-files +0 -12
- package/dist/cjs/auth.js.map +0 -1
- package/dist/cjs/cluster.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/middleware/404.js.map +0 -1
- package/dist/cjs/middleware/cache.js.map +0 -1
- package/dist/cjs/middleware/connection.js.map +0 -1
- package/dist/cjs/middleware/context.js.map +0 -1
- package/dist/cjs/middleware/cors.js.map +0 -1
- package/dist/cjs/middleware/swagger.js.map +0 -1
- package/dist/cjs/middleware/user.js.map +0 -1
- package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
- package/dist/cjs/oauth-providers/facebook.js.map +0 -1
- package/dist/cjs/oauth-providers/google.js.map +0 -1
- package/dist/cjs/oauth-providers/index.js.map +0 -1
- package/dist/cjs/oauth-providers/instagram.js.map +0 -1
- package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
- package/dist/cjs/oauth-providers/spotify.js.map +0 -1
- package/dist/cjs/routes/auth-change-password.js.map +0 -1
- package/dist/cjs/routes/auth-delete.js.map +0 -1
- package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
- package/dist/cjs/routes/auth-reset-password.js.map +0 -1
- package/dist/cjs/routes/auth-signin.js.map +0 -1
- package/dist/cjs/routes/auth-signout.js.map +0 -1
- package/dist/cjs/routes/auth-signup.js.map +0 -1
- package/dist/cjs/routes/auth-state.js.map +0 -1
- package/dist/cjs/routes/auth-update.js.map +0 -1
- package/dist/cjs/routes/auth-verify-email.js.map +0 -1
- package/dist/cjs/routes/auth.js.map +0 -1
- package/dist/cjs/routes/data-exists.js.map +0 -1
- package/dist/cjs/routes/data-export.js.map +0 -1
- package/dist/cjs/routes/data-get.js.map +0 -1
- package/dist/cjs/routes/data-import.js.map +0 -1
- package/dist/cjs/routes/data-index-create.js.map +0 -1
- package/dist/cjs/routes/data-index-delete.js.map +0 -1
- package/dist/cjs/routes/data-index-list.js.map +0 -1
- package/dist/cjs/routes/data-query.js.map +0 -1
- package/dist/cjs/routes/data-reflect.js.map +0 -1
- package/dist/cjs/routes/data-schema-get.js.map +0 -1
- package/dist/cjs/routes/data-schema-set.js.map +0 -1
- package/dist/cjs/routes/data-schema-test.js.map +0 -1
- package/dist/cjs/routes/data-schemas-list.js.map +0 -1
- package/dist/cjs/routes/data-set.js.map +0 -1
- package/dist/cjs/routes/data-sync-changes.js.map +0 -1
- package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
- package/dist/cjs/routes/data-transaction.js.map +0 -1
- package/dist/cjs/routes/data-update.js.map +0 -1
- package/dist/cjs/routes/data.js.map +0 -1
- package/dist/cjs/routes/docs.js.map +0 -1
- package/dist/cjs/routes/meta-info.js.map +0 -1
- package/dist/cjs/routes/meta-ping.js.map +0 -1
- package/dist/cjs/routes/meta-stats.js.map +0 -1
- package/dist/cjs/routes/meta.js.map +0 -1
- package/dist/cjs/routes/oauth2-init.js.map +0 -1
- package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
- package/dist/cjs/routes/oauth2-signin.js.map +0 -1
- package/dist/cjs/routes/webmanager.js.map +0 -1
- package/dist/cjs/rules.js.map +0 -1
- package/dist/cjs/schema/user.js.map +0 -1
- package/dist/cjs/server.js.map +0 -1
- package/dist/cjs/settings/email.js.map +0 -1
- package/dist/cjs/settings/index.js.map +0 -1
- package/dist/cjs/shared/clients.js.map +0 -1
- package/dist/cjs/shared/email.js.map +0 -1
- package/dist/cjs/shared/env.js.map +0 -1
- package/dist/cjs/shared/error.js.map +0 -1
- package/dist/cjs/shared/http.js.map +0 -1
- package/dist/cjs/shared/password.js.map +0 -1
- package/dist/cjs/shared/rootpath.js.map +0 -1
- package/dist/cjs/shared/signin.js.map +0 -1
- package/dist/cjs/shared/simple-fetch.js.map +0 -1
- package/dist/cjs/shared/tokens.js.map +0 -1
- package/dist/cjs/shared/validate.js.map +0 -1
- package/dist/cjs/start.js.map +0 -1
- package/dist/cjs/test.js.map +0 -1
- package/dist/cjs/websocket/index.js.map +0 -1
- package/dist/cjs/websocket/manager.js.map +0 -1
- package/dist/cjs/websocket/socket.io.js.map +0 -1
- package/dist/esm/auth.js.map +0 -1
- package/dist/esm/cluster.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/middleware/404.js.map +0 -1
- package/dist/esm/middleware/cache.js.map +0 -1
- package/dist/esm/middleware/connection.js.map +0 -1
- package/dist/esm/middleware/context.js.map +0 -1
- package/dist/esm/middleware/cors.js.map +0 -1
- package/dist/esm/middleware/swagger.js.map +0 -1
- package/dist/esm/middleware/user.js.map +0 -1
- package/dist/esm/oauth-providers/dropbox.js.map +0 -1
- package/dist/esm/oauth-providers/facebook.js.map +0 -1
- package/dist/esm/oauth-providers/google.js.map +0 -1
- package/dist/esm/oauth-providers/index.js.map +0 -1
- package/dist/esm/oauth-providers/instagram.js.map +0 -1
- package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
- package/dist/esm/oauth-providers/spotify.js.map +0 -1
- package/dist/esm/routes/auth-change-password.js.map +0 -1
- package/dist/esm/routes/auth-delete.js.map +0 -1
- package/dist/esm/routes/auth-forgot-password.js.map +0 -1
- package/dist/esm/routes/auth-reset-password.js.map +0 -1
- package/dist/esm/routes/auth-signin.js.map +0 -1
- package/dist/esm/routes/auth-signout.js.map +0 -1
- package/dist/esm/routes/auth-signup.js.map +0 -1
- package/dist/esm/routes/auth-state.js.map +0 -1
- package/dist/esm/routes/auth-update.js.map +0 -1
- package/dist/esm/routes/auth-verify-email.js.map +0 -1
- package/dist/esm/routes/auth.js.map +0 -1
- package/dist/esm/routes/data-exists.js.map +0 -1
- package/dist/esm/routes/data-export.js.map +0 -1
- package/dist/esm/routes/data-get.js.map +0 -1
- package/dist/esm/routes/data-import.js.map +0 -1
- package/dist/esm/routes/data-index-create.js.map +0 -1
- package/dist/esm/routes/data-index-delete.js.map +0 -1
- package/dist/esm/routes/data-index-list.js.map +0 -1
- package/dist/esm/routes/data-query.js.map +0 -1
- package/dist/esm/routes/data-reflect.js.map +0 -1
- package/dist/esm/routes/data-schema-get.js.map +0 -1
- package/dist/esm/routes/data-schema-set.js.map +0 -1
- package/dist/esm/routes/data-schema-test.js.map +0 -1
- package/dist/esm/routes/data-schemas-list.js.map +0 -1
- package/dist/esm/routes/data-set.js.map +0 -1
- package/dist/esm/routes/data-sync-changes.js.map +0 -1
- package/dist/esm/routes/data-sync-mutations.js.map +0 -1
- package/dist/esm/routes/data-transaction.js.map +0 -1
- package/dist/esm/routes/data-update.js.map +0 -1
- package/dist/esm/routes/data.js.map +0 -1
- package/dist/esm/routes/docs.js.map +0 -1
- package/dist/esm/routes/meta-info.js.map +0 -1
- package/dist/esm/routes/meta-ping.js.map +0 -1
- package/dist/esm/routes/meta-stats.js.map +0 -1
- package/dist/esm/routes/meta.js.map +0 -1
- package/dist/esm/routes/oauth2-init.js.map +0 -1
- package/dist/esm/routes/oauth2-refresh.js.map +0 -1
- package/dist/esm/routes/oauth2-signin.js.map +0 -1
- package/dist/esm/routes/webmanager.js.map +0 -1
- package/dist/esm/rules.js.map +0 -1
- package/dist/esm/schema/user.js.map +0 -1
- package/dist/esm/server.js.map +0 -1
- package/dist/esm/settings/email.js.map +0 -1
- package/dist/esm/settings/index.js.map +0 -1
- package/dist/esm/shared/clients.js.map +0 -1
- package/dist/esm/shared/email.js.map +0 -1
- package/dist/esm/shared/env.js.map +0 -1
- package/dist/esm/shared/error.js.map +0 -1
- package/dist/esm/shared/http.js.map +0 -1
- package/dist/esm/shared/password.js.map +0 -1
- package/dist/esm/shared/rootpath.js.map +0 -1
- package/dist/esm/shared/signin.js.map +0 -1
- package/dist/esm/shared/simple-fetch.js.map +0 -1
- package/dist/esm/shared/tokens.js.map +0 -1
- package/dist/esm/shared/validate.js.map +0 -1
- package/dist/esm/start.js.map +0 -1
- package/dist/esm/test.js.map +0 -1
- package/dist/esm/websocket/index.js.map +0 -1
- package/dist/esm/websocket/manager.js.map +0 -1
- package/dist/esm/websocket/socket.io.js.map +0 -1
- package/src/auth.ts +0 -87
- package/src/cluster.ts +0 -62
- package/src/index.ts +0 -4
- package/src/middleware/404.ts +0 -13
- package/src/middleware/cache.ts +0 -15
- package/src/middleware/connection.ts +0 -48
- package/src/middleware/context.ts +0 -23
- package/src/middleware/cors.ts +0 -49
- package/src/middleware/swagger.ts +0 -19
- package/src/middleware/user.ts +0 -51
- package/src/oauth-providers/dropbox.ts +0 -144
- package/src/oauth-providers/facebook.ts +0 -103
- package/src/oauth-providers/google.ts +0 -147
- package/src/oauth-providers/index.ts +0 -21
- package/src/oauth-providers/instagram.ts +0 -98
- package/src/oauth-providers/oauth-provider.ts +0 -65
- package/src/oauth-providers/spotify.ts +0 -127
- package/src/placeholder.d.ts +0 -12
- package/src/routes/auth-change-password.ts +0 -89
- package/src/routes/auth-change-password.yaml +0 -74
- package/src/routes/auth-delete.ts +0 -47
- package/src/routes/auth-delete.yaml +0 -78
- package/src/routes/auth-forgot-password.ts +0 -73
- package/src/routes/auth-forgot-password.yaml +0 -50
- package/src/routes/auth-reset-password.ts +0 -93
- package/src/routes/auth-reset-password.yaml +0 -54
- package/src/routes/auth-signin.ts +0 -55
- package/src/routes/auth-signin.yaml +0 -130
- package/src/routes/auth-signout.ts +0 -61
- package/src/routes/auth-signout.yaml +0 -46
- package/src/routes/auth-signup.ts +0 -161
- package/src/routes/auth-signup.yaml +0 -136
- package/src/routes/auth-state.ts +0 -20
- package/src/routes/auth-state.yaml +0 -29
- package/src/routes/auth-update.ts +0 -147
- package/src/routes/auth-update.yaml +0 -152
- package/src/routes/auth-verify-email.ts +0 -67
- package/src/routes/auth-verify-email.yaml +0 -53
- package/src/routes/auth.ts +0 -67
- package/src/routes/data-exists.ts +0 -31
- package/src/routes/data-exists.yaml +0 -44
- package/src/routes/data-export.ts +0 -51
- package/src/routes/data-export.yaml +0 -64
- package/src/routes/data-get.ts +0 -68
- package/src/routes/data-get.yaml +0 -54
- package/src/routes/data-import.ts +0 -56
- package/src/routes/data-import.yaml +0 -75
- package/src/routes/data-index-create.ts +0 -85
- package/src/routes/data-index-create.yaml +0 -105
- package/src/routes/data-index-delete.ts +0 -39
- package/src/routes/data-index-delete.yaml +0 -51
- package/src/routes/data-index-list.ts +0 -42
- package/src/routes/data-index-list.yaml +0 -80
- package/src/routes/data-query.ts +0 -97
- package/src/routes/data-query.yaml +0 -166
- package/src/routes/data-reflect.ts +0 -94
- package/src/routes/data-reflect.yaml +0 -124
- package/src/routes/data-schema-get.ts +0 -38
- package/src/routes/data-schema-get.yaml +0 -53
- package/src/routes/data-schema-set.ts +0 -38
- package/src/routes/data-schema-set.yaml +0 -60
- package/src/routes/data-schema-test.ts +0 -53
- package/src/routes/data-schema-test.yaml +0 -66
- package/src/routes/data-schemas-list.ts +0 -33
- package/src/routes/data-schemas-list.yaml +0 -41
- package/src/routes/data-set.ts +0 -80
- package/src/routes/data-set.yaml +0 -77
- package/src/routes/data-sync-changes.ts +0 -78
- package/src/routes/data-sync-changes.yaml +0 -67
- package/src/routes/data-sync-mutations.ts +0 -78
- package/src/routes/data-sync-mutations.yaml +0 -67
- package/src/routes/data-transaction-finish.yaml +0 -82
- package/src/routes/data-transaction-start.yaml +0 -58
- package/src/routes/data-transaction.ts +0 -159
- package/src/routes/data-update.ts +0 -81
- package/src/routes/data-update.yaml +0 -77
- package/src/routes/data.ts +0 -79
- package/src/routes/docs.ts +0 -249
- package/src/routes/meta-info.ts +0 -80
- package/src/routes/meta-info.yaml +0 -41
- package/src/routes/meta-ping.ts +0 -15
- package/src/routes/meta-ping.yaml +0 -23
- package/src/routes/meta-stats.ts +0 -31
- package/src/routes/meta-stats.yaml +0 -41
- package/src/routes/meta.ts +0 -18
- package/src/routes/oauth2-init.ts +0 -44
- package/src/routes/oauth2-init.yaml +0 -63
- package/src/routes/oauth2-refresh.ts +0 -39
- package/src/routes/oauth2-refresh.yaml +0 -65
- package/src/routes/oauth2-signin.ts +0 -282
- package/src/routes/oauth2-signin.yaml +0 -66
- package/src/routes/webmanager.ts +0 -29
- package/src/rules.ts +0 -196
- package/src/schema/user.ts +0 -99
- package/src/server.ts +0 -418
- package/src/settings/email.ts +0 -18
- package/src/settings/index.ts +0 -241
- package/src/shared/clients.ts +0 -31
- package/src/shared/email.ts +0 -33
- package/src/shared/env.ts +0 -38
- package/src/shared/error.ts +0 -37
- package/src/shared/http.ts +0 -26
- package/src/shared/password.ts +0 -41
- package/src/shared/rootpath.ts +0 -15
- package/src/shared/signin.ts +0 -143
- package/src/shared/simple-fetch.ts +0 -65
- package/src/shared/tokens.ts +0 -77
- package/src/shared/validate.ts +0 -53
- package/src/start.ts +0 -45
- package/src/test.ts +0 -10
- package/src/websocket/index.ts +0 -320
- package/src/websocket/manager.ts +0 -46
- package/src/websocket/socket.io.ts +0 -90
- package/tsconfig-cjs.json +0 -10
- 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'
|
package/src/routes/data-get.ts
DELETED
|
@@ -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;
|
package/src/routes/data-get.yaml
DELETED
|
@@ -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,85 +0,0 @@
|
|
|
1
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
-
import { sendError, sendUnauthorizedError } from '../shared/error';
|
|
3
|
-
import { Response } from '../shared/http';
|
|
4
|
-
|
|
5
|
-
export type FullTextIndexOptions = {
|
|
6
|
-
type: 'fulltext';
|
|
7
|
-
config?: {
|
|
8
|
-
/** Callback function that transforms (and/or filters) words being indexed _and_ queried */
|
|
9
|
-
transform?: (locale: string, word: string) => string;
|
|
10
|
-
/** Also known as a stoplist. Array of words to automatically be ignored for indexing and querying. */
|
|
11
|
-
blacklist?: string[];
|
|
12
|
-
/** Words to be included if they did not match minLength and/or blacklist criteria */
|
|
13
|
-
whitelist?: string[];
|
|
14
|
-
/** Only use words with a minimum length */
|
|
15
|
-
minLength?: number;
|
|
16
|
-
/** Only use words with a maximum length */
|
|
17
|
-
maxLength?: number;
|
|
18
|
-
/** 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. */
|
|
19
|
-
localeKey?: string;
|
|
20
|
-
/** 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. */
|
|
21
|
-
useStoplist?: boolean;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
export type GeoIndexOptions = {
|
|
25
|
-
type: 'geo';
|
|
26
|
-
};
|
|
27
|
-
export type ArrayIndexOptions = {
|
|
28
|
-
type: 'array';
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type CreateIndexRequest = {
|
|
32
|
-
path: string;
|
|
33
|
-
key: string;
|
|
34
|
-
options?: {
|
|
35
|
-
type?: 'normal'|'array'|'fulltext'|'geo';
|
|
36
|
-
rebuild?: boolean;
|
|
37
|
-
textLocale?: string;
|
|
38
|
-
include?: string[];
|
|
39
|
-
config?: {}
|
|
40
|
-
} & ({} | FullTextIndexOptions | GeoIndexOptions | ArrayIndexOptions);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type RequestQuery = null;
|
|
44
|
-
export type RequestBody = CreateIndexRequest;
|
|
45
|
-
export type ResponseBody = { success: true } // 200
|
|
46
|
-
| { code: 'admin_only'; message: string } // 403
|
|
47
|
-
| { code: 'unexpected'; message: string }; // 500 (TODO check if 400 is also possible)
|
|
48
|
-
|
|
49
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
50
|
-
|
|
51
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
52
|
-
|
|
53
|
-
const handleRequest = async (req: Request, res: Response) => {
|
|
54
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
55
|
-
return sendUnauthorizedError(res, 'admin_only', 'only admin can perform index operations');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const data = req.body;
|
|
60
|
-
await env.db.indexes.create(data.path, data.key, data.options);
|
|
61
|
-
res.contentType('application/json').send({ success: true });
|
|
62
|
-
}
|
|
63
|
-
catch(err) {
|
|
64
|
-
env.debug.error(`failed to perform index action`, err);
|
|
65
|
-
sendError(res, err);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
env.app.post(`/index/${env.db.name}`, async (req: RouteRequest<any, ResponseBody, RequestBody & { action: 'create'} >, res) => {
|
|
70
|
-
// Legacy endpoint that was designed to handle multiple actions
|
|
71
|
-
// The only action ever implemented was 'create', so we'll handle that here
|
|
72
|
-
if (req.body?.action !== 'create') {
|
|
73
|
-
return sendError(res, { code: 'invalid_action', message: 'Invalid action' });
|
|
74
|
-
}
|
|
75
|
-
handleRequest(req, res);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
env.app.post(`/index/${env.db.name}/create`, async (req: Request, res) => {
|
|
79
|
-
// New dedicated create endpoint
|
|
80
|
-
handleRequest(req, res);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
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,39 +0,0 @@
|
|
|
1
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
-
import { sendError, sendUnauthorizedError } from '../shared/error';
|
|
3
|
-
|
|
4
|
-
export type RequestQuery = null;
|
|
5
|
-
export type RequestBody = {
|
|
6
|
-
fileName: string;
|
|
7
|
-
};
|
|
8
|
-
export type ResponseBody = { success: true } // 200
|
|
9
|
-
| { code: 'admin_only'; message: string } // 403
|
|
10
|
-
| { code: 'unexpected'; message: string }; // 500 (TODO check if 400 is also possible)
|
|
11
|
-
|
|
12
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
13
|
-
|
|
14
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
15
|
-
|
|
16
|
-
env.app.post(`/index/${env.db.name}/delete`, async (req: Request, res) => {
|
|
17
|
-
// Delete an index
|
|
18
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
19
|
-
return sendUnauthorizedError(res, 'admin_only', 'only admin can perform index operations');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const data = req.body;
|
|
24
|
-
if (!data.fileName) {
|
|
25
|
-
throw new Error('fileName not given');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await env.db.indexes.delete(data.fileName); // Requires newer acebase & acebase-core packages
|
|
29
|
-
res.contentType('application/json').send({ success: true });
|
|
30
|
-
}
|
|
31
|
-
catch(err) {
|
|
32
|
-
env.debug.error(`failed to perform index action`, err);
|
|
33
|
-
sendError(res, err);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
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,42 +0,0 @@
|
|
|
1
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
-
import { sendError, sendUnauthorizedError } from '../shared/error';
|
|
3
|
-
|
|
4
|
-
export interface PublicDataIndex {
|
|
5
|
-
path: string;
|
|
6
|
-
key: string;
|
|
7
|
-
caseSensitive: boolean;
|
|
8
|
-
textLocale: string;
|
|
9
|
-
includeKeys: string[];
|
|
10
|
-
indexMetadataKeys: string[];
|
|
11
|
-
type: "normal" | "array" | "fulltext" | "geo";
|
|
12
|
-
fileName: string;
|
|
13
|
-
description: string;
|
|
14
|
-
};
|
|
15
|
-
export type RequestQuery = null;
|
|
16
|
-
export type RequestBody = null;
|
|
17
|
-
export type ResponseBody = PublicDataIndex[] | { code: string; message: string };
|
|
18
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
-
|
|
20
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
-
|
|
22
|
-
env.app.get(`/index/${env.db.name}`, async (req: Request, res) => {
|
|
23
|
-
// Get all indexes
|
|
24
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
25
|
-
return sendUnauthorizedError(res, 'admin_only', 'only admin can perform index operations');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const indexes = await env.db.indexes.get();
|
|
30
|
-
res.contentType('application/json').send(indexes.map(index => {
|
|
31
|
-
const { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description } = index;
|
|
32
|
-
return { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description };
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
sendError(res, err);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default addRoute;
|