Skip to content

Commit f3aa7c2

Browse files
committed
feat(grpc): update to grpc v2.4.3
1 parent a226064 commit f3aa7c2

7 files changed

+177
-160
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@aws-sdk/client-s3": "^3.657.0",
2929
"@aws-sdk/client-ses": "^3.515.0",
3030
"@inquirer/prompts": "^7.2.0",
31-
"@pretendonetwork/grpc": "^2.4.0",
31+
"@pretendonetwork/grpc": "^2.4.3",
3232
"bcrypt": "^5.0.0",
3333
"buffer-crc32": "^0.2.13",
3434
"colors": "^1.4.0",

src/services/grpc/account/v2/exchange-independent-service-token-for-user-data.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function exchangeIndependentServiceTokenForUserData(request: Exchan
2424
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token');
2525
}
2626

27-
// TODO - Add checks for the client ID/title ID and matching system/token types here
27+
// TODO - Add checks for the client IDs and matching system/token types here
2828

2929
if (serviceToken.info.expires < new Date()) {
3030
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token');
@@ -116,6 +116,11 @@ export async function exchangeIndependentServiceTokenForUserData(request: Exchan
116116
titleId: serviceToken.info.title_id,
117117
issueTime: serviceToken.info.issued,
118118
expireTime: serviceToken.info.expires
119+
},
120+
basicUserInfo: {
121+
// TODO - ban: {}
122+
accessBetaServers: pnid.access_level === 1 || pnid.access_level === 2 || pnid.access_level === 3, // TODO - Remove with a better permission check later
123+
accessDeveloperServers: pnid.access_level === 3 // TODO - Remove with a better permission check later
119124
}
120125
};
121126
} else {
@@ -137,6 +142,11 @@ export async function exchangeIndependentServiceTokenForUserData(request: Exchan
137142
titleId: serviceToken.info.title_id,
138143
issueTime: serviceToken.info.issued,
139144
expireTime: serviceToken.info.expires
145+
},
146+
basicUserInfo: {
147+
// TODO - ban: {}
148+
accessBetaServers: nexAccount.access_level === 1 || nexAccount.access_level === 2 || nexAccount.access_level === 3, // TODO - Remove with a better permission check later
149+
accessDeveloperServers: nexAccount.access_level === 3 // TODO - Remove with a better permission check later
140150
}
141151
};
142152
}

src/services/grpc/account/v2/exchange-nex-token-for-user-data.ts

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import crypto from 'node:crypto';
22
import { Status, ServerError } from 'nice-grpc';
33
import { NEXToken } from '@/models/nex-token';
44
import { NEXAccount } from '@/models/nex-account';
5+
import { getPNIDByPID } from '@/database';
56
import type { ExchangeNEXTokenForUserDataRequest, ExchangeNEXTokenForUserDataResponse } from '@pretendonetwork/grpc/account/v2/exchange_nex_token_for_user_data_rpc';
67
import type { HydratedNEXAccountDocument } from '@/types/mongoose/nex-account';
78
import type { HydratedNEXTokenDocument } from '@/models/nex-token';
@@ -33,23 +34,57 @@ export async function exchangeNEXTokenForUserData(request: ExchangeNEXTokenForUs
3334
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token. No user found');
3435
}
3536

36-
return {
37-
nexAccount: {
38-
pid: nexAccount.pid,
39-
owningPid: nexAccount.owning_pid,
40-
accessLevel: nexAccount.access_level,
41-
serverAccessLevel: nexAccount.server_access_level,
42-
friendCode: nexAccount.friend_code,
43-
deviceType: nexAccount.device_type
44-
},
45-
tokenInfo: {
46-
systemType: nexToken.info.system_type as any, // TODO - Stop the any usage
47-
tokenType: nexToken.info.system_type as any, // TODO - Stop the any usage
48-
pid: BigInt(nexAccount.pid),
49-
accessLevel: nexAccount.access_level,
50-
titleId: nexToken.info.title_id,
51-
issueTime: nexToken.info.issued,
52-
expireTime: nexToken.info.expires
53-
}
54-
};
37+
const pnid = await getPNIDByPID(nexAccount.owning_pid || nexAccount.pid);
38+
39+
if (pnid) {
40+
return {
41+
nexAccount: {
42+
pid: nexAccount.pid,
43+
owningPid: nexAccount.owning_pid,
44+
accessLevel: nexAccount.access_level,
45+
serverAccessLevel: nexAccount.server_access_level,
46+
friendCode: nexAccount.friend_code,
47+
deviceType: nexAccount.device_type
48+
},
49+
tokenInfo: {
50+
systemType: nexToken.info.system_type as any, // TODO - Stop the any usage
51+
tokenType: nexToken.info.system_type as any, // TODO - Stop the any usage
52+
pid: BigInt(nexAccount.pid),
53+
accessLevel: nexAccount.access_level,
54+
titleId: nexToken.info.title_id,
55+
issueTime: nexToken.info.issued,
56+
expireTime: nexToken.info.expires
57+
},
58+
basicUserInfo: {
59+
// TODO - ban: {}
60+
accessBetaServers: pnid.access_level === 1 || pnid.access_level === 2 || pnid.access_level === 3, // TODO - Remove with a better permission check later
61+
accessDeveloperServers: pnid.access_level === 3 // TODO - Remove with a better permission check later
62+
}
63+
};
64+
} else {
65+
return {
66+
nexAccount: {
67+
pid: nexAccount.pid,
68+
owningPid: nexAccount.owning_pid,
69+
accessLevel: nexAccount.access_level,
70+
serverAccessLevel: nexAccount.server_access_level,
71+
friendCode: nexAccount.friend_code,
72+
deviceType: nexAccount.device_type
73+
},
74+
tokenInfo: {
75+
systemType: nexToken.info.system_type as any, // TODO - Stop the any usage
76+
tokenType: nexToken.info.system_type as any, // TODO - Stop the any usage
77+
pid: BigInt(nexAccount.pid),
78+
accessLevel: nexAccount.access_level,
79+
titleId: nexToken.info.title_id,
80+
issueTime: nexToken.info.issued,
81+
expireTime: nexToken.info.expires
82+
},
83+
basicUserInfo: {
84+
// TODO - ban: {}
85+
accessBetaServers: nexAccount.access_level === 1 || nexAccount.access_level === 2 || nexAccount.access_level === 3, // TODO - Remove with a better permission check later
86+
accessDeveloperServers: nexAccount.access_level === 3 // TODO - Remove with a better permission check later
87+
}
88+
};
89+
}
5590
}

src/services/grpc/account/v2/exchange-oauth-token-for-user-data.ts

Lines changed: 79 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -36,108 +36,89 @@ export async function exchangeOAuthTokenForUserData(request: ExchangeOAuthTokenF
3636
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token');
3737
}
3838

39-
if (!nexAccount) {
39+
if (!nexAccount || !pnid) {
4040
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid token. No user found');
4141
}
4242

43-
// TODO - Change this. This duplication sucks, but I wanna push this out the door
44-
if (pnid) {
45-
const devices = (await Device.find({
46-
linked_pids: pnid.pid
47-
})).map((device) => {
48-
return {
49-
model: device.get('model'), // * ".model" gives the Mongoose model
50-
serial: device.serial,
51-
linkedPids: device.linked_pids,
52-
accessLevel: device.access_level,
53-
serverAccessLevel: device.server_access_level,
54-
deviceId: device.device_id
55-
};
56-
});
57-
43+
const devices = (await Device.find({
44+
linked_pids: pnid.pid
45+
})).map((device) => {
5846
return {
59-
pnid: {
60-
deleted: pnid.deleted,
61-
pid: pnid.pid,
62-
username: pnid.username,
63-
accessLevel: pnid.access_level,
64-
serverAccessLevel: pnid.server_access_level,
65-
mii: {
66-
name: pnid.mii.name,
67-
data: pnid.mii.data,
68-
url: `${config.cdn.base_url}/mii/${pnid.pid}/standard.tga`
69-
},
70-
creationDate: pnid.creation_date,
71-
birthdate: pnid.birthdate,
72-
gender: pnid.gender,
73-
country: pnid.country,
74-
language: pnid.language,
75-
emailAddress: pnid.email.address,
76-
tierName: pnid.connections.stripe.tier_name,
77-
permissions: {
78-
bannedAllPermanently: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_PERMANENTLY),
79-
bannedAllTemporarily: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_TEMPORARILY),
80-
betaAccess: pnid.hasPermission(PNID_PERMISSION_FLAGS.BETA_ACCESS),
81-
accessAdminPanel: pnid.hasPermission(PNID_PERMISSION_FLAGS.ACCESS_ADMIN_PANEL),
82-
createServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_SERVER_CONFIGS),
83-
modifyServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_SERVER_CONFIGS),
84-
deployServer: pnid.hasPermission(PNID_PERMISSION_FLAGS.DEPLOY_SERVER),
85-
modifyPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_PNIDS),
86-
modifyNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_NEX_ACCOUNTS),
87-
modifyConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_CONSOLES),
88-
banPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_PNIDS),
89-
banNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_NEX_ACCOUNTS),
90-
banConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_CONSOLES),
91-
moderateMiiverse: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODERATE_MIIVERSE),
92-
createApiKeys: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_API_KEYS),
93-
createBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_BOSS_TASKS),
94-
updateBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_TASKS),
95-
deleteBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_TASKS),
96-
uploadBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPLOAD_BOSS_FILES),
97-
updateBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_FILES),
98-
deleteBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_FILES),
99-
updatePnidPermissions: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_PNID_PERMISSIONS)
100-
},
101-
linkedDevices: devices
102-
},
103-
nexAccount: {
104-
pid: nexAccount.pid,
105-
owningPid: nexAccount.owning_pid,
106-
accessLevel: nexAccount.access_level,
107-
serverAccessLevel: nexAccount.server_access_level,
108-
friendCode: nexAccount.friend_code,
109-
deviceType: nexAccount.device_type
110-
},
111-
tokenInfo: {
112-
systemType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
113-
tokenType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
114-
pid: BigInt(pnid.pid),
115-
accessLevel: pnid.access_level,
116-
titleId: oAuthToken.info.title_id,
117-
issueTime: oAuthToken.info.issued,
118-
expireTime: oAuthToken.info.expires
119-
}
47+
model: device.get('model'), // * ".model" gives the Mongoose model
48+
serial: device.serial,
49+
linkedPids: device.linked_pids,
50+
accessLevel: device.access_level,
51+
serverAccessLevel: device.server_access_level,
52+
deviceId: device.device_id
12053
};
121-
} else {
122-
return {
123-
pnid: undefined, // * Throws an error if this is not explictly set?
124-
nexAccount: {
125-
pid: nexAccount.pid,
126-
owningPid: nexAccount.owning_pid,
127-
accessLevel: nexAccount.access_level,
128-
serverAccessLevel: nexAccount.server_access_level,
129-
friendCode: nexAccount.friend_code,
130-
deviceType: nexAccount.device_type
54+
});
55+
56+
return {
57+
pnid: {
58+
deleted: pnid.deleted,
59+
pid: pnid.pid,
60+
username: pnid.username,
61+
accessLevel: pnid.access_level,
62+
serverAccessLevel: pnid.server_access_level,
63+
mii: {
64+
name: pnid.mii.name,
65+
data: pnid.mii.data,
66+
url: `${config.cdn.base_url}/mii/${pnid.pid}/standard.tga`
13167
},
132-
tokenInfo: {
133-
systemType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
134-
tokenType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
135-
pid: BigInt(nexAccount.pid),
136-
accessLevel: nexAccount.access_level,
137-
titleId: oAuthToken.info.title_id,
138-
issueTime: oAuthToken.info.issued,
139-
expireTime: oAuthToken.info.expires
140-
}
141-
};
142-
}
68+
creationDate: pnid.creation_date,
69+
birthdate: pnid.birthdate,
70+
gender: pnid.gender,
71+
country: pnid.country,
72+
language: pnid.language,
73+
emailAddress: pnid.email.address,
74+
tierName: pnid.connections.stripe.tier_name,
75+
permissions: {
76+
bannedAllPermanently: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_PERMANENTLY),
77+
bannedAllTemporarily: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_TEMPORARILY),
78+
betaAccess: pnid.hasPermission(PNID_PERMISSION_FLAGS.BETA_ACCESS),
79+
accessAdminPanel: pnid.hasPermission(PNID_PERMISSION_FLAGS.ACCESS_ADMIN_PANEL),
80+
createServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_SERVER_CONFIGS),
81+
modifyServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_SERVER_CONFIGS),
82+
deployServer: pnid.hasPermission(PNID_PERMISSION_FLAGS.DEPLOY_SERVER),
83+
modifyPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_PNIDS),
84+
modifyNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_NEX_ACCOUNTS),
85+
modifyConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_CONSOLES),
86+
banPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_PNIDS),
87+
banNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_NEX_ACCOUNTS),
88+
banConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_CONSOLES),
89+
moderateMiiverse: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODERATE_MIIVERSE),
90+
createApiKeys: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_API_KEYS),
91+
createBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_BOSS_TASKS),
92+
updateBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_TASKS),
93+
deleteBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_TASKS),
94+
uploadBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPLOAD_BOSS_FILES),
95+
updateBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_FILES),
96+
deleteBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_FILES),
97+
updatePnidPermissions: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_PNID_PERMISSIONS)
98+
},
99+
linkedDevices: devices
100+
},
101+
nexAccount: {
102+
pid: nexAccount.pid,
103+
owningPid: nexAccount.owning_pid,
104+
accessLevel: nexAccount.access_level,
105+
serverAccessLevel: nexAccount.server_access_level,
106+
friendCode: nexAccount.friend_code,
107+
deviceType: nexAccount.device_type
108+
},
109+
tokenInfo: {
110+
systemType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
111+
tokenType: oAuthToken.info.system_type as any, // TODO - Stop the any usage
112+
pid: BigInt(pnid.pid),
113+
accessLevel: pnid.access_level,
114+
titleId: oAuthToken.info.title_id,
115+
issueTime: oAuthToken.info.issued,
116+
expireTime: oAuthToken.info.expires
117+
},
118+
basicUserInfo: {
119+
// TODO - ban: {}
120+
accessBetaServers: pnid.access_level === 1 || pnid.access_level === 2 || pnid.access_level === 3, // TODO - Remove with a better permission check later
121+
accessDeveloperServers: pnid.access_level === 3 // TODO - Remove with a better permission check later
122+
}
123+
};
143124
}

src/services/grpc/account/v2/exchange-password-reset-token-for-user-data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export async function exchangePasswordResetTokenForUserData(request: ExchangePas
110110
titleId: passwordResetToken.info.title_id,
111111
issueTime: passwordResetToken.info.issued,
112112
expireTime: passwordResetToken.info.expires
113+
},
114+
basicUserInfo: {
115+
// TODO - ban: {}
116+
accessBetaServers: pnid.access_level === 1 || pnid.access_level === 2 || pnid.access_level === 3, // TODO - Remove with a better permission check later
117+
accessDeveloperServers: pnid.access_level === 3 // TODO - Remove with a better permission check later
113118
}
114119
};
115120
}

0 commit comments

Comments
 (0)