@based/server 6.8.0 → 7.0.1
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/auth/defaultConfig.js +4 -9
- package/dist/auth/defaultConfig.js.map +1 -1
- package/dist/auth/index.d.ts +3 -3
- package/dist/auth/index.js +21 -24
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseAuthState.js +3 -5
- package/dist/auth/parseAuthState.js.map +1 -1
- package/dist/auth/parseJSONAuthState.js +1 -3
- package/dist/auth/parseJSONAuthState.js.map +1 -1
- package/dist/authorize.d.ts +2 -2
- package/dist/authorize.js +17 -22
- package/dist/authorize.js.map +1 -1
- package/dist/channel/cleanup.d.ts +1 -1
- package/dist/channel/cleanup.js +2 -6
- package/dist/channel/cleanup.js.map +1 -1
- package/dist/channel/create.d.ts +2 -2
- package/dist/channel/create.js +5 -9
- package/dist/channel/create.js.map +1 -1
- package/dist/channel/destroy.d.ts +2 -2
- package/dist/channel/destroy.js +7 -12
- package/dist/channel/destroy.js.map +1 -1
- package/dist/channel/extend.d.ts +3 -3
- package/dist/channel/extend.js +2 -7
- package/dist/channel/extend.js.map +1 -1
- package/dist/channel/get.d.ts +2 -2
- package/dist/channel/get.js +4 -9
- package/dist/channel/get.js.map +1 -1
- package/dist/channel/index.d.ts +8 -8
- package/dist/channel/index.js +8 -24
- package/dist/channel/index.js.map +1 -1
- package/dist/channel/start.d.ts +1 -1
- package/dist/channel/start.js +10 -15
- package/dist/channel/start.js.map +1 -1
- package/dist/channel/subscribe.d.ts +1 -1
- package/dist/channel/subscribe.js +8 -13
- package/dist/channel/subscribe.js.map +1 -1
- package/dist/channel/types.js +1 -2
- package/dist/channel/types.js.map +1 -1
- package/dist/channel/unsub.d.ts +1 -1
- package/dist/channel/unsub.js +7 -13
- package/dist/channel/unsub.js.map +1 -1
- package/dist/compress.d.ts +1 -1
- package/dist/compress.js +9 -16
- package/dist/compress.js.map +1 -1
- package/dist/error/errorTypeHandlers.d.ts +1 -1
- package/dist/error/errorTypeHandlers.js +20 -23
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.d.ts +4 -4
- package/dist/error/index.js +10 -29
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.js +3 -6
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/callFunction.d.ts +1 -1
- package/dist/functionApi/callFunction.js +10 -14
- package/dist/functionApi/callFunction.js.map +1 -1
- package/dist/functionApi/channelSubscribe.d.ts +1 -1
- package/dist/functionApi/channelSubscribe.js +14 -18
- package/dist/functionApi/channelSubscribe.js.map +1 -1
- package/dist/functionApi/client/channel.js +12 -12
- package/dist/functionApi/client/channel.js.map +1 -1
- package/dist/functionApi/client/index.d.ts +4 -4
- package/dist/functionApi/client/index.js +15 -21
- package/dist/functionApi/client/index.js.map +1 -1
- package/dist/functionApi/client/query.d.ts +1 -1
- package/dist/functionApi/client/query.js +9 -10
- package/dist/functionApi/client/query.js.map +1 -1
- package/dist/functionApi/get.d.ts +1 -1
- package/dist/functionApi/get.js +17 -21
- package/dist/functionApi/get.js.map +1 -1
- package/dist/functionApi/index.d.ts +7 -8
- package/dist/functionApi/index.js +7 -26
- package/dist/functionApi/index.js.map +1 -1
- package/dist/functionApi/observe.d.ts +2 -2
- package/dist/functionApi/observe.js +15 -19
- package/dist/functionApi/observe.js.map +1 -1
- package/dist/functionApi/publish.d.ts +1 -1
- package/dist/functionApi/publish.js +7 -11
- package/dist/functionApi/publish.js.map +1 -1
- package/dist/functionApi/stream.d.ts +1 -1
- package/dist/functionApi/stream.js +13 -17
- package/dist/functionApi/stream.js.map +1 -1
- package/dist/functions/genVersion.js +8 -12
- package/dist/functions/genVersion.js.map +1 -1
- package/dist/functions/index.d.ts +5 -4
- package/dist/functions/index.js +54 -59
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.js +2 -7
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +1 -1
- package/dist/functions/types.js +1 -2
- package/dist/incoming/http/function.d.ts +1 -1
- package/dist/incoming/http/function.js +13 -17
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/handleRequest.d.ts +3 -0
- package/dist/incoming/http/handleRequest.js +11 -0
- package/dist/incoming/http/handleRequest.js.map +1 -0
- package/dist/incoming/http/index.d.ts +1 -1
- package/dist/incoming/http/index.js +54 -90
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/parseQuery.d.ts +2 -2
- package/dist/incoming/http/parseQuery.js +9 -8
- package/dist/incoming/http/parseQuery.js.map +1 -1
- package/dist/incoming/http/publish.d.ts +1 -1
- package/dist/incoming/http/publish.js +16 -20
- package/dist/incoming/http/publish.js.map +1 -1
- package/dist/incoming/http/query.d.ts +1 -1
- package/dist/incoming/http/query.js +32 -46
- package/dist/incoming/http/query.js.map +1 -1
- package/dist/incoming/http/readBody.d.ts +1 -1
- package/dist/incoming/http/readBody.js +17 -25
- package/dist/incoming/http/readBody.js.map +1 -1
- package/dist/incoming/http/streamFunction/getExtension.js +3 -8
- package/dist/incoming/http/streamFunction/getExtension.js.map +1 -1
- package/dist/incoming/http/streamFunction/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/index.js +8 -12
- package/dist/incoming/http/streamFunction/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.js +12 -19
- package/dist/incoming/http/streamFunction/multiPart/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/readFormData.d.ts +1 -1
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js +11 -16
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.js +13 -18
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/index.d.ts +1 -1
- package/dist/incoming/http/streamFunction/stream/index.js +19 -26
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +19 -24
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.d.ts +1 -1
- package/dist/incoming/upgrade.js +8 -13
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +2 -2
- package/dist/incoming/ws/auth.js +19 -25
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/channelPublish.d.ts +1 -1
- package/dist/incoming/ws/channelPublish.js +17 -21
- package/dist/incoming/ws/channelPublish.js.map +1 -1
- package/dist/incoming/ws/channelSubscribe.d.ts +2 -2
- package/dist/incoming/ws/channelSubscribe.js +32 -38
- package/dist/incoming/ws/channelSubscribe.js.map +1 -1
- package/dist/incoming/ws/function.d.ts +1 -1
- package/dist/incoming/ws/function.js +23 -27
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.d.ts +1 -1
- package/dist/incoming/ws/get.js +34 -38
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.d.ts +1 -1
- package/dist/incoming/ws/index.js +19 -23
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/query.d.ts +2 -2
- package/dist/incoming/ws/query.js +26 -32
- package/dist/incoming/ws/query.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +1 -1
- package/dist/incoming/ws/types.js +1 -2
- package/dist/index.d.ts +9 -9
- package/dist/index.js +9 -29
- package/dist/index.js.map +1 -1
- package/dist/installFn.d.ts +3 -3
- package/dist/installFn.js +10 -14
- package/dist/installFn.js.map +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +55 -78
- package/dist/protocol.js.map +1 -1
- package/dist/query/cleanup.d.ts +1 -1
- package/dist/query/cleanup.js +2 -6
- package/dist/query/cleanup.js.map +1 -1
- package/dist/query/create.d.ts +2 -2
- package/dist/query/create.js +5 -9
- package/dist/query/create.js.map +1 -1
- package/dist/query/destroy.d.ts +2 -2
- package/dist/query/destroy.js +7 -12
- package/dist/query/destroy.js.map +1 -1
- package/dist/query/extendCache.d.ts +1 -1
- package/dist/query/extendCache.js +1 -5
- package/dist/query/extendCache.js.map +1 -1
- package/dist/query/genObservableId.js +4 -8
- package/dist/query/genObservableId.js.map +1 -1
- package/dist/query/get.d.ts +2 -2
- package/dist/query/get.js +4 -9
- package/dist/query/get.js.map +1 -1
- package/dist/query/index.d.ts +10 -10
- package/dist/query/index.js +10 -26
- package/dist/query/index.js.map +1 -1
- package/dist/query/send.d.ts +2 -2
- package/dist/query/send.js +8 -13
- package/dist/query/send.js.map +1 -1
- package/dist/query/start/error.d.ts +2 -2
- package/dist/query/start/error.js +6 -10
- package/dist/query/start/error.js.map +1 -1
- package/dist/query/start/index.d.ts +1 -1
- package/dist/query/start/index.js +14 -19
- package/dist/query/start/index.js.map +1 -1
- package/dist/query/start/relay.d.ts +2 -2
- package/dist/query/start/relay.js +3 -7
- package/dist/query/start/relay.js.map +1 -1
- package/dist/query/start/update.d.ts +2 -2
- package/dist/query/start/update.js +18 -19
- package/dist/query/start/update.js.map +1 -1
- package/dist/query/subscribe.d.ts +3 -3
- package/dist/query/subscribe.js +13 -19
- package/dist/query/subscribe.js.map +1 -1
- package/dist/query/types.d.ts +1 -1
- package/dist/query/types.js +1 -2
- package/dist/query/unsub.d.ts +2 -2
- package/dist/query/unsub.js +7 -13
- package/dist/query/unsub.js.map +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.js +8 -14
- package/dist/security.js.map +1 -1
- package/dist/sendError.d.ts +2 -2
- package/dist/sendError.js +21 -28
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.d.ts +1 -1
- package/dist/sendHttpResponse.js +11 -17
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +8 -8
- package/dist/server.js +73 -64
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +2 -2
- package/dist/verifyRoute.js +13 -17
- package/dist/verifyRoute.js.map +1 -1
- package/package.json +10 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleRequest.js","sourceRoot":"","sources":["../../../src/incoming/http/handleRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,UAAU,MAAM,iBAAiB,CAAA;AAExC,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAmB,EACnB,MAAc,EACd,GAAyB,EACzB,KAAiB,EACjB,KAA8B,EAC9B,EAAE;IACF,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;KACpC;SAAM;QACL,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;KAC9B;AACH,CAAC,CAAA"}
|
|
@@ -1,56 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const sendError_1 = require("../../sendError");
|
|
14
|
-
const security_1 = require("../../security");
|
|
15
|
-
const parseQuery_1 = __importDefault(require("./parseQuery"));
|
|
16
|
-
const auth_1 = require("../../auth");
|
|
17
|
-
const authorize_1 = require("../../authorize");
|
|
18
|
-
const sendHttpResponse_1 = require("../../sendHttpResponse");
|
|
19
|
-
const publish_1 = require("./publish");
|
|
1
|
+
import { isBasedRoute } from '@based/functions';
|
|
2
|
+
import { httpFunction } from './function.js';
|
|
3
|
+
import { httpStreamFunction } from './streamFunction/index.js';
|
|
4
|
+
import { httpGet } from './query.js';
|
|
5
|
+
import { BasedErrorCode } from '../../error/index.js';
|
|
6
|
+
import { sendError } from '../../sendError.js';
|
|
7
|
+
import { blockIncomingRequest, rateLimitRequest, endRateLimitHttp, } from '../../security.js';
|
|
8
|
+
import { parseAuthState, parseJSONAuthState } from '../../auth/index.js';
|
|
9
|
+
import { authorize } from '../../authorize.js';
|
|
10
|
+
import { end } from '../../sendHttpResponse.js';
|
|
11
|
+
import { httpPublish } from './publish.js';
|
|
12
|
+
import { handleRequest } from './handleRequest.js';
|
|
20
13
|
let clientId = 0;
|
|
21
|
-
const
|
|
22
|
-
if (method === 'post') {
|
|
23
|
-
(0, readBody_1.readBody)(server, ctx, ready, route);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
ready((0, parseQuery_1.default)(ctx));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const getQuery = (req) => {
|
|
30
|
-
const obj = {}, string = req.getQuery();
|
|
31
|
-
let index = 0;
|
|
32
|
-
let index2;
|
|
33
|
-
let index3;
|
|
34
|
-
do {
|
|
35
|
-
index2 = string.indexOf('=', index);
|
|
36
|
-
if (index2 == -1)
|
|
37
|
-
index2 = string.length;
|
|
38
|
-
index3 = string.indexOf('&', index2 + 1);
|
|
39
|
-
if (index3 == -1)
|
|
40
|
-
index3 = string.length;
|
|
41
|
-
obj[string.slice(index, index2)] = string.slice(index2 + 1, index3);
|
|
42
|
-
index = index3 + 1;
|
|
43
|
-
} while (index3 != string.length);
|
|
44
|
-
return obj;
|
|
45
|
-
};
|
|
46
|
-
const httpHandler = (server, req, res) => {
|
|
14
|
+
export const httpHandler = (server, req, res) => {
|
|
47
15
|
res.onAborted(() => {
|
|
48
16
|
ctx.session.res = null;
|
|
49
17
|
ctx.session.req = null;
|
|
50
18
|
ctx.session = null;
|
|
51
19
|
});
|
|
52
20
|
const ip = server.getIp(res, req);
|
|
53
|
-
if (
|
|
21
|
+
if (blockIncomingRequest(server, ip, res, req, server.rateLimit.http, 1)) {
|
|
54
22
|
return;
|
|
55
23
|
}
|
|
56
24
|
const method = req.getMethod();
|
|
@@ -58,8 +26,9 @@ const httpHandler = (server, req, res) => {
|
|
|
58
26
|
const path = url.split('/');
|
|
59
27
|
const route = server.functions.route(path[1], url);
|
|
60
28
|
if (route === null || route.internalOnly === true) {
|
|
61
|
-
|
|
29
|
+
sendError(server, {
|
|
62
30
|
session: {
|
|
31
|
+
url,
|
|
63
32
|
origin: req.getHeader('origin'),
|
|
64
33
|
ua: req.getHeader('user-agent'),
|
|
65
34
|
ip,
|
|
@@ -70,7 +39,7 @@ const httpHandler = (server, req, res) => {
|
|
|
70
39
|
res,
|
|
71
40
|
req,
|
|
72
41
|
},
|
|
73
|
-
},
|
|
42
|
+
}, BasedErrorCode.FunctionNotFound, path[1]
|
|
74
43
|
? { route: { name: path[1], type: 'function' } }
|
|
75
44
|
: { route: { name: '', path: url, type: 'function' } });
|
|
76
45
|
return;
|
|
@@ -78,41 +47,37 @@ const httpHandler = (server, req, res) => {
|
|
|
78
47
|
let authState = {};
|
|
79
48
|
if (route.public !== true) {
|
|
80
49
|
let authorization = req.getHeader('authorization');
|
|
81
|
-
if (!authorization && req.getQuery()) {
|
|
82
|
-
const query = getQuery(req);
|
|
83
|
-
if (query.authorization) {
|
|
84
|
-
authorization = query.authorization;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (authorization.length > 5e3) {
|
|
88
|
-
(0, sendError_1.sendError)(server, {
|
|
89
|
-
session: {
|
|
90
|
-
ua: req.getHeader('user-agent'),
|
|
91
|
-
ip,
|
|
92
|
-
method,
|
|
93
|
-
origin: req.getHeader('origin'),
|
|
94
|
-
id: ++clientId,
|
|
95
|
-
headers: {},
|
|
96
|
-
authState: {},
|
|
97
|
-
res,
|
|
98
|
-
req,
|
|
99
|
-
},
|
|
100
|
-
}, error_1.BasedErrorCode.PayloadTooLarge, { route: { name: 'authorize', type: 'function' } });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
50
|
if (authorization) {
|
|
104
|
-
|
|
51
|
+
if (authorization.length > 5e3) {
|
|
52
|
+
sendError(server, {
|
|
53
|
+
session: {
|
|
54
|
+
url,
|
|
55
|
+
ua: req.getHeader('user-agent'),
|
|
56
|
+
ip,
|
|
57
|
+
method,
|
|
58
|
+
origin: req.getHeader('origin'),
|
|
59
|
+
id: ++clientId,
|
|
60
|
+
headers: {},
|
|
61
|
+
authState: {},
|
|
62
|
+
res,
|
|
63
|
+
req,
|
|
64
|
+
},
|
|
65
|
+
}, BasedErrorCode.PayloadTooLarge, { route: { name: 'authorize', type: 'function' } });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
authState = parseAuthState(authorization);
|
|
105
69
|
}
|
|
106
70
|
else {
|
|
107
71
|
// TODO: remove this when c++ client can encode
|
|
108
72
|
const authorization = req.getHeader('json-authorization');
|
|
109
73
|
if (authorization) {
|
|
110
|
-
authState =
|
|
74
|
+
authState = parseJSONAuthState(authorization);
|
|
111
75
|
}
|
|
112
76
|
}
|
|
113
77
|
}
|
|
114
78
|
const ctx = {
|
|
115
79
|
session: {
|
|
80
|
+
url,
|
|
116
81
|
res,
|
|
117
82
|
req,
|
|
118
83
|
method,
|
|
@@ -153,8 +118,8 @@ const httpHandler = (server, req, res) => {
|
|
|
153
118
|
ctx.session.headers[header] = req.getHeader(header);
|
|
154
119
|
}
|
|
155
120
|
}
|
|
156
|
-
if (
|
|
157
|
-
|
|
121
|
+
if (rateLimitRequest(server, ctx, route.rateLimitTokens, server.rateLimit.http)) {
|
|
122
|
+
endRateLimitHttp(res);
|
|
158
123
|
return;
|
|
159
124
|
}
|
|
160
125
|
const query = req.getQuery();
|
|
@@ -169,7 +134,7 @@ const httpHandler = (server, req, res) => {
|
|
|
169
134
|
if (method === 'post' &&
|
|
170
135
|
ctx.session.headers['content-length'] === undefined) {
|
|
171
136
|
// Zero allowed, but not for streams
|
|
172
|
-
|
|
137
|
+
sendError(server, ctx, BasedErrorCode.LengthRequired, route);
|
|
173
138
|
return;
|
|
174
139
|
}
|
|
175
140
|
if (route.headers) {
|
|
@@ -180,56 +145,55 @@ const httpHandler = (server, req, res) => {
|
|
|
180
145
|
}
|
|
181
146
|
}
|
|
182
147
|
}
|
|
183
|
-
if (
|
|
148
|
+
if (isBasedRoute('query', route)) {
|
|
184
149
|
// Handle HEAD
|
|
185
150
|
if (method !== 'post' && method !== 'get') {
|
|
186
|
-
|
|
151
|
+
sendError(server, ctx, BasedErrorCode.MethodNotAllowed, route);
|
|
187
152
|
return;
|
|
188
153
|
}
|
|
189
154
|
const checksumRaw = req.getHeader('if-none-match');
|
|
190
155
|
const checksumNum = Number(checksumRaw);
|
|
191
156
|
const checksum = !isNaN(checksumNum) ? checksumNum : 0;
|
|
192
157
|
handleRequest(server, method, ctx, route, (payload) => {
|
|
193
|
-
|
|
158
|
+
httpGet(route, payload, ctx, server, checksum);
|
|
194
159
|
});
|
|
195
160
|
return;
|
|
196
161
|
}
|
|
197
|
-
if (
|
|
162
|
+
if (isBasedRoute('stream', route)) {
|
|
198
163
|
if (method === 'options') {
|
|
199
|
-
|
|
164
|
+
end(ctx);
|
|
200
165
|
return;
|
|
201
166
|
}
|
|
202
167
|
if (method !== 'post') {
|
|
203
|
-
|
|
168
|
+
sendError(server, ctx, BasedErrorCode.MethodNotAllowed, route);
|
|
204
169
|
return;
|
|
205
170
|
}
|
|
206
171
|
if (ctx.session.headers['content-length'] === 0) {
|
|
207
172
|
// Zero is also not allowed for streams
|
|
208
|
-
|
|
173
|
+
sendError(server, ctx, BasedErrorCode.LengthRequired, route);
|
|
209
174
|
return;
|
|
210
175
|
}
|
|
211
|
-
|
|
176
|
+
httpStreamFunction(server, ctx, route);
|
|
212
177
|
return;
|
|
213
178
|
}
|
|
214
|
-
if (
|
|
179
|
+
if (isBasedRoute('channel', route)) {
|
|
215
180
|
if (method !== 'post' && method !== 'get') {
|
|
216
|
-
|
|
181
|
+
sendError(server, ctx, BasedErrorCode.MethodNotAllowed, route);
|
|
217
182
|
return;
|
|
218
183
|
}
|
|
219
184
|
handleRequest(server, method, ctx, route, (payload) => {
|
|
220
|
-
|
|
185
|
+
authorize(route, server, ctx, payload, httpPublish, undefined, undefined, route.publicPublisher || route.public);
|
|
221
186
|
});
|
|
222
187
|
return;
|
|
223
188
|
}
|
|
224
|
-
if (
|
|
189
|
+
if (isBasedRoute('function', route)) {
|
|
225
190
|
if (method !== 'post' && method !== 'get') {
|
|
226
|
-
|
|
191
|
+
sendError(server, ctx, BasedErrorCode.MethodNotAllowed, route);
|
|
227
192
|
return;
|
|
228
193
|
}
|
|
229
194
|
handleRequest(server, method, ctx, route, (payload) => {
|
|
230
|
-
|
|
195
|
+
authorize(route, server, ctx, payload, httpFunction);
|
|
231
196
|
});
|
|
232
197
|
}
|
|
233
198
|
};
|
|
234
|
-
exports.httpHandler = httpHandler;
|
|
235
199
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/incoming/http/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/incoming/http/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EA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AAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,CAAC,CAAA;QACtD,CAAC,CAAC,CAAA;KACH;AACH,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, HttpSession } from '@based/functions';
|
|
1
|
+
import { BasedRoute, Context, HttpSession } from '@based/functions';
|
|
2
2
|
import { parseQuery } from '@saulx/utils';
|
|
3
|
-
declare const _default: (ctx: Context<HttpSession
|
|
3
|
+
declare const _default: (ctx: Context<HttpSession>, route: BasedRoute) => ReturnType<typeof parseQuery>;
|
|
4
4
|
export default _default;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const auth_1 = require("../../auth");
|
|
5
|
-
exports.default = (ctx) => {
|
|
1
|
+
import { parseQuery } from '@saulx/utils';
|
|
2
|
+
import { parseAuthState } from '../../auth/index.js';
|
|
3
|
+
export default (ctx, route) => {
|
|
6
4
|
if (!('query' in ctx.session)) {
|
|
7
5
|
return;
|
|
8
6
|
}
|
|
@@ -10,13 +8,16 @@ exports.default = (ctx) => {
|
|
|
10
8
|
return ctx.session.parsedQuery;
|
|
11
9
|
}
|
|
12
10
|
try {
|
|
13
|
-
ctx.session.parsedQuery =
|
|
14
|
-
// TODO
|
|
11
|
+
ctx.session.parsedQuery = parseQuery(ctx.session.query);
|
|
12
|
+
// TODO check if this is a good idea (can also call it 'authState')
|
|
15
13
|
if (!ctx.session.authState.token &&
|
|
16
14
|
!ctx.session.authState.refreshToken &&
|
|
17
15
|
ctx.session.parsedQuery &&
|
|
18
16
|
'token' in ctx.session.parsedQuery) {
|
|
19
|
-
ctx.session.authState =
|
|
17
|
+
ctx.session.authState = parseAuthState(ctx.session.parsedQuery.token);
|
|
18
|
+
if (route.type === 'query') {
|
|
19
|
+
delete ctx.session.parsedQuery.token;
|
|
20
|
+
}
|
|
20
21
|
}
|
|
21
22
|
return ctx.session.parsedQuery;
|
|
22
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseQuery.js","sourceRoot":"","sources":["../../../src/incoming/http/parseQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseQuery.js","sourceRoot":"","sources":["../../../src/incoming/http/parseQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,eAAe,CACb,GAAyB,EACzB,KAAiB,EACc,EAAE;IACjC,IAAI,CAAC,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,EAAE;QAC7B,OAAM;KACP;IACD,IAAI,aAAa,IAAI,GAAG,CAAC,OAAO,EAAE;QAChC,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,CAAA;KAC/B;IACD,IAAI;QACF,GAAG,CAAC,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACvD,mEAAmE;QACnE,IACE,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK;YAC5B,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY;YACnC,GAAG,CAAC,OAAO,CAAC,WAAW;YACvB,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,EAClC;YACA,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YACrE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC1B,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAA;aACrC;SACF;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,CAAA;KAC/B;IAAC,OAAO,GAAG,EAAE;QACZ,GAAG,CAAC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAA;KACpC;AACH,CAAC,CAAA"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const query_1 = require("../../query");
|
|
9
|
-
const channel_1 = require("../../channel");
|
|
10
|
-
const httpPublish = async (route, spec, server, ctx, payload) => {
|
|
1
|
+
import { sendHttpResponse } from '../../sendHttpResponse.js';
|
|
2
|
+
import { BasedErrorCode } from '../../error/index.js';
|
|
3
|
+
import { sendError } from '../../sendError.js';
|
|
4
|
+
import { installFn } from '../../installFn.js';
|
|
5
|
+
import { genObservableId } from '../../query/index.js';
|
|
6
|
+
import { hasChannel, createChannel, destroyChannel, extendChannel, } from '../../channel/index.js';
|
|
7
|
+
export const httpPublish = async (route, _spec, server, ctx, payload) => {
|
|
11
8
|
// parse channel payload / msg
|
|
12
9
|
let msg;
|
|
13
10
|
let channelPayload;
|
|
@@ -43,23 +40,23 @@ const httpPublish = async (route, spec, server, ctx, payload) => {
|
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
const name = route.name;
|
|
46
|
-
const id =
|
|
47
|
-
|
|
43
|
+
const id = genObservableId(name, channelPayload);
|
|
44
|
+
installFn(server, ctx, route).then(async (spec) => {
|
|
48
45
|
if (spec === null) {
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
if (!hasChannel(server, id)) {
|
|
49
|
+
createChannel(server, name, id, channelPayload, true);
|
|
50
|
+
destroyChannel(server, id);
|
|
54
51
|
}
|
|
55
52
|
else {
|
|
56
|
-
|
|
53
|
+
extendChannel(server, server.activeChannelsById.get(id));
|
|
57
54
|
}
|
|
58
55
|
try {
|
|
59
56
|
spec.publisher(server.client, channelPayload, msg, id, ctx);
|
|
60
57
|
if (spec.httpResponse) {
|
|
61
58
|
const send = (responseData, headers, status) => {
|
|
62
|
-
|
|
59
|
+
sendHttpResponse(ctx, responseData, headers, status !== undefined
|
|
63
60
|
? typeof status === 'string'
|
|
64
61
|
? status
|
|
65
62
|
: String(status)
|
|
@@ -68,15 +65,14 @@ const httpPublish = async (route, spec, server, ctx, payload) => {
|
|
|
68
65
|
await spec.httpResponse(server.client, payload, undefined, send, ctx);
|
|
69
66
|
return;
|
|
70
67
|
}
|
|
71
|
-
|
|
68
|
+
sendHttpResponse(ctx, undefined);
|
|
72
69
|
}
|
|
73
70
|
catch (err) {
|
|
74
|
-
|
|
71
|
+
sendError(server, ctx, BasedErrorCode.FunctionError, {
|
|
75
72
|
err,
|
|
76
73
|
route,
|
|
77
74
|
});
|
|
78
75
|
}
|
|
79
76
|
});
|
|
80
77
|
};
|
|
81
|
-
exports.httpPublish = httpPublish;
|
|
82
78
|
//# sourceMappingURL=publish.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/incoming/http/publish.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/incoming/http/publish.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,wBAAwB,CAAA;AAE/B,MAAM,CAAC,MAAM,WAAW,GAAqC,KAAK,EAChE,KAA4B,EAC5B,KAAqC,EACrC,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE;IACF,8BAA8B;IAC9B,IAAI,GAAQ,CAAA;IACZ,IAAI,cAAmB,CAAA;IACvB,IAAI,OAAO,OA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,EAAE,EAAE,CAAC,CAAA;SAC3B;aAAM;YACL,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;SACzD;QAED,IAAI;YACF,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;YAC3D,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,MAAM,IAAI,GAAqB,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC/D,gBAAgB,CACd,GAAG,EACH,YAAY,EACZ,OAAO,EACP,MAAM,KAAK,SAAS;wBAClB,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ;4BAC1B,CAAC,CAAC,MAAM;4BACR,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;wBAClB,CAAC,CAAC,SAAS,CACd,CAAA;gBACH,CAAC,CAAA;gBACD,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;gBACrE,OAAM;aACP;YACD,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;SACjC;QAAC,OAAO,GAAG,EAAE;YACZ,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,cAAc,CAAC,aAAa,EAAE;gBACnD,GAAG;gBACH,KAAK;aACN,CAAC,CAAA;SACH;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BasedServer } from '../../server';
|
|
1
|
+
import { BasedServer } from '../../server.js';
|
|
2
2
|
import { HttpSession, Context, BasedRoute } from '@based/functions';
|
|
3
3
|
export declare const httpGet: (route: BasedRoute<'query'>, payload: any, ctx: Context<HttpSession>, server: BasedServer, checksum: number) => void;
|
|
@@ -1,73 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const node_zlib_1 = __importDefault(require("node:zlib"));
|
|
11
|
-
const utils_1 = require("@saulx/utils");
|
|
12
|
-
const error_1 = require("../../error");
|
|
13
|
-
const sendError_1 = require("../../sendError");
|
|
14
|
-
const node_util_1 = require("node:util");
|
|
15
|
-
const authorize_1 = require("../../authorize");
|
|
16
|
-
const inflate = (0, node_util_1.promisify)(node_zlib_1.default.inflateRaw);
|
|
1
|
+
import { end, sendHeaders } from '../../sendHttpResponse.js';
|
|
2
|
+
import { compress } from '../../compress.js';
|
|
3
|
+
import { createObs, destroyObs, getObsAndStopRemove, hasObs, sendObsGetError, subscribeNext, start, genObservableId, } from '../../query/index.js';
|
|
4
|
+
import zlib from 'node:zlib';
|
|
5
|
+
import { BasedErrorCode } from '../../error/index.js';
|
|
6
|
+
import { sendError } from '../../sendError.js';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { authorize } from '../../authorize.js';
|
|
9
|
+
const inflate = promisify(zlib.inflateRaw);
|
|
17
10
|
const sendCacheSwapEncoding = async (server, route, ctx, buffer, checksum, headers, status = '200 OK') => {
|
|
18
11
|
try {
|
|
19
12
|
const inflated = await inflate(buffer.slice(20));
|
|
20
|
-
const { payload, encoding } = await
|
|
13
|
+
const { payload, encoding } = await compress(inflated, ctx.session.headers.encoding);
|
|
21
14
|
if (!ctx.session.res) {
|
|
22
15
|
return;
|
|
23
16
|
}
|
|
24
17
|
ctx.session.res.cork(() => {
|
|
25
18
|
if (headers) {
|
|
26
|
-
|
|
19
|
+
sendHeaders(ctx, headers);
|
|
27
20
|
}
|
|
28
21
|
ctx.session.res.writeStatus(status);
|
|
29
22
|
if (encoding) {
|
|
30
23
|
ctx.session.res.writeHeader('Content-Encoding', encoding);
|
|
31
24
|
}
|
|
32
25
|
ctx.session.res.writeHeader('ETag', String(checksum));
|
|
33
|
-
|
|
26
|
+
end(ctx, payload);
|
|
34
27
|
});
|
|
35
28
|
}
|
|
36
29
|
catch (err) {
|
|
37
|
-
|
|
30
|
+
sendError(server, ctx, BasedErrorCode.UnsupportedContentEncoding, route);
|
|
38
31
|
}
|
|
39
32
|
};
|
|
40
33
|
const sendCache = (ctx, buffer, checksum, isDeflate, headers, status = '200 OK') => {
|
|
41
34
|
ctx.session.res.cork(() => {
|
|
42
35
|
if (headers) {
|
|
43
|
-
|
|
36
|
+
sendHeaders(ctx, headers);
|
|
44
37
|
}
|
|
45
38
|
ctx.session.res.writeStatus(status);
|
|
46
39
|
ctx.session.res.writeHeader('ETag', String(checksum));
|
|
47
40
|
if (isDeflate) {
|
|
48
41
|
ctx.session.res.writeHeader('Content-Encoding', 'deflate');
|
|
49
42
|
}
|
|
50
|
-
|
|
43
|
+
end(ctx, buffer.slice(20));
|
|
51
44
|
});
|
|
52
45
|
};
|
|
53
46
|
const sendNotModified = (ctx, headers, status = '304 Not Modified') => {
|
|
54
47
|
ctx.session.res.cork(() => {
|
|
55
48
|
if (headers) {
|
|
56
|
-
|
|
49
|
+
sendHeaders(ctx, headers);
|
|
57
50
|
}
|
|
58
51
|
ctx.session.res.writeStatus(status);
|
|
59
|
-
|
|
52
|
+
end(ctx);
|
|
60
53
|
});
|
|
61
54
|
};
|
|
62
55
|
const sendGetResponseInternal = (route, server, id, obs, checksum, ctx, headers, status) => {
|
|
63
56
|
if (!ctx.session) {
|
|
64
|
-
|
|
57
|
+
destroyObs(server, id);
|
|
65
58
|
return;
|
|
66
59
|
}
|
|
67
60
|
const encoding = ctx.session.headers.encoding;
|
|
68
61
|
if (checksum === 0 || checksum !== obs.checksum) {
|
|
69
62
|
if (!obs.cache) {
|
|
70
|
-
|
|
63
|
+
sendError(server, ctx, BasedErrorCode.NoOservableCacheAvailable, {
|
|
71
64
|
observableId: id,
|
|
72
65
|
route: { name: obs.name, type: 'query' },
|
|
73
66
|
});
|
|
@@ -87,12 +80,12 @@ const sendGetResponseInternal = (route, server, id, obs, checksum, ctx, headers,
|
|
|
87
80
|
else {
|
|
88
81
|
sendNotModified(ctx);
|
|
89
82
|
}
|
|
90
|
-
|
|
83
|
+
destroyObs(server, id);
|
|
91
84
|
};
|
|
92
85
|
const sendGetResponse = (route, spec, server, id, obs, checksum, ctx) => {
|
|
93
86
|
if ('httpResponse' in spec) {
|
|
94
87
|
// response data does not work for query responses
|
|
95
|
-
const send = (
|
|
88
|
+
const send = (_responseData, headers, status) => {
|
|
96
89
|
sendGetResponseInternal(route, server, id, obs, checksum, ctx, headers, typeof status === 'string' ? status : String(status));
|
|
97
90
|
};
|
|
98
91
|
spec.httpResponse(server.client, obs.payload, obs.cache, send, ctx);
|
|
@@ -101,24 +94,24 @@ const sendGetResponse = (route, spec, server, id, obs, checksum, ctx) => {
|
|
|
101
94
|
sendGetResponseInternal(route, server, id, obs, checksum, ctx);
|
|
102
95
|
};
|
|
103
96
|
const getFromExisting = (server, id, ctx, route, spec, checksum) => {
|
|
104
|
-
const obs =
|
|
97
|
+
const obs = getObsAndStopRemove(server, id);
|
|
105
98
|
if (server.queryEvents) {
|
|
106
99
|
server.queryEvents.get(obs, ctx);
|
|
107
100
|
}
|
|
108
101
|
if (obs.error) {
|
|
109
|
-
|
|
102
|
+
sendObsGetError(server, ctx, obs.id, obs.error);
|
|
110
103
|
return;
|
|
111
104
|
}
|
|
112
105
|
if (obs.cache) {
|
|
113
106
|
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
114
107
|
return;
|
|
115
108
|
}
|
|
116
|
-
|
|
109
|
+
subscribeNext(obs, (err) => {
|
|
117
110
|
if (!ctx.session) {
|
|
118
111
|
return;
|
|
119
112
|
}
|
|
120
113
|
if (err) {
|
|
121
|
-
|
|
114
|
+
sendObsGetError(server, ctx, obs.id, err);
|
|
122
115
|
}
|
|
123
116
|
else {
|
|
124
117
|
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
@@ -127,35 +120,28 @@ const getFromExisting = (server, id, ctx, route, spec, checksum) => {
|
|
|
127
120
|
};
|
|
128
121
|
const isAuthorized = (route, spec, server, ctx, payload, id, checksum) => {
|
|
129
122
|
const name = route.name;
|
|
130
|
-
if (
|
|
123
|
+
if (hasObs(server, id)) {
|
|
131
124
|
getFromExisting(server, id, ctx, route, spec, checksum);
|
|
132
125
|
return;
|
|
133
126
|
}
|
|
134
|
-
const obs =
|
|
127
|
+
const obs = createObs(server, name, id, payload, true);
|
|
135
128
|
if (server.queryEvents) {
|
|
136
129
|
server.queryEvents.get(obs, ctx);
|
|
137
130
|
}
|
|
138
|
-
|
|
131
|
+
subscribeNext(obs, (err) => {
|
|
139
132
|
if (err) {
|
|
140
|
-
|
|
133
|
+
sendObsGetError(server, ctx, obs.id, err);
|
|
141
134
|
}
|
|
142
135
|
else {
|
|
143
136
|
sendGetResponse(route, spec, server, id, obs, checksum, ctx);
|
|
144
137
|
}
|
|
145
138
|
});
|
|
146
|
-
|
|
139
|
+
start(server, id);
|
|
147
140
|
};
|
|
148
|
-
const httpGet = (route, payload, ctx, server, checksum) => {
|
|
141
|
+
export const httpGet = (route, payload, ctx, server, checksum) => {
|
|
149
142
|
if (!ctx.session) {
|
|
150
143
|
return;
|
|
151
144
|
}
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
payload = (0, utils_1.parseQuery)(decodeURIComponent(ctx.session.query));
|
|
155
|
-
}
|
|
156
|
-
catch (err) { }
|
|
157
|
-
}
|
|
158
|
-
(0, authorize_1.authorize)(route, server, ctx, payload, isAuthorized, (0, query_1.genObservableId)(route.name, payload), checksum);
|
|
145
|
+
authorize(route, server, ctx, payload, isAuthorized, genObservableId(route.name, payload), checksum);
|
|
159
146
|
};
|
|
160
|
-
exports.httpGet = httpGet;
|
|
161
147
|
//# sourceMappingURL=query.js.map
|