003bc86262
* Change accès token with query privateAccessToken in the url Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Add play uri param Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * PlayUri parameter Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * removed unused imports * send group userIds to players * sending info about group lock state. wip * listening to lockGroupMessage on front * cleanup * Updating GroupDescriptors on LockGroupMessage * remove console logs * group circles with color fill * fix GameRoom text * remove obsolete check * cr fixes #1 wip * much cleaner approach to group lock update * fix compilation error * well-known values wip * Removing old unused images Just a bit of cleanup! * update with dan suggest Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Change roomId by playUri Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * hide voice indicator for player leaving still existing bubble conversation * Refactor access by token Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Refactor connexion manager Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Add z-index on embeds screens and action menu * Fixes tileset import * Adds settings options and localUser functions * PrivacyShutdownStore modifies constraints according to the user's setting * switches dropdown for checkboxes and adjusts wording * Adds the todo about German translation * Adds test map * Makes the default setting: camera off and mic on * Fixes tileset import * Applying German translation, thanks to @Lurkars * removed obsolete console.log * fix linter issues * make use of proto well knows types * fixed types for RoomConnection * fix locking bubble when returning from away mode * Fix run pretty Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> * prevent actions menu from appearing when inserting space key on chat * Bump ansi-regex from 4.1.0 to 4.1.1 in /maps Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump minimist from 1.2.5 to 1.2.6 in /desktop/local-app Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /desktop/electron Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump ansi-regex from 4.1.0 to 4.1.1 in /uploader Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump plist from 3.0.4 to 3.0.5 in /desktop/electron Bumps [plist](https://github.com/TooTallNate/node-plist) from 3.0.4 to 3.0.5. - [Release notes](https://github.com/TooTallNate/node-plist/releases) - [Changelog](https://github.com/TooTallNate/plist.js/blob/master/History.md) - [Commits](https://github.com/TooTallNate/node-plist/commits) --- updated-dependencies: - dependency-name: plist dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> Co-authored-by: Piotr 'pwh' Hanusiak <p.hanusiak@workadventu.re> Co-authored-by: Benedicte Quimbert <b.quimbert@workadventu.re> Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Bénédicte Q <37311765+HimeShaman@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
180 lines
6.3 KiB
TypeScript
180 lines
6.3 KiB
TypeScript
import { ADMIN_API_TOKEN, ADMIN_API_URL, ADMIN_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
|
|
import Axios, { AxiosResponse } from "axios";
|
|
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
|
import { isRoomRedirect, RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
|
import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
|
import * as tg from "generic-type-guard";
|
|
import { isNumber } from "generic-type-guard";
|
|
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
|
import qs from "qs";
|
|
|
|
export interface AdminBannedData {
|
|
is_banned: boolean;
|
|
message: string;
|
|
}
|
|
|
|
const isFetchMemberDataByUuidResponse = new tg.IsInterface()
|
|
.withProperties({
|
|
email: tg.isString,
|
|
userUuid: tg.isString,
|
|
tags: tg.isArray(tg.isString),
|
|
visitCardUrl: tg.isNullable(tg.isString),
|
|
textures: tg.isArray(isWokaDetail),
|
|
messages: tg.isArray(tg.isUnknown),
|
|
})
|
|
.withOptionalProperties({
|
|
anonymous: tg.isBoolean,
|
|
userRoomToken: tg.isString,
|
|
})
|
|
.get();
|
|
|
|
export type FetchMemberDataByUuidResponse = tg.GuardedType<typeof isFetchMemberDataByUuidResponse>;
|
|
|
|
class AdminApi {
|
|
/**
|
|
* @var playUri: is url of the room
|
|
* @var userId: can to be undefined or email or uuid
|
|
* @return MapDetailsData|RoomRedirect
|
|
*/
|
|
async fetchMapDetails(playUri: string, userId?: string): Promise<MapDetailsData | RoomRedirect> {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
|
|
const params: { playUri: string; userId?: string } = {
|
|
playUri,
|
|
userId,
|
|
};
|
|
|
|
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/map", {
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
params,
|
|
});
|
|
if (!isMapDetailsData(res.data) && !isRoomRedirect(res.data)) {
|
|
throw new Error(
|
|
"Invalid answer received from the admin for the /api/map endpoint. Received: " +
|
|
JSON.stringify(res.data)
|
|
);
|
|
}
|
|
return res.data;
|
|
}
|
|
|
|
async fetchMemberDataByUuid(
|
|
userIdentifier: string | null,
|
|
playUri: string,
|
|
ipAddress: string,
|
|
characterLayers: string[]
|
|
): Promise<FetchMemberDataByUuidResponse> {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/room/access", {
|
|
params: {
|
|
userIdentifier,
|
|
playUri,
|
|
ipAddress,
|
|
characterLayers,
|
|
},
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
paramsSerializer: (p) => {
|
|
return qs.stringify(p, { arrayFormat: "brackets" });
|
|
},
|
|
});
|
|
if (!isFetchMemberDataByUuidResponse(res.data)) {
|
|
throw new Error(
|
|
"Invalid answer received from the admin for the /api/room/access endpoint. Received: " +
|
|
JSON.stringify(res.data)
|
|
);
|
|
}
|
|
return res.data;
|
|
}
|
|
|
|
async fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
//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}` },
|
|
});
|
|
if (!isAdminApiData(res.data)) {
|
|
console.error("Message received from /api/login-url is not in the expected format. Message: ", res.data);
|
|
throw new Error("Message received from /api/login-url is not in the expected format.");
|
|
}
|
|
return res.data;
|
|
}
|
|
|
|
reportPlayer(
|
|
reportedUserUuid: string,
|
|
reportedUserComment: string,
|
|
reporterUserUuid: string,
|
|
reportWorldSlug: string
|
|
) {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
return Axios.post(
|
|
`${ADMIN_API_URL}/api/report`,
|
|
{
|
|
reportedUserUuid,
|
|
reportedUserComment,
|
|
reporterUserUuid,
|
|
reportWorldSlug,
|
|
},
|
|
{
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
}
|
|
);
|
|
}
|
|
|
|
async verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
//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 +
|
|
"/api/ban" +
|
|
"?ipAddress=" +
|
|
encodeURIComponent(ipAddress) +
|
|
"&token=" +
|
|
encodeURIComponent(userUuid) +
|
|
"&roomUrl=" +
|
|
encodeURIComponent(roomUrl),
|
|
{ headers: { Authorization: `${ADMIN_API_TOKEN}` } }
|
|
).then((data) => {
|
|
return data.data;
|
|
});
|
|
}
|
|
|
|
async getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]> {
|
|
if (!ADMIN_API_URL) {
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
|
}
|
|
|
|
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
}).then((data) => {
|
|
return data.data;
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param accessToken
|
|
*/
|
|
getProfileUrl(accessToken: string): string {
|
|
if (!OPID_PROFILE_SCREEN_PROVIDER) {
|
|
throw new Error("No admin backoffice set!");
|
|
}
|
|
return `${OPID_PROFILE_SCREEN_PROVIDER}?accessToken=${accessToken}`;
|
|
}
|
|
|
|
async logoutOauth(token: string) {
|
|
await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`);
|
|
}
|
|
}
|
|
|
|
export const adminApi = new AdminApi();
|