acebase-server 1.10.1 → 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.
- package/.vscode/launch.json +24 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +16 -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/oauth-providers/dropbox.js +3 -2
- package/dist/cjs/oauth-providers/facebook.js +3 -2
- package/dist/cjs/oauth-providers/google.js +3 -2
- package/dist/cjs/oauth-providers/instagram.js +3 -2
- package/dist/cjs/oauth-providers/oauth-provider.js +23 -0
- package/dist/cjs/oauth-providers/spotify.js +3 -2
- 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 +11 -7
- package/dist/cjs/routes/data-transaction.js +30 -10
- package/dist/cjs/routes/data-update.js +11 -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 +15 -11
- package/dist/cjs/rules.js +5 -5
- package/dist/cjs/server.js +6 -4
- package/dist/cjs/settings/index.js +6 -7
- 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 +43 -24
- package/dist/cjs/websocket/socket.io.js +8 -11
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -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/oauth-providers/dropbox.js +3 -2
- package/dist/esm/oauth-providers/facebook.js +3 -2
- package/dist/esm/oauth-providers/google.js +3 -2
- package/dist/esm/oauth-providers/instagram.js +3 -2
- package/dist/esm/oauth-providers/oauth-provider.js +21 -1
- package/dist/esm/oauth-providers/spotify.js +3 -2
- 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 +9 -5
- package/dist/esm/routes/data-transaction.js +28 -8
- package/dist/esm/routes/data-update.js +9 -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 +14 -10
- package/dist/esm/rules.js +5 -5
- package/dist/esm/server.js +6 -4
- package/dist/esm/settings/index.js +5 -6
- 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 +38 -23
- package/dist/esm/websocket/socket.io.js +9 -11
- package/dist/types/index.d.ts +2 -0
- package/dist/types/logger.d.ts +35 -0
- package/dist/types/middleware/admin-only.d.ts +19 -0
- package/dist/types/oauth-providers/dropbox.d.ts +3 -14
- package/dist/types/oauth-providers/facebook.d.ts +3 -7
- package/dist/types/oauth-providers/google.d.ts +3 -7
- package/dist/types/oauth-providers/index.d.ts +2 -10
- package/dist/types/oauth-providers/instagram.d.ts +3 -7
- package/dist/types/oauth-providers/oauth-provider.d.ts +25 -21
- package/dist/types/oauth-providers/spotify.d.ts +3 -7
- package/dist/types/routes/data-query.d.ts +1 -1
- package/dist/types/routes/meta-logs.d.ts +20 -0
- package/dist/types/rules.d.ts +4 -4
- package/dist/types/server.d.ts +9 -7
- package/dist/types/settings/email.d.ts +1 -1
- package/dist/types/settings/index.d.ts +5 -6
- package/dist/types/shared/clients.d.ts +3 -1
- package/dist/types/shared/env.d.ts +6 -4
- package/dist/types/shared/http.d.ts +2 -0
- package/dist/types/shared/signin.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +4 -0
- package/dist/types/websocket/manager.d.ts +1 -1
- package/package.json +8 -8
- package/webmanager/acebase-client-browser.min.js +16 -0
- package/webmanager/index.html +2 -2
- package/webmanager/index.js +3 -6
- 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 -2
- 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 -143
- package/src/oauth-providers/facebook.ts +0 -102
- package/src/oauth-providers/google.ts +0 -146
- package/src/oauth-providers/index.ts +0 -20
- package/src/oauth-providers/instagram.ts +0 -97
- package/src/oauth-providers/oauth-provider.ts +0 -55
- package/src/oauth-providers/spotify.ts +0 -126
- 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 -76
- package/src/routes/data-set.yaml +0 -71
- 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 -76
- package/src/routes/data-transaction-start.yaml +0 -58
- package/src/routes/data-transaction.ts +0 -144
- package/src/routes/data-update.ts +0 -77
- package/src/routes/data-update.yaml +0 -71
- 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 -281
- 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 -416
- package/src/settings/email.ts +0 -18
- package/src/settings/index.ts +0 -240
- 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 -24
- 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 -91
- package/tsconfig-cjs.json +0 -10
- package/tsconfig.json +0 -21
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/schema/{dbname}:
|
|
2
|
-
post:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- schemas
|
|
6
|
-
summary: Add a schema definition
|
|
7
|
-
description: Adds a schema definition to the specified path. This schema will be enabled while the server runs, and cleared upon restart. If you need the schema to be persisted, add it to your server's rules.json file
|
|
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: details about the data and schema to test
|
|
18
|
-
content:
|
|
19
|
-
'application/json':
|
|
20
|
-
schema:
|
|
21
|
-
type: object
|
|
22
|
-
properties:
|
|
23
|
-
action:
|
|
24
|
-
type: string
|
|
25
|
-
description: The desired operation `'set'` (optional, deprecated since v1.10.0)
|
|
26
|
-
example: set
|
|
27
|
-
path:
|
|
28
|
-
type: string
|
|
29
|
-
description: database path to the given value
|
|
30
|
-
example: collection/item
|
|
31
|
-
schema:
|
|
32
|
-
type: string
|
|
33
|
-
description: When given, tests this schema definition against the passed value instead of ones defined in the database
|
|
34
|
-
example: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
35
|
-
required:
|
|
36
|
-
- path
|
|
37
|
-
- schema
|
|
38
|
-
responses:
|
|
39
|
-
200:
|
|
40
|
-
description: Returns "200 OK" if the schema was added successfully
|
|
41
|
-
content:
|
|
42
|
-
'application/json':
|
|
43
|
-
schema:
|
|
44
|
-
type: object
|
|
45
|
-
properties:
|
|
46
|
-
success:
|
|
47
|
-
type: boolean
|
|
48
|
-
example: true
|
|
49
|
-
403:
|
|
50
|
-
description: Returns a "403 Forbidden" if the signed in user is not admin
|
|
51
|
-
content:
|
|
52
|
-
'application/json':
|
|
53
|
-
schema:
|
|
54
|
-
$ref: '#/components/schemas/Error'
|
|
55
|
-
500:
|
|
56
|
-
description: An error occurred
|
|
57
|
-
content:
|
|
58
|
-
'application/json':
|
|
59
|
-
schema:
|
|
60
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ISchemaCheckResult, SchemaDefinition, Transport } from 'acebase-core';
|
|
2
|
-
import type { IAceBaseSchemaInfo } from 'acebase-core/src/api';
|
|
3
|
-
import type { SerializedValue } from 'acebase-core/types/transport';
|
|
4
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
5
|
-
import { sendError, sendUnauthorizedError } from '../shared/error';
|
|
6
|
-
|
|
7
|
-
export type RequestQuery = null;
|
|
8
|
-
export type RequestBody = {
|
|
9
|
-
value: SerializedValue;
|
|
10
|
-
partial: boolean;
|
|
11
|
-
path?: string;
|
|
12
|
-
schema?: IAceBaseSchemaInfo
|
|
13
|
-
};
|
|
14
|
-
export type ResponseBody = ISchemaCheckResult // 200
|
|
15
|
-
| { code: 'admin_only'; message: string } // 403
|
|
16
|
-
| { code: 'unexpected'; message: string }; // 500
|
|
17
|
-
|
|
18
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
-
|
|
20
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
-
|
|
22
|
-
env.app.post(`/schema/${env.db.name}/test`, async (req: Request, res) => {
|
|
23
|
-
// tests a schema
|
|
24
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
25
|
-
return sendUnauthorizedError(res, 'admin_only', 'only admin can perform schema operations');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const data = req.body;
|
|
30
|
-
if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
|
|
31
|
-
return sendError(res, { code: 'invalid_serialized_value', message: 'The sent value is not properly serialized' });
|
|
32
|
-
}
|
|
33
|
-
const value = Transport.deserialize(data.value);
|
|
34
|
-
const { path, schema, partial } = data;
|
|
35
|
-
let result: ISchemaCheckResult;
|
|
36
|
-
if (schema) {
|
|
37
|
-
const definition = new SchemaDefinition(schema);
|
|
38
|
-
result = definition.check(path, value, partial);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
result = await env.db.schema.check(path, schema, partial);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
res.contentType('application/json').send(result);
|
|
45
|
-
}
|
|
46
|
-
catch(err) {
|
|
47
|
-
sendError(res, err);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export default addRoute;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/schema/{dbname}/test:
|
|
2
|
-
post:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- schemas
|
|
6
|
-
summary: Test a data schema
|
|
7
|
-
description: Tests an existing data schema in the database, or a given custom schema.
|
|
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: details about the data and schema to test
|
|
18
|
-
content:
|
|
19
|
-
'application/json':
|
|
20
|
-
schema:
|
|
21
|
-
type: object
|
|
22
|
-
properties:
|
|
23
|
-
path:
|
|
24
|
-
type: string
|
|
25
|
-
description: database path to the given value
|
|
26
|
-
example: collection/item
|
|
27
|
-
value:
|
|
28
|
-
$ref: '#/components/schemas/SerializedValue'
|
|
29
|
-
partial:
|
|
30
|
-
type: boolean
|
|
31
|
-
description: Whether to only test passed data (`update` db operation), or to validate the value against the entire schema (`set` db operation). Update operations allow required children in the schema not to be present in the passed value.
|
|
32
|
-
example: false
|
|
33
|
-
schema:
|
|
34
|
-
type: string
|
|
35
|
-
description: When given, tests this schema definition against the passed value instead of ones defined in the database
|
|
36
|
-
example: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
37
|
-
required:
|
|
38
|
-
- path
|
|
39
|
-
- value
|
|
40
|
-
- partial
|
|
41
|
-
responses:
|
|
42
|
-
200:
|
|
43
|
-
description: Returns an object that indicates whether the value successfully validated against schema
|
|
44
|
-
content:
|
|
45
|
-
'application/json':
|
|
46
|
-
schema:
|
|
47
|
-
type: object
|
|
48
|
-
properties:
|
|
49
|
-
ok:
|
|
50
|
-
type: boolean
|
|
51
|
-
example: false
|
|
52
|
-
reason:
|
|
53
|
-
type: string
|
|
54
|
-
example: path "books/book1/title" must be typeof string
|
|
55
|
-
403:
|
|
56
|
-
description: Returns a "403 Forbidden" if the signed in user is not admin
|
|
57
|
-
content:
|
|
58
|
-
'application/json':
|
|
59
|
-
schema:
|
|
60
|
-
$ref: '#/components/schemas/Error'
|
|
61
|
-
500:
|
|
62
|
-
description: An unexpected error occurred
|
|
63
|
-
content:
|
|
64
|
-
'application/json':
|
|
65
|
-
schema:
|
|
66
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -1,33 +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 = null;
|
|
6
|
-
export type ResponseBody =
|
|
7
|
-
{ path: string; schema: string; text: string }[] // 200
|
|
8
|
-
|
|
9
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
10
|
-
|
|
11
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
12
|
-
|
|
13
|
-
env.app.get(`/schema/${env.db.name}`, async (req: Request, res) => {
|
|
14
|
-
// Get all defined schemas
|
|
15
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
16
|
-
return sendUnauthorizedError(res, 'admin_only', 'only admin can perform schema operations');
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const schemas = await env.db.schema.all();
|
|
20
|
-
res.contentType('application/json').send(schemas.map(schema => ({
|
|
21
|
-
path: schema.path,
|
|
22
|
-
schema: typeof schema.schema === 'string' ? schema.schema : schema.text,
|
|
23
|
-
text: schema.text
|
|
24
|
-
})));
|
|
25
|
-
}
|
|
26
|
-
catch(err) {
|
|
27
|
-
sendError(res, err);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default addRoute;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/schema/{dbname}:
|
|
2
|
-
get:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- schemas
|
|
6
|
-
summary: Gets all defined schema definitions
|
|
7
|
-
description: Gets a list of all defined schema definitions
|
|
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
|
-
responses:
|
|
17
|
-
200:
|
|
18
|
-
description: Returns all defined schemas in the database
|
|
19
|
-
content:
|
|
20
|
-
'application/json':
|
|
21
|
-
schema:
|
|
22
|
-
type: array
|
|
23
|
-
items:
|
|
24
|
-
type: object
|
|
25
|
-
description: Object containing the string representation of the schema
|
|
26
|
-
example:
|
|
27
|
-
- path: collection/child
|
|
28
|
-
schema: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
29
|
-
text: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
30
|
-
403:
|
|
31
|
-
description: Returns a "403 Forbidden" if the signed in user is not admin
|
|
32
|
-
content:
|
|
33
|
-
'application/json':
|
|
34
|
-
schema:
|
|
35
|
-
$ref: '#/components/schemas/Error'
|
|
36
|
-
500:
|
|
37
|
-
description: An unexpected error occurred
|
|
38
|
-
content:
|
|
39
|
-
'application/json':
|
|
40
|
-
schema:
|
|
41
|
-
$ref: '#/components/schemas/UnexpectedError'
|
package/src/routes/data-set.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { SchemaValidationError } from 'acebase';
|
|
2
|
-
import { Transport } from 'acebase-core';
|
|
3
|
-
import { SerializedValue } from 'acebase-core/types/transport';
|
|
4
|
-
import { RuleValidationFailCode } from '../rules';
|
|
5
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
6
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
7
|
-
|
|
8
|
-
export class SetDataError extends Error {
|
|
9
|
-
constructor(public code: 'invalid_serialized_value', message: string) {
|
|
10
|
-
super(message);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export type RequestQuery = null;
|
|
14
|
-
export type RequestBody = SerializedValue; // { val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
|
|
15
|
-
export type ResponseBody = { success: true } // 200
|
|
16
|
-
| { code: 'invalid_serialized_value', message: string } // 400
|
|
17
|
-
| { code: RuleValidationFailCode, message: string } // 403
|
|
18
|
-
| { code: 'schema_validation_failed', message: string } // 422
|
|
19
|
-
| { code: string, message: string } // 500
|
|
20
|
-
|
|
21
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
22
|
-
|
|
23
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
24
|
-
|
|
25
|
-
env.app.put(`/data/${env.db.name}/*`, async (req: Request, res) => {
|
|
26
|
-
// Set data
|
|
27
|
-
const path = req.path.slice(env.db.name.length + 7);
|
|
28
|
-
const access = env.rules.userHasAccess(req.user, path, true);
|
|
29
|
-
if (!access.allow) {
|
|
30
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const data = req.body;
|
|
35
|
-
if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
|
|
36
|
-
throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
37
|
-
}
|
|
38
|
-
const val = Transport.deserialize(data);
|
|
39
|
-
|
|
40
|
-
if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
|
|
41
|
-
// Non-admin user: remove any private properties from the update object
|
|
42
|
-
Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Schema validation moved to storage, no need to check here but an early check won't do no harm!
|
|
46
|
-
const validation = await env.db.schema.check(path, val, false);
|
|
47
|
-
if (!validation.ok) {
|
|
48
|
-
throw new SchemaValidationError(validation.reason);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
await env.db.ref(path)
|
|
52
|
-
.context(req.context)
|
|
53
|
-
.set(val);
|
|
54
|
-
|
|
55
|
-
res.send({ success: true });
|
|
56
|
-
}
|
|
57
|
-
catch(err) {
|
|
58
|
-
if (err instanceof SchemaValidationError) {
|
|
59
|
-
env.logRef?.push({ action: 'set_data', success: false, code: 'schema_validation_failed', path, error: err.reason, ip: req.ip, uid: req.user?.uid ?? null });
|
|
60
|
-
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
61
|
-
}
|
|
62
|
-
else if (err instanceof SetDataError) {
|
|
63
|
-
env.logRef?.push({ action: 'set_data', success: false, code: err.code, path, ip: req.ip, uid: req.user?.uid ?? null });
|
|
64
|
-
sendBadRequestError(res, err);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
env.debug.error(`failed to set "${path}":`, err);
|
|
68
|
-
env.logRef?.push({ action: 'set_data', success: false, code: 'unknown_error', path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
|
|
69
|
-
sendError(res, err);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default addRoute;
|
package/src/routes/data-set.yaml
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/data/{dbname}/{path}:
|
|
2
|
-
put:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
summary: Sets the value of a path
|
|
6
|
-
description: Sets the stored value of a path in the database, overwriting existing data and its children
|
|
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
|
-
- name: AceBase-Context
|
|
23
|
-
in: header
|
|
24
|
-
description: Contextual info about the database operation (must be valid JSON). This info is included in event notifications sent to clients watching data at this or child paths
|
|
25
|
-
schema:
|
|
26
|
-
type: string
|
|
27
|
-
example: {}
|
|
28
|
-
requestBody:
|
|
29
|
-
description: serialized value to store in the database
|
|
30
|
-
content:
|
|
31
|
-
'application/json':
|
|
32
|
-
schema:
|
|
33
|
-
$ref: '#/components/schemas/SerializedValue'
|
|
34
|
-
responses:
|
|
35
|
-
200:
|
|
36
|
-
description: Returns "200 OK" when the database operation succeeded
|
|
37
|
-
content:
|
|
38
|
-
'application/json':
|
|
39
|
-
schema:
|
|
40
|
-
type: object
|
|
41
|
-
properties:
|
|
42
|
-
success:
|
|
43
|
-
type: boolean
|
|
44
|
-
example: true
|
|
45
|
-
400:
|
|
46
|
-
description: Returns "400 Bad Request" if the sent value is incorrect
|
|
47
|
-
content:
|
|
48
|
-
'application/json':
|
|
49
|
-
schema:
|
|
50
|
-
$ref: '#/components/schemas/Error'
|
|
51
|
-
example:
|
|
52
|
-
code: invalid_serialized_value
|
|
53
|
-
message: The sent value is not properly serialized
|
|
54
|
-
403:
|
|
55
|
-
description: Returns "403 Forbidden" if the signed in user is not allowed to write to the target path
|
|
56
|
-
content:
|
|
57
|
-
'application/json':
|
|
58
|
-
schema:
|
|
59
|
-
$ref: '#/components/schemas/Error'
|
|
60
|
-
422:
|
|
61
|
-
description: Returns "422 Unprocessable Entity" if schema validation for the sent value failed.
|
|
62
|
-
content:
|
|
63
|
-
'application/json':
|
|
64
|
-
schema:
|
|
65
|
-
$ref: '#/components/schemas/SchemaValidationError'
|
|
66
|
-
500:
|
|
67
|
-
description: An unexpected error occurred
|
|
68
|
-
content:
|
|
69
|
-
'application/json':
|
|
70
|
-
schema:
|
|
71
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ValueChange } from 'acebase-core/src/api';
|
|
2
|
-
import { PathInfo, Transport } from 'acebase-core';
|
|
3
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
4
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
5
|
-
|
|
6
|
-
export type RequestQuery = {
|
|
7
|
-
path?: string;
|
|
8
|
-
for?: Array<{ path: string, events: string[] }>;
|
|
9
|
-
cursor?: string;
|
|
10
|
-
timestamp?: string;
|
|
11
|
-
};
|
|
12
|
-
export type RequestBody = null;
|
|
13
|
-
export type ResponseBody = ValueChange[] // 200
|
|
14
|
-
| { code: 'no_transaction_logging', message: string } // 400
|
|
15
|
-
| { code: 'invalid_request', message: string } // 400
|
|
16
|
-
| { code: 'not_authorized', message: string } // 403
|
|
17
|
-
| { code: 'unexpected', message: string }; // 500
|
|
18
|
-
|
|
19
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
20
|
-
|
|
21
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
22
|
-
|
|
23
|
-
env.app.get(`/sync/changes/${env.db.name}`, async (req: Request, res) => {
|
|
24
|
-
// Gets effective changes for specific path(s) and event combinations since given cursor
|
|
25
|
-
if (!env.config.transactions?.log) {
|
|
26
|
-
return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
const data = req.query;
|
|
30
|
-
let targets = typeof data.path === 'string'
|
|
31
|
-
? [{ path: data.path, events: ['value'] }]
|
|
32
|
-
: typeof data.for === 'string'
|
|
33
|
-
? JSON.parse(data.for)
|
|
34
|
-
: null;
|
|
35
|
-
if (targets === null) {
|
|
36
|
-
return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid changes request' });
|
|
37
|
-
}
|
|
38
|
-
if (targets.length === 0) {
|
|
39
|
-
targets.push({ path: '', events: ['value'] });
|
|
40
|
-
}
|
|
41
|
-
// Filter out any requested paths user does not have access to.
|
|
42
|
-
targets = targets.filter(target => {
|
|
43
|
-
let path = target.path;
|
|
44
|
-
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
45
|
-
// Only child_ events, check if they have access to children instead
|
|
46
|
-
path = PathInfo.get(path).childPath('*');
|
|
47
|
-
}
|
|
48
|
-
return env.rules.userHasAccess(req.user, path, false).allow;
|
|
49
|
-
});
|
|
50
|
-
if (targets.length === 0) {
|
|
51
|
-
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { cursor } = data;
|
|
55
|
-
let timestamp: number;
|
|
56
|
-
if (typeof data.timestamp !== 'undefined') {
|
|
57
|
-
timestamp = parseInt(data.timestamp);
|
|
58
|
-
if (isNaN(timestamp)) {
|
|
59
|
-
return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const result = await env.db.api.getChanges({ for: targets, cursor, timestamp });
|
|
63
|
-
|
|
64
|
-
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
65
|
-
res.contentType('application/json');
|
|
66
|
-
|
|
67
|
-
const serialized = Transport.serialize2(result.changes);
|
|
68
|
-
res.send(serialized);
|
|
69
|
-
}
|
|
70
|
-
catch(err) {
|
|
71
|
-
sendError(res, err);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default addRoute;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/sync/changes/{dbname}:
|
|
2
|
-
get:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
summary: Gets effective changes since cursor
|
|
6
|
-
description: Gets effective changes for specific path(s) and event combinations since given cursor. Use either the _path_ or _for_ parameter. If both are given, only _path_ is used.
|
|
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: query
|
|
17
|
-
description: "single database path to get all changes for (equivalent to _for_ `[{ path, events: ['value'] }]`)"
|
|
18
|
-
schema:
|
|
19
|
-
type: string
|
|
20
|
-
example: collection
|
|
21
|
-
- name: for
|
|
22
|
-
in: query
|
|
23
|
-
description: JSON array of path / events combinations
|
|
24
|
-
schema:
|
|
25
|
-
type: string
|
|
26
|
-
example: "[{ path: 'collection', events: ['child_changed'] }]"
|
|
27
|
-
- name: cursor
|
|
28
|
-
in: query
|
|
29
|
-
description: previously acquired cursor to use
|
|
30
|
-
schema:
|
|
31
|
-
type: string
|
|
32
|
-
example: l2a37q55000008ll8dyngkny
|
|
33
|
-
- name: timestamp
|
|
34
|
-
in: query
|
|
35
|
-
description: instead of a cursor, you can also use a timestamp (ms since 1970/01/01)
|
|
36
|
-
schema:
|
|
37
|
-
type: integer
|
|
38
|
-
example: ""
|
|
39
|
-
responses:
|
|
40
|
-
200:
|
|
41
|
-
description: Returns an array of all effective changes to the requested selection
|
|
42
|
-
content:
|
|
43
|
-
'application/json':
|
|
44
|
-
schema:
|
|
45
|
-
type: object
|
|
46
|
-
example: []
|
|
47
|
-
400:
|
|
48
|
-
description: Returns "400 Bad Request" if transaction logging is not enabled in the server settings (code `no_transaction_logging`) or if no targets were specified in your query (no _path_ or _for_ parameters given, code `invalid_request`)
|
|
49
|
-
content:
|
|
50
|
-
'application/json':
|
|
51
|
-
schema:
|
|
52
|
-
$ref: '#/components/schemas/Error'
|
|
53
|
-
example:
|
|
54
|
-
code: no_transaction_logging
|
|
55
|
-
message: Transaction logging not enabled
|
|
56
|
-
403:
|
|
57
|
-
description: Returns a "403 Forbidden" if the signed in user is not allowed to read from any of the targeted paths
|
|
58
|
-
content:
|
|
59
|
-
'application/json':
|
|
60
|
-
schema:
|
|
61
|
-
$ref: '#/components/schemas/Error'
|
|
62
|
-
500:
|
|
63
|
-
description: An unexpected error occurred
|
|
64
|
-
content:
|
|
65
|
-
'application/json':
|
|
66
|
-
schema:
|
|
67
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { PathInfo, Transport } from 'acebase-core';
|
|
2
|
-
import { ValueMutation } from 'acebase-core/src/api';
|
|
3
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
4
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
5
|
-
|
|
6
|
-
export type RequestQuery = {
|
|
7
|
-
path?: string;
|
|
8
|
-
for?: Array<{ path: string, events: string[] }>;
|
|
9
|
-
cursor?: string;
|
|
10
|
-
timestamp?: string;
|
|
11
|
-
};
|
|
12
|
-
export type RequestBody = null;
|
|
13
|
-
export type ResponseBody = ValueMutation[] // 200
|
|
14
|
-
| { code: 'no_transaction_logging', message: string } // 400
|
|
15
|
-
| { code: 'invalid_request', message: string } // 400
|
|
16
|
-
| { code: 'not_authorized', message: string } // 403
|
|
17
|
-
| { code: 'unexpected', message: string }; // 500
|
|
18
|
-
|
|
19
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
20
|
-
|
|
21
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
22
|
-
|
|
23
|
-
env.app.get(`/sync/mutations/${env.db.name}`, async (req: Request, res) => {
|
|
24
|
-
// Gets mutations for specific path(s) and event combinations since given cursor
|
|
25
|
-
if (!env.config.transactions?.log) {
|
|
26
|
-
return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
const data = req.query;
|
|
30
|
-
let targets = typeof data.path === 'string'
|
|
31
|
-
? [{ path: data.path, events: ['value'] }]
|
|
32
|
-
: typeof data.for === 'string'
|
|
33
|
-
? JSON.parse(data.for)
|
|
34
|
-
: null;
|
|
35
|
-
if (targets === null) {
|
|
36
|
-
return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid mutations request' });
|
|
37
|
-
}
|
|
38
|
-
if (targets.length === 0) {
|
|
39
|
-
targets.push({ path: '', events: ['value'] });
|
|
40
|
-
}
|
|
41
|
-
// Filter out any requested paths user does not have access to.
|
|
42
|
-
targets = targets.filter(target => {
|
|
43
|
-
let path = target.path;
|
|
44
|
-
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
45
|
-
// Only child_ events, check if they have access to children instead
|
|
46
|
-
path = PathInfo.get(path).childPath('*');
|
|
47
|
-
}
|
|
48
|
-
return env.rules.userHasAccess(req.user, path, false).allow;
|
|
49
|
-
});
|
|
50
|
-
if (targets.length === 0) {
|
|
51
|
-
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { cursor } = data;
|
|
55
|
-
let timestamp: number;
|
|
56
|
-
if (typeof data.timestamp !== 'undefined') {
|
|
57
|
-
timestamp = parseInt(data.timestamp);
|
|
58
|
-
if (isNaN(timestamp)) {
|
|
59
|
-
return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const result = await env.db.api.getMutations({ for: targets, cursor, timestamp });
|
|
63
|
-
|
|
64
|
-
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
65
|
-
res.contentType('application/json');
|
|
66
|
-
|
|
67
|
-
const serialized = Transport.serialize2(result.mutations);
|
|
68
|
-
res.send(serialized);
|
|
69
|
-
}
|
|
70
|
-
catch(err) {
|
|
71
|
-
sendError(res, err);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default addRoute;
|