acebase-server 1.16.2 → 1.17.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/README.md +180 -10
- package/build-vars.js +2 -1
- package/dist/cjs/auth.js +88 -88
- package/dist/cjs/cluster.js +56 -56
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +24 -24
- package/dist/cjs/logger.js +73 -73
- package/dist/cjs/middleware/404.js +14 -14
- package/dist/cjs/middleware/admin-only.js +28 -28
- package/dist/cjs/middleware/cache.js +14 -14
- package/dist/cjs/middleware/connection.js +49 -49
- package/dist/cjs/middleware/context.js +20 -20
- package/dist/cjs/middleware/cors.js +50 -50
- package/dist/cjs/middleware/swagger.js +17 -17
- package/dist/cjs/middleware/user.js +57 -57
- package/dist/cjs/oauth-providers/dropbox.js +109 -109
- package/dist/cjs/oauth-providers/facebook.js +85 -85
- package/dist/cjs/oauth-providers/google.js +119 -119
- package/dist/cjs/oauth-providers/index.js +26 -26
- package/dist/cjs/oauth-providers/instagram.js +80 -80
- package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
- package/dist/cjs/oauth-providers/spotify.js +113 -113
- package/dist/cjs/routes/auth-change-password.js +87 -87
- package/dist/cjs/routes/auth-delete.js +52 -52
- package/dist/cjs/routes/auth-forgot-password.js +77 -77
- package/dist/cjs/routes/auth-reset-password.js +97 -97
- package/dist/cjs/routes/auth-signin.js +46 -46
- package/dist/cjs/routes/auth-signout.js +61 -61
- package/dist/cjs/routes/auth-signup.js +142 -142
- package/dist/cjs/routes/auth-state.js +25 -25
- package/dist/cjs/routes/auth-update.js +131 -131
- package/dist/cjs/routes/auth-verify-email.js +71 -71
- package/dist/cjs/routes/auth.js +57 -54
- package/dist/cjs/routes/data-exists.js +33 -33
- package/dist/cjs/routes/data-export.js +48 -48
- package/dist/cjs/routes/data-get.js +70 -66
- package/dist/cjs/routes/data-import.js +54 -54
- package/dist/cjs/routes/data-index-create.js +42 -42
- package/dist/cjs/routes/data-index-delete.js +33 -33
- package/dist/cjs/routes/data-index-list.js +31 -31
- package/dist/cjs/routes/data-query.js +80 -70
- package/dist/cjs/routes/data-reflect.js +97 -86
- package/dist/cjs/routes/data-schema-get.js +36 -36
- package/dist/cjs/routes/data-schema-set.js +30 -30
- package/dist/cjs/routes/data-schema-test.js +43 -43
- package/dist/cjs/routes/data-schemas-list.js +32 -32
- package/dist/cjs/routes/data-set.js +85 -75
- package/dist/cjs/routes/data-sync-changes.js +81 -67
- package/dist/cjs/routes/data-sync-mutations.js +81 -67
- package/dist/cjs/routes/data-transaction.js +159 -139
- package/dist/cjs/routes/data-update.js +86 -75
- package/dist/cjs/routes/data.js +62 -62
- package/dist/cjs/routes/docs.js +258 -251
- package/dist/cjs/routes/meta-info.js +63 -63
- package/dist/cjs/routes/meta-logs.js +49 -49
- package/dist/cjs/routes/meta-ping.js +11 -11
- package/dist/cjs/routes/meta-stats.js +27 -27
- package/dist/cjs/routes/meta.js +19 -19
- package/dist/cjs/routes/oauth2-init.js +54 -54
- package/dist/cjs/routes/oauth2-refresh.js +42 -42
- package/dist/cjs/routes/oauth2-signin.js +265 -265
- package/dist/cjs/routes/webmanager.js +26 -26
- package/dist/cjs/rules.js +380 -167
- package/dist/cjs/sandbox.js +28 -0
- package/dist/cjs/schema/user.js +24 -24
- package/dist/cjs/server.js +415 -407
- package/dist/cjs/settings/email.js +2 -2
- package/dist/cjs/settings/index.js +175 -172
- package/dist/cjs/shared/clients.js +26 -26
- package/dist/cjs/shared/email.js +2 -2
- package/dist/cjs/shared/env.js +2 -2
- package/dist/cjs/shared/error.js +33 -33
- package/dist/cjs/shared/http.js +28 -28
- package/dist/cjs/shared/password.js +45 -45
- package/dist/cjs/shared/rootpath.js +16 -16
- package/dist/cjs/shared/signin.js +143 -143
- package/dist/cjs/shared/simple-fetch.js +76 -76
- package/dist/cjs/shared/tokens.js +79 -79
- package/dist/cjs/shared/validate.js +61 -61
- package/dist/cjs/start.js +53 -53
- package/dist/cjs/test.js +10 -10
- package/dist/cjs/websocket/index.js +331 -319
- package/dist/cjs/websocket/manager.js +15 -15
- package/dist/cjs/websocket/socket.io.js +76 -76
- package/dist/esm/auth.js +75 -75
- package/dist/esm/cluster.js +54 -54
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/logger.js +51 -51
- package/dist/esm/middleware/404.js +10 -10
- package/dist/esm/middleware/admin-only.js +24 -24
- package/dist/esm/middleware/cache.js +10 -10
- package/dist/esm/middleware/connection.js +45 -45
- package/dist/esm/middleware/context.js +16 -16
- package/dist/esm/middleware/cors.js +44 -44
- package/dist/esm/middleware/swagger.js +13 -13
- package/dist/esm/middleware/user.js +44 -44
- package/dist/esm/oauth-providers/dropbox.js +90 -90
- package/dist/esm/oauth-providers/facebook.js +66 -66
- package/dist/esm/oauth-providers/google.js +96 -96
- package/dist/esm/oauth-providers/index.js +18 -18
- package/dist/esm/oauth-providers/instagram.js +61 -61
- package/dist/esm/oauth-providers/oauth-provider.js +16 -16
- package/dist/esm/oauth-providers/spotify.js +92 -92
- package/dist/esm/routes/auth-change-password.js +72 -72
- package/dist/esm/routes/auth-delete.js +37 -37
- package/dist/esm/routes/auth-forgot-password.js +62 -62
- package/dist/esm/routes/auth-reset-password.js +81 -81
- package/dist/esm/routes/auth-signin.js +33 -33
- package/dist/esm/routes/auth-signout.js +47 -47
- package/dist/esm/routes/auth-signup.js +127 -127
- package/dist/esm/routes/auth-state.js +12 -12
- package/dist/esm/routes/auth-update.js +116 -116
- package/dist/esm/routes/auth-verify-email.js +57 -57
- package/dist/esm/routes/auth.js +53 -50
- package/dist/esm/routes/data-exists.js +20 -20
- package/dist/esm/routes/data-export.js +35 -35
- package/dist/esm/routes/data-get.js +56 -52
- package/dist/esm/routes/data-import.js +41 -41
- package/dist/esm/routes/data-index-create.js +28 -28
- package/dist/esm/routes/data-index-delete.js +20 -20
- package/dist/esm/routes/data-index-list.js +18 -18
- package/dist/esm/routes/data-query.js +66 -56
- package/dist/esm/routes/data-reflect.js +83 -72
- package/dist/esm/routes/data-schema-get.js +23 -23
- package/dist/esm/routes/data-schema-set.js +17 -17
- package/dist/esm/routes/data-schema-test.js +29 -29
- package/dist/esm/routes/data-schemas-list.js +19 -19
- package/dist/esm/routes/data-set.js +70 -60
- package/dist/esm/routes/data-sync-changes.js +67 -53
- package/dist/esm/routes/data-sync-mutations.js +67 -53
- package/dist/esm/routes/data-transaction.js +142 -123
- package/dist/esm/routes/data-update.js +71 -60
- package/dist/esm/routes/data.js +58 -58
- package/dist/esm/routes/docs.js +252 -245
- package/dist/esm/routes/meta-info.js +59 -59
- package/dist/esm/routes/meta-logs.js +35 -35
- package/dist/esm/routes/meta-ping.js +7 -7
- package/dist/esm/routes/meta-stats.js +14 -14
- package/dist/esm/routes/meta.js +15 -15
- package/dist/esm/routes/oauth2-init.js +41 -41
- package/dist/esm/routes/oauth2-refresh.js +29 -29
- package/dist/esm/routes/oauth2-signin.js +251 -251
- package/dist/esm/routes/webmanager.js +22 -22
- package/dist/esm/rules.js +374 -163
- package/dist/esm/sandbox.js +12 -0
- package/dist/esm/schema/user.js +19 -19
- package/dist/esm/server.js +395 -387
- package/dist/esm/settings/email.js +1 -1
- package/dist/esm/settings/index.js +168 -165
- package/dist/esm/shared/clients.js +22 -22
- package/dist/esm/shared/email.js +1 -1
- package/dist/esm/shared/env.js +1 -1
- package/dist/esm/shared/error.js +25 -25
- package/dist/esm/shared/http.js +22 -22
- package/dist/esm/shared/password.js +38 -38
- package/dist/esm/shared/rootpath.js +13 -13
- package/dist/esm/shared/signin.js +128 -128
- package/dist/esm/shared/simple-fetch.js +59 -59
- package/dist/esm/shared/tokens.js +72 -72
- package/dist/esm/shared/validate.js +41 -41
- package/dist/esm/start.js +50 -50
- package/dist/esm/test.js +8 -8
- package/dist/esm/websocket/index.js +313 -302
- package/dist/esm/websocket/manager.js +11 -11
- package/dist/esm/websocket/socket.io.js +71 -71
- package/dist/types/auth.d.ts +3 -3
- package/dist/types/cluster.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger.d.ts +35 -35
- package/dist/types/middleware/404.d.ts +7 -7
- package/dist/types/middleware/admin-only.d.ts +19 -19
- package/dist/types/middleware/cache.d.ts +3 -3
- package/dist/types/middleware/connection.d.ts +7 -7
- package/dist/types/middleware/context.d.ts +3 -3
- package/dist/types/middleware/cors.d.ts +25 -25
- package/dist/types/middleware/swagger.d.ts +3 -3
- package/dist/types/middleware/user.d.ts +2 -2
- package/dist/types/oauth-providers/dropbox.d.ts +52 -52
- package/dist/types/oauth-providers/facebook.d.ts +41 -41
- package/dist/types/oauth-providers/google.d.ts +43 -43
- package/dist/types/oauth-providers/index.d.ts +10 -10
- package/dist/types/oauth-providers/instagram.d.ts +50 -50
- package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
- package/dist/types/oauth-providers/spotify.d.ts +53 -53
- package/dist/types/routes/auth-change-password.d.ts +20 -20
- package/dist/types/routes/auth-delete.d.ts +16 -16
- package/dist/types/routes/auth-forgot-password.d.ts +16 -16
- package/dist/types/routes/auth-reset-password.d.ts +23 -23
- package/dist/types/routes/auth-signin.d.ts +24 -24
- package/dist/types/routes/auth-signout.d.ts +14 -14
- package/dist/types/routes/auth-signup.d.ts +32 -32
- package/dist/types/routes/auth-state.d.ts +13 -13
- package/dist/types/routes/auth-update.d.ts +33 -33
- package/dist/types/routes/auth-verify-email.d.ts +21 -21
- package/dist/types/routes/auth.d.ts +6 -6
- package/dist/types/routes/data-exists.d.ts +9 -9
- package/dist/types/routes/data-export.d.ts +10 -10
- package/dist/types/routes/data-get.d.ts +14 -14
- package/dist/types/routes/data-import.d.ts +13 -13
- package/dist/types/routes/data-index-create.d.ts +51 -51
- package/dist/types/routes/data-index-delete.d.ts +17 -17
- package/dist/types/routes/data-index-list.d.ts +21 -21
- package/dist/types/routes/data-query.d.ts +49 -49
- package/dist/types/routes/data-reflect.d.ts +29 -29
- package/dist/types/routes/data-schema-get.d.ts +11 -11
- package/dist/types/routes/data-schema-set.d.ts +19 -19
- package/dist/types/routes/data-schema-test.d.ts +19 -19
- package/dist/types/routes/data-schemas-list.d.ts +11 -11
- package/dist/types/routes/data-set.d.ts +27 -27
- package/dist/types/routes/data-sync-changes.d.ts +25 -28
- package/dist/types/routes/data-sync-mutations.d.ts +25 -28
- package/dist/types/routes/data-transaction.d.ts +34 -34
- package/dist/types/routes/data-update.d.ts +27 -27
- package/dist/types/routes/data.d.ts +3 -3
- package/dist/types/routes/docs.d.ts +3 -3
- package/dist/types/routes/meta-info.d.ts +11 -11
- package/dist/types/routes/meta-logs.d.ts +20 -20
- package/dist/types/routes/meta-ping.d.ts +7 -7
- package/dist/types/routes/meta-stats.d.ts +13 -13
- package/dist/types/routes/meta.d.ts +3 -3
- package/dist/types/routes/oauth2-init.d.ts +13 -13
- package/dist/types/routes/oauth2-refresh.d.ts +17 -17
- package/dist/types/routes/oauth2-signin.d.ts +15 -15
- package/dist/types/routes/webmanager.d.ts +3 -3
- package/dist/types/rules.d.ts +73 -34
- package/dist/types/sandbox.d.ts +3 -0
- package/dist/types/schema/user.d.ts +85 -85
- package/dist/types/server.d.ts +117 -111
- package/dist/types/settings/email.d.ts +14 -14
- package/dist/types/settings/index.d.ts +195 -187
- package/dist/types/shared/clients.d.ts +46 -46
- package/dist/types/shared/email.d.ts +34 -34
- package/dist/types/shared/env.d.ts +47 -44
- package/dist/types/shared/error.d.ts +15 -15
- package/dist/types/shared/http.d.ts +22 -21
- package/dist/types/shared/password.d.ts +19 -19
- package/dist/types/shared/rootpath.d.ts +2 -2
- package/dist/types/shared/signin.d.ts +31 -31
- package/dist/types/shared/simple-fetch.d.ts +21 -21
- package/dist/types/shared/tokens.d.ts +24 -24
- package/dist/types/shared/validate.d.ts +22 -22
- package/dist/types/start.d.ts +1 -1
- package/dist/types/test.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +6 -6
- package/dist/types/websocket/manager.d.ts +99 -99
- package/dist/types/websocket/socket.io.d.ts +10 -10
- package/package.json +4 -4
- package/src/routes/data-set.yaml +5 -5
- package/src/routes/data-update.yaml +4 -4
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const error_1 = require("../shared/error");
|
|
14
|
-
const addRoute = (env) => {
|
|
15
|
-
env.
|
|
16
|
-
// Import API
|
|
17
|
-
const path = req.path.slice(env.db.name.length + 9);
|
|
18
|
-
const access = env.rules.
|
|
19
|
-
if (!access.allow) {
|
|
20
|
-
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
21
|
-
}
|
|
22
|
-
const format = req.query.format || 'json';
|
|
23
|
-
const suppress_events = req.query.suppress_events === '1';
|
|
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 = (length) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
let chunk = req.read();
|
|
29
|
-
if (chunk === null && !eof) {
|
|
30
|
-
yield new Promise(resolve => req.once('readable', resolve));
|
|
31
|
-
chunk = req.read();
|
|
32
|
-
}
|
|
33
|
-
// env.debug.verbose(`Received chunk: `, chunk);
|
|
34
|
-
return chunk;
|
|
35
|
-
});
|
|
36
|
-
const ref = env.db.ref(path);
|
|
37
|
-
try {
|
|
38
|
-
yield ref.import(read, { format, suppress_events });
|
|
39
|
-
res.send({ success: true });
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
env.debug.error(`Error importing data for path "/${path}": `, err);
|
|
43
|
-
if (!res.headersSent) {
|
|
44
|
-
res.statusCode = 500;
|
|
45
|
-
res.send({ success: false, reason: err.message });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
res.end();
|
|
50
|
-
}
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
|
-
exports.addRoute = addRoute;
|
|
54
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const error_1 = require("../shared/error");
|
|
14
|
+
const addRoute = (env) => {
|
|
15
|
+
env.router.post(`/import/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
// Import API
|
|
17
|
+
const path = req.path.slice(env.db.name.length + 9);
|
|
18
|
+
const access = yield env.rules.isOperationAllowed(req.user, path, 'import', { context: req.context });
|
|
19
|
+
if (!access.allow) {
|
|
20
|
+
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
21
|
+
}
|
|
22
|
+
const format = req.query.format || 'json';
|
|
23
|
+
const suppress_events = req.query.suppress_events === '1';
|
|
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 = (length) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
let chunk = req.read();
|
|
29
|
+
if (chunk === null && !eof) {
|
|
30
|
+
yield new Promise(resolve => req.once('readable', resolve));
|
|
31
|
+
chunk = req.read();
|
|
32
|
+
}
|
|
33
|
+
// env.debug.verbose(`Received chunk: `, chunk);
|
|
34
|
+
return chunk;
|
|
35
|
+
});
|
|
36
|
+
const ref = env.db.ref(path);
|
|
37
|
+
try {
|
|
38
|
+
yield ref.import(read, { format, suppress_events });
|
|
39
|
+
res.send({ success: true });
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
env.debug.error(`Error importing data for path "/${path}": `, err);
|
|
43
|
+
if (!res.headersSent) {
|
|
44
|
+
res.statusCode = 500;
|
|
45
|
+
res.send({ success: false, reason: err.message });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
res.end();
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
exports.addRoute = addRoute;
|
|
54
|
+
exports.default = exports.addRoute;
|
|
55
55
|
//# sourceMappingURL=data-import.js.map
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const addRoute = (env) => {
|
|
16
|
-
const handleRequest = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
try {
|
|
18
|
-
const data = req.body;
|
|
19
|
-
yield env.db.indexes.create(data.path, data.key, data.options);
|
|
20
|
-
res.contentType('application/json').send({ success: true });
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
env.debug.error(`failed to perform index action`, err);
|
|
24
|
-
(0, error_1.sendError)(res, err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
env.
|
|
28
|
-
var _a;
|
|
29
|
-
// Legacy endpoint that was designed to handle multiple actions
|
|
30
|
-
// The only action ever implemented was 'create', so we'll handle that here
|
|
31
|
-
if (((_a = req.body) === null || _a === void 0 ? void 0 : _a.action) !== 'create') {
|
|
32
|
-
return (0, error_1.sendError)(res, { code: 'invalid_action', message: 'Invalid action' });
|
|
33
|
-
}
|
|
34
|
-
handleRequest(req, res);
|
|
35
|
-
}));
|
|
36
|
-
env.
|
|
37
|
-
// New dedicated create endpoint
|
|
38
|
-
handleRequest(req, res);
|
|
39
|
-
}));
|
|
40
|
-
};
|
|
41
|
-
exports.addRoute = addRoute;
|
|
42
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const addRoute = (env) => {
|
|
16
|
+
const handleRequest = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
const data = req.body;
|
|
19
|
+
yield env.db.indexes.create(data.path, data.key, data.options);
|
|
20
|
+
res.contentType('application/json').send({ success: true });
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
env.debug.error(`failed to perform index action`, err);
|
|
24
|
+
(0, error_1.sendError)(res, err);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
env.router.post(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
var _a;
|
|
29
|
+
// Legacy endpoint that was designed to handle multiple actions
|
|
30
|
+
// The only action ever implemented was 'create', so we'll handle that here
|
|
31
|
+
if (((_a = req.body) === null || _a === void 0 ? void 0 : _a.action) !== 'create') {
|
|
32
|
+
return (0, error_1.sendError)(res, { code: 'invalid_action', message: 'Invalid action' });
|
|
33
|
+
}
|
|
34
|
+
handleRequest(req, res);
|
|
35
|
+
}));
|
|
36
|
+
env.router.post(`/index/${env.db.name}/create`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
// New dedicated create endpoint
|
|
38
|
+
handleRequest(req, res);
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
exports.addRoute = addRoute;
|
|
42
|
+
exports.default = exports.addRoute;
|
|
43
43
|
//# sourceMappingURL=data-index-create.js.map
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const addRoute = (env) => {
|
|
16
|
-
env.
|
|
17
|
-
// Delete an index
|
|
18
|
-
try {
|
|
19
|
-
const data = req.body;
|
|
20
|
-
if (!data.fileName) {
|
|
21
|
-
throw new Error('fileName not given');
|
|
22
|
-
}
|
|
23
|
-
yield env.db.indexes.delete(data.fileName); // Requires newer acebase & acebase-core packages
|
|
24
|
-
res.contentType('application/json').send({ success: true });
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
env.debug.error(`failed to perform index action`, err);
|
|
28
|
-
(0, error_1.sendError)(res, err);
|
|
29
|
-
}
|
|
30
|
-
}));
|
|
31
|
-
};
|
|
32
|
-
exports.addRoute = addRoute;
|
|
33
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const addRoute = (env) => {
|
|
16
|
+
env.router.post(`/index/${env.db.name}/delete`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
// Delete an index
|
|
18
|
+
try {
|
|
19
|
+
const data = req.body;
|
|
20
|
+
if (!data.fileName) {
|
|
21
|
+
throw new Error('fileName not given');
|
|
22
|
+
}
|
|
23
|
+
yield env.db.indexes.delete(data.fileName); // Requires newer acebase & acebase-core packages
|
|
24
|
+
res.contentType('application/json').send({ success: true });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
env.debug.error(`failed to perform index action`, err);
|
|
28
|
+
(0, error_1.sendError)(res, err);
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
exports.addRoute = addRoute;
|
|
33
|
+
exports.default = exports.addRoute;
|
|
34
34
|
//# sourceMappingURL=data-index-delete.js.map
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const addRoute = (env) => {
|
|
16
|
-
env.
|
|
17
|
-
// Get all indexes
|
|
18
|
-
try {
|
|
19
|
-
const indexes = yield env.db.indexes.get();
|
|
20
|
-
res.contentType('application/json').send(indexes.map(index => {
|
|
21
|
-
const { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description } = index;
|
|
22
|
-
return { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description };
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
catch (err) {
|
|
26
|
-
(0, error_1.sendError)(res, err);
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
|
-
};
|
|
30
|
-
exports.addRoute = addRoute;
|
|
31
|
-
exports.default = exports.addRoute;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const addRoute = (env) => {
|
|
16
|
+
env.router.get(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
// Get all indexes
|
|
18
|
+
try {
|
|
19
|
+
const indexes = yield env.db.indexes.get();
|
|
20
|
+
res.contentType('application/json').send(indexes.map(index => {
|
|
21
|
+
const { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description } = index;
|
|
22
|
+
return { path, key, caseSensitive, textLocale, includeKeys, indexMetadataKeys, type, fileName, description };
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
(0, error_1.sendError)(res, err);
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
exports.addRoute = addRoute;
|
|
31
|
+
exports.default = exports.addRoute;
|
|
32
32
|
//# sourceMappingURL=data-index-list.js.map
|
|
@@ -1,71 +1,81 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addRoute = void 0;
|
|
13
|
-
const acebase_core_1 = require("acebase-core");
|
|
14
|
-
const error_1 = require("../shared/error");
|
|
15
|
-
const addRoute = (env) => {
|
|
16
|
-
env.
|
|
17
|
-
var _a;
|
|
18
|
-
// Execute query
|
|
19
|
-
const path = req.path.slice(env.db.name.length + 8);
|
|
20
|
-
const access = env.rules.
|
|
21
|
-
if (!access.allow) {
|
|
22
|
-
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
23
|
-
}
|
|
24
|
-
const data = acebase_core_1.Transport.deserialize(req.body);
|
|
25
|
-
if (typeof data !== 'object' || typeof data.query !== 'object' || typeof data.options !== 'object') {
|
|
26
|
-
return (0, error_1.sendError)(res, { code: 'invalid_request', message: 'Invalid query request' });
|
|
27
|
-
}
|
|
28
|
-
const query = data.query;
|
|
29
|
-
const options = data.options;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
client
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const acebase_core_1 = require("acebase-core");
|
|
14
|
+
const error_1 = require("../shared/error");
|
|
15
|
+
const addRoute = (env) => {
|
|
16
|
+
env.router.post(`/query/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
var _a;
|
|
18
|
+
// Execute query
|
|
19
|
+
const path = req.path.slice(env.db.name.length + 8);
|
|
20
|
+
const access = yield env.rules.isOperationAllowed(req.user, path, 'query', { context: req.context });
|
|
21
|
+
if (!access.allow) {
|
|
22
|
+
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
23
|
+
}
|
|
24
|
+
const data = acebase_core_1.Transport.deserialize(req.body);
|
|
25
|
+
if (typeof data !== 'object' || typeof data.query !== 'object' || typeof data.options !== 'object') {
|
|
26
|
+
return (0, error_1.sendError)(res, { code: 'invalid_request', message: 'Invalid query request' });
|
|
27
|
+
}
|
|
28
|
+
const query = data.query;
|
|
29
|
+
const options = data.options;
|
|
30
|
+
let cancelSubscription;
|
|
31
|
+
if (options.monitor === true) {
|
|
32
|
+
options.monitor = { add: true, change: true, remove: true };
|
|
33
|
+
}
|
|
34
|
+
if (typeof options.monitor === 'object' && (options.monitor.add || options.monitor.change || options.monitor.remove)) {
|
|
35
|
+
const queryId = data.query_id;
|
|
36
|
+
const clientId = data.client_id;
|
|
37
|
+
const client = env.clients.get(clientId);
|
|
38
|
+
client.realtimeQueries[queryId] = { path, query, options };
|
|
39
|
+
const sendEvent = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
try {
|
|
41
|
+
const client = env.clients.get(clientId);
|
|
42
|
+
if (!client) {
|
|
43
|
+
return cancelSubscription === null || cancelSubscription === void 0 ? void 0 : cancelSubscription();
|
|
44
|
+
} // Not connected, stop subscription
|
|
45
|
+
if (!(yield env.rules.isOperationAllowed(client.user, event.path, 'get', { context: req.context, value: event.value })).allow) {
|
|
46
|
+
return cancelSubscription === null || cancelSubscription === void 0 ? void 0 : cancelSubscription(); // Access denied, stop subscription
|
|
47
|
+
}
|
|
48
|
+
event.query_id = queryId;
|
|
49
|
+
const data = acebase_core_1.Transport.serialize(event);
|
|
50
|
+
client.socket.emit('query-event', data);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
env.debug.error(`Unexpected error orccured trying to send event`);
|
|
54
|
+
env.debug.error(err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
options.eventHandler = (event) => {
|
|
58
|
+
sendEvent(event);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const { results, context, stop } = yield env.db.api.query(path, query, options);
|
|
63
|
+
cancelSubscription = stop;
|
|
64
|
+
if (!((_a = env.config.transactions) === null || _a === void 0 ? void 0 : _a.log)) {
|
|
65
|
+
delete context.acebase_cursor;
|
|
66
|
+
}
|
|
67
|
+
const response = {
|
|
68
|
+
count: results.length,
|
|
69
|
+
list: results, // []
|
|
70
|
+
};
|
|
71
|
+
res.setHeader('AceBase-Context', JSON.stringify(context));
|
|
72
|
+
res.send(acebase_core_1.Transport.serialize(response));
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
(0, error_1.sendError)(res, { code: 'unknown', message: err.message });
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
exports.addRoute = addRoute;
|
|
80
|
+
exports.default = exports.addRoute;
|
|
71
81
|
//# sourceMappingURL=data-query.js.map
|