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.
- package/.vscode/launch.json +24 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/shared/rootpath.js +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/shared/rootpath.js +2 -0
- package/package.json +3 -3
- 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/logger.js.map +0 -1
- package/dist/cjs/middleware/404.js.map +0 -1
- package/dist/cjs/middleware/admin-only.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-logs.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/logger.js.map +0 -1
- package/dist/esm/middleware/404.js.map +0 -1
- package/dist/esm/middleware/admin-only.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-logs.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/logger.ts +0 -56
- package/src/middleware/404.ts +0 -13
- package/src/middleware/admin-only.ts +0 -29
- 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 -92
- package/src/routes/auth-change-password.yaml +0 -74
- package/src/routes/auth-delete.ts +0 -49
- package/src/routes/auth-delete.yaml +0 -78
- package/src/routes/auth-forgot-password.ts +0 -77
- package/src/routes/auth-forgot-password.yaml +0 -50
- package/src/routes/auth-reset-password.ts +0 -96
- 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 -64
- package/src/routes/auth-signout.yaml +0 -46
- package/src/routes/auth-signup.ts +0 -164
- 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 -149
- package/src/routes/auth-update.yaml +0 -152
- package/src/routes/auth-verify-email.ts +0 -75
- 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 -82
- package/src/routes/data-index-create.yaml +0 -105
- package/src/routes/data-index-delete.ts +0 -36
- package/src/routes/data-index-delete.yaml +0 -51
- package/src/routes/data-index-list.ts +0 -39
- 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 -91
- package/src/routes/data-reflect.yaml +0 -124
- package/src/routes/data-schema-get.ts +0 -36
- package/src/routes/data-schema-get.yaml +0 -53
- package/src/routes/data-schema-set.ts +0 -35
- package/src/routes/data-schema-set.yaml +0 -60
- package/src/routes/data-schema-test.ts +0 -50
- package/src/routes/data-schema-test.yaml +0 -66
- package/src/routes/data-schemas-list.ts +0 -31
- package/src/routes/data-schemas-list.yaml +0 -41
- package/src/routes/data-set.ts +0 -84
- 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 -168
- package/src/routes/data-update.ts +0 -85
- 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-logs.ts +0 -57
- 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 -22
- 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 -286
- 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 -420
- 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 -39
- 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 -149
- 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 -48
- package/src/test.ts +0 -10
- package/src/websocket/index.ts +0 -337
- 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,80 +0,0 @@
|
|
|
1
|
-
/index/{dbname}:
|
|
2
|
-
get:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- indexes
|
|
6
|
-
summary: Get indexes in the database
|
|
7
|
-
description: Gets a list of indexes created in the database (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
|
-
responses:
|
|
17
|
-
200:
|
|
18
|
-
description: Returns an array of indexes in the database
|
|
19
|
-
content:
|
|
20
|
-
'application/json':
|
|
21
|
-
schema:
|
|
22
|
-
type: array
|
|
23
|
-
items:
|
|
24
|
-
type: object
|
|
25
|
-
properties:
|
|
26
|
-
path:
|
|
27
|
-
type: string
|
|
28
|
-
description: path of the indexed collection
|
|
29
|
-
example: books
|
|
30
|
-
key:
|
|
31
|
-
type: string
|
|
32
|
-
description: key (property) of the indexed items in the collection
|
|
33
|
-
example: title
|
|
34
|
-
caseSensitive:
|
|
35
|
-
type: boolean
|
|
36
|
-
description: Whether the values are indexed with case sensitivity or not (applies to string values only)
|
|
37
|
-
example: false
|
|
38
|
-
textLocale:
|
|
39
|
-
type: string
|
|
40
|
-
description: Locale of the indexed string values
|
|
41
|
-
example: en-us
|
|
42
|
-
includeKeys:
|
|
43
|
-
type: array
|
|
44
|
-
description: keys (properties) whose values are included in the index
|
|
45
|
-
items:
|
|
46
|
-
type: string
|
|
47
|
-
example:
|
|
48
|
-
- rating
|
|
49
|
-
- year
|
|
50
|
-
indexMetadataKeys:
|
|
51
|
-
type: array
|
|
52
|
-
description: Any additional info that is being stored with the items. Eg for fulltext indexes, it contains the word count and location
|
|
53
|
-
items:
|
|
54
|
-
type: string
|
|
55
|
-
type:
|
|
56
|
-
type: string
|
|
57
|
-
description: Type of index
|
|
58
|
-
enum:
|
|
59
|
-
- normal
|
|
60
|
-
- array
|
|
61
|
-
- fulltext
|
|
62
|
-
- geo
|
|
63
|
-
fileName:
|
|
64
|
-
type: string
|
|
65
|
-
description: name of the index file on disk
|
|
66
|
-
description:
|
|
67
|
-
type: string
|
|
68
|
-
description: description of the index
|
|
69
|
-
403:
|
|
70
|
-
description: Returns a "403 Forbidden" if the signed in user is not admin
|
|
71
|
-
content:
|
|
72
|
-
'application/json':
|
|
73
|
-
schema:
|
|
74
|
-
$ref: '#/components/schemas/Error'
|
|
75
|
-
500:
|
|
76
|
-
description: An unexpected error occurred
|
|
77
|
-
content:
|
|
78
|
-
'application/json':
|
|
79
|
-
schema:
|
|
80
|
-
$ref: '#/components/schemas/UnexpectedError'
|
package/src/routes/data-query.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Transport } from 'acebase-core';
|
|
2
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
3
|
-
import { sendError, sendUnauthorizedError } from '../shared/error';
|
|
4
|
-
|
|
5
|
-
export type RequestQuery = null;
|
|
6
|
-
export type RequestBody = {
|
|
7
|
-
map: any;
|
|
8
|
-
val: {
|
|
9
|
-
query: {
|
|
10
|
-
/** result filters */
|
|
11
|
-
filters: Array<{ key: string, op: string, compare: any }>;
|
|
12
|
-
/** number of results to skip, useful for paging */
|
|
13
|
-
skip: number;
|
|
14
|
-
/** max number of results to return */
|
|
15
|
-
take: number;
|
|
16
|
-
/** sort order */
|
|
17
|
-
order: Array<{ key: string, ascending: boolean }>;
|
|
18
|
-
};
|
|
19
|
-
/** client's query id for realtime event notifications through the websocket */
|
|
20
|
-
query_id?: string;
|
|
21
|
-
/** client's socket id for realtime event notifications through websocket */
|
|
22
|
-
client_id?: string;
|
|
23
|
-
options: {
|
|
24
|
-
snapshots?: boolean;
|
|
25
|
-
monitor?: boolean|{ add: boolean; change: boolean; remove: boolean };
|
|
26
|
-
include?: string[];
|
|
27
|
-
exclude?: string[];
|
|
28
|
-
child_objects?: boolean;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export type ResponseBody = {
|
|
33
|
-
val: {
|
|
34
|
-
count: number;
|
|
35
|
-
list: any[]
|
|
36
|
-
},
|
|
37
|
-
map?: any
|
|
38
|
-
};
|
|
39
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
40
|
-
|
|
41
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
42
|
-
|
|
43
|
-
env.app.post(`/query/${env.db.name}/*`, async (req: Request, res) => {
|
|
44
|
-
// Execute query
|
|
45
|
-
const path = req.path.slice(env.db.name.length + 8);
|
|
46
|
-
const access = env.rules.userHasAccess(req.user, path, false);
|
|
47
|
-
if (!access.allow) {
|
|
48
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const data = Transport.deserialize(req.body);
|
|
52
|
-
if (typeof data !== 'object' || typeof data.query !== 'object' || typeof data.options !== 'object') {
|
|
53
|
-
return sendError(res, { code: 'invalid_request', message: 'Invalid query request' });
|
|
54
|
-
}
|
|
55
|
-
const query = data.query;
|
|
56
|
-
const options = data.options;
|
|
57
|
-
if (options.monitor === true) {
|
|
58
|
-
options.monitor = { add: true, change: true, remove: true };
|
|
59
|
-
}
|
|
60
|
-
if (typeof options.monitor === 'object' && (options.monitor.add || options.monitor.change || options.monitor.remove)) {
|
|
61
|
-
const queryId = data.query_id;
|
|
62
|
-
const clientId = data.client_id;
|
|
63
|
-
const client = env.clients.get(clientId);
|
|
64
|
-
client.realtimeQueries[queryId] = { path, query, options };
|
|
65
|
-
|
|
66
|
-
const sendEvent = event => {
|
|
67
|
-
const client = env.clients.get(clientId);
|
|
68
|
-
if (!client) { return false; } // Not connected, stop subscription
|
|
69
|
-
if (!env.rules.userHasAccess(client.user, event.path, false).allow) {
|
|
70
|
-
return false; // Access denied, stop subscription
|
|
71
|
-
}
|
|
72
|
-
event.query_id = queryId;
|
|
73
|
-
const data = Transport.serialize(event);
|
|
74
|
-
client.socket.emit('query-event', data);
|
|
75
|
-
}
|
|
76
|
-
options.eventHandler = sendEvent;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const { results, context } = await env.db.api.query(path, query, options);
|
|
80
|
-
if (!env.config.transactions?.log) {
|
|
81
|
-
delete context.acebase_cursor;
|
|
82
|
-
}
|
|
83
|
-
const response = {
|
|
84
|
-
count: results.length,
|
|
85
|
-
list: results // []
|
|
86
|
-
};
|
|
87
|
-
res.setHeader('AceBase-Context', JSON.stringify(context));
|
|
88
|
-
res.send(Transport.serialize(response));
|
|
89
|
-
}
|
|
90
|
-
catch(err) {
|
|
91
|
-
sendError(res, { code: 'unknown', message: err.message });
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export default addRoute;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/query/{dbname}/{path}:
|
|
2
|
-
post:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- query
|
|
6
|
-
summary: Query an object collection
|
|
7
|
-
description: Query an object collection in 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
|
-
- name: path
|
|
17
|
-
in: path
|
|
18
|
-
description: database path
|
|
19
|
-
required: true
|
|
20
|
-
schema:
|
|
21
|
-
type: string
|
|
22
|
-
example: books
|
|
23
|
-
requestBody:
|
|
24
|
-
description: serialized query object
|
|
25
|
-
content:
|
|
26
|
-
'application/json':
|
|
27
|
-
schema:
|
|
28
|
-
type: object
|
|
29
|
-
properties:
|
|
30
|
-
map:
|
|
31
|
-
description: Data type mappings for the value in _val_. See the _SerializedValue_ schema for more info
|
|
32
|
-
oneOf:
|
|
33
|
-
- type: string
|
|
34
|
-
- type: object
|
|
35
|
-
example: {}
|
|
36
|
-
val:
|
|
37
|
-
description: Information about the query to execute
|
|
38
|
-
type: object
|
|
39
|
-
properties:
|
|
40
|
-
query:
|
|
41
|
-
type: object
|
|
42
|
-
properties:
|
|
43
|
-
filters:
|
|
44
|
-
type: array
|
|
45
|
-
items:
|
|
46
|
-
type: object
|
|
47
|
-
properties:
|
|
48
|
-
key:
|
|
49
|
-
type: string
|
|
50
|
-
example: title
|
|
51
|
-
description: Key to apply filter on
|
|
52
|
-
op:
|
|
53
|
-
type: string
|
|
54
|
-
description: Comparison operator to use, such as `==`, `>`, 'like' etc
|
|
55
|
-
example: like
|
|
56
|
-
compare:
|
|
57
|
-
example: AceBase*
|
|
58
|
-
description: Value to compare with
|
|
59
|
-
oneOf:
|
|
60
|
-
- type: string
|
|
61
|
-
- type: number
|
|
62
|
-
- type: boolean
|
|
63
|
-
skip:
|
|
64
|
-
type: integer
|
|
65
|
-
example: 0
|
|
66
|
-
description: Number of results to skip, useful for paging
|
|
67
|
-
take:
|
|
68
|
-
type: integer
|
|
69
|
-
example: 10
|
|
70
|
-
description: Max number of results to return
|
|
71
|
-
order:
|
|
72
|
-
type: array
|
|
73
|
-
items:
|
|
74
|
-
type: object
|
|
75
|
-
properties:
|
|
76
|
-
key:
|
|
77
|
-
type: string
|
|
78
|
-
description: Name of the key to sort the results on
|
|
79
|
-
example: rating
|
|
80
|
-
ascending:
|
|
81
|
-
type: boolean
|
|
82
|
-
description: Whether to sort the results in ascending or descending order
|
|
83
|
-
example: false
|
|
84
|
-
query_id:
|
|
85
|
-
type: string
|
|
86
|
-
description: (realtime queries only) client's query id for realtime event notifications through the websocket
|
|
87
|
-
example: l27nswgz000009l58bo7gqhf
|
|
88
|
-
client_id:
|
|
89
|
-
type: string
|
|
90
|
-
description: (realtime queries only) client's socket id for realtime event notifications through websocket
|
|
91
|
-
example: l27mjf9k000209mhafylc3eo
|
|
92
|
-
options:
|
|
93
|
-
type: object
|
|
94
|
-
properties:
|
|
95
|
-
snapshots:
|
|
96
|
-
type: boolean
|
|
97
|
-
description: Whether to return snapshots of the data, or references to the results only (default)
|
|
98
|
-
example: true
|
|
99
|
-
monitor:
|
|
100
|
-
description: (optional, realtime queries only) which realtime events to monitor
|
|
101
|
-
oneOf:
|
|
102
|
-
- type: boolean
|
|
103
|
-
description: Whether to monitor all or none of the realtime events (add, change, remove)
|
|
104
|
-
- type: object
|
|
105
|
-
description: Which realtime events to monitor
|
|
106
|
-
properties:
|
|
107
|
-
add:
|
|
108
|
-
type: boolean
|
|
109
|
-
description: Monitors results that are added after initial query execution
|
|
110
|
-
change:
|
|
111
|
-
type: boolean
|
|
112
|
-
description: Monitors results that are changed after initial query execution
|
|
113
|
-
remove:
|
|
114
|
-
type: boolean
|
|
115
|
-
description: Monitors results that are removed after initial query execution
|
|
116
|
-
example: false
|
|
117
|
-
include:
|
|
118
|
-
type: array
|
|
119
|
-
items:
|
|
120
|
-
type: string
|
|
121
|
-
description: (optional) keys to include in the results set
|
|
122
|
-
example:
|
|
123
|
-
- title
|
|
124
|
-
- author
|
|
125
|
-
- rating
|
|
126
|
-
- reviews/*/author
|
|
127
|
-
- reviews/*/text
|
|
128
|
-
exclude:
|
|
129
|
-
type: array
|
|
130
|
-
items:
|
|
131
|
-
type: string
|
|
132
|
-
description: (optional) keys to exclude from the results set
|
|
133
|
-
example: []
|
|
134
|
-
child_objects:
|
|
135
|
-
type: boolean
|
|
136
|
-
description: (optional) whether to load child object values
|
|
137
|
-
example: true
|
|
138
|
-
responses:
|
|
139
|
-
200:
|
|
140
|
-
description: Returns the serialized count and list of query results
|
|
141
|
-
content:
|
|
142
|
-
'application/json':
|
|
143
|
-
schema:
|
|
144
|
-
required:
|
|
145
|
-
- val
|
|
146
|
-
allOf:
|
|
147
|
-
- $ref: '#/components/schemas/SerializedValue'
|
|
148
|
-
example:
|
|
149
|
-
val: { count: 1, list: [{ path: 'books/l27oxggz000009ml9ri26y2d', val: { title: 'AceBase is cool', author: 'Database guru', rating: 5.0, reviews: { 'cl27ozp2g000009lbfopcbkd2': { author: 'DB admin', text: 'The title says it all!' } } }}] }
|
|
150
|
-
map: { 'stats/created': 'date', 'stats/modified': 'date' }
|
|
151
|
-
403:
|
|
152
|
-
description: Returns a "403 Forbidden" if the signed in user is not allowed to read from the target path
|
|
153
|
-
content:
|
|
154
|
-
'application/json':
|
|
155
|
-
schema:
|
|
156
|
-
$ref: '#/components/schemas/Error'
|
|
157
|
-
500:
|
|
158
|
-
description: An unexpected error occurred
|
|
159
|
-
content:
|
|
160
|
-
'application/json':
|
|
161
|
-
schema:
|
|
162
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { IReflectionChildrenInfo, IReflectionNodeInfo, PathInfo } from 'acebase-core';
|
|
2
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
3
|
-
import { sendUnauthorizedError } from '../shared/error';
|
|
4
|
-
|
|
5
|
-
export type RequestQuery = { type: 'info'|'children'; impersonate?: string };
|
|
6
|
-
export type RequestBody = null;
|
|
7
|
-
export type ResponseBody = IReflectionNodeInfo & IReflectionChildrenInfo & { impersonation: {
|
|
8
|
-
uid: string;
|
|
9
|
-
read: {
|
|
10
|
-
allow: boolean;
|
|
11
|
-
error?: { code: string; message: string };
|
|
12
|
-
};
|
|
13
|
-
write: {
|
|
14
|
-
allow: boolean;
|
|
15
|
-
error?: { code: string; message: string };
|
|
16
|
-
};
|
|
17
|
-
}};
|
|
18
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
-
|
|
20
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
-
|
|
22
|
-
env.app.get(`/reflect/${env.db.name}/*`, async (req: Request, res) => {
|
|
23
|
-
// Reflection API
|
|
24
|
-
const path = req.path.slice(env.db.name.length + 10);
|
|
25
|
-
const access = env.rules.userHasAccess(req.user, path, false);
|
|
26
|
-
if (!access.allow) {
|
|
27
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
28
|
-
}
|
|
29
|
-
const impersonatedAccess = {
|
|
30
|
-
uid: req.user?.uid !== 'admin' ? null : req.query.impersonate,
|
|
31
|
-
read: {
|
|
32
|
-
allow: false,
|
|
33
|
-
error: null
|
|
34
|
-
},
|
|
35
|
-
write: {
|
|
36
|
-
allow: false,
|
|
37
|
-
error: null
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const impersonatedUser = impersonatedAccess.uid === 'anonymous' ? null : { uid: impersonatedAccess.uid };
|
|
41
|
-
if (impersonatedAccess.uid) {
|
|
42
|
-
const readAccess = env.rules.userHasAccess(impersonatedUser, path, false);
|
|
43
|
-
impersonatedAccess.read.allow = readAccess.allow;
|
|
44
|
-
if (!readAccess.allow) {
|
|
45
|
-
impersonatedAccess.read.error = { code: readAccess.code, message: readAccess.message };
|
|
46
|
-
}
|
|
47
|
-
const writeAccess = env.rules.userHasAccess(impersonatedUser, path, true);
|
|
48
|
-
impersonatedAccess.write.allow = writeAccess.allow;
|
|
49
|
-
if (!writeAccess.allow) {
|
|
50
|
-
impersonatedAccess.write.error = { code: writeAccess.code, message: writeAccess.message };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const type = req.query.type;
|
|
54
|
-
const args = {};
|
|
55
|
-
Object.keys(req.query).forEach(key => {
|
|
56
|
-
if (!['type','impersonate'].includes(key)) {
|
|
57
|
-
let val = req.query[key];
|
|
58
|
-
if (/^(?:true|false|[0-9]+)$/.test(val)) { val = JSON.parse(val); }
|
|
59
|
-
args[key] = val;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const result: ResponseBody = await (env.db.ref(path).reflect as (type: string, args: any) => any)(type, args);
|
|
65
|
-
if (impersonatedAccess.uid) {
|
|
66
|
-
result.impersonation = impersonatedAccess;
|
|
67
|
-
let list;
|
|
68
|
-
if (type === 'children') {
|
|
69
|
-
list = result.list;
|
|
70
|
-
}
|
|
71
|
-
else if (type === 'info') {
|
|
72
|
-
list = typeof result.children === 'object' ? result.children.list : [];
|
|
73
|
-
}
|
|
74
|
-
list && list.forEach(childInfo => {
|
|
75
|
-
childInfo.access = {
|
|
76
|
-
read: env.rules.userHasAccess(impersonatedUser, PathInfo.getChildPath(path, childInfo.key), false).allow,
|
|
77
|
-
write: env.rules.userHasAccess(impersonatedUser, PathInfo.getChildPath(path, childInfo.key), true).allow
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
res.send(result);
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
res.statusCode = 500;
|
|
85
|
-
res.send(err);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default addRoute;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/reflect/{dbname}/{path}:
|
|
2
|
-
get:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
summary: Reflection
|
|
6
|
-
description: Gets information about a node and/or its children without loading any values. When signed in as the admin user, it is possible to include security info (read/write access rights) for an impersonated user
|
|
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: type
|
|
23
|
-
in: query
|
|
24
|
-
description: reflection type
|
|
25
|
-
required: true
|
|
26
|
-
schema:
|
|
27
|
-
type: string
|
|
28
|
-
enum:
|
|
29
|
-
- info
|
|
30
|
-
- children
|
|
31
|
-
example: info
|
|
32
|
-
- name: include_child_count
|
|
33
|
-
in: query
|
|
34
|
-
required: false
|
|
35
|
-
description: if type is 'info', whether to include the child count
|
|
36
|
-
schema:
|
|
37
|
-
type: boolean
|
|
38
|
-
example: false
|
|
39
|
-
- name: child_limit
|
|
40
|
-
in: query
|
|
41
|
-
required: false
|
|
42
|
-
description: (for paging) if type is 'info', the max number of children to reflect. To skip previously acquired children, use in combination with `skip` or `from`
|
|
43
|
-
schema:
|
|
44
|
-
type: integer
|
|
45
|
-
example: 10
|
|
46
|
-
- name: child_skip
|
|
47
|
-
in: query
|
|
48
|
-
required: false
|
|
49
|
-
description: (for paging) if type is 'info', the number of children to skip
|
|
50
|
-
schema:
|
|
51
|
-
type: integer
|
|
52
|
-
example: 0
|
|
53
|
-
- name: child_from
|
|
54
|
-
in: query
|
|
55
|
-
required: false
|
|
56
|
-
description: (for paging) if type is 'info', the last child in previous reflection results to start enumerating
|
|
57
|
-
schema:
|
|
58
|
-
oneOf:
|
|
59
|
-
- type: string
|
|
60
|
-
description: key of the last enumerated child
|
|
61
|
-
- type: number
|
|
62
|
-
description: index of the last enumerated child
|
|
63
|
-
- name: limit
|
|
64
|
-
in: query
|
|
65
|
-
required: false
|
|
66
|
-
description: (for paging) if type is 'children', the max number of children to reflect. To skip previously acquired children, use in combination with `skip` or `from`
|
|
67
|
-
schema:
|
|
68
|
-
type: integer
|
|
69
|
-
example: 10
|
|
70
|
-
- name: skip
|
|
71
|
-
in: query
|
|
72
|
-
required: false
|
|
73
|
-
description: (for paging) if type is 'children', the number of children to skip
|
|
74
|
-
schema:
|
|
75
|
-
type: integer
|
|
76
|
-
example: 0
|
|
77
|
-
- name: from
|
|
78
|
-
in: query
|
|
79
|
-
required: false
|
|
80
|
-
description: (for paging) if type is 'children', the last child in previous reflection results to start enumerating
|
|
81
|
-
schema:
|
|
82
|
-
oneOf:
|
|
83
|
-
- type: string
|
|
84
|
-
description: key of the last enumerated child
|
|
85
|
-
- type: number
|
|
86
|
-
description: index of the last enumerated child
|
|
87
|
-
- name: impersonate
|
|
88
|
-
in: query
|
|
89
|
-
description: uid of the user to add access rights information for
|
|
90
|
-
required: false
|
|
91
|
-
schema:
|
|
92
|
-
type: string
|
|
93
|
-
responses:
|
|
94
|
-
200:
|
|
95
|
-
description: Returns requested reflection info for the target path
|
|
96
|
-
content:
|
|
97
|
-
'application/json':
|
|
98
|
-
schema:
|
|
99
|
-
oneOf:
|
|
100
|
-
- $ref: '#/components/schemas/ReflectionNodeInfo'
|
|
101
|
-
description: If reflection type is 'info'
|
|
102
|
-
- type: object
|
|
103
|
-
description: If reflection type is 'children'
|
|
104
|
-
properties:
|
|
105
|
-
more:
|
|
106
|
-
type: boolean
|
|
107
|
-
description: If there are more children
|
|
108
|
-
example: true
|
|
109
|
-
list:
|
|
110
|
-
type: array
|
|
111
|
-
items:
|
|
112
|
-
$ref: '#/components/schemas/ReflectionNodeInfo'
|
|
113
|
-
403:
|
|
114
|
-
description: Returns a "403 Forbidden" if the signed in user is not allowed to read from the target path
|
|
115
|
-
content:
|
|
116
|
-
'application/json':
|
|
117
|
-
schema:
|
|
118
|
-
$ref: '#/components/schemas/Error'
|
|
119
|
-
500:
|
|
120
|
-
description: An unexpected error occurred
|
|
121
|
-
content:
|
|
122
|
-
'application/json':
|
|
123
|
-
schema:
|
|
124
|
-
$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 = null;
|
|
7
|
-
export type ResponseBody =
|
|
8
|
-
{ path: string; schema: string; text: string } // 200
|
|
9
|
-
| 'Not Found'; // 410
|
|
10
|
-
|
|
11
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
12
|
-
|
|
13
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
14
|
-
|
|
15
|
-
env.app.get(`/schema/${env.db.name}/*`, adminOnly(env), async (req: Request, res) => {
|
|
16
|
-
// Get defined schema for a specifc path
|
|
17
|
-
try {
|
|
18
|
-
const path = req.path.slice(env.db.name.length + 9);
|
|
19
|
-
const schema = await env.db.schema.get(path);
|
|
20
|
-
if (!schema) {
|
|
21
|
-
return res.status(410).send('Not Found');
|
|
22
|
-
}
|
|
23
|
-
res.contentType('application/json').send({
|
|
24
|
-
path: schema.path,
|
|
25
|
-
schema: typeof schema.schema === 'string' ? schema.schema : schema.text,
|
|
26
|
-
text: schema.text
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
catch(err) {
|
|
30
|
-
sendError(res, err);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default addRoute;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/schema/{dbname}/{path}:
|
|
2
|
-
get:
|
|
3
|
-
tags:
|
|
4
|
-
- data
|
|
5
|
-
- schemas
|
|
6
|
-
summary: Gets the schema defined on a path
|
|
7
|
-
description: Gets the schema defined on a specific path
|
|
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
|
-
- name: path
|
|
17
|
-
in: path
|
|
18
|
-
description: database path
|
|
19
|
-
required: true
|
|
20
|
-
schema:
|
|
21
|
-
type: string
|
|
22
|
-
example: collection/item
|
|
23
|
-
responses:
|
|
24
|
-
200:
|
|
25
|
-
description: Returns the defined schema on the target path
|
|
26
|
-
content:
|
|
27
|
-
'application/json':
|
|
28
|
-
schema:
|
|
29
|
-
type: object
|
|
30
|
-
description: Object containing the string representation of the schema
|
|
31
|
-
example:
|
|
32
|
-
path: collection/child
|
|
33
|
-
schema: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
34
|
-
text: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
|
|
35
|
-
403:
|
|
36
|
-
description: Returns a "403 Forbidden" if the signed in user is not admin
|
|
37
|
-
content:
|
|
38
|
-
'application/json':
|
|
39
|
-
schema:
|
|
40
|
-
$ref: '#/components/schemas/Error'
|
|
41
|
-
410:
|
|
42
|
-
description: Returns "410 Gone" if there is no schema definition on the requested path
|
|
43
|
-
content:
|
|
44
|
-
'text/plain':
|
|
45
|
-
schema:
|
|
46
|
-
type: text
|
|
47
|
-
example: Not Found
|
|
48
|
-
500:
|
|
49
|
-
description: An unexpected error occurred
|
|
50
|
-
content:
|
|
51
|
-
'application/json':
|
|
52
|
-
schema:
|
|
53
|
-
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -1,35 +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
|
-
action?: 'set'; // deprecated
|
|
8
|
-
path: string;
|
|
9
|
-
schema: string|Object;
|
|
10
|
-
};
|
|
11
|
-
export type ResponseBody = { success: true } // 200
|
|
12
|
-
| { code: 'admin_only'; message: string } // 403
|
|
13
|
-
| { code: 'unexpected'; message: string }; // 500
|
|
14
|
-
|
|
15
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
16
|
-
|
|
17
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
18
|
-
|
|
19
|
-
env.app.post(`/schema/${env.db.name}`, adminOnly(env), async (req: Request, res) => {
|
|
20
|
-
// defines a schema
|
|
21
|
-
try {
|
|
22
|
-
const data = req.body;
|
|
23
|
-
const { path, schema } = data;
|
|
24
|
-
await env.db.schema.set(path, schema);
|
|
25
|
-
|
|
26
|
-
res.contentType('application/json').send({ success: true });
|
|
27
|
-
}
|
|
28
|
-
catch(err) {
|
|
29
|
-
sendError(res, err);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default addRoute;
|