Skip to content

Commit

Permalink
Refactor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Jan 11, 2024
1 parent a0a01c5 commit 8ed45c8
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 25 deletions.
13 changes: 8 additions & 5 deletions platform/account/src/jsonrpc/methods/getAccountAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OAuthAccountType } from '@proofzero/types/account'

import type { Context } from '../../context'
import { MicrosoftAccount } from '../../nodes'
import { InternalServerError } from '@proofzero/errors'

export const GetAccountAvatarOutput = z.string()

Expand All @@ -30,12 +31,14 @@ export const getAccountAvatarMethod: GetAccountAvatarMethod = async ({
throw new Error('missing address or type')
}

if (!ctx.hashedIdref) {
throw new InternalServerError({
message: 'Missing hashedIdref',
})
}

if (type == OAuthAccountType.Microsoft) {
const oAuthNode = new MicrosoftAccount(
nodeClient,
ctx.hashedIdref!,
ctx.env
)
const oAuthNode = new MicrosoftAccount(nodeClient, ctx.hashedIdref, ctx.env)
return oAuthNode.getAvatar()
}

Expand Down
14 changes: 11 additions & 3 deletions platform/account/src/jsonrpc/methods/getAccountProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
AccountProfileSchema,
MaskAccountProfileSchema,
} from '../validators/profile'
import OAuthAccount from '../../nodes/oauth'
import { AccountURN, AccountURNSpace } from '@proofzero/urns/account'

export const GetAccountProfileOutput = z.union([
Expand Down Expand Up @@ -64,7 +63,11 @@ export const getAccountProfileMethod: GetAccountProfileMethod = async ({
if (!nodeClient)
throw new InternalServerError({ message: 'missing nodeClient' })

return getProfile(ctx, nodeClient, ctx.accountURN!)
if (!ctx.accountURN) {
throw new InternalServerError({ message: 'missing accountURN' })
}

return getProfile(ctx, nodeClient, ctx.accountURN)
}

export const getAccountProfileBatchMethod = async ({
Expand Down Expand Up @@ -119,7 +122,12 @@ async function getProfile(
case OAuthAccountType.Google:
return new GoogleAccount(node, ctx.env)
case OAuthAccountType.Microsoft:
return new MicrosoftAccount(node, ctx.hashedIdref!, ctx.env)
if (!ctx.hashedIdref) {
throw new InternalServerError({
message: 'Missing hashedIdref',
})
}
return new MicrosoftAccount(node, ctx.hashedIdref, ctx.env)
case OAuthAccountType.Twitter:
return new TwitterAccount(node)
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/jsonrpc/methods/getIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface GetIdentityMethod {
(params: GetIdentityParams): Promise<GetIdentityResult>
}

export const getIdentityMethod: GetIdentityMethod = async ({ input, ctx }) => {
export const getIdentityMethod: GetIdentityMethod = async ({ ctx }) => {
if (isHandleAccountType(ctx.addrType as string)) {
throw new Error('Not implemented')
}
Expand Down
2 changes: 0 additions & 2 deletions platform/account/src/jsonrpc/methods/getOAuthData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import OAuthAccount from '../../nodes/oauth'
export const GetOAuthDataOutput = OAuthDataSchema.optional()

export const getOAuthDataMethod = async ({
input,
ctx,
}: {
input: unknown
ctx: Context
}): Promise<z.infer<typeof GetOAuthDataOutput>> => {
const nodeClient = new OAuthAccount(ctx.account as AccountNode)
Expand Down
2 changes: 0 additions & 2 deletions platform/account/src/jsonrpc/methods/getWebAuthNData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { AccountNode, WebauthnAccount } from '../../nodes'
export const GetWebAuthNDataOutput = z.any()

export const getWebAuthNDataMethod = async ({
input,
ctx,
}: {
input: unknown
ctx: Context
}): Promise<z.infer<typeof GetWebAuthNDataOutput>> => {
const nodeClient = new WebauthnAccount(ctx.account as AccountNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const sendReconciliationNotificationMethod = async ({
const devBatchModels = input.apps
.filter((a) => Boolean(a.devEmail))
.map((app) => ({
email: app.devEmail!,
email: app.devEmail as string,
type: ReconciliationNotificationType.Dev,
appName: app.appName,
billingURL: input.billingURL,
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class AppleAccount extends OAuthAccount {
return TOKEN_URL
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'apple' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class DiscordAccount extends OAuthAccount {
}
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'discord' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class GithubAccount extends OAuthAccount {
}
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'github' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class GoogleAccount extends OAuthAccount {
}
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'google' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class MicrosoftAccount extends OAuthAccount {
}
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'oauth' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class OAuthAccount {
throw new Error('not implemented')
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'oauth' })
}
}
Expand Down
2 changes: 1 addition & 1 deletion platform/account/src/nodes/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class TwitterAccount extends OAuthAccount {
}
}

static async alarm(account: Account) {
static async alarm() {
console.log({ alarm: 'oauth' })
}
}
Expand Down
3 changes: 2 additions & 1 deletion platform/authorization/src/jsonrpc/methods/exchangeToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ const handleAuthorizationCode: ExchangeTokenMethod<
ctx.traceSpan,
combinedPersonaData
)
for (const [_, scopeClaimResponse] of Object.entries(idTokenClaims)) {
for (const entry of Object.entries(idTokenClaims)) {
const scopeClaimResponse = entry[1]
if (!scopeClaimResponse.meta.valid)
throw new UnauthorizedError({
message: 'Authorized data error. Re-authorization by user required',
Expand Down
3 changes: 2 additions & 1 deletion platform/authorization/src/jsonrpc/methods/getUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export const getUserInfoMethod = async ({
personaData
)

for (const [_, scopeClaimResponse] of Object.entries(claimValues)) {
for (const entry of Object.entries(claimValues)) {
const scopeClaimResponse = entry[1]
if (!scopeClaimResponse.meta.valid)
throw new UnauthorizedError({
message: 'Authorized data error. Re-authorization by user required',
Expand Down
3 changes: 2 additions & 1 deletion platform/authorization/src/jsonrpc/methods/preauthorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const preauthorizeMethod = async ({
const existingPersonaData = await authorizationNode.storage.get('personaData')
const { tokenMap } = await authorizationNode.class.getTokenState()

for (const [k, v] of Object.entries(tokenMap)) {
for (const kv of Object.entries(tokenMap)) {
const v = kv[1]
const existingScopeValSet = new Set(v.scope)
if (requestedScope.every((scopeVal) => existingScopeValSet.has(scopeVal))) {
console.log('Pre-authorizing based on matching scope subset:', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export const acceptIdentityGroupMemberInvitation = async ({
message: 'Identity group DO not found',
})
}
if (!ctx.identityURN) {
throw new InternalServerError({
message: 'Missing identityURN',
})
}

const invitations = await node.class.getInvitations()
const invitation = invitations.find(
Expand All @@ -62,7 +67,7 @@ export const acceptIdentityGroupMemberInvitation = async ({
const caller = router.createCaller(ctx)

const accounts = await caller.identity.getOwnAccounts({
URN: ctx.identityURN!,
URN: ctx.identityURN,
})
const targetAccount = accounts.find(
(account) =>
Expand Down

0 comments on commit 8ed45c8

Please sign in to comment.