@based/server 4.0.3 → 4.0.5
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 +1 -1
- package/dist/auth/defaultConfig.js.map +1 -1
- package/dist/auth/index.d.ts +14 -2
- package/dist/auth/index.js +12 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseJSONAuthState.d.ts +3 -0
- package/dist/auth/parseJSONAuthState.js +10 -0
- package/dist/auth/parseJSONAuthState.js.map +1 -0
- package/dist/authorize copy.d.ts +9 -0
- package/dist/authorize copy.js +69 -0
- package/dist/authorize copy.js.map +1 -0
- package/dist/authorize.d.ts +5 -5
- package/dist/authorize.js +33 -17
- package/dist/authorize.js.map +1 -1
- package/dist/authorizeAndInstall.d.ts +9 -0
- package/dist/authorizeAndInstall.js +69 -0
- package/dist/authorizeAndInstall.js.map +1 -0
- package/dist/channel/cleanup.d.ts +2 -0
- package/dist/channel/cleanup.js +53 -0
- package/dist/channel/cleanup.js.map +1 -0
- package/dist/channel/create.d.ts +3 -0
- package/dist/channel/create.js +33 -0
- package/dist/channel/create.js.map +1 -0
- package/dist/channel/destroy.d.ts +4 -0
- package/dist/channel/destroy.js +48 -0
- package/dist/channel/destroy.js.map +1 -0
- package/dist/channel/extend.d.ts +4 -0
- package/dist/channel/extend.js +16 -0
- package/dist/channel/extend.js.map +1 -0
- package/dist/channel/get.d.ts +4 -0
- package/dist/channel/get.js +15 -0
- package/dist/channel/get.js.map +1 -0
- package/dist/channel/index.d.ts +8 -0
- package/dist/channel/index.js +25 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/start.d.ts +2 -0
- package/dist/channel/start.js +76 -0
- package/dist/channel/start.js.map +1 -0
- package/dist/channel/subscribe.d.ts +4 -0
- package/dist/channel/subscribe.js +28 -0
- package/dist/channel/subscribe.js.map +1 -0
- package/dist/channel/types.d.ts +14 -0
- package/dist/channel/types.js +4 -0
- package/dist/channel/types.js.map +1 -0
- package/dist/channel/unsub.d.ts +5 -0
- package/dist/channel/unsub.js +49 -0
- package/dist/channel/unsub.js.map +1 -0
- package/dist/createSimpleServer.d.ts +18 -16
- package/dist/createSimpleServer.js +92 -26
- package/dist/createSimpleServer.js.map +1 -1
- package/dist/error/errorTypeHandlers.d.ts +1 -1
- package/dist/error/errorTypeHandlers.js +16 -46
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.js +3 -0
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.d.ts +22 -27
- package/dist/error/types.js +2 -6
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/channelSubscribe.d.ts +3 -0
- package/dist/functionApi/channelSubscribe.js +43 -0
- package/dist/functionApi/channelSubscribe.js.map +1 -0
- package/dist/functionApi/client/channel.d.ts +10 -0
- package/dist/functionApi/client/channel.js +33 -0
- package/dist/functionApi/client/channel.js.map +1 -0
- package/dist/functionApi/client/index.d.ts +5 -3
- package/dist/functionApi/client/index.js +10 -5
- package/dist/functionApi/client/index.js.map +1 -1
- package/dist/functionApi/get.js +2 -2
- package/dist/functionApi/get.js.map +1 -1
- package/dist/functionApi/index.d.ts +3 -0
- package/dist/functionApi/index.js +3 -1
- package/dist/functionApi/index.js.map +1 -1
- package/dist/functionApi/observe.js +2 -2
- package/dist/functionApi/observe.js.map +1 -1
- package/dist/functionApi/publish.d.ts +3 -0
- package/dist/functionApi/publish.js +29 -0
- package/dist/functionApi/publish.js.map +1 -0
- package/dist/functionApi/stream.d.ts +2 -2
- package/dist/functionApi/stream.js +44 -6
- package/dist/functionApi/stream.js.map +1 -1
- package/dist/functions/index.d.ts +3 -2
- package/dist/functions/index.js +55 -34
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.js +4 -2
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +100 -56
- package/dist/functions/types.js +16 -5
- package/dist/functions/types.js.map +1 -1
- package/dist/incoming/http/function.js +26 -28
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/index.js +33 -7
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/publish.d.ts +3 -0
- package/dist/incoming/http/publish.js +82 -0
- package/dist/incoming/http/publish.js.map +1 -0
- package/dist/incoming/http/query.js +13 -23
- package/dist/incoming/http/query.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.js +9 -9
- 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 +2 -2
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +2 -3
- package/dist/incoming/http/streamFunction/stream/createStream.js +2 -2
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/index.js +4 -3
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +66 -54
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.js +19 -12
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +1 -1
- package/dist/incoming/ws/auth.js +70 -22
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/channelPublish.d.ts +2 -0
- package/dist/incoming/ws/channelPublish.js +60 -0
- package/dist/incoming/ws/channelPublish.js.map +1 -0
- package/dist/incoming/ws/channelSubscribe.d.ts +7 -0
- package/dist/incoming/ws/channelSubscribe.js +128 -0
- package/dist/incoming/ws/channelSubscribe.js.map +1 -0
- package/dist/incoming/ws/function.js +14 -7
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.js +33 -29
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.js +22 -2
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/observable.js +24 -21
- package/dist/incoming/ws/observable.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/installFn.js +32 -34
- package/dist/installFn.js.map +1 -1
- package/dist/observable/cleanup.d.ts +2 -0
- package/dist/observable/cleanup.js +66 -0
- package/dist/observable/cleanup.js.map +1 -0
- package/dist/observable/create.js +1 -0
- package/dist/observable/create.js.map +1 -1
- package/dist/observable/destroy.d.ts +2 -0
- package/dist/observable/destroy.js +26 -30
- package/dist/observable/destroy.js.map +1 -1
- package/dist/observable/extendCache.js +2 -3
- package/dist/observable/extendCache.js.map +1 -1
- package/dist/observable/genObservableId.js +3 -0
- package/dist/observable/genObservableId.js.map +1 -1
- package/dist/observable/get.d.ts +1 -1
- package/dist/observable/get.js +3 -3
- package/dist/observable/get.js.map +1 -1
- package/dist/observable/send.d.ts +1 -1
- package/dist/observable/send.js +2 -2
- package/dist/observable/send.js.map +1 -1
- package/dist/observable/start/error.d.ts +1 -1
- package/dist/observable/start/error.js +7 -2
- package/dist/observable/start/error.js.map +1 -1
- package/dist/observable/start/index.js +3 -1
- package/dist/observable/start/index.js.map +1 -1
- package/dist/observable/start/update.d.ts +1 -4
- package/dist/observable/start/update.js +0 -1
- package/dist/observable/start/update.js.map +1 -1
- package/dist/observable/subscribe.d.ts +1 -1
- package/dist/observable/subscribe.js +7 -8
- package/dist/observable/subscribe.js.map +1 -1
- package/dist/observable/types.d.ts +9 -9
- package/dist/observable/unsub.d.ts +1 -1
- package/dist/observable/unsub.js +9 -6
- package/dist/observable/unsub.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.js +60 -48
- package/dist/protocol.js.map +1 -1
- package/dist/security.js +1 -0
- package/dist/security.js.map +1 -1
- package/dist/sendError.js +2 -4
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.js +16 -3
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +24 -12
- package/dist/server.js +14 -8
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +4 -3
- package/dist/verifyRoute.js +31 -20
- package/dist/verifyRoute.js.map +1 -1
- package/package.json +7 -7
- package/dist/functionApi/callFunction copy.d.ts +0 -3
- package/dist/functionApi/callFunction copy.js +0 -29
- package/dist/functionApi/callFunction copy.js.map +0 -1
- package/dist/incoming/http/get.d.ts +0 -4
- package/dist/incoming/http/get.js +0 -156
- package/dist/incoming/http/get.js.map +0 -1
- package/dist/incoming/http/streamFunction/DataStream.d.ts +0 -15
- package/dist/incoming/http/streamFunction/DataStream.js +0 -58
- package/dist/incoming/http/streamFunction/DataStream.js.map +0 -1
|
@@ -5,7 +5,7 @@ const defaultAuthorize = async () => {
|
|
|
5
5
|
return true;
|
|
6
6
|
};
|
|
7
7
|
exports.defaultAuthorize = defaultAuthorize;
|
|
8
|
-
const defaultVerifyAuthState = () => {
|
|
8
|
+
const defaultVerifyAuthState = async () => {
|
|
9
9
|
return true;
|
|
10
10
|
};
|
|
11
11
|
exports.defaultVerifyAuthState = defaultVerifyAuthState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../../src/auth/defaultConfig.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAc,KAAK,IAAI,EAAE;IACpD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAEM,MAAM,sBAAsB,GAAoB,
|
|
1
|
+
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../../src/auth/defaultConfig.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAc,KAAK,IAAI,EAAE;IACpD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAEM,MAAM,sBAAsB,GAAoB,KAAK,IAAI,EAAE;IAChE,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { BasedServer } from '../server';
|
|
2
2
|
import { Context, AuthState, WebSocketSession, Authorize, AuthorizeConnection, VerifyAuthState } from '@based/functions';
|
|
3
3
|
import parseAuthState from './parseAuthState';
|
|
4
|
+
import parseJSONAuthState from './parseJSONAuthState';
|
|
4
5
|
export { parseAuthState };
|
|
5
|
-
export
|
|
6
|
+
export { parseJSONAuthState };
|
|
7
|
+
export type AuthConfig = {
|
|
8
|
+
/** This function is called before any BasedFunction that isn't public.
|
|
9
|
+
* The BasedFunction requested will only execute if `authorize` returns `true`. */
|
|
6
10
|
authorize?: Authorize;
|
|
7
11
|
authorizeConnection?: AuthorizeConnection;
|
|
12
|
+
/** This function is called every time an authState is set.
|
|
13
|
+
* @returns `true` if the authState is valid and does not need to be updated
|
|
14
|
+
* @returns `AuthState` object if the authState of the session needs to be updated
|
|
15
|
+
*/
|
|
8
16
|
verifyAuthState?: VerifyAuthState;
|
|
9
17
|
};
|
|
10
18
|
export declare class BasedAuth {
|
|
@@ -14,8 +22,12 @@ export declare class BasedAuth {
|
|
|
14
22
|
authorize: Authorize;
|
|
15
23
|
constructor(server: BasedServer, config?: AuthConfig);
|
|
16
24
|
updateConfig(config: AuthConfig): void;
|
|
17
|
-
|
|
25
|
+
/** Calls `verifyAuthState` on the current session's authState.
|
|
26
|
+
* If it's in a wsContext, sends the new verified authState to the client and updates the session's authState.
|
|
27
|
+
*/
|
|
28
|
+
renewAuthState(ctx: Context, authState?: AuthState): Promise<AuthState>;
|
|
18
29
|
encodeAuthState(authState: AuthState): string;
|
|
19
30
|
decodeAuthState(authState: any): AuthState;
|
|
31
|
+
/** Sets the `authState` on the client. */
|
|
20
32
|
sendAuthState(ctx: Context<WebSocketSession>, authState: AuthState): void;
|
|
21
33
|
}
|
package/dist/auth/index.js
CHANGED
|
@@ -3,12 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BasedAuth = exports.parseAuthState = void 0;
|
|
6
|
+
exports.BasedAuth = exports.parseJSONAuthState = exports.parseAuthState = void 0;
|
|
7
7
|
const protocol_1 = require("../protocol");
|
|
8
8
|
const functions_1 = require("@based/functions");
|
|
9
9
|
const defaultConfig_1 = require("./defaultConfig");
|
|
10
10
|
const parseAuthState_1 = __importDefault(require("./parseAuthState"));
|
|
11
11
|
exports.parseAuthState = parseAuthState_1.default;
|
|
12
|
+
const parseJSONAuthState_1 = __importDefault(require("./parseJSONAuthState"));
|
|
13
|
+
exports.parseJSONAuthState = parseJSONAuthState_1.default;
|
|
12
14
|
class BasedAuth {
|
|
13
15
|
constructor(server, config = {}) {
|
|
14
16
|
this.verifyAuthState = defaultConfig_1.defaultVerifyAuthState;
|
|
@@ -30,21 +32,25 @@ class BasedAuth {
|
|
|
30
32
|
this.verifyAuthState = config.verifyAuthState;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
/** Calls `verifyAuthState` on the current session's authState.
|
|
36
|
+
* If it's in a wsContext, sends the new verified authState to the client and updates the session's authState.
|
|
37
|
+
*/
|
|
38
|
+
async renewAuthState(ctx, authState) {
|
|
34
39
|
if (!ctx.session) {
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
42
|
if (!('authState' in ctx.session)) {
|
|
38
43
|
return;
|
|
39
44
|
}
|
|
40
|
-
const verified = this.server.auth.verifyAuthState(this.server.client, ctx, ctx.session.authState);
|
|
41
|
-
if (verified === true) {
|
|
45
|
+
const verified = await this.server.auth.verifyAuthState(this.server.client, ctx, authState || ctx.session.authState);
|
|
46
|
+
if (verified === true || !ctx.session) {
|
|
42
47
|
return;
|
|
43
48
|
}
|
|
44
49
|
ctx.session.authState = verified;
|
|
45
50
|
if ((0, functions_1.isWsContext)(ctx)) {
|
|
46
51
|
this.sendAuthState(ctx, verified);
|
|
47
52
|
}
|
|
53
|
+
return verified;
|
|
48
54
|
}
|
|
49
55
|
encodeAuthState(authState) {
|
|
50
56
|
return Buffer.from(JSON.stringify(authState), 'utf8').toString('base64');
|
|
@@ -52,8 +58,9 @@ class BasedAuth {
|
|
|
52
58
|
decodeAuthState(authState) {
|
|
53
59
|
return (0, parseAuthState_1.default)(authState);
|
|
54
60
|
}
|
|
61
|
+
/** Sets the `authState` on the client. */
|
|
55
62
|
sendAuthState(ctx, authState) {
|
|
56
|
-
ctx.session?.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(authState)), true, false);
|
|
63
|
+
ctx.session?.ws.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(authState)), true, false);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
exports.BasedAuth = BasedAuth;
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA+D;AAE/D,gDASyB;AACzB,mDAA0E;AAC1E,sEAA6C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA+D;AAE/D,gDASyB;AACzB,mDAA0E;AAC1E,sEAA6C;AAGpC,yBAHF,wBAAc,CAGE;AAFvB,8EAAqD;AAG5C,6BAHF,4BAAkB,CAGE;AAc3B,MAAa,SAAS;IAOpB,YAAY,MAAmB,EAAE,SAAqB,EAAE;QAHxD,oBAAe,GAAoB,sCAAsB,CAAA;QACzD,cAAS,GAAc,gCAAgB,CAAA;QAGrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAED,YAAY,CAAC,MAAkB;QAC7B,IAAI,CAA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AAS,CAAC,CAAA;IAClC,CAAC;IAED,0CAA0C;IAC1C,aAAa,CAAC,GAA8B,EAAE,SAAoB;QAChE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAClB,IAAA,6BAAkB,EAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,EAC5C,IAAI,EACJ,KAAK,CACN,CAAA;IACH,CAAC;CACF;AA7ED,8BA6EC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (authorization) => {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(decodeURIComponent(authorization));
|
|
6
|
+
}
|
|
7
|
+
catch (err) { }
|
|
8
|
+
return { error: 'Invalid token' };
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=parseJSONAuthState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseJSONAuthState.js","sourceRoot":"","sources":["../../src/auth/parseJSONAuthState.ts"],"names":[],"mappings":";;AAEA,kBAAe,CAAC,aAAqB,EAAa,EAAE;IAClD,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAA;KACrD;IAAC,OAAO,GAAG,EAAE,GAAE;IAChB,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAA;AACnC,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasedServer } from './server';
|
|
2
|
+
import { BasedRoute } from './functions';
|
|
3
|
+
import { HttpSession, Context, WebSocketSession } from '@based/functions';
|
|
4
|
+
type ClientSession = HttpSession | WebSocketSession;
|
|
5
|
+
export type IsAuthorizedHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number) => void;
|
|
6
|
+
export type AuthErrorHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number, err?: Error) => true | void;
|
|
7
|
+
export declare const defaultAuthError: AuthErrorHandler;
|
|
8
|
+
export declare const authorize: <S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any>(route: R, server: BasedServer, ctx: Context<S>, payload: P, isAuthorized: IsAuthorizedHandler<S, R, P>, id?: number, checksum?: number, authError?: AuthErrorHandler<S, R, P>) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorize = exports.defaultAuthError = void 0;
|
|
4
|
+
const functions_1 = require("./functions");
|
|
5
|
+
const sendError_1 = require("./sendError");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const defaultAuthError = (route, server, ctx, payload, id, checksum, err) => {
|
|
8
|
+
const code = err
|
|
9
|
+
? error_1.BasedErrorCode.AuthorizeFunctionError
|
|
10
|
+
: error_1.BasedErrorCode.AuthorizeRejectedError;
|
|
11
|
+
if (id && (0, functions_1.isChannelFunctionRoute)(route)) {
|
|
12
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
13
|
+
route,
|
|
14
|
+
err,
|
|
15
|
+
channelId: id,
|
|
16
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (id && (0, functions_1.isQueryFunctionRoute)(route)) {
|
|
20
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
21
|
+
route,
|
|
22
|
+
err,
|
|
23
|
+
observableId: id,
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (id) {
|
|
28
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
29
|
+
route,
|
|
30
|
+
err,
|
|
31
|
+
requestId: id,
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
36
|
+
route,
|
|
37
|
+
err,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.defaultAuthError = defaultAuthError;
|
|
41
|
+
const authorize = (route, server, ctx, payload, isAuthorized, id, checksum, authError = exports.defaultAuthError) => {
|
|
42
|
+
if (!ctx.session) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (route.public === true) {
|
|
46
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
server.auth
|
|
50
|
+
.authorize(server.client, ctx, route.name, payload)
|
|
51
|
+
.then((ok) => {
|
|
52
|
+
if (!ctx.session || !ok) {
|
|
53
|
+
if (ctx.session &&
|
|
54
|
+
!authError(route, server, ctx, payload, id, checksum)) {
|
|
55
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
60
|
+
})
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
if (ctx.session &&
|
|
63
|
+
!authError(route, server, ctx, payload, id, checksum, err)) {
|
|
64
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum, err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
exports.authorize = authorize;
|
|
69
|
+
//# sourceMappingURL=authorize%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize copy.js","sourceRoot":"","sources":["../src/authorize copy.ts"],"names":[],"mappings":";;;AACA,2CAIoB;AACpB,2CAAuC;AACvC,mCAAwC;AAgCjC,MAAM,gBAAgB,GAAqB,CAChD,KAAK,EACL,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE,EACF,QAAQ,EACR,GAAG,EACH,EAAE;IACF,MAAM,IAAI,GAAG,GAAG;QACd,CA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EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;SAClD,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACX,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,EAAE,EAAE;YACvB,IACE,GAAG,CAAC,OAAO;gBACX,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EACrD;gBACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;aAC5D;YACD,OAAM;SACP;QACD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;IACzD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IACE,GAAG,CAAC,OAAO;YACX,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,EAC1D;YACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;SACjE;IACH,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AA7CY,QAAA,SAAS,aA6CrB"}
|
package/dist/authorize.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BasedServer } from './server';
|
|
2
|
-
import { BasedRoute } from './functions';
|
|
2
|
+
import { BasedRoute, BasedSpec } from './functions';
|
|
3
3
|
import { HttpSession, Context, WebSocketSession } from '@based/functions';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
type ClientSession = HttpSession | WebSocketSession;
|
|
5
|
+
export type IsAuthorizedHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, spec: BasedSpec<R>, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number) => void;
|
|
6
|
+
export type AuthErrorHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number, err?: Error) => true | void;
|
|
7
7
|
export declare const defaultAuthError: AuthErrorHandler;
|
|
8
|
-
export declare const authorize: <S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any>(route: R, server: BasedServer, ctx: Context<S>, payload: P, isAuthorized: IsAuthorizedHandler<S, R, P>, id?: number, checksum?: number, authError?: AuthErrorHandler<S, R, P>) => void;
|
|
8
|
+
export declare const authorize: <S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any>(route: R, server: BasedServer, ctx: Context<S>, payload: P, isAuthorized: IsAuthorizedHandler<S, R, P>, id?: number, checksum?: number, isPublic?: boolean, authError?: AuthErrorHandler<S, R, P>) => void;
|
|
9
9
|
export {};
|
package/dist/authorize.js
CHANGED
|
@@ -4,10 +4,19 @@ exports.authorize = exports.defaultAuthError = void 0;
|
|
|
4
4
|
const functions_1 = require("./functions");
|
|
5
5
|
const sendError_1 = require("./sendError");
|
|
6
6
|
const error_1 = require("./error");
|
|
7
|
+
const installFn_1 = require("./installFn");
|
|
7
8
|
const defaultAuthError = (route, server, ctx, payload, id, checksum, err) => {
|
|
8
9
|
const code = err
|
|
9
10
|
? error_1.BasedErrorCode.AuthorizeFunctionError
|
|
10
11
|
: error_1.BasedErrorCode.AuthorizeRejectedError;
|
|
12
|
+
if (id && (0, functions_1.isChannelFunctionRoute)(route)) {
|
|
13
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
14
|
+
route,
|
|
15
|
+
err,
|
|
16
|
+
channelId: id,
|
|
17
|
+
});
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
11
20
|
if (id && (0, functions_1.isQueryFunctionRoute)(route)) {
|
|
12
21
|
(0, sendError_1.sendError)(server, ctx, code, {
|
|
13
22
|
route,
|
|
@@ -30,29 +39,36 @@ const defaultAuthError = (route, server, ctx, payload, id, checksum, err) => {
|
|
|
30
39
|
});
|
|
31
40
|
};
|
|
32
41
|
exports.defaultAuthError = defaultAuthError;
|
|
33
|
-
const authorize = (route, server, ctx, payload, isAuthorized, id, checksum, authError = exports.defaultAuthError) => {
|
|
42
|
+
const authorize = (route, server, ctx, payload, isAuthorized, id, checksum, isPublic = false, authError = exports.defaultAuthError) => {
|
|
34
43
|
if (!ctx.session) {
|
|
35
44
|
return;
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
server.auth
|
|
42
|
-
.authorize(server.client, ctx, route.name, payload)
|
|
43
|
-
.then((ok) => {
|
|
44
|
-
if (!ctx.session || !ok) {
|
|
45
|
-
if (!authError(route, server, ctx, payload, id, checksum)) {
|
|
46
|
-
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum);
|
|
47
|
-
}
|
|
46
|
+
(0, installFn_1.installFn)(server, ctx, route, id).then((spec) => {
|
|
47
|
+
if (spec === null) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!authError(route, server, ctx, payload, id, checksum, err)) {
|
|
54
|
-
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum, err);
|
|
50
|
+
if (route.public === true || isPublic) {
|
|
51
|
+
isAuthorized(route, spec, server, ctx, payload, id, checksum);
|
|
52
|
+
return;
|
|
55
53
|
}
|
|
54
|
+
const authorize = spec.authorize || server.auth.authorize;
|
|
55
|
+
authorize(server.client, ctx, route.name, payload)
|
|
56
|
+
.then((ok) => {
|
|
57
|
+
if (!ctx.session || !ok) {
|
|
58
|
+
if (ctx.session &&
|
|
59
|
+
!authError(route, server, ctx, payload, id, checksum)) {
|
|
60
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
isAuthorized(route, spec, server, ctx, payload, id, checksum);
|
|
65
|
+
})
|
|
66
|
+
.catch((err) => {
|
|
67
|
+
if (ctx.session &&
|
|
68
|
+
!authError(route, server, ctx, payload, id, checksum, err)) {
|
|
69
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum, err);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
56
72
|
});
|
|
57
73
|
};
|
|
58
74
|
exports.authorize = authorize;
|
package/dist/authorize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":";;;AACA,2CAKoB;AACpB,2CAAuC;AACvC,mCAAwC;AAExC,2CAAuC;AAgChC,MAAM,gBAAgB,GAAqB,CAChD,KAAK,EACL,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE,EACF,QAAQ,EACR,GAAG,EACH,EAAE;IACF,MAAM,IAAI,GAAG,GAAG;QACd,CAAC,CAAC,sBAAc,CAAC,sBAAsB;QACvC,CAAC,CAAC,sBAAc,CAAC,sBAAsB,CAAA;IAEzC,IAAI,EAAE,IAAI,IAAA,kCAAsB,EAAC,KAAK,CAAC,EAAE;QACvC,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE;YAC3B,KAAK;YACL,GAAG;YACH,SAAS,EAAE,EAAE;SACd,CAAC,CAAA;QACF,OAAM;KACP;IAED,IAAI,EAAE,IAAI,IAAA,gCAAoB,EAAC,KAAK,CAAC,EAAE;QACrC,IAAA,qBAAS,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE;YAC3B,KAAK;YACL,GAAG;YACH,YAAY,EAAE,EAAE;SACjB,CAAC,CAAA;QACF,OAAM;KACP;IAED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AAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EACrD;oBACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;iBAC5D;gBACD,OAAM;aACP;YACD,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC/D,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,IACE,GAAG,CAAC,OAAO;gBACX,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,EAC1D;gBACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;aACjE;QACH,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AArDY,QAAA,SAAS,aAqDrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasedServer } from './server';
|
|
2
|
+
import { BasedRoute } from './functions';
|
|
3
|
+
import { HttpSession, Context, WebSocketSession } from '@based/functions';
|
|
4
|
+
type ClientSession = HttpSession | WebSocketSession;
|
|
5
|
+
export type IsAuthorizedHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number) => void;
|
|
6
|
+
export type AuthErrorHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number, err?: Error) => true | void;
|
|
7
|
+
export declare const defaultAuthError: AuthErrorHandler;
|
|
8
|
+
export declare const authorize: <S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any>(route: R, server: BasedServer, ctx: Context<S>, payload: P, isAuthorized: IsAuthorizedHandler<S, R, P>, id?: number, checksum?: number, authError?: AuthErrorHandler<S, R, P>) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorize = exports.defaultAuthError = void 0;
|
|
4
|
+
const functions_1 = require("./functions");
|
|
5
|
+
const sendError_1 = require("./sendError");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const defaultAuthError = (route, server, ctx, payload, id, checksum, err) => {
|
|
8
|
+
const code = err
|
|
9
|
+
? error_1.BasedErrorCode.AuthorizeFunctionError
|
|
10
|
+
: error_1.BasedErrorCode.AuthorizeRejectedError;
|
|
11
|
+
if (id && (0, functions_1.isChannelFunctionRoute)(route)) {
|
|
12
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
13
|
+
route,
|
|
14
|
+
err,
|
|
15
|
+
channelId: id,
|
|
16
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (id && (0, functions_1.isQueryFunctionRoute)(route)) {
|
|
20
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
21
|
+
route,
|
|
22
|
+
err,
|
|
23
|
+
observableId: id,
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (id) {
|
|
28
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
29
|
+
route,
|
|
30
|
+
err,
|
|
31
|
+
requestId: id,
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
36
|
+
route,
|
|
37
|
+
err,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.defaultAuthError = defaultAuthError;
|
|
41
|
+
const authorize = (route, server, ctx, payload, isAuthorized, id, checksum, authError = exports.defaultAuthError) => {
|
|
42
|
+
if (!ctx.session) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (route.public === true) {
|
|
46
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
server.auth
|
|
50
|
+
.authorize(server.client, ctx, route.name, payload)
|
|
51
|
+
.then((ok) => {
|
|
52
|
+
if (!ctx.session || !ok) {
|
|
53
|
+
if (ctx.session &&
|
|
54
|
+
!authError(route, server, ctx, payload, id, checksum)) {
|
|
55
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum);
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
60
|
+
})
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
if (ctx.session &&
|
|
63
|
+
!authError(route, server, ctx, payload, id, checksum, err)) {
|
|
64
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum, err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
exports.authorize = authorize;
|
|
69
|
+
//# sourceMappingURL=authorizeAndInstall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorizeAndInstall.js","sourceRoot":"","sources":["../src/authorizeAndInstall.ts"],"names":[],"mappings":";;;AACA,2CAIoB;AACpB,2CAAuC;AACvC,mCAAwC;AAgCjC,MAAM,gBAAgB,GAAqB,CAChD,KAAK,EACL,MAAM,EACN,GAAG,EACH,OAAO,EACP,EAAE,EACF,QAAQ,EACR,GAAG,EACH,EAAE;IACF,MAAM,IAAI,GAAG,GAAG;QACd,CAAC,CAAC,sBAAc,CAAC,sBAAsB;QACvC,CAAC,CAAC,sBAAc,CAAC,sBAAsB,CAAA;IAEzC,IAAI,EAAE,IAAI,IAAA,kCAAsB,EAAC,KAAK,CAAC,EAAE;QACvC,IAAA,qBAAS,E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AAC,OAAO;gBACX,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EACrD;gBACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;aAC5D;YACD,OAAM;SACP;QACD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;IACzD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IACE,GAAG,CAAC,OAAO;YACX,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,EAC1D;YACA,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;SACjE;IACH,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AA7CY,QAAA,SAAS,aA6CrB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanUpChannels = void 0;
|
|
4
|
+
const destroyChannel = (server, channel) => {
|
|
5
|
+
const id = channel.id;
|
|
6
|
+
channel.timeTillDestroy = null;
|
|
7
|
+
if (!server.activeChannels[channel.name]) {
|
|
8
|
+
console.info('Trying to destroy a removed channel function');
|
|
9
|
+
server.activeChannelsById.delete(id);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
server.activeChannels[channel.name].delete(id);
|
|
13
|
+
if (server.activeChannels[channel.name].size === 0) {
|
|
14
|
+
delete server.activeChannels[channel.name];
|
|
15
|
+
}
|
|
16
|
+
server.activeChannelsById.delete(id);
|
|
17
|
+
channel.isDestroyed = true;
|
|
18
|
+
if (channel.closeFunction) {
|
|
19
|
+
channel.isActive = false;
|
|
20
|
+
channel.closeFunction();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const cleanUpChannels = (server) => {
|
|
24
|
+
if (!server.channelCleanTimeout) {
|
|
25
|
+
const cycleTime = Math.max(server.channelCleanupCycle, 500);
|
|
26
|
+
server.channelCleanTimeout = setTimeout(() => {
|
|
27
|
+
server.channelCleanTimeout = null;
|
|
28
|
+
let keepRunning = false;
|
|
29
|
+
let shortestCycleTime;
|
|
30
|
+
server.activeChannelsById.forEach((channel) => {
|
|
31
|
+
if (channel.timeTillDestroy !== null) {
|
|
32
|
+
channel.timeTillDestroy -= cycleTime;
|
|
33
|
+
if (channel.timeTillDestroy < 1) {
|
|
34
|
+
destroyChannel(server, channel);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (shortestCycleTime === undefined ||
|
|
38
|
+
channel.timeTillDestroy < shortestCycleTime) {
|
|
39
|
+
shortestCycleTime = channel.timeTillDestroy;
|
|
40
|
+
}
|
|
41
|
+
keepRunning = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (keepRunning) {
|
|
46
|
+
server.channelCleanupCycle = Math.round(shortestCycleTime / 2);
|
|
47
|
+
(0, exports.cleanUpChannels)(server);
|
|
48
|
+
}
|
|
49
|
+
}, cycleTime);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.cleanUpChannels = cleanUpChannels;
|
|
53
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../../src/channel/cleanup.ts"],"names":[],"mappings":";;;AAGA,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAE,OAAsB,EAAE,EAAE;IACrE,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,CAAA;IACrB,OAAO,CAAC,eAAe,GAA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;oBACpC,IAAI,OAAO,CAAC,eAAe,GAAG,CAAC,EAAE;wBAC/B,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;qBAChC;yBAAM;wBACL,IACE,iBAAiB,KAAK,SAAS;4BAC/B,OAAO,CAAC,eAAe,GAAG,iBAAiB,EAC3C;4BACA,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAA;yBAC5C;wBACD,WAAW,GAAG,IAAI,CAAA;qBACnB;iBACF;YACH,CAAC,CAAC,CAAA;YACF,IAAI,WAAW,EAAE;gBACf,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAA;gBAC9D,IAAA,uBAAe,EAAC,MAAM,CAAC,CAAA;aACxB;QACH,CAAC,EAAE,SAAS,CAAC,CAAA;KACd;AACH,CAAC,CAAA;AA7BY,QAAA,eAAe,mBA6B3B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createChannel = void 0;
|
|
4
|
+
const start_1 = require("./start");
|
|
5
|
+
const get_1 = require("./get");
|
|
6
|
+
const createChannel = (server, name, id, payload, noStart) => {
|
|
7
|
+
if ((0, get_1.hasChannel)(server, id)) {
|
|
8
|
+
const msg = `Allready has channel ${name} ${id}`;
|
|
9
|
+
console.error(msg);
|
|
10
|
+
throw new Error(msg);
|
|
11
|
+
}
|
|
12
|
+
const channel = {
|
|
13
|
+
payload,
|
|
14
|
+
clients: new Set(),
|
|
15
|
+
functionChannelClients: new Set(),
|
|
16
|
+
id,
|
|
17
|
+
name,
|
|
18
|
+
isDestroyed: false,
|
|
19
|
+
isActive: false,
|
|
20
|
+
timeTillDestroy: null,
|
|
21
|
+
};
|
|
22
|
+
if (!server.activeChannels[name]) {
|
|
23
|
+
server.activeChannels[name] = new Map();
|
|
24
|
+
}
|
|
25
|
+
server.activeChannels[name].set(id, channel);
|
|
26
|
+
server.activeChannelsById.set(id, channel);
|
|
27
|
+
if (!noStart) {
|
|
28
|
+
(0, start_1.startChannel)(server, id);
|
|
29
|
+
}
|
|
30
|
+
return channel;
|
|
31
|
+
};
|
|
32
|
+
exports.createChannel = createChannel;
|
|
33
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/channel/create.ts"],"names":[],"mappings":";;;AAEA,mCAAsC;AACtC,+BAAkC;AAE3B,MAAM,aAAa,GAAG,CAC3B,MAAmB,EACnB,IAAY,EACZ,EAAU,EACV,OAAY,EACZ,OAAiB,EACF,EAAE;IACjB,IAAI,IAAA,gBAAU,EAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QAC1B,MAAM,GAAG,GAAG,wBAAwB,IAAI,IAAI,EAAE,EAAE,CAAA;QAChD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;IAED,MAAM,OAAO,GAAkB;QAC7B,OAAO;QACP,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,sBAAsB,EAAE,IAAI,GAAG,EAAE;QACjC,EAAE;QACF,IAAI;QACJ,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,KAAK;QACf,eAAe,EAAE,IAAI;KACtB,CAAA;IAED,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAA;KACxC;IAED,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC5C,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAE1C,IAAI,CAAC,OAAO,EAAE;QACZ,IAAA,oBAAY,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;KACzB;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAnCY,QAAA,aAAa,iBAmCzB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.destroyChannel = exports.updateDestroyTimer = void 0;
|
|
4
|
+
const functions_1 = require("../functions");
|
|
5
|
+
const cleanup_1 = require("./cleanup");
|
|
6
|
+
const updateDestroyTimer = (server, channel) => {
|
|
7
|
+
const spec = server.functions.specs[channel.name];
|
|
8
|
+
if (spec && !(0, functions_1.isChannelFunctionSpec)(spec)) {
|
|
9
|
+
console.error('channel updateDestroyTimer - Not channel spec!', spec, channel.name);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const closeAfterIdleTime =
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
spec?.closeAfterIdleTime ??
|
|
15
|
+
server.functions.config.closeAfterIdleTime.channel;
|
|
16
|
+
channel.timeTillDestroy = closeAfterIdleTime;
|
|
17
|
+
channel.closeAfterIdleTime = closeAfterIdleTime;
|
|
18
|
+
const closeTime = Math.round(closeAfterIdleTime / 2);
|
|
19
|
+
if (closeTime < server.channelCleanupCycle) {
|
|
20
|
+
server.channelCleanupCycle = closeTime;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.updateDestroyTimer = updateDestroyTimer;
|
|
24
|
+
// dont use timer just use counter to remove it over time
|
|
25
|
+
const destroyChannel = (server, id) => {
|
|
26
|
+
const channel = server.activeChannelsById.get(id);
|
|
27
|
+
if (!channel) {
|
|
28
|
+
console.error('destroyChannel', id, 'does not exist!');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (channel.isDestroyed) {
|
|
32
|
+
console.error('Channel allready destroyed', channel.name);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (channel.clients.size || channel.functionChannelClients.size) {
|
|
36
|
+
if (channel.timeTillDestroy) {
|
|
37
|
+
console.warn(`Channel being destroyed while listeners are present ${channel.name} ${channel.id}`, channel.payload);
|
|
38
|
+
channel.timeTillDestroy = null;
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (channel.timeTillDestroy === null) {
|
|
43
|
+
(0, exports.updateDestroyTimer)(server, channel);
|
|
44
|
+
(0, cleanup_1.cleanUpChannels)(server);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.destroyChannel = destroyChannel;
|
|
48
|
+
//# sourceMappingURL=destroy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/channel/destroy.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AAEpD,uCAA2C;AAGpC,MAAM,kBAAkB,GAAG,CAChC,MAAmB,EACnB,OAAsB,EACtB,EAAE;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,IAAI,IAAI,IAAI,CAAC,IAAA,iCAAqB,EAAC,IAAI,CAAC,EAAE;QACxC,OAAO,CAAC,KAAK,CACX,gDAAgD,EAChD,IAAI,EACJ,OAAO,CAAC,IAAI,CACb,CAAA;QACD,OAAM;KACP;IAED,MAAM,kBAAkB;IACtB,aAAa;IACb,IAAI,EAAE,kBAAkB;QACxB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAA;IACpD,OAAO,CAAC,eAAe,GAAG,kBAAkB,CAAA;IAC5C,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAA;IACpD,IAAI,SAAS,GAAG,MAAM,CAAC,mBAAmB,EAAE;QAC1C,MAAM,CAAC,mBAAmB,GAAG,SAAS,CAAA;KACvC;AACH,CAAC,CAAA;AAxBY,QAAA,kBAAkB,sBAwB9B;AAED,yDAAyD;AAClD,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAE,EAAU,EAAE,EAAE;IAChE,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEjD,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,CAAC,CAAA;QACtD,OAAM;KACP;IAED,IAAI,OAAO,CAAC,WAAW,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QACzD,OAAM;KACP;IAED,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC,IAAI,EAAE;QAC/D,IAAI,OAAO,CAAC,eAAe,EAAE;YAC3B,OAAO,CAAC,IAAI,CACV,uDAAuD,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,EAAE,EACnF,OAAO,CAAC,OAAO,CAChB,CAAA;YACD,OAAO,CAAC,eAAe,GAAG,IAAI,CAAA;SAC/B;QACD,OAAM;KACP;IAED,IAAI,OAAO,CAAC,eAAe,KAAK,IAAI,EAAE;QACpC,IAAA,0BAAkB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnC,IAAA,yBAAe,EAAC,MAAM,CAAC,CAAA;KACxB;AACH,CAAC,CAAA;AA5BY,QAAA,cAAc,kBA4B1B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendChannel = exports.stopRemoveChannel = void 0;
|
|
4
|
+
const stopRemoveChannel = (channel) => {
|
|
5
|
+
if (channel.timeTillDestroy) {
|
|
6
|
+
channel.timeTillDestroy = null;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.stopRemoveChannel = stopRemoveChannel;
|
|
10
|
+
const extendChannel = (server, channel) => {
|
|
11
|
+
if (channel.closeAfterIdleTime && channel.timeTillDestroy !== null) {
|
|
12
|
+
channel.timeTillDestroy = channel.closeAfterIdleTime;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.extendChannel = extendChannel;
|
|
16
|
+
//# sourceMappingURL=extend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extend.js","sourceRoot":"","sources":["../../src/channel/extend.ts"],"names":[],"mappings":";;;AAGO,MAAM,iBAAiB,GAAG,CAAC,OAAsB,EAAE,EAAE;IAC1D,IAAI,OAAO,CAAC,eAAe,EAAE;QAC3B,OAAO,CAAC,eAAe,GAAG,IAAI,CAAA;KAC/B;AACH,CAAC,CAAA;AAJY,QAAA,iBAAiB,qBAI7B;AAEM,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAE,OAAsB,EAAE,EAAE;IAC3E,IAAI,OAAO,CAAC,kBAAkB,IAAI,OAAO,CAAC,eAAe,KAAK,IAAI,EAAE;QAClE,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAA;KACrD;AACH,CAAC,CAAA;AAJY,QAAA,aAAa,iBAIzB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasChannel = exports.getChannelAndStopRemove = void 0;
|
|
4
|
+
const extend_1 = require("./extend");
|
|
5
|
+
const getChannelAndStopRemove = (server, id) => {
|
|
6
|
+
const obs = server.activeChannelsById.get(id);
|
|
7
|
+
(0, extend_1.stopRemoveChannel)(obs);
|
|
8
|
+
return obs;
|
|
9
|
+
};
|
|
10
|
+
exports.getChannelAndStopRemove = getChannelAndStopRemove;
|
|
11
|
+
const hasChannel = (server, id) => {
|
|
12
|
+
return server.activeChannelsById.has(id);
|
|
13
|
+
};
|
|
14
|
+
exports.hasChannel = hasChannel;
|
|
15
|
+
//# sourceMappingURL=get.js.map
|