diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index d00a820a..62daef9a 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -169,11 +169,11 @@ export class AuthenticateController extends BaseHttpController { //Get user data from Admin Back Office //This is very important to create User Local in LocalStorage in WorkAdventure const resUserData = await adminService.fetchMemberDataByUuid( - req.header("accept-language"), authTokenData.identifier, playUri as string, IPAddress, - [] + [], + req.header("accept-language") ); if (authTokenData.accessToken == undefined) { @@ -225,7 +225,13 @@ export class AuthenticateController extends BaseHttpController { //Get user data from Admin Back Office //This is very important to create User Local in LocalStorage in WorkAdventure - const data = await adminService.fetchMemberDataByUuid(req.header("accept-language"), email, playUri as string, IPAddress, []); + const data = await adminService.fetchMemberDataByUuid( + email, + playUri as string, + IPAddress, + [], + req.header("accept-language") + ); return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale }); } catch (e) { @@ -328,7 +334,11 @@ export class AuthenticateController extends BaseHttpController { try { if (typeof organizationMemberToken != "string") throw new Error("No organization token"); - const data = await adminService.fetchMemberDataByToken(req.header("accept-language"), organizationMemberToken, playUri); + const data = await adminService.fetchMemberDataByToken( + organizationMemberToken, + playUri, + req.header("accept-language") + ); const userUuid = data.userUuid; const email = data.email; const roomUrl = data.roomUrl; @@ -506,7 +516,7 @@ export class AuthenticateController extends BaseHttpController { userRoomToken: undefined, }; try { - data = await adminService.fetchMemberDataByUuid("en", email, playUri, IPAddress, []); + data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []); } catch (err) { console.error("openIDCallback => fetchMemberDataByUuid", err); } diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 31ed0203..b08e2091 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -107,7 +107,11 @@ export class MapController extends BaseHttpController { (async () => { try { const mapDetails = isMapDetailsData.parse( - await adminService.fetchMapDetails(req.header("accept-language"), query.playUri as string, query.authToken as string) + await adminService.fetchMapDetails( + req.header("accept-language"), + query.playUri as string, + query.authToken as string + ) ); if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true; diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index 01b9ff98..caefd8e2 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -29,7 +29,11 @@ export const isFetchMemberDataByUuidResponse = z.object({ export type FetchMemberDataByUuidResponse = z.infer; class AdminApi implements AdminInterface { - async fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise { + async fetchMapDetails( + playUri: string, + authToken?: string, + locale?: string + ): Promise { let userId: string | undefined = undefined; if (authToken != undefined) { let authTokenData: AuthTokenData; @@ -64,7 +68,7 @@ class AdminApi implements AdminInterface { }; const res = await Axios.get>(ADMIN_API_URL + "/api/map", { - headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, + headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" }, params, }); @@ -87,11 +91,11 @@ class AdminApi implements AdminInterface { } async fetchMemberDataByUuid( - locale: string, userIdentifier: string, playUri: string, ipAddress: string, - characterLayers: string[] + characterLayers: string[], + locale?: string ): Promise { const res = await Axios.get>(ADMIN_API_URL + "/api/room/access", { params: { @@ -100,7 +104,7 @@ class AdminApi implements AdminInterface { ipAddress, characterLayers, }, - headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, + headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" }, paramsSerializer: (p) => { return qs.stringify(p, { arrayFormat: "brackets" }); }, @@ -119,11 +123,15 @@ class AdminApi implements AdminInterface { ); } - async fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise { + async fetchMemberDataByToken( + organizationMemberToken: string, + playUri: string | null, + locale?: string + ): Promise { //todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case. const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, { params: { playUri }, - headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, + headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" }, }); const adminApiData = isAdminApiData.safeParse(res.data); @@ -138,11 +146,11 @@ class AdminApi implements AdminInterface { } reportPlayer( - locale: string, reportedUserUuid: string, reportedUserComment: string, reporterUserUuid: string, - reportWorldSlug: string + reportWorldSlug: string, + locale?: string ) { return Axios.post( `${ADMIN_API_URL}/api/report`, @@ -153,12 +161,17 @@ class AdminApi implements AdminInterface { reportWorldSlug, }, { - headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, + headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" }, } ); } - async verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise { + async verifyBanUser( + userUuid: string, + ipAddress: string, + roomUrl: string, + locale?: string + ): Promise { //todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case. return Axios.get( ADMIN_API_URL + @@ -169,15 +182,15 @@ class AdminApi implements AdminInterface { encodeURIComponent(userUuid) + "&roomUrl=" + encodeURIComponent(roomUrl), - { headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale } } + { headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" } } ).then((data) => { return data.data; }); } - async getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise { + async getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise { return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), { - headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, + headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" }, }).then((data) => { return data.data; }); diff --git a/pusher/src/Services/AdminInterface.ts b/pusher/src/Services/AdminInterface.ts index ccb664e1..e70a653a 100644 --- a/pusher/src/Services/AdminInterface.ts +++ b/pusher/src/Services/AdminInterface.ts @@ -4,7 +4,6 @@ import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect"; import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; export interface AdminInterface { - /** * @var playUri: is url of the room * @var userIdentifier: can to be undefined or email or uuid @@ -13,11 +12,11 @@ export interface AdminInterface { * @return MapDetailsData|RoomRedirect */ fetchMemberDataByUuid( - locale: string, userIdentifier: string, playUri: string, ipAddress: string, - characterLayers: string[] + characterLayers: string[], + locale?: string ): Promise; /** @@ -25,7 +24,7 @@ export interface AdminInterface { * @var userId: can to be undefined or email or uuid * @return MapDetailsData|RoomRedirect */ - fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise; + fetchMapDetails(playUri: string, authToken?: string, locale?: string): Promise; /** * @param locale @@ -33,7 +32,11 @@ export interface AdminInterface { * @param playUri * @return AdminApiData */ - fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise; + fetchMemberDataByToken( + organizationMemberToken: string, + playUri: string | null, + locale?: string + ): Promise; /** * @param locale @@ -43,11 +46,11 @@ export interface AdminInterface { * @param reportWorldSlug */ reportPlayer( - locale: string, reportedUserUuid: string, reportedUserComment: string, reporterUserUuid: string, - reportWorldSlug: string + reportWorldSlug: string, + locale?: string ): Promise; /** @@ -57,14 +60,14 @@ export interface AdminInterface { * @param roomUrl * @return AdminBannedData */ - verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise; + verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string, locale?: string): Promise; /** * @param locale * @param roomUrl * @return string[] */ - getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise; + getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise; /** * @param accessToken diff --git a/pusher/src/Services/LocalAdmin.ts b/pusher/src/Services/LocalAdmin.ts index a92d292a..d4c8bcba 100644 --- a/pusher/src/Services/LocalAdmin.ts +++ b/pusher/src/Services/LocalAdmin.ts @@ -10,17 +10,16 @@ import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; * A local class mocking a real admin if no admin is configured. */ class LocalAdmin implements AdminInterface { - fetchMemberDataByUuid( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, userIdentifier: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars playUri: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars ipAddress: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - characterLayers: string[] + characterLayers: string[], + // eslint-disable-next-line @typescript-eslint/no-unused-vars + locale?: string ): Promise { return Promise.resolve({ email: userIdentifier, @@ -34,11 +33,11 @@ class LocalAdmin implements AdminInterface { } fetchMapDetails( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, playUri: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - authToken?: string + authToken?: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + locale?: string ): Promise { const roomUrl = new URL(playUri); @@ -64,19 +63,17 @@ class LocalAdmin implements AdminInterface { } async fetchMemberDataByToken( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars organizationMemberToken: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - playUri: string | null + playUri: string | null, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + locale?: string ): Promise { return Promise.reject(new Error("No admin backoffice set!")); } reportPlayer( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars reportedUserUuid: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -84,29 +81,31 @@ class LocalAdmin implements AdminInterface { // eslint-disable-next-line @typescript-eslint/no-unused-vars reporterUserUuid: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - reportWorldSlug: string + reportWorldSlug: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + locale?: string ) { return Promise.reject(new Error("No admin backoffice set!")); } async verifyBanUser( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars userUuid: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars ipAddress: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - roomUrl: string + roomUrl: string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + locale?: string ): Promise { return Promise.reject(new Error("No admin backoffice set!")); } async getUrlRoomsFromSameWorld( // eslint-disable-next-line @typescript-eslint/no-unused-vars - locale: string, + roomUrl: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - roomUrl: string + locale?: string ): Promise { return Promise.reject(new Error("No admin backoffice set!")); } diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index c2d904ed..54697062 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -125,10 +125,10 @@ export class SocketManager implements ZoneEventListener { .on("end", () => { console.warn( "Admin connection lost to back server '" + - apiClient.getChannel().getTarget() + - "' for room '" + - roomId + - "'" + apiClient.getChannel().getTarget() + + "' for room '" + + roomId + + "'" ); // Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start. if (!client.disconnecting) { @@ -139,10 +139,10 @@ export class SocketManager implements ZoneEventListener { .on("error", (err: Error) => { console.error( "Error in connection to back server '" + - apiClient.getChannel().getTarget() + - "' for room '" + - roomId + - "':", + apiClient.getChannel().getTarget() + + "' for room '" + + roomId + + "':", err ); if (!client.disconnecting) { @@ -231,10 +231,10 @@ export class SocketManager implements ZoneEventListener { .on("end", () => { console.warn( "Connection lost to back server '" + - apiClient.getChannel().getTarget() + - "' for room '" + - client.roomId + - "'" + apiClient.getChannel().getTarget() + + "' for room '" + + client.roomId + + "'" ); // Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start. if (!client.disconnecting) { @@ -245,10 +245,10 @@ export class SocketManager implements ZoneEventListener { .on("error", (err: Error) => { console.error( "Error in connection to back server '" + - apiClient.getChannel().getTarget() + - "' for room '" + - client.roomId + - "':", + apiClient.getChannel().getTarget() + + "' for room '" + + client.roomId + + "':", err ); if (!client.disconnecting) {