@signe/room 2.8.3 → 2.9.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/index.d.ts +6 -1
- package/dist/index.js +37 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +48 -0
- package/src/decorators.ts +13 -1
- package/src/server.ts +39 -25
package/dist/index.d.ts
CHANGED
|
@@ -175,6 +175,11 @@ type ServerOptions = {
|
|
|
175
175
|
type GuardFn = (sender: Connection, value: any | Request$1, room: Room$1) => boolean | Promise<boolean | Response>;
|
|
176
176
|
type RoomGuardFn = (conn: Connection, ctx: ConnectionContext, room: Room$1) => boolean | Promise<boolean | Response>;
|
|
177
177
|
declare function Action(name: string, bodyValidation?: z.ZodSchema): (target: any, propertyKey: string) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Fallback decorator for handling websocket messages whose action
|
|
180
|
+
* does not match any registered @Action decorator.
|
|
181
|
+
*/
|
|
182
|
+
declare function UnhandledAction(): (target: any, propertyKey: string) => void;
|
|
178
183
|
/**
|
|
179
184
|
* Request decorator for handling HTTP requests with path and method routing
|
|
180
185
|
* @param options Configuration for the HTTP request handler
|
|
@@ -922,4 +927,4 @@ declare function createRequireSessionGuard(storage: Storage$1): (sender: Connect
|
|
|
922
927
|
*/
|
|
923
928
|
declare const requireSession: (sender: Connection, value: any, room: Room$1) => Promise<boolean>;
|
|
924
929
|
|
|
925
|
-
export { Action, ClientIo, Guard, MockConnection, Request, type RequestOptions, Room, RoomGuard, type RoomInterceptorPacket, type RoomMethods, type RoomOnJoin, type RoomOnLeave, type RoomOptions, Server, ServerIo, ServerResponse, Shard, type ShardOptions, WorldRoom, createRequireSessionGuard, request, requireSession, testRoom, tick };
|
|
930
|
+
export { Action, ClientIo, Guard, MockConnection, Request, type RequestOptions, Room, RoomGuard, type RoomInterceptorPacket, type RoomMethods, type RoomOnJoin, type RoomOnLeave, type RoomOptions, Server, ServerIo, ServerResponse, Shard, type ShardOptions, UnhandledAction, WorldRoom, createRequireSessionGuard, request, requireSession, testRoom, tick };
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,14 @@ function Action(name, bodyValidation) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
__name(Action, "Action");
|
|
17
|
+
function UnhandledAction() {
|
|
18
|
+
return function(target, propertyKey) {
|
|
19
|
+
target.constructor._unhandledActionMetadata = {
|
|
20
|
+
key: propertyKey
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
__name(UnhandledAction, "UnhandledAction");
|
|
17
25
|
function Request2(options, bodyValidation) {
|
|
18
26
|
return function(target, propertyKey) {
|
|
19
27
|
if (!target.constructor._requestMetadata) {
|
|
@@ -1050,27 +1058,37 @@ var Server = class {
|
|
|
1050
1058
|
}
|
|
1051
1059
|
}
|
|
1052
1060
|
const actions = subRoom.constructor["_actionMetadata"];
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1061
|
+
const signal2 = this.getUsersProperty(subRoom);
|
|
1062
|
+
const { publicId } = sender.state;
|
|
1063
|
+
const user = signal2?.()[publicId];
|
|
1064
|
+
const actionName = actions?.get(result.data.action);
|
|
1065
|
+
if (actionName) {
|
|
1066
|
+
const guards = subRoom.constructor["_actionGuards"]?.get(actionName.key) || [];
|
|
1067
|
+
for (const guard of guards) {
|
|
1068
|
+
const isAuthorized = await guard(sender, result.data.value, this.room);
|
|
1069
|
+
if (!isAuthorized) {
|
|
1070
|
+
return;
|
|
1065
1071
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1072
|
+
}
|
|
1073
|
+
if (actionName.bodyValidation) {
|
|
1074
|
+
const bodyResult = actionName.bodyValidation.safeParse(result.data.value);
|
|
1075
|
+
if (!bodyResult.success) {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
await awaitReturn(subRoom[actionName.key](user, result.data.value, sender));
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
const unhandledAction = subRoom.constructor["_unhandledActionMetadata"];
|
|
1083
|
+
if (unhandledAction) {
|
|
1084
|
+
const guards = subRoom.constructor["_actionGuards"]?.get(unhandledAction.key) || [];
|
|
1085
|
+
for (const guard of guards) {
|
|
1086
|
+
const isAuthorized = await guard(sender, result.data, this.room);
|
|
1087
|
+
if (!isAuthorized) {
|
|
1088
|
+
return;
|
|
1071
1089
|
}
|
|
1072
|
-
await awaitReturn(subRoom[actionName.key](user, result.data.value, sender));
|
|
1073
1090
|
}
|
|
1091
|
+
await awaitReturn(subRoom[unhandledAction.key](user, result.data, sender));
|
|
1074
1092
|
}
|
|
1075
1093
|
}
|
|
1076
1094
|
/**
|
|
@@ -2732,6 +2750,7 @@ export {
|
|
|
2732
2750
|
ServerIo,
|
|
2733
2751
|
ServerResponse,
|
|
2734
2752
|
Shard,
|
|
2753
|
+
UnhandledAction,
|
|
2735
2754
|
WorldRoom,
|
|
2736
2755
|
createRequireSessionGuard,
|
|
2737
2756
|
request,
|