acebase-server 1.10.1 → 1.11.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/dist/cjs/index.js +16 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/oauth-providers/dropbox.js +3 -2
- package/dist/cjs/oauth-providers/dropbox.js.map +1 -1
- package/dist/cjs/oauth-providers/facebook.js +3 -2
- package/dist/cjs/oauth-providers/facebook.js.map +1 -1
- package/dist/cjs/oauth-providers/google.js +3 -2
- package/dist/cjs/oauth-providers/google.js.map +1 -1
- package/dist/cjs/oauth-providers/index.js.map +1 -1
- package/dist/cjs/oauth-providers/instagram.js +3 -2
- package/dist/cjs/oauth-providers/instagram.js.map +1 -1
- package/dist/cjs/oauth-providers/oauth-provider.js +23 -0
- package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -1
- package/dist/cjs/oauth-providers/spotify.js +3 -2
- package/dist/cjs/oauth-providers/spotify.js.map +1 -1
- package/dist/cjs/routes/data-set.js +3 -0
- package/dist/cjs/routes/data-set.js.map +1 -1
- package/dist/cjs/routes/data-sync-changes.js.map +1 -1
- package/dist/cjs/routes/data-sync-mutations.js.map +1 -1
- package/dist/cjs/routes/data-transaction.js +16 -3
- package/dist/cjs/routes/data-transaction.js.map +1 -1
- package/dist/cjs/routes/data-update.js +3 -0
- package/dist/cjs/routes/data-update.js.map +1 -1
- package/dist/cjs/routes/meta-info.js.map +1 -1
- package/dist/cjs/routes/oauth2-signin.js +6 -5
- package/dist/cjs/routes/oauth2-signin.js.map +1 -1
- package/dist/cjs/rules.js +5 -5
- package/dist/cjs/rules.js.map +1 -1
- package/dist/cjs/server.js +3 -3
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/settings/index.js +6 -7
- package/dist/cjs/settings/index.js.map +1 -1
- package/dist/cjs/shared/clients.js.map +1 -1
- package/dist/cjs/shared/http.js.map +1 -1
- package/dist/cjs/websocket/index.js +3 -3
- package/dist/cjs/websocket/index.js.map +1 -1
- package/dist/cjs/websocket/socket.io.js +8 -11
- package/dist/cjs/websocket/socket.io.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/oauth-providers/dropbox.js +3 -2
- package/dist/esm/oauth-providers/dropbox.js.map +1 -1
- package/dist/esm/oauth-providers/facebook.js +3 -2
- package/dist/esm/oauth-providers/facebook.js.map +1 -1
- package/dist/esm/oauth-providers/google.js +3 -2
- package/dist/esm/oauth-providers/google.js.map +1 -1
- package/dist/esm/oauth-providers/index.js.map +1 -1
- package/dist/esm/oauth-providers/instagram.js +3 -2
- package/dist/esm/oauth-providers/instagram.js.map +1 -1
- package/dist/esm/oauth-providers/oauth-provider.js +21 -1
- package/dist/esm/oauth-providers/oauth-provider.js.map +1 -1
- package/dist/esm/oauth-providers/spotify.js +3 -2
- package/dist/esm/oauth-providers/spotify.js.map +1 -1
- package/dist/esm/routes/data-set.js +3 -0
- package/dist/esm/routes/data-set.js.map +1 -1
- package/dist/esm/routes/data-sync-changes.js.map +1 -1
- package/dist/esm/routes/data-sync-mutations.js.map +1 -1
- package/dist/esm/routes/data-transaction.js +16 -3
- package/dist/esm/routes/data-transaction.js.map +1 -1
- package/dist/esm/routes/data-update.js +3 -0
- package/dist/esm/routes/data-update.js.map +1 -1
- package/dist/esm/routes/meta-info.js.map +1 -1
- package/dist/esm/routes/oauth2-signin.js +6 -5
- package/dist/esm/routes/oauth2-signin.js.map +1 -1
- package/dist/esm/rules.js +5 -5
- package/dist/esm/rules.js.map +1 -1
- package/dist/esm/server.js +3 -3
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/settings/index.js +5 -6
- package/dist/esm/settings/index.js.map +1 -1
- package/dist/esm/shared/clients.js.map +1 -1
- package/dist/esm/shared/http.js.map +1 -1
- package/dist/esm/websocket/index.js +3 -3
- package/dist/esm/websocket/index.js.map +1 -1
- package/dist/esm/websocket/socket.io.js +9 -11
- package/dist/esm/websocket/socket.io.js.map +1 -1
- package/dist/types/index.d.ts +2 -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/rules.d.ts +2 -2
- 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 +3 -3
- package/dist/types/shared/http.d.ts +2 -0
- package/dist/types/websocket/manager.d.ts +1 -1
- package/package.json +7 -7
- package/src/index.ts +3 -1
- package/src/oauth-providers/dropbox.ts +5 -4
- package/src/oauth-providers/facebook.ts +5 -4
- package/src/oauth-providers/google.ts +5 -4
- package/src/oauth-providers/index.ts +2 -1
- package/src/oauth-providers/instagram.ts +5 -4
- package/src/oauth-providers/oauth-provider.ts +14 -4
- package/src/oauth-providers/spotify.ts +5 -4
- package/src/placeholder.d.ts +12 -0
- package/src/routes/data-query.ts +1 -1
- package/src/routes/data-set.ts +4 -0
- package/src/routes/data-set.yaml +7 -1
- package/src/routes/data-sync-changes.ts +1 -1
- package/src/routes/data-sync-mutations.ts +1 -1
- package/src/routes/data-transaction-finish.yaml +6 -0
- package/src/routes/data-transaction.ts +21 -6
- package/src/routes/data-update.ts +4 -0
- package/src/routes/data-update.yaml +7 -1
- package/src/routes/meta-info.ts +1 -1
- package/src/routes/oauth2-signin.ts +6 -5
- package/src/rules.ts +7 -7
- package/src/server.ts +10 -8
- package/src/settings/email.ts +1 -1
- package/src/settings/index.ts +7 -6
- package/src/shared/clients.ts +1 -1
- package/src/shared/env.ts +3 -3
- package/src/shared/http.ts +2 -0
- package/src/websocket/index.ts +3 -3
- package/src/websocket/manager.ts +1 -1
- package/src/websocket/socket.io.ts +9 -10
- package/webmanager/acebase-client-browser.min.js +16 -0
- package/webmanager/index.html +2 -2
- package/webmanager/index.js +3 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SchemaValidationError } from 'acebase';
|
|
2
2
|
import { ID, Transport } from 'acebase-core';
|
|
3
|
+
import { Api } from 'acebase-core/src/api';
|
|
3
4
|
import { SerializedValue } from 'acebase-core/types/transport';
|
|
4
5
|
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
5
6
|
import { sendBadRequestError, sendError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
|
|
@@ -34,7 +35,7 @@ export type FinishResponseBody = 'done' // 200
|
|
|
34
35
|
|
|
35
36
|
export type FinishRequest = RouteRequest<any, FinishResponseBody, FinishRequestBody, FinishRequestQuery>;
|
|
36
37
|
|
|
37
|
-
type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) =>
|
|
38
|
+
type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => ReturnType<Api['transaction']>; timeout: NodeJS.Timeout };
|
|
38
39
|
|
|
39
40
|
export const addRoutes = (env: RouteInitEnvironment) => {
|
|
40
41
|
|
|
@@ -69,7 +70,7 @@ export const addRoutes = (env: RouteInitEnvironment) => {
|
|
|
69
70
|
const donePromise = env.db.api.transaction(tx.path, val => {
|
|
70
71
|
env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
|
|
71
72
|
const currentValue = Transport.serialize(val);
|
|
72
|
-
const promise = new Promise((resolve) => {
|
|
73
|
+
const promise = new Promise<any>((resolve) => {
|
|
73
74
|
tx.finish = (val: any) => {
|
|
74
75
|
env.debug.verbose(`Transaction ${tx.id} finishing with value: `, val);
|
|
75
76
|
_transactions.delete(tx.id);
|
|
@@ -108,17 +109,31 @@ export const addRoutes = (env: RouteInitEnvironment) => {
|
|
|
108
109
|
|
|
109
110
|
// Finish transaction
|
|
110
111
|
try {
|
|
111
|
-
|
|
112
|
+
let cancel = false;
|
|
113
|
+
if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
|
|
114
|
+
// Returning undefined from a transaction callback should cancel the transaction
|
|
115
|
+
// acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
|
|
116
|
+
// then is sent to the server as an empty object: {}
|
|
117
|
+
cancel = true;
|
|
118
|
+
}
|
|
119
|
+
else if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
|
|
112
120
|
throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
113
121
|
}
|
|
114
|
-
const newValue = Transport.deserialize(data.value);
|
|
122
|
+
const newValue = cancel ? undefined : Transport.deserialize(data.value);
|
|
115
123
|
|
|
116
124
|
if (tx.path === '' && req.user?.uid !== 'admin' && newValue !== null && typeof newValue === 'object') {
|
|
117
125
|
// Non-admin user: remove any private properties from the update object
|
|
118
126
|
Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
|
|
119
127
|
}
|
|
120
128
|
|
|
121
|
-
|
|
129
|
+
|
|
130
|
+
const result = await tx.finish(newValue);
|
|
131
|
+
|
|
132
|
+
// NEW: capture cursor and return it in the response context header
|
|
133
|
+
if (!tx.context) { tx.context = {}; }
|
|
134
|
+
tx.context.acebase_cursor = result.cursor;
|
|
135
|
+
res.setHeader('AceBase-Context', JSON.stringify(tx.context));
|
|
136
|
+
|
|
122
137
|
res.send('done');
|
|
123
138
|
}
|
|
124
139
|
catch (err) {
|
|
@@ -137,7 +152,7 @@ export const addRoutes = (env: RouteInitEnvironment) => {
|
|
|
137
152
|
sendError(res, err);
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
|
-
});
|
|
155
|
+
});
|
|
141
156
|
|
|
142
157
|
};
|
|
143
158
|
|
|
@@ -53,6 +53,10 @@ export const addRoute = (env: RouteInitEnvironment) => {
|
|
|
53
53
|
.context(req.context)
|
|
54
54
|
.update(val);
|
|
55
55
|
|
|
56
|
+
// NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
|
|
57
|
+
const returnContext = { acebase_cursor: req.context.acebase_cursor };
|
|
58
|
+
res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
|
|
59
|
+
|
|
56
60
|
res.send({ success: true });
|
|
57
61
|
}
|
|
58
62
|
catch(err) {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
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
25
|
schema:
|
|
26
26
|
type: string
|
|
27
|
-
example: {}
|
|
27
|
+
example: '{}'
|
|
28
28
|
requestBody:
|
|
29
29
|
description: serialized value to store in the database
|
|
30
30
|
content:
|
|
@@ -36,6 +36,12 @@
|
|
|
36
36
|
description: Returns "200 OK" when the database operation succeeded
|
|
37
37
|
content:
|
|
38
38
|
'application/json':
|
|
39
|
+
headers:
|
|
40
|
+
'AceBase-Context':
|
|
41
|
+
description: Returns contextual information, such as the `acebase_cursor` if transaction logging is enabled on the server.
|
|
42
|
+
schema:
|
|
43
|
+
type: string
|
|
44
|
+
example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
|
|
39
45
|
schema:
|
|
40
46
|
type: object
|
|
41
47
|
properties:
|
package/src/routes/meta-info.ts
CHANGED
|
@@ -58,7 +58,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
|
|
|
58
58
|
total: numberToByteSize(os.totalmem()),
|
|
59
59
|
free: numberToByteSize(os.freemem()),
|
|
60
60
|
process: {
|
|
61
|
-
arrayBuffers: numberToByteSize(mem.arrayBuffers),
|
|
61
|
+
arrayBuffers: numberToByteSize((mem as any).arrayBuffers), // arrayBuffers was added in Node v13.9.0, v12.17.0
|
|
62
62
|
external: numberToByteSize(mem.external),
|
|
63
63
|
heapTotal: numberToByteSize(mem.heapTotal),
|
|
64
64
|
heapUsed: numberToByteSize(mem.heapUsed),
|
|
@@ -58,12 +58,13 @@ export const addRoute = (env: RouteInitEnvironment) => {
|
|
|
58
58
|
if (contentType === 'image/png') { //state.provider === 'google' &&
|
|
59
59
|
// Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials
|
|
60
60
|
user_details.picture = [];
|
|
61
|
-
return;
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
else {
|
|
63
|
+
const image = await response.arrayBuffer();
|
|
64
|
+
let buff = Buffer.from(image);
|
|
65
|
+
best.url = `data:${contentType};base64,${buff.toString('base64')}`;
|
|
66
|
+
user_details.picture = [best]; // Only keep the best one
|
|
67
|
+
}
|
|
67
68
|
}
|
|
68
69
|
catch(err) {
|
|
69
70
|
env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err);
|
package/src/rules.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { AceBase } from 'acebase';
|
|
|
2
2
|
import { DebugLogger, PathInfo } from 'acebase-core';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import { DbUserAccountDetails } from './schema/user';
|
|
5
|
-
import { AUTH_ACCESS_DEFAULT } from './settings';
|
|
5
|
+
import { AUTH_ACCESS_DEFAULT, AuthAccessDefault } from './settings';
|
|
6
6
|
|
|
7
7
|
type PathRuleFunction = ((env: any) => boolean) & { getText(): string };
|
|
8
8
|
type PathRules = {} & {
|
|
@@ -24,7 +24,7 @@ export class PathBasedRules {
|
|
|
24
24
|
private accessRules: RulesData;
|
|
25
25
|
stop(): void { throw new Error('not started yet'); }
|
|
26
26
|
|
|
27
|
-
constructor(rulesFilePath: string, defaultAccess:
|
|
27
|
+
constructor(rulesFilePath: string, defaultAccess: AuthAccessDefault, env: { debug: DebugLogger, db: AceBase, authEnabled: boolean } ) {
|
|
28
28
|
// Reads rules from a file and monitors it
|
|
29
29
|
// Check if there is a rules file, load it or generate default
|
|
30
30
|
|
|
@@ -85,11 +85,11 @@ export class PathBasedRules {
|
|
|
85
85
|
rule.getText = () => {
|
|
86
86
|
return text;
|
|
87
87
|
}
|
|
88
|
-
parent[key] = rule;
|
|
88
|
+
return parent[key] = rule;
|
|
89
89
|
}
|
|
90
90
|
else if (key === '.schema') {
|
|
91
91
|
// Add schema
|
|
92
|
-
env.db.schema.set(path, rule)
|
|
92
|
+
return env.db.schema.set(path, rule)
|
|
93
93
|
.catch(err => {
|
|
94
94
|
env.debug.error(`Error parsing ${path}/.schema: ${err.message}`)
|
|
95
95
|
});
|
|
@@ -105,15 +105,15 @@ export class PathBasedRules {
|
|
|
105
105
|
processRules('', accessRules.rules, []);
|
|
106
106
|
|
|
107
107
|
// Watch file for changes
|
|
108
|
-
const
|
|
108
|
+
const watchFileListener = () => {
|
|
109
109
|
// Reload access rules
|
|
110
110
|
const accessRules = readRules();
|
|
111
111
|
processRules('', accessRules, []);
|
|
112
112
|
this.accessRules = accessRules;
|
|
113
113
|
};
|
|
114
|
-
fs.watchFile(rulesFilePath,
|
|
114
|
+
fs.watchFile(rulesFilePath, watchFileListener);
|
|
115
115
|
this.stop = () => {
|
|
116
|
-
fs.unwatchFile(rulesFilePath,
|
|
116
|
+
fs.unwatchFile(rulesFilePath, watchFileListener);
|
|
117
117
|
}
|
|
118
118
|
process.on('SIGINT', this.stop);
|
|
119
119
|
|
package/src/server.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ColorStyle, DebugLogger, SimpleEventEmitter } from 'acebase-core';
|
|
2
2
|
import { AceBaseServerSettings, AceBaseServerConfig } from './settings';
|
|
3
|
-
import { createApp } from './shared/http';
|
|
3
|
+
import { createApp, HttpRequest, HttpResponse } from './shared/http';
|
|
4
4
|
import { addWebsocketServer } from './websocket';
|
|
5
5
|
import { RouteInitEnvironment } from './shared/env';
|
|
6
6
|
import { ConnectedClient } from './shared/clients';
|
|
7
7
|
import { AceBase, AceBaseLocalSettings, AceBaseStorageSettings } from 'acebase';
|
|
8
8
|
import { createServer } from 'http';
|
|
9
9
|
import { createServer as createSecureServer } from 'https';
|
|
10
|
-
import {
|
|
10
|
+
import { OAuth2Provider } from './oauth-providers/oauth-provider';
|
|
11
11
|
import oAuth2Providers from './oauth-providers';
|
|
12
12
|
import { PathBasedRules } from './rules';
|
|
13
13
|
import { DbUserAccountDetails } from './schema/user';
|
|
@@ -31,6 +31,8 @@ export class AceBaseServerNotReadyError extends Error {
|
|
|
31
31
|
constructor() { super('Server is not ready yet'); }
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
type HttpMethod = 'get'|'GET'|'put'|'PUT'|'post'|'POST'|'delete'|'DELETE';
|
|
35
|
+
|
|
34
36
|
export class AceBaseServer extends SimpleEventEmitter {
|
|
35
37
|
|
|
36
38
|
private _ready: boolean = false;
|
|
@@ -83,7 +85,7 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
83
85
|
*/
|
|
84
86
|
readonly app: ReturnType<typeof createApp>;
|
|
85
87
|
|
|
86
|
-
private readonly authProviders: { [provider: string]:
|
|
88
|
+
private readonly authProviders: { [provider: string]: OAuth2Provider } = {};
|
|
87
89
|
|
|
88
90
|
constructor(dbname: string, options?: AceBaseServerSettings) {
|
|
89
91
|
super();
|
|
@@ -211,7 +213,7 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
211
213
|
addWebManagerRoutes(routeEnv);
|
|
212
214
|
|
|
213
215
|
// Allow adding custom routes
|
|
214
|
-
this.extend = (method:
|
|
216
|
+
this.extend = (method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => any) => {
|
|
215
217
|
const route = `/ext/${db.name}/${ext_path}`;
|
|
216
218
|
this.debug.log(`Extending server: `, method, route);
|
|
217
219
|
routeEnv.app[method.toLowerCase()](route, handler);
|
|
@@ -385,11 +387,11 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
385
387
|
* .then(quote => {
|
|
386
388
|
* console.log(`Got random quote: ${quote}`);
|
|
387
389
|
* })
|
|
388
|
-
* @param
|
|
389
|
-
* @param
|
|
390
|
-
* @param
|
|
390
|
+
* @param method http method to bind to
|
|
391
|
+
* @param ext_path path to bind to (appended to /ext/)
|
|
392
|
+
* @param handler your Express request handler callback
|
|
391
393
|
*/
|
|
392
|
-
|
|
394
|
+
extend(method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => void) {
|
|
393
395
|
throw new AceBaseServerNotReadyError();
|
|
394
396
|
}
|
|
395
397
|
|
package/src/settings/email.ts
CHANGED
|
@@ -14,5 +14,5 @@ export interface AceBaseServerEmailSettings {
|
|
|
14
14
|
server?: AceBaseServerEmailServerSettings;
|
|
15
15
|
|
|
16
16
|
/** function to call when an e-mail needs to be sent */
|
|
17
|
-
send: (request: AceBaseEmailRequest) => Promise<
|
|
17
|
+
send: (request: AceBaseEmailRequest) => Promise<void>;
|
|
18
18
|
};
|
package/src/settings/index.ts
CHANGED
|
@@ -35,11 +35,12 @@ export class AceBaseServerHttpsConfig {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
export type AuthAccessDefault = 'deny'|'allow'|'auth';
|
|
39
|
+
export const AUTH_ACCESS_DEFAULT: { [key: string]: AuthAccessDefault } = {
|
|
40
|
+
DENY_ALL: 'deny',
|
|
41
|
+
ALLOW_ALL: 'allow',
|
|
42
|
+
ALLOW_AUTHENTICATED: 'auth'
|
|
43
|
+
};
|
|
43
44
|
|
|
44
45
|
export class AceBaseServerAuthenticationSettings {
|
|
45
46
|
|
|
@@ -66,7 +67,7 @@ export class AceBaseServerAuthenticationSettings {
|
|
|
66
67
|
/**
|
|
67
68
|
* When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
|
|
68
69
|
*/
|
|
69
|
-
readonly defaultAccessRule:
|
|
70
|
+
readonly defaultAccessRule: AuthAccessDefault = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
* When the server runs for the first time, what password to use for the admin user. If not supplied, a generated password will be used and shown ONCE in the console output.
|
package/src/shared/clients.ts
CHANGED
|
@@ -27,5 +27,5 @@ export class ConnectedClient {
|
|
|
27
27
|
realtimeQueries: { [id: string]: { path: string; query: IApiQuery, options: IApiQueryOptions }} = {};
|
|
28
28
|
|
|
29
29
|
/** Currently running transactions */
|
|
30
|
-
transactions: { [id: string]: { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<
|
|
30
|
+
transactions: { [id: string]: { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<{ cursor?: string }>; timeout: NodeJS.Timeout } } = {};
|
|
31
31
|
}
|
package/src/shared/env.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { AceBaseServerConfig } from '../settings';
|
|
|
4
4
|
import type { DbUserAccountDetails } from '../schema/user';
|
|
5
5
|
import type { ConnectedClient } from './clients';
|
|
6
6
|
import type { DebugLogger, SimpleCache } from 'acebase-core';
|
|
7
|
-
import type {
|
|
7
|
+
import type { OAuth2Provider } from '../oauth-providers/oauth-provider';
|
|
8
8
|
import type { Server as HttpServer } from 'http';
|
|
9
9
|
import type { Server as SecureHttpServer } from 'https';
|
|
10
10
|
import type { PathBasedRules } from '../rules';
|
|
@@ -23,7 +23,7 @@ export interface RouteInitEnvironment {
|
|
|
23
23
|
tokenSalt: string;
|
|
24
24
|
clients: Map<string, ConnectedClient>;
|
|
25
25
|
authCache: SimpleCache<string, DbUserAccountDetails>;
|
|
26
|
-
authProviders: { [providerName: string]:
|
|
26
|
+
authProviders: { [providerName: string]: OAuth2Provider };
|
|
27
27
|
rules: PathBasedRules
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ export interface RouteRequestEnvironment {
|
|
|
32
32
|
user?: DbUserAccountDetails;
|
|
33
33
|
|
|
34
34
|
/** If context is sent through AceBase-Context header, it will be bound to the incoming request */
|
|
35
|
-
context
|
|
35
|
+
context: { [key: string]: any };
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type RouteRequest<Params = any, ResBody = any, ReqBody = any, ReqQuery = any, Locals extends Record<string, any> = Record<string, any>> = Request<Params, ResBody, ReqBody, ReqQuery, Locals> & RouteRequestEnvironment;
|
package/src/shared/http.ts
CHANGED
|
@@ -5,6 +5,8 @@ const createExpress = (express as any).default ?? express; // ESM and CJS compat
|
|
|
5
5
|
|
|
6
6
|
export type HttpApp = express.Express;
|
|
7
7
|
export type HttpSocket = Socket;
|
|
8
|
+
export type HttpRequest = express.Request;
|
|
9
|
+
export type HttpResponse = express.Response;
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Creates an app that handles http requests, adds json body parsing.
|
package/src/websocket/index.ts
CHANGED
|
@@ -299,11 +299,11 @@ export const addWebsocketServer = (env: RouteInitEnvironment) => {
|
|
|
299
299
|
throw new Error('access_denied');
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
const newValue = Transport.deserialize(data.value);
|
|
302
|
+
const newValue = 'val' in data.value ? Transport.deserialize(data.value) : undefined;
|
|
303
303
|
try {
|
|
304
|
-
await tx.finish(newValue);
|
|
304
|
+
const { cursor } = await tx.finish(newValue);
|
|
305
305
|
env.debug.verbose(`Transaction ${tx.id} finished`);
|
|
306
|
-
serverManager.send(event.socket, 'tx_completed', { id: tx.id });
|
|
306
|
+
serverManager.send(event.socket, 'tx_completed', { id: tx.id, context: { cursor } });
|
|
307
307
|
}
|
|
308
308
|
catch (err) {
|
|
309
309
|
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.message });
|
package/src/websocket/manager.ts
CHANGED
|
@@ -31,7 +31,7 @@ export abstract class WebSocketManager<SocketType> extends SimpleEventEmitter {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
emit(event: 'connect', data: WebSocketEventData<SocketType>): void;
|
|
34
|
-
emit(event: 'disconnect', data: WebSocketEventData<SocketType>): void;
|
|
34
|
+
emit(event: 'disconnect', data: WebSocketEventData<SocketType, string>): void;
|
|
35
35
|
/** @deprecated deprecated since client v0.9.4 */
|
|
36
36
|
emit(event: 'signin', data: WebSocketEventData<SocketType, { accessToken: string }>): void;
|
|
37
37
|
/** @deprecated deprecated since client v0.9.4 */
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { Server as SocketIOServer } from 'socket.io';
|
|
2
|
+
import type { ServerOptions as SocketIOServerOptions } from 'socket.io';
|
|
3
|
+
const createSocketIOServer = (httpServer: any, options: Partial<SocketIOServerOptions>) => {
|
|
4
|
+
return new SocketIOServer(httpServer, options);
|
|
5
|
+
}
|
|
3
6
|
|
|
4
7
|
import type { Socket } from 'socket.io';
|
|
5
8
|
import { RouteInitEnvironment } from '../shared/env';
|
|
@@ -42,15 +45,11 @@ export const createServer = (env: RouteInitEnvironment) => {
|
|
|
42
45
|
pingTimeout: 5000, // socket.io 2.x default is 5000, 3.x default = 20000
|
|
43
46
|
maxHttpBufferSize: maxPayloadBytes,
|
|
44
47
|
|
|
45
|
-
// socket.io 2.x:
|
|
46
|
-
|
|
47
|
-
const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
|
|
48
|
-
res.writeHead(200, headers);
|
|
49
|
-
res.end();
|
|
50
|
-
}
|
|
48
|
+
// Allow socket.io 2.x clients (using engine.io 3.x):
|
|
49
|
+
allowEIO3: true,
|
|
51
50
|
|
|
52
51
|
// socket.io 3+ uses cors package:
|
|
53
|
-
|
|
52
|
+
cors: getCorsOptions(env.config.allowOrigin)
|
|
54
53
|
});
|
|
55
54
|
|
|
56
55
|
// Setup event emitter for communication with consuming server
|
|
@@ -64,7 +63,7 @@ export const createServer = (env: RouteInitEnvironment) => {
|
|
|
64
63
|
manager.emit('connect', { socket, socket_id: socket.id });
|
|
65
64
|
|
|
66
65
|
// Pass any events to manager
|
|
67
|
-
socket.on('disconnect',
|
|
66
|
+
socket.on('disconnect', reason => manager.emit('disconnect', { socket, socket_id: socket.id, data: reason }));
|
|
68
67
|
socket.on('reconnect', data => manager.emit('connect', { socket, socket_id: socket.id, data }));
|
|
69
68
|
socket.on('signin', accessToken => manager.emit('signin', { socket, socket_id: socket.id, data: { accessToken } }));
|
|
70
69
|
socket.on('signout', data => manager.emit('signout', { socket, socket_id: socket.id, data }));
|