@evolu/nodejs 1.0.1-preview.10 → 1.0.1-preview.12
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/Evolu/Relay.d.ts.map +1 -1
- package/dist/Evolu/Relay.js +9 -12
- package/package.json +3 -3
- package/src/Evolu/Relay.ts +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../src/Evolu/Relay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,qBAAqB,
|
|
1
|
+
{"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../src/Evolu/Relay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,qBAAqB,EAKrB,MAAM,EAEN,WAAW,EAGZ,MAAM,eAAe,CAAC;AACvB,OAAO,EASL,KAAK,EACL,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAO7B,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC3B,MAAM,UAAU,MAChB,QAAQ,iBAAiB,KAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,CAInD,CAAC;AAEf;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,GAC3C,MAAM,UAAU,GAAG,qBAAqB,MACxC,QAAQ,iBAAiB,KAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,CAKnD,CAAC"}
|
package/dist/Evolu/Relay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createManyToManyMap, createRandom, createSqlite, ok, SimpleName, Uint8Array, } from "@evolu/common";
|
|
1
|
+
import { createManyToManyMap, createRandom, createSqlite, isAsync, ok, SimpleName, Uint8Array, } from "@evolu/common";
|
|
2
2
|
import { applyProtocolMessageAsRelay, createBaseSqliteStorageTables, createRelayLogger, createRelaySqliteStorage, createRelayStorageTables, defaultProtocolMessageMaxSize, parseOwnerIdFromOwnerWebSocketTransportUrl, } from "@evolu/common/evolu";
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
4
|
import { createServer } from "http";
|
|
@@ -27,7 +27,7 @@ export const createNodeJsRelayWithSqliteDriver = (deps) => (config) => createNod
|
|
|
27
27
|
random: createRandom(),
|
|
28
28
|
timingSafeEqual: createTimingSafeEqual(),
|
|
29
29
|
})(config);
|
|
30
|
-
const createNodeJsRelayWithDeps = (deps) => async ({ port = 443, name = SimpleName.orThrow("evolu-relay"), enableLogging = false,
|
|
30
|
+
const createNodeJsRelayWithDeps = (deps) => async ({ port = 443, name = SimpleName.orThrow("evolu-relay"), enableLogging = false, isOwnerAllowed, isOwnerWithinQuota, }) => {
|
|
31
31
|
const log = createRelayLogger(deps);
|
|
32
32
|
log.started(enableLogging, port);
|
|
33
33
|
const dbFileExists = existsSync(`${name}.db`);
|
|
@@ -45,6 +45,7 @@ const createNodeJsRelayWithDeps = (deps) => async ({ port = 443, name = SimpleNa
|
|
|
45
45
|
}
|
|
46
46
|
const storage = createRelaySqliteStorage(depsWithSqlite)({
|
|
47
47
|
onStorageError: log.storageError,
|
|
48
|
+
isOwnerWithinQuota,
|
|
48
49
|
});
|
|
49
50
|
const server = createServer();
|
|
50
51
|
const wss = new WebSocketServer({
|
|
@@ -60,7 +61,7 @@ const createNodeJsRelayWithDeps = (deps) => async ({ port = 443, name = SimpleNa
|
|
|
60
61
|
wss.emit("connection", ws, request);
|
|
61
62
|
});
|
|
62
63
|
};
|
|
63
|
-
if (!
|
|
64
|
+
if (!isOwnerAllowed) {
|
|
64
65
|
completeUpgrade();
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
@@ -71,21 +72,17 @@ const createNodeJsRelayWithDeps = (deps) => async ({ port = 443, name = SimpleNa
|
|
|
71
72
|
socket.destroy();
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
void (async () => {
|
|
76
|
+
const result = isOwnerAllowed(ownerId);
|
|
77
|
+
const isAllowed = isAsync(result) ? await result : result;
|
|
78
|
+
if (!isAllowed) {
|
|
77
79
|
log.unauthorizedOwner(ownerId);
|
|
78
80
|
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
79
81
|
socket.destroy();
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
completeUpgrade();
|
|
83
|
-
})
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
log.authenticateOwnerError(error);
|
|
86
|
-
socket.write("HTTP/1.1 500 Internal Server Error\r\n\r\n");
|
|
87
|
-
socket.destroy();
|
|
88
|
-
});
|
|
85
|
+
})();
|
|
89
86
|
});
|
|
90
87
|
wss.on("connection", (ws) => {
|
|
91
88
|
log.connectionEstablished(wss.clients.size);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evolu/nodejs",
|
|
3
|
-
"version": "1.0.1-preview.
|
|
3
|
+
"version": "1.0.1-preview.12",
|
|
4
4
|
"description": "Evolu for Node.js",
|
|
5
5
|
"author": "Daniel Steigerwald <daniel@steigerwald.cz>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"shx": "^0.4.0",
|
|
31
31
|
"typescript": "^5.9.2",
|
|
32
32
|
"vitest": "^4.0.4",
|
|
33
|
-
"@evolu/common": "6.0.1-preview.
|
|
33
|
+
"@evolu/common": "6.0.1-preview.30",
|
|
34
34
|
"@evolu/tsconfig": "0.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@evolu/common": "^6.0.1-preview.
|
|
37
|
+
"@evolu/common": "^6.0.1-preview.30"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=22.0.0"
|
package/src/Evolu/Relay.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createRandom,
|
|
5
5
|
createSqlite,
|
|
6
6
|
CreateSqliteDriverDep,
|
|
7
|
+
isAsync,
|
|
7
8
|
ok,
|
|
8
9
|
OwnerId,
|
|
9
10
|
RandomDep,
|
|
@@ -72,7 +73,8 @@ const createNodeJsRelayWithDeps =
|
|
|
72
73
|
port = 443,
|
|
73
74
|
name = SimpleName.orThrow("evolu-relay"),
|
|
74
75
|
enableLogging = false,
|
|
75
|
-
|
|
76
|
+
isOwnerAllowed,
|
|
77
|
+
isOwnerWithinQuota,
|
|
76
78
|
}: NodeJsRelayConfig): Promise<Result<Relay, SqliteError>> => {
|
|
77
79
|
const log = createRelayLogger(deps);
|
|
78
80
|
log.started(enableLogging, port);
|
|
@@ -94,6 +96,7 @@ const createNodeJsRelayWithDeps =
|
|
|
94
96
|
|
|
95
97
|
const storage = createRelaySqliteStorage(depsWithSqlite)({
|
|
96
98
|
onStorageError: log.storageError,
|
|
99
|
+
isOwnerWithinQuota,
|
|
97
100
|
});
|
|
98
101
|
|
|
99
102
|
const server = createServer();
|
|
@@ -114,7 +117,7 @@ const createNodeJsRelayWithDeps =
|
|
|
114
117
|
});
|
|
115
118
|
};
|
|
116
119
|
|
|
117
|
-
if (!
|
|
120
|
+
if (!isOwnerAllowed) {
|
|
118
121
|
completeUpgrade();
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
@@ -122,6 +125,7 @@ const createNodeJsRelayWithDeps =
|
|
|
122
125
|
const ownerId = parseOwnerIdFromOwnerWebSocketTransportUrl(
|
|
123
126
|
request.url ?? "",
|
|
124
127
|
);
|
|
128
|
+
|
|
125
129
|
if (!ownerId) {
|
|
126
130
|
log.invalidOrMissingOwnerIdInUrl(request.url);
|
|
127
131
|
socket.write("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
@@ -129,21 +133,17 @@ const createNodeJsRelayWithDeps =
|
|
|
129
133
|
return;
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
completeUpgrade();
|
|
141
|
-
})
|
|
142
|
-
.catch((error: unknown) => {
|
|
143
|
-
log.authenticateOwnerError(error);
|
|
144
|
-
socket.write("HTTP/1.1 500 Internal Server Error\r\n\r\n");
|
|
136
|
+
void (async () => {
|
|
137
|
+
const result = isOwnerAllowed(ownerId);
|
|
138
|
+
const isAllowed = isAsync(result) ? await result : result;
|
|
139
|
+
if (!isAllowed) {
|
|
140
|
+
log.unauthorizedOwner(ownerId);
|
|
141
|
+
socket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
145
142
|
socket.destroy();
|
|
146
|
-
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
completeUpgrade();
|
|
146
|
+
})();
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
wss.on("connection", (ws) => {
|