diff --git a/backend/.env.dist b/backend/.env.dist index 9844d8c4a..580f7ad2b 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -62,4 +62,8 @@ WEBHOOK_ELOPAGE_SECRET=secret # LOG_LEVEL=info # Federation -FEDERATION_VALIDATE_COMMUNITY_TIMER=60000 \ No newline at end of file +FEDERATION_VALIDATE_COMMUNITY_TIMER=60000 + +# GMS +GMS_HOST=54.176.169.179 +GMS_PORT=3071 diff --git a/backend/.env.template b/backend/.env.template index e79122368..05cec536e 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -1,5 +1,5 @@ # must match the CONFIG_VERSION.EXPECTED definition in scr/config/index.ts -CONFIG_VERSION=v20.2023-09-19 +CONFIG_VERSION=v21.2023-11-15 # Server JWT_SECRET=$JWT_SECRET @@ -61,3 +61,7 @@ WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET # Federation FEDERATION_VALIDATE_COMMUNITY_TIMER=$FEDERATION_VALIDATE_COMMUNITY_TIMER + +# GMS +GMS_HOST=$GMS_HOST +GMS_PORT=$GMS_PORT diff --git a/backend/src/apis/gms/GmsClient.ts b/backend/src/apis/gms/GmsClient.ts new file mode 100644 index 000000000..d96fbf879 --- /dev/null +++ b/backend/src/apis/gms/GmsClient.ts @@ -0,0 +1,80 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-argument */ +import axios from 'axios' + +import { CONFIG } from '@/config' +import { LogError } from '@/server/LogError' +import { backendLogger as logger } from '@/server/logger' + +import { GmsCommunity } from './model/GmsCommunity' +import { GmsUser } from './model/GmsUser' + +export async function communityList(): Promise { + const baseUrl = 'http://'.concat(CONFIG.GMS_HOST).concat(':').concat(CONFIG.GMS_PORT).concat('/') + const service = 'community/list?page=1&perPage=20' + const config = { + headers: { + accept: 'application/json', + language: 'en', + timezone: 'UTC', + connection: 'keep-alive', + authorization: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiVTJGc2RHVmtYMThuNzllbGJscThDbmxxZ0I2SGxicTZuajlpM2lmV3BTc3pHZFRtOFVTQjJZNWY2bG56elhuSUF0SEwvYVBWdE1uMjA3bnNtWDQ0M21xWVFyd0xJMklHNGtpRkZ3U2FKbVJwRk9VZXNDMXIyRGlta3VLMklwN1lYRTU0c2MzVmlScmMzaHE3djlFNkRabk4xeVMrU1QwRWVZRFI5c09pTDJCdmg4a05DNUc5NTdoZUJzeWlRbXcrNFFmMXFuUk5SNXpWdXhtZEE2WUUrT3hlcS85Y0d6NURyTmhoaHM3MTJZTFcvTmprZGNwdU55dUgxeWxhNEhJZyIsImlhdCI6MTcwMDUxMDg4OX0.WhtNGZc9A_hUfh8CcPjr44kWQWMkKJ7hlYXELOd3yy4', + }, + } + try { + const result = await axios.get(baseUrl.concat(service), config) + logger.debug('GET-Response of community/list:', result) + if (result.status !== 200) { + throw new LogError('HTTP Status Error in community/list:', result.status, result.statusText) + } + logger.debug('responseData:', result.data.responseData.data) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + const gmsCom = JSON.parse(result.data.responseData.data) + logger.debug('gmsCom:', gmsCom) + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return gmsCom + } catch (error: any) { + logger.error('Error in Get community/list:', error) + const errMsg: string = error.message + return errMsg + } +} + +export async function userList(): Promise { + const baseUrl = 'http://'.concat(CONFIG.GMS_HOST).concat(':').concat(CONFIG.GMS_PORT).concat('/') + const service = 'community-user/list?page=1&perPage=20' + const config = { + headers: { + accept: 'application/json', + language: 'en', + timezone: 'UTC', + connection: 'keep-alive', + authorization: + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiVTJGc2RHVmtYMThuNzllbGJscThDbmxxZ0I2SGxicTZuajlpM2lmV3BTc3pHZFRtOFVTQjJZNWY2bG56elhuSUF0SEwvYVBWdE1uMjA3bnNtWDQ0M21xWVFyd0xJMklHNGtpRkZ3U2FKbVJwRk9VZXNDMXIyRGlta3VLMklwN1lYRTU0c2MzVmlScmMzaHE3djlFNkRabk4xeVMrU1QwRWVZRFI5c09pTDJCdmg4a05DNUc5NTdoZUJzeWlRbXcrNFFmMXFuUk5SNXpWdXhtZEE2WUUrT3hlcS85Y0d6NURyTmhoaHM3MTJZTFcvTmprZGNwdU55dUgxeWxhNEhJZyIsImlhdCI6MTcwMDUxMDg4OX0.WhtNGZc9A_hUfh8CcPjr44kWQWMkKJ7hlYXELOd3yy4', + }, + } + try { + const result = await axios.get(baseUrl.concat(service), config) + logger.debug('GET-Response of community/list:', result) + if (result.status !== 200) { + throw new LogError( + 'HTTP Status Error in community-user/list:', + result.status, + result.statusText, + ) + } + logger.debug('responseData:', result.data.responseData.data) + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + const gmsUser = JSON.parse(result.data.responseData.data) + logger.debug('gmsUser:', gmsUser) + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return gmsUser + } catch (error: any) { + logger.error('Error in Get community-user/list:', error) + const errMsg: string = error.message + return errMsg + } +} diff --git a/backend/src/apis/gms/model/GmsCommunity.ts b/backend/src/apis/gms/model/GmsCommunity.ts new file mode 100644 index 000000000..c979d8ef7 --- /dev/null +++ b/backend/src/apis/gms/model/GmsCommunity.ts @@ -0,0 +1,17 @@ +import { GmsCommunityProfile } from './GmsCommunityProfile' +import { GmsRole } from './GmsRoles' + +export class GmsCommunity { + id: number + uuid: string + communityUuid: string + email: string + countryCode: string + mobile: string + status: number + createdAt: Date + updatedAt: Date + UserProfile: unknown + communityProfile: GmsCommunityProfile + roles: GmsRole[] +} diff --git a/backend/src/apis/gms/model/GmsCommunityProfile.ts b/backend/src/apis/gms/model/GmsCommunityProfile.ts new file mode 100644 index 000000000..a099e2680 --- /dev/null +++ b/backend/src/apis/gms/model/GmsCommunityProfile.ts @@ -0,0 +1,16 @@ +export class GmsCommunityProfile { + name: string + location: { + type: string + coordinates: [number] + } + + address: string + communityId: number + radius: number + description: string + // eslint-disable-next-line camelcase + api_key: string + communityAuthUrl: unknown + profileImage: unknown +} diff --git a/backend/src/apis/gms/model/GmsRoles.ts b/backend/src/apis/gms/model/GmsRoles.ts new file mode 100644 index 000000000..22f4adfb2 --- /dev/null +++ b/backend/src/apis/gms/model/GmsRoles.ts @@ -0,0 +1,6 @@ +export class GmsRole { + code: string + status: number + name: string + Permissions: [unknown] +} diff --git a/backend/src/apis/gms/model/GmsUser.ts b/backend/src/apis/gms/model/GmsUser.ts new file mode 100644 index 000000000..aa1ae4ce4 --- /dev/null +++ b/backend/src/apis/gms/model/GmsUser.ts @@ -0,0 +1,18 @@ +import { GmsRole } from './GmsRoles' +import { GmsUserAccount } from './GmsUserAccount' +import { GmsUserProfile } from './GmsUserProfile' + +export class GmsUser { + id: number + uuid: string + communityUuid: string + email: string + countryCode: string + mobile: string + status: number + createdAt: Date + updatedAt: Date + userProfile: GmsUserProfile + userAccounts: GmsUserAccount[] + roles: GmsRole[] +} diff --git a/backend/src/apis/gms/model/GmsUserAccount.ts b/backend/src/apis/gms/model/GmsUserAccount.ts new file mode 100644 index 000000000..545ed03f3 --- /dev/null +++ b/backend/src/apis/gms/model/GmsUserAccount.ts @@ -0,0 +1,16 @@ +import { Decimal } from 'decimal.js-light' + +export class GmsUserAccount { + name: string + location: { + type: string + coordinates: [Decimal, Decimal] + } + + address: string + radius: number + description: string + // eslint-disable-next-line camelcase + api_key: string + profileImage: unknown +} diff --git a/backend/src/apis/gms/model/GmsUserProfile.ts b/backend/src/apis/gms/model/GmsUserProfile.ts new file mode 100644 index 000000000..de47a1639 --- /dev/null +++ b/backend/src/apis/gms/model/GmsUserProfile.ts @@ -0,0 +1,22 @@ +import { Decimal } from 'decimal.js-light' + +export class GmsUserProfile { + firstName: string + lastName: string + alias: string + type: number + name: string + location: { + type: string + coordinates: [Decimal, Decimal] + } + + accuracy: unknown + address: string + city: string + state: string + country: string + zipCode: string + language: string + profileImage: unknown +} diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 7ad0271ea..645192476 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -19,7 +19,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL ?? 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v20.2023-09-19', + EXPECTED: 'v21.2023-11-15', CURRENT: '', }, } @@ -134,6 +134,12 @@ const federation = { process.env.FEDERATION_XCOM_MAXREPEAT_REVERTSENDCOINS ?? 3, } +const gms = { + // koordinates of Illuminz-instance of GMS + GMS_HOST: process.env.GMS_HOST ?? 'localhost', + GMS_PORT: process.env.GMS_PORT ?? '4044', +} + export const CONFIG = { ...constants, ...server, @@ -145,4 +151,5 @@ export const CONFIG = { ...loginServer, ...webhook, ...federation, + ...gms, } diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index 69b69070a..462595fae 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -12,6 +12,7 @@ import { backendLogger as logger } from '@/server/logger' import { startCommunityAuthentication } from './authenticateCommunities' import { ApiVersionType } from './enum/apiVersionType' +import { communityList, userList } from '@/apis/gms/GmsClient' export async function startValidateCommunities(timerInterval: number): Promise { logger.info( @@ -29,6 +30,16 @@ export async function startValidateCommunities(timerInterval: number): Promise { + // test GMS-Api Client + try { + const gmsComArray = await communityList() + logger.debug('GMS-Community-List:', gmsComArray) + const gmsUserArray = await userList() + logger.debug('GMS-Community-User-List:', gmsUserArray) + } catch (err) { + logger.error('Error in GMS-API:', err) + } + const dbFederatedCommunities: DbFederatedCommunity[] = await DbFederatedCommunity.createQueryBuilder() .where({ foreign: true, verifiedAt: IsNull() })